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(github-commands): stop refusing people with several linked accounts (#116811)

Julian Bez202915495206
diff --git a/products/github_commands/README.md b/products/github_commands/README.md
index d08891ed1c66..74d3716b56c2 100644
--- a/products/github_commands/README.md
+++ b/products/github_commands/README.md
@@ -53,7 +53,7 @@ So a command can only do what the commenter could already do in PostHog, and a c
The checks that make that true:
- **Who is asking.** The webhook's `author_association` filters out outside contributors before a task is queued. The task then asks GitHub for the commenter's permission on the repository and requires write access, for the commenter's numeric account id, so a login that changed hands does not count.
-- **Which PostHog user.** The match is on GitHub's numeric user id, never on the login, and only through identities GitHub confirmed to PostHog: a connected GitHub account or GitHub login. A GitHub account linked to two PostHog accounts runs nothing.
+- **Which PostHog user.** The match is on GitHub's numeric user id, never on the login, and only through identities GitHub confirmed to PostHog: a connected GitHub account or GitHub login. A GitHub account can be linked to several PostHog accounts, for example a work and a personal one. The command picks the project first, and the linked account that is a member of it acts there. When two linked accounts are members of that project, the one linked most recently acts.
- **Which project.** Only projects whose GitHub integration uses the installation the comment came from, that the user is a member of, and that are in the `github-commands` rollout. For an environment, the user must also be a member of its parent project. An organization that enforces verified email domains gives no project to a user whose email is outside them, as the product APIs do. `review` runs only in the project that owns the repository in PostHog Review, and the commenter must be a member of it.
- **Which product gates.** A command applies the gates the target product's own API applies. `loop` needs Loops access, and `qa` needs PostHog Code access for the commenter's organization and PostHog Code credits left.
- **What the person typed.** Only a new comment counts, so an edit cannot turn a reviewed comment into a command. Comments by bots, and comments a GitHub App posted with a person's token, never run a command. That covers PostHog's own replies and coding agents that act as a user.
diff --git a/products/github_commands/backend/logic/commands.py b/products/github_commands/backend/logic/commands.py
index 0b3e22cd3d71..7f7551951ec6 100644
--- a/products/github_commands/backend/logic/commands.py
+++ b/products/github_commands/backend/logic/commands.py
@@ -29,14 +29,25 @@ class PullRequestFacts:
is_fork: bool
+@frozen
+class ProjectMember:
+ """A project the commenter may act in, and the commenter's PostHog account that acts there.
+
+ One GitHub account can be linked to several PostHog accounts, for example a work and a personal
+ one, so the account goes with the project the command picks.
+ """
+
+ team_id: int
+ user_id: int
+
+
@frozen
class CommandContext:
request: CommentCommandRequest
pull_request: PullRequestFacts
- user_id: int
- # Projects the commenter may act in for this command, best candidate first. Every id here
- # passed the membership, rollout and resource-access checks for this command.
- team_ids: tuple[int, ...]
+ # Best candidate first. Every entry passed the membership, rollout and resource-access checks
+ # for this command. A project appears once per linked account that is a member of it.
+ members: tuple[ProjectMember, ...]
@frozen
diff --git a/products/github_commands/backend/logic/dispatch.py b/products/github_commands/backend/logic/dispatch.py
index d0acbc55f238..278e35efdfbb 100644
--- a/products/github_commands/backend/logic/dispatch.py
+++ b/products/github_commands/backend/logic/dispatch.py
@@ -12,10 +12,11 @@ Every command passes the same checks, in this order, before its handler runs:
The webhook's `author_association` only filtered noise; organization members can lack write
access to a given repository.
5. The comment holds exactly one command, the command exists, and its arguments match its grammar.
-6. The commenter's GitHub account is linked to exactly one active PostHog user, and that user is a
- member of a rolled-out project whose GitHub integration uses this installation.
+6. The commenter's GitHub account is linked to an active PostHog account that is a member of a
+ rolled-out project whose GitHub integration uses this installation. With several linked
+ accounts, the handler picks the project, and the account that is a member of it acts there.
7. The pull request is open, and the command allows forks if the head is a fork.
-8. The user has the access the command declares on the project, in PostHog access control.
+8. The account has the access the command declares on the project, in PostHog access control.
People who fail checks 1 to 4 get no answer at all, so the bot gives outsiders nothing to probe and
no way to make it post. Everyone past them gets a reply that says what happened.
@@ -39,7 +40,7 @@ from posthog.models.user import User
from posthog.permissions import UserAccessControl, posthog_feature_flag_enabled
from posthog.token_bucket import BucketDecision, Budget, consume
-from .commands import CommandContext
+from .commands import CommandContext, ProjectMember
from .github import CommandGitHub, GitHubCallFailed, InstallationGitHub, UnsupportedPullRequest
from .identity import Commenter, resolve_commenter
from .intake import CommentCommandRequest
@@ -201,8 +202,8 @@ def _command_context(
if not isinstance(commenter, Commenter):
outcome: DispatchOutcome = "account_refused" if commenter.reason == "refused" else "unlinked"
return _Answer(outcome=outcome, message=_UNRESOLVED_MESSAGES[commenter.reason])
- team_ids = tuple(team_id for team_id in commenter.team_ids if team_id in rolled_out_team_ids)
- if not team_ids:
+ members = tuple(member for member in commenter.members if member.team_id in rolled_out_team_ids)
+ if not members:
return _Answer(
outcome="no_project",
message="You aren't a member of a PostHog project that uses pull request commands on this repository.",
@@ -231,20 +232,18 @@ def _command_context(
access = declaration.access
if access is not None:
- team_ids = _teams_with_access(User.objects.get(id=commenter.user_id), team_ids, access)
- if not team_ids:
+ members = _members_with_access(members, access)
+ if not members:
return _Answer(
outcome="access_denied",
message=f"You need {access.level} access to {access.resource} in PostHog to use `{declaration.verb}`.",
)
- return CommandContext(request=request, pull_request=pull_request, user_id=commenter.user_id, team_ids=team_ids)
+ return CommandContext(request=request, pull_request=pull_request, members=members)
_UNRESOLVED_MESSAGES = {
"unlinked": "Your GitHub account is not linked to a PostHog account, so I can't tell who to run this as. "
"Connect GitHub in your PostHog personal settings, then comment again.",
- "ambiguous": "Your GitHub account is linked to more than one PostHog account, so I can't tell which to run this "
- "as. Disconnect GitHub from the accounts you don't use, then comment again.",
"refused": "I can't run commands for your PostHog account.",
}
@@ -324,12 +323,18 @@ def _rolled_out_team_ids(installation_id: str) -> frozenset[int]:
)
-def _teams_with_access(user: User, team_ids: tuple[int, ...], access: ResourceAccess) -> tuple[int, ...]:
+def _members_with_access(members: tuple[ProjectMember, ...], access: ResourceAccess) -> tuple[ProjectMember, ...]:
# Products keep their rows, and their access rules, on the parent project.
- effective_team_ids = {team_id: resolve_effective_team_id(team_id) for team_id in team_ids}
+ effective_team_ids = {member.team_id: resolve_effective_team_id(member.team_id) for member in members}
teams = Team.objects.in_bulk(set(effective_team_ids.values()))
- has_access: dict[int, bool] = {}
- for effective_team_id, team in teams.items():
+ users = User.objects.in_bulk({member.user_id for member in members})
+
+ def has_access(member: ProjectMember) -> bool:
+ team = teams.get(effective_team_ids[member.team_id])
+ if team is None:
+ return False
+ user = users[member.user_id]
access_control = UserAccessControl(user=user, team=team, organization_id=str(team.organization_id))
- has_access[effective_team_id] = access_control.check_access_level_for_resource(access.resource, access.level)
- return tuple(team_id for team_id in team_ids if has_access.get(effective_team_ids[team_id], False))
+ return access_control.check_access_level_for_resource(access.resource, access.level)
+
+ return tuple(member for member in members if has_access(member))
diff --git a/products/github_commands/backend/logic/handlers.py b/products/github_commands/backend/logic/handlers.py
index 03fc95bf55ab..142409bbf1a2 100644
--- a/products/github_commands/backend/logic/handlers.py
+++ b/products/github_commands/backend/logic/handlers.py
@@ -1,9 +1,10 @@
"""Handlers that dispatch a command into the product that does the work.
-Each handler runs as the commenter's own PostHog user and only in projects that passed
-``dispatch.py``'s checks, so a command can only do what the commenter could do in PostHog
-themselves. Handlers never pass the pull request's title, body or comments to an agent. They pass
-identifiers, and the downstream product reads the content itself as untrusted data.
+Each handler picks a project from the ones that passed ``dispatch.py``'s checks, and runs as the
+commenter's PostHog account that is a member of it, so a command can only do what the commenter
+could do in PostHog themselves. Handlers never pass the pull request's title, body or comments to
+an agent. They pass identifiers, and the downstream product reads the content itself as untrusted
+data.
"""
import structlog
@@ -27,7 +28,7 @@ from products.tasks.backend.facade import (
usage as tasks_usage,
)
-from .commands import CommandContext, CommandOutcome
+from .commands import CommandContext, CommandOutcome, ProjectMember
from .schema import LoopArgs, QaArgs, ReviewArgs, StampArgs
logger = structlog.get_logger(__name__)
@@ -38,10 +39,13 @@ def handle_stamp(context: CommandContext, args: StampArgs) -> CommandOutcome:
pull_request = context.pull_request
refusal: stamphog_contracts.ReviewRequestRefusedError | None = None
# Stamphog keeps its repositories on the parent project, so environments of one project are one.
- for team_id in dict.fromkeys(resolve_effective_team_id(team_id) for team_id in context.team_ids):
+ user_ids_by_project: dict[int, int] = {}
+ for member in context.members:
+ user_ids_by_project.setdefault(resolve_effective_team_id(member.team_id), member.user_id)
+ for team_id, user_id in user_ids_by_project.items():
try:
result = stamphog_requests.request_review(
- team_id, user_id=context.user_id, repository=pull_request.repository, pr_number=pull_request.number
+ team_id, user_id=user_id, repository=pull_request.repository, pr_number=pull_request.number
)
except stamphog_contracts.ReviewRequestRefusedError as error:
refusal = error
@@ -60,23 +64,24 @@ def handle_stamp(context: CommandContext, args: StampArgs) -> CommandOutcome:
return CommandOutcome(accepted=False, message=refusal.message)
-def _team_in_project(team_ids: tuple[int, ...], project_team_id: int) -> int | None:
- """The first of ``team_ids`` that belongs to the project, environments included."""
+def _member_in_project(members: tuple[ProjectMember, ...], project_team_id: int) -> ProjectMember | None:
+ """The first of ``members`` that belongs to the project, environments included."""
project_id = resolve_effective_team_id(project_team_id)
- return next((team_id for team_id in team_ids if resolve_effective_team_id(team_id) == project_id), None)
+ return next((member for member in members if resolve_effective_team_id(member.team_id) == project_id), None)
def handle_review(context: CommandContext, args: ReviewArgs) -> CommandOutcome:
"""Start a PostHog Review run on the pull request, with the commenter as the acting user.
- The project that owns the repository in PostHog Review decides, and the commenter must be a member of it.
+ The project that owns the repository in PostHog Review decides, and one of the commenter's linked
+ accounts must be a member of it. That account acts.
"""
pull_request = context.pull_request
owner_team_id = review_hog_github.owning_team_id(context.request.installation_id, pull_request.repository)
if owner_team_id is None:
return CommandOutcome(accepted=False, message="PostHog Review isn't set up for this repository.")
- team_id = _team_in_project(context.team_ids, owner_team_id)
- if team_id is None:
+ member = _member_in_project(context.members, owner_team_id)
+ if member is None:
return CommandOutcome(
accepted=False, message="You aren't a member of the PostHog project that reviews this repository."
)
@@ -90,8 +95,8 @@ def handle_review(context: CommandContext, args: ReviewArgs) -> CommandOutcome:
else:
run_mode = review_hog_facade.RUN_MODE_REVIEW
outcome = review_hog_facade.request_pr_review(
- team_id=team_id,
- requester_id=context.user_id,
+ team_id=member.team_id,
+ requester_id=member.user_id,
repository=pull_request.repository,
pr_number=pull_request.number,
run_mode=run_mode,
@@ -107,9 +112,10 @@ def handle_review(context: CommandContext, args: ReviewArgs) -> CommandOutcome:
def handle_qa(context: CommandContext, args: QaArgs) -> CommandOutcome:
"""Start a PostHog Code task that runs the frontend QA skill against the pull request head."""
pull_request = context.pull_request
- team_id = context.team_ids[0]
+ member = context.members[0]
+ team_id = member.team_id
team = Team.objects.select_related("organization").get(id=team_id)
- user = User.objects.get(id=context.user_id)
+ user = User.objects.get(id=member.user_id)
# The Tasks API applies the same gates before it starts a run.
try:
decision = tasks_access.get_desktop_access_decision(user, team.organization)
@@ -132,7 +138,7 @@ def handle_qa(context: CommandContext, args: QaArgs) -> CommandOutcome:
title=f"QA {pull_request.repository}#{pull_request.number}",
description=build_qa_instructions(context, args.focus),
origin_product=tasks_facade.TaskOriginProduct.USER_CREATED,
- user_id=context.user_id,
+ user_id=member.user_id,
repository=pull_request.repository,
branch=pull_request.head_branch,
create_pr=False,
diff --git a/products/github_commands/backend/logic/identity.py b/products/github_commands/backend/logic/identity.py
index 4e2c16d65208..ef1a36c365a9 100644
--- a/products/github_commands/backend/logic/identity.py
+++ b/products/github_commands/backend/logic/identity.py
@@ -1,13 +1,19 @@
-"""Finds the PostHog user behind a GitHub commenter, and the projects they may act in.
+"""Finds the PostHog accounts behind a GitHub commenter, and the projects each may act in.
The match is on GitHub's numeric user id, never on the login. A login can be renamed and then
claimed by someone else, but the id stays with the account. Only identities that GitHub itself
confirmed to PostHog count: the GitHub account a user connected in PostHog, or the one they log in
with. A login typed into a profile or saved on a project integration does not.
+
+One GitHub account can be linked to several PostHog accounts, for example a work and a personal one.
+Every link needed that GitHub account's approval, so all of them belong to the person behind the
+comment. The command picks the project, and the linked account that is a member of it acts there.
"""
+from datetime import datetime
from typing import Literal
+import structlog
from social_django.models import UserSocialAuth
from posthog.dataclasses import frozen
@@ -22,51 +28,39 @@ from products.security.backend.facade.api import access_refused
from products.security.backend.facade.contracts import SubjectInput
from products.security.backend.facade.enums import Surface
+from .commands import ProjectMember
+
+logger = structlog.get_logger(__name__)
+
@frozen
class Commenter:
- user_id: int
- # Projects whose GitHub integration uses this installation and that the user is a member of,
- # oldest integration first. Empty when the user belongs to none of them.
- team_ids: tuple[int, ...]
+ # Projects whose GitHub integration uses this installation, each with a linked account that is a
+ # member of it. Oldest integration first, and within a project the most recently linked account
+ # first. Empty when no linked account belongs to any of them.
+ members: tuple[ProjectMember, ...]
@frozen
class UnresolvedCommenter:
- reason: Literal["unlinked", "ambiguous", "refused"]
-
-
-def resolve_commenter(*, github_user_id: int, installation_id: str) -> Commenter | UnresolvedCommenter:
- user_ids = _linked_user_ids(github_user_id)
- if not user_ids:
- return UnresolvedCommenter(reason="unlinked")
- if len(user_ids) > 1:
- # Two PostHog accounts claim the same GitHub account. Picking one would let the other act
- # with its access, so neither may.
- return UnresolvedCommenter(reason="ambiguous")
- user = User.objects.get(id=next(iter(user_ids)))
- # The same rule that refuses the account's logins and API keys refuses its commands.
- if access_refused(
- SubjectInput(email=user.email, user_uuid=str(user.uuid)), Surface.APP, call_site="github_command"
- ):
- return UnresolvedCommenter(reason="refused")
- return Commenter(user_id=user.id, team_ids=_member_team_ids(user, installation_id))
-
-
-def _linked_user_ids(github_user_id: int) -> set[int]:
- integration_user_ids = UserIntegration.objects.filter(
- kind=UserIntegration.IntegrationKind.GITHUB,
- # The id arrives as a JSON number from the GitHub OAuth flow. Older rows may hold a string.
- config__github_user__id__in=[github_user_id, str(github_user_id)],
- ).values_list("user_id", flat=True)
- social_user_ids = UserSocialAuth.objects.filter(provider="github", uid=str(github_user_id)).values_list(
- "user_id", flat=True
- )
- return set(
- User.objects.filter(id__in={*integration_user_ids, *social_user_ids}, is_active=True).values_list(
- "id", flat=True
- )
- )
+ reason: Literal["unlinked", "refused"]
+
+
+def _linked_users(github_user_id: int) -> list[User]:
+ """The active users linked to the GitHub account, most recently linked first."""
+ links = [
+ *UserIntegration.objects.filter(
+ kind=UserIntegration.IntegrationKind.GITHUB,
+ # The id arrives as a JSON number from the GitHub OAuth flow. Older rows may hold a string.
+ config__github_user__id__in=[github_user_id, str(github_user_id)],
+ ).values_list("user_id", "created_at"),
+ *UserSocialAuth.objects.filter(provider="github", uid=str(github_user_id)).values_list("user_id", "created"),
+ ]
+ linked_at: dict[int, datetime] = {}
+ for user_id, created_at in links:
+ linked_at[user_id] = max(created_at, linked_at.get(user_id, created_at))
+ users = User.objects.filter(id__in=linked_at, is_active=True)
+ return sorted(users, key=lambda user: (linked_at[user.id], user.id), reverse=True)
def _is_member(permissions: UserPermissions, team: Team) -> bool:
@@ -78,18 +72,9 @@ def _is_member(permissions: UserPermissions, team: Team) -> bool:
return parent is None or permissions.team(parent).effective_membership_level is not None
-def _member_team_ids(user: User, installation_id: str) -> tuple[int, ...]:
- team_ids = list(
- dict.fromkeys(
- Integration.objects.filter(kind="github", integration_id=installation_id)
- .order_by("id")
- .values_list("team_id", flat=True)
- )
- )
- teams = Team.objects.filter(id__in=team_ids).select_related("organization", "parent_team__organization")
- teams_by_id = {team.id: team for team in teams}
+def _member_team_ids(user: User, teams: list[Team]) -> set[int]:
permissions = UserPermissions(user)
- organizations = {team.organization_id: team.organization for team in teams_by_id.values()}
+ organizations = {team.organization_id: team.organization for team in teams}
# The product APIs refuse an organization that is pending deletion or inactive, and a member
# whose email is outside its enforced verified domains, so a comment must not reach those
# projects either.
@@ -100,10 +85,49 @@ def _member_team_ids(user: User, installation_id: str) -> tuple[int, ...]:
or not organization.is_active
or OrganizationDomain.objects.is_email_blocked_by_domain_enforcement(user.email, organization)
}
+ return {
+ team.id
+ for team in teams
+ if team.organization_id not in blocked_organization_ids and _is_member(permissions, team)
+ }
+
+
+def _project_members(users: list[User], installation_id: str) -> tuple[ProjectMember, ...]:
+ team_ids = list(
+ dict.fromkeys(
+ Integration.objects.filter(kind="github", integration_id=installation_id)
+ .order_by("id")
+ .values_list("team_id", flat=True)
+ )
+ )
+ teams_by_id = Team.objects.select_related("organization", "parent_team__organization").in_bulk(team_ids)
+ teams = [teams_by_id[team_id] for team_id in team_ids if team_id in teams_by_id]
+ member_team_ids = {user.id: _member_team_ids(user, teams) for user in users}
+ # When two linked accounts are members of the same project, the most recently linked one acts
+ # there, as in the Slack app: the person linked it last, so it is the one they use.
return tuple(
- team_id
- for team_id in team_ids
- if team_id in teams_by_id
- and teams_by_id[team_id].organization_id not in blocked_organization_ids
- and _is_member(permissions, teams_by_id[team_id])
+ ProjectMember(team_id=team.id, user_id=user.id)
+ for team in teams
+ for user in users
+ if team.id in member_team_ids[user.id]
)
+
+
+def resolve_commenter(*, github_user_id: int, installation_id: str) -> Commenter | UnresolvedCommenter:
+ users = _linked_users(github_user_id)
+ if not users:
+ return UnresolvedCommenter(reason="unlinked")
+ # The same rule that refuses an account's logins and API keys refuses its commands. Another
+ # linked account can still log in, so it can still run commands.
+ users = [
+ user
+ for user in users
+ if not access_refused(
+ SubjectInput(email=user.email, user_uuid=str(user.uuid)), Surface.APP, call_site="github_command"
+ )
+ ]
+ if not users:
+ return UnresolvedCommenter(reason="refused")
+ if len(users) > 1:
+ logger.info("github_command_commenter_has_several_accounts", account_count=len(users))
+ return Commenter(members=_project_members(users, installation_id))
diff --git a/products/github_commands/backend/tests/test_dispatch.py b/products/github_commands/backend/tests/test_dispatch.py
index 86c5ed425ac8..1baad53940c1 100644
--- a/products/github_commands/backend/tests/test_dispatch.py
+++ b/products/github_commands/backend/tests/test_dispatch.py
@@ -1,6 +1,7 @@
import hmac
import json
import hashlib
+from datetime import timedelta
from itertools import count
from typing import Any
@@ -17,13 +18,15 @@ from social_django.models import UserSocialAuth
from posthog.constants import AvailableFeature
from posthog.ingress.dispatch.loading import reset_consumer_registry
from posthog.models.integration import Integration
+from posthog.models.organization import Organization
from posthog.models.organization_domain import OrganizationDomain
from posthog.models.team import Team
+from posthog.models.user import User
from posthog.models.user_integration import UserIntegration
from posthog.token_bucket import BucketDecision
from products.access_control.backend.facade.testing import create_access_control
-from products.github_commands.backend.logic.commands import CommandContext, PullRequestFacts
+from products.github_commands.backend.logic.commands import CommandContext, ProjectMember, PullRequestFacts
from products.github_commands.backend.logic.dispatch import dispatch_comment_command
from products.github_commands.backend.logic.github import InstallationGitHub, Reaction, UnsupportedPullRequest
from products.github_commands.backend.logic.handlers import handle_loop, handle_qa, handle_review
@@ -195,6 +198,54 @@ class TestDispatchCommentCommand(BaseTest):
request_review.assert_not_called()
assert "can't run commands" in github.replies[0]
+ def _link_github_account(self, user: User, days_ago: int) -> None:
+ link = UserIntegration.objects.create(
+ user=user,
+ kind=UserIntegration.IntegrationKind.GITHUB,
+ integration_id=INSTALLATION_ID,
+ config={"github_user": {"login": "octo", "id": self.github_id}},
+ )
+ UserIntegration.objects.filter(id=link.id).update(created_at=timezone.now() - timedelta(days=days_ago))
+
+ @parameterized.expand(
+ [
+ ("newer_account_outside_the_installation", "outside", True, False, "first"),
+ ("older_account_in_the_owning_project", "owning_project", False, False, "second"),
+ ("newer_account_in_the_same_project", "same_project", True, False, "second"),
+ ("newer_account_refused", "same_project", True, True, "first"),
+ ]
+ )
+ def test_a_github_account_linked_to_several_posthog_accounts_runs_as_the_one_in_the_project(
+ self, _name: str, second_account_in: str, second_linked_last: bool, second_refused: bool, expected: str
+ ) -> None:
+ owner_team = self.team
+ if second_account_in == "same_project":
+ second_user = User.objects.create_and_join(self.organization, "[email protected]", None)
+ else:
+ other_organization = Organization.objects.create(name="Other")
+ second_user = User.objects.create_and_join(other_organization, "[email protected]", None)
+ if second_account_in == "owning_project":
+ owner_team = Team.objects.create(organization=other_organization, name="Other")
+ Integration.objects.create(team=owner_team, kind="github", integration_id=INSTALLATION_ID, config={})
+ self._link_github_account(self.user, days_ago=10)
+ self._link_github_account(second_user, days_ago=1 if second_linked_last else 30)
+ started = PRReviewRequestOutcome(status=PRReviewRequestStatus.STARTED, workflow_id="wf-1")
+
+ with (
+ patch(
+ "products.github_commands.backend.logic.identity.access_refused",
+ side_effect=lambda subject, *_args, **_kwargs: second_refused and subject.email == second_user.email,
+ ),
+ patch(OWNING_TEAM_ID, return_value=owner_team.id),
+ patch(REQUEST_PR_REVIEW, return_value=started) as request_pr_review,
+ ):
+ outcome = dispatch_comment_command(self._request(verb="review"), github=FakeGitHub())
+
+ assert outcome == "accepted"
+ expected_user = self.user if expected == "first" else second_user
+ assert request_pr_review.call_args.kwargs["team_id"] == owner_team.id
+ assert request_pr_review.call_args.kwargs["requester_id"] == expected_user.id
+
def test_a_comment_runs_at_most_once(self) -> None:
self._link_github_login()
@@ -283,8 +334,7 @@ class TestDispatchCommentCommand(BaseTest):
context = CommandContext(
request=self._request(verb="loop", argument="Triage PR"),
pull_request=_pull_request(),
- user_id=self.user.id,
- team_ids=(self.team.id,),
+ members=(ProjectMember(team_id=self.team.id, user_id=self.user.id),),
)
outcome = handle_loop(context, LoopArgs(name="Triage PR"))
@@ -304,8 +354,7 @@ class TestDispatchCommentCommand(BaseTest):
context = CommandContext(
request=self._request(verb="qa"),
pull_request=_pull_request(),
- user_id=self.user.id,
- team_ids=(self.team.id,),
+ members=(ProjectMember(team_id=self.team.id, user_id=self.user.id),),
)
with (
@@ -372,8 +421,7 @@ class TestDispatchCommentCommand(BaseTest):
context = CommandContext(
request=self._request(verb="review"),
pull_request=_pull_request(),
- user_id=self.user.id,
- team_ids=(self.team.id,),
+ members=(ProjectMember(team_id=self.team.id, user_id=self.user.id),),
)
started = PRReviewRequestOutcome(status=PRReviewRequestStatus.STARTED, workflow_id="wf-1")