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 11, 2024
1 parent add723f commit 08d6522
Show file tree
Hide file tree
Showing 18 changed files with 984 additions and 28 deletions.
6 changes: 5 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
*.pyc
.idea
.idea
*.properties
tests/Framework.py
venv
GithubCredentials.py
42 changes: 32 additions & 10 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):
gh_user_char = ""

api_rate_limits(gh)
prId = issue.number
repository = repo.full_name
Expand Down Expand Up @@ -961,12 +963,17 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
warned_too_many_commits = False
ok_too_many_files = False
warned_too_many_files = False
is_draft_pr = False

if issue.pull_request:
pr = repo.get_pull(prId)
if pr.changed_files == 0:
print("Ignoring: PR with no files changed")
return
if pr.draft:
print("Draft PR, mentions turned off")
is_draft_pr = True
gh_user_char = ""
if cmssw_repo and cms_repo and (pr.base.ref == CMSSW_DEVEL_BRANCH):
if pr.state != "closed":
print("This pull request must go in to master branch")
Expand Down Expand Up @@ -1109,7 +1116,8 @@ 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
last_commit_date = last_commit.committer.date.replace(tzinfo=None)

print(
"Latest commit by ",
last_commit.committer.name.encode("ascii", "ignore").decode(),
Expand Down Expand Up @@ -1664,6 +1672,13 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F

print("Processing commits")

if not pull_request_updated:
_bot_cache_shas = set(bot_cache["commits"].keys())
diff = all_commit_shas.difference(_bot_cache_shas)
if diff:
print("Setting pull-request-update to True:", len(diff), "new commit(s)")
pull_request_updated = True

# Make sure to mark squashed=False if a cached/squashed commit is added back
for commit_sha in [
sha
Expand Down Expand Up @@ -2193,6 +2208,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 +2226,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 @@ -2491,11 +2510,15 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
)

messageUpdatedPR = format(
"Pull request #%(pr)s was updated."
" %(signers)s can you please check and sign again.\n",
"Pull request #%(pr)s was updated.",
pr=pr.number,
signers=", ".join(missing_notifications),
)

if not is_draft_pr:
messageUpdatedPR += format(
" %(signers)s can you please check and sign again.\n",
signers=", ".join(missing_notifications),
)
else:
messageNewPR = format(
"%(msgPrefix)s %(gh_user_char)s%(user)s"
Expand Down Expand Up @@ -2528,11 +2551,10 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
print("Status: Not see= %s, Updated: %s" % (already_seen, pull_request_updated))
if is_closed_branch(pr.base.ref) and (pr.state != "closed"):
commentMsg = messageBranchClosed
elif (not already_seen) or pull_request_updated:
if not already_seen:
commentMsg = messageNewPR
else:
commentMsg = messageUpdatedPR
elif (already_seen or is_draft_pr) and pull_request_updated:
commentMsg = messageUpdatedPR
elif not already_seen and not is_draft_pr:
commentMsg = messageNewPR
elif new_categories:
commentMsg = messageUpdatedPR
elif not missingApprovals:
Expand All @@ -2542,7 +2564,7 @@ def process_pr(repo_config, gh, repo, issue, dryRun, cmsbuild_user=None, force=F
if commentMsg and dryRun:
print("The following comment will be made:")
try:
print(commentMsg.decode("ascii", "replace"))
print(commentMsg.encode("ascii", "replace").decode("ascii", "replace"))
except:
pass
for pre_check in pre_checks + extra_pre_checks:
Expand Down
2 changes: 1 addition & 1 deletion tests/PRActionData/TestProcessPr.test_assign.json
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@
"context": "bot/17/ack"
}
}
]
]
8 changes: 4 additions & 4 deletions tests/PRActionData/TestProcessPr.test_close.json
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,10 @@
true
]
},
{
"type": "close",
"data": null
},
{
"type": "emoji",
"data": [
Expand All @@ -107,10 +111,6 @@
"type": "remove-label",
"data": []
},
{
"type": "close",
"data": null
},
{
"type": "edit-comment",
"data": "cms-bot internal usage<!-- bot cache: {\"commits\":{\"2a9454e30606b17e52000110972998326ce9e428\":{\"files\":[\"Utilities/ReleaseScripts/test/BuildFile.xml\"],\"squashed\":false,\"time\":1711538467},\"79752f053efecad55dde17732259737e621a1f3f\":{\"files\":[\"Utilities/ReleaseScripts/test/BuildFile.xml\"],\"squashed\":false,\"time\":1712828239},\"dae848e38b8e387d7283a3e35818121487d9d76b\":{\"files\":[\"DQMServices/Components/test/dqmiofilecopy.sh\"],\"squashed\":false,\"time\":1712829250},\"e4d069b76c464274bf6e7d7cf9bac2153ed9a903\":{\"files\":[\"DQMServices/Components/test/dqmiofilecopy.sh\"],\"squashed\":false,\"time\":1712819089}},\"emoji\":{\"2049242908\":\"+1\",\"2049536626\":\"+1\",\"2056736344\":\"+1\",\"2056739513\":\"+1\",\"2056740892\":\"+1\",\"2056796593\":\"+1\",\"2056801055\":\"+1\",\"2056820593\":\"+1\",\"2056903278\":\"+1\",\"2056930228\":\"+1\",\"2056934192\":\"+1\"},\"last_seen_sha\":\"dae848e38b8e387d7283a3e35818121487d9d76b\",\"signatures\":{\"2049242908\":\"2a9454e30606b17e52000110972998326ce9e428\"}} -->"
Expand Down
57 changes: 57 additions & 0 deletions tests/PRActionData/TestProcessPr.test_draft_pr_assign.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
[
{
"type": "load-bot-cache",
"data": {
"commits": {
"9138474754099798ff50cb07287e7caa4786f247": {
"files": [
"FWCore/Utilities/BuildFile.xml"
],
"squashed": false,
"time": 1733482192
}
},
"emoji": {
"2523442237": "+1"
},
"last_seen_sha": "9138474754099798ff50cb07287e7caa4786f247",
"signatures": {}
}
},
{
"type": "emoji",
"data": [
2523442237,
"+1",
true
]
},
{
"type": "create-comment",
"data": "New categories assigned: l1\n\n@aloeliger,@epalencia you have been requested to review this Pull request/Issue and eventually sign? Thanks"
},
{
"type": "add-label",
"data": [
"l1-pending"
]
},
{
"type": "remove-label",
"data": []
},
{
"type": "edit-comment",
"data": "cms-bot internal usage<!-- bot cache: {\"commits\":{\"9138474754099798ff50cb07287e7caa4786f247\":{\"files\":[\"FWCore/Utilities/BuildFile.xml\"],\"squashed\":false,\"time\":1733482192}},\"emoji\":{\"2523442237\":\"+1\"},\"last_seen_sha\":\"9138474754099798ff50cb07287e7caa4786f247\",\"signatures\":{}} -->"
},
{
"type": "status",
"data": {
"commit": "9138474754099798ff50cb07287e7caa4786f247",
"state": "success",
"target_url": "https://github.com/iarspider-cmssw/cmssw/pull/21#issuecomment-2523442237",
"description": "Comment by iarspider at 2024-12-06 15:01:51 UTC processed.",
"context": "bot/21/ack"
}
}
]
61 changes: 61 additions & 0 deletions tests/PRActionData/TestProcessPr.test_draft_pr_opened.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
[
{
"type": "load-bot-cache",
"data": {
"commits": {
"9138474754099798ff50cb07287e7caa4786f247": {
"files": [
"FWCore/Utilities/BuildFile.xml"
],
"squashed": false,
"time": 1733482192
}
},
"emoji": {},
"last_seen_sha": "9138474754099798ff50cb07287e7caa4786f247",
"signatures": {}
}
},
{
"type": "status",
"data": {
"commit": "9138474754099798ff50cb07287e7caa4786f247",
"state": "pending",
"target_url": null,
"description": "Waiting for authorized user to issue the test command.",
"context": "bot/21/jenkins"
}
},
{
"type": "add-label",
"data": [
"code-checks-approved"
]
},
{
"type": "remove-label",
"data": [
"code-checks-pending"
]
},
{
"type": "status",
"data": {
"commit": "9138474754099798ff50cb07287e7caa4786f247",
"state": "success",
"target_url": "https://github.com/iarspider-cmssw/cmssw/pull/21#issuecomment-2523440118",
"description": "Check details",
"context": "cms/21/code-checks"
}
},
{
"type": "status",
"data": {
"commit": "9138474754099798ff50cb07287e7caa4786f247",
"state": "success",
"target_url": "https://github.com/iarspider-cmssw/cmssw/pull/21#issuecomment-2523440118",
"description": "Comment by iarspider at 2024-12-06 15:00:50 UTC processed.",
"context": "bot/21/ack"
}
}
]
104 changes: 104 additions & 0 deletions tests/PRActionData/TestProcessPr.test_draft_pr_ready.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
[
{
"type": "load-bot-cache",
"data": {
"commits": {
"28ce3f5888b5433dcae409ee336b2ad422595246": {
"files": [
"FWCore/Utilities/BuildFile.xml"
],
"squashed": false,
"time": 1733495641
},
"9138474754099798ff50cb07287e7caa4786f247": {
"files": [
"FWCore/Utilities/BuildFile.xml"
],
"squashed": false,
"time": 1733482192
}
},
"emoji": {
"2523442237": "+1",
"2532358732": "+1"
},
"last_seen_sha": "28ce3f5888b5433dcae409ee336b2ad422595246",
"signatures": {}
}
},
{
"type": "emoji",
"data": [
2523442237,
"+1",
true
]
},
{
"type": "status",
"data": {
"commit": "28ce3f5888b5433dcae409ee336b2ad422595246",
"state": "success",
"target_url": "https://github.com/iarspider-cmssw/cmssw/pull/21#issuecomment-2532358732",
"description": "Tests requested by iarspider at 2024-12-10 17:30:16 UTC.",
"context": "bot/21/jenkins"
}
},
{
"type": "emoji",
"data": [
2532358732,
"+1",
true
]
},
{
"type": "add-label",
"data": [
"tests-started"
]
},
{
"type": "remove-label",
"data": [
"tests-pending"
]
},
{
"type": "create-property-file",
"data": {
"filename": "trigger-tests-iarspider-cmssw-cmssw-21.properties",
"data": {
"PULL_REQUESTS": "iarspider-cmssw/cmssw#21",
"EXTRA_RELVALS_TESTS": "THREADING GPU HIGH_STATS NANO",
"CONTEXT_PREFIX": "cms/21"
}
}
},
{
"type": "emoji",
"data": [
2532358732,
"+1",
true
]
},
{
"type": "create-comment",
"data": "A new Pull Request was created by @iarspider for master.\n\nIt involves the following packages:\n\n- FWCore/Utilities (**core**)\n\n\n@Dr15Jones, @aloeliger, @epalencia, @makortel, @smuzaffar can you please review it and eventually sign? Thanks.\n@felicepantaleo, @makortel, @missirol, @wddgit this is something you requested to watch as well.\n@iarspider you are the release manager for this.\n\ncms-bot commands are listed <a href=\"http://cms-sw.github.io/cms-bot-cmssw-cmds.html\">here</a>\n"
},
{
"type": "edit-comment",
"data": "cms-bot internal usage<!-- bot cache: {\"commits\":{\"28ce3f5888b5433dcae409ee336b2ad422595246\":{\"files\":[\"FWCore/Utilities/BuildFile.xml\"],\"squashed\":false,\"time\":1733495641},\"9138474754099798ff50cb07287e7caa4786f247\":{\"files\":[\"FWCore/Utilities/BuildFile.xml\"],\"squashed\":false,\"time\":1733482192}},\"emoji\":{\"2523442237\":\"+1\",\"2532358732\":\"+1\"},\"last_seen_sha\":\"28ce3f5888b5433dcae409ee336b2ad422595246\",\"signatures\":{}} -->"
},
{
"type": "status",
"data": {
"commit": "28ce3f5888b5433dcae409ee336b2ad422595246",
"state": "success",
"target_url": "https://github.com/iarspider-cmssw/cmssw/pull/21#issuecomment-2532358732",
"description": "Comment by iarspider at 2024-12-10 17:30:16 UTC processed.",
"context": "bot/21/ack"
}
}
]
Loading

0 comments on commit 08d6522

Please sign in to comment.