Merge pull request #1 from bentohq/fix-branch-labeler

This commit is contained in:
Josh Dales
2021-09-16 18:40:19 -04:00
committed by GitHub
5 changed files with 25 additions and 5 deletions

View File

@@ -3,3 +3,6 @@ test-branch:
feature-branch:
- branch: "*/feature/*"
bug-branch:
- branch: "{bug,fix}/*"

View File

@@ -105,7 +105,7 @@ describe("run", () => {
});
it("adds labels based on the branch names that match the glob pattern", async () => {
github.context.ref = "test/testing-time";
github.context.payload.pull_request!.head = { ref: "test/testing-time" };
usingLabelerConfigYaml("branches.yml");
await run();
@@ -119,7 +119,9 @@ describe("run", () => {
});
it("adds labels based on branch names that match different glob patterns", async () => {
github.context.ref = "my/feature/that-i-like";
github.context.payload.pull_request!.head = {
ref: "my/feature/that-i-like",
};
usingLabelerConfigYaml("branches.yml");
await run();
@@ -131,6 +133,20 @@ describe("run", () => {
labels: ["feature-branch"],
});
});
it("it can support multiple branches by batching", async () => {
github.context.payload.pull_request!.head = { ref: "fix/123" };
usingLabelerConfigYaml("branches.yml");
await run();
expect(addLabelsMock).toHaveBeenCalledTimes(1);
expect(addLabelsMock).toHaveBeenCalledWith({
owner: "monalisa",
repo: "helloworld",
issue_number: 123,
labels: ["bug-branch"],
});
});
});
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {

2
dist/index.js vendored
View File

@@ -205,7 +205,7 @@ function checkAll(changedFiles, globs) {
}
function checkBranch(glob) {
const matcher = new minimatch_1.Minimatch(glob);
const branchName = github.context.ref;
const branchName = github.context.payload.pull_request.head.ref;
core.debug(` checking "branch" pattern against ${branchName}`);
core.debug(` - ${printPattern(matcher)}`);
if (!matcher.match(branchName)) {

1
package-lock.json generated
View File

@@ -5,6 +5,7 @@
"requires": true,
"packages": {
"": {
"name": "labeler",
"version": "3.0.2",
"license": "MIT",
"dependencies": {

View File

@@ -216,10 +216,10 @@ function checkAll(changedFiles: string[], globs: string[]): boolean {
function checkBranch(glob: string): boolean {
const matcher = new Minimatch(glob);
const branchName = github.context.ref;
const branchName = github.context.payload.pull_request?.head.ref;
core.debug(` checking "branch" pattern against ${branchName}`);
core.debug(` - ${printPattern(matcher)}`);
if (!matcher.match(branchName)) {
if (branchName || !matcher.match(branchName)) {
core.debug(` ${printPattern(matcher)} did not match`);
return false;
}