-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
71 lines (56 loc) · 1.37 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"log"
resty "github.com/go-resty/resty/v2"
"github.com/stargazer39/github-utility/utils"
)
func main() {
// Read token
token, err := utils.ReadToken()
check(err)
// Initialize HTTP client
client := resty.New()
github := &GitHubContext{
Client: client,
Token: token,
}
// Get Organization from user
from := utils.GetString("Transfer from: ")
fmt.Printf("\nGetting Repositories of %s...\n", from)
// List all repositories
repos, _, err := list(from, github)
check(err)
// Display all repos
displayRepos(*repos)
// Get repos to transfer
choices, err2 := utils.GetIntChoice("\nEnter one or more Repo numbers (Ex: 1 5 10): ")
check(err2)
// Fix the index
for i := range choices {
choices[i]--
}
// Get where to transfer
to := utils.GetString("Transfer to: ")
// Show what will happen before
for _, r := range choices {
fmt.Printf("Repo %s will be transferred to %s\n", (*repos)[r].FullName, to)
}
// If confirmed run the tasks
if utils.GetConfirm("Continue ? [N]: ", true) {
for _, r := range choices {
if err, resp := transfer(to, (*repos)[r], github); err != nil {
log.Printf("\n%s", resp)
continue
}
fmt.Printf("Repo %s transferred to %s\n", (*repos)[r].FullName, to)
}
} else {
log.Println("\nYou cancelled the transfer.")
}
}
func check(err error) {
if err != nil {
log.Panic(err)
}
}