diff --git a/.github/scripts/git_issues/generate_jira_issue_data.sh b/.github/scripts/git_issues/generate_jira_issue_data.sh old mode 100755 new mode 100644 index 4be1cf1..d507199 --- a/.github/scripts/git_issues/generate_jira_issue_data.sh +++ b/.github/scripts/git_issues/generate_jira_issue_data.sh @@ -37,29 +37,29 @@ if [[ "${git_issue_event_name}" == "issues" ]]; then if [[ ${git_issue_event_action} == "opened" ]]; then echo "Generating new jira issue description" JIRA_EVENT_DESCRIPTION="*Issue Title:* ${git_issue_title} - *Repository:* ${repository} - *Git Issue id:* ${git_issue_id} - *Git User:* ${git_user} - *Git issue Description:* - ${git_issue_body} - *Git Issue Creation Time:* ${git_issue_created_at} - *Git Issue URL:* ${git_issue_url}" +*Repository:* ${repository} +*Git Issue id:* ${git_issue_id} +*Git User:* ${git_user} +*Git issue Description:* +${git_issue_body} +*Git Issue Creation Time:* ${git_issue_created_at} +*Git Issue URL:* ${git_issue_url}" elif [[ ${git_issue_event_action} == "closed" ]]; then echo "Closing ${akeyless_jira_issue} jira issue description" JIRA_EVENT_DESCRIPTION="*Git Issue has been closed* - *Git issue closed by:* ${git_user} - *Git Issue Update Time:* ${git_issue_updated_at} - *Git Issue URL:* ${git_issue_url}" +*Git issue closed by:* ${git_user} +*Git Issue Update Time:* ${git_issue_updated_at} +*Git Issue URL:* ${git_issue_url}" fi elif [[ ${git_issue_event_name} == "issue_comment" ]]; then echo "Generation new comment on jira issue ${akeyless_jira_issue}" JIRA_EVENT_DESCRIPTION="*Git Issue has new comment* - *Git User:* ${git_user} - *Git issue comment:* - ${git_issue_comment_body} - *Git Issue Comment Creation Time:* ${git_issue_comment_created_at} - *Git Issue Comment URL:* ${git_issue_comment_url}" +*Git User:* ${git_user} +*Git issue comment:* +${git_issue_comment_body} +*Git Issue Comment Creation Time:* ${git_issue_comment_created_at} +*Git Issue Comment URL:* ${git_issue_comment_url}" fi delimiter="$(openssl rand -hex 8)" diff --git a/.github/workflows/git-issues-jira-automation.yaml b/.github/workflows/git-issues-jira-automation.yaml index 001b798..e1c9c97 100644 --- a/.github/workflows/git-issues-jira-automation.yaml +++ b/.github/workflows/git-issues-jira-automation.yaml @@ -1,7 +1,7 @@ name: Git Issues Jira Automation Pipeline on: issues: - types: [opened, closed] + types: [opened] issue_comment: types: [created] @@ -12,71 +12,7 @@ env: jobs: git-issues-jira-automation: - name: git-issues-jira-automation - runs-on: ubuntu-20.04 - steps: - - name: Check out code - uses: actions/checkout@v4 - - - name: Login to Akeyless jira - uses: atlassian/gajira-login@master - env: - JIRA_BASE_URL: ${{ secrets.AKEYLESS_JIRA_BASE_URL }} - JIRA_USER_EMAIL: ${{ secrets.AKEYLESS_JIRA_USER_EMAIL }} - JIRA_API_TOKEN: ${{ secrets.AKEYLESS_JIRA_ISSUE_TOKEN }} - - - name: Generate Git Issue Event Description For Jira - env: - GITHUB_CONTEXT: ${{ toJson(github) }} - run: .github/scripts/git_issues/generate_jira_issue_data.sh - - - name: Find Existing Jira issue - if: env.jira_issue_exist == 'true' - uses: atlassian/gajira-find-issue-key@v3 - with: - string: ${{ env.akeyless_jira_issue }} - - - name: Create Jira issue - if: env.jira_issue_exist == 'false' && github.event.action == 'opened' - id: create-jira-issue - uses: atlassian/gajira-create@v3 - with: - project: ASM - issuetype: Bug-Field - summary: ${{ env.jira_issue_summary }} - description: ${{ env.jira_description }} - fields: ${{ env.jira_fields }} - - - name: Log created issue - if: steps.create-jira-issue.outcome == 'success' - run: echo "Jira Issue ${{ steps.create-jira-issue.outputs.issue }} was created" - - - name: Label Create Git Issue - uses: actions/github-script@v7 - if: steps.create-jira-issue.outcome == 'success' - with: - script: | - github.rest.issues.addLabels({ - issue_number: context.issue.number, - owner: context.repo.owner, - repo: context.repo.repo, - labels: ["${{ steps.create-jira-issue.outputs.issue }}"] - }) - - - name: Add Comment On Jira issue - if: env.jira_issue_exist == 'true' && (github.event_name == 'issue_comment' || (github.event_name == 'issues' && github.event.action == 'closed')) - uses: atlassian/gajira-comment@v3 - with: - issue: ${{ env.akeyless_jira_issue }} - comment: ${{ env.jira_description }} - - - name: Transition issue - if: github.event_name == 'issues' && github.event.action == 'closed' && env.jira_issue_exist == 'true' - id: transition - uses: atlassian/gajira-transition@v3 - with: - issue: ${{ env.akeyless_jira_issue }} - transition: "Done" - - - name: Issue summary - run: echo '### Github issue automation summary -${{ steps.create-jira-issue.outputs.issue }} ${{ env.jira_description }}! :rocket:' >> $GITHUB_STEP_SUMMARY \ No newline at end of file + uses: akeyless-community/terraform-provider-akeyless/.github/workflows/reusable-git-issues-jira-automation.yaml@main + with: + caller_repo_name: ${{ github.event.repository.name }} + secrets: inherit \ No newline at end of file diff --git a/.github/workflows/reusable-git-issues-jira-automation.yaml b/.github/workflows/reusable-git-issues-jira-automation.yaml new file mode 100644 index 0000000..58d0928 --- /dev/null +++ b/.github/workflows/reusable-git-issues-jira-automation.yaml @@ -0,0 +1,89 @@ +name: Reusable Git Issues Jira Automation Pipeline +on: + workflow_call: + inputs: + caller_repo_name: + type: string + +env: + AKEYLESS_JIRA_BASE_URL: ${{ secrets.AKEYLESS_JIRA_BASE_URL }} + AKEYLESS_JIRA_USER_EMAIL: ${{ secrets.AKEYLESS_JIRA_USER_EMAIL }} + AKEYLESS_JIRA_ISSUE_TOKEN: ${{ secrets.AKEYLESS_JIRA_ISSUE_TOKEN }} + caller_repo_name: ${{ inputs.caller_repo_name }} + +jobs: + git-issues-jira-automation: + name: ${{ inputs.caller_repo_name }}-git-issues-jira-automation + runs-on: ubuntu-20.04 + steps: + - name: Checkout terraform-provider-akeyless code + uses: actions/checkout@v4 + with: + repository: akeyless-community/terraform-provider-akeyless + ref: main + token: ${{ secrets.GITHUB_TOKEN }} + + - name: Login to Akeyless jira + uses: atlassian/gajira-login@master + env: + JIRA_BASE_URL: ${{ secrets.AKEYLESS_JIRA_BASE_URL }} + JIRA_USER_EMAIL: ${{ secrets.AKEYLESS_JIRA_USER_EMAIL }} + JIRA_API_TOKEN: ${{ secrets.AKEYLESS_JIRA_ISSUE_TOKEN }} + + - name: Generate Git Issue Event Description For Jira + env: + GITHUB_CONTEXT: ${{ toJson(github) }} + run: .github/scripts/git_issues/generate_jira_issue_data.sh + + - name: Find Existing Jira issue + if: env.jira_issue_exist == 'true' + uses: atlassian/gajira-find-issue-key@v3 + with: + string: ${{ env.akeyless_jira_issue }} + + - name: Create Jira issue + if: env.jira_issue_exist == 'false' && github.event.action == 'opened' + id: create-jira-issue + uses: atlassian/gajira-create@v3 + with: + project: ASM + issuetype: Bug-Field + summary: ${{ env.jira_issue_summary }} + description: ${{ env.jira_description }} + fields: ${{ env.jira_fields }} + + - name: Log created issue + if: steps.create-jira-issue.outcome == 'success' + run: echo "Jira Issue ${{ steps.create-jira-issue.outputs.issue }} was created" + + - name: Add Comment On Jira issue + if: env.jira_issue_exist == 'true' && (github.event_name == 'issue_comment' || (github.event_name == 'issues' && github.event.action == 'closed')) + uses: atlassian/gajira-comment@v3 + with: + issue: ${{ env.akeyless_jira_issue }} + comment: ${{ env.jira_description }} + + - name: Prepare Slack Message On Success + if: env.jira_issue_exist == 'false' && github.event.action == 'opened' + id: slack-message-success-creator + run: | + SLACK_MESSAGE="${jira_description} + *Jira Ticket*: https://akeyless.atlassian.net/browse/${{steps.create-jira-issue.outputs.issue}}" + delimiter="$(openssl rand -hex 8)" + echo "slack-message<<${delimiter}" >> $GITHUB_ENV + echo "${SLACK_MESSAGE//$/%0A}" >> $GITHUB_ENV + echo "${delimiter}" >> $GITHUB_ENV + + - name: Slack Success Notification + if: env.jira_issue_exist == 'false' && github.event.action == 'opened' + uses: rtCamp/action-slack-notify@v2 + env: + SLACK_CHANNEL: 'github-public-repo-issues' + SLACK_COLOR: ${{ job.status }} + SLACK_ICON: https://github.com/rtCamp.png?size=48 + SLACK_TITLE: 'New Git Issue Created' + SLACK_MESSAGE: '${{ env.slack-message }}' + SLACK_USERNAME: githubBot + SLACK_WEBHOOK: ${{ secrets.SLACK_GITHUB_ISSUES_WEBHOOK }} + MSG_MINIMAL: true + SLACK_FOOTER: GitHub Issue To Jira Automation