Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 46 additions & 9 deletions .github/workflows/find-jira-id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ name: Has jira-id

on:
push:
branches: [ main ]

jobs:
dumpcontext:
Expand All @@ -13,17 +12,55 @@ jobs:
GITHUB_CONTEXT: ${{ toJSON(github) }}
run: echo "$GITHUB_CONTEXT"
verify-pull-request-title:
if: ${{ github.event_name == 'pull_request'}}
#if: ${{ github.event_name == 'pull_request'}}
runs-on: ubuntu-latest
steps:
- uses: deepakputhraya/action-pr-title@v1.0.2
- uses: actions/github-script@v6
with:
regex: '(\w)+(\s\w)*' # Regex the title should match.
allowed_prefixes: 'Bump,ID-,MINID-,PBLEID-,MP-,KRR-,PF-,AOS-' # title should start with the given prefix
prefix_case_sensitive: false # title prefix are case insensitive
min_length: 10 # Min length of the title
max_length: 100 # Max length of the title
github_token: ${{ github.token }} # Default: ${{ github.token }}
script: |
const REGEX = new RegExp("^[^…]+$"); // Title must match this regex
const MIN_LENGTH = 10; // Min length of the title
const MAX_LENGTH = 100; // Max length of the title (-1 is no max)
const ALLOWED_PREFIXES = ['Bump','ID-','MIN-','PBLEID-','MP-','KRR-','PF-','AOS-','SP-']; // Title must start with one of these prefixes
const PREFIX_CASE_SENSITIVE = false; // Whether the prefix is case sensitive

const validateTitlePrefix = (title, prefix) =>
PREFIX_CASE_SENSITIVE
? title.startsWith(prefix)
: title.toLowerCase().startsWith(prefix.toLowerCase());

const { title } = context.payload.pull_request;
if (!REGEX.test(title)) {
core.setFailed(
`Pull Request title "${title}" failed to match regex - ${REGEX}`
);
return;
}

if (title.length < MIN_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is smaller than the minimum length - ${MIN_LENGTH}`
);
return;
}

if (MAX_LENGTH > 0 && title.length > MAX_LENGTH) {
core.setFailed(
`Pull Request title "${title}" is greater than the maximum length - ${MAX_LENGTH}`
);
return;
}

core.info(`Allowed Prefixes: ${ALLOWED_PREFIXES}`);
if (
ALLOWED_PREFIXES.length &&
!ALLOWED_PREFIXES.some((prefix) => validateTitlePrefix(title, prefix))
) {
core.setFailed(
`Pull Request title "${title}" did not start with any of the required prefixes - ${ALLOWED_PREFIXES}`
);
return;
}
find-jira-id:
runs-on: ubuntu-latest
steps:
Expand Down