diff options
author | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-05-19 01:00:26 -0600 |
---|---|---|
committer | Luke T. Shumaker <lukeshu@lukeshu.com> | 2024-05-19 01:49:27 -0600 |
commit | 75d2ab4f4d2415b1ecead2361acddb1e6d6392dd (patch) | |
tree | 5a5f20ce867e4a695de6ca0135a92a777dfac0c6 /cmd | |
parent | 798f82a342d3885db23733c00b9978e8d77fdcb3 (diff) |
imworkingon: Add GitLab updated-by
Diffstat (limited to 'cmd')
-rw-r--r-- | cmd/generate/src_contribs.go | 50 |
1 files changed, 49 insertions, 1 deletions
diff --git a/cmd/generate/src_contribs.go b/cmd/generate/src_contribs.go index eb611a3..2ace0fd 100644 --- a/cmd/generate/src_contribs.go +++ b/cmd/generate/src_contribs.go @@ -409,12 +409,60 @@ func (c Contribution) fetchLastUpdated() (time.Time, User, error) { urlStr := "https://" + authority + "/api/v4/projects/" + url.QueryEscape(projectID) + "/merge_requests/" + mrnum var obj struct { + ID int `json:"id"` + UpdatedAt time.Time `json:"updated_at"` + + CreatedAt time.Time `json:"created_at"` + CreatedBy struct { + Username string `json:"username"` + WebURL string `json:"web_url"` + } `json:"author"` + + MergedAt time.Time `json:"merged_at"` + MergedBy struct { + Username string `json:"username"` + WebURL string `json:"web_url"` + } `json:"merged_by"` } if err := httpGetJSON(urlStr, nil, &obj); err != nil { return time.Time{}, User{}, err } - return obj.UpdatedAt, User{}, nil + + retUpdatedAt := obj.UpdatedAt + var retUser User + + if retUser == (User{}) && withinOneSecond(obj.CreatedAt, retUpdatedAt) { + retUser.Name = obj.CreatedBy.Username + retUser.URL = obj.CreatedBy.WebURL + } + if retUser == (User{}) && withinOneSecond(obj.MergedAt, retUpdatedAt) { + retUser.Name = obj.MergedBy.Username + retUser.URL = obj.MergedBy.WebURL + } + if retUser == (User{}) { + var notes struct { + Notes []struct { + UpdatedAt time.Time `json:"updated_at"` + Author struct { + Username string `json:"username"` + WebURL string `json:"web_url"` + } `json:"author"` + } `json:"notes"` + } + if err := httpGetJSON(fmt.Sprintf("https://%s/%s/noteable/merge_request/%d/notes", authority, projectID, obj.ID), map[string]string{"X-Last-Fetched-At": "0"}, ¬es); err != nil { + return time.Time{}, User{}, err + } + for _, note := range notes.Notes { + if withinOneSecond(note.UpdatedAt, retUpdatedAt) { + retUser.Name = note.Author.Username + retUser.URL = note.Author.WebURL + break + } + } + } + + return retUpdatedAt, retUser, nil } var ret time.Time |