Skip to content

Commit 34b378d

Browse files
authored
Fix error with new commit pushed to existing PR (#577)
It seems like GitHub is sending the url in "url" instead of "issue_url". Couldn't find documentation if there has been recent change about this. I made it to look up for either one of them.
1 parent 7460cbe commit 34b378d

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

.coveragerc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
[run]
22
branch = True
3+
dynamic_context = test_function
34

45
[report]
56
fail_under = 100
7+
8+
[html]
9+
show_contexts = True

bedevere/util.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,12 @@ async def files_for_PR(gh, pull_request):
113113
async def issue_for_PR(gh, pull_request):
114114
"""Return a dict with data about the given PR."""
115115
# "issue_url" is the API endpoint for the given pull_request (despite the name)
116-
return await gh.getitem(pull_request["issue_url"])
116+
# It could also come from "url"
117+
118+
url_key = "issue_url"
119+
if not pull_request.get(url_key):
120+
url_key = "url"
121+
return await gh.getitem(pull_request[url_key])
117122

118123

119124
def build_pr_body(issue_number: int, body: str) -> str:

tests/test_stage.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,8 +1096,8 @@ async def test_awaiting_label_not_removed_when_pr_not_merged(label):
10961096
await awaiting.router.dispatch(event, gh)
10971097
assert gh.delete_url is None
10981098

1099-
1100-
async def test_new_commit_pushed_to_approved_pr():
1099+
@pytest.mark.parametrize("issue_url_key", ["url", "issue_url"])
1100+
async def test_new_commit_pushed_to_approved_pr(issue_url_key):
11011101
# There is new commit on approved PR
11021102
username = "brettcannon"
11031103
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
@@ -1121,7 +1121,8 @@ async def test_new_commit_pushed_to_approved_pr():
11211121
"name": "awaiting merge",
11221122
},
11231123
],
1124-
"issue_url": "/repos/python/cpython/issues/5547",
1124+
# the key could be 'url' or 'issue_url'
1125+
issue_url_key: "/repos/python/cpython/issues/5547",
11251126
}
11261127
],
11271128
},
@@ -1168,8 +1169,8 @@ async def test_new_commit_pushed_to_approved_pr():
11681169
)
11691170
}
11701171

1171-
1172-
async def test_new_commit_pushed_to_not_approved_pr():
1172+
@pytest.mark.parametrize("issue_url_key", ["url", "issue_url"])
1173+
async def test_new_commit_pushed_to_not_approved_pr(issue_url_key):
11731174
# There is new commit on approved PR
11741175
sha = "f2393593c99dd2d3ab8bfab6fcc5ddee540518a9"
11751176
data = {"commits": [{"id": sha}]}
@@ -1190,7 +1191,8 @@ async def test_new_commit_pushed_to_not_approved_pr():
11901191
"name": "awaiting review",
11911192
},
11921193
],
1193-
"issue_url": "/repos/python/cpython/issues/5547",
1194+
#
1195+
issue_url_key: "/repos/python/cpython/issues/5547",
11941196
}
11951197
],
11961198
},

0 commit comments

Comments
 (0)