Skip to content

Commit 3674d7c

Browse files
authored
fix: limit autorelease trigger job to recent release PRs (#328)
* fix: limit autorelease trigger job to recent release PRs * docs: add comment about updating the CREATED_AFTER constant * test: fix test * test: fix test
1 parent 56a75c8 commit 3674d7c

3 files changed

Lines changed: 18 additions & 3 deletions

File tree

autorelease/github.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,16 @@ def list_org_repos(self, org: str, type: str = None) -> Generator[dict, None, No
9090
url = response.links.get("next", {}).get("url")
9191

9292
def list_org_issues(
93-
self, org: str, state: str = None, labels: str = None
93+
self, org: str, state: str = None, labels: str = None, created_after: str = None
9494
) -> Generator[dict, None, None]:
9595
url = f"{self.GITHUB_ROOT}/search/issues?q=org:{quote(org)}+state:{quote(state)}+archived:false"
9696
if labels:
9797
# Note: GitHub query API expects label to be enclosed in quotes:
9898
quotedLabels = '"' + labels + '"'
9999
url += f"+label:{quote(quotedLabels)}"
100+
if created_after:
101+
url += f"+created:>{created_after}"
102+
print(url)
100103
# GitHub sometimes returns 5xx errors for this request.
101104
# Retry after 500, 502 response up to 4 times.
102105
max_retries = Retry(status=4, status_forcelist=[500, 502])

autorelease/trigger.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@
2121
LANGUAGE_ALLOWLIST = ["java"]
2222
ORGANIZATIONS_TO_SCAN = ["googleapis", "GoogleCloudPlatform"]
2323

24+
# Whenever we add new languages to the allowlist, update this value as
25+
# well to prevent trying to release old versions.
26+
CREATED_AFTER = "2021-04-01"
27+
2428

2529
def trigger_kokoro_build_for_pull_request(
2630
kokoro_session, gh: github.GitHub, issue: dict, result
@@ -100,6 +104,8 @@ def main(github_token, kokoro_credentials) -> reporter.Reporter:
100104
state="closed",
101105
# Must be labeled with "autorelease: pending"
102106
labels="autorelease: tagged",
107+
# Only look at issues created recently
108+
created_after=CREATED_AFTER,
103109
)
104110

105111
# Just in case any non-PRs got in here.

tests/test_autorelease_trigger.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,16 @@ def test_processes_issues(
4949
list_org_issues.side_effect = [[pr1, pr2]]
5050
trigger.main("github-token", "kokoro-credentials")
5151
list_org_issues.assert_any_call(
52-
org="googleapis", state="closed", labels="autorelease: tagged"
52+
org="googleapis",
53+
state="closed",
54+
labels="autorelease: tagged",
55+
created_after="2021-04-01",
5356
)
5457
list_org_issues.assert_any_call(
55-
org="GoogleCloudPlatform", state="closed", labels="autorelease: tagged"
58+
org="GoogleCloudPlatform",
59+
state="closed",
60+
labels="autorelease: tagged",
61+
created_after="2021-04-01",
5662
)
5763
assert trigger_kokoro_build_for_pull_request.call_count == 2
5864

0 commit comments

Comments
 (0)