Skip to content

Commit

Permalink
add progress bar
Browse files Browse the repository at this point in the history
  • Loading branch information
justlorain committed Apr 5, 2024
1 parent c9ae0d7 commit 4d40a3f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ go install github.com/B1NARY-GR0UP/openalysis@latest
- Get Library

```shell
go get github.com/B1NARY-GR0UP/openalysis
go get -u github.com/B1NARY-GR0UP/openalysis
```

## Usage
Expand Down
20 changes: 19 additions & 1 deletion cron/cron.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ import (
"github.com/B1NARY-GR0UP/openalysis/storage"
"github.com/B1NARY-GR0UP/openalysis/util"
"github.com/robfig/cron/v3"
"github.com/schollz/progressbar/v3"
"github.com/shurcooL/githubv4"
"golang.org/x/sync/errgroup"
"gorm.io/gorm"
)

// TODO: add progress bar
// TODO: support group, org, repo update in UpdateTask

var ErrReachedRetryTimes = errors.New("error reached retry times")
Expand Down Expand Up @@ -139,9 +139,15 @@ type Count struct {
func InitTask(ctx context.Context, db *gorm.DB) error {
// handle groups
for _, group := range config.GlobalConfig.Groups {
// new progressbar
bar := progressbar.Default(int64(len(group.Orgs)+len(group.Repos)), "HANDLING GROUP: "+group.Name)

var groupCount Count
// handle orgs in groups
for _, login := range group.Orgs {
// increase bar
_ = bar.Add(1)

var orgCount Count
// org data
org, err := graphql.QueryOrgInfo(ctx, login)
Expand Down Expand Up @@ -211,6 +217,9 @@ func InitTask(ctx context.Context, db *gorm.DB) error {
}
// handle repos in group
for _, nameWithOwner := range group.Repos {
// increase bar
_ = bar.Add(1)

owner, name := util.SplitNameWithOwner(nameWithOwner)
rd := &RepoData{
Owner: owner,
Expand Down Expand Up @@ -265,8 +274,14 @@ func InitTask(ctx context.Context, db *gorm.DB) error {

func UpdateTask(ctx context.Context, db *gorm.DB) error {
for _, group := range config.GlobalConfig.Groups {
// new progressbar
bar := progressbar.Default(int64(len(group.Orgs)+len(group.Repos)), "HANDLING GROUP: "+group.Name)

var groupCount Count
for _, login := range group.Orgs {
// increase bar
_ = bar.Add(1)

var orgCount Count
org, err := graphql.QueryOrgInfo(ctx, login)
if err != nil {
Expand Down Expand Up @@ -343,6 +358,9 @@ func UpdateTask(ctx context.Context, db *gorm.DB) error {
}
}
for _, nameWithOwner := range group.Repos {
// increase bar
_ = bar.Add(1)

owner, name := util.SplitNameWithOwner(nameWithOwner)
rd := &RepoData{
Owner: owner,
Expand Down

0 comments on commit 4d40a3f

Please sign in to comment.