(queue: WebhookQueueProtocol, status_event: StatusEvent)
Trigger evaluation of all PRs associated with the status event commit SHA.
Trigger evaluation of all PRs associated with the status event commit SHA.
Trigger evaluation of all PRs associated with the status event commit SHA .
async def status_event(queue: WebhookQueueProtocol, status_event: StatusEvent) -> None:
    """
    Trigger evaluation of all PRs associated with the status event commit SHA.
    """
    owner = status_event.repository.owner.login
    repo = status_event.repository.name
    installation_id = str(status_event.installation.id)
    log = logger.bind(owner=owner, repo=repo, install=installation_id)

    refs = find_branch_names_latest(
        sha=status_event.sha, branches=status_event.branches
    )

    async with Client(
        owner=owner, repo=repo, installation_id=installation_id
    ) as api_client:
        if len(refs) == 0:
            # when a pull request is from a fork the status event will not have
            # any `branches`, so to be able to trigger evaluation of the PR, we
            # fetch all pull requests.
            #
            # I think we could optimize this by selecting only the fork PRs, but
            # I worry that we might miss some events where `branches` is empty,
            # but not because of a fork.
            pr_results = [await api_client.get_open_pull_requests()]
            log.info("could not find refs for status_event")
        else:
            pr_requests = [
                api_client.get_open_pull_requests(head=f"{owner}:{ref}") for ref in refs
            ]
            pr_results = await asyncio.gather(*pr_requests)

        all_events: set[WebhookEvent] = set()
        for prs in pr_results:
            if prs is None:
                continue
            for pr in prs:
                all_events.add(
                    WebhookEvent(
                        repo_owner=owner,
                        repo_name=repo,
                        pull_request_number=pr.number,
                        target_name=pr.base.ref,
                        installation_id=str(installation_id),
                    )
                )
        for event in all_events:
            await queue.enqueue(event=event)
async def status_event ( queue : WebhookQueueProtocol , status_event : StatusEvent ) -> None : owner = status_event . repository . owner . login repo = status_event . repository . name installation_id = str ( status_event . installation . id ) log = logger . bind ( owner = owner , repo = repo , install = installation_id ) refs = find_branch_names_latest ( sha = status_event . sha , branches = status_event . branches ) async with Client ( owner = owner , repo = repo , installation_id = installation_id ) as api_client : if len ( refs ) == 0 : # when a pull request is from a fork the status event will not have # any `branches`, so to be able to trigger evaluation of the PR, we # fetch all pull requests. # # I think we could optimize this by selecting only the fork PRs, but # I worry that we might miss some events where `branches` is empty, # but not because of a fork. pr_results = [ await api_client . get_open_pull_requests ( ) ] log . info ( "could not find refs for status_event" ) else : pr_requests = [ api_client . get_open_pull_requests ( head = f"{owner}:{ref}" ) for ref in refs ] pr_results = await asyncio . gather ( * pr_requests ) all_events : set [ WebhookEvent ] = set ( ) for prs in pr_results : if prs is None : continue for pr in prs : all_events . add ( WebhookEvent ( repo_owner = owner , repo_name = repo , pull_request_number = pr . number , target_name = pr . base . ref , installation_id = str ( installation_id ) , ) ) for event in all_events : await queue . enqueue ( event = event )