summaryrefslogtreecommitdiff
path: root/cmd/generate/src_contribs.go
diff options
context:
space:
mode:
authorLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-29 15:12:06 -0600
committerLuke T. Shumaker <lukeshu@lukeshu.com>2024-04-29 15:14:16 -0600
commited194592ed3378e4e870a26efb726b6e1c0fc7ed (patch)
tree278c0ad7562e8bd8bec2bf0e2c8f57f407aeb13b /cmd/generate/src_contribs.go
parent888c11cebe88008a1fdf64f7a10b010237ad1411 (diff)
imworkingon: v0 of last-updated-by
Diffstat (limited to 'cmd/generate/src_contribs.go')
-rw-r--r--cmd/generate/src_contribs.go101
1 files changed, 89 insertions, 12 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go
index bbb87a6..4e65665 100644
--- a/cmd/generate/src_contribs.go
+++ b/cmd/generate/src_contribs.go
@@ -11,6 +11,11 @@ import (
"sigs.k8s.io/yaml"
)
+type User struct {
+ Name string `json:"name"`
+ URL string `json:"url"`
+}
+
type Contribution struct {
URLs []string `json:"urls"`
Tags []string `json:"tags"`
@@ -19,6 +24,7 @@ type Contribution struct {
SubmittedAt time.Time `json:"submitted-at"`
LastUpdatedAt time.Time `json:"last-updated-at"`
+ LastUpdatedBy User `json:"last-updated-by"`
Status string `json:"status"`
StatusClass string `json:"-"`
@@ -52,7 +58,7 @@ func (c *Contribution) Fill() error {
}
}
if c.LastUpdatedAt.IsZero() {
- c.LastUpdatedAt, err = c.fetchLastUpdatedAt()
+ c.LastUpdatedAt, c.LastUpdatedBy, err = c.fetchLastUpdated()
if err != nil {
return err
}
@@ -252,21 +258,92 @@ func (c Contribution) fetchSubmittedAt() (time.Time, error) {
return time.Time{}, fmt.Errorf("idk how to get created timestamp for %q", c.URLs[0])
}
-func (c Contribution) fetchLastUpdatedAt() (time.Time, error) {
+func (c Contribution) fetchLastUpdated() (time.Time, User, error) {
if m := reGitHubPR.FindStringSubmatch(c.URLs[0]); m != nil {
user := m[1]
repo := m[2]
prnum := m[3]
- urlStr := "https://api.github.com/repos/" + user + "/" + repo + "/pulls/" + prnum
-
var obj struct {
UpdatedAt time.Time `json:"updated_at"`
+ MergedAt time.Time `json:"merged_at"`
+ MergedBy struct {
+ Login string `json:"login"`
+ HTMLURL string `json:"html_url"`
+ } `json:"merged_by"`
}
- if err := httpGetJSON(urlStr, &obj); err != nil {
- return time.Time{}, err
+ if err := httpGetJSON("https://api.github.com/repos/"+user+"/"+repo+"/pulls/"+prnum, &obj); err != nil {
+ return time.Time{}, User{}, err
+ }
+
+ retUpdatedAt := obj.UpdatedAt
+ var retUser User
+
+ if obj.MergedAt == retUpdatedAt {
+ retUser.Name = obj.MergedBy.Login
+ retUser.URL = obj.MergedBy.HTMLURL
+ }
+ if retUser == (User{}) {
+ // "normal" comments
+ var comments []struct {
+ UpdatedAt time.Time `json:"updated_at"`
+ User struct {
+ Login string `json:"login"`
+ HTMLURL string `json:"html_url"`
+ } `json:"user"`
+ }
+ if err := httpGetJSON("https://api.github.com/repos/"+user+"/"+repo+"/issues/"+prnum+"/comments", &comments); err != nil {
+ return time.Time{}, User{}, err
+ }
+ for _, comment := range comments {
+ if comment.UpdatedAt == retUpdatedAt || comment.UpdatedAt.Add(1*time.Second) == retUpdatedAt {
+ retUser.Name = comment.User.Login
+ retUser.URL = comment.User.HTMLURL
+ break
+ }
+ }
}
- return obj.UpdatedAt, nil
+ if retUser == (User{}) {
+ // comments on a specific part of the diff
+ var reviewComments []struct {
+ UpdatedAt time.Time `json:"updated_at"`
+ User struct {
+ Login string `json:"login"`
+ HTMLURL string `json:"html_url"`
+ } `json:"user"`
+ }
+ if err := httpGetJSON("https://api.github.com/repos/"+user+"/"+repo+"/pulls/"+prnum+"/comments", &reviewComments); err != nil {
+ return time.Time{}, User{}, err
+ }
+ for _, comment := range reviewComments {
+ if comment.UpdatedAt == retUpdatedAt {
+ retUser.Name = comment.User.Login
+ retUser.URL = comment.User.HTMLURL
+ break
+ }
+ }
+ }
+ if retUser == (User{}) {
+ var events []struct {
+ CreatedAt time.Time `json:"created_at"`
+ Actor struct {
+ Login string `json:"login"`
+ HTMLURL string `json:"html_url"`
+ } `json:"actor"`
+ }
+ if err := httpGetJSON("https://api.github.com/repos/"+user+"/"+repo+"/issues/"+prnum+"/events", &events); err != nil {
+ return time.Time{}, User{}, err
+ }
+ for _, event := range events {
+ if event.CreatedAt == retUpdatedAt {
+ retUser.Name = event.Actor.Login
+ retUser.URL = event.Actor.HTMLURL
+ break
+ }
+ }
+ }
+
+ return retUpdatedAt, retUser, nil
}
if m := reGitLabMR.FindStringSubmatch(c.URLs[0]); m != nil {
authority := m[1]
@@ -279,9 +356,9 @@ func (c Contribution) fetchLastUpdatedAt() (time.Time, error) {
UpdatedAt time.Time `json:"updated_at"`
}
if err := httpGetJSON(urlStr, &obj); err != nil {
- return time.Time{}, err
+ return time.Time{}, User{}, err
}
- return obj.UpdatedAt, nil
+ return obj.UpdatedAt, User{}, nil
}
var ret time.Time
@@ -304,7 +381,7 @@ func (c Contribution) fetchLastUpdatedAt() (time.Time, error) {
} `json:"commit"`
}
if err := httpGetJSON(urlStr, &obj); err != nil {
- return time.Time{}, err
+ return time.Time{}, User{}, err
}
if obj.Commit.Author.Date.After(ret) {
ret = obj.Commit.Author.Date
@@ -316,8 +393,8 @@ func (c Contribution) fetchLastUpdatedAt() (time.Time, error) {
}
}
if !ret.IsZero() {
- return ret, nil
+ return ret, User{}, nil
}
- return time.Time{}, nil //fmt.Errorf("idk how to get updated timestamp for %q", c.URLs[0])
+ return time.Time{}, User{}, nil //fmt.Errorf("idk how to get updated timestamp for %q", c.URLs[0])
}