diff --git a/fetch_job.go b/fetch_job.go index 30a6660..fed5b86 100644 --- a/fetch_job.go +++ b/fetch_job.go @@ -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 } @@ -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, @@ -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") } diff --git a/fetch_job_test.go b/fetch_job_test.go new file mode 100644 index 0000000..5013148 --- /dev/null +++ b/fetch_job_test.go @@ -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) + } + } +}