Skip to content

Commit

Permalink
feat: Store state 0 of stargazers count for new repositories
Browse files Browse the repository at this point in the history
  • Loading branch information
reobin committed May 24, 2024
1 parent 840d2ee commit eaa25d2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
7 changes: 6 additions & 1 deletion internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,12 @@ func UniquifyRepositories(repositories []*gogithub.Repository) []*gogithub.Repos
func (repository Repository) AppendToStargazersCountHistory() []StargazersCountHistoryItem {
history := repository.StargazersCountHistory
if history == nil {
history = []StargazersCountHistoryItem{}
history = []StargazersCountHistoryItem{
{
Date: repository.GitHubCreatedAt,
StargazersCount: 0,
},
}
} // sort: newest first
if len(history) > 0 {
sort.Slice(history, func(i int, j int) bool {
Expand Down
2 changes: 2 additions & 0 deletions internal/repository/repository_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,15 @@ func TestUniquifyRepositories(t *testing.T) {
func TestAppendToStargazersCountHistory(t *testing.T) {
t.Run("should initialize history when it's empty", func(t *testing.T) {
repository := Repository{
GitHubCreatedAt: time.Date(1990, time.November, 1, 0, 0, 0, 0, time.UTC),
StargazersCount: 100,
}
history := repository.AppendToStargazersCountHistory()
today := dateUtil.Today()

expected := []StargazersCountHistoryItem{
{Date: today, StargazersCount: 100},
{Date: repository.GitHubCreatedAt, StargazersCount: 0},
}

if !reflect.DeepEqual(history, expected) {
Expand Down

0 comments on commit eaa25d2

Please sign in to comment.