Openverse is a search engine for openly-licensed media. This monorepo includes all application code.
Always assume special urgency for contributor PR pings (#4385)
Madison Swain-Bowden28f0356b8a7a
diff --git a/catalog/dags/common/github.py b/catalog/dags/common/github.pyindex 79653fff9..1e2daead1 100644--- a/catalog/dags/common/github.py+++ b/catalog/dags/common/github.py@@ -107,3 +107,9 @@ class GitHubAPI:f"repos/{owner}/{repo}/actions/workflows/{workflow_id}/dispatches",json={"inputs": inputs or {}, "ref": ref},)++ def get_team_members(self, team: str, owner: str = "WordPress"):+ return self._make_request(+ "GET",+ f"orgs/{owner}/teams/{team}/members",+ )diff --git a/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py b/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.pyindex c73f242f5..4360ac519 100644--- a/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py+++ b/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py@@ -3,6 +3,7 @@ import loggingfrom collections import defaultdictfrom dataclasses import dataclass+from airflow.decorators import taskfrom requests import HTTPErrorfrom common.github import GitHubAPI@@ -15,6 +16,9 @@ REPOSITORIES = ["openverse","openverse-infrastructure",]+MAINTAINER_TEAM = "openverse-maintainers"+OPENVERSE_BOT = "openverse-bot"+BOT_ACCOUNTS = {OPENVERSE_BOT, "renovate", "dependabot[bot]"}class Urgency:@@ -25,11 +29,16 @@ class Urgency:CRITICAL = Urgency("critical", 1)HIGH = Urgency("high", 2)+ CONTRIBUTOR = Urgency("contributor", 3)MEDIUM = Urgency("medium", 4)LOW = Urgency("low", 5)@classmethod- def for_pr(cls, pr: dict) -> Urgency | None:+ def for_pr(cls, pr: dict, maintainers: set[str]) -> Urgency | None:+ # All contributor PRs should be treated as a special case+ if pr["user"]["login"] not in maintainers:+ return cls.CONTRIBUTOR+priority_labels = [label["name"]for label in pr["labels"]@@ -57,6 +66,14 @@ class ReviewDelta:days: int+@task+def get_maintainers(github_pat: str) -> set[str]:+ gh = GitHubAPI(github_pat)+ maintainer_info = gh.get_team_members(MAINTAINER_TEAM)+ maintainers = {member["login"] for member in maintainer_info} | BOT_ACCOUNTS+ return maintainers++def days_without_weekends(today: datetime.datetime, updated_at: datetime.datetime) -> int:@@ -80,7 +97,9 @@ def parse_gh_date(d) -> datetime.datetime:return datetime.datetime.fromisoformat(d.rstrip("Z"))-def get_urgency_if_urgent(gh: GitHubAPI, pr: dict) -> ReviewDelta | None:+def get_urgency_if_urgent(+ gh: GitHubAPI, pr: dict, maintainers: set[str]+) -> ReviewDelta | None:events = gh.get_issue_events(base_repo_name(pr), pr["number"])ready_for_review_date = pr["created_at"]for event in reversed(events):@@ -99,7 +118,7 @@ def get_urgency_if_urgent(gh: GitHubAPI, pr: dict) -> ReviewDelta | None:urgency_base_date = parse_gh_date(ready_for_review_date)today = datetime.datetime.now()- pr_urgency = Urgency.for_pr(pr)+ pr_urgency = Urgency.for_pr(pr, maintainers)if pr_urgency is None:return None@@ -192,7 +211,8 @@ def get_min_required_approvals(gh: GitHubAPI, pr: dict) -> int:]-def post_reminders(github_pat: str, dry_run: bool):+@task(task_id="pr_review_reminder_operator")+def post_reminders(maintainers: set[str], github_pat: str, dry_run: bool):gh = GitHubAPI(github_pat)open_prs = []@@ -201,7 +221,7 @@ def post_reminders(github_pat: str, dry_run: bool):urgent_prs = []for pr in open_prs:- review_delta = get_urgency_if_urgent(gh, pr)+ review_delta = get_urgency_if_urgent(gh, pr, maintainers)if review_delta:urgent_prs.append((pr, review_delta))@@ -214,7 +234,7 @@ def post_reminders(github_pat: str, dry_run: bool):commentfor comment in previous_commentsif (- comment["user"]["login"] == "openverse-bot"+ comment["user"]["login"] == OPENVERSE_BOTand COMMENT_MARKER in comment["body"])]diff --git a/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders_dag.py b/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders_dag.pyindex a97792b0b..1bc8031a1 100644--- a/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders_dag.py+++ b/catalog/dags/maintenance/pr_review_reminders/pr_review_reminders_dag.py@@ -10,9 +10,14 @@ This DAG runs daily and pings on the following schedule based on priority label:| --- | --- || critical | 1 day || high | >2 days |+| contributor | >3 days || medium | >4 days || low | >7 days |+Special consideration is made for non-maintainer PRs so that we ensure contributors+are responded to in a timely manner+[per this documentation](https://docs.openverse.org/general/contribution/good_first_and_help_wanted_issues.html#timing-and-process).+The DAG does not ping on Saturday and Sunday and accounts for weekend dayswhen determining how much time has passed since the review.@@ -24,7 +29,6 @@ is unavailable for the time period during which the PR should be reviewed.from datetime import datetime, timedeltafrom airflow.models import DAG-from airflow.operators.python import PythonOperatorfrom common.constants import DAG_DEFAULT_ARGSfrom maintenance.pr_review_reminders import pr_review_reminders@@ -32,6 +36,7 @@ from maintenance.pr_review_reminders import pr_review_remindersDAG_ID = "pr_review_reminders"MAX_ACTIVE_TASKS = 1+DEFERRED_GITHUB_PAT = "{{ var.value.get('GITHUB_API_KEY', 'not_set') }}"dag = DAG(dag_id=DAG_ID,@@ -54,12 +59,10 @@ dag = DAG()with dag:- PythonOperator(- task_id="pr_review_reminder_operator",- python_callable=pr_review_reminders.post_reminders,- op_kwargs={- "github_pat": "{{ var.value.get('GITHUB_API_KEY', 'not_set') }}",- "dry_run": "{{ var.json.get('PR_REVIEW_REMINDER_DRY_RUN', "- "var.value.ENVIRONMENT != 'production') }}",- },+ maintainers = pr_review_reminders.get_maintainers(DEFERRED_GITHUB_PAT)+ pr_review_reminders.post_reminders(+ maintainers,+ github_pat=DEFERRED_GITHUB_PAT,+ dry_run="{{ var.json.get('PR_REVIEW_REMINDER_DRY_RUN', "+ "var.value.ENVIRONMENT != 'production') }}",)diff --git a/catalog/tests/dags/maintenance/test_pr_review_reminders.py b/catalog/tests/dags/maintenance/test_pr_review_reminders.pyindex d2224af26..eb38ce4d4 100644--- a/catalog/tests/dags/maintenance/test_pr_review_reminders.py+++ b/catalog/tests/dags/maintenance/test_pr_review_reminders.py@@ -44,6 +44,8 @@ LAST_WEDNESDAY = MONDAY - timedelta(days=5)LAST_TUESDAY = MONDAY - timedelta(days=6)LAST_MONDAY = MONDAY - timedelta(days=7)+MAINTAINERS = {"helpful-contributor"}+@pytest.mark.parametrize("today, against, expected_days",@@ -239,6 +241,14 @@ parametrize_possible_pingable_events = pytest.mark.parametrize()+@parametrize_urgency+def test_urgency_respects_contributors(urgency):+ pull = make_pull(urgency, old=False)+ # Don't pass maintainers in so any author is considered a "contributor"+ actual = Urgency.for_pr(pull, set())+ assert actual == Urgency.CONTRIBUTOR++@parametrize_urgency@parametrize_possible_pingable_eventsdef test_pings_past_due(github, urgency, events):@@ -269,7 +279,7 @@ def test_pings_past_due(github, urgency, events):make_non_urgent_reviewable_events(events))- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] in github["posted_comments"]assert not_due_pull["number"] not in github["posted_comments"]@@ -311,7 +321,7 @@ def test_does_not_reping_past_due_if_reminder_is_current(github, urgency, eventsmake_non_urgent_reviewable_events(events))- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] not in github["posted_comments"]assert not_due_pull["number"] not in github["posted_comments"]@@ -347,7 +357,7 @@ def test_does_reping_past_due_if_reminder_is_outdated(github, urgency, events):make_non_urgent_reviewable_events(events))- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] in github["posted_comments"]assert not_due_pull["number"] not in github["posted_comments"]@@ -400,7 +410,7 @@ def test_does_ping_if_pr_has_less_than_min_required_approvals(github["pull_reviews"][past_due_pull["number"]] = reviewsgithub["events"][past_due_pull["number"]] = make_urgent_events(urgency, events)- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] in github["posted_comments"]@@ -438,7 +448,7 @@ def test_does_not_ping_if_pr_has_min_required_approvals(] * min_required_approvalsgithub["events"][past_due_pull["number"]] = make_urgent_events(urgency, events)- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] not in github["posted_comments"]@@ -466,7 +476,7 @@ def test_does_not_ping_if_no_reviewers(github, urgency, events):for pr in [past_due_pull, not_due_pull]:_setup_branch_protection(github, pr)- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] not in github["posted_comments"]assert not_due_pull["number"] not in github["posted_comments"]@@ -545,7 +555,7 @@ def test_ignores_created_at_and_pings_if_urgent_ready_for_review_event_exists(_setup_branch_protection(github, pull)- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert pull["number"] in github["posted_comments"]@@ -579,6 +589,6 @@ def test_falls_back_to_main_on_multiple_branch_levels(Urgency.LOW, ["review_requested"])- post_reminders("not_set", dry_run=False)+ post_reminders.function(MAINTAINERS, "not_set", dry_run=False)assert past_due_pull["number"] not in github["posted_comments"]diff --git a/catalog/tests/factories/github/team.json b/catalog/tests/factories/github/team.jsonnew file mode 100644index 000000000..311913e0b--- /dev/null+++ b/catalog/tests/factories/github/team.json@@ -0,0 +1,22 @@+[+ {+ "login": "helpful-contributor",+ "id": 0,+ "node_id": "MDQ6VXNlcjg5NTgxO222",+ "avatar_url": "https://avatars.githubusercontent.com/u/0?v=4",+ "gravatar_id": "",+ "url": "https://api.github.com/users/helpful-contributor",+ "html_url": "https://github.com/helpful-contributor",+ "followers_url": "https://api.github.com/users/helpful-contributor/followers",+ "following_url": "https://api.github.com/users/helpful-contributor/following{/other_user}",+ "gists_url": "https://api.github.com/users/helpful-contributor/gists{/gist_id}",+ "starred_url": "https://api.github.com/users/helpful-contributor/starred{/owner}{/repo}",+ "subscriptions_url": "https://api.github.com/users/helpful-contributor/subscriptions",+ "organizations_url": "https://api.github.com/users/helpful-contributor/orgs",+ "repos_url": "https://api.github.com/users/helpful-contributor/repos",+ "events_url": "https://api.github.com/users/helpful-contributor/events{/privacy}",+ "received_events_url": "https://api.github.com/users/helpful-contributor/received_events",+ "type": "User",+ "site_admin": false+ }+]diff --git a/documentation/catalog/reference/DAGs.md b/documentation/catalog/reference/DAGs.mdindex f4c841d1d..f6b934ead 100644--- a/documentation/catalog/reference/DAGs.md+++ b/documentation/catalog/reference/DAGs.md@@ -860,12 +860,17 @@ have not yet approved the PR or explicitly requested changes.This DAG runs daily and pings on the following schedule based on priority label:-| priority | days |-| -------- | ------- |-| critical | 1 day |-| high | >2 days |-| medium | >4 days |-| low | >7 days |+| priority | days |+| ----------- | ------- |+| critical | 1 day |+| high | >2 days |+| contributor | >3 days |+| medium | >4 days |+| low | >7 days |++Special consideration is made for non-maintainer PRs so that we ensure+contributors are responded to in a timely manner+[per this documentation](https://docs.openverse.org/general/contribution/good_first_and_help_wanted_issues.html#timing-and-process).The DAG does not ping on Saturday and Sunday and accounts for weekend days whendetermining how much time has passed since the review.