@@ -134,8 +134,138 @@ type MinimalProject struct {
134134 OwnerType string `json:"owner_type,omitempty"`
135135}
136136
137+ // MinimalPullRequest is the trimmed output type for pull request objects to reduce verbosity.
138+ type MinimalPullRequest struct {
139+ Number int `json:"number"`
140+ Title string `json:"title"`
141+ Body string `json:"body,omitempty"`
142+ State string `json:"state"`
143+ Draft bool `json:"draft"`
144+ Merged bool `json:"merged"`
145+ MergeableState string `json:"mergeable_state,omitempty"`
146+ HTMLURL string `json:"html_url"`
147+ User * MinimalUser `json:"user,omitempty"`
148+ Labels []string `json:"labels,omitempty"`
149+ Assignees []string `json:"assignees,omitempty"`
150+ RequestedReviewers []string `json:"requested_reviewers,omitempty"`
151+ MergedBy string `json:"merged_by,omitempty"`
152+ Head * MinimalPRBranch `json:"head,omitempty"`
153+ Base * MinimalPRBranch `json:"base,omitempty"`
154+ Additions int `json:"additions,omitempty"`
155+ Deletions int `json:"deletions,omitempty"`
156+ ChangedFiles int `json:"changed_files,omitempty"`
157+ Commits int `json:"commits,omitempty"`
158+ Comments int `json:"comments,omitempty"`
159+ CreatedAt string `json:"created_at,omitempty"`
160+ UpdatedAt string `json:"updated_at,omitempty"`
161+ ClosedAt string `json:"closed_at,omitempty"`
162+ MergedAt string `json:"merged_at,omitempty"`
163+ Milestone string `json:"milestone,omitempty"`
164+ }
165+
166+ // MinimalPRBranch is the trimmed output type for pull request branch references.
167+ type MinimalPRBranch struct {
168+ Ref string `json:"ref"`
169+ SHA string `json:"sha"`
170+ Repo * MinimalPRBranchRepo `json:"repo,omitempty"`
171+ }
172+
173+ // MinimalPRBranchRepo is the trimmed repo info nested inside a PR branch.
174+ type MinimalPRBranchRepo struct {
175+ FullName string `json:"full_name"`
176+ Description string `json:"description,omitempty"`
177+ }
178+
137179// Helper functions
138180
181+ func convertToMinimalPullRequest (pr * github.PullRequest ) MinimalPullRequest {
182+ m := MinimalPullRequest {
183+ Number : pr .GetNumber (),
184+ Title : pr .GetTitle (),
185+ Body : pr .GetBody (),
186+ State : pr .GetState (),
187+ Draft : pr .GetDraft (),
188+ Merged : pr .GetMerged (),
189+ MergeableState : pr .GetMergeableState (),
190+ HTMLURL : pr .GetHTMLURL (),
191+ User : convertToMinimalUser (pr .GetUser ()),
192+ Additions : pr .GetAdditions (),
193+ Deletions : pr .GetDeletions (),
194+ ChangedFiles : pr .GetChangedFiles (),
195+ Commits : pr .GetCommits (),
196+ Comments : pr .GetComments (),
197+ }
198+
199+ if pr .CreatedAt != nil {
200+ m .CreatedAt = pr .CreatedAt .Format ("2006-01-02T15:04:05Z" )
201+ }
202+ if pr .UpdatedAt != nil {
203+ m .UpdatedAt = pr .UpdatedAt .Format ("2006-01-02T15:04:05Z" )
204+ }
205+ if pr .ClosedAt != nil {
206+ m .ClosedAt = pr .ClosedAt .Format ("2006-01-02T15:04:05Z" )
207+ }
208+ if pr .MergedAt != nil {
209+ m .MergedAt = pr .MergedAt .Format ("2006-01-02T15:04:05Z" )
210+ }
211+
212+ for _ , label := range pr .Labels {
213+ if label != nil {
214+ m .Labels = append (m .Labels , label .GetName ())
215+ }
216+ }
217+
218+ for _ , assignee := range pr .Assignees {
219+ if assignee != nil {
220+ m .Assignees = append (m .Assignees , assignee .GetLogin ())
221+ }
222+ }
223+
224+ for _ , reviewer := range pr .RequestedReviewers {
225+ if reviewer != nil {
226+ m .RequestedReviewers = append (m .RequestedReviewers , reviewer .GetLogin ())
227+ }
228+ }
229+
230+ if mergedBy := pr .GetMergedBy (); mergedBy != nil {
231+ m .MergedBy = mergedBy .GetLogin ()
232+ }
233+
234+ if head := pr .Head ; head != nil {
235+ m .Head = convertToMinimalPRBranch (head )
236+ }
237+
238+ if base := pr .Base ; base != nil {
239+ m .Base = convertToMinimalPRBranch (base )
240+ }
241+
242+ if milestone := pr .GetMilestone (); milestone != nil {
243+ m .Milestone = milestone .GetTitle ()
244+ }
245+
246+ return m
247+ }
248+
249+ func convertToMinimalPRBranch (branch * github.PullRequestBranch ) * MinimalPRBranch {
250+ if branch == nil {
251+ return nil
252+ }
253+
254+ b := & MinimalPRBranch {
255+ Ref : branch .GetRef (),
256+ SHA : branch .GetSHA (),
257+ }
258+
259+ if repo := branch .GetRepo (); repo != nil {
260+ b .Repo = & MinimalPRBranchRepo {
261+ FullName : repo .GetFullName (),
262+ Description : repo .GetDescription (),
263+ }
264+ }
265+
266+ return b
267+ }
268+
139269func convertToMinimalProject (fullProject * github.ProjectV2 ) * MinimalProject {
140270 if fullProject == nil {
141271 return nil
0 commit comments