-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.go
More file actions
58 lines (48 loc) · 1.16 KB
/
main.go
File metadata and controls
58 lines (48 loc) · 1.16 KB
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
56
57
58
package main
import (
"context"
"fmt"
"log"
"os"
"github.com/google/go-github/v45/github"
"github.com/manifoldco/promptui"
"golang.org/x/oauth2"
)
func main() {
githubToken := os.Getenv("GITHUB_TOKEN")
if len(githubToken) == 0 {
log.Fatalln("No env var GITHUB_TOKEN found")
}
ctx := context.Background()
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: githubToken},
)
tc := oauth2.NewClient(ctx, ts)
client := github.NewClient(tc)
repos, _, err := client.Repositories.List(ctx, "", nil)
if err != nil {
log.Fatalln(err)
}
for _, repo := range repos {
if repo.GetFork() {
fmt.Println("Delete:", *repo.Owner.Login, "/", *repo.Name, "?")
if yesNo() {
client.Repositories.Delete(context.Background(), *repo.Owner.Login, *repo.Name)
fmt.Println("Deleted:", *repo.Owner.Login, "/", *repo.Name, "?")
}
} else {
fmt.Printf("Skipping non-forked repo: %s/%s\n", *repo.Owner.Login, *repo.Name)
}
}
}
func yesNo() bool {
prompt := promptui.Select{
Label: "Select[Yes/No]",
Items: []string{"Yes", "No"},
}
_, result, err := prompt.Run()
if err != nil {
log.Fatalf("Prompt failed %v\n", err)
}
return result == "Yes"
}