Skip to content

Commit 7624214

Browse files
authored
Merge pull request #1 from bentohq/fix-branch-labeler
2 parents 765934f + 27a1d89 commit 7624214

File tree

5 files changed

+25
-5
lines changed

5 files changed

+25
-5
lines changed

__tests__/fixtures/branches.yml

+3
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ test-branch:
33

44
feature-branch:
55
- branch: "*/feature/*"
6+
7+
bug-branch:
8+
- branch: "{bug,fix}/*"

__tests__/main.test.ts

+18-2
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ describe("run", () => {
105105
});
106106

107107
it("adds labels based on the branch names that match the glob pattern", async () => {
108-
github.context.ref = "test/testing-time";
108+
github.context.payload.pull_request!.head = { ref: "test/testing-time" };
109109
usingLabelerConfigYaml("branches.yml");
110110
await run();
111111

@@ -119,7 +119,9 @@ describe("run", () => {
119119
});
120120

121121
it("adds labels based on branch names that match different glob patterns", async () => {
122-
github.context.ref = "my/feature/that-i-like";
122+
github.context.payload.pull_request!.head = {
123+
ref: "my/feature/that-i-like",
124+
};
123125
usingLabelerConfigYaml("branches.yml");
124126
await run();
125127

@@ -131,6 +133,20 @@ describe("run", () => {
131133
labels: ["feature-branch"],
132134
});
133135
});
136+
137+
it("it can support multiple branches by batching", async () => {
138+
github.context.payload.pull_request!.head = { ref: "fix/123" };
139+
usingLabelerConfigYaml("branches.yml");
140+
await run();
141+
142+
expect(addLabelsMock).toHaveBeenCalledTimes(1);
143+
expect(addLabelsMock).toHaveBeenCalledWith({
144+
owner: "monalisa",
145+
repo: "helloworld",
146+
issue_number: 123,
147+
labels: ["bug-branch"],
148+
});
149+
});
134150
});
135151

136152
function usingLabelerConfigYaml(fixtureName: keyof typeof yamlFixtures): void {

dist/index.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ function checkAll(changedFiles, globs) {
205205
}
206206
function checkBranch(glob) {
207207
const matcher = new minimatch_1.Minimatch(glob);
208-
const branchName = github.context.ref;
208+
const branchName = github.context.payload.pull_request.head.ref;
209209
core.debug(` checking "branch" pattern against ${branchName}`);
210210
core.debug(` - ${printPattern(matcher)}`);
211211
if (!matcher.match(branchName)) {

package-lock.json

+1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/labeler.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -216,10 +216,10 @@ function checkAll(changedFiles: string[], globs: string[]): boolean {
216216

217217
function checkBranch(glob: string): boolean {
218218
const matcher = new Minimatch(glob);
219-
const branchName = github.context.ref;
219+
const branchName = github.context.payload.pull_request?.head.ref;
220220
core.debug(` checking "branch" pattern against ${branchName}`);
221221
core.debug(` - ${printPattern(matcher)}`);
222-
if (!matcher.match(branchName)) {
222+
if (branchName || !matcher.match(branchName)) {
223223
core.debug(` ${printPattern(matcher)} did not match`);
224224
return false;
225225
}

0 commit comments

Comments
 (0)