Skip to content

Commit 07b9737

Browse files
authored
Attempt to avoid rate limit (#156)
Use pre-existing info instead of making another API call. python/miss-islington#153
1 parent 1138fd5 commit 07b9737

File tree

2 files changed

+30
-95
lines changed

2 files changed

+30
-95
lines changed

miss_islington/status_change.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ async def check_status(event, gh, *args, **kwargs):
2727
pr_labels = pr_for_commit["labels"]
2828
if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels):
2929
await check_ci_status_and_approval(
30-
gh, sha, leave_comment=True, is_automerge=True
30+
gh,
31+
sha,
32+
pr_for_commit=pr_for_commit,
33+
leave_comment=True,
34+
is_automerge=True,
3135
)
3236

3337

@@ -39,18 +43,22 @@ async def pr_reviewed(event, gh, *args, **kwargs):
3943
if util.pr_is_automerge(pr_labels) and util.pr_is_awaiting_merge(pr_labels):
4044
sha = event.data["pull_request"]["head"]["sha"]
4145

42-
await check_ci_status_and_approval(gh, sha, is_automerge=True)
46+
await check_ci_status_and_approval(
47+
gh, sha, pr_for_commit=event.data["pull_request"], is_automerge=True
48+
)
4349
elif event.data["pull_request"]["user"][
4450
"login"
4551
] == "miss-islington" and util.pr_is_awaiting_merge(
4652
event.data["pull_request"]["labels"]
4753
):
4854
sha = event.data["pull_request"]["head"]["sha"]
49-
await check_ci_status_and_approval(gh, sha)
55+
await check_ci_status_and_approval(
56+
gh, sha, pr_for_commit=event.data["pull_request"]
57+
)
5058

5159

5260
async def check_ci_status_and_approval(
53-
gh, sha, leave_comment=False, is_automerge=False
61+
gh, sha, pr_for_commit=None, leave_comment=False, is_automerge=False
5462
):
5563

5664
result = await gh.getitem(f"/repos/python/cpython/commits/{sha}/status")
@@ -61,7 +69,8 @@ async def check_ci_status_and_approval(
6169
"pending" not in all_ci_status
6270
and "continuous-integration/travis-ci/pr" in all_ci_context
6371
):
64-
pr_for_commit = await util.get_pr_for_commit(gh, sha)
72+
if not pr_for_commit:
73+
pr_for_commit = await util.get_pr_for_commit(gh, sha)
6574
if pr_for_commit:
6675
pr_number = pr_for_commit["number"]
6776
normalized_pr_title = util.normalize_title(

tests/test_status_change.py

Lines changed: 16 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,9 @@ async def test_awaiting_merge_label_added_and_ci_passed_pr_is_merged():
204204
"user": {"login": "miss-islington"},
205205
"labels": [{"name": "awaiting merge"}, {"name": "CLA signed"}],
206206
"head": {"sha": sha},
207+
"number": 5547,
208+
"title": "[3.6] bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)",
209+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta <Mariatta@users.noreply.github.com>",
207210
},
208211
}
209212

@@ -225,21 +228,7 @@ async def test_awaiting_merge_label_added_and_ci_passed_pr_is_merged():
225228
"context": "continuous-integration/travis-ci/pr",
226229
},
227230
],
228-
},
229-
"/repos/python/cpython/pulls/5547": {
230-
"labels": [{"name": "awaiting merge"}, {"name": "CLA signed"}]
231-
},
232-
f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": {
233-
"total_count": 1,
234-
"items": [
235-
{
236-
"number": 5547,
237-
"title": "[3.6] bpo-32720: Fixed the replacement field grammar documentation. (GH-5544)",
238-
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.\n(cherry picked from commit 7a561afd2c79f63a6008843b83733911d07f0119)\n\nCo-authored-by: Mariatta <Mariatta@users.noreply.github.com>",
239-
"labels": [{"name": "awaiting merge"}, {"name": "CLA signed"}],
240-
}
241-
],
242-
},
231+
}
243232
}
244233

245234
getiter = {
@@ -1001,6 +990,9 @@ async def test_awaiting_merge_label_and_automerge_label_added_not_miss_islington
1001990
{"name": "CLA signed"},
1002991
],
1003992
"head": {"sha": sha},
993+
"number": 5547,
994+
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
995+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
1004996
},
1005997
}
1006998

@@ -1022,31 +1014,7 @@ async def test_awaiting_merge_label_and_automerge_label_added_not_miss_islington
10221014
"context": "continuous-integration/travis-ci/pr",
10231015
},
10241016
],
1025-
},
1026-
"/repos/python/cpython/pulls/5547": {
1027-
"user": {"login": "Mariatta"},
1028-
"merged_by": None,
1029-
"labels": [
1030-
{"name": "awaiting merge"},
1031-
{"name": AUTOMERGE_LABEL},
1032-
{"name": "CLA signed"},
1033-
],
1034-
},
1035-
f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": {
1036-
"total_count": 1,
1037-
"items": [
1038-
{
1039-
"number": 5547,
1040-
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
1041-
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
1042-
"labels": [
1043-
{"name": "awaiting merge"},
1044-
{"name": AUTOMERGE_LABEL},
1045-
{"name": "CLA signed"},
1046-
],
1047-
}
1048-
],
1049-
},
1017+
}
10501018
}
10511019

10521020
getiter = {"/repos/python/cpython/pulls/5547/commits": [{"sha": sha}]}
@@ -1154,6 +1122,9 @@ async def test_automerge_multi_commits_in_pr():
11541122
{"name": "CLA signed"},
11551123
],
11561124
"head": {"sha": sha},
1125+
"number": 5547,
1126+
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
1127+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
11571128
},
11581129
}
11591130

@@ -1175,31 +1146,7 @@ async def test_automerge_multi_commits_in_pr():
11751146
"context": "continuous-integration/travis-ci/pr",
11761147
},
11771148
],
1178-
},
1179-
"/repos/python/cpython/pulls/5547": {
1180-
"user": {"login": "Mariatta"},
1181-
"merged_by": None,
1182-
"labels": [
1183-
{"name": "awaiting merge"},
1184-
{"name": AUTOMERGE_LABEL},
1185-
{"name": "CLA signed"},
1186-
],
1187-
},
1188-
f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": {
1189-
"total_count": 1,
1190-
"items": [
1191-
{
1192-
"number": 5547,
1193-
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
1194-
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
1195-
"labels": [
1196-
{"name": "awaiting merge"},
1197-
{"name": AUTOMERGE_LABEL},
1198-
{"name": "CLA signed"},
1199-
],
1200-
}
1201-
],
1202-
},
1149+
}
12031150
}
12041151

12051152
getiter = {
@@ -1237,6 +1184,9 @@ async def test_automerge_commit_not_found():
12371184
{"name": "CLA signed"},
12381185
],
12391186
"head": {"sha": sha},
1187+
"number": 5547,
1188+
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
1189+
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
12401190
},
12411191
}
12421192

@@ -1258,31 +1208,7 @@ async def test_automerge_commit_not_found():
12581208
"context": "continuous-integration/travis-ci/pr",
12591209
},
12601210
],
1261-
},
1262-
"/repos/python/cpython/pulls/5547": {
1263-
"user": {"login": "Mariatta"},
1264-
"merged_by": None,
1265-
"labels": [
1266-
{"name": "awaiting merge"},
1267-
{"name": AUTOMERGE_LABEL},
1268-
{"name": "CLA signed"},
1269-
],
1270-
},
1271-
f"/search/issues?q=type:pr+repo:python/cpython+sha:{sha}": {
1272-
"total_count": 1,
1273-
"items": [
1274-
{
1275-
"number": 5547,
1276-
"title": "bpo-32720: Fixed the replacement field grammar documentation.",
1277-
"body": "\n\n`arg_name` and `element_index` are defined as `digit`+ instead of `integer`.",
1278-
"labels": [
1279-
{"name": "awaiting merge"},
1280-
{"name": AUTOMERGE_LABEL},
1281-
{"name": "CLA signed"},
1282-
],
1283-
}
1284-
],
1285-
},
1211+
}
12861212
}
12871213

12881214
getiter = {"/repos/python/cpython/pulls/5547/commits": []}

0 commit comments

Comments
 (0)