Skip to content

:hedgehog: PostHog is the leading platform for building self-driving products. Our developer tools – AI observability, analytics, session replay, flags, experiments, error tracking, logs, and more – capture all the context agents need to diagnose problems, uncover opportunities, and ship fixes. Steer it all from Slack, web, desktop, or the MCP.

fix(signals): put one responsible individual on every self-driving pr (#102787)

Julian Bez2ed116da959d
diff --git a/products/signals/ARCHITECTURE.md b/products/signals/ARCHITECTURE.md
index 12bc1d6d0844..b48f001d4247 100644
--- a/products/signals/ARCHITECTURE.md
+++ b/products/signals/ARCHITECTURE.md
@@ -1290,16 +1290,26 @@ An irreversible end closes the tracker issue: a resolve asked for through the st
**One DRI per pull request** (`backend/reviewer_pr_assignment.py`).
-Every self-driving pull request opens with no assignee, so it never reaches a GitHub "Assigned to me" view. `schedule_reviewer_pr_assignment` runs when a pull request first reaches a report and applies two rules on a worker:
+Every self-driving pull request opens with no assignee, so it never reaches a GitHub "Assigned to me" view. `schedule_reviewer_pr_assignment` runs when a pull request first reaches a report, and assigns on a worker.
-- A suggested reviewer who turned on `SignalUserAutonomyConfig.github_assign_on_pull_request` is always added.
-- A pull request that nobody assigned by hand gets exactly one directly responsible individual (DRI), unless an opted-in reviewer already owns it. An opted-in reviewer owns it only as the claimant or as a member of the owning team, because a reviewer who opted in is often suggested for other teams' code too. The claimant of the report comes first (for a task claim, the user who started the task). The next candidates come from one of two sources:
- - When the repository declares its ownership in `owners.yaml` files, the candidates are the members of the GitHub team that owns most of the changed files, in random order (`backend/pr_owning_team.py`). The engineering analytics facade (`resolve_path_owners`) resolves the team. GitHub teams are the canonical team identity, so the team members come from GitHub's team members API. That call needs the organization members read permission on the GitHub app.
- - Otherwise, or when that team has no candidate, the candidates are the suggested reviewers in rank order.
+> **At assignment time, select exactly one human responsible for the pull request. Explicit human intent wins; otherwise derive a DRI. Machine-generated claims never participate in that decision.**
- A candidate must be an organization member with a connected GitHub account. Each candidate is checked with GitHub's read-only assignee check first, because the add-assignees call drops a login without push access instead of failing. A candidate GitHub cannot assign moves the walk to the next one, for up to four checks, and a failed check stops it.
+This governs what the rule adds. Nobody is ever unassigned, so a person can still assign three people by hand.
-The DRI rule is involuntary on purpose. A pull request that several people could pick up diffuses responsibility, and a wrong owner costs one reassignment. It rolls out per organization behind the `signals-pr-dri-assignee` flag. Assignment is additive: nobody is unassigned, and a pull request somebody already assigned gets no DRI. A pull request that somebody ever unassigned by hand gets no DRI either, because a later report event must not undo that decision. When the result of the opted-in assignment call is unknown (a request that failed in transit), no DRI is added on top of it.
+"Assignee" here means GitHub's assignee, the person responsible. GitHub's other field, the requested reviewer, is never written by this code — a separate app requests the owning team for review, which is why both appear on these pull requests.
+
+Under the `signals-pr-dri-assignee` flag, the candidates are, most responsible first:
+
+1. **The person who chose the work.** A claim a person made, or one their agent made for them, since an agent claim records the person it ran as. A task claim does not count: an auto-started report is claimed by its own implementation task, and that task runs as the report's top suggested reviewer, so it names a commit-history guess rather than a decision.
+2. **Somebody who asked to be assigned** through `SignalUserAutonomyConfig.github_assign_on_pull_request`. Where several did, the one who owns the changed code wins, else the highest-ranked suggested reviewer among them.
+3. **A member of the team that owns the changed files**, when the repository declares ownership in `owners.yaml` (`backend/pr_owning_team.py`). A member the report already suggests comes first, because they touched this code; the rest follow in random order. The engineering analytics facade (`resolve_path_owners`) resolves the team. GitHub teams are the canonical team identity, so the members come from GitHub's team members API, which needs the organization members read permission on the GitHub app.
+4. **The suggested reviewers in rank order**, when no ownership source names a team.
+
+A candidate must be an organization member with a connected GitHub account. Each is checked with GitHub's read-only assignee check first, because the add-assignees call drops a login without push access instead of failing. A candidate GitHub cannot assign moves the walk to the next one, for up to four checks, and a failed check stops it. A report with no candidate at all gets no DRI.
+
+A pull request that already has an assignee is left alone, and so is one that somebody ever unassigned by hand, because a later report event must not undo that decision.
+
+Without the flag the older rule stands: every suggested reviewer who opted in is added as an assignee, and there is no DRI.
> [!WARNING]
> Keep the `signals-pr-dri-assignee` flag on the PostHog organization only until a team-level off switch exists in the inbox settings. Assigning people on a customer's GitHub is that team's decision, and today a team cannot turn the rule off: removing `owners.yaml` only changes who gets picked.
diff --git a/products/signals/backend/reviewer_pr_assignment.py b/products/signals/backend/reviewer_pr_assignment.py
index cc17b86152b9..5a85e19b3b7e 100644
--- a/products/signals/backend/reviewer_pr_assignment.py
+++ b/products/signals/backend/reviewer_pr_assignment.py
@@ -1,16 +1,19 @@
"""Put a person on a report's implementation PR as its GitHub assignee.
-A reviewer whose workflow is GitHub's "Assigned to me" never sees an inbox PR otherwise, because
-every self-driving pull request opens with no assignee. Two rules add assignees:
-
-- A suggested reviewer who opted in through `SignalUserAutonomyConfig.github_assign_on_pull_request`
- is always added.
-- A pull request that still has no assignee after that gets exactly one directly responsible
- individual (DRI): the person who claimed the report, else a random member of the GitHub team that
- owns the changed files (see `pr_owning_team.py`), else the most relevant suggested reviewer.
- A pull request that everybody could pick up is a pull request nobody picks up, and a wrong
- owner costs one reassignment. The `signals-pr-dri-assignee` flag rolls this rule out per
- organization.
+Somebody whose workflow is GitHub's "Assigned to me" never sees an inbox PR otherwise, because
+every self-driving pull request opens with no assignee.
+
+Under the `signals-pr-dri-assignee` flag, a pull request with no assignee gets exactly one
+directly responsible individual (DRI): the person who chose the work, else somebody who asked to
+be assigned, else a member of the team that owns the changed code (see `pr_owning_team.py`), else
+the most relevant suggested reviewer. A pull request that everybody could pick up is a pull request
+nobody picks up, and a wrong owner costs one reassignment.
+
+Without the flag the older rule stands: every suggested reviewer who opted in through
+`SignalUserAutonomyConfig.github_assign_on_pull_request` is added, and there is no DRI.
+
+Reviewers, in GitHub's sense of a review request, are never written here. This module only ever
+writes assignees.
Best effort throughout: a GitHub failure must never break the claim, sync, or reviewer edit that
triggered it.
@@ -20,18 +23,22 @@ from __future__ import annotations
import json
from typing import Any
+from uuid import UUID
from django.conf import settings
from django.db import transaction
import structlog
+from pydantic import ValidationError
from posthog.models import Team
from posthog.models.github_integration_base import PullRequestRef
from posthog.models.integration import GitHubIntegration
from posthog.ph_client import feature_enabled_or_false
+from products.signals.backend.artefact_schemas import TASK_RUN_TYPE_IMPLEMENTATION, TaskRunArtefact
from products.signals.backend.models import (
+ SignalActorKind,
SignalReport,
SignalReportArtefact,
SignalReportAssignment,
@@ -50,8 +57,8 @@ logger = structlog.get_logger(__name__)
PR_DRI_FEATURE_FLAG = "signals-pr-dri-assignee"
-# Each DRI candidate costs one GitHub read. This covers the claimant and three other candidates,
-# and stops a large team or a long scout reviewer list from turning one pull request into ten reads.
+# Each DRI candidate costs one GitHub read, so this stops a large team or a long scout reviewer
+# list from turning one pull request into ten reads.
MAX_DRI_CHECKS = 4
# Assign only while the pull request can still be reviewed. UNKNOWN is included because a PR whose
@@ -123,7 +130,7 @@ def _latest_reviewer_rows(report_id: str) -> list[dict[str, Any]]:
return [row for row in payloads if isinstance(row, dict)]
-def opted_in_reviewer_logins(*, team_id: int, report_id: str) -> list[str]:
+def opted_in_assignee_logins(*, team_id: int, report_id: str) -> list[str]:
"""GitHub logins of the report's current suggested reviewers who opted in to PR assignment."""
logins = normalized_github_logins_from_reviewer_payloads(_latest_reviewer_rows(report_id))
if not logins:
@@ -159,13 +166,52 @@ def _pr_dri_enabled(team_id: int) -> bool:
return False
-def claimant_login(*, team_id: int, report_id: str) -> str | None:
- """The GitHub login of the person who claimed the report, when that person can be assigned."""
+def _is_manual_implementation_task(*, team_id: int, report_id: str, task_id: UUID) -> bool:
+ """Whether a person started the implementation task, rather than auto-start creating it.
+
+ Auto-start stamps the branch it generated onto the run artefact, and a manual start leaves it
+ unset, so only a run without one is somebody's decision. Anything unreadable counts as
+ automatic, because a claim nobody can vouch for must not outrank the team that owns the code.
+ """
+ rows = SignalReportArtefact.objects.filter(
+ team_id=team_id,
+ report_id=report_id,
+ type=SignalReportArtefact.ArtefactType.TASK_RUN,
+ task_id=task_id,
+ )
+ for row in rows:
+ try:
+ content = TaskRunArtefact.model_validate_json(row.content)
+ except ValidationError:
+ continue
+ if content.type == TASK_RUN_TYPE_IMPLEMENTATION and content.automation_branch is None:
+ return True
+ return False
+
+
+def human_claimant_login(*, team_id: int, report_id: str) -> str | None:
+ """The GitHub login of the person who chose to work on the report, when they can be assigned.
+
+ A claim a person made counts, and so does one their agent made for them, because an agent claim
+ carries the person it ran as. A task claim counts only when a person started that task: an
+ auto-started task runs as the report's top suggested reviewer, so it names a commit-history
+ guess rather than a decision.
+ """
claim = get_active_claim(team_id=team_id, report_id=report_id)
- claimant = responsible_user(claim) if claim is not None else None
- if claimant is None:
+ if claim is None:
+ return None
+ if claim.actor_kind in (SignalActorKind.USER, SignalActorKind.AGENT):
+ user = claim.actor_user
+ elif claim.actor_task_id is not None and _is_manual_implementation_task(
+ team_id=team_id, report_id=report_id, task_id=claim.actor_task_id
+ ):
+ user = responsible_user(claim)
+ else:
+ return None
+ if user is None:
return None
- return get_org_member_github_logins_by_user_uuid(team_id, [str(claimant.uuid)]).get(str(claimant.uuid))
+ user_uuid = str(user.uuid)
+ return get_org_member_github_logins_by_user_uuid(team_id, [user_uuid]).get(user_uuid)
def ranked_reviewer_logins(*, team_id: int, report_id: str) -> list[str]:
@@ -332,29 +378,41 @@ def _was_unassigned_by_hand(github: GitHubIntegration, *, team_id: int, report_i
return bool(result.get("unassigned"))
-def dri_candidate_logins(*, claimant: str | None, team: OwningTeam | None, reviewers: list[str]) -> list[str]:
- """GitHub logins that can own the pull request, the most responsible first.
+def dri_candidate_logins(
+ *, claimant: str | None, opted_in: set[str], team: OwningTeam | None, reviewers: list[str]
+) -> list[str]:
+ """GitHub logins that can be the DRI, the most responsible first.
- The claimant comes first, because to claim a report is to take the work on. The members of the
- team that owns the changed files come next. The suggested reviewers take their place when no
+ In order: the person who chose the work, then somebody who asked to be assigned, then a member
+ of the team that owns the changed files. The suggested reviewers are the owners only when no
ownership source names a team.
+
+ Within a rung, somebody who has touched this code comes first — an owning-team member among
+ those who opted in, and a suggested reviewer among the team.
"""
- others = team.logins if team is not None and team.logins else reviewers
- return list(dict.fromkeys(login for login in (claimant, *others) if login))
+ team_logins = list(team.logins) if team is not None and team.logins else []
+ owners = team_logins or reviewers
+ opted_in_ranked = [login for login in reviewers if login in opted_in]
+
+ candidates = [claimant]
+ candidates += [login for login in opted_in_ranked if login in team_logins]
+ candidates += opted_in_ranked
+ candidates += [login for login in owners if login in reviewers]
+ candidates += owners
+ return list(dict.fromkeys(login for login in candidates if login))
def assign_reviewers_to_pull_request(*, team_id: int, report_id: str, pr_url: str) -> list[str]:
- """Put the report's opted-in reviewers, and one DRI when they do not own the code, on its pull request.
+ """Assign the report's pull request: one DRI under the flag, else every opted-in reviewer.
- Returns the pull request's assignees after the last call GitHub accepted. Never unassigns:
- GitHub's add-assignees endpoint is additive, so a person somebody assigned by hand stays on the
- pull request, and a pull request that somebody assigned or unassigned by hand gets no DRI.
- Returns an empty list when there is nothing to do or the call failed, and raises nothing.
+ Returns the assignees GitHub accepted. Never unassigns: the add-assignees endpoint is additive,
+ so a person somebody assigned by hand stays on the pull request. Returns an empty list when
+ there is nothing to do or the call failed, and raises nothing.
"""
if not SignalReport.objects.filter(id=report_id, team_id=team_id).exists():
return []
- logins = opted_in_reviewer_logins(team_id=team_id, report_id=report_id)
+ logins = opted_in_assignee_logins(team_id=team_id, report_id=report_id)
dri_enabled = _pr_dri_enabled(team_id)
if not logins and not dri_enabled:
return []
@@ -371,42 +429,37 @@ def assign_reviewers_to_pull_request(*, team_id: int, report_id: str, pr_url: st
if pr is None:
return []
- assigned = (
- _add_assignees(github, team_id=team_id, report_id=report_id, parsed=parsed, logins=logins) if logins else []
- )
- if assigned is None:
+ if dri_enabled:
+ return _assign_one_dri(github, team_id=team_id, report_id=report_id, parsed=parsed, pr=pr, opted_in=set(logins))
+ return _add_assignees(github, team_id=team_id, report_id=report_id, parsed=parsed, logins=logins) or []
+
+
+def _assign_one_dri(
+ github: GitHubIntegration,
+ *,
+ team_id: int,
+ report_id: str,
+ parsed: PullRequestRef,
+ pr: dict[str, Any],
+ opted_in: set[str],
+) -> list[str]:
+ """Put exactly one directly responsible individual on a pull request that has none.
+
+ A pull request somebody already assigned has an owner, and a pull request somebody unassigned by
+ hand was a decision a later report event must not undo. Both are left alone.
+ """
+ if pr.get("assignees"):
return []
- # An assignee who is not an opted-in reviewer came from a person or from an earlier DRI pick, so
- # the pull request already has its owner. GitHub returns the full assignee list after the call,
- # which also shows a person who assigned somebody while the call ran.
- opted_in = {login.lower() for login in logins}
- owned_elsewhere = any(login.lower() not in opted_in for login in (*(pr.get("assignees") or []), *assigned))
- if not dri_enabled or owned_elsewhere:
- return assigned
-
- claimant = claimant_login(team_id=team_id, report_id=report_id)
- team = _owning_team(github, team_id=team_id, report_id=report_id, parsed=parsed)
- # An opted-in reviewer owns the pull request only as its claimant or as a member of the owning
- # team. A reviewer who opted in is often suggested for other teams' code too.
- owners = {login.lower() for login in (claimant, *(team.logins if team else ())) if login}
- assigned_lower = {login.lower() for login in assigned}
- if assigned and (not owners or assigned_lower & owners):
- return assigned
if _was_unassigned_by_hand(github, team_id=team_id, report_id=report_id, parsed=parsed):
- return assigned
+ return []
- # One owner rather than every candidate, because each person on a shared assignment reads the
- # pull request as somebody else's job.
candidates = dri_candidate_logins(
- claimant=claimant, team=team, reviewers=ranked_reviewer_logins(team_id=team_id, report_id=report_id)
- )
- dri = _first_assignable_login(
- github,
- team_id=team_id,
- report_id=report_id,
- parsed=parsed,
- candidates=[login for login in candidates if login not in assigned_lower],
+ claimant=human_claimant_login(team_id=team_id, report_id=report_id),
+ opted_in=opted_in,
+ team=_owning_team(github, team_id=team_id, report_id=report_id, parsed=parsed),
+ reviewers=ranked_reviewer_logins(team_id=team_id, report_id=report_id),
)
+ dri = _first_assignable_login(github, team_id=team_id, report_id=report_id, parsed=parsed, candidates=candidates)
if dri is None:
- return assigned
- return _add_assignees(github, team_id=team_id, report_id=report_id, parsed=parsed, logins=[dri]) or assigned
+ return []
+ return _add_assignees(github, team_id=team_id, report_id=report_id, parsed=parsed, logins=[dri]) or []
diff --git a/products/signals/backend/test/test_reviewer_pr_assignment.py b/products/signals/backend/test/test_reviewer_pr_assignment.py
index 4ed95ebc6d31..da0a54543d1d 100644
--- a/products/signals/backend/test/test_reviewer_pr_assignment.py
+++ b/products/signals/backend/test/test_reviewer_pr_assignment.py
@@ -24,7 +24,7 @@ from products.signals.backend.report_assignments import (
)
from products.signals.backend.reviewer_pr_assignment import (
assign_reviewers_to_pull_request,
- opted_in_reviewer_logins,
+ opted_in_assignee_logins,
schedule_reviewer_pr_assignment,
)
from products.signals.backend.task_run_artefacts import record_implementation_task
@@ -92,7 +92,7 @@ class TestOptedInReviewerLogins:
_make_reviewer(org, "opted-out", opted_in=False)
report = _make_report(team, ["opted-in", "opted-out"])
- assert opted_in_reviewer_logins(team_id=team.id, report_id=str(report.id)) == ["opted-in"]
+ assert opted_in_assignee_logins(team_id=team.id, report_id=str(report.id)) == ["opted-in"]
@pytest.mark.django_db
def test_reviewer_without_a_config_row_is_not_assigned(self, org_and_team):
@@ -102,7 +102,7 @@ class TestOptedInReviewerLogins:
UserSocialAuth.objects.create(user=user, provider="github", uid="gh-nobody", extra_data={"login": "nobody"})
report = _make_report(team, ["nobody"])
- assert opted_in_reviewer_logins(team_id=team.id, report_id=str(report.id)) == []
+ assert opted_in_assignee_logins(team_id=team.id, report_id=str(report.id)) == []
@pytest.mark.django_db
def test_reviewer_dropped_from_the_latest_row_is_not_assigned(self, org_and_team):
@@ -112,7 +112,7 @@ class TestOptedInReviewerLogins:
# suggested_reviewers is append-only and latest-wins, so only the newest row is live.
report = _make_report(team, ["opted-in", "removed"], ["opted-in"])
- assert opted_in_reviewer_logins(team_id=team.id, report_id=str(report.id)) == ["opted-in"]
+ assert opted_in_assignee_logins(team_id=team.id, report_id=str(report.id)) == ["opted-in"]
@pytest.mark.django_db
@pytest.mark.parametrize("content", ["not json", '{"github_login": "opted-in"}'])
@@ -127,7 +127,7 @@ class TestOptedInReviewerLogins:
content=content,
)
- assert opted_in_reviewer_logins(team_id=team.id, report_id=str(report.id)) == []
+ assert opted_in_assignee_logins(team_id=team.id, report_id=str(report.id)) == []
class TestAssignReviewersToPullRequest:
@@ -453,21 +453,49 @@ class TestDirectlyResponsibleIndividual:
def _team_x(self, github: MagicMock) -> None:
github.list_team_members.return_value = {"success": True, "logins": ["bob", "dave", "stranger"]}
+ def _claim(
+ self, team, report, users: dict, *, kind: str, login: str, automation_branch: str | None = "auto"
+ ) -> None:
+ if kind in ("user", "agent"):
+ actor = (
+ ArtefactAttribution.from_user(users[login].id)
+ if kind == "user"
+ else ArtefactAttribution.from_agent(users[login].id, "some-agent")
+ )
+ claim_report(report=report, actor=actor, user=users[login], was_impersonated=False)
+ return
+ task = Task.objects.create(
+ team=team, title="Implementation", description="", origin_product="signals", created_by=users[login]
+ )
+ claim_report_for_task(team_id=team.id, report_id=str(report.id), task_id=str(task.id))
+ record_implementation_task(
+ team_id=team.id,
+ report_id=str(report.id),
+ task_id=str(task.id),
+ automation_branch=automation_branch,
+ )
+
@pytest.mark.django_db
@pytest.mark.parametrize(
("reviewers", "claimant", "expected_owner"),
[
(["alice", "bob"], None, "alice"),
(["alice"], "user", "carol"),
- (["alice"], "task", "carol"),
+ (["alice"], "agent", "carol"),
+ (["alice"], "task", "alice"),
+ (["alice"], "manual-task", "carol"),
+ ([], "task", None),
(["uuid:bob", "alice"], None, "bob"),
(["stranger", "bob"], None, "bob"),
([], None, None),
],
ids=[
"top_reviewer",
- "user_claimant_first",
- "task_claimant_is_its_creator",
+ "a_person_who_chose_the_work_is_the_dri",
+ "an_agent_claim_names_the_person_who_ran_it",
+ "an_auto_started_task_claim_does_not_rank_its_claimant",
+ "a_task_a_person_started_ranks_its_creator",
+ "a_task_claim_alone_is_nobody_to_assign",
"reviewer_stored_by_uuid",
"non_member_skipped",
"nobody_to_assign",
@@ -478,18 +506,15 @@ class TestDirectlyResponsibleIndividual:
):
org, team = org_and_team
report, users = self._setup(org, team, reviewers)
- if claimant == "user":
- claim_report(
- report=report,
- actor=ArtefactAttribution.from_user(users["carol"].id),
- user=users["carol"],
- was_impersonated=False,
- )
- elif claimant == "task":
- task = Task.objects.create(
- team=team, title="Implementation", description="", origin_product="signals", created_by=users["carol"]
+ if claimant:
+ self._claim(
+ team,
+ report,
+ users,
+ kind="task" if claimant == "manual-task" else claimant,
+ login="carol",
+ automation_branch=None if claimant == "manual-task" else "auto",
)
- claim_report_for_task(team_id=team.id, report_id=str(report.id), task_id=str(task.id))
calls = self._assign(team, report, self._github(existing_assignees=[], assignable=None))
@@ -539,18 +564,24 @@ class TestDirectlyResponsibleIndividual:
@pytest.mark.django_db
@pytest.mark.parametrize(
- ("team_by_path", "members", "claimant", "expected_owner"),
+ ("reviewers", "team_by_path", "members", "claimant", "expected_owner"),
[
- ({"a.py": "team-x", "b.py": "team-x", "c.py": "team-y"}, {"success": True}, False, "dave"),
- ({"a.py": "team-x"}, {"success": True}, True, "carol"),
- (None, {"success": True}, False, "alice"),
- ({"a.py": UNOWNED_TEAM}, {"success": True}, False, "alice"),
- ({"a.py": "team-x"}, {"success": False, "status_code": 403}, False, "alice"),
- ({"a.py": "team-y"}, {"success": True}, False, "alice"),
+ (["alice"], {"a.py": "team-x", "b.py": "team-x", "c.py": "team-y"}, {"success": True}, None, "dave"),
+ (["bob"], {"a.py": "team-x"}, {"success": True}, None, "bob"),
+ (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "carol"), "dave"),
+ (["alice"], {"a.py": "team-x"}, {"success": True}, ("task", "bob"), "dave"),
+ (["alice"], {"a.py": "team-x"}, {"success": True}, ("user", "carol"), "carol"),
+ (["alice"], None, {"success": True}, None, "alice"),
+ (["alice"], {"a.py": UNOWNED_TEAM}, {"success": True}, None, "alice"),
+ (["alice"], {"a.py": "team-x"}, {"success": False, "status_code": 403}, None, "alice"),
+ (["alice"], {"a.py": "team-y"}, {"success": True}, None, "alice"),
],
ids=[
"random_member_of_the_majority_team",
- "claimant_before_the_team",
+ "a_suggested_member_comes_before_a_random_one",
+ "a_task_claim_outside_the_team_does_not_rank",
+ "a_task_claim_inside_the_team_does_not_reorder_it",
+ "a_person_who_chose_the_work_outranks_the_team",
"no_owners_files_uses_reviewers",
"unowned_files_use_reviewers",
"unreadable_team_uses_reviewers",
@@ -561,20 +592,16 @@ class TestDirectlyResponsibleIndividual:
self,
org_and_team,
ownership,
+ reviewers: list[str],
team_by_path: dict[str, str] | None,
members: dict,
- claimant: bool,
+ claimant: tuple[str, str] | None,
expected_owner: str,
):
org, team = org_and_team
- report, users = self._setup(org, team, ["alice"])
+ report, users = self._setup(org, team, reviewers)
if claimant:
- claim_report(
- report=report,
- actor=ArtefactAttribution.from_user(users["carol"].id),
- user=users["carol"],
- was_impersonated=False,
- )
+ self._claim(team, report, users, kind=claimant[0], login=claimant[1])
if team_by_path is not None:
ownership.return_value = PathOwnership(team_by_path=team_by_path, registry={}, resolved=True)
github = self._github(existing_assignees=[], assignable=None)
@@ -594,8 +621,9 @@ class TestDirectlyResponsibleIndividual:
@pytest.mark.parametrize(
("opted_in", "existing_assignees", "add_result", "events", "expected_calls"),
[
- (("alice",), [], None, _NOT_UNASSIGNED, [["alice"], ["dave"]]),
- (("alice",), ["alice"], None, _NOT_UNASSIGNED, [["alice"], ["dave"]]),
+ (("alice",), [], None, _NOT_UNASSIGNED, [["alice"]]),
+ (("alice", "bob"), [], None, _NOT_UNASSIGNED, [["bob"]]),
+ (("alice",), ["alice"], None, _NOT_UNASSIGNED, []),
(("alice",), [], {"success": True, "assignees": ["alice", "someone"]}, _NOT_UNASSIGNED, [["alice"]]),
(("bob",), [], None, _NOT_UNASSIGNED, [["bob"]]),
(("alice",), [], {"success": False, "error": "Network error"}, _NOT_UNASSIGNED, [["alice"]]),
@@ -603,8 +631,9 @@ class TestDirectlyResponsibleIndividual:
((), [], None, {"success": False, "error": "Failed to list issue events"}, []),
],
ids=[
- "opted_in_reviewer_outside_the_owning_team_gets_a_dri_beside_them",
- "an_earlier_opted_in_assignment_is_not_a_hand_assignment",
+ "an_opted_in_person_outside_the_owning_team_is_the_dri",
+ "two_opted_in_people_yield_one_dri_preferring_the_owner",
+ "a_pull_request_that_already_has_an_assignee_is_left_alone",
"a_hand_assignment_during_the_call_counts",
"opted_in_reviewer_in_the_owning_team_is_the_owner",
"unknown_assignment_outcome_adds_nobody_else",