mirror of
https://github.com/actions/labeler.git
synced 2025-12-11 03:58:05 +00:00
Merge pull request #1 from bentohq/fix-branch-labeler
This commit is contained in:
@@ -3,3 +3,6 @@ test-branch:
|
||||
|
||||
feature-branch:
|
||||
- branch: "*/feature/*"
|
||||
|
||||
bug-branch:
|
||||
- branch: "{bug,fix}/*"
|
||||
|
||||
@@ -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
2
dist/index.js
vendored
@@ -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
1
package-lock.json
generated
@@ -5,6 +5,7 @@
|
||||
"requires": true,
|
||||
"packages": {
|
||||
"": {
|
||||
"name": "labeler",
|
||||
"version": "3.0.2",
|
||||
"license": "MIT",
|
||||
"dependencies": {
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user