8000 Comment about a backport even if the original PR doesn't have a label… · python/bedevere@01fc118 · GitHub
[go: up one dir, main page]

Skip to content

Commit 01fc118

Browse files
authored
Comment about a backport even if the original PR doesn't have a label (#489)
1 parent 71e7252 commit 01fc118

File tree

2 files changed

+47
-5
lines changed

2 files changed

+47
-5
lines changed

bedevere/backport.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,11 +37,11 @@ async def _remove_backport_label(gh, original_issue, branch, backport_pr_number)
3737
Also leave a comment on the original PR referencing the backport PR.
3838
"""
3939
backport_label = BACKPORT_LABEL.format(branch=branch)
40+
message = MESSAGE_TEMPLATE.format(branch=branch, pr=backport_pr_number)
41+
await gh.post(original_issue['comments_url'], data={'body': message})
4042
if backport_label not in util.labels(original_issue):
4143
return
4244
await gh.delete(original_issue['labels_url'], {'name': backport_label})
43-
message = MESSAGE_TEMPLATE.format(branch=branch, pr=backport_pr_number)
44-
await gh.post(original_issue['comments_url'], data={'body': message})
4545

4646

4747
@router.register("pull_request", action="opened")

tests/test_backport.py

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,11 @@ async def test_missing_backport_label():
102102
event = sansio.Event(data, event='pull_request',
103103
delivery_id='1')
104104
getitem = {
105-
'https://api.github.com/issue/1234':
106-
{'labels': [{'name': 'CLA signed'}]},
107-
'https://api.github.com/issue/2248': {},
105+
"https://api.github.com/issue/1234": {
106+
"labels": [{"name": "CLA signed"}],
107+
"comments_url": "https://api.github.com/issue/1234/comments",
108+
},
109+
"https://api.github.com/issue/2248": {},
108110
}
109111
gh = FakeGH(getitem=getitem)
110112
await backport.router.dispatch(event, gh)
@@ -154,6 +156,46 @@ async def test_backport_label_removal_success(pr_prefix):
154156
assert expected_post is not None
155157

156158

159+
async def test_backport_link_comment_without_label(pr_prefix):
160+
event_data = {
161+
"action": "opened",
162+
"number": 2248,
163+
"pull_request": {
164+
"title": f"[3.6] Backport this ({pr_prefix}-1234)",
165+
"body": "",
166+
"issue_url": "https://api.github.com/issue/2248",
167+
"base": {
168+
"ref": "3.6",
169+
},
170+
"statuses_url": "https://api.github.com/repos/python/cpython/statuses/somehash",
171+
},
172+
"repository": {
173+
"issues_url": "https://api.github.com/issue{/number}",
174+
},
175+
}
176+
event = sansio.Event(event_data, event="pull_request", delivery_id="1")
177+
getitem_data = {
178+
"https://api.github.com/issue/1234": {
179+
"labels": [],
180+
"comments_url": "https://api.github.com/issue/1234/comments",
181+
},
182+
"https://api.github.com/issue/2248": {},
183+
}
184+
gh = FakeGH(getitem=getitem_data)
185+
await backport.router.dispatch(event, gh)
186+
issue_data = getitem_data["https://api.github.com/issue/1234"]
187+
assert gh.delete_url is None
188+
assert len(gh.post_) > 0
189+
expected_post = None
190+
for post in gh.post_:
191+
if post[0] == issue_data["comments_url"]:
192+
expected_post = post
193+
message = post[1]["body"]
194+
assert message == backport.MESSAGE_TEMPLATE.format(branch="3.6", pr="2248")
195+
196+
assert expected_post is not None
197+
198+
157199
async def test_backport_label_removal_with_leading_space_in_title(pr_prefix):
158200
event_data = {
159201
'action': 'opened',

0 commit comments

Comments
 (0)
0