-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgithub.go
More file actions
39 lines (33 loc) · 910 Bytes
/
github.go
File metadata and controls
39 lines (33 loc) · 910 Bytes
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
package main
import (
"context"
"fmt"
"github.com/aws/aws-sdk-go-v2/aws"
"github.com/google/go-github/github"
"golang.org/x/oauth2"
)
// Create GitHub repository
func githubCreateRepo(gitPass, repo, desc, branch string, private bool) error {
var err error
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: gitPass},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
gitRepo := &github.Repository{
Name: github.String(repo),
Private: github.Bool(private),
DefaultBranch: github.String(branch),
MasterBranch: github.String(branch),
Description: aws.String(desc),
}
_, _, err = client.Repositories.Create(ctx, "", gitRepo)
if err != nil {
fmt.Printf("!!! %q alredy exist in GitHub !!!\n", repo)
fmt.Println("Skipping...")
} else {
fmt.Printf("Creating %q repository in GitHub\n", repo)
}
return err
}