summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cmd/generate/src_contribs.go20
1 files changed, 14 insertions, 6 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go
index 0b5acb5..eb611a3 100644
--- a/cmd/generate/src_contribs.go
+++ b/cmd/generate/src_contribs.go
@@ -258,6 +258,14 @@ func (c Contribution) fetchSubmittedAt() (time.Time, error) {
return time.Time{}, fmt.Errorf("idk how to get created timestamp for %q", c.URLs[0])
}
+func withinOneSecond(a, b time.Time) bool {
+ d := a.Sub(b)
+ if d < 0 {
+ d = -d
+ }
+ return d <= time.Second
+}
+
func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
for _, u := range c.URLs {
if m := reGoLangGerritCL.FindStringSubmatch(u); m != nil {
@@ -283,7 +291,7 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
retUpdatedAt := obj.Updated.Val
var retUser User
for _, message := range obj.Messages {
- if message.Date.Val == retUpdatedAt {
+ if withinOneSecond(message.Date.Val, retUpdatedAt) {
if message.Author.DisplayName != "" {
retUser.Name = message.Author.DisplayName
} else {
@@ -323,11 +331,11 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
retUpdatedAt := obj.UpdatedAt
var retUser User
- if retUser == (User{}) && obj.CreatedAt == retUpdatedAt {
+ if retUser == (User{}) && withinOneSecond(obj.CreatedAt, retUpdatedAt) {
retUser.Name = obj.CreatedBy.Login
retUser.URL = obj.CreatedBy.HTMLURL
}
- if retUser == (User{}) && obj.MergedAt == retUpdatedAt {
+ if retUser == (User{}) && withinOneSecond(obj.MergedAt, retUpdatedAt) {
retUser.Name = obj.MergedBy.Login
retUser.URL = obj.MergedBy.HTMLURL
}
@@ -344,7 +352,7 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
return time.Time{}, User{}, err
}
for _, comment := range comments {
- if comment.UpdatedAt == retUpdatedAt || comment.UpdatedAt.Add(1*time.Second) == retUpdatedAt {
+ if withinOneSecond(comment.UpdatedAt, retUpdatedAt) {
retUser.Name = comment.User.Login
retUser.URL = comment.User.HTMLURL
break
@@ -364,7 +372,7 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
return time.Time{}, User{}, err
}
for _, comment := range reviewComments {
- if comment.UpdatedAt == retUpdatedAt {
+ if withinOneSecond(comment.UpdatedAt, retUpdatedAt) {
retUser.Name = comment.User.Login
retUser.URL = comment.User.HTMLURL
break
@@ -383,7 +391,7 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
return time.Time{}, User{}, err
}
for _, event := range events {
- if event.CreatedAt == retUpdatedAt {
+ if withinOneSecond(event.CreatedAt, retUpdatedAt) {
retUser.Name = event.Actor.Login
retUser.URL = event.Actor.HTMLURL
break