X-Git-Url: http://nitlanguage.org diff --git a/contrib/github_merge.nit b/contrib/github_merge.nit index 29d7924..ca61f39 100644 --- a/contrib/github_merge.nit +++ b/contrib/github_merge.nit @@ -36,7 +36,8 @@ redef class GithubCurl 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}/statuses/{sha}") + 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"] @@ -45,11 +46,19 @@ redef class GithubCurl else print "\tmergeable: unknown" end - var st = prm["statuses"].json_as_a - if not st.is_empty then - print "\tstatus: {st[0].json_as_map["state"].to_s}" - else + 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 end @@ -91,8 +100,10 @@ var opt_repo = new OptionString("Repository (e.g. nitlang/nit)", "-r", "--repo") var opt_auth = new OptionString("OAuth token", "--auth") var opt_query = new OptionString("Query to get issues (e.g. label=ok_will_merge)", "-q", "--query") var opt_keepgoing = new OptionBool("Skip merge conflicts", "-k", "--keep-going") +var opt_all = new OptionBool("Merge all", "-a", "--all") +var opt_status = new OptionArray("A status context that must be \"success\" (e.g. default)", "--status") var opts = new OptionContext -opts.add_option(opt_repo, opt_auth, opt_query, opt_keepgoing) +opts.add_option(opt_repo, opt_auth, opt_query, opt_status, opt_all, opt_keepgoing) opts.parse(sys.args) var args = opts.rest @@ -113,11 +124,22 @@ var curl = new GithubCurl(auth, "Merge-o-matic (nitlang/nit)") if args.is_empty then # Without args, list `ok_will_merge` var x = curl.get_and_check("https://api.github.com/repos/{repo}/issues?{query}") + var list = new Array[String] for y in x.json_as_a do var number = y.json_as_map["number"].as(Int) - curl.getpr(repo, number) - end - return + var pr = curl.getpr(repo, number) + if pr == null then continue + for ctx in opt_status.value do + if pr.get_or_null("status-{ctx}") != "success" then + print "No \"success\" for {ctx}. Skip." + continue label + end + end + list.add number.to_s + end label + + if not opt_all.value then return + args = list end for arg in args do