Skip to content

Commit 6a6d063

Browse files
committed
Add Option to not post failure status to github when there is no successful policy
1 parent 63aae55 commit 6a6d063

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,11 @@ approval_rules:
9797
- "^staging/.*$"
9898
requires:
9999
count: 0
100+
101+
# Settings which affect how policy-bot acts
102+
settings:
103+
# Set the below to true if you only want policy-bot statuses on PRs where the policy has evaluated to true
104+
only_post_success_status: false
100105
```
101106
102107
#### Notes on YAML Syntax

policy/policy.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,11 @@ type RemoteConfig struct {
3737
type Config struct {
3838
Policy Policy `yaml:"policy"`
3939
ApprovalRules []*approval.Rule `yaml:"approval_rules"`
40+
Settings Settings `yaml:"settings"`
41+
}
42+
43+
type Settings struct {
44+
OnlyPostSuccessStatus bool `yaml:"only_post_success_status"`
4045
}
4146

4247
type Policy struct {

server/handler/eval_context.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,11 @@ func (ec *EvalContext) PostStatus(ctx context.Context, state, message string) {
195195
return
196196
}
197197

198+
if state != "success" && ec.Config.Config.Settings.OnlyPostSuccessStatus {
199+
logger.Info().Msg("Skipping status update as it is not success and the setting is enabled to only post status updates on success")
200+
return
201+
}
202+
198203
if !ec.PullContext.IsOpen() {
199204
logger.Info().Msg("Skipping status update because PR state is not open")
200205
return

0 commit comments

Comments
 (0)