Skip to content

Commit

Permalink
spin
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Dec 11, 2016
1 parent 9a6d66b commit 8ce8485
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 7 deletions.
6 changes: 4 additions & 2 deletions glide.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions glide.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,5 @@ import:
- package: golang.org/x/oauth2
- package: github.com/urfave/cli
version: ~1.19.1
- package: github.com/tj/go-spin
version: ~1.0.0
4 changes: 0 additions & 4 deletions internal/cleaner/repos.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cleaner

import (
"fmt"
"time"

"github.com/google/go-github/github"
Expand All @@ -10,7 +9,6 @@ import (
// DeleteForks delete the given list of forks
func DeleteForks(deletions []*github.Repository, client *github.Client) error {
for _, repo := range deletions {
fmt.Println("Deleting fork", *repo.FullName+"...")
_, err := client.Repositories.Delete(*repo.Owner.Login, *repo.Name)
if err != nil {
return err
Expand All @@ -24,7 +22,6 @@ func Repos(owner string, client *github.Client) ([]*github.Repository, error) {
opt := &github.RepositoryListOptions{
ListOptions: github.ListOptions{PerPage: 50},
}
fmt.Println("Repos that could be deleted:")
var deletions []*github.Repository
for {
repos, resp, err := client.Repositories.List(owner, opt)
Expand All @@ -34,7 +31,6 @@ func Repos(owner string, client *github.Client) ([]*github.Repository, error) {
for _, repo := range repos {
if shouldDelete(repo) {
deletions = append(deletions, repo)
fmt.Println(*repo.HTMLURL)
}
}
if resp.NextPage == 0 {
Expand Down
28 changes: 27 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import (
"bufio"
"fmt"
"os"
"time"

"github.com/caarlos0/fork-cleaner/internal/cleaner"
"github.com/google/go-github/github"
spin "github.com/tj/go-spin"
"github.com/urfave/cli"
"golang.org/x/oauth2"
)
Expand Down Expand Up @@ -45,18 +47,42 @@ func main() {
owner = *user.Login
}

active := true
s := spin.New()
s.Set(`⦾⦿`)
go func() {
for active {
fmt.Printf("\r \033[36m%s Gathering data for '%s'...\033[m", s.Next(), owner)
time.Sleep(100 * time.Millisecond)
}
}()
deletions, err := cleaner.Repos(owner, client)
active = false
fmt.Printf("\r")
if err != nil {
return err
}
for _, repo := range deletions {
fmt.Println(*repo.HTMLURL)
}

fmt.Print("\nDelete all ", len(deletions), " listed forks? [y/n] ")
reply, err := bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil {
return err
}
if reply == "y\n" || reply == "Y\n" {
if err := cleaner.DeleteForks(deletions, client); err != nil {
active = true
go func() {
for active {
fmt.Printf("\r \033[36m%s Removing forks...\033[m", s.Next())
time.Sleep(100 * time.Millisecond)
}
}()
err = cleaner.DeleteForks(deletions, client)
active = false
fmt.Printf("\r")
if err != nil {
return err
}
} else {
Expand Down

0 comments on commit 8ce8485

Please sign in to comment.