diff --git a/.github/workflows/dependabot2jira.yml b/.github/workflows/dependabot2jira.yml new file mode 100644 index 00000000000..a65e931aa73 --- /dev/null +++ b/.github/workflows/dependabot2jira.yml @@ -0,0 +1,53 @@ +name: Dependabot Jira ticket +# This workflow is triggered to create a Jira ticket for every new dependabot PR + +permissions: {} + +on: + pull_request: + types: [opened] + +jobs: + run-if-dependabot: + if: github.actor == 'dependabot' + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Create a new Jira ticket + env: + JIRA_PROJECT_KEY: "DAOS" + PR_TITLE: ${{ github.event.pull_request.title }} + PR_BODY: ${{ github.event.pull_request.body }} + run: | + new_title=$(echo "$PR_TITLE" | sed 's/^Doc-only: true //') + jira_response=$(curl -u "${{ secrets.JIRA_EMAIL }}:${{ secrets.JIRA_API_TOKEN }}" \ + -X POST \ + -H "Content-Type: application/json" \ + --data "$(jq -n --arg title "$new_title" \ + --arg body "$PR_BODY" \ + --arg project_key "$JIRA_PROJECT_KEY" \ + '{ + fields: { + project: { key: $project_key }, + summary: $title, + description: $body, + issuetype: { name: "Story" } + } + }')" ${{ secrets.JIRA_BASE_URL }} + ) + + jira_ticket_key=$(echo $jira_response | jq -r .key) + echo "PR_NEW_TITLE=$jira_ticket_key cq: $new_title" >> $GITHUB_ENV + + - name: Update the PR title with a prefix based on the Jira ticket key + env: + PR_URL: "https://api.github.com/repos/${{ github.repository }}/pulls/${{ github.event.pull_request.number }}" # yamllint disable-line + run: | + curl -X PATCH -sS -o /dev/null \ + -H "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \ + -H "Content-Type: application/json" \ + --data "$(jq -n --arg title "$PR_NEW_TITLE" \ + '{ + title: $title, + }' )" $PR_URL