@@ -168,14 +168,15 @@ def query_pull_request_data_from_github(
168168
169169def 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" ,
0 commit comments