-
Notifications
You must be signed in to change notification settings - Fork 447
Assigns labels based on branch names #203
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
Changes from 25 commits
2bf42e4
ad73546
6c50d09
ee0e0eb
a01b9ae
bce88a9
765934f
827e118
8aa7614
cb5f448
2ced1f3
d9ed3e8
79c0cc7
27a1d89
7624214
2d63815
ab49f7a
2246b66
89f6b77
7aadc17
71fc664
818399d
6e27606
0ad789c
0861fa5
4c74e84
7f8d8e4
c54c5a2
7b1327b
8c59ecc
f2b2513
2343710
cd3a8df
0b6e68d
2daf35a
231de6b
922ffdf
7a5c525
969899d
7d17531
b071d82
0eb9d49
09f0853
ed31b27
da83a18
56347d5
8943ca2
e5b1bdd
2e10ffb
2a5bc55
394a01b
5e6bdf6
84e83a9
f40b387
90ef370
3eec5d8
fc5eb71
e4486e9
e939550
51b763c
c08f5fa
9f259ee
1ce9b35
ef108a9
a988f4e
3af9a47
c31ee1f
17694aa
e9a1777
65b7640
7741e57
64ce5e9
cc1e025
d0d3628
92990c0
d31255f
b25e3a8
1c9c27e
8e6367d
9bfc999
5d0a66e
e51b118
a9e07ce
3bec922
432b275
4967646
4554c0d
5ac9519
ef6ab1b
62f22bd
0b2cfb0
29382eb
fa7f98c
210043e
938f9c9
3ddce51
4be192c
67604ee
b1a2f85
2f1dfd1
7f169bc
d4d4a10
2637d23
c1b0ca7
2a3422a
13e75b4
68a2598
11812c3
9488def
3aa0d43
9cfddd0
51cc5e0
09645fd
34a5bf6
4ac1764
a5bed11
a256a58
57d3407
3352df1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test-branch: | ||
- branch: "test/**" | ||
|
||
feature-branch: | ||
- branch: "*/feature/*" | ||
|
||
bug-branch: | ||
- branch: "{bug,fix}/*" | ||
|
||
array-branch: | ||
- branch: ["array/*"] |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ import { Minimatch, IMinimatch } from "minimatch"; | |
interface MatchConfig { | ||
all?: string[]; | ||
any?: string[]; | ||
branch?: string | string[]; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, the new field name in the yaml config file ( There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. At the moment, the new field (
Potentially, more new fields will be added in the future and such a structure will become non-obvious, non-intuitive. I think we should introduce a new field for changed files as well:
This will be a breaking change, but we're going to release a new major version anyway to fix the bug related to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Interesting so to follow up from your previous comment the we would actually wanna change this to the following: - label name:
- changed-files:
- patterns
- head-branch:
- patterns So that we could add another level for 🤔 Or in the way that - label name:
- changed-files:
- any:
- patterns
- all:
- patterns
- branch:
- head:
- patterns
- base:
- patterns I like that idea 👍 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small follow up question to that - what would we want the defaults to be in the case that these nested options are not provided? - label 1: 'pattern'
- label 2:
- changed-files: 'pattern'
- label 3:
- branch: 'pattern' Currently it defaults to match
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my understanding, the final structure should look like this: - label name:
- changed-files:
- patterns
# or
- any:
- patterns
- all:
- patterns
- head-branch:
- patterns
- base-branch:
- patterns We may want to expand branch settings, for example the base and/or head branches can have ...
- head-branch:
- include:
- patterns
- exclude:
- patterns
- base-branch:
- include:
- patterns
- exclude:
- patterns
... Regarding your question about omitting nested options - I think we should adhere the following approach:
- head-branch:
- patterns
- base-branch:
- patterns There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would having include and exclude options more not come from the pattern that you pass? Regardless avoiding deeply nested objects makes sense for now so I'll start on adding that functionality 👍 |
||
} | ||
|
||
type StringOrMatchConfig = string | MatchConfig; | ||
|
@@ -71,6 +72,15 @@ function getPrNumber(): number | undefined { | |
return pullRequest.number; | ||
} | ||
|
||
function getBranchName(): string | undefined { | ||
const pullRequest = github.context.payload.pull_request; | ||
if (!pullRequest) { | ||
return undefined; | ||
} | ||
|
||
return pullRequest.head?.ref; | ||
} | ||
|
||
async function getChangedFiles( | ||
client: ClientType, | ||
prNumber: number | ||
|
@@ -213,6 +223,42 @@ function checkAll(changedFiles: string[], globs: string[]): boolean { | |
return true; | ||
} | ||
|
||
function matchBranchPattern(matcher: IMinimatch, branchName: string): boolean { | ||
core.debug(` - ${printPattern(matcher)}`); | ||
if (matcher.match(branchName)) { | ||
core.debug(` "branch" pattern matched`); | ||
return true; | ||
} | ||
|
||
core.debug(` ${printPattern(matcher)} did not match`); | ||
return false; | ||
} | ||
|
||
function checkBranch(glob: string | string[]): boolean { | ||
const branchName = getBranchName(); | ||
if (!branchName) { | ||
core.debug(` no branch name`); | ||
return false; | ||
} | ||
|
||
core.debug(` checking "branch" pattern against ${branchName}`); | ||
if (Array.isArray(glob)) { | ||
const matchers = glob.map((g) => new Minimatch(g)); | ||
for (const matcher of matchers) { | ||
if (matchBranchPattern(matcher, branchName)) { | ||
core.debug(` "branch" patterns matched against ${branchName}`); | ||
return true; | ||
} | ||
} | ||
|
||
core.debug(` "branch" patterns did not match against ${branchName}`); | ||
return false; | ||
} else { | ||
const matcher = new Minimatch(glob); | ||
return matchBranchPattern(matcher, branchName); | ||
} | ||
} | ||
|
||
function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { | ||
if (matchConfig.all !== undefined) { | ||
if (!checkAll(changedFiles, matchConfig.all)) { | ||
|
@@ -226,6 +272,12 @@ function checkMatch(changedFiles: string[], matchConfig: MatchConfig): boolean { | |
} | ||
} | ||
|
||
if (matchConfig.branch !== undefined) { | ||
if (!checkBranch(matchConfig.branch)) { | ||
return false; | ||
} | ||
} | ||
|
||
return true; | ||
} | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.