...
1
2
3
4
5
6
7
8
9
10 package main
11
12 import (
13 "context"
14 "flag"
15 "fmt"
16 "log"
17 "os"
18
19 "github.com/google/go-github/v33/github"
20 "golang.org/x/oauth2"
21 )
22
23 var (
24 name = flag.String("name", "", "Name of repo to create in authenticated user's GitHub account.")
25 description = flag.String("description", "", "Description of created repo.")
26 private = flag.Bool("private", false, "Will created repo be private.")
27 )
28
29 func main() {
30 flag.Parse()
31 token := os.Getenv("GITHUB_AUTH_TOKEN")
32 if token == "" {
33 log.Fatal("Unauthorized: No token present")
34 }
35 if *name == "" {
36 log.Fatal("No name: New repos must be given a name")
37 }
38 ctx := context.Background()
39 ts := oauth2.StaticTokenSource(&oauth2.Token{AccessToken: token})
40 tc := oauth2.NewClient(ctx, ts)
41 client := github.NewClient(tc)
42
43 r := &github.Repository{Name: name, Private: private, Description: description}
44 repo, _, err := client.Repositories.Create(ctx, "", r)
45 if err != nil {
46 log.Fatal(err)
47 }
48 fmt.Printf("Successfully created new repo: %v\n", repo.GetName())
49 }
50
View as plain text