|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "time" |
| 5 | + |
4 | 6 | "github.com/google/go-github/v82/github" |
5 | 7 | ) |
6 | 8 |
|
@@ -134,8 +136,81 @@ type MinimalProject struct { |
134 | 136 | OwnerType string `json:"owner_type,omitempty"` |
135 | 137 | } |
136 | 138 |
|
| 139 | +// MinimalIssue is the trimmed output type for issue objects to reduce verbosity. |
| 140 | +type MinimalIssue struct { |
| 141 | + Number int `json:"number"` |
| 142 | + Title string `json:"title"` |
| 143 | + Body string `json:"body,omitempty"` |
| 144 | + State string `json:"state"` |
| 145 | + StateReason string `json:"state_reason,omitempty"` |
| 146 | + Draft bool `json:"draft,omitempty"` |
| 147 | + Locked bool `json:"locked,omitempty"` |
| 148 | + HTMLURL string `json:"html_url"` |
| 149 | + User *MinimalUser `json:"user,omitempty"` |
| 150 | + Labels []string `json:"labels,omitempty"` |
| 151 | + Assignees []string `json:"assignees,omitempty"` |
| 152 | + Milestone string `json:"milestone,omitempty"` |
| 153 | + Comments int `json:"comments,omitempty"` |
| 154 | + CreatedAt string `json:"created_at,omitempty"` |
| 155 | + UpdatedAt string `json:"updated_at,omitempty"` |
| 156 | + ClosedAt string `json:"closed_at,omitempty"` |
| 157 | + ClosedBy string `json:"closed_by,omitempty"` |
| 158 | + IssueType string `json:"issue_type,omitempty"` |
| 159 | +} |
| 160 | + |
137 | 161 | // Helper functions |
138 | 162 |
|
| 163 | +func convertToMinimalIssue(issue *github.Issue) MinimalIssue { |
| 164 | + m := MinimalIssue{ |
| 165 | + Number: issue.GetNumber(), |
| 166 | + Title: issue.GetTitle(), |
| 167 | + Body: issue.GetBody(), |
| 168 | + State: issue.GetState(), |
| 169 | + StateReason: issue.GetStateReason(), |
| 170 | + Draft: issue.GetDraft(), |
| 171 | + Locked: issue.GetLocked(), |
| 172 | + HTMLURL: issue.GetHTMLURL(), |
| 173 | + User: convertToMinimalUser(issue.GetUser()), |
| 174 | + Comments: issue.GetComments(), |
| 175 | + } |
| 176 | + |
| 177 | + if issue.CreatedAt != nil { |
| 178 | + m.CreatedAt = issue.CreatedAt.Format(time.RFC3339) |
| 179 | + } |
| 180 | + if issue.UpdatedAt != nil { |
| 181 | + m.UpdatedAt = issue.UpdatedAt.Format(time.RFC3339) |
| 182 | + } |
| 183 | + if issue.ClosedAt != nil { |
| 184 | + m.ClosedAt = issue.ClosedAt.Format(time.RFC3339) |
| 185 | + } |
| 186 | + |
| 187 | + for _, label := range issue.Labels { |
| 188 | + if label != nil { |
| 189 | + m.Labels = append(m.Labels, label.GetName()) |
| 190 | + } |
| 191 | + } |
| 192 | + |
| 193 | + for _, assignee := range issue.Assignees { |
| 194 | + if assignee != nil { |
| 195 | + m.Assignees = append(m.Assignees, assignee.GetLogin()) |
| 196 | + } |
| 197 | + } |
| 198 | + |
| 199 | + if closedBy := issue.GetClosedBy(); closedBy != nil { |
| 200 | + m.ClosedBy = closedBy.GetLogin() |
| 201 | + } |
| 202 | + |
| 203 | + if milestone := issue.GetMilestone(); milestone != nil { |
| 204 | + m.Milestone = milestone.GetTitle() |
| 205 | + } |
| 206 | + |
| 207 | + if issueType := issue.GetType(); issueType != nil { |
| 208 | + m.IssueType = issueType.GetName() |
| 209 | + } |
| 210 | + |
| 211 | + return m |
| 212 | +} |
| 213 | + |
139 | 214 | func convertToMinimalProject(fullProject *github.ProjectV2) *MinimalProject { |
140 | 215 | if fullProject == nil { |
141 | 216 | return nil |
|
0 commit comments