MCPcopy Create free account
hub / github.com/ezyang/ghstack / dump_github

Function dump_github

src/ghstack/test_prelude.py:337–398  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

335
336
337def dump_github() -> str:
338 self = CTX
339 r = self.github.graphql(
340 """
341 query {
342 repository(name: "pytorch", owner: "pytorch") {
343 pullRequests {
344 nodes {
345 number
346 baseRefName
347 headRefName
348 title
349 body
350 closed
351 }
352 }
353 }
354 }
355 """
356 )
357 prs = []
358 for pr in r["data"]["repository"]["pullRequests"]["nodes"]:
359 pr["body"] = indent(pr["body"].replace("\r", ""), " ")
360 # TODO: Use of git --graph here is a bit of a loaded
361 # footgun, because git doesn't really give any guarantees
362 # about what the graph should look like. So there isn't
363 # really any assurance that this will output the same thing
364 # on multiple test runs. We'll have to reimplement this
365 # ourselves to do it right.
366 #
367 # UPDATE: Another good reason to rewrite this is because git
368 # puts the first parent on the left, which leads to ugly
369 # graphs. Swapping the parents would give us nice pretty graphs.
370 if not pr["closed"]:
371 pr["commits"] = self.upstream_sh.git(
372 "log",
373 "--graph",
374 "--oneline",
375 "--pretty=format:%h %s",
376 f'{pr["baseRefName"]}..{pr["headRefName"]}',
377 )
378 pr["commits"] = indent(strip_trailing_whitespace(pr["commits"]), " ")
379 else:
380 pr["commits"] = " (omitted)"
381 pr["status"] = "[X]" if pr["closed"] else "[O]"
382 prs.append(
383 "{status} #{number} {title} ({headRefName} -> {baseRefName})\n\n"
384 "{body}\n\n{commits}\n\n".format(**pr)
385 )
386
387 refs = self.upstream_sh.git(
388 "log",
389 "--graph",
390 "--oneline",
391 "--branches=gh/*/*/next",
392 "--branches=gh/*/*/head",
393 "--pretty=format:%h%d%n%w(0,3,3)%s",
394 )

Callers 1

assert_github_stateFunction · 0.85

Calls 5

indentFunction · 0.85
gitMethod · 0.80
formatMethod · 0.80
graphqlMethod · 0.45

Tested by

no test coverage detected