-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (48 loc) · 1.62 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
49
50
51
52
53
54
55
package main
import (
"context"
"fmt"
"github.com/google/go-github/v52/github"
"github.com/torinasakura/github/config"
fileCommands "github.com/torinasakura/github/file/commands"
issueCommands "github.com/torinasakura/github/issues/commands"
userCommands "github.com/torinasakura/github/users/commands"
userQueries "github.com/torinasakura/github/users/queries"
"golang.org/x/oauth2"
"log"
"strings"
)
func main() {
cfg, err := config.GetConfig()
if err != nil {
log.Fatalf("Could not read config: %v", err)
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: cfg.GithubToken},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
teamMembers, err := userQueries.GetOrganizationTeamMembers(ctx, client, cfg.GithubOrg, cfg.GithubOrgTeamID)
if err != nil {
log.Fatalf("Could not get organization team members: %v", err)
}
for _, user := range teamMembers {
repoName := fmt.Sprintf("%s.github.io", *user.Login)
err = userCommands.CreateRepoForUser(ctx, client, user, repoName)
if err != nil {
log.Fatalf("Could not create repository: %v", err)
}
content, err := fileCommands.ReadMarkdownFileFromRepo(ctx, client.Repositories, cfg.GithubOrg, cfg.GithubTasksRepo, "README.md")
if err != nil {
log.Fatalf("Could not read file from repo: %v", err)
}
issueContent := strings.Split(content, "\n\n")
for i, issue := range issueContent {
err = issueCommands.CreateIssueFromMarkdown(ctx, client, cfg.GithubOrg, repoName, fmt.Sprintf("Task %d", i+1), issue)
if err != nil {
log.Fatalf("Could not create issue from markdown: %v", err)
}
}
}
}