Skip to content

Commit

Permalink
fix: baseBranch wrong field accessed (#154)
Browse files Browse the repository at this point in the history
* chore: test basebranch pr

* fix: baseBranch wrong field accessed

* add more test

* fix warnings

* fix tests
  • Loading branch information
fuxingloh authored Jul 23, 2022
1 parent 77066d4 commit fb9bc28
Show file tree
Hide file tree
Showing 6 changed files with 86 additions and 66 deletions.
79 changes: 79 additions & 0 deletions __tests__/matcher/base-branch.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import match from "../../src/matcher/base-branch";
import * as github from "@actions/github";
import { Config } from "../../src/config";

function getMatchedLabels(config: Config): string[] {
// @ts-ignore
return match(null, config);
}

const config: Config = {
version: "v1",
labels: [
{
label: "release",
matcher: {
baseBranch: "^release/.*"
}
},
{
label: "master",
matcher: {
baseBranch: "master"
}
}
]
};

describe("empty", function() {
it("no payload should be undefined", async function() {
github.context.payload = {};
expect(getMatchedLabels(config)).toEqual([]);
});

it("pull_request should be empty", async function() {
github.context.payload = {
pull_request: {
number: 1,
title: "nothing interesting",
base: {
ref: "main"
}
}
};

expect(getMatchedLabels(config)).toEqual([]);
});
});

describe("pull_request", () => {
it("should have release", async function() {
github.context.payload = {
pull_request: {
number: 1,
title: "spaceship",
base: {
ref: "release/1.0"
}
}
};

const labels = getMatchedLabels(config);
expect(labels).toEqual(["release"]);
});

it("should have main", async function() {
github.context.payload = {
pull_request: {
number: 1,
title: "spaceship",
base: {
ref: "master"
}
}
};

const labels = getMatchedLabels(config);
expect(labels).toEqual(["master"]);
});
});
59 changes: 0 additions & 59 deletions __tests__/matcher/baseBranch.test.ts

This file was deleted.

8 changes: 4 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import title from './matcher/title'
import body from './matcher/body'
import comment from './matcher/comment'
import branch from './matcher/branch'
import baseBranch from './matcher/baseBranch'
import baseBranch from './matcher/base-branch'
import commits from './matcher/commits'
import files from './matcher/files'
import author from './matcher/author'
Expand Down
2 changes: 1 addition & 1 deletion src/matcher/baseBranch.ts → src/matcher/base-branch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function match(

return config
.labels!.filter(value => {
return matcherRegex({regex: value.matcher?.branch, text: ref})
return matcherRegex({regex: value.matcher?.baseBranch, text: ref})
})
.map(value => value.label)
}

0 comments on commit fb9bc28

Please sign in to comment.