Skip to content

Commit

Permalink
Fix: fetch commits for today using query date qualifier (#4)
Browse files Browse the repository at this point in the history
* Fix: fetch commits for today using query date qualifier

* Add simple test for keyword with date qualifier helper
  • Loading branch information
Flexicon authored Oct 25, 2023
1 parent 14a12d4 commit 8ffd5be
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 7 deletions.
13 changes: 6 additions & 7 deletions fetch_job.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ func searchSketchyCommits(api *GitHubAPI) ([]SearchResultItem, error) {
// Note: don't perform this search concurrently - GitHub does NOT like that.
var results []SearchResultItem

for i, q := range QueryKeywords {
r, err := searchCommits(api, q, 1)
for i, k := range QueryKeywords {
r, err := searchCommits(api, keywordWithDateQualifier(k, today()), 1)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -111,11 +111,6 @@ func buildCommitLogFromResults(results []SearchResultItem) ([]*Commit, error) {
debugLog(fmt.Sprintf("filtering out commit %s as not from today: %v", item.SHA, commitDate))
continue
}
// Ignore commits from the future 🧙‍♂️
if isDateInTheFuture(commitDate) {
debugLog(fmt.Sprintf("filtering out commit %s as in the future: %v", item.SHA, commitDate))
continue
}

c := &Commit{
ID: item.SHA,
Expand Down Expand Up @@ -162,6 +157,10 @@ func containsDaysInThePast(items []SearchResultItem) bool {
return false
}

func keywordWithDateQualifier(keyword string, date time.Time) string {
return fmt.Sprintf("%s author-date:%s", keyword, date.Format("2006-01-02"))
}

func searchPageDepth() int {
return viper.GetInt("github.search_page_depth")
}
38 changes: 38 additions & 0 deletions fetch_job_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"testing"
"time"
)

func Test_keywordWithDateQualifier(t *testing.T) {
cases := []struct {
keyword string
date time.Time
want string
}{
{
keyword: "foo",
date: time.Date(2020, time.January, 1, 0, 0, 0, 0, time.UTC),
want: "foo author-date:2020-01-01",
},
{
keyword: "multi-word query",
date: time.Date(2022, time.March, 30, 0, 0, 0, 0, time.UTC),
want: "multi-word query author-date:2022-03-30",
},
{
keyword: "90's date",
date: time.Date(1993, time.October, 12, 0, 0, 0, 0, time.UTC),
want: "90's date author-date:1993-10-12",
},
}

for _, tc := range cases {
got := keywordWithDateQualifier(tc.keyword, tc.date)
if got != tc.want {
t.Errorf("keywordWithDateQualifier(\"%v\", \"%v\") == \"%v\", want \"%v\"",
tc.keyword, tc.date, got, tc.want)
}
}
}

0 comments on commit 8ffd5be

Please sign in to comment.