Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Option to not post failure status to github when there is no successful policy #711

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,11 @@ approval_rules:
- "^staging/.*$"
requires:
count: 0

# Settings which affect how policy-bot acts
settings:
# Set the below to true if you only want policy-bot statuses on PRs where the policy has evaluated to true
only_post_success_status: false
```

#### Notes on YAML Syntax
Expand Down
5 changes: 5 additions & 0 deletions policy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ type RemoteConfig struct {
type Config struct {
Policy Policy `yaml:"policy"`
ApprovalRules []*approval.Rule `yaml:"approval_rules"`
Settings Settings `yaml:"settings"`
}

type Settings struct {
OnlyPostSuccessStatus bool `yaml:"only_post_success_status"`
}

type Policy struct {
Expand Down
5 changes: 5 additions & 0 deletions server/handler/eval_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ func (ec *EvalContext) PostStatus(ctx context.Context, state, message string) {
return
}

if state != "success" && ec.Config.Config.Settings.OnlyPostSuccessStatus {
logger.Info().Msg("Skipping status update as it is not success and the setting is enabled to only post status updates on success")
return
}

if !ec.PullContext.IsOpen() {
logger.Info().Msg("Skipping status update because PR state is not open")
return
Expand Down