Skip to content

Comment about a backport even if the original PR doesn't have a label #489

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions bedevere/backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,11 @@ async def _remove_backport_label(gh, original_issue, branch, backport_pr_number)
Also leave a comment on the original PR referencing the backport PR.
"""
backport_label = BACKPORT_LABEL.format(branch=branch)
message = MESSAGE_TEMPLATE.format(branch=branch, pr=backport_pr_number)
await gh.post(original_issue['comments_url'], data={'body': message})
if backport_label not in util.labels(original_issue):
return
await gh.delete(original_issue['labels_url'], {'name': backport_label})
message = MESSAGE_TEMPLATE.format(branch=branch, pr=backport_pr_number)
await gh.post(original_issue['comments_url'], data={'body': message})


@router.register("pull_request", action="opened")
Expand Down
48 changes: 45 additions & 3 deletions tests/test_backport.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,11 @@ async def test_missing_backport_label():
event = sansio.Event(data, event='pull_request',
delivery_id='1')
getitem = {
'https://api.github.com/issue/1234':
{'labels': [{'name': 'CLA signed'}]},
'https://api.github.com/issue/2248': {},
"https://api.github.com/issue/1234": {
"labels": [{"name": "CLA signed"}],
"comments_url": "https://api.github.com/issue/1234/comments",
},
"https://api.github.com/issue/2248": {},
}
gh = FakeGH(getitem=getitem)
await backport.router.dispatch(event, gh)
Expand Down Expand Up @@ -154,6 +156,46 @@ async def test_backport_label_removal_success(pr_prefix):
assert expected_post is not None


async def test_backport_link_comment_without_label(pr_prefix):
event_data = {
"action": "opened",
"number": 2248,
"pull_request": {
"title": f"[3.6] Backport this ({pr_prefix}-1234)",
"body": "",
"issue_url": "https://api.github.com/issue/2248",
"base": {
"ref": "3.6",
},
"statuses_url": "https://api.github.com/repos/python/cpython/statuses/somehash",
},
"repository": {
"issues_url": "https://api.github.com/issue{/number}",
},
}
event = sansio.Event(event_data, event="pull_request", delivery_id="1")
getitem_data = {
"https://api.github.com/issue/1234": {
"labels": [],
"comments_url": "https://api.github.com/issue/1234/comments",
},
"https://api.github.com/issue/2248": {},
}
gh = FakeGH(getitem=getitem_data)
await backport.router.dispatch(event, gh)
issue_data = getitem_data["https://api.github.com/issue/1234"]
assert gh.delete_url is None
assert len(gh.post_) > 0
expected_post = None
for post in gh.post_:
if post[0] == issue_data["comments_url"]:
expected_post = post
message = post[1]["body"]
assert message == backport.MESSAGE_TEMPLATE.format(branch="3.6", pr="2248")

assert expected_post is not None


async def test_backport_label_removal_with_leading_space_in_title(pr_prefix):
event_data = {
'action': 'opened',
Expand Down