Commit a3bcae0
Changed files (4)
pkg
gitlab
pkg/gitlab/issue.go
@@ -9,23 +9,44 @@ import (
)
type IssueState string
+type IssueType string
const (
- IssueStateClosed IssueState = "closed"
+ IssueClosed IssueState = "closed"
+)
+
+const (
+ IssueTypeIncident IssueType = "incident"
)
type Issue struct {
- ID int `json:"id" yaml:"id"`
- IID int `json:"iid" yaml:"iid"`
- ProjectID int `json:"project_id" yaml:"project_id"`
- Title string `json:"title" yaml:"title"`
- Description string `json:"description" yaml:"description"`
- State IssueState `json:"state" yaml:"state"`
- CreatedAt time.Time `json:"created_at" yaml:"created_at"`
- UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
- ClosedAt time.Time `json:"closed_at" yaml:"closed_at"`
- ClosedBy User `json:"closed_by" yaml:"closed_by"`
- Labels []string `json:"labels" yaml:"labels"`
+ ID int `json:"id" yaml:"id"`
+ IID int `json:"iid" yaml:"iid"`
+ ProjectID int `json:"project_id" yaml:"project_id"`
+ Title string `json:"title" yaml:"title"`
+ Description string `json:"description" yaml:"description"`
+ State IssueState `json:"state" yaml:"state"`
+ CreatedAt time.Time `json:"created_at" yaml:"created_at"`
+ UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
+ ClosedAt time.Time `json:"closed_at" yaml:"closed_at"`
+ ClosedBy User `json:"closed_by" yaml:"closed_by"`
+ Labels []string `json:"labels" yaml:"labels"`
+ Milestone *Milestone `json:"milestone" yaml:"milestone"`
+ Assignees []User `json:"assignees" yaml:"assignees"`
+ Author User `json:"author" yaml:"author"`
+ Type IssueType `json:"issue_type" yaml:"issue_type"`
+ Assignee *User `json:"assignee" yaml:"assignee"`
+ UserNotesCount int `json:"user_notes_count" yaml:"user_notes_count"`
+ MergeRequestsCount int `json:"merge_requests_count" yaml:"merge_requests_count"`
+ Upvotes int `json:"upvotes" yaml:"upvotes"`
+ Downvotes int `json:"downvotes" yaml:"downvotes"`
+ DueDate *string `json:"due_date" yaml:"due_date"`
+ Confidential bool `json:"confidential" yaml:"confidential"`
+ DiscussionLocked *bool `json:"discussion_locked" yaml:"discussion_locked"`
+ WebUrl string `json:"web_url" yaml:"web_url"`
+ BlockingIssuesCount int `json:"blocking_issues_count" yaml:"blocking_issues_count"`
+ HasTasks bool `json:"has_tasks" yaml:"has_tasks"`
+ TaskStatus string `json:"task_status" yaml:"task_status"`
}
func (issue *Issue) ToParam() string {
pkg/gitlab/issue_test.go
@@ -44,7 +44,7 @@ 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, IssueStateClosed, result.State)
+ assert.Equal(t, IssueClosed, 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)
@@ -53,7 +53,7 @@ func TestIssue(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, UserActive, 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)
@@ -64,6 +64,39 @@ func TestIssue(t *testing.T) {
"master-broken::job-timeout",
"master:broken",
}, result.Labels)
+
+ assert.Nil(t, result.Milestone)
+ assert.Empty(t, result.Assignees)
+
+ assert.Equal(t, 1786152, result.Author.ID)
+ assert.Equal(t, IssueTypeIncident, result.Type)
+ assert.Nil(t, result.Assignee)
+ assert.Equal(t, 4, result.UserNotesCount)
+ assert.Equal(t, 0, result.MergeRequestsCount)
+ assert.Equal(t, 0, result.Upvotes)
+ assert.Equal(t, 0, result.Downvotes)
+ assert.Nil(t, result.DueDate)
+ assert.False(t, result.Confidential)
+ assert.Nil(t, result.DiscussionLocked)
+ assert.Equal(t, "https://gitlab.com/gitlab-org/quality/engineering-productivity/master-broken-incidents/-/issues/6375", result.WebUrl)
+
+ // t.Run("time_stats", func(t *testing.T) {
+ // stats := result.TimeStatistics
+ // assert.Equal(t, 0, stats.TimeEstimate)
+ // assert.Equal(t, 0, stats.TotalTimeSpent)
+ // assert.Nil(t, stats.HumanTimeEstimate)
+ // assert.Nil(t, stats.HumanTimeSpent)
+ // })
+
+ // t.Run("task_completion_status", func(t *testing.T) {
+ // status := result.TaskCompletionStatus
+ // assert.Equal(t, 0, status.Count)
+ // assert.Equal(t, 0, status.CompletedCount)
+ // })
+
+ assert.Equal(t, 0, result.BlockingIssuesCount)
+ assert.True(t, result.HasTasks)
+ assert.Equal(t, "0 of 0 checklist items completed", result.TaskStatus)
})
})
}
pkg/gitlab/milestone.go
@@ -0,0 +1,24 @@
+package gitlab
+
+import "time"
+
+type MilestoneState string
+
+const (
+ MilestoneActive MilestoneState = "active"
+)
+
+type Milestone struct {
+ ID int `json:"id" yaml:"id"`
+ IID int `json:"iid" yaml:"iid"`
+ GroupID int `json:"group_id" yaml:"group_id"`
+ Title string `json:"title" yaml:"title"`
+ Description string `json:"description" yaml:"description"`
+ State MilestoneState `json:"state" yaml:"state"`
+ CreatedAt time.Time `json:"created_at" yaml:"created_at"`
+ UpdatedAt time.Time `json:"updated_at" yaml:"updated_at"`
+ DueAt string `json:"due_date" yaml:"due_date"`
+ StartedAt string `json:"start_date" yaml:"start_date"`
+ Expired bool `json:"expired" yaml:"expired"`
+ WebUrl string `json:"web_url" yaml:"web_url"`
+}
pkg/gitlab/user.go
@@ -3,7 +3,7 @@ package gitlab
type UserState string
const (
- UserStateActive UserState = "active"
+ UserActive UserState = "active"
)
type User struct {