Skip to content

Commit

Permalink
Implement special handling for draft PRs
Browse files Browse the repository at this point in the history
  • Loading branch information
iarspider committed Dec 5, 2024
1 parent add723f commit 22973b8
Showing 1 changed file with 38 additions and 48 deletions.
86 changes: 38 additions & 48 deletions process_pr.py
Original file line number Diff line number Diff line change
Expand Up @@ -881,8 +881,10 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
return

gh_user_char = "@"
if not notify_user(issue):

if issue.as_pull_request().draft or (not notify_user(issue)):
gh_user_char = ""

api_rate_limits(gh)
prId = issue.number
repository = repo.full_name
Expand Down Expand Up @@ -1110,6 +1112,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
print("PR Statuses:", commit_statuses)
print(len(commit_statuses))
last_commit_date = last_commit.committer.date

print(
"Latest commit by ",
last_commit.committer.name.encode("ascii", "ignore").decode(),
Expand Down Expand Up @@ -2193,6 +2196,9 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
new_categories.add(nc_lab)

if new_assign_cats:
tmp_gh_user_char = gh_user_char
if notify_user(issue):
gh_user_char = "@"
new_l2s = [
gh_user_char + name
for name, l2_categories in list(CMSSW_L2.items())
Expand All @@ -2208,6 +2214,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
+ ",".join(new_l2s)
+ " you have been requested to review this Pull request/Issue and eventually sign? Thanks"
)
gh_user_char = tmp_gh_user_char

# update blocker massge
if new_blocker:
Expand Down Expand Up @@ -2466,58 +2473,40 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
pkg_msg.append("- %s (**%s**)" % (pkg, ", ".join(package_categories[pkg])))
else:
pkg_msg.append("- %s (**new**)" % pkg)
messageNewPR = format(
"%(msgPrefix)s %(gh_user_char)s%(user)s"
" for %(branch)s.\n\n"
"It involves the following packages:\n\n"
"%(packages)s\n\n"
"%(new_package_message)s\n"
"%(l2s)s can you please review it and eventually sign?"
" Thanks.\n"
"%(watchers)s"
"%(releaseManagers)s"
"%(patch_branch_warning)s\n"
'cms-bot commands are listed <a href="http://cms-sw.github.io/cms-bot-cmssw-cmds.html">here</a>\n',
msgPrefix=NEW_PR_PREFIX,
user=pr.user.login,
gh_user_char=gh_user_char,
branch=pr.base.ref,
l2s=", ".join(missing_notifications),
packages="\n".join(pkg_msg),
new_package_message=new_package_message,
watchers=watchersMsg,
releaseManagers=releaseManagersMsg,
patch_branch_warning=warning_msg,
pkg_msg_s = "\n".join(pkg_msg)
messageNewPR = (
f"{NEW_PR_PREFIX} {gh_user_char}{pr.user.login} for {pr.base.ref}.\n\n"
f"It involves the following packages:\n\n"
f"{pkg_msg_s}\n\n"
f"{new_package_message}\n"
f"{', '.join(missing_notifications)} can you please review it and eventually sign?"
f" Thanks.\n"
f"{watchersMsg}"
f"{releaseManagersMsg}"
f"{warning_msg}\n"
'cms-bot commands are listed <a href="http://cms-sw.github.io/cms-bot-cmssw-cmds.html">here</a>\n'
)

messageUpdatedPR = format(
"Pull request #%(pr)s was updated."
" %(signers)s can you please check and sign again.\n",
pr=pr.number,
signers=", ".join(missing_notifications),
)
messageUpdatedPR = f"Pull request #{pr.number} was updated. "
if not issue.as_pull_request().draft:
messageUpdatedPR += (
f"{', '.join(missing_notifications)} can you please check and sign again.\n"
)
else:
messageNewPR = format(
"%(msgPrefix)s %(gh_user_char)s%(user)s"
" for branch %(branch)s.\n\n"
"%(l2s)s can you please review it and eventually sign?"
" Thanks.\n"
"%(watchers)s"
"%(releaseManagers)s"
'cms-bot commands are listed <a href="http://cms-sw.github.io/cms-bot-cmssw-cmds.html">here</a>\n',
msgPrefix=NEW_PR_PREFIX,
user=pr.user.login,
gh_user_char=gh_user_char,
branch=pr.base.ref,
l2s=", ".join(missing_notifications),
releaseManagers=releaseManagersMsg,
watchers=watchersMsg,
messageNewPR = (
f"{NEW_PR_PREFIX} {gh_user_char}{pr.user.login} "
f"for branch {pr.base.ref}.\n\n"
f"{', '.join(missing_notifications)} can you please review it and eventually sign?"
f" Thanks.\n"
f"{watchersMsg}"
f"{releaseManagersMsg}"
'cms-bot commands are listed <a href="http://cms-sw.github.io/cms-bot-cmssw-cmds.html">here</a>\n'
)

messageUpdatedPR = format("Pull request #%(pr)s was updated.", pr=pr.number)
messageUpdatedPR = f"Pull request #{pr.number} was updated."

# Finally decide whether or not we should close the pull request:
messageBranchClosed = format(
messageBranchClosed = (
"This branch is closed for updates."
" Closing this pull request.\n"
" Please bring this up in the ORP"
Expand All @@ -2530,7 +2519,8 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
commentMsg = messageBranchClosed
elif (not already_seen) or pull_request_updated:
if not already_seen:
commentMsg = messageNewPR
if not issue.as_pull_request().draft:
commentMsg = messageNewPR
else:
commentMsg = messageUpdatedPR
elif new_categories:
Expand Down Expand Up @@ -2565,7 +2555,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
)
continue
if (not dryRunOrig) and (pre_checks_state[pre_check] == ""):
params = {"PULL_REQUEST": "%s" % (prId), "CONTEXT_PREFIX": cms_status_prefix}
params = {"PULL_REQUEST": str(prId), "CONTEXT_PREFIX": cms_status_prefix}
if pre_check == "code-checks":
params["CMSSW_TOOL_CONF"] = code_checks_tools
params["APPLY_PATCH"] = str(code_check_apply_patch).lower()
Expand Down

0 comments on commit 22973b8

Please sign in to comment.