generated from argoproj-labs/argo-workflows-hello-executor-plugin
/
main.go
34 lines (28 loc) · 809 Bytes
/
main.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
package main
import (
"context"
"net/http"
"os"
"github.com/google/go-github/github"
githubexecutor "github.com/crenshaw-dev/github-executor-plugin/internal"
"golang.org/x/oauth2"
)
func main() {
agentToken, err := os.ReadFile("/var/run/argo/token")
if err != nil {
panic(err.Error())
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: os.Getenv("GITHUB_TOKEN")},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
gitHubClient := &githubexecutor.GitHubClient{Issues: client.Issues}
executor := githubexecutor.NewGitHubExecutor(gitHubClient, string(agentToken))
http.HandleFunc("/api/v1/template.execute", githubexecutor.GitHubPlugin(&executor))
err = http.ListenAndServe(":4356", nil)
if err != nil {
panic(err.Error())
}
}