From c3f4ff6c446abd692a1d4bb29d496dae44bbd83d Mon Sep 17 00:00:00 2001 From: Filipe Constantinov Menezes Date: Fri, 24 Nov 2023 11:16:35 +0000 Subject: [PATCH] CLOUDP-212931 Create Jira tickets for dependabot PRs (#2470) --- .github/workflows/dependabot.yml | 65 +++++++++++++++++++++++++++++++ build/ci/library_owners_jira.json | 4 ++ 2 files changed, 69 insertions(+) create mode 100644 .github/workflows/dependabot.yml create mode 100644 build/ci/library_owners_jira.json diff --git a/.github/workflows/dependabot.yml b/.github/workflows/dependabot.yml new file mode 100644 index 0000000000..33de1a5c11 --- /dev/null +++ b/.github/workflows/dependabot.yml @@ -0,0 +1,65 @@ +--- + name: Create JIRA ticket for dependabot prs + + on: pull_request + + permissions: + pull-requests: write + contents: read + jobs: + jira_task: + name: Create Jira issue + runs-on: ubuntu-latest + if: github.actor == 'dependabot[bot]' + steps: + - name: Create JIRA ticket + id: create + shell: bash + env: + PR_NUMBER: ${{ github.event.pull_request.number }} + PR_URL: ${{ github.event.pull_request.html_url }} + JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} + JIRA_ASSIGNEE: ${{ secrets.ASSIGNEE_JIRA_TICKET }} + run: | + ASSIGNED_TEAM=$(git diff HEAD~1..HEAD -- go.mod | grep -v "// indirect" | grep -i "^\-" | grep -v "^\-\-\-" | awk '{print $2}' | xargs -I $ echo "jq -r \".\\\"$\\\"\" < build/ci/library_owners.json" | sh | xargs -I $ echo "jq -r \".\\\"$\\\"\" < build/ci/library_owners_jira.json" | sh | head -1) + json_response=$(curl --request POST \ + --url 'https://jira.mongodb.org/rest/api/2/issue' \ + --header 'Authorization: Bearer '"${JIRA_API_TOKEN}" \ + --header 'Accept: application/json' \ + --header 'Content-Type: application/json' \ + --data '{ + "fields": { + "project": { + "id": "10984" + }, + "summary": "AtlasCLI Dependency Update n. '"${PR_NUMBER}"'", + "issuetype": { + "id": "12" + }, + "customfield_12751": [{ + "id": "$ASSIGNED_TEAM" + }], + "description": "This ticket tracks the following GitHub pull request: '"${PR_URL}"'.", + "components": [ + { + "id": "30450" + } + ], + "assignee": { + "name": "'"${JIRA_ASSIGNEE}"'" + } + } + }') + + echo "Response: ${json_response}" + + JIRA_TICKET_ID=$(echo "${json_response}" | jq -r '.key') + + echo "The following JIRA ticket has been created: ${JIRA_TICKET_ID}" + echo "jira-ticket-id=${JIRA_TICKET_ID}" >> "${GITHUB_OUTPUT}" + - name: Add comment + uses: peter-evans/create-or-update-comment@v3 + with: + issue-number: ${{ github.event.pull_request.number }} + body: | + The ticket [${{ steps.create.outputs.jira-ticket-id }}](https://jira.mongodb.org/browse/${{ steps.create.outputs.jira-ticket-id }}) was created for internal tracking. diff --git a/build/ci/library_owners_jira.json b/build/ci/library_owners_jira.json new file mode 100644 index 0000000000..8979036ceb --- /dev/null +++ b/build/ci/library_owners_jira.json @@ -0,0 +1,4 @@ +{ + "mongocli": "22223", + "atlas_kubernetes_team": "24741" +}