Skip to content

Commit 700346a

Browse files
authored
Allow hyphens as separators in branch name. (#4)
* Allow hyphens as separators in branch name. * Add tests for getClubhouseStoryIdFromBranchName * Update index.js and add documentation.
1 parent 95bad7c commit 700346a

File tree

4 files changed

+30
-5
lines changed

4 files changed

+30
-5
lines changed

README.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,12 @@ It works for the opposite use-case, assuming that the Clubhouse story exists
4646
_before_ the pull request is created.
4747

4848
This Action will specifically check for branch names that follow the naming
49-
convention for this built-in integration. Any branch name that looks like
50-
`*/ch####/*` will be ignored by this Action, on the assumption that a Clubhouse
51-
story already exists for the pull request.
49+
convention for this built-in integration. Any branch name that contains
50+
`ch####` will be ignored by this Action, on the assumption that a Clubhouse
51+
story already exists for the pull request. The `ch####` must be separated
52+
from leading or following text with either a `/` or a `-`. So, branches
53+
named `ch1`, `prefix/ch23`, `prefix-ch123`, `ch3456/suffix`, `ch3456-suffux`,
54+
`prefix/ch987/suffix` would match, but `xch123` and `ch987end` would not.
5255

5356
## Customizing the Pull Request Comment
5457

__tests__/util.test.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,28 @@ test("getClubhouseWorkflowState", async () => {
9494
scope.done();
9595
});
9696

97+
test("getClubhouseStoryIdFromBranchName matching", () => {
98+
[["ch1", "1"],
99+
["ch89/something", "89"],
100+
["ch99-something", "99"],
101+
["prefix-1/ch123", "123"],
102+
["prefix-1-ch321", "321"],
103+
["prefix/ch5678/suffix", "5678"],
104+
["prefix-ch6789/suffix-more", "6789"],
105+
["prefix/ch7890-suffix", "7890"],
106+
["prefix-ch0987-suffix-extra", "0987"]].forEach(item => {
107+
const id = util.getClubhouseStoryIdFromBranchName(item[0]);
108+
expect(id).toEqual(item[1]);
109+
});
110+
});
111+
112+
test("getClubhouseStoryIdFromBranchName non-matching", () => {
113+
["prefix/ch8765+suffix", "ch554X", "ach8765", "this_ch1234"].forEach(branch => {
114+
const id = util.getClubhouseStoryIdFromBranchName(branch);
115+
expect(id).toBeNull();
116+
})
117+
});
118+
97119
test("getClubhouseURLFromPullRequest", async () => {
98120
const payload = {
99121
pull_request: {

dist/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ exports.updateClubhouseStoryById = exports.addCommentToPullRequest = exports.get
279279
const core = __importStar(__webpack_require__(186));
280280
const github = __importStar(__webpack_require__(438));
281281
exports.CLUBHOUSE_STORY_URL_REGEXP = /https:\/\/app.clubhouse.io\/\w+\/story\/(\d+)(\/[A-Za-z0-9-]*)?/;
282-
exports.CLUBHOUSE_BRANCH_NAME_REGEXP = /^(?:.+\/)?ch(\d+)(?:\/.+)?$/;
282+
exports.CLUBHOUSE_BRANCH_NAME_REGEXP = /^(?:.+[-\/])?ch(\d+)(?:[-\/].+)?$/;
283283
/**
284284
* Convert a Map to a sorted string representation. Useful for debugging.
285285
*

src/util.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import {
1313
} from "./types";
1414

1515
export const CLUBHOUSE_STORY_URL_REGEXP = /https:\/\/app.clubhouse.io\/\w+\/story\/(\d+)(\/[A-Za-z0-9-]*)?/;
16-
export const CLUBHOUSE_BRANCH_NAME_REGEXP = /^(?:.+\/)?ch(\d+)(?:\/.+)?$/;
16+
export const CLUBHOUSE_BRANCH_NAME_REGEXP = /^(?:.+[-\/])?ch(\d+)(?:[-\/].+)?$/;
1717

1818
interface Stringable {
1919
toString(): string;

0 commit comments

Comments
 (0)