Skip to content

Commit

Permalink
move stargazer data into internal state file
Browse files Browse the repository at this point in the history
commit-id:6429b70a
  • Loading branch information
ejoffe committed Mar 29, 2023
1 parent fe13ac2 commit 9198098
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 18 deletions.
12 changes: 5 additions & 7 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ type UserConfig struct {
CreateDraftPRs bool `default:"false" yaml:"createDraftPRs"`
PreserveTitleAndBody bool `default:"false" yaml:"preserveTitleAndBody"`
NoRebase bool `default:"false" yaml:"noRebase"`

Stargazer bool `default:"false" yaml:"stargazer"`
RunCount int `default:"0" yaml:"runcount"`
}

type InternalConfig struct {
MergeCheckCommit map[string]string `yaml:"mergeCheckCommit"`

Stargazer bool `default:"false" yaml:"stargazer"`
RunCount int `default:"0" yaml:"runcount"`
}

func EmptyConfig() *Config {
Expand Down Expand Up @@ -117,13 +117,11 @@ func ParseConfig(gitcmd git.GitInterface) *Config {
rake.YamlFileSource(InternalConfigFilePath()),
)

if !cfg.User.Stargazer {
cfg.User.RunCount = cfg.User.RunCount + 1
}

rake.LoadSources(cfg.User,
rake.YamlFileWriter(UserConfigFilePath()))

cfg.Internal.RunCount = cfg.Internal.RunCount + 1

rake.LoadSources(cfg.Internal,
rake.YamlFileWriter(InternalConfigFilePath()))

Expand Down
4 changes: 0 additions & 4 deletions config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,6 @@ func TestDefaultConfig(t *testing.T) {
LogGitHubCalls: false,
StatusBitsHeader: true,
StatusBitsEmojis: true,
Stargazer: false,
RunCount: 0,
},
Internal: &InternalConfig{
MergeCheckCommit: map[string]string{},
Expand Down Expand Up @@ -118,8 +116,6 @@ func TestGitHubRemoteSource(t *testing.T) {
LogGitCommands: false,
LogGitHubCalls: false,
StatusBitsHeader: false,
Stargazer: false,
RunCount: 0,
},
}

Expand Down
14 changes: 7 additions & 7 deletions github/githubclient/star.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const (
)

func (c *client) MaybeStar(ctx context.Context, cfg *config.Config) {
if !cfg.User.Stargazer && cfg.User.RunCount%promptCycle == 0 {
if !cfg.Internal.Stargazer && cfg.Internal.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()))
cfg.Internal.Stargazer = true
rake.LoadSources(cfg.Internal,
rake.YamlFileWriter(config.InternalConfigFilePath()))
} else {
log.Debug().Bool("stargazer", false).Msg("MaybeStar")
fmt.Print("enjoying git spr? add a GitHub star? [Y/n]:")
Expand All @@ -35,9 +35,9 @@ func (c *client) MaybeStar(ctx context.Context, cfg *config.Config) {
if line != "n" {
log.Debug().Msg("MaybeStar : adding star")
c.addStar(ctx)
cfg.User.Stargazer = true
rake.LoadSources(cfg.User,
rake.YamlFileWriter(config.UserConfigFilePath()))
cfg.Internal.Stargazer = true
rake.LoadSources(cfg.Internal,
rake.YamlFileWriter(config.InternalConfigFilePath()))
fmt.Println("Thank you! Happy Coding!")
}
}
Expand Down

0 comments on commit 9198098

Please sign in to comment.