-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* refactor(additional features): add separator and anywhere in title features - bump action to Node.js 20 - update dependencies - add optional separator parameter - add optional keyAnywhereInTitle parameter - update docs - add eslint config file BREAKING CHANGE: Now requires Node.js 20 * refactor(additional features): add separator and anywhere in title features - bump action to Node.js 20 - update dependencies - add optional separator parameter - add optional keyAnywhereInTitle parameter - update docs - add eslint config file BREAKING CHANGE: Now requires Node.js 20 * docs(separator): fix default docs for separator - move default docs for separator in readme * test(tests): reset environment variables on each test - reset environment variables on each test * ci(qodana): add qodana quality scan - add qodana workflow * ci(qodana): change release of qodana - switch to qodana action 2023.2.8 * ci(tests): fix typo in test workflow - fix typo in test workflow * ci(qodana): install node dependencies - install node dependencies in qodana workflow * test(ci): set environment variables at start of tests - set environment variables at start of tests * test(regex): fix eslint errors in regex - fix eslint errors in regex * refactor(refactor): move logic to main.ts - move most logic to main.ts - don't need to call run in internal tests
- Loading branch information
Showing
19 changed files
with
34,337 additions
and
12,646 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
module.exports = { | ||
"env": { | ||
"browser": true, | ||
"es2021": true | ||
}, | ||
"extends": [ | ||
"eslint:recommended", | ||
"plugin:@typescript-eslint/recommended" | ||
], | ||
"overrides": [ | ||
{ | ||
"env": { | ||
"node": true | ||
}, | ||
"files": [ | ||
".eslintrc.{js,cjs}" | ||
], | ||
"parserOptions": { | ||
"sourceType": "script" | ||
} | ||
} | ||
], | ||
"parser": "@typescript-eslint/parser", | ||
"parserOptions": { | ||
"ecmaVersion": "latest", | ||
"sourceType": "module" | ||
}, | ||
"plugins": [ | ||
"@typescript-eslint" | ||
], | ||
"rules": { | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: Qodana | ||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
qodana: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- name: Use Node.js 20.x | ||
uses: actions/setup-node@v1 | ||
with: | ||
node-version: 20.x | ||
- uses: actions/cache@v2 | ||
with: | ||
path: ~/.npm | ||
key: ${{ runner.os }}-node-qodana-${{ hashFiles('**/package-lock.json') }} | ||
restore-keys: | | ||
${{ runner.os }}-node- | ||
- run: npm ci | ||
- name: 'Qodana Scan' | ||
uses: JetBrains/[email protected] | ||
env: | ||
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
node_modules/ | ||
node_modules/ | ||
.idea/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v12 | ||
v20 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,51 +1,144 @@ | ||
import * as github from "@actions/github"; | ||
import * as core from "@actions/core"; | ||
import { readFileSync } from "fs"; | ||
import { getPullRequestTitle, getRegex } from "../src"; | ||
import { getPullRequestTitle, getRegex } from "../src/main"; | ||
|
||
const projectKeyInputName = "projectKey"; | ||
const separatorKeyInputName = "separator"; | ||
const keyAnywhereInTitle = "keyAnywhereInTitle"; | ||
|
||
const resetEnvironmentVariables = () => { | ||
process.env[`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}`] = | ||
""; | ||
process.env[ | ||
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = ""; | ||
process.env[`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}`] = | ||
"false"; | ||
}; | ||
|
||
resetEnvironmentVariables(); | ||
|
||
describe("index", () => { | ||
describe("getPullRequestTitle", () => { | ||
beforeEach(() => { | ||
delete process.env["GITHUB_EVENT_PATH"]; | ||
}); | ||
it("can get the title from the context", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/valid-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }) | ||
); | ||
const title = getPullRequestTitle(); | ||
expect(title).toBe("Test Title"); | ||
}); | ||
|
||
it("raises an exception if the event is not for a pull_request", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/wrong-event-type-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: 'utf8' }) | ||
); | ||
expect(getPullRequestTitle).toThrowError("This action should only be run with Pull Request Events"); | ||
}) | ||
}); | ||
|
||
describe("getRegex", () => { | ||
const name = "projectKey"; | ||
it("gets the default when no project key is provided", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = ""; | ||
const regex = getRegex(); | ||
let defaultRegex = /(?<=^|[a-z]\-|[\s\p{Punct}&&[^\-]])([A-Z][A-Z0-9_]*-\d+)(?![^\W_])(\s)+(.)+/; | ||
expect(regex).toEqual(defaultRegex); | ||
expect(regex.test("PR-4 this is valid")).toBe(true); | ||
}); | ||
|
||
it("uses a project key if it exists", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "AB"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(\\s)+(.)+`)); | ||
expect(regex.test("AB-43 stuff and things")).toBe(true); | ||
}); | ||
|
||
it("throws an exception if the provided project key is not valid", () => { | ||
process.env[`INPUT_${name.replace(/ /g, '_').toUpperCase()}`] = "aB"; | ||
expect(getRegex).toThrowError("Project Key \"aB\" is invalid"); | ||
}); | ||
}); | ||
}); | ||
describe("getPullRequestTitle", () => { | ||
beforeEach(() => { | ||
delete process.env["GITHUB_EVENT_PATH"]; | ||
resetEnvironmentVariables(); | ||
}); | ||
it("can get the title from the context", () => { | ||
process.env["GITHUB_EVENT_PATH"] = __dirname + "/valid-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }), | ||
); | ||
const title = getPullRequestTitle(); | ||
expect(title).toBe("Test Title"); | ||
}); | ||
|
||
it("raises an exception if the event is not for a pull_request", () => { | ||
process.env["GITHUB_EVENT_PATH"] = | ||
__dirname + "/wrong-event-type-context.json"; | ||
github.context.payload = JSON.parse( | ||
readFileSync(process.env.GITHUB_EVENT_PATH, { encoding: "utf8" }), | ||
); | ||
expect(getPullRequestTitle).toThrow( | ||
"This action should only be run with Pull Request Events", | ||
); | ||
}); | ||
}); | ||
|
||
describe("getRegex", () => { | ||
beforeEach(() => resetEnvironmentVariables()); | ||
it("gets the default when no project key is provided", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = ""; | ||
const regex = getRegex(); | ||
const defaultRegex = | ||
// eslint-disable-next-line no-useless-escape | ||
/(?<=^|[a-z]-|[\s\p{Punct}&[^\-]])([A-Z][A-Z0-9_]*-\d+)(?![^\W_])(\s)+(.)+/; | ||
expect(regex).toEqual(defaultRegex); | ||
expect(regex.test("PR-4 this is valid")).toBe(true); | ||
}); | ||
|
||
it("uses a project key if it exists", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "AB"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(\\s)+(.)+`)); | ||
expect(regex.test("AB-43 stuff and things")).toBe(true); | ||
}); | ||
|
||
it("throws an exception if the provided project key is not valid", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "aB"; | ||
expect(getRegex).toThrow('Project Key "aB" is invalid'); | ||
}); | ||
|
||
it("uses a project key and a colon separator if they exist", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "AB"; | ||
process.env[ | ||
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = ":"; | ||
process.env[ | ||
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}` | ||
] = "false"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(:)+(\\S)+(.)+`)); | ||
expect(regex.test("AB-43: stuff and things")).toBe(false); | ||
expect(regex.test("AB-123: PR Title")).toBe(false); | ||
expect(regex.test("AB-43:stuff and things")).toBe(true); | ||
expect(regex.test("AB-123:PR Title")).toBe(true); | ||
}); | ||
|
||
it("uses a project key and an underscore separator if they exist", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "AB"; | ||
process.env[ | ||
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "_"; | ||
process.env[ | ||
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}` | ||
] = "false"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(^AB-){1}(\\d)+(_)+(\\S)+(.)+`)); | ||
expect(regex.test("AB-43_stuff and things")).toBe(true); | ||
expect(regex.test("AB-123_PR Title")).toBe(true); | ||
}); | ||
|
||
it("uses a project key if it exists anywhere in the title", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "AB"; | ||
process.env[ | ||
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}` | ||
] = "true"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+(\\s)+(.)+`)); | ||
expect(regex.test("other words AB-43 stuff and things")).toBe(true); | ||
}); | ||
|
||
it("uses a project key and a colon separator if they exist anywhere in the title", () => { | ||
process.env[ | ||
`INPUT_${projectKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = "AB"; | ||
process.env[ | ||
`INPUT_${separatorKeyInputName.replace(/ /g, "_").toUpperCase()}` | ||
] = ":"; | ||
process.env[ | ||
`INPUT_${keyAnywhereInTitle.replace(/ /g, "_").toUpperCase()}` | ||
] = "true"; | ||
const regex = getRegex(); | ||
expect(regex).toEqual(new RegExp(`(.)*(AB-){1}(\\d)+(:)+(\\S)+(.)+`)); | ||
expect(regex.test("other words AB-43: stuff and things")).toBe(false); | ||
expect(regex.test("other words AB-123: PR Title")).toBe(false); | ||
expect(regex.test("other words AB-43:stuff and things")).toBe(true); | ||
expect(regex.test("other words AB-123:PR Title")).toBe(true); | ||
expect(regex.test("AB-43:stuff and things")).toBe(true); | ||
expect(regex.test("AB-123:PR Title")).toBe(true); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.