Skip to content
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

Match branches on the head branch for the PR instead of the temporary PR checkout #1

Merged
merged 7 commits into from
Sep 16, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions __tests__/fixtures/branches.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,6 @@ test-branch:

feature-branch:
- branch: "*/feature/*"

bug-branch:
- branch: "{bug,fix}/*"
20 changes: 18 additions & 2 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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();

Expand All @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
1 change: 1 addition & 0 deletions package-lock.json

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

4 changes: 2 additions & 2 deletions src/labeler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down