From 55ec5e62ad3e92715e911844a5159f69270f8469 Mon Sep 17 00:00:00 2001 From: Dongjoon Hyun Date: Sat, 7 Oct 2023 15:35:42 -0700 Subject: [PATCH] ORC-1509: Auto grant contributor role to first-time contributors ### What changes were proposed in this pull request? This PR aims to grant 'Apache ORC Contributor' role to the first-time contributors. ### Why are the changes needed? To provide more convenient ways to the Apache ORC committers ### How was this patch tested? Manual. Closes #1621 from dongjoon-hyun/ORC-1509. Authored-by: Dongjoon Hyun Signed-off-by: Dongjoon Hyun --- dev/merge_orc_pr.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/dev/merge_orc_pr.py b/dev/merge_orc_pr.py index 6795701fad..12062c1665 100755 --- a/dev/merge_orc_pr.py +++ b/dev/merge_orc_pr.py @@ -373,7 +373,22 @@ def choose_jira_assignee(issue, asf_jira): except BaseException: # assume it's a user id, and try to assign (might fail, we just prompt again) assignee = asf_jira.user(raw_assignee) - asf_jira.assign_issue(issue.key, assignee.name) + try: + assign_issue(asf_jira, issue.key, assignee.name) + except Exception as e: + if ( + e.__class__.__name__ == "JIRAError" + and ("'%s' cannot be assigned" % assignee.name) + in getattr(e, "response").text + ): + continue_maybe( + "User '%s' cannot be assigned, add to contributors role and try again?" + % assignee.name + ) + grant_contributor_role(assignee.name, asf_jira) + assign_issue(asf_jira, issue.key, assignee.name) + else: + raise e return assignee except KeyboardInterrupt: raise @@ -382,6 +397,25 @@ def choose_jira_assignee(issue, asf_jira): print("Error assigning JIRA, try again (or leave blank and fix manually)") +def grant_contributor_role(user: str, asf_jira): + role = asf_jira.project_role("ORC", 10010) + role.add_user(user) + print("Successfully added user '%s' to contributors role" % user) + + +def assign_issue(client: jira.client.JIRA, issue: int, assignee: str) -> bool: + """ + Assign an issue to a user, which is a shorthand for jira.client.JIRA.assign_issue. + The original one has an issue that it will search users again and only choose the assignee + from 20 candidates. If it's unmatched, it picks the head blindly. In our case, the assignee + is already resolved. + """ + url = getattr(client, "_get_latest_url")(f"issue/{issue}/assignee") + payload = {"name": assignee} + getattr(client, "_session").put(url, data=json.dumps(payload)) + return True + + def resolve_jira_issues(title, merge_branches, comment): jira_ids = re.findall("ORC-[0-9]{4,5}", title)