Skip to content

Commit

Permalink
Add logs to stargazer code
Browse files Browse the repository at this point in the history
commit-id:e62aa0c7
  • Loading branch information
ejoffe authored and Eitan Joffe committed Mar 30, 2022
1 parent 749b443 commit 54e57eb
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion github/githubclient/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,31 @@ import (

"github.com/ejoffe/rake"
"github.com/ejoffe/spr/config"
"github.com/rs/zerolog/log"
"github.com/shurcooL/githubv4"
)

const (
sprRepoOwner = "ejoffe"
sprRepoName = "spr"
sprRepo = "ejoffe/spr"
promptCycle = 25
)

func (c *client) MaybeStar(ctx context.Context, cfg *config.Config) {
if !cfg.User.Stargazer && cfg.User.RunCount%promptCycle == 0 {
if c.isStar(ctx) {
log.Debug().Bool("stargazer", true).Msg("MaybeStar")
cfg.User.Stargazer = true
rake.LoadSources(cfg.User,
rake.YamlFileWriter(config.UserConfigFilePath()))
} else {
log.Debug().Bool("stargazer", false).Msg("MaybeStar")
fmt.Print("enjoying git spr? add a GitHub star? [Y/n]:")
reader := bufio.NewReader(os.Stdin)
line, _ := reader.ReadString('\n')
line = strings.TrimSpace(line)
if line != "n" {
log.Debug().Msg("MaybeStar : adding star")
c.addStar(ctx)
cfg.User.Stargazer = true
rake.LoadSources(cfg.User,
Expand Down Expand Up @@ -68,11 +71,14 @@ func (c *client) isStar(ctx context.Context) bool {

edgeCount := len(query.Viewer.StarredRepositories.Edges)
if edgeCount == 0 {
log.Debug().Bool("stargazer", false).Msg("MaybeStar::isStar")
return false
}

sprRepo := fmt.Sprintf("%s/%s", sprRepoOwner, sprRepoName)
for _, node := range query.Viewer.StarredRepositories.Nodes {
if node.NameWithOwner == sprRepo {
log.Debug().Bool("stargazer", true).Msg("MaybeStar::isStar")
return true
}
}
Expand All @@ -82,6 +88,7 @@ func (c *client) isStar(ctx context.Context) bool {
iteration++
if iteration > 10 {
// too many stars in the sky
log.Debug().Bool("stargazer", false).Msg("MaybeStar::isStar (too many stars)")
return false
}
}
Expand Down

0 comments on commit 54e57eb

Please sign in to comment.