Skip to content
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
12 changes: 6 additions & 6 deletions app/matchers.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
export function transferMatcher(text) {
return text.match(/\/transfer ([\dA-Za-z-]+)/);
return text.match(/(?:^| | \r\n|\n)\/transfer ([\dA-Za-z-]+)/);
}

export function closeMatcher(text) {
return text.match(/\/close (not-planned)|\/close/);
return text.match(/(?:^| | \r\n|\n)\/close (not-planned)|\/close/);
}

export function reopenMatcher(text) {
return text.match(/\/reopen/);
return text.match(/(?:^| | \r\n|\n)\/reopen/);
}

export function labelMatcher(text) {
return text.match(/\/label ([\s/A-Za-z\d-,:]+)/);
return text.match(/(?:^| | \r\n|\n)\/label ([ /A-Za-z\d-,:]+)/);
}

export function removeLabelMatcher(text) {
// TODO prevent matching across lines
return text.match(/\/remove-label ([\s/A-Za-z\d-,:]+)/);
return text.match(/(?:^| | \r\n|\n)\/remove-label ([ /A-Za-z\d-,:]+)/);
}

export function reviewerMatcher(text) {
return text.match(/\/reviewers? ([\s/@A-Za-z\d-,]+)/);
return text.match(/(?:^| | \r\n|\n)\/reviewers? ([ /@A-Za-z\d-,]+)/);
}
55 changes: 55 additions & 0 deletions app/matchers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,19 @@ describe("matchers", () => {
test("does not match without a repository name", () => {
const result = transferMatcher("/transfer");

expect(result).toBeFalsy();
});
test("only matches the current line", () => {
const result = transferMatcher("/transfer github-comment-ops\nasda");

expect(result).toBeTruthy();
expect(result[1]).toEqual("github-comment-ops");
});
test("does not match in the middle of a string", () => {
const result = transferMatcher(
"hello world/transfer github-comment-ops\nasda"
);

expect(result).toBeFalsy();
});
});
Expand Down Expand Up @@ -65,6 +78,12 @@ describe("matchers", () => {

expect(result).toBeFalsy();
});

test("does not match in the middle of a string", () => {
const result = reopenMatcher("a string/reopen");

expect(result).toBeFalsy();
});
});

describe("label", () => {
Expand All @@ -74,6 +93,17 @@ describe("matchers", () => {
expect(result).toBeTruthy();
expect(result[1]).toEqual("label1");
});
test("only matches the current line", () => {
const result = labelMatcher("/label label1\nasda");

expect(result).toBeTruthy();
expect(result[1]).toEqual("label1");
});
test("does not match in the middle of a string", () => {
const result = labelMatcher("something cool/label label1\nasda");

expect(result).toBeFalsy();
});
test("does not match input without /label", () => {
const result = labelMatcher("label label1");

Expand Down Expand Up @@ -131,6 +161,19 @@ describe("matchers", () => {
expect(result).toBeTruthy();
expect(result[1]).toEqual("label1,label 2 with spaces,label3");
});
test("only matches the current line", () => {
const result = removeLabelMatcher("/remove-label label1\nasda");

expect(result).toBeTruthy();
expect(result[1]).toEqual("label1");
});
test("does not match in the middle of a string", () => {
const result = removeLabelMatcher(
"something cool/remove-label label1\nasda"
);

expect(result).toBeFalsy();
});
});

describe("reviewer", () => {
Expand Down Expand Up @@ -179,5 +222,17 @@ describe("matchers", () => {
expect(result).toBeTruthy();
expect(result[1]).toEqual("reviewer1 @reviewer2 @org/team");
});

test("only matches the current line", () => {
const result = reviewerMatcher("/reviewer reviewer1\nasda");

expect(result).toBeTruthy();
expect(result[1]).toEqual("reviewer1");
});
test("does not match in the middle of a string", () => {
const result = reviewerMatcher("something cool/reviewer reviewer1\nasda");

expect(result).toBeFalsy();
});
});
});
1 change: 0 additions & 1 deletion app/router.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export async function router(auth, id, payload, verbose) {
const commands = getCommands(id, payload);

if (noneMatch(commands)) {
console.log("none match");
if (verbose) {
console.log("No match for", payload.comment.body);
}
Expand Down