Skip to content

Commit

Permalink
ORC-1509: Auto grant contributor role to first-time contributors
Browse files Browse the repository at this point in the history
### 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 <dongjoon@apache.org>
Signed-off-by: Dongjoon Hyun <dongjoon@apache.org>
  • Loading branch information
dongjoon-hyun committed Oct 7, 2023
1 parent d90ad49 commit 55ec5e6
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion dev/merge_orc_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 55ec5e6

Please sign in to comment.