Skip to content

Commit

Permalink
Add Option to not post failure status to github when there is no succ…
Browse files Browse the repository at this point in the history
…essful policy
  • Loading branch information
RoryDoherty committed Feb 9, 2024
1 parent 63aae55 commit 6a6d063
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
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

0 comments on commit 6a6d063

Please sign in to comment.