MCPcopy
hub / github.com/mislav/hub / listPulls

Function listPulls

commands/pr.go:191–251  ·  view source on GitHub ↗
(cmd *Command, args *Args)

Source from the content-addressed store, hash-verified

189}
190
191func listPulls(cmd *Command, args *Args) {
192 localRepo, err := github.LocalRepo()
193 utils.Check(err)
194
195 project, err := localRepo.MainProject()
196 utils.Check(err)
197
198 gh := github.NewClient(project.Host)
199
200 args.NoForward()
201 if args.Noop {
202 ui.Printf("Would request list of pull requests for %s\n", project)
203 return
204 }
205
206 filters := map[string]interface{}{}
207 if args.Flag.HasReceived("--state") {
208 filters["state"] = args.Flag.Value("--state")
209 }
210 if args.Flag.HasReceived("--sort") {
211 filters["sort"] = args.Flag.Value("--sort")
212 }
213 if args.Flag.HasReceived("--base") {
214 filters["base"] = args.Flag.Value("--base")
215 }
216 if args.Flag.HasReceived("--head") {
217 head := args.Flag.Value("--head")
218 if !strings.Contains(head, ":") {
219 head = fmt.Sprintf("%s:%s", project.Owner, head)
220 }
221 filters["head"] = head
222 }
223
224 if args.Flag.Bool("--sort-ascending") {
225 filters["direction"] = "asc"
226 } else {
227 filters["direction"] = "desc"
228 }
229
230 onlyMerged := false
231 if filters["state"] == "merged" {
232 filters["state"] = "closed"
233 onlyMerged = true
234 }
235
236 flagPullRequestLimit := args.Flag.Int("--limit")
237 flagPullRequestFormat := args.Flag.Value("--format")
238 if !args.Flag.HasReceived("--format") {
239 flagPullRequestFormat = "%pC%>(8)%i%Creset %t% l%n"
240 }
241
242 pulls, err := gh.FetchPullRequests(project, filters, flagPullRequestLimit, func(pr *github.PullRequest) bool {
243 return !(onlyMerged && pr.MergedAt.IsZero())
244 })
245 utils.Check(err)
246
247 colorize := colorizeOutput(args.Flag.HasReceived("--color"), args.Flag.Value("--color"))
248 for _, pr := range pulls {

Callers

nothing calls this directly

Calls 14

FetchPullRequestsMethod · 0.95
LocalRepoFunction · 0.92
CheckFunction · 0.92
NewClientFunction · 0.92
PrintfFunction · 0.92
PrintFunction · 0.92
colorizeOutputFunction · 0.85
formatPullRequestFunction · 0.85
MainProjectMethod · 0.80
NoForwardMethod · 0.80
HasReceivedMethod · 0.80
ValueMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…