def close_out_labels( ctx: GithubContext, pr_json: LazyJson, gh: Optional[github3.GitHub] = None, dry_run: bool = False, ) -> Optional[dict]: gh = ensure_gh(ctx, gh) # run this twice so we always have the latest info (eg a thing was already closed) if pr_json["state"] != "closed" and "bot-rerun" in [ l["name"] for l in pr_json.get("labels", []) ]: # update if dry_run: print("dry run: checking pr %s" % pr_json["id"]) else: pr_obj = github3.pulls.PullRequest(dict(pr_json), gh) pr_obj.refresh(True) pr_json = pr_obj.as_dict() if pr_json["state"] != "closed" and "bot-rerun" in [ l["name"] for l in pr_json.get("labels", []) ]: if dry_run: print("dry run: comment and close pr %s" % pr_json["id"]) else: pr_obj.create_comment( "Due to the `bot-rerun` label I'm closing " "this PR. I will make another one as" " appropriate. This was generated by {}".format( ctx.circle_build_url), ) pr_obj.close() delete_branch(ctx=ctx, pr_json=pr_json, dry_run=dry_run) pr_obj.refresh(True) return pr_obj.as_dict() return None
def close_out_dirty_prs( ctx: GithubContext, pr_json: LazyJson, gh: Optional[github3.GitHub] = None, dry_run: bool = False, ) -> Optional[dict]: gh = ensure_gh(ctx, gh) # run this twice so we always have the latest info (eg a thing was already closed) if pr_json["state"] != "closed" and pr_json["mergeable_state"] == "dirty": # update if dry_run: print("dry run: checking pr %s" % pr_json["id"]) else: pr_json = lazy_update_pr_json(pr_json, ctx) if (pr_json["state"] != "closed" and pr_json["mergeable_state"] == "dirty" and not pr_json.get("draft", False)): d = dict(pr_json) if dry_run: print("dry run: comment and close pr %s" % pr_json["id"]) else: pr_obj = get_pr_obj_from_pr_json(pr_json, gh) if all(c.as_dict()["commit"]["author"]["name"] in CF_BOT_NAMES for c in pr_obj.commits()): pr_obj.create_comment( "I see that this PR has conflicts, and I'm the only committer. " "I'm going to close this PR and will make another one as" " appropriate. This was generated by {}".format( ctx.circle_build_url, ), ) pr_obj.close() delete_branch(ctx=ctx, pr_json=pr_json, dry_run=dry_run) pr_json = lazy_update_pr_json(pr_json, ctx) d = dict(pr_json) # This will cause the _update_nodes_with_bot_rerun to trigger # properly and shouldn't be overridden since # this is the last function to run, the long term solution here # is to add the bot to conda-forge and then # it should have label adding capability and we can just add # the label properly d["labels"].append(DUMMY_BOT_RERUN_METADATA) return d return None
def refresh_pr( ctx: GithubContext, pr_json: LazyJson, gh: Optional[github3.GitHub] = None, dry_run: bool = False, ) -> Optional[dict]: if not pr_json["state"] == "closed": if dry_run: print("dry run: refresh pr %s" % pr_json["id"]) pr_dict = dict(pr_json) else: pr_json = lazy_update_pr_json(copy.deepcopy(pr_json), ctx) # if state passed from opened to merged or if it # closed for a day delete the branch if pr_json["state"] == "closed" and pr_json.get( "merged_at", False): delete_branch(ctx=ctx, pr_json=pr_json, dry_run=dry_run) pr_dict = dict(pr_json) return pr_dict return None