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 draft status to signals #321

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
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
12 changes: 8 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,23 @@ merge:
# Pull requests with auto merge enabled are added to the trigger.
auto_merge: true

# Pull requests in draft status are added to the trigger.
draft: true

# "ignore" defines the set of pull request ignored by bulldozer. If the
# section is missing, bulldozer considers all pull requests. It takes the
# same keys as the "trigger" section.
ignore:
labels: ["do not merge"]
comment_substrings: ["==DO_NOT_MERGE=="]
draft: true

# "method" defines the merge method. The available options are "merge",
# "rebase", "squash", and "ff-only".
method: squash

##### branch_method has been DEPRECATED in favor of merge_method #####
#
#
# Allows the merge method that is used when auto-merging a PR to be different
# target branch. The keys of the hash are the target branch name, and the values are the merge method that
# will be used for PRs targeting that branch. The valid values are the same as for the "method" key.
Expand All @@ -142,9 +146,9 @@ merge:

# Allows the merge method that is used when auto-merging a PR to be different
# based on trigger criteria. The first method where ALL triggers match will
# be used. Otherwise, the method specified previously in "merge.method" will
# be used. Otherwise, the method specified previously in "merge.method" will
# be used.
# - ALL trigger criteria must match, unlike merge/trigger where ANY match
# - ALL trigger criteria must match, unlike merge/trigger where ANY match
# will trigger bulldozer.
# - This will override any branch_method logic if one of the methods is
# triggered
Expand Down Expand Up @@ -428,7 +432,7 @@ previously installed.

### Reducing Update Commit and CI Pressure

The Bulldozer "Update" feature is useful when keeping branches up-to-date, but
The Bulldozer "Update" feature is useful when keeping branches up-to-date, but
can cause lots of pressure on CI build systems and Github when there are many pull requests
open on a single repository.

Expand Down
24 changes: 24 additions & 0 deletions bulldozer/signals.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ type BranchesSignal []string
type BranchPatternsSignal []string
type MaxCommitsSignal int
type AutoMergeSignal bool
type DraftSignal bool

type Signals struct {
Labels LabelsSignal `yaml:"labels"`
Expand All @@ -51,6 +52,7 @@ type Signals struct {
BranchPatterns BranchPatternsSignal `yaml:"branch_patterns"`
MaxCommits MaxCommitsSignal `yaml:"max_commits"`
AutoMerge AutoMergeSignal `yaml:"auto_merge"`
Draft DraftSignal `yaml:"draft"`
}

func (signal LabelsSignal) Enabled() bool {
Expand Down Expand Up @@ -85,6 +87,10 @@ func (signal AutoMergeSignal) Enabled() bool {
return bool(signal)
}

func (signal DraftSignal) Enabled() bool {
return bool(signal)
}

func (s Signals) Enabled() bool {
return s.Labels.Enabled() ||
s.CommentSubstrings.Enabled() ||
Expand Down Expand Up @@ -149,6 +155,7 @@ func (s Signals) MatchesAny(ctx context.Context, pullCtx pull.Context, tag strin
&s.Branches,
&s.BranchPatterns,
&s.AutoMerge,
&s.Draft,
}

for _, signal := range signals {
Expand Down Expand Up @@ -366,3 +373,20 @@ func (signal AutoMergeSignal) Matches(ctx context.Context, pullCtx pull.Context,

return false, "", nil
}

func (signal DraftSignal) Matches(ctx context.Context, pullCtx pull.Context, tag string) (bool, string, error) {
logger := zerolog.Ctx(ctx)

if !signal.Enabled() {
logger.Debug().Msgf("No valid draft pr value has been provided to match against")
return false, "", nil
}

isDraft := pullCtx.IsDraft(ctx)

if isDraft {
return true, "pull request is a draft", nil
}

return false, "", nil
}
10 changes: 10 additions & 0 deletions bulldozer/signals_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestSignalsMatchesAny(t *testing.T) {
Branches: []string{"develop"},
BranchPatterns: []string{"test/.*", "^feature/.*$"},
AutoMerge: true,
Draft: true,
}

ctx := context.Background()
Expand Down Expand Up @@ -141,6 +142,13 @@ func TestSignalsMatchesAny(t *testing.T) {
Matches: true,
Reason: "pull request is configured to auto merge",
},
"draftMatch": {
PullContext: &pulltest.MockPullContext{
IsDraftValue: true,
},
Matches: true,
Reason: "pull request is a draft",
},
}

for name, test := range tests {
Expand Down Expand Up @@ -272,6 +280,7 @@ func TestSignalsMatchesAll(t *testing.T) {
BranchPatterns: []string{"test/.*", "^feature/.*$"},
MaxCommits: 2,
AutoMerge: true,
Draft: true,
}

ctx := context.Background()
Expand All @@ -292,6 +301,7 @@ func TestSignalsMatchesAll(t *testing.T) {
{SHA: "2", Message: "commit 2"},
},
AutoMergeValue: true,
IsDraftValue: true,
},
Matches: true,
Reason: `pull request matches all testlist signals`,
Expand Down