-
-
Notifications
You must be signed in to change notification settings - Fork 18
/
commands.go
57 lines (50 loc) · 1.36 KB
/
commands.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
package ui
import (
"context"
"fmt"
"log"
"strings"
"time"
forkcleaner "github.com/caarlos0/fork-cleaner/v2"
tea "github.com/charmbracelet/bubbletea"
"github.com/google/go-github/v50/github"
)
func requestDeleteReposCmd() tea.Msg {
return requestDeleteSelectedReposMsg{}
}
func deleteReposCmd(client *github.Client, repos []*forkcleaner.RepositoryWithDetails) tea.Cmd {
return func() tea.Msg {
var names []string
for _, r := range repos {
names = append(names, r.Name)
}
log.Println("deleteReposCmd", strings.Join(names, ", "))
if err := forkcleaner.Delete(context.Background(), client, repos); err != nil {
return errMsg{err}
}
return reposDeletedMsg{}
}
}
func enqueueGetReposCmd() tea.Msg {
return getRepoListMsg{}
}
func getReposCmd(client *github.Client, login string, skipUpstream bool) tea.Cmd {
limits, _, _ := client.RateLimits(context.Background())
log.Println("RateLimits: ", limits)
if limits.Core.Remaining < 1 {
return func() tea.Msg {
return errMsg{
fmt.Errorf("Rate limit exceeded. Remaining: %d, Time till reset: %v",
limits.Core.Remaining, time.Since(limits.Core.Reset.Time)),
}
}
}
return func() tea.Msg {
log.Println("getReposCmd")
repos, err := forkcleaner.FindAllForks(context.Background(), client, login, skipUpstream)
if err != nil {
return errMsg{err}
}
return gotRepoListMsg{repos}
}
}