Skip to content

Commit

Permalink
refactor(fetch): return a list of entries instead of a pointer to a l…
Browse files Browse the repository at this point in the history
…ist of entries
  • Loading branch information
gabor-boros committed Oct 8, 2021
1 parent 1a24535 commit 000a6b7
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ func runRootCmd(_ *cobra.Command, _ []string) {
})
cobra.CheckErr(err)

wl := worklog.NewWorklog(*entries)
wl := worklog.NewWorklog(entries)
completeEntries := wl.CompleteEntries()
incompleteEntries := wl.IncompleteEntries()

Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type Fetcher interface {
// FetchEntries from a given source and return the list of worklog items
// If the fetching resulted in an error, the list of worklog items will be
// nil and an error will return.
FetchEntries(ctx context.Context, opts *FetchOpts) (*[]worklog.Entry, error)
FetchEntries(ctx context.Context, opts *FetchOpts) ([]worklog.Entry, error)
}

// UploadOpts specifies the only options for the Uploader. In contrast to the
Expand Down
8 changes: 4 additions & 4 deletions internal/pkg/client/clockify/clockify.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ type clockifyClient struct {
opts *ClientOpts
}

func (c clockifyClient) getSearchURL(user string, params *WorklogSearchParams) (string, error) {
func (c *clockifyClient) getSearchURL(user string, params *WorklogSearchParams) (string, error) {
searchPath := fmt.Sprintf(PathWorklog, c.opts.Workspace, user)
worklogURL, err := url.Parse(c.opts.BaseURL + searchPath)
if err != nil {
Expand All @@ -102,7 +102,7 @@ func (c clockifyClient) getSearchURL(user string, params *WorklogSearchParams) (
return fmt.Sprintf("%s?%s", worklogURL.Path, worklogURL.Query().Encode()), nil
}

func (c clockifyClient) splitEntry(entry FetchEntry, bd time.Duration, ubd time.Duration) (*[]worklog.Entry, error) {
func (c *clockifyClient) splitEntry(entry FetchEntry, bd time.Duration, ubd time.Duration) (*[]worklog.Entry, error) {
r, err := regexp.Compile(c.opts.TasksAsTagsRegex)
if err != nil {
return nil, err
Expand Down Expand Up @@ -146,7 +146,7 @@ func (c clockifyClient) splitEntry(entry FetchEntry, bd time.Duration, ubd time.
return &items, nil
}

func (c clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpts) (*[]worklog.Entry, error) {
func (c *clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpts) ([]worklog.Entry, error) {
var items []worklog.Entry
currentPage := 1
pageSize := 100
Expand Down Expand Up @@ -224,7 +224,7 @@ func (c clockifyClient) FetchEntries(ctx context.Context, opts *client.FetchOpts
currentPage++
}

return &items, nil
return items, nil
}

// NewClient returns a new Clockify client.
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/client/clockify/clockify_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func TestClockifyClient_FetchEntries(t *testing.T) {
end := time.Date(2021, 10, 2, 23, 59, 59, 0, time.Local)
remainingCalls := 1

expectedEntries := &[]worklog.Entry{
expectedEntries := []worklog.Entry{
{
Client: worklog.IDNameField{
ID: "456",
Expand Down Expand Up @@ -212,7 +212,7 @@ func TestClockifyClient_FetchEntries_TasksAsTags(t *testing.T) {
end := time.Date(2021, 10, 2, 23, 59, 59, 0, time.Local)
remainingCalls := 1

expectedEntries := &[]worklog.Entry{
expectedEntries := []worklog.Entry{
{
Client: worklog.IDNameField{
ID: "456",
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/client/tempo/tempo.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ type tempoClient struct {
opts *ClientOpts
}

func (c *tempoClient) FetchEntries(ctx context.Context, opts *client.FetchOpts) (*[]worklog.Entry, error) {
func (c *tempoClient) FetchEntries(ctx context.Context, opts *client.FetchOpts) ([]worklog.Entry, error) {
searchParams := &SearchParams{
From: opts.Start.Local().Format("2006-01-02"),
To: opts.End.Local().Format("2006-01-02"),
Expand Down Expand Up @@ -111,7 +111,7 @@ func (c *tempoClient) FetchEntries(ctx context.Context, opts *client.FetchOpts)
})
}

return &items, nil
return items, nil
}

func (c *tempoClient) uploadEntry(ctx context.Context, item worklog.Entry, opts *client.UploadOpts, errChan chan error) {
Expand Down
2 changes: 1 addition & 1 deletion internal/pkg/client/tempo/tempo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ func TestTempoClient_FetchEntries(t *testing.T) {
clientUsername := "Thor"
clientPassword := "The strongest Avenger"

expectedEntries := &[]worklog.Entry{
expectedEntries := []worklog.Entry{
{
Client: worklog.IDNameField{
ID: "My Awesome Company",
Expand Down

0 comments on commit 000a6b7

Please sign in to comment.