Skip to content

Commit 66d2f9b

Browse files
committed
Add tracking for 'stale' merged pull requests
1 parent bf00784 commit 66d2f9b

File tree

3 files changed

+38
-12
lines changed

3 files changed

+38
-12
lines changed

premerge/bigquery_schema/llvm_repository_snapshots_table_schema.json

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,15 @@
1212
"description": "The number of non-stale, open pull requests at this snapshot."
1313
},
1414
{
15-
"name": "require_post_commit_count",
15+
"name": "recent_unapproved_pull_request_count",
1616
"type": "INTEGER",
1717
"mode": "NULLABLE",
18-
"description": "The number of pull requests requiring post-commit review."
18+
"description": "The number of pull requests requiring post-commit review (merged within the last 14 days)."
19+
},
20+
{
21+
"name": "stale_unapproved_pull_request_count",
22+
"type": "INTEGER",
23+
"mode": "NULLABLE",
24+
"description": "The number of pull requests requiring post-commit review (merged between 14 an 180 days ago)."
1925
}
2026
]

premerge/ops-container/amend_pull_request_data.py

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,14 +168,15 @@ def query_pull_request_data_from_github(
168168

169169
def get_unapproved_pull_requests_from_bigquery(
170170
bq_client: bigquery.Client,
171-
cutoff_age_days: int,
171+
minimum_age_days: int,
172+
maximum_age_days: int,
172173
) -> list[int]:
173174
"""Get merged pull requests that have not yet been approved.
174175
175176
Args:
176177
bq_client: The BigQuery client to use for querying.
177-
cutoff_age_days: The number of days to look back for unreviewed pull
178-
requests.
178+
minimum_age_days: The minimum age of pull requests to query, inclusive.
179+
maximum_age_days: The maximum age of pull requests to query, exclusive.
179180
180181
Returns:
181182
A list of relevant pull request numbers
@@ -186,11 +187,16 @@ def get_unapproved_pull_requests_from_bigquery(
186187
FROM {OPERATIONAL_METRICS_DATASET}.{LLVM_PULL_REQUESTS_TABLE} AS LLVMPull
187188
WHERE
188189
LLVMPull.pull_request_state = 'MERGED'
190+
AND TIMESTAMP_DIFF(
191+
CURRENT_TIMESTAMP(),
192+
TIMESTAMP_SECONDS(LLVMPull.pull_request_timestamp_seconds),
193+
DAY
194+
) >= @minimum_age_days
189195
AND TIMESTAMP_DIFF(
190196
CURRENT_TIMESTAMP(),
191197
TIMESTAMP_SECONDS(LLVMPull.merged_at_timestamp_seconds),
192198
DAY
193-
) <= @cutoff_age_days
199+
) < @maximum_age_days
194200
AND 'reviewed-post-commit' NOT IN UNNEST(LLVMPull.labels.name)
195201
AND NOT EXISTS(
196202
SELECT 1
@@ -203,7 +209,10 @@ def get_unapproved_pull_requests_from_bigquery(
203209
job_config = bigquery.QueryJobConfig(
204210
query_parameters=[
205211
bigquery.ScalarQueryParameter(
206-
"cutoff_age_days", "INT64", cutoff_age_days
212+
"minimum_age_days", "INT64", minimum_age_days
213+
),
214+
bigquery.ScalarQueryParameter(
215+
"maximum_age_days", "INT64", maximum_age_days
207216
),
208217
],
209218
)
@@ -329,7 +338,8 @@ def update_post_commit_reviews_in_bigquery(
329338
# any more reviews.
330339
unapproved_merged_pull_requests = get_unapproved_pull_requests_from_bigquery(
331340
bq_client,
332-
cutoff_age_days=14,
341+
minimum_age_days=0,
342+
maximum_age_days=14,
333343
)
334344
pull_request_data = query_pull_request_data_from_github(
335345
unapproved_merged_pull_requests, github_token
@@ -357,10 +367,18 @@ def record_repository_snapshot_in_bigquery(
357367
datetime.datetime.now(datetime.timezone.utc).timestamp()
358368
)
359369
open_pull_request_count = len(get_open_pull_requests_from_bigquery(bq_client))
360-
require_post_commit_count = len(
370+
recent_unapproved_pull_request_count = len(
371+
get_unapproved_pull_requests_from_bigquery(
372+
bq_client,
373+
minimum_age_days=0,
374+
maximum_age_days=14,
375+
)
376+
)
377+
stale_unapproved_pull_request_count = len(
361378
get_unapproved_pull_requests_from_bigquery(
362379
bq_client,
363-
cutoff_age_days=14,
380+
minimum_age_days=14,
381+
maximum_age_days=180, # Six months.
364382
)
365383
)
366384

@@ -372,7 +390,8 @@ def record_repository_snapshot_in_bigquery(
372390
operational_metrics_lib.LLVMRepositorySnapshot(
373391
snapshot_timestamp_seconds=snapshot_timestamp_seconds,
374392
open_pull_request_count=open_pull_request_count,
375-
require_post_commit_count=require_post_commit_count,
393+
recent_unapproved_pull_request_count=recent_unapproved_pull_request_count,
394+
stale_unapproved_pull_request_count=stale_unapproved_pull_request_count,
376395
)
377396
],
378397
"snapshot_timestamp_seconds",

premerge/ops-container/operational_metrics_lib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,8 @@ class LLVMReviewData:
9696
class LLVMRepositorySnapshot:
9797
snapshot_timestamp_seconds: int
9898
open_pull_request_count: int
99-
require_post_commit_count: int
99+
recent_unapproved_pull_request_count: int
100+
stale_unapproved_pull_request_count: int
100101

101102

102103
LLVMData: TypeAlias = (

0 commit comments

Comments
 (0)