Skip to content

Commit

Permalink
refactor: Refactor code to include debug flag in List struct
Browse files Browse the repository at this point in the history
  • Loading branch information
MH4GF committed Nov 2, 2023
1 parent 55eb652 commit 914b967
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
4 changes: 2 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ var RootCmd = &cobra.Command{
Use: "github-nippou",
Short: "Print today's your GitHub activity for issues and pull requests",
Run: func(cmd *cobra.Command, args []string) {
list, err := lib.NewListFromCLI(sinceDate, untilDate)
list, err := lib.NewListFromCLI(sinceDate, untilDate, debug)
if err != nil {
fmt.Println(err)
os.Exit(1)
}

lines, err := list.Collect(debug)
lines, err := list.Collect()
if err != nil {
fmt.Println(err)
os.Exit(1)
Expand Down
13 changes: 8 additions & 5 deletions lib/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,23 @@ type List struct {
user string
accessToken string
settingsGistID string
debug bool
}

// NewList returns a new List.
func NewList(sinceDate, untilDate, user, accessToken, settingsGistID string) *List {
func NewList(sinceDate, untilDate, user, accessToken, settingsGistID string, debug bool) *List {
return &List{
sinceDate: sinceDate,
untilDate: untilDate,
user: user,
accessToken: accessToken,
settingsGistID: settingsGistID,
debug: debug,
}
}

// NewListFromCLI returns a new List from environment variables or git config.
func NewListFromCLI(sinceDate, untilDate string) (*List, error) {
func NewListFromCLI(sinceDate, untilDate string, debug bool) (*List, error) {
user, err := getUser()
if err != nil {
return nil, err
Expand All @@ -46,11 +48,12 @@ func NewListFromCLI(sinceDate, untilDate string) (*List, error) {
user: user,
accessToken: accessToken,
settingsGistID: settingsGistID,
debug: debug,
}, nil
}

// Collect collects GitHub activities.
func (l *List) Collect(debug bool) (string, error) {
func (l *List) Collect() (string, error) {
sinceTime, err := getSinceTime(l.sinceDate)
if err != nil {
return "", err
Expand All @@ -64,15 +67,15 @@ func (l *List) Collect(debug bool) (string, error) {
ctx := context.Background()
client := getClient(ctx, l.accessToken)

events, err := NewEvents(ctx, client, l.user, sinceTime, untilTime, debug).Collect()
events, err := NewEvents(ctx, client, l.user, sinceTime, untilTime, l.debug).Collect()
if err != nil {
return "", err
}
var settings Settings
if err = settings.Init(l.settingsGistID, l.accessToken); err != nil {
return "", err
}
format := NewFormat(ctx, client, settings, debug)
format := NewFormat(ctx, client, settings, l.debug)

parallelNum, err := getParallelNum()
if err != nil {
Expand Down

0 comments on commit 914b967

Please sign in to comment.