diff --git a/lib/events.go b/lib/events.go index 0ffc325..207a90a 100644 --- a/lib/events.go +++ b/lib/events.go @@ -88,7 +88,7 @@ func (e *Events) filter(events []*github.Event) []*github.Event { for _, event := range events { if e.debug { - format := NewFormat(e.ctx, e.client, false) + format := NewFormat(e.ctx, e.client, Settings{}, false) fmt.Printf("[Debug] %s: %v\n", *event.Type, format.Line(event, 999)) } diff --git a/lib/format.go b/lib/format.go index 9f01604..fdd794b 100644 --- a/lib/format.go +++ b/lib/format.go @@ -14,14 +14,15 @@ import ( // Format is Formatter type Format struct { - ctx context.Context - client *github.Client - debug bool + ctx context.Context + client *github.Client + settings Settings + debug bool } // NewFormat is an initializer -func NewFormat(ctx context.Context, client *github.Client, debug bool) *Format { - return &Format{ctx: ctx, client: client, debug: debug} +func NewFormat(ctx context.Context, client *github.Client, settings Settings, debug bool) *Format { + return &Format{ctx: ctx, client: client, settings: settings, debug: debug} } // Line is line infomation @@ -162,15 +163,6 @@ func getOwnerRepo(repoFullName string) (string, string) { // All returns all lines which are formatted and sorted func (f *Format) All(lines Lines) (string, error) { var result, prevRepoName, currentRepoName string - var settings Settings - - accessToken, err := getAccessToken() - if err != nil { - return "", err - } - if err := settings.Init(getGistID(), accessToken); err != nil { - return "", err - } sort.Sort(lines) @@ -179,10 +171,10 @@ func (f *Format) All(lines Lines) (string, error) { if currentRepoName != prevRepoName { prevRepoName = currentRepoName - result += fmt.Sprintf("\n%s\n\n", formatSubject(settings, currentRepoName)) + result += fmt.Sprintf("\n%s\n\n", formatSubject(f.settings, currentRepoName)) } - result += fmt.Sprintf("%s\n", formatLine(settings, line)) + result += fmt.Sprintf("%s\n", formatLine(f.settings, line)) } return result, nil diff --git a/lib/list.go b/lib/list.go index 7043553..0bd3e24 100644 --- a/lib/list.go +++ b/lib/list.go @@ -39,7 +39,11 @@ func List(sinceDate, untilDate string, debug bool) error { if err != nil { return err } - format := NewFormat(ctx, client, debug) + var settings Settings + if err = settings.Init(getGistID(), accessToken); err != nil { + return err + } + format := NewFormat(ctx, client, settings, debug) parallelNum, err := getParallelNum() if err != nil {