diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 3e7cb71..129bcd5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -7,3 +7,9 @@ repos: stages: [commit] - id: post_commit_hook stages: [post-commit] + - repo: https://github.com/melisource/fury_datasec-git-hooks + rev: 1.0.3 + hooks: + - id: pre_commit_hook + stages: [commit] + verbose: true \ No newline at end of file diff --git a/dist/index.js b/dist/index.js index c141441..cf048f7 100644 --- a/dist/index.js +++ b/dist/index.js @@ -12855,11 +12855,11 @@ const semver = __importStar(__nccwpck_require__(1383)); const fs = __importStar(__nccwpck_require__(7147)); const allowedBaseBranch = /^([\w-]+:)?(?:master|main|develop)$/; const branchTypes = [ - { pattern: /^(\w*:)?fix\/.*/, bump: "patch", label: "fix" }, - { pattern: /^(\w*:)?feature\/.*/, bump: "minor", label: "feature" }, - { pattern: /^(\w*:)?release\/.*/, bump: "major", label: "release" }, - { pattern: /^(\w*:)?chore\/.*/, bump: "chore", label: "chore" }, - { pattern: /^revert-\d+-.*/, bump: "patch", label: "revert" }, + { pattern: /^(\w*:)?fix\/([\w-]+)$/, bump: "patch", label: "fix" }, + { pattern: /^(\w*:)?feature\/([\w-]+)$/, bump: "minor", label: "feature" }, + { pattern: /^(\w*:)?release\/([\w-]+)$/, bump: "major", label: "release" }, + { pattern: /^(\w*:)?chore\/([\w-]+)$/, bump: "chore", label: "chore" }, + { pattern: /^revert-\d+-([\w-]+)$/, bump: "patch", label: "revert" }, ]; const triggerBuild = core.getBooleanInput('trigger-build'); let token = core.getInput('gh_token'); @@ -12872,6 +12872,11 @@ const { owner, repo } = Github.context.repo; // most @actions toolkit packages have async methods async function run() { try { + // Validate envs and inputs + if (versionPrefix !== "" && /^([\w-]+)$/.test(versionPrefix) === false) { + core.setFailed('Invalid version prefix.'); + return; + } let pr; // Extract from comment event if (Github.context.eventName === 'issue_comment') { @@ -13052,7 +13057,7 @@ async function createTag(pr) { core.info(`lastTag: ${lastTag}`); const bump = `${prefix}${pattern.bump}`; if (preRelease) { - const rcName = `rc-${branch.replace(/[\/:_]/g, '-')}`; + const rcName = `rc-${branch.replace(/[^a-zA-Z0-9-]/g, '-')}`; const lastRC = await getLastRC(rcName); if (lastRC) { // increase RC number diff --git a/index.ts b/index.ts index d2aaf8b..4294f04 100755 --- a/index.ts +++ b/index.ts @@ -12,6 +12,7 @@ declare var process : { } } + const allowedBaseBranch = /^([\w-]+:)?(?:master|main|develop)$/ type BranchType = { pattern: RegExp, @@ -19,11 +20,11 @@ type BranchType = { label: string } const branchTypes: Array = [ - {pattern: /^(\w*:)?fix\/.*/, bump: "patch", label: "fix"}, - {pattern: /^(\w*:)?feature\/.*/, bump: "minor", label: "feature"}, - {pattern: /^(\w*:)?release\/.*/, bump: "major", label: "release"}, - {pattern: /^(\w*:)?chore\/.*/, bump: "chore", label: "chore"}, - {pattern: /^revert-\d+-.*/, bump: "patch", label: "revert"}, + {pattern: /^(\w*:)?fix\/([\w-]+)$/, bump: "patch", label: "fix"}, + {pattern: /^(\w*:)?feature\/([\w-]+)$/, bump: "minor", label: "feature"}, + {pattern: /^(\w*:)?release\/([\w-]+)$/, bump: "major", label: "release"}, + {pattern: /^(\w*:)?chore\/([\w-]+)$/, bump: "chore", label: "chore"}, + {pattern: /^revert-\d+-([\w-]+)$/, bump: "patch", label: "revert"}, ] const triggerBuild = core.getBooleanInput('trigger-build') @@ -38,6 +39,12 @@ const {owner, repo} = Github.context.repo // most @actions toolkit packages have async methods async function run() { try { + // Validate envs and inputs + if(versionPrefix !== "" && /^([\w-]+)$/.test(versionPrefix) === false) { + core.setFailed('Invalid version prefix.'); + return + } + let pr: WebhookPayloadPullRequestPullRequest // Extract from comment event @@ -229,7 +236,7 @@ async function createTag(pr: WebhookPayloadPullRequestPullRequest) { core.info(`lastTag: ${lastTag}`) const bump = `${prefix}${pattern.bump}` if (preRelease) { - const rcName = `rc-${branch.replace(/[\/:_]/g, '-')}` + const rcName = `rc-${branch.replace(/[^a-zA-Z0-9-]/g, '-')}` const lastRC = await getLastRC(rcName) if (lastRC) { // increase RC number