-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c50fa79
commit c7a9611
Showing
2 changed files
with
82 additions
and
37 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,82 @@ | ||
name: "Lint and Link PR title" | ||
|
||
on: | ||
pull_request: | ||
types: | ||
- opened | ||
- edited | ||
- reopened | ||
- synchronize | ||
|
||
jobs: | ||
lint: | ||
name: Validate PR title And link Jira Issue | ||
runs-on: ubuntu-22.04 | ||
env: | ||
JIRA_COMMENT_REGEX: "^.*Jira.*" | ||
steps: | ||
- uses: Slashgear/action-check-pr-title@860e8dc639f8e60335a6f5e8936ba67ed2536890 #v4.3.0 | ||
id: lint | ||
with: | ||
regexp: "\\[(#?[A-Z]*-[0-9]*( |, )?){1,}\\]" # Regex the title should match. | ||
continue-on-error: true | ||
|
||
- name: Find Jira Comment | ||
uses: peter-evans/find-comment@81e2da3af01c92f83cb927cf3ace0e085617c556 #v2 | ||
id: fc | ||
with: | ||
issue-number: ${{ github.event.pull_request.number }} | ||
comment-author: "github-actions[bot]" | ||
body-regex: "${{ env.JIRA_COMMENT_REGEX }}" | ||
|
||
- name: Extract Jira Issue to Link | ||
id: extract_jira_issue | ||
if: steps.lint.outcome == 'success' | ||
run: | | ||
PR_TITLE=$(echo "${{ github.event.pull_request.title }}") | ||
ISSUES_STR=$(awk -F'\\[|\\]' '{print $2}' <<< "$PR_TITLE" | sed "s/#//g" | sed "s/,//g") | ||
ISSUES=($ISSUES_STR) | ||
JIRA_ISSUE=$(echo ${ISSUES_STR##* }) | ||
MARKDOWN_CARRIAGE_RETURN="<br>" | ||
MARKDOWN_PREFIX="- Link to" | ||
JIRA_COMMENT_MARKDOWN="This Pull Request refers to Jira issues:<br>" | ||
if [[ ${#ISSUES[@]} -eq 1 ]] | ||
then | ||
JIRA_COMMENT_MARKDOWN="This Pull Request refers to the following Jira issue" | ||
MARKDOWN_PREFIX="" | ||
fi | ||
for ISSUE in "${ISSUES[@]}" | ||
do | ||
JIRA_COMMENT_MARKDOWN+="$MARKDOWN_PREFIX [$ISSUE](https://pagopa.atlassian.net/browse/$ISSUE) $MARKDOWN_CARRIAGE_RETURN" | ||
done | ||
echo "JIRA_ISSUE=$JIRA_ISSUE" >> $GITHUB_ENV | ||
echo "JIRA_COMMENT_MARKDOWN=$JIRA_COMMENT_MARKDOWN" >> $GITHUB_ENV | ||
- name: Create Jira Link comment | ||
if: steps.lint.outcome == 'success' | ||
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808 #v2 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
## Jira Pull Request Link ## | ||
${{ env.JIRA_COMMENT_MARKDOWN }} | ||
edit-mode: replace | ||
- name: Create Empty Jira Link comment | ||
if: steps.lint.outcome != 'success' | ||
uses: peter-evans/create-or-update-comment@5adcb0bb0f9fb3f95ef05400558bdb3f329ee808 #v2 | ||
with: | ||
comment-id: ${{ steps.fc.outputs.comment-id }} | ||
issue-number: ${{ github.event.pull_request.number }} | ||
body: | | ||
## Jira Pull request Link ## | ||
It seems this Pull Request has no issues that refers to Jira!!! | ||
Please check it out. | ||
edit-mode: replace | ||
- name: Failure message | ||
if: steps.lint.outcome != 'success' | ||
run: | | ||
echo "Pull request title (${{ github.event.pull_request.title }}) is not properly formatted or it is not related to any Jira issue" | ||
exit 1 |