diff options
| author | mo khan <mo@mokhan.ca> | 2024-05-18 13:26:11 -0600 |
|---|---|---|
| committer | mo khan <mo@mokhan.ca> | 2024-05-18 13:26:11 -0600 |
| commit | d2a9990f40d6fe4bd2231a663dae1f2e5ac0e3b8 (patch) | |
| tree | 56bee90da885645031d08d26f14c6a86d869fbc3 | |
| parent | bc2a7aa283a9afc5b25b7c5d25e2472605b60572 (diff) | |
feat: Parse closed_by fields
| -rw-r--r-- | pkg/gitlab/issue.go | 18 | ||||
| -rw-r--r-- | pkg/gitlab/issue_test.go | 12 |
2 files changed, 28 insertions, 2 deletions
diff --git a/pkg/gitlab/issue.go b/pkg/gitlab/issue.go index 2469978..8ccaebe 100644 --- a/pkg/gitlab/issue.go +++ b/pkg/gitlab/issue.go @@ -10,9 +10,24 @@ import ( type IssueState string const ( - StateClosed IssueState = "closed" + IssueStateClosed IssueState = "closed" ) +type UserState string + +const ( + UserStateActive UserState = "active" +) + +type User struct { + ID int `json:"id"` + Username string `json:"username"` + State UserState `json:"state"` + Locked bool `json:"locked"` + AvatarUrl string `json:"avatar_url"` + WebUrl string `json:"web_url"` +} + type Issue struct { ID int `json:"id"` IID int `json:"iid"` @@ -23,6 +38,7 @@ type Issue struct { CreatedAt time.Time `json:"created_at"` UpdatedAt time.Time `json:"updated_at"` ClosedAt time.Time `json:"closed_at"` + ClosedBy User `json:"closed_by"` } func FromIssues(r io.Reader) ([]Issue, error) { diff --git a/pkg/gitlab/issue_test.go b/pkg/gitlab/issue_test.go index 2889359..894c91a 100644 --- a/pkg/gitlab/issue_test.go +++ b/pkg/gitlab/issue_test.go @@ -44,10 +44,20 @@ func TestIssue(t *testing.T) { assert.Equal(t, 40549124, result.ProjectID) assert.Contains(t, result.Title, "`gitlab-org/gitlab` broken `master` with rspec unit") assert.Contains(t, result.Description, "## How to close this incident\n\n- Follow the steps in the") - assert.Equal(t, StateClosed, result.State) + assert.Equal(t, IssueStateClosed, result.State) assert.Equal(t, x.Must(time.Parse(time.RFC3339Nano, "2024-05-18T17:39:14.548Z")), result.CreatedAt) assert.Equal(t, x.Must(time.Parse(time.RFC3339Nano, "2024-05-18T18:14:37.830Z")), result.UpdatedAt) assert.Equal(t, x.Must(time.Parse(time.RFC3339Nano, "2024-05-18T17:39:16.837Z")), result.ClosedAt) + + t.Run("closed_by", func(t *testing.T) { + user := result.ClosedBy + assert.Equal(t, 1786152, user.ID) + assert.Equal(t, "gitlab-bot", user.Username) + assert.Equal(t, UserStateActive, user.State) + assert.Equal(t, false, user.Locked) + assert.Equal(t, "https://gitlab.com/uploads/-/system/user/avatar/1786152/avatar.png", user.AvatarUrl) + assert.Equal(t, "https://gitlab.com/gitlab-bot", user.WebUrl) + }) }) }) } |
