-redef class GithubCurl
- # Get a given pull request (PR)
- fun getpr(repo: String, number: Int): nullable JsonObject
- do
- var ir = get_and_check("https://api.github.com/repos/{repo}/issues/{number}")
- var irm = ir.json_as_map
- if not irm.has_key("pull_request") then return null
- var pr = get_and_check("https://api.github.com/repos/{repo}/pulls/{number}")
- var prm = pr.json_as_map
- var sha = prm["head"].json_as_map["sha"].to_s
- var statuses = get_and_check("https://api.github.com/repos/{repo}/commits/{sha}/status")
- statuses = statuses.json_as_map
- prm["statuses"] = statuses
- print "{prm["title"].to_s}: by {prm["user"].json_as_map["login"].to_s} (# {prm["number"].to_s})"
- var mergeable = prm["mergeable"]
- if mergeable != null then
- print "\tmergeable: {mergeable.to_s}"
- else
- print "\tmergeable: unknown"
- end
- var state = statuses["state"]
- if state == null then
- print "\tstatus: not tested"
- else
- print "\tstatus: {state}"
- var sts = statuses["statuses"].json_as_a
- for st in sts do
- st = st.json_as_map
- var ctx = st["context"].to_s
- state = st["state"].to_s
- print "\tstatus {ctx}: {state}"
- prm["status-{ctx}"] = state
- end
- end
- return prm
+ # Get a given pull request and its state
+ private fun get_pull_with_state(repo: String, number: Int): nullable PullState do
+ var pull = get_pull(repo, number)
+ if not pull isa PullRequest then return null
+
+ var statuses = get_commit_status(repo, pull.head.sha)
+ if not statuses isa CommitStatus then return null
+
+ return new PullState(pull, statuses)