Skip to content

Commit ae0d3fc

Browse files
authored
Merge pull request #8 from github/do-not-self-combine
Do not self combine
2 parents 3c94dcc + fb7b0d9 commit ae0d3fc

File tree

3 files changed

+126
-0
lines changed

3 files changed

+126
-0
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ You can also require a set of multiple labels
109109
gh combine owner/repo --labels security,dependencies
110110
```
111111

112+
> Note that the labels are OR'd together. So if a pull request has either label, it will be included in the combined pull request. Meaning that if you use `--labels security,dependencies` and a pull request has the `security` label, it will be included in the combined pull request even if it does not have the `dependencies` label.
113+
112114
### Only Combine Pull Requests that match a given Regex
113115

114116
```bash
@@ -133,6 +135,8 @@ gh combine owner/repo --branch-suffix "-some-cool-feature"
133135
gh combine owner/repo --ignore-labels wip,dependencies
134136
```
135137

138+
> Note that labels are OR'd together. So if a pull request has either label, it will be ignored in the combined pull request. Meaning that if you use `--ignore-labels wip,dependencies` and a pull request has the `wip` label, it will be ignored in the combined pull request even if it does not have the `dependencies` label.
139+
136140
### Update the Resulting Combined Pull Request Branch if Possible
137141

138142
```bash

internal/cmd/match_criteria.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ func PrMatchesCriteria(branch string, prLabels []string) bool {
2828

2929
// checks if a branch matches the branch filtering criteria
3030
func branchMatchesCriteria(branch string) bool {
31+
// Do not attempt to match on existing branches that were created by this CLI
32+
if branch == combineBranchName {
33+
return false
34+
}
35+
3136
// If no branch filters are specified, all branches pass this check
3237
if branchPrefix == "" && branchSuffix == "" && branchRegex == "" {
3338
return true

internal/cmd/match_criteria_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,3 +111,120 @@ func TestLabelsMatch(t *testing.T) {
111111
})
112112
}
113113
}
114+
func TestBranchMatchesCriteria(t *testing.T) {
115+
t.Parallel()
116+
117+
// Define test cases
118+
tests := []struct {
119+
name string
120+
branch string
121+
combineBranch string
122+
prefix string
123+
suffix string
124+
regex string
125+
want bool
126+
}{
127+
{
128+
name: "Branch matches all criteria",
129+
branch: "feature/test",
130+
combineBranch: "combined-prs",
131+
prefix: "feature/",
132+
suffix: "/test",
133+
regex: `^feature/.*$`,
134+
want: true,
135+
},
136+
{
137+
name: "Branch is the combine branch",
138+
branch: "combined-prs",
139+
combineBranch: "combined-prs",
140+
want: false,
141+
},
142+
{
143+
name: "Branch ends with the combine branch",
144+
branch: "fix-combined-prs",
145+
combineBranch: "combined-prs",
146+
want: true,
147+
},
148+
{
149+
name: "No filters specified",
150+
branch: "any-branch",
151+
combineBranch: "combined-prs",
152+
want: true,
153+
},
154+
{
155+
name: "No filters specified and partial match on combine branch name",
156+
branch: "bug/combined-prs-fix",
157+
combineBranch: "combined-prs",
158+
want: true,
159+
},
160+
{
161+
name: "Prefix does not match",
162+
branch: "test/feature",
163+
combineBranch: "combined-prs",
164+
prefix: "feature/",
165+
want: false,
166+
},
167+
{
168+
name: "Suffix does not match",
169+
branch: "feature/test",
170+
combineBranch: "combined-prs",
171+
suffix: "/feature",
172+
want: false,
173+
},
174+
{
175+
name: "Regex does not match",
176+
branch: "test/feature",
177+
combineBranch: "combined-prs",
178+
regex: `^feature/.*`,
179+
want: false,
180+
},
181+
{
182+
name: "Invalid regex pattern",
183+
branch: "feature/test",
184+
combineBranch: "combined-prs",
185+
regex: `^(feature/.*$`,
186+
want: false,
187+
},
188+
{
189+
name: "Branch matches prefix only",
190+
branch: "feature/test",
191+
combineBranch: "combined-prs",
192+
prefix: "feature/",
193+
want: true,
194+
},
195+
{
196+
name: "Branch matches suffix only",
197+
branch: "test/feature",
198+
combineBranch: "combined-prs",
199+
suffix: "/feature",
200+
want: true,
201+
},
202+
{
203+
name: "Branch matches regex only",
204+
branch: "feature/test",
205+
combineBranch: "combined-prs",
206+
regex: `^feature/.*$`,
207+
want: true,
208+
},
209+
}
210+
211+
for _, test := range tests {
212+
t.Run(test.name, func(t *testing.T) {
213+
t.Parallel()
214+
215+
// Set global variables for the test
216+
combineBranchName = test.combineBranch
217+
branchPrefix = test.prefix
218+
branchSuffix = test.suffix
219+
branchRegex = test.regex
220+
221+
// Run the function
222+
got := branchMatchesCriteria(test.branch)
223+
224+
// Check the result
225+
if got != test.want {
226+
t.Errorf("branchMatchesCriteria(%q) = %v; want %v", test.branch, got, test.want)
227+
}
228+
})
229+
}
230+
}

0 commit comments

Comments
 (0)