From fecad30d35ecfd80b1f72c7c0e74af7587fb6800 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:29:47 +0200 Subject: [PATCH 1/9] fix: use "" for case sensitivity flag in reg exp --- README.md | 14 +++++++------- dist/index.js | 2 +- package.json | 2 +- src/validate.ts | 2 +- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 5021eee..3cd4d96 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ This action will get information about the preferred ship/show/ask strategy of t ## Usage instructions -Create a workflow file (e.g. `.github/workflows/ship-show-ask.yml`) that contains a step that `uses: tsinis/ship-show-ask@v0.1.2`. Here's an example workflow file: +Create a workflow file (e.g. `.github/workflows/ship-show-ask.yml`) that contains a step that `uses: tsinis/ship-show-ask@v0.1.3`. Here's an example workflow file: ```yaml name: Auto approve Ship/Show PRs @@ -22,7 +22,7 @@ jobs: permissions: pull-requests: write steps: - - uses: tsinis/ship-show-ask@v0.1.2 + - uses: tsinis/ship-show-ask@v0.1.3 with: ship-keyword: 'lgtm' # optional, default to 'ship' show-keyword: 'lgty' # optional, default to 'show' @@ -71,7 +71,7 @@ jobs: pull-requests: write if: github.actor == 'dependabot[bot]' steps: - - uses: tsinis/ship-show-ask@v0.1.2 + - uses: tsinis/ship-show-ask@v0.1.3 ``` If you want to use this action from a workflow file that doesn't run on the `pull_request` or `pull_request_target` events, use the `pull-request-number` input: @@ -92,7 +92,7 @@ jobs: permissions: pull-requests: write steps: - - uses: tsinis/ship-show-ask@v0.1.2 + - uses: tsinis/ship-show-ask@v0.1.3 with: pull-request-number: ${{ github.event.inputs.pullRequestNumber }} ``` @@ -112,7 +112,7 @@ jobs: pull-requests: write if: github.actor == 'dependabot[bot]' steps: - - uses: tsinis/ship-show-ask@v0.1.2 + - uses: tsinis/ship-show-ask@v0.1.3 with: review-message: "Auto approved automated PR (from Dependabot)" ``` @@ -133,7 +133,7 @@ jobs: ship-show-ask: runs-on: ubuntu-latest steps: - - uses: tsinis/ship-show-ask@v0.1.2 + - uses: tsinis/ship-show-ask@v0.1.3 with: github-token: ${{ secrets.SOME_USERS_PAT }} ``` @@ -156,4 +156,4 @@ If you're using a [CODEOWNERS file](https://docs.github.com/en/github/creating-c ## Development and release process -Each major version corresponds to a branch (e.g. `v0.1`, `v1.0`). Releases are tagged with semver-style version numbers (e.g. `v0.1.2`). +Each major version corresponds to a branch (e.g. `v0.1`, `v1.0`). Releases are tagged with semver-style version numbers (e.g. `v0.1.3`). diff --git a/dist/index.js b/dist/index.js index b0627f8..eadf5c8 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29339,7 +29339,7 @@ function buildRegexPattern(shipKeyword, showKeyword, askKeyword, requireBrackets const bracketPattern = requireBrackets ? `\\[((${pattern}))\\]|\\(((${pattern}))\\)|\\{((${pattern}))\\}` : pattern; - return new RegExp(bracketPattern, caseSensitive ? undefined : "i"); + return new RegExp(bracketPattern, caseSensitive ? "" : "i"); } diff --git a/package.json b/package.json index 05bf447..08a691a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "ship-show-ask", - "version": "0.1.2", + "version": "0.1.3", "description": "GitHub Action for a Ship, Show, Ask branching strategy from PR title", "main": "dist/main.ts", "scripts": { diff --git a/src/validate.ts b/src/validate.ts index f97966b..abbe615 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -166,5 +166,5 @@ function buildRegexPattern( const bracketPattern = requireBrackets ? `\\[((${pattern}))\\]|\\(((${pattern}))\\)|\\{((${pattern}))\\}` : pattern; - return new RegExp(bracketPattern, caseSensitive ? undefined : "i"); + return new RegExp(bracketPattern, caseSensitive ? "" : "i"); } From ddbcda7dfce2d1a1df6c999adabd3ff992105607 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:31:08 +0200 Subject: [PATCH 2/9] refactor(ci): update self test --- .github/workflows/self_test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/self_test.yml b/.github/workflows/self_test.yml index 967e792..80c90ef 100644 --- a/.github/workflows/self_test.yml +++ b/.github/workflows/self_test.yml @@ -16,7 +16,7 @@ jobs: uses: ./ with: add-label: true - case-sensitive: true + case-sensitive: false fallback-to-ask: true require-brackets: true review-message: "Auto approved Ship or Ask PRs (from Dependabot/Author)" From 62b297641081f396b385080b8b79fc6b8ee75cbd Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:40:32 +0200 Subject: [PATCH 3/9] refactor: added more console logs for debugging case-sensitive issue --- src/validate.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/validate.ts b/src/validate.ts index abbe615..654c97d 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -68,6 +68,10 @@ export async function validate({ const title = pr.title.trim(); const match = title.match(regex); + console.log(`Regex: ${regex}`); + console.log(`Title: "${title}"`); + console.log(`Match: ${match}`); + if (match) { // Extract the keyword from the match // If using the above regex, the keyword will be in one of these groups From 514feef47c4594bf27c11a9680b5a64315ea6b41 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:41:33 +0200 Subject: [PATCH 4/9] feat: npm run build --- dist/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/dist/index.js b/dist/index.js index eadf5c8..d92dfe6 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29255,6 +29255,9 @@ function validate(_a) { }); const title = pr.title.trim(); const match = title.match(regex); + console.log(`Regex: ${regex}`); + console.log(`Title: "${title}"`); + console.log(`Match: ${match}`); if (match) { // Extract the keyword from the match // If using the above regex, the keyword will be in one of these groups From bfb650f4c55304da6c08bfd3a95647b7cf3fd368 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 11:57:06 +0200 Subject: [PATCH 5/9] fix: normalize input title --- dist/index.js | 8 +++++++- src/validate.ts | 10 +++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/dist/index.js b/dist/index.js index d92dfe6..64a8c95 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29253,8 +29253,14 @@ function validate(_a) { repo, pull_number: prNumber, }); - const title = pr.title.trim(); + const title = pr.title.trim().normalize(); + console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); + console.log(`Match Result: ${match}`); + console.log(title + .split("") + .map((c) => c.charCodeAt(0).toString(16)) + .join(" ")); console.log(`Regex: ${regex}`); console.log(`Title: "${title}"`); console.log(`Match: ${match}`); diff --git a/src/validate.ts b/src/validate.ts index 654c97d..504865d 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -65,8 +65,16 @@ export async function validate({ pull_number: prNumber, }); - const title = pr.title.trim(); + const title = pr.title.trim().normalize(); + console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); + console.log(`Match Result: ${match}`); + console.log( + title + .split("") + .map((c) => c.charCodeAt(0).toString(16)) + .join(" "), + ); console.log(`Regex: ${regex}`); console.log(`Title: "${title}"`); From bbae5195ea7d9a2043ce2d0c0ddb4870e9ba825d Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:03:57 +0200 Subject: [PATCH 6/9] fix: remove any quotes from the pr title --- dist/index.js | 6 ++---- src/validate.ts | 7 ++----- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/dist/index.js b/dist/index.js index 64a8c95..b9e0f0c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29253,7 +29253,8 @@ function validate(_a) { repo, pull_number: prNumber, }); - const title = pr.title.trim().normalize(); + console.log(`Regex: ${regex}`); + const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); console.log(`Match Result: ${match}`); @@ -29261,9 +29262,6 @@ function validate(_a) { .split("") .map((c) => c.charCodeAt(0).toString(16)) .join(" ")); - console.log(`Regex: ${regex}`); - console.log(`Title: "${title}"`); - console.log(`Match: ${match}`); if (match) { // Extract the keyword from the match // If using the above regex, the keyword will be in one of these groups diff --git a/src/validate.ts b/src/validate.ts index 504865d..6d0642c 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -65,7 +65,8 @@ export async function validate({ pull_number: prNumber, }); - const title = pr.title.trim().normalize(); + console.log(`Regex: ${regex}`); + const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); console.log(`Match Result: ${match}`); @@ -76,10 +77,6 @@ export async function validate({ .join(" "), ); - console.log(`Regex: ${regex}`); - console.log(`Title: "${title}"`); - console.log(`Match: ${match}`); - if (match) { // Extract the keyword from the match // If using the above regex, the keyword will be in one of these groups From e1bf18e57f29f31e3d3363e0f8feef30b3f3edce Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:09:50 +0200 Subject: [PATCH 7/9] refactor: add console log for debugging case-sensitive issue --- dist/index.js | 1 + src/validate.ts | 1 + 2 files changed, 2 insertions(+) diff --git a/dist/index.js b/dist/index.js index b9e0f0c..481b12c 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29254,6 +29254,7 @@ function validate(_a) { pull_number: prNumber, }); console.log(`Regex: ${regex}`); + console.log(`Case Sensitive: ${caseSensitive}`); const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); diff --git a/src/validate.ts b/src/validate.ts index 6d0642c..eb57225 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -66,6 +66,7 @@ export async function validate({ }); console.log(`Regex: ${regex}`); + console.log(`Case Sensitive: ${caseSensitive}`); const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); From bb8cdb53a4d2e7dd90c38cd784bfd5581355ffd5 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:16:33 +0200 Subject: [PATCH 8/9] refactor: case sensitivity and require brackets handling in validate.ts --- dist/index.js | 11 +++++------ src/validate.ts | 15 ++++++--------- 2 files changed, 11 insertions(+), 15 deletions(-) diff --git a/dist/index.js b/dist/index.js index 481b12c..7ff11b4 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29244,7 +29244,11 @@ function validate(_a) { let strategy = undefined; fallbackToAsk = fallbackToAsk !== undefined ? fallbackToAsk : false; const client = github.getOctokit(token, octokitOpts); - const regex = buildRegexPattern(shipKeyword || strategy_1.Strategy.Ship, showKeyword || strategy_1.Strategy.Show, askKeyword || strategy_1.Strategy.Ask, requireBrackets !== undefined ? requireBrackets : true, caseSensitive !== undefined ? caseSensitive : false); + caseSensitive = String(caseSensitive).toLowerCase() === "true"; + console.log(`Case Sensitive: ${caseSensitive}`); + requireBrackets = String(requireBrackets).toLowerCase() === "true"; + console.log(`Require Brackets: ${requireBrackets}`); + const regex = buildRegexPattern(shipKeyword || strategy_1.Strategy.Ship, showKeyword || strategy_1.Strategy.Show, askKeyword || strategy_1.Strategy.Ask, requireBrackets, caseSensitive); try { const { owner, repo } = context.repo; core.info(`Fetching pull request information`); @@ -29254,15 +29258,10 @@ function validate(_a) { pull_number: prNumber, }); console.log(`Regex: ${regex}`); - console.log(`Case Sensitive: ${caseSensitive}`); const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); console.log(`Match Result: ${match}`); - console.log(title - .split("") - .map((c) => c.charCodeAt(0).toString(16)) - .join(" ")); if (match) { // Extract the keyword from the match // If using the above regex, the keyword will be in one of these groups diff --git a/src/validate.ts b/src/validate.ts index eb57225..e354fa2 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -48,12 +48,16 @@ export async function validate({ let strategy: Strategy | undefined = undefined; fallbackToAsk = fallbackToAsk !== undefined ? fallbackToAsk : false; const client = github.getOctokit(token, octokitOpts); + caseSensitive = String(caseSensitive).toLowerCase() === "true"; + console.log(`Case Sensitive: ${caseSensitive}`); + requireBrackets = String(requireBrackets).toLowerCase() === "true"; + console.log(`Require Brackets: ${requireBrackets}`); const regex = buildRegexPattern( shipKeyword || Strategy.Ship, showKeyword || Strategy.Show, askKeyword || Strategy.Ask, - requireBrackets !== undefined ? requireBrackets : true, - caseSensitive !== undefined ? caseSensitive : false, + requireBrackets, + caseSensitive, ); try { @@ -66,17 +70,10 @@ export async function validate({ }); console.log(`Regex: ${regex}`); - console.log(`Case Sensitive: ${caseSensitive}`); const title = pr.title.trim().normalize().replace(/"/g, ""); console.log(`Actual PR Title Before Match: "${title}"`); const match = title.match(regex); console.log(`Match Result: ${match}`); - console.log( - title - .split("") - .map((c) => c.charCodeAt(0).toString(16)) - .join(" "), - ); if (match) { // Extract the keyword from the match From c04ac9f6279ef9c074755ffec2303dafa73aa709 Mon Sep 17 00:00:00 2001 From: Roman Cinis <52065414+tsinis@users.noreply.github.com> Date: Tue, 9 Apr 2024 12:21:40 +0200 Subject: [PATCH 9/9] fix: input params compare --- dist/index.js | 18 ++++++++---------- src/main.ts | 16 ++++++++-------- src/validate.ts | 2 -- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/dist/index.js b/dist/index.js index 7ff11b4..ffdd01e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -29112,10 +29112,10 @@ function run() { const shipKeyword = core.getInput("ship-keyword"); const showKeyword = core.getInput("show-keyword"); const askKeyword = core.getInput("ask-keyword"); - const caseSensitive = Boolean(core.getInput("case-sensitive")); - const addLabel = Boolean(core.getInput("add-label")); - const requireBrackets = Boolean(core.getInput("require-brackets")); - const fallbackToAsk = Boolean(core.getInput("fallback-to-ask")); + const caseSensitive = core.getInput("case-sensitive") === "true"; + const addLabel = core.getInput("add-label") === "true"; + const requireBrackets = core.getInput("require-brackets") === "true"; + const fallbackToAsk = core.getInput("fallback-to-ask") === "true"; const strategy = yield (0, validate_1.validate)({ token, context: github.context, @@ -29123,10 +29123,10 @@ function run() { shipKeyword: shipKeyword || undefined, showKeyword: showKeyword || undefined, askKeyword: askKeyword || undefined, - caseSensitive: caseSensitive || undefined, - addLabel: addLabel || undefined, - requireBrackets: requireBrackets || undefined, - fallbackToAsk: fallbackToAsk || undefined, + caseSensitive: caseSensitive, + addLabel: addLabel, + requireBrackets: requireBrackets, + fallbackToAsk: fallbackToAsk, }); if (strategy !== strategy_1.Strategy.Ship && strategy !== strategy_1.Strategy.Show) { return console.log("This is not a Ship or Show PR! Skipping approval.", strategy); @@ -29244,9 +29244,7 @@ function validate(_a) { let strategy = undefined; fallbackToAsk = fallbackToAsk !== undefined ? fallbackToAsk : false; const client = github.getOctokit(token, octokitOpts); - caseSensitive = String(caseSensitive).toLowerCase() === "true"; console.log(`Case Sensitive: ${caseSensitive}`); - requireBrackets = String(requireBrackets).toLowerCase() === "true"; console.log(`Require Brackets: ${requireBrackets}`); const regex = buildRegexPattern(shipKeyword || strategy_1.Strategy.Ship, showKeyword || strategy_1.Strategy.Show, askKeyword || strategy_1.Strategy.Ask, requireBrackets, caseSensitive); try { diff --git a/src/main.ts b/src/main.ts index 6c08a54..083ef84 100644 --- a/src/main.ts +++ b/src/main.ts @@ -13,10 +13,10 @@ export async function run() { const shipKeyword = core.getInput("ship-keyword"); const showKeyword = core.getInput("show-keyword"); const askKeyword = core.getInput("ask-keyword"); - const caseSensitive = Boolean(core.getInput("case-sensitive")); - const addLabel = Boolean(core.getInput("add-label")); - const requireBrackets = Boolean(core.getInput("require-brackets")); - const fallbackToAsk = Boolean(core.getInput("fallback-to-ask")); + const caseSensitive = core.getInput("case-sensitive") === "true"; + const addLabel = core.getInput("add-label") === "true"; + const requireBrackets = core.getInput("require-brackets") === "true"; + const fallbackToAsk = core.getInput("fallback-to-ask") === "true"; const strategy = await validate({ token, context: github.context, @@ -24,10 +24,10 @@ export async function run() { shipKeyword: shipKeyword || undefined, showKeyword: showKeyword || undefined, askKeyword: askKeyword || undefined, - caseSensitive: caseSensitive || undefined, - addLabel: addLabel || undefined, - requireBrackets: requireBrackets || undefined, - fallbackToAsk: fallbackToAsk || undefined, + caseSensitive: caseSensitive, + addLabel: addLabel, + requireBrackets: requireBrackets, + fallbackToAsk: fallbackToAsk, }); if (strategy !== Strategy.Ship && strategy !== Strategy.Show) { return console.log( diff --git a/src/validate.ts b/src/validate.ts index e354fa2..02adc0b 100644 --- a/src/validate.ts +++ b/src/validate.ts @@ -48,9 +48,7 @@ export async function validate({ let strategy: Strategy | undefined = undefined; fallbackToAsk = fallbackToAsk !== undefined ? fallbackToAsk : false; const client = github.getOctokit(token, octokitOpts); - caseSensitive = String(caseSensitive).toLowerCase() === "true"; console.log(`Case Sensitive: ${caseSensitive}`); - requireBrackets = String(requireBrackets).toLowerCase() === "true"; console.log(`Require Brackets: ${requireBrackets}`); const regex = buildRegexPattern( shipKeyword || Strategy.Ship,