MCPcopy Create free account
hub / github.com/cli/cli / ExportData

Method ExportData

api/export_pr.go:123–250  ·  view source on GitHub ↗
(fields []string)

Source from the content-addressed store, hash-verified

121}
122
123func (pr *PullRequest) ExportData(fields []string) map[string]interface{} {
124 v := reflect.ValueOf(pr).Elem()
125 data := map[string]interface{}{}
126
127 for _, f := range fields {
128 switch f {
129 case "headRepository":
130 data[f] = pr.HeadRepository
131 case "statusCheckRollup":
132 if n := pr.StatusCheckRollup.Nodes; len(n) > 0 {
133 checks := make([]interface{}, 0, len(n[0].Commit.StatusCheckRollup.Contexts.Nodes))
134 for _, c := range n[0].Commit.StatusCheckRollup.Contexts.Nodes {
135 if c.TypeName == "CheckRun" {
136 checks = append(checks, map[string]interface{}{
137 "__typename": c.TypeName,
138 "name": c.Name,
139 "workflowName": c.CheckSuite.WorkflowRun.Workflow.Name,
140 "status": c.Status,
141 "conclusion": c.Conclusion,
142 "startedAt": c.StartedAt,
143 "completedAt": c.CompletedAt,
144 "detailsUrl": c.DetailsURL,
145 })
146 } else {
147 checks = append(checks, map[string]interface{}{
148 "__typename": c.TypeName,
149 "context": c.Context,
150 "state": c.State,
151 "targetUrl": c.TargetURL,
152 "startedAt": c.CreatedAt,
153 })
154 }
155 }
156 data[f] = checks
157 } else {
158 data[f] = nil
159 }
160 case "commits":
161 commits := make([]interface{}, 0, len(pr.Commits.Nodes))
162 for _, c := range pr.Commits.Nodes {
163 commit := c.Commit
164 authors := make([]interface{}, 0, len(commit.Authors.Nodes))
165 for _, author := range commit.Authors.Nodes {
166 authors = append(authors, map[string]interface{}{
167 "name": author.Name,
168 "email": author.Email,
169 "id": author.User.ID,
170 "login": author.User.Login,
171 })
172 }
173 commits = append(commits, map[string]interface{}{
174 "oid": commit.OID,
175 "messageHeadline": commit.MessageHeadline,
176 "messageBody": commit.MessageBody,
177 "committedDate": commit.CommittedDate,
178 "authoredDate": commit.AuthoredDate,
179 "authors": authors,
180 })

Callers 1

Calls 2

LoginOrSlugMethod · 0.80
fieldByNameFunction · 0.70

Tested by 1