diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-05-18 23:10:05 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-05-19 01:30:41 -0600 |
commit | 8b92fbf0062e1b4d6b579f4918bc67929925676e (patch) | |
tree | 8855ae7e346b9e232a3d07be2136d88cd00b765f /cmd/generate/src_contribs.go | |
parent | c0da2a0bdaf1caad67f67bccbd982e1d4ca0fdc4 (diff) |
imworkingon: Add Gerrit last-updated detection
Diffstat (limited to 'cmd/generate/src_contribs.go')
-rw-r--r-- | cmd/generate/src_contribs.go | 41 |
1 files changed, 39 insertions, 2 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go index f22f721..eb9d9ad 100644 --- a/cmd/generate/src_contribs.go +++ b/cmd/generate/src_contribs.go @@ -75,7 +75,7 @@ func (c *Contribution) Fill() error { } for _, u := range c.URLs { if m := reGoLangGerritCL.FindStringSubmatch(u); m != nil { - c.URLs = append(c.URLs, "https://golang.org/cl/"+m[1]) + c.URLs = append(c.URLs, "https://golang.org/cl/"+m[2]) } } return nil @@ -97,7 +97,7 @@ func classifyStatus(status string) (string, error) { } var ( - reGoLangGerritCL = regexp.MustCompile(`https://go-review\.googlesource\.com/c/[^/?#]+/\+/([0-9]+)(?:\?[^#]*)?(?:#.*)?$`) + reGoLangGerritCL = regexp.MustCompile(`https://go-review\.googlesource\.com/c/([^/?#]+)/\+/([0-9]+)(?:\?[^#]*)?(?:#.*)?$`) reGitHubPR = regexp.MustCompile(`^https://github\.com/([^/?#]+)/([^/?#]+)/pull/([0-9]+)(?:\?[^#]*)?(?:#.*)?$`) reGitHubCommit = regexp.MustCompile(`^https://github\.com/([^/?#]+)/([^/?#]+)/commit/([0-9a-f]+)(?:\?[^#]*)?(?:#.*)?$`) reGitLabMR = regexp.MustCompile(`^https://([^/]+)/([^?#]+)/-/merge_requests/([0-9]+)(?:\?[^#]*)?(?:#.*)?$`) @@ -259,6 +259,43 @@ func (c Contribution) fetchSubmittedAt() (time.Time, error) { } func (c Contribution) fetchLastUpdated() (time.Time, User, error) { + for _, u := range c.URLs { + if m := reGoLangGerritCL.FindStringSubmatch(u); m != nil { + projectID := m[1] + changeID := m[2] + + urlStr := "https://go-review.googlesource.com/changes/" + projectID + "~" + changeID + "?o=MESSAGES&o=DETAILED_ACCOUNTS" + + var obj struct { + Updated GerritTime `json:"updated"` + Messages []struct { + Author struct { + AccountID int `json:"_account_id"` + Name string `json:"name"` + DisplayName string `json:"display_name"` + } `json:"author"` + Date GerritTime `json:"date"` + } `json:"messages"` + } + if err := httpGetGerritJSON(urlStr, &obj); err != nil { + return time.Time{}, User{}, err + } + retUpdatedAt := obj.Updated.Val + var retUser User + for _, message := range obj.Messages { + if message.Date.Val == retUpdatedAt { + if message.Author.DisplayName != "" { + retUser.Name = message.Author.DisplayName + } else { + retUser.Name = message.Author.Name + } + retUser.URL = fmt.Sprintf("https://go-review.googlesource.com/dashboard/%d", message.Author.AccountID) + break + } + } + return retUpdatedAt, retUser, nil + } + } if m := reGitHubPR.FindStringSubmatch(c.URLs[0]); m != nil { user := m[1] repo := m[2] |