Skip to content

LoadError posts failing policy-bot status in repos with no policy #1179

@dblinkhorn

Description

@dblinkhorn

When policy-bot has installation access to a repo, it attempts to discover the repo's policy before evaluating a PR. If no policy exists, the current behavior is to skip posting status. But if policy discovery hits a non-404 GitHub API error, policy-bot posts a failing error status. This causes noisy failures in repos that do not define a policy and do not require policy-bot as a check.

The README states that a missing policy should not post a status:

If a policy does not exist in the repository or in the shared organization
repository, `policy-bot` does not post a status check on the pull request.

The error noise in repos that don't utilize policy-bot is caused by this code in eval_context.go:

case fc.LoadError != nil:
    msg := fmt.Sprintf("Error loading policy from %s", fc.Source)
    logger.Warn().Err(fc.LoadError).Msg(msg)

    ec.PostStatus(ctx, "error", msg)
    return nil, errors.Wrapf(fc.LoadError, "failed to load policy: %s: %s", fc.Source, fc.Path)

Ideally, the fix would distinguish “missing policy” from “unknown due to API error” without reporting failures in repos that don’t use policy-bot. One option is to stop posting a failing status on LoadError entirely, but where policy-bot is required, users will see policy-bot not reporting/completing for that commit, without any error details provided. Another option is to post LoadError status only for repos/branches where policy-bot is required by branch protection/rulesets.

Hoping to get some advice/discussion here from maintainers. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions