-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgithub.go
More file actions
51 lines (43 loc) · 1.14 KB
/
github.go
File metadata and controls
51 lines (43 loc) · 1.14 KB
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
package main
import (
"bytes"
"encoding/json"
"fmt"
"net/http"
"os"
)
func notifyGithub(env, label, tags, ref, lmsDomain, slackThreadTs string) {
url := "https://api.github.com/repos/atomicjolt/atomic-e2e-testing/actions/workflows/manual-run.yml/dispatches"
githubToken := os.Getenv("GITHUB_TOKEN")
payload := map[string]any{
"ref": ref,
"inputs": map[string]string{
"canvasDomain": lmsDomain,
"tags": tags,
"appEnv": env,
"label": label,
"slackThreadTs": slackThreadTs,
},
}
jsonPayload, err := json.Marshal(payload)
if err != nil {
fmt.Println("Failed to marshal JSON:", err)
return
}
req, err := http.NewRequest("POST", url, bytes.NewBuffer(jsonPayload))
if err != nil {
fmt.Println("Failed to create request:", err)
return
}
req.Header.Set("Accept", "application/vnd.github+json")
req.Header.Set("Authorization", "token "+githubToken)
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
fmt.Println("Request failed:", err)
return
}
defer resp.Body.Close()
fmt.Printf("Response status: %s\n", resp.Status)
}