Skip to content

Commit 92a22e1

Browse files
authored
Merge pull request #66 from adavila0703/sum-contributions-streaks
2 parents 40440f0 + bd4d253 commit 92a22e1

2 files changed

Lines changed: 25 additions & 10 deletions

File tree

internal/github/contributions.go

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -169,16 +169,19 @@ func (g *GithubService) GetFirstContributionYearByUsername(ctx context.Context,
169169
}
170170

171171
type CurrentContributionStreak struct {
172-
Streak int
173-
StartedAt time.Time
172+
Streak int
173+
Contributions int
174+
StartedAt time.Time
174175
}
175176

176177
func (c CurrentContributionStreak) String() string {
177-
msg := fmt.Sprintf("current contribution streak: %d days", c.Streak)
178+
msg := fmt.Sprintf("current contribution streak\nstreak: %d days", c.Streak)
178179
if c.Streak > 0 {
179-
msg = fmt.Sprintf("%s started at: %s", msg, c.StartedAt.Format("2006-01-02"))
180+
msg = fmt.Sprintf("%s\nstarted at: %s", msg, c.StartedAt.Format("2006-01-02"))
180181
}
181182

183+
msg = fmt.Sprintf("%s\ncontributions: %d", msg, c.Contributions)
184+
182185
return msg
183186
}
184187

@@ -212,23 +215,30 @@ func (g *GithubService) GetCurrentContributionStreakByUsername(ctx context.Conte
212215
}
213216
currentContributionStreak.StartedAt = d.Date
214217

218+
currentContributionStreak.Contributions += d.ContributionCount
219+
215220
currentContributionStreak.Streak++
216221
}
217222

218223
return currentContributionStreak, nil
219224
}
220225

221226
type LongestContributionStreak struct {
222-
Streak int
223-
StartedAt time.Time
224-
EndedAt time.Time
227+
Streak int
228+
Contributions int
229+
StartedAt time.Time
230+
EndedAt time.Time
225231
}
226232

227233
func (c LongestContributionStreak) String() string {
234+
startAt := c.StartedAt.Format("2006-01-02")
235+
msg := "longest contribution streak"
236+
228237
if c.EndedAt.IsZero() {
229-
return fmt.Sprintf("longest and current contribution streak: %d days started at: %s", c.Streak, c.StartedAt.Format("2006-01-02"))
238+
return fmt.Sprintf("%s\nstreak: %d days\nstarted at: %s", msg, c.Streak, startAt)
230239
}
231-
return fmt.Sprintf("longest contribution streak: %d days started at: %s ended at: %s", c.Streak, c.StartedAt.Format("2006-01-02"), c.EndedAt.Format("2006-01-02"))
240+
241+
return fmt.Sprintf("%s\nstreak: %d days\nstarted at: %s\nended at: %s\ncontributions: %d", msg, c.Streak, startAt, c.EndedAt.Format("2006-01-02"), c.Contributions)
232242
}
233243

234244
func (g *GithubService) GetLongestContributionStreakByUsername(ctx context.Context, username string) (*LongestContributionStreak, error) {
@@ -265,14 +275,17 @@ func (g *GithubService) GetLongestContributionStreakByUsername(ctx context.Conte
265275
startedAt := time.Time{}
266276
endedAt := time.Time{}
267277
streak := 0
278+
contributionCount := 0
268279
for _, d := range days {
269280
if d.ContributionCount == 0 {
270281
if streak > longestContributionStreak.Streak {
271282
longestContributionStreak.Streak = streak
272283
longestContributionStreak.StartedAt = startedAt
273284
longestContributionStreak.EndedAt = endedAt
285+
longestContributionStreak.Contributions = contributionCount
274286
}
275287

288+
contributionCount = 0
276289
streak = 0
277290

278291
continue
@@ -283,7 +296,9 @@ func (g *GithubService) GetLongestContributionStreakByUsername(ctx context.Conte
283296
}
284297
startedAt = d.Date
285298

299+
contributionCount += d.ContributionCount
286300
streak++
301+
287302
}
288303

289304
now := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 0, 0, 0, 0, time.UTC)

internal/github/repositories.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ type LastRepo struct {
2020
func (c LastRepo) String() string {
2121
msg := fmt.Sprintf("\nThe last repo updated \n\n **%v** \n \t %v \n %v \n Created At: %s \n Updated At: %s", c.Name, c.Description, c.URL, c.CreatedAt.Format("2006-01-02"), c.UpdatedAt.Format("2006-01-02"))
2222
if len(c.Name) == 0 {
23-
msg = fmt.Sprintf("Could not find a repository")
23+
msg = "Could not find a repository"
2424
}
2525

2626
return msg

0 commit comments

Comments
 (0)