Skip to content

Commit

Permalink
Merge pull request #5 from tsinis/v0.1.3
Browse files Browse the repository at this point in the history
fix: use "" for case sensitivity flag in reg exp [SHIP]
  • Loading branch information
tsinis authored Apr 9, 2024
2 parents 344ac2c + c04ac9f commit 821c4ae
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 32 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/self_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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)"
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/[email protected].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/[email protected].3`. Here's an example workflow file:

```yaml
name: Auto approve Ship/Show PRs
Expand All @@ -22,7 +22,7 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: tsinis/[email protected].2
- uses: tsinis/[email protected].3
with:
ship-keyword: 'lgtm' # optional, default to 'ship'
show-keyword: 'lgty' # optional, default to 'show'
Expand Down Expand Up @@ -71,7 +71,7 @@ jobs:
pull-requests: write
if: github.actor == 'dependabot[bot]'
steps:
- uses: tsinis/[email protected].2
- uses: tsinis/[email protected].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:
Expand All @@ -92,7 +92,7 @@ jobs:
permissions:
pull-requests: write
steps:
- uses: tsinis/[email protected].2
- uses: tsinis/[email protected].3
with:
pull-request-number: ${{ github.event.inputs.pullRequestNumber }}
```
Expand All @@ -112,7 +112,7 @@ jobs:
pull-requests: write
if: github.actor == 'dependabot[bot]'
steps:
- uses: tsinis/[email protected].2
- uses: tsinis/[email protected].3
with:
review-message: "Auto approved automated PR (from Dependabot)"
```
Expand All @@ -133,7 +133,7 @@ jobs:
ship-show-ask:
runs-on: ubuntu-latest
steps:
- uses: tsinis/[email protected].2
- uses: tsinis/[email protected].3
with:
github-token: ${{ secrets.SOME_USERS_PAT }}
```
Expand All @@ -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`).
27 changes: 16 additions & 11 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
16 changes: 8 additions & 8 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,21 @@ 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,
prNumber: pullRequestNumber,
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(
Expand Down
13 changes: 9 additions & 4 deletions src/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,14 @@ export async function validate({
let strategy: Strategy | undefined = undefined;
fallbackToAsk = fallbackToAsk !== undefined ? fallbackToAsk : false;
const client = github.getOctokit(token, octokitOpts);
console.log(`Case Sensitive: ${caseSensitive}`);
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 {
Expand All @@ -65,8 +67,11 @@ export async function validate({
pull_number: prNumber,
});

const title = pr.title.trim();
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}`);

if (match) {
// Extract the keyword from the match
Expand Down Expand Up @@ -166,5 +171,5 @@ function buildRegexPattern(
const bracketPattern = requireBrackets
? `\\[((${pattern}))\\]|\\(((${pattern}))\\)|\\{((${pattern}))\\}`
: pattern;
return new RegExp(bracketPattern, caseSensitive ? undefined : "i");
return new RegExp(bracketPattern, caseSensitive ? "" : "i");
}

0 comments on commit 821c4ae

Please sign in to comment.