-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
48 lines (38 loc) · 1.02 KB
/
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package main
import (
"context"
"log/slog"
"os"
"github.com/shurcooL/githubv4"
"github.com/spf13/viper"
"golang.org/x/oauth2"
)
func main() {
if err := validateEnv(); err != nil {
slog.Error(err.Error())
os.Exit(1)
}
// setup github client
ctx := context.Background()
src := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: viper.GetString("TOKEN")})
gh := githubv4.NewClient(oauth2.NewClient(ctx, src))
// context for early exit
childCtx, cancel := context.WithCancel(ctx)
defer cancel()
// channel for capturing errors
errChan := make(chan error)
// load project data
project := githubv4.ID(viper.GetString("PROJECT_ID"))
field := githubv4.ID(viper.GetString("FIELD_ID"))
// start the pipeline
itemChan, wg := GetProjectItems(childCtx, gh, project, errChan)
updateChan := ProcessProjectItems(childCtx, gh, itemChan, errChan)
done := UpdateProjectItems(childCtx, gh, wg, project, field, updateChan, errChan)
select {
case err := <-errChan:
cancel()
slog.Error(err.Error())
case <-done:
break
}
}