-
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
Merged
Merged
Changes from 47 commits
Commits
Show all changes
119 commits
Select commit
Hold shift + click to select a range
2bf42e4
Add branch to MatchConfig interface
joshdales ad73546
Add function for checking branches
joshdales 6c50d09
include checkBranch in checkMatch
joshdales ee0e0eb
Add a new fixture and test for the branch checking
joshdales a01b9ae
Add another test to make sure that partial branch naming works
joshdales bce88a9
Update new test description
joshdales 765934f
Run build
joshdales 827e118
Fix PR branch labeler
amiel 8aa7614
Run build
amiel cb5f448
Use correct branch name and update tests
amiel 2ced1f3
Run build
amiel d9ed3e8
Format
amiel 79c0cc7
Include a test for branching
amiel 27a1d89
Update src/labeler.ts
amiel 7624214
Merge pull request #1 from bentohq/fix-branch-labeler
joshdales 2d63815
Allow branch config to be an array as well
joshdales ab49f7a
Add tests for array branh labelling
joshdales 2246b66
Run build
joshdales 89f6b77
minor adjustment for successful branch matching.
joshdales 7aadc17
Update the tests for applying multiple branch based labels
joshdales 71fc664
run the build script
joshdales 818399d
Merge branch 'main' into main
joshdales 6e27606
Update README with reference to branch options
joshdales 0ad789c
Merge branch 'main' into main
joshdales 0861fa5
Run the build command
joshdales 4c74e84
Fix typo in the README
joshdales 7f8d8e4
Merge branch 'main' into main
joshdales c54c5a2
Run prettier
joshdales 7b1327b
Run the build command
joshdales 8c59ecc
Rename the getBranchName helper
joshdales f2b2513
Update the matching to use a regexp rather than minimatch
joshdales 2343710
Move all the branch checking into its own file
joshdales cd3a8df
Create a test file for branch
joshdales 0b6e68d
Add options for getting the head or base branch
joshdales 2daf35a
Add an extra test now that we can check the base branch
joshdales 231de6b
Remove the branch option and replace with just head-branch and base-b…
joshdales 922ffdf
Remove deprecated IMinimatch import from labeler.ts
joshdales 7a5c525
Create new interfaces for MatchConfig
joshdales 969899d
Add the changedFiles key and update logic in labeler
joshdales 7d17531
Update the labeler tests
joshdales b071d82
Run the build command
joshdales 0eb9d49
reverse the conditions of checkMatch
joshdales 09f0853
Fix some typos in the branch checks
joshdales ed31b27
Rename some functions and variables to match what they are doing
joshdales da83a18
Make sure that the changed files config values are an array
joshdales 56347d5
Add unit tests for toBranchMatchConfig
joshdales 8943ca2
Merge pull request #3 from joshdales/new-config-structure
joshdales e5b1bdd
Update the README with documentation about the new config structure
joshdales 2e10ffb
Reference minimatch in docs
joshdales 2a5bc55
Fix bad test descriptions
joshdales 394a01b
Make getBranchName argument non-optional
joshdales 5e6bdf6
update the example workflow in the readme
joshdales 84e83a9
Merge branch 'main' into main
joshdales f40b387
Correct errors and typos in the README
joshdales 90ef370
Merge branch 'actions:main' into main
joshdales 3eec5d8
Update the syntax for checking a match
joshdales fc5eb71
Revert "reverse the conditions of checkMatch"
joshdales e4486e9
Throw an error if the config is the wrong type
joshdales e939550
Simplfy the conditions in toBranchMatchConfig
joshdales 51b763c
Update comments in getMatchConfigs to represent updated types
joshdales c08f5fa
Condense assignment of further config options in toChangedFilesMatchC…
joshdales 9f259ee
Rename checkGlobs to checkMatchConfigs and check each property
joshdales 1ce9b35
Move all changedFiles logic into it's own file
joshdales ef108a9
Convert the yaml output to a matchConfig in getLabelConfigMapFromObject
joshdales a988f4e
Add todo tests for changedFiles
joshdales 3af9a47
Add unit tests for toChangedFilesMatchConfig
joshdales c31ee1f
Add more unit tests for changedFiles.ts
joshdales 17694aa
Update the argument type for toMatchConfig
joshdales e9a1777
Fix linting and formatting
joshdales 65b7640
Add unit tests for toMatchConfig
joshdales 7741e57
Run the build command
joshdales 64ce5e9
Update README with better description for branches
joshdales cc1e025
Update object assignment in toChangedFilesMatchConfig
joshdales d0d3628
Add extra tests and use toEqual matcher.
joshdales 92990c0
Don't allow empty changed-files objects through
joshdales d31255f
Make sure that empty config options don't accidently label things
joshdales b25e3a8
Better wording for the new test
joshdales 1c9c27e
Run the build command
joshdales 8e6367d
Merge branch 'main' into main
joshdales 9bfc999
Run build and fix bad merge
joshdales 5d0a66e
Run the build command again
joshdales e51b118
Change the structure of the config
joshdales a9e07ce
Add some new tests
joshdales 3bec922
Add any and all functions for both checks
joshdales 432b275
Get all the tests passings
joshdales 4967646
Run the build command
joshdales 4554c0d
Add a bunch more tests
joshdales 5ac9519
Update the README
joshdales ef6ab1b
Add function for checking if any path matches
joshdales 62f22bd
Run the build command
joshdales 0b2cfb0
Im an idiot, bad copy pasta
joshdales 29382eb
Build command
joshdales fa7f98c
Yikes, still missed that
joshdales 210043e
Run the build command
joshdales 938f9c9
Update the readme a little more
joshdales 3ddce51
Update the debug values
joshdales 4be192c
Run the build command
joshdales 67604ee
Update more debugging statements
joshdales b1a2f85
Update debugging indentation on the branch checks
joshdales 2f1dfd1
Adjust the indenting again
joshdales 7f169bc
Merge pull request #4 from joshdales/another-config-setup
joshdales d4d4a10
Have a single isMatch for checking changed files
joshdales 2637d23
Add test for when not all globs match any changed file
joshdales c1b0ca7
Run the build command
joshdales 2a3422a
Better description for the new test
joshdales 13e75b4
minor update to the readme
joshdales 68a2598
Merge branch 'actions:main' into main
joshdales 11812c3
Revert "Have a single isMatch for checking changed files"
joshdales 9488def
Update tests and build
joshdales 3aa0d43
Better test description
joshdales 9cfddd0
Consolidate the new any change files test into the old one
joshdales 51cc5e0
Update text in test descriptions and logging
joshdales 09645fd
Move the allowed Matchconfig keys into a constant
joshdales 34a5bf6
Update the validation when there are no options in the matchConfigs
joshdales 4ac1764
Add a guard clause to stop false changed-files positives
joshdales a5bed11
Run the build command
joshdales a256a58
Add check for empty objects in checkAll
joshdales 57d3407
Better check for empty configs in checkAll
joshdales 3352df1
Bring test I accidently deleted
joshdales File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,155 @@ | ||
import { | ||
getBranchName, | ||
checkBranch, | ||
toBranchMatchConfig, | ||
BranchMatchConfig | ||
} from '../src/branch'; | ||
import * as github from '@actions/github'; | ||
|
||
jest.mock('@actions/core'); | ||
jest.mock('@actions/github'); | ||
|
||
describe('getBranchName', () => { | ||
describe('when the pull requests base branch is requested', () => { | ||
it('returns the base branch name', () => { | ||
const result = getBranchName('base'); | ||
expect(result).toEqual('base-branch-name'); | ||
}); | ||
}); | ||
|
||
describe('when the pull requests head branch is requested', () => { | ||
it('returns the head branch name', () => { | ||
const result = getBranchName('head'); | ||
expect(result).toEqual('head-branch-name'); | ||
}); | ||
}); | ||
|
||
describe('when no branch is specified', () => { | ||
it('returns the head branch name', () => { | ||
const result = getBranchName(); | ||
expect(result).toEqual('head-branch-name'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('checkBranch', () => { | ||
beforeEach(() => { | ||
github.context.payload.pull_request!.head = { | ||
ref: 'test/feature/123' | ||
}; | ||
github.context.payload.pull_request!.base = { | ||
ref: 'main' | ||
}; | ||
}); | ||
|
||
describe('when a single pattern is provided', () => { | ||
describe('and the pattern matches the head branch', () => { | ||
it('returns true', () => { | ||
const result = checkBranch(['^test']); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('and the pattern does not match the head branch', () => { | ||
it('returns false', () => { | ||
const result = checkBranch(['^feature/']); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when multiple patterns are provided', () => { | ||
describe('and at least one pattern matches', () => { | ||
it('returns true', () => { | ||
const result = checkBranch(['^test/', '^feature/']); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('and all patterns match', () => { | ||
it('returns true', () => { | ||
const result = checkBranch(['^test/', '/feature/']); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
|
||
describe('and no patterns match', () => { | ||
it('returns false', () => { | ||
const result = checkBranch(['^feature/', '/test$']); | ||
expect(result).toBe(false); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the branch to check is specified as the base branch', () => { | ||
describe('and the pattern matches the base branch', () => { | ||
it('returns true', () => { | ||
const result = checkBranch(['^main$'], 'base'); | ||
expect(result).toBe(true); | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('toBranchMatchConfig', () => { | ||
describe('when there are no branch keys in the config', () => { | ||
const config = {'changed-files': [{any: ['testing']}]}; | ||
it('returns an empty object', () => { | ||
const result = toBranchMatchConfig(config); | ||
expect(result).toMatchObject({}); | ||
}); | ||
}); | ||
|
||
describe('when the config contains a head-branch option', () => { | ||
const config = {'head-branch': ['testing']}; | ||
it('sets headBranch in the matchConfig', () => { | ||
const result = toBranchMatchConfig(config); | ||
expect(result).toMatchObject<BranchMatchConfig>({ | ||
headBranch: ['testing'] | ||
}); | ||
}); | ||
|
||
describe('and the matching option is a string', () => { | ||
const stringConfig = {'head-branch': 'testing'}; | ||
|
||
it('sets headBranch in the matchConfig', () => { | ||
const result = toBranchMatchConfig(stringConfig); | ||
expect(result).toMatchObject<BranchMatchConfig>({ | ||
headBranch: ['testing'] | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the config contains a base-branch option', () => { | ||
const config = {'base-branch': ['testing']}; | ||
it('sets headBranch in the matchConfig', () => { | ||
joshdales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result = toBranchMatchConfig(config); | ||
expect(result).toMatchObject<BranchMatchConfig>({ | ||
baseBranch: ['testing'] | ||
}); | ||
}); | ||
|
||
describe('and the matching option is a string', () => { | ||
const stringConfig = {'base-branch': 'testing'}; | ||
|
||
it('sets headBranch in the matchConfig', () => { | ||
joshdales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result = toBranchMatchConfig(stringConfig); | ||
expect(result).toMatchObject<BranchMatchConfig>({ | ||
baseBranch: ['testing'] | ||
}); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('when the config contains both a base-branch and head-branch option', () => { | ||
const config = {'base-branch': ['testing'], 'head-branch': ['testing']}; | ||
it('sets headBranch in the matchConfig', () => { | ||
joshdales marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const result = toBranchMatchConfig(config); | ||
expect(result).toMatchObject<BranchMatchConfig>({ | ||
baseBranch: ['testing'], | ||
headBranch: ['testing'] | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
test-branch: | ||
- head-branch: "^test/" | ||
|
||
feature-branch: | ||
- head-branch: "/feature/" | ||
|
||
bug-branch: | ||
- head-branch: "^bug/|fix/" | ||
|
||
array-branch: | ||
- head-branch: ["^array/"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
touched-a-pdf-file: | ||
- any: ['*.pdf'] | ||
- changed-files: | ||
- any: ['*.pdf'] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.