Ejemplo n.º 1
0
async def _ensure_summary_on_head_sha(ctxt: context.Context) -> None:
    for check in await ctxt.pull_engine_check_runs:
        if check[
                "name"] == ctxt.SUMMARY_NAME and actions_runner.load_conclusions_line(
                    ctxt, check):
            return

    opened = ctxt.has_been_opened()
    sha = await ctxt.get_cached_last_summary_head_sha()
    if sha is None:
        if not opened:
            ctxt.log.warning(
                "the pull request doesn't have the last summary head sha stored in redis"
            )
        return

    previous_summary = await _get_summary_from_sha(ctxt, sha)
    if previous_summary:
        await ctxt.set_summary_check(
            check_api.Result(
                check_api.Conclusion(previous_summary["conclusion"]),
                title=previous_summary["output"]["title"],
                summary=previous_summary["output"]["summary"],
            ))
    elif not opened:
        ctxt.log.warning("the pull request doesn't have a summary")
Ejemplo n.º 2
0
async def _ensure_summary_on_head_sha(ctxt: context.Context) -> None:
    for check in await ctxt.pull_engine_check_runs:
        if check[
                "name"] == ctxt.SUMMARY_NAME and actions_runner.load_conclusions_line(
                    ctxt, check):
            return

    opened = ctxt.has_been_opened()
    sha = await ctxt.get_cached_last_summary_head_sha()
    if sha is None:
        if not opened:
            ctxt.log.warning(
                "the pull request doesn't have the last summary head sha stored in redis"
            )
        return

    previous_summary = await _get_summary_from_sha(ctxt, sha)

    if previous_summary is None:
        # NOTE(sileht): If the cached summary sha expires and the next event we got for
        # a pull request is "synchronize" we will lose the summary. Most of the times
        # it's not a big deal, but if the pull request is queued for merge, it may
        # be stuck.
        previous_summary = await _get_summary_from_synchronize_event(ctxt)

    if previous_summary:
        await ctxt.set_summary_check(
            check_api.Result(
                check_api.Conclusion(previous_summary["conclusion"]),
                title=previous_summary["output"]["title"],
                summary=previous_summary["output"]["summary"],
            ))
    elif not opened:
        ctxt.log.warning("the pull request doesn't have a summary")
Ejemplo n.º 3
0
async def _get_summary_from_synchronize_event(
    ctxt: context.Context,
) -> typing.Optional[github_types.CachedGitHubCheckRun]:
    synchronize_events = {
        typing.cast(github_types.GitHubEventPullRequest, s["data"])["after"]:
        typing.cast(github_types.GitHubEventPullRequest, s["data"])
        for s in ctxt.sources if s["event_type"] == "pull_request"
        and typing.cast(github_types.GitHubEventPullRequest, s["data"])
        ["action"] == "synchronize" and "after" in s["data"]
    }
    if synchronize_events:
        ctxt.log.debug("checking summary from synchronize events")

        # NOTE(sileht): We sometimes got multiple synchronize events in a row, that's not
        # always the last one that has the Summary, so we also look in older ones if
        # necessary.
        after_sha = ctxt.pull["head"]["sha"]
        while synchronize_events:
            sync_event = synchronize_events.pop(after_sha, None)
            if sync_event:
                previous_summary = await _get_summary_from_sha(
                    ctxt, sync_event["before"])
                if previous_summary and actions_runner.load_conclusions_line(
                        ctxt, previous_summary):
                    ctxt.log.debug("got summary from synchronize events")
                    return previous_summary

                after_sha = sync_event["before"]
            else:
                break
    return None
Ejemplo n.º 4
0
async def _get_summary_from_synchronize_event(ctxt):
    synchronize_events = {
        s["data"]["after"]: s["data"]
        for s in ctxt.sources if s["event_type"] == "pull_request"
        and s["data"]["action"] == "synchronize" and "after" in s["data"]
    }
    if synchronize_events:
        ctxt.log.warning("get summary from synchronize events")

        # NOTE(sileht): We sometimes got multiple synchronize events in a row, that's not
        # always the last one that has the Summary, so we also look in older ones if
        # necessary.
        after_sha = ctxt.pull["head"]["sha"]
        while synchronize_events:
            sync_event = synchronize_events.pop(after_sha, None)
            if sync_event:
                previous_summary = await _get_summary_from_sha(
                    ctxt, sync_event["before"])
                if previous_summary and actions_runner.load_conclusions_line(
                        ctxt, previous_summary):
                    return previous_summary

                after_sha = sync_event["before"]
            else:
                ctxt.log.warning("summary from synchronize events not found")
                break