Skip to content

Openverse is a search engine for openly-licensed media. This monorepo includes all application code.

Re-ping if PR is updated and don't ping if 2 approvals exist (#642)

sarayourfriend54aee38bc94b
diff --git a/openverse_catalog/dags/common/github.py b/openverse_catalog/dags/common/github.py
index 83612b271..2ad587033 100644
--- a/openverse_catalog/dags/common/github.py
+++ b/openverse_catalog/dags/common/github.py
@@ -53,3 +53,22 @@ class GitHubAPI:
"GET",
f"repos/{owner}/{repo}/issues/{issue_number}/comments",
)
+
+ def delete_issue_comment(
+ self, repo: str, comment_id: int, owner: str = "WordPress"
+ ):
+ return self._make_request(
+ "DELETE", f"repos/{owner}/{repo}/issues/comments/{comment_id}"
+ )
+
+ def get_pull_reviews(self, repo: str, pull_number: int, owner: str = "WordPress"):
+ return self._make_request(
+ "GET",
+ f"repos/{owner}/{repo}/pulls/{pull_number}/reviews",
+ )
+
+ def get_branch_protection(self, repo: str, branch: str, owner: str = "WordPress"):
+ return self._make_request(
+ "GET",
+ f"repos/{owner}/{repo}/branches/{branch}/protection",
+ )
diff --git a/openverse_catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py b/openverse_catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py
index b10bc9b10..f042b6cb4 100644
--- a/openverse_catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py
+++ b/openverse_catalog/dags/maintenance/pr_review_reminders/pr_review_reminders.py
@@ -1,5 +1,6 @@
import datetime
import logging
+from collections import defaultdict
from dataclasses import dataclass
from typing import Optional
@@ -71,8 +72,12 @@ def days_without_weekends(today: datetime, updated_at: datetime) -> int:
return sum(1 for day in daygenerator if day.weekday() < 5)
+def parse_gh_date(d) -> datetime.datetime:
+ return datetime.datetime.fromisoformat(d.rstrip("Z"))
+
+
def get_urgency_if_urgent(pr: dict) -> Optional[ReviewDelta]:
- updated_at = datetime.datetime.fromisoformat(pr["updated_at"].rstrip("Z"))
+ updated_at = parse_gh_date(pr["updated_at"])
today = datetime.datetime.now()
urgency = pr_urgency(pr)
if urgency is None:
@@ -89,20 +94,27 @@ COMMENT_MARKER = (
COMMENT_TEMPLATE = (
- """
-Based on the {urgency_label} urgency of this PR, the following reviewers are being
+ """\
+Based on the {urgency_label} urgency of this PR, the following reviewers are being \
gently reminded to review this PR:
{user_logins}
-
"""
f"{COMMENT_MARKER}"
"""
-Ignoring weekend days, this PR was updated {days_since_update} day(s) ago. PRs
-labelled with {urgency_label} urgency are expected to be reviewed within {urgency_days}.
-@{pr_author}, if this PR is not ready for a review, please draft it to prevent reviewers
-from getting further unnecessary pings.
+Excluding weekend[^1] days, this PR was updated {days_since_update} day(s) ago. \
+PRs labelled with {urgency_label} urgency are expected to be reviewed within \
+{urgency_days} weekday(s)[^2].
+
+@{pr_author}, if this PR is not ready for a review, please draft it to \
+prevent reviewers from getting further unnecessary pings.
+
+[^1]: Specifically, Saturday and Sunday.
+[^2]: For the purpose of these reminders we treat Monday - Friday as weekdays. \
+Please note that the that generates these reminders runs at midnight \
+UTC on Monday - Friday. This means that depending on your timezone, \
+you may be pinged outside of the expected range.
"""
)
@@ -122,6 +134,27 @@ def base_repo_name(pr: dict):
return pr["base"]["repo"]["name"]
+_BRANCH_PROTECTION_CACHE = defaultdict(dict)
+
+
+def get_branch_protection(gh: GitHubAPI, pr: dict) -> dict:
+ repo = base_repo_name(pr)
+ branch_name = pr["base"]["ref"]
+ if branch_name not in _BRANCH_PROTECTION_CACHE[repo]:
+ _BRANCH_PROTECTION_CACHE[repo][branch_name] = gh.get_branch_protection(
+ repo, branch_name
+ )
+
+ return _BRANCH_PROTECTION_CACHE[repo][branch_name]
+
+
+def get_min_required_approvals(gh: GitHubAPI, pr: dict) -> int:
+ branch_protection_rules = get_branch_protection(gh, pr)
+ return branch_protection_rules["required_pull_request_reviews"][
+ "required_approving_review_count"
+ ]
+
+
def post_reminders(github_pat: str, dry_run: bool):
gh = GitHubAPI(github_pat)
@@ -138,18 +171,35 @@ def post_reminders(github_pat: str, dry_run: bool):
to_ping = []
for pr, review_delta in urgent_prs:
repo = base_repo_name(pr)
- comments = gh.get_issue_comments(repo, pr["number"])
+ previous_comments = gh.get_issue_comments(repo, pr["number"])
reminder_comments = [
comment
- for comment in comments
+ for comment in previous_comments
if (
comment["user"]["login"] == "openverse-bot"
and COMMENT_MARKER in comment["body"]
)
]
- if reminder_comments:
- # maybe in the future we re-ping in some cases?
+
+ # While this version of the DAG will only ever allow a single
+ # current reminder comment to exist, we still need to split this out
+ # so that comments left by previous iterations will still get picked
+ # up, read as current or not, and also recorded for deletion by the
+ # script so that the final step can delete all but the most recently
+ # left reminder comment.
+ current_reminder = next(
+ iter(
+ [
+ r
+ for r in reminder_comments
+ if parse_gh_date(r["created_at"]) > parse_gh_date(pr["updated_at"])
+ ]
+ ),
+ None,
+ )
+
+ if current_reminder:
continue
if pr["requested_reviewers"] == []:
@@ -157,14 +207,30 @@ def post_reminders(github_pat: str, dry_run: bool):
# the PR author or the whole openverse maintainers team?
continue
- to_ping.append((pr, review_delta))
+ existing_reviews = gh.get_pull_reviews(base_repo_name(pr), pr["number"])
+
+ approved_reviews = [r for r in existing_reviews if r["state"] == "APPROVED"]
+ if len(approved_reviews) >= get_min_required_approvals(gh, pr):
+ # if PR already has sufficient reviews to be merged, do not ping
+ # the requested reviewers.
+ continue
+
+ to_ping.append(
+ (
+ pr,
+ review_delta,
+ reminder_comments,
+ )
+ )
- for pr, review_delta in to_ping:
+ for pr, review_delta, previous_comments in to_ping:
user_handles, comment_body = build_comment(review_delta, pr)
logger.info(f"Pinging {', '.join(user_handles)} to review {pr['title']}")
if not dry_run:
gh.post_issue_comment(base_repo_name(pr), pr["number"], comment_body)
+ for comment in previous_comments:
+ gh.delete_issue_comment(base_repo_name(pr), comment["id"])
if dry_run:
logger.info(
diff --git a/tests/dags/maintenance/test_pr_review_reminders.py b/tests/dags/maintenance/test_pr_review_reminders.py
index 9f1bb5484..ee687bd5e 100644
--- a/tests/dags/maintenance/test_pr_review_reminders.py
+++ b/tests/dags/maintenance/test_pr_review_reminders.py
@@ -8,7 +8,15 @@ from openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders
days_without_weekends,
post_reminders,
)
-from tests.factories.github import make_pr_comment, make_pull, make_requested_reviewer
+from tests.factories.github import (
+ make_branch_protection,
+ make_current_pr_comment,
+ make_outdated_pr_comment,
+ make_pr_comment,
+ make_pull,
+ make_requested_reviewer,
+ make_review,
+)
MONDAY = datetime(2022, 6, 13)
@@ -65,6 +73,9 @@ def github(monkeypatch):
pulls = []
pull_comments = defaultdict(list)
posted_comments = defaultdict(list)
+ deleted_comments = []
+ pull_reviews = defaultdict(list)
+ branch_protection = defaultdict(dict)
def get_prs(*args, **kwargs):
return pulls
@@ -78,23 +89,39 @@ def github(monkeypatch):
body = args[3]
posted_comments[pr_number].append(body)
- monkeypatch.setattr(
- "openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders.GitHubAPI.get_open_prs",
- get_prs,
- )
- monkeypatch.setattr(
- "openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders.GitHubAPI.get_issue_comments",
- get_comments,
- )
- monkeypatch.setattr(
- "openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders.GitHubAPI.post_issue_comment",
- post_comment,
- )
+ def delete_comment(*args, **kwargs):
+ comment_number = args[2]
+ deleted_comments.append(comment_number)
+
+ def get_reviews(*args, **kwargs):
+ pr_number = args[2]
+ return pull_reviews[pr_number]
+
+ def get_branch_protection(*args, **kwargs):
+ repo = args[1]
+ branch = args[2]
+ return branch_protection[repo][branch]
+
+ def patch_gh_fn(fn, impl):
+ monkeypatch.setattr(
+ f"openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders.GitHubAPI.{fn}",
+ impl,
+ )
+
+ patch_gh_fn("get_open_prs", get_prs)
+ patch_gh_fn("get_issue_comments", get_comments)
+ patch_gh_fn("post_issue_comment", post_comment)
+ patch_gh_fn("delete_issue_comment", delete_comment)
+ patch_gh_fn("get_pull_reviews", get_reviews)
+ patch_gh_fn("get_branch_protection", get_branch_protection)
yield {
"pulls": pulls,
"pull_comments": pull_comments,
"posted_comments": posted_comments,
+ "deleted_comments": deleted_comments,
+ "pull_reviews": pull_reviews,
+ "branch_protection": branch_protection,
}
@@ -103,7 +130,16 @@ def freeze_friday(freeze_time):
freeze_time.freeze(FRIDAY)
+def _setup_branch_protection(github: dict, pr: dict, min_required_approvals: int = 2):
+ branch_protection = make_branch_protection(min_required_approvals)
+
+ repo = pr["base"]["repo"]["name"]
+ branch = pr["base"]["ref"]
+
+ github["branch_protection"][repo][branch] = branch_protection
+
+
+parametrize_urgency = pytest.mark.parametrize(
"urgency",
(
Urgency.CRITICAL,
@@ -112,6 +148,9 @@ def freeze_friday(freeze_time):
Urgency.LOW,
),
)
+
+
+@parametrize_urgency
def test_pings_past_due(github, urgency):
past_due_pull = make_pull(urgency, past_due=True)
past_due_pull["requested_reviewers"] = [
@@ -121,6 +160,10 @@ def test_pings_past_due(github, urgency):
not_due_pull["requested_reviewers"] = [
make_requested_reviewer(f"reviewer-not-due-{i}") for i in range(2)
]
+
+ for pr in [past_due_pull, not_due_pull]:
+ _setup_branch_protection(github, pr)
+
github["pulls"] += [past_due_pull, not_due_pull]
github["pull_comments"][past_due_pull["number"]].append(
make_pr_comment(is_reminder=False)
@@ -137,16 +180,8 @@ def test_pings_past_due(github, urgency):
assert f"@{reviewer['login']}" in comment
- "urgency",
- (
- Urgency.CRITICAL,
- Urgency.HIGH,
- Urgency.MEDIUM,
- Urgency.LOW,
- ),
-)
-def test_does_not_reping_past_due(github, urgency):
+@parametrize_urgency
+def test_does_not_reping_past_due_if_reminder_is_current(github, urgency):
past_due_pull = make_pull(urgency, past_due=True)
past_due_pull["requested_reviewers"] = [
make_requested_reviewer(f"reviewer-due-{i}") for i in range(2)
@@ -155,9 +190,13 @@ def test_does_not_reping_past_due(github, urgency):
not_due_pull["requested_reviewers"] = [
make_requested_reviewer(f"reviewer-not-due-{i}") for i in range(2)
]
+
+ for pr in [past_due_pull, not_due_pull]:
+ _setup_branch_protection(github, pr)
+
github["pulls"] += [past_due_pull, not_due_pull]
github["pull_comments"][past_due_pull["number"]].append(
- make_pr_comment(is_reminder=True)
+ make_current_pr_comment(past_due_pull)
)
post_reminders("not_set", dry_run=False)
@@ -166,15 +205,101 @@ def test_does_not_reping_past_due(github, urgency):
assert not_due_pull["number"] not in github["posted_comments"]
+@parametrize_urgency
+def test_does_reping_past_due_if_reminder_is_outdated(github, urgency):
+ past_due_pull = make_pull(urgency, past_due=True)
+ past_due_pull["requested_reviewers"] = [
+ make_requested_reviewer(f"reviewer-due-{i}") for i in range(2)
+ ]
+ not_due_pull = make_pull(urgency, past_due=False)
+ not_due_pull["requested_reviewers"] = [
+ make_requested_reviewer(f"reviewer-not-due-{i}") for i in range(2)
+ ]
+
+ for pr in [past_due_pull, not_due_pull]:
+ _setup_branch_protection(github, pr)
+
+ github["pulls"] += [past_due_pull, not_due_pull]
+ reminder_comment = make_outdated_pr_comment(past_due_pull)
+ github["pull_comments"][past_due_pull["number"]].append(reminder_comment)
+
+ post_reminders("not_set", dry_run=False)
+
+ assert past_due_pull["number"] in github["posted_comments"]
+ assert not_due_pull["number"] not in github["posted_comments"]
+ assert reminder_comment["id"] in github["deleted_comments"]
+
+
+UNAPPROVED_REVIEW_STATES = ("CHANGES_REQUESTED", "COMMENTED")
+
+
+@parametrize_urgency
@pytest.mark.parametrize(
- "urgency",
- (
- Urgency.CRITICAL,
- Urgency.HIGH,
- Urgency.MEDIUM,
- Urgency.LOW,
- ),
+ "first_review_state",
+ # None represents not having a review so we can test the
+ # one review state.
+ (None,) + UNAPPROVED_REVIEW_STATES,
+)
+ "second_review_state",
+ # No none here otherwise we'd duplicate the single review states
+ # and we don't need to test the "no review" state because that's
+ # tested elsewhere.
+ ("APPROVED",) + UNAPPROVED_REVIEW_STATES,
)
+def test_does_ping_if_pr_has_less_than_min_required_approvals(
+ github, urgency, first_review_state, second_review_state
+):
+ reviews = [
+ make_review(state)
+ for state in (first_review_state, second_review_state)
+ if state is not None
+ ]
+ past_due_pull = make_pull(urgency, past_due=True)
+ past_due_pull["requested_reviewers"] = [
+ make_requested_reviewer(f"reviewer-due-{i}") for i in range(2)
+ ]
+
+ _setup_branch_protection(
+ github,
+ pr=past_due_pull,
+ min_required_approvals=2,
+ )
+
+ github["pulls"] += [past_due_pull]
+ github["pull_reviews"][past_due_pull["id"]] = reviews
+
+ post_reminders("not_set", dry_run=False)
+
+ assert past_due_pull["number"] in github["posted_comments"]
+
+
+@parametrize_urgency
+def test_does_not_ping_if_pr_has_min_required_approvals(github, urgency):
+ past_due_pull = make_pull(urgency, past_due=True)
+ past_due_pull["requested_reviewers"] = [
+ make_requested_reviewer(f"reviewer-due-{i}") for i in range(2)
+ ]
+
+ min_required_approvals = 4
+
+ _setup_branch_protection(
+ github,
+ pr=past_due_pull,
+ min_required_approvals=min_required_approvals,
+ )
+
+ github["pulls"] += [past_due_pull]
+ github["pull_reviews"][past_due_pull["id"]] = [
+ make_review("APPROVED"),
+ ] * min_required_approvals
+
+ post_reminders("not_set", dry_run=False)
+
+ assert past_due_pull["number"] not in github["posted_comments"]
+
+
+@parametrize_urgency
def test_does_not_ping_if_no_reviewers(github, urgency):
past_due_pull = make_pull(urgency, past_due=True)
past_due_pull["requested_reviewers"] = []
@@ -185,6 +310,9 @@ def test_does_not_ping_if_no_reviewers(github, urgency):
make_pr_comment(is_reminder=False)
)
+ for pr in [past_due_pull, not_due_pull]:
+ _setup_branch_protection(github, pr)
+
post_reminders("not_set", dry_run=False)
assert past_due_pull["number"] not in github["posted_comments"]
diff --git a/tests/factories/github/__init__.py b/tests/factories/github/__init__.py
index 530305ce9..1435a9f18 100644
--- a/tests/factories/github/__init__.py
+++ b/tests/factories/github/__init__.py
@@ -1,10 +1,12 @@
import datetime
import json
from pathlib import Path
+from typing import Literal, Optional
from openverse_catalog.dags.maintenance.pr_review_reminders.pr_review_reminders import (
COMMENT_MARKER,
Urgency,
+ parse_gh_date,
)
@@ -17,6 +19,10 @@ def _make_label(priority: Urgency) -> dict:
return {"name": f"priority: {priority.label}"}
+def _gh_date(d: datetime.datetime) -> str:
+ return f"{d.isoformat()}Z"
+
+
def walk_backwards_in_time_until_weekday_count(today: datetime.datetime, count: int):
test_date = today
weekday_count = 0
@@ -61,7 +67,7 @@ def make_pull(urgency: Urgency, past_due: bool) -> dict:
else:
updated_at = datetime.datetime.now()
- pull["updated_at"] = f"{updated_at.isoformat()}Z"
+ pull["updated_at"] = _gh_date(updated_at)
return pull
@@ -74,8 +80,17 @@ def make_requested_reviewer(login: str) -> dict:
return requested_reviewer
-def make_pr_comment(is_reminder: bool) -> dict:
+_comment_count = 1
+
+
+def make_pr_comment(
+ is_reminder: bool, created_at: Optional[datetime.datetime] = None
+) -> dict:
+ global _comment_count
+
comment = _read_fixture("comment")
+ comment["id"] = _comment_count
+ _comment_count += 1
if is_reminder:
comment["user"]["login"] = "openverse-bot"
@@ -90,6 +105,9 @@ def make_pr_comment(is_reminder: bool) -> dict:
)
)
+ if created_at:
+ comment["created_at"] = _gh_date(created_at)
+
return comment
@@ -99,3 +117,33 @@ def make_issue(state: str) -> dict:
issue["state"] = state
return issue
+
+
+def make_current_pr_comment(pull: dict) -> dict:
+ return make_pr_comment(
+ True, parse_gh_date(pull["updated_at"]) + datetime.timedelta(minutes=1)
+ )
+
+
+def make_outdated_pr_comment(pull: dict) -> dict:
+ return make_pr_comment(
+ True, parse_gh_date(pull["updated_at"]) - datetime.timedelta(minutes=1)
+ )
+
+
+def make_review(state: Literal["APPROVED", "CHANGES_REQUESTED", "COMMENTED"]):
+ review = _read_fixture("review")
+
+ review["state"] = state
+
+ return review
+
+
+def make_branch_protection(required_reviewers: int = 2) -> dict:
+ branch_protection = _read_fixture("branch_protection")
+
+ branch_protection["required_pull_request_reviews"][
+ "required_approving_review_count"
+ ] = required_reviewers
+
+ return branch_protection
diff --git a/tests/factories/github/branch_protection.json b/tests/factories/github/branch_protection.json
new file mode 100644
index 000000000..b531fc2b8
--- /dev/null
+++ b/tests/factories/github/branch_protection.json
@@ -0,0 +1,194 @@
+{
+ "allow_deletions": {
+ "enabled": true
+ },
+ "allow_force_pushes": {
+ "enabled": true
+ },
+ "enforce_admins": {
+ "enabled": true,
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/enforce_admins"
+ },
+ "required_conversation_resolution": {
+ "enabled": true
+ },
+ "required_linear_history": {
+ "enabled": true
+ },
+ "required_pull_request_reviews": {
+ "dismiss_stale_reviews": true,
+ "dismissal_restrictions": {
+ "apps": [
+ {
+ "created_at": "2017-07-08T16:18:44-04:00",
+ "description": "",
+ "events": [
+ "push",
+ "pull_request"
+ ],
+ "external_url": "https://example.com",
+ "html_url": "https://github.com/apps/octoapp",
+ "id": 1,
+ "name": "Octocat App",
+ "node_id": "MDExOkludGVncmF0aW9uMQ==",
+ "owner": {
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "description": "A great organization",
+ "events_url": "https://api.github.com/orgs/github/events",
+ "hooks_url": "https://api.github.com/orgs/github/hooks",
+ "id": 1,
+ "issues_url": "https://api.github.com/orgs/github/issues",
+ "login": "github",
+ "members_url": "https://api.github.com/orgs/github/members{/member}",
+ "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
+ "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
+ "repos_url": "https://api.github.com/orgs/github/repos",
+ "url": "https://api.github.com/orgs/github"
+ },
+ "permissions": {
+ "contents": "read",
+ "issues": "write",
+ "metadata": "read",
+ "single_file": "write"
+ },
+ "slug": "octoapp",
+ "updated_at": "2017-07-08T16:18:44-04:00"
+ }
+ ],
+ "teams": [
+ {
+ "description": "A great team.",
+ "html_url": "https://github.com/orgs/github/teams/justice-league",
+ "id": 1,
+ "members_url": "https://api.github.com/teams/1/members{/member}",
+ "name": "Justice League",
+ "node_id": "MDQ6VGVhbTE=",
+ "parent": null,
+ "permission": "admin",
+ "privacy": "closed",
+ "repositories_url": "https://api.github.com/teams/1/repos",
+ "slug": "justice-league",
+ "url": "https://api.github.com/teams/1"
+ }
+ ],
+ "teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/teams",
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions",
+ "users": [
+ {
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
+ "followers_url": "https://api.github.com/users/octocat/followers",
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/octocat",
+ "id": 1,
+ "login": "octocat",
+ "node_id": "MDQ6VXNlcjE=",
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
+ "repos_url": "https://api.github.com/users/octocat/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
+ "type": "User",
+ "url": "https://api.github.com/users/octocat"
+ }
+ ],
+ "users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/dismissal_restrictions/users"
+ },
+ "require_code_owner_reviews": true,
+ "required_approving_review_count": 2,
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_pull_request_reviews"
+ },
+ "required_status_checks": {
+ "contexts": [
+ "continuous-integration/travis-ci"
+ ],
+ "contexts_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks/contexts",
+ "enforcement_level": "non_admins",
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/required_status_checks"
+ },
+ "restrictions": {
+ "apps": [
+ {
+ "created_at": "2017-07-08T16:18:44-04:00",
+ "description": "",
+ "events": [
+ "push",
+ "pull_request"
+ ],
+ "external_url": "https://example.com",
+ "html_url": "https://github.com/apps/octoapp",
+ "id": 1,
+ "name": "Octocat App",
+ "node_id": "MDExOkludGVncmF0aW9uMQ==",
+ "owner": {
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "description": "A great organization",
+ "events_url": "https://api.github.com/orgs/github/events",
+ "hooks_url": "https://api.github.com/orgs/github/hooks",
+ "id": 1,
+ "issues_url": "https://api.github.com/orgs/github/issues",
+ "login": "github",
+ "members_url": "https://api.github.com/orgs/github/members{/member}",
+ "node_id": "MDEyOk9yZ2FuaXphdGlvbjE=",
+ "public_members_url": "https://api.github.com/orgs/github/public_members{/member}",
+ "repos_url": "https://api.github.com/orgs/github/repos",
+ "url": "https://api.github.com/orgs/github"
+ },
+ "permissions": {
+ "contents": "read",
+ "issues": "write",
+ "metadata": "read",
+ "single_file": "write"
+ },
+ "slug": "octoapp",
+ "updated_at": "2017-07-08T16:18:44-04:00"
+ }
+ ],
+ "apps_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/apps",
+ "teams": [
+ {
+ "description": "A great team.",
+ "html_url": "https://github.com/orgs/github/teams/justice-league",
+ "id": 1,
+ "members_url": "https://api.github.com/teams/1/members{/member}",
+ "name": "Justice League",
+ "node_id": "MDQ6VGVhbTE=",
+ "parent": null,
+ "permission": "admin",
+ "privacy": "closed",
+ "repositories_url": "https://api.github.com/teams/1/repos",
+ "slug": "justice-league",
+ "url": "https://api.github.com/teams/1"
+ }
+ ],
+ "teams_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/teams",
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions",
+ "users": [
+ {
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
+ "events_url": "https://api.github.com/users/octocat/events{/privacy}",
+ "followers_url": "https://api.github.com/users/octocat/followers",
+ "following_url": "https://api.github.com/users/octocat/following{/other_user}",
+ "gists_url": "https://api.github.com/users/octocat/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/octocat",
+ "id": 1,
+ "login": "octocat",
+ "node_id": "MDQ6VXNlcjE=",
+ "organizations_url": "https://api.github.com/users/octocat/orgs",
+ "received_events_url": "https://api.github.com/users/octocat/received_events",
+ "repos_url": "https://api.github.com/users/octocat/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/octocat/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/octocat/subscriptions",
+ "type": "User",
+ "url": "https://api.github.com/users/octocat"
+ }
+ ],
+ "users_url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection/restrictions/users"
+ },
+ "url": "https://api.github.com/repos/octocat/Hello-World/branches/master/protection"
+}
diff --git a/tests/factories/github/comment.json b/tests/factories/github/comment.json
index 7c1ea0b02..edfaeca25 100644
--- a/tests/factories/github/comment.json
+++ b/tests/factories/github/comment.json
@@ -1,11 +1,11 @@
{
"author_association": "NONE",
- "body": "**API Developer Docs Preview**: _Ready_\n\n<https://wordpress.github.io/openverse-api/_preview/763>\n\nPlease note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.\n\nYou can check [the GitHub pages deployment action list](https://github.com/WordPress/openverse-api/actions/workflows/pages/pages-build-deployment) to see the current status of the deployments.",
+ "body": "**API Developer Docs Preview**: _Ready_\n\n<https://wordpress.github.io/openverse-api/_preview/0>\n\nPlease note that GitHub pages takes a little time to deploy newly pushed code, if the links above don't work or you see old versions, wait 5 minutes and try again.\n\nYou can check [the GitHub pages deployment action list](https://github.com/WordPress/openverse-api/actions/workflows/pages/pages-build-deployment) to see the current status of the deployments.",
"created_at": "2022-06-20T23:10:10Z",
- "html_url": "https://github.com/WordPress/openverse-api/pull/763#issuecomment-1160936954",
- "id": 1160936954,
- "issue_url": "https://api.github.com/repos/WordPress/openverse-api/issues/763",
- "node_id": "IC_kwDOFSZ4Yc5FMn36",
+ "html_url": "https://github.com/WordPress/openverse-api/pull/0#issuecomment-0",
+ "id": 0,
+ "issue_url": "https://api.github.com/repos/WordPress/openverse-api/issues/0",
+ "node_id": "0",
"performed_via_github_app": null,
"reactions": {
"+1": 0,
@@ -17,10 +17,10 @@
"laugh": 0,
"rocket": 0,
"total_count": 0,
- "url": "https://api.github.com/repos/WordPress/openverse-api/issues/comments/1160936954/reactions"
+ "url": "https://api.github.com/repos/WordPress/openverse-api/issues/comments/0/reactions"
},
"updated_at": "2022-06-20T23:11:40Z",
- "url": "https://api.github.com/repos/WordPress/openverse-api/issues/comments/1160936954",
+ "url": "https://api.github.com/repos/WordPress/openverse-api/issues/comments/0",
"user": {
"avatar_url": "https://avatars.githubusercontent.com/in/15368?v=4",
"events_url": "https://api.github.com/users/github-actions%5Bbot%5D/events{/privacy}",
diff --git a/tests/factories/github/pull.json b/tests/factories/github/pull.json
index 17d21918e..12396b66d 100644
--- a/tests/factories/github/pull.json
+++ b/tests/factories/github/pull.json
@@ -1,25 +1,25 @@
{
"_links": {
"comments": {
- "href": "https://api.github.com/repos/WordPress/openverse-frontend/issues/1234598237459283745/comments"
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/issues/0/comments"
},
"commits": {
- "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745/commits"
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0/commits"
},
"html": {
- "href": "https://github.com/WordPress/openverse-frontend/pull/1234598237459283745"
+ "href": "https://github.com/WordPress/openverse-frontend/pull/0"
},
"issue": {
- "href": "https://api.github.com/repos/WordPress/openverse-frontend/issues/1234598237459283745"
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/issues/0"
},
"review_comment": {
"href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/comments{/number}"
},
"review_comments": {
- "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745/comments"
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0/comments"
},
"self": {
- "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745"
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0"
},
"statuses": {
"href": "https://api.github.com/repos/WordPress/openverse-frontend/statuses/asdfasdfasdfasdfasdfasdfasdf"
@@ -170,10 +170,10 @@
},
"body": "## Fixes\r\nFixes #437498349234 by @reporter",
"closed_at": null,
- "comments_url": "https://api.github.com/repos/WordPress/openverse-frontend/issues/1234598237459283745/comments",
- "commits_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745/commits",
+ "comments_url": "https://api.github.com/repos/WordPress/openverse-frontend/issues/0/comments",
+ "commits_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0/commits",
"created_at": "2022-03-30T05:41:16Z",
- "diff_url": "https://github.com/WordPress/openverse-frontend/pull/1234598237459283745.diff",
+ "diff_url": "https://github.com/WordPress/openverse-frontend/pull/0.diff",
"draft": false,
"head": {
"label": "helpful-contributor:super-sweet-feature-branch",
@@ -304,9 +304,9 @@
"url": "https://api.github.com/users/helpful-contributor"
}
},
- "html_url": "https://github.com/WordPress/openverse-frontend/pull/1234598237459283745",
+ "html_url": "https://github.com/WordPress/openverse-frontend/pull/0",
"id": 123412341234,
- "issue_url": "https://api.github.com/repos/WordPress/openverse-frontend/issues/1234598237459283745",
+ "issue_url": "https://api.github.com/repos/WordPress/openverse-frontend/issues/0",
"labels": [
{
"color": "ffcc00",
@@ -341,17 +341,17 @@
"merged_at": null,
"milestone": null,
"node_id": "PR_asdfasdfasdfasdfasdfasdf",
- "number": 1234598237459283745,
- "patch_url": "https://github.com/WordPress/openverse-frontend/pull/1234598237459283745.patch",
+ "number": 0,
+ "patch_url": "https://github.com/WordPress/openverse-frontend/pull/0.patch",
"requested_reviewers": [],
"requested_teams": [],
"review_comment_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/comments{/number}",
- "review_comments_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745/comments",
+ "review_comments_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0/comments",
"state": "open",
"statuses_url": "https://api.github.com/repos/WordPress/openverse-frontend/statuses/asdfasdfasdfasdfasdfasdfasdf",
"title": "Super cool PR to add amazing new features.",
"updated_at": "2022-06-16T11:57:28Z",
- "url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/1234598237459283745",
+ "url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0",
"user": {
"avatar_url": "https://avatars.githubusercontent.com/u/0?v=4",
"events_url": "https://api.github.com/users/helpful-contributor/events{/privacy}",
diff --git a/tests/factories/github/review.json b/tests/factories/github/review.json
new file mode 100644
index 000000000..ab28c9ec8
--- /dev/null
+++ b/tests/factories/github/review.json
@@ -0,0 +1,39 @@
+{
+ "_links": {
+ "html": {
+ "href": "https://github.com/WordPress/openverse-frontend/pull/0#pullrequestreview-0"
+ },
+ "pull_request": {
+ "href": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0"
+ }
+ },
+ "author_association": "MEMBER",
+ "body": "el gee tee em",
+ "commit_id": "702248899a81326c7b59585cc90d46dbbbaa6487465707fb27",
+ "html_url": "https://github.com/WordPress/openverse-frontend/pull/0#pullrequestreview-0",
+ "id": -1002,
+ "node_id": "PRR_kwDOFSZ5Dc40UYT5",
+ "pull_request_url": "https://api.github.com/repos/WordPress/openverse-frontend/pulls/0",
+ "state": "APPROVED",
+ "submitted_at": "2022-02-09T16:43:51Z",
+ "user": {
+ "avatar_url": "https://avatars.githubusercontent.com/u/-1?&v=4",
+ "events_url": "https://api.github.com/users/very-cool-reviewer/events{/privacy}",
+ "followers_url": "https://api.github.com/users/very-cool-reviewer/followers",
+ "following_url": "https://api.github.com/users/very-cool-reviewer/following{/other_user}",
+ "gists_url": "https://api.github.com/users/very-cool-reviewer/gists{/gist_id}",
+ "gravatar_id": "",
+ "html_url": "https://github.com/very-cool-reviewer",
+ "id": -1,
+ "login": "very-cool-reviewer",
+ "node_id": "abc1234=",
+ "organizations_url": "https://api.github.com/users/very-cool-reviewer/orgs",
+ "received_events_url": "https://api.github.com/users/very-cool-reviewer/received_events",
+ "repos_url": "https://api.github.com/users/very-cool-reviewer/repos",
+ "site_admin": false,
+ "starred_url": "https://api.github.com/users/very-cool-reviewer/starred{/owner}{/repo}",
+ "subscriptions_url": "https://api.github.com/users/very-cool-reviewer/subscriptions",
+ "type": "User",
+ "url": "https://api.github.com/users/very-cool-reviewer"
+ }
+}