-
-
Notifications
You must be signed in to change notification settings - Fork 20
/
util.go
52 lines (45 loc) · 1.24 KB
/
util.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package tagpr
import (
"fmt"
"os"
"strings"
"github.com/google/go-github/v66/github"
)
func exists(filename string) bool {
_, err := os.Stat(filename)
return err == nil
}
func (tp *tagpr) setOutput(name, value string) error {
return setOutput(name, value)
}
func setOutput(name, value string) error {
fpath, ok := os.LookupEnv("GITHUB_OUTPUT")
if !ok {
return nil
}
f, err := os.OpenFile(fpath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0666)
if err != nil {
return err
}
defer f.Close()
_, err = f.WriteString(fmt.Sprintf("%s=%s\n", name, value))
return err
}
func showGHError(err error, resp *github.Response) {
title := "failed to request GitHub API"
message := err.Error()
if resp != nil {
respInfo := []string{
fmt.Sprintf("status:%d", resp.StatusCode),
}
for name := range resp.Header {
n := strings.ToLower(name)
if strings.HasPrefix(n, "x-ratelimit") || n == "x-github-request-id" || n == "retry-after" {
respInfo = append(respInfo, fmt.Sprintf("%s:%s", n, resp.Header.Get(name)))
}
}
message += " " + strings.Join(respInfo, ", ")
}
// https://docs.github.com/en/actions/using-workflows/workflow-commands-for-github-actions#setting-an-error-message
fmt.Printf("::error title=%s::%s\n", title, message)
}