DOCS-403: ci bump actions/github-script from v8 to v9 #19
Workflow file for this run
This file contains hidden or 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
| name: Dependabot PR Jira Task | |
| permissions: | |
| contents: read | |
| pull-requests: read | |
| on: | |
| pull_request_target: | |
| types: | |
| - opened | |
| jobs: | |
| create-jira-task: | |
| if: github.event.pull_request.user.login == 'dependabot[bot]' | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Collect changed PR files | |
| uses: actions/github-script@v9 | |
| with: | |
| script: | | |
| const fs = require('fs'); | |
| const files = await github.paginate( | |
| github.rest.pulls.listFiles, | |
| { | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| pull_number: context.issue.number, | |
| per_page: 100, | |
| } | |
| ); | |
| fs.mkdirSync('.github/automation-reports', { recursive: true }); | |
| fs.writeFileSync( | |
| '.github/automation-reports/dependabot-pr-files.json', | |
| JSON.stringify( | |
| files.map((file) => ({ | |
| filename: file.filename, | |
| status: file.status, | |
| })), | |
| null, | |
| 2 | |
| ) | |
| ); | |
| - name: Create Jira issue | |
| id: jira | |
| env: | |
| JIRA_BASE_URL: ${{ secrets.DOCS_JIRA_BASE_URL }} | |
| JIRA_EMAIL: ${{ secrets.DOCS_JIRA_EMAIL }} | |
| JIRA_API_TOKEN: ${{ secrets.DOCS_JIRA_API_TOKEN }} | |
| JIRA_PROJECT_KEY: ${{ secrets.DOCS_JIRA_PROJECT_KEY }} | |
| PR_NUMBER: ${{ github.event.pull_request.number }} | |
| PR_TITLE: ${{ github.event.pull_request.title }} | |
| PR_URL: ${{ github.event.pull_request.html_url }} | |
| PR_AUTHOR: ${{ github.event.pull_request.user.login }} | |
| PR_HEAD_REF: ${{ github.event.pull_request.head.ref }} | |
| PR_BASE_REF: ${{ github.event.pull_request.base.ref }} | |
| REPO_NAME: ${{ github.repository }} | |
| run: | | |
| set -e | |
| SUMMARY_PREFIX="Dependabot PR #${PR_NUMBER}:" | |
| SUMMARY="${SUMMARY_PREFIX} ${PR_TITLE}" | |
| AUTH_HEADER="Authorization: Basic $(printf "%s:%s" "$JIRA_EMAIL" "$JIRA_API_TOKEN" | base64 -w 0)" | |
| JIRA_CURL_OPTS=( | |
| --retry 3 | |
| --retry-all-errors | |
| --retry-delay 2 | |
| --retry-max-time 30 | |
| --connect-timeout 10 | |
| --max-time 45 | |
| ) | |
| FILE_LIST=$(jq -r '.[].filename' .github/automation-reports/dependabot-pr-files.json | sed '/^\s*$/d' | head -50) | |
| if [ -z "$FILE_LIST" ]; then | |
| FILE_LIST="(no changed files reported)" | |
| fi | |
| SEARCH_JQL=$(jq -rn --arg proj "$JIRA_PROJECT_KEY" --arg prefix "$SUMMARY_PREFIX" '$proj + " AND summary ~ \"\\\"" + $prefix + "\\\"\""') | |
| SEARCH_RESP=$(curl -sS "${JIRA_CURL_OPTS[@]}" \ | |
| -G \ | |
| -H "$AUTH_HEADER" \ | |
| --data-urlencode "jql=${SEARCH_JQL}" \ | |
| --data-urlencode "maxResults=1" \ | |
| "$JIRA_BASE_URL/rest/api/3/search") | |
| EXISTING_KEY=$(echo "$SEARCH_RESP" | jq -r '.issues[0].key // empty') | |
| EXISTING_ID=$(echo "$SEARCH_RESP" | jq -r '.issues[0].id // empty') | |
| if [ -n "$EXISTING_KEY" ]; then | |
| echo "issue_key=$EXISTING_KEY" >> "$GITHUB_OUTPUT" | |
| echo "issue_id=$EXISTING_ID" >> "$GITHUB_OUTPUT" | |
| echo "Jira issue already exists: $EXISTING_KEY" | |
| exit 0 | |
| fi | |
| ADF_DESC=$(jq -n \ | |
| --arg repo "$REPO_NAME" \ | |
| --arg prtitle "$PR_TITLE" \ | |
| --arg prurl "$PR_URL" \ | |
| --arg prnum "$PR_NUMBER" \ | |
| --arg author "$PR_AUTHOR" \ | |
| --arg head "$PR_HEAD_REF" \ | |
| --arg base "$PR_BASE_REF" \ | |
| --arg files "$FILE_LIST" \ | |
| 'def para($t): {type:"paragraph", content:[{type:"text", text:$t}]}; | |
| def linkPara($label; $url): | |
| { type:"paragraph", content:[ | |
| {type:"text", text:$label}, | |
| {type:"text", text:$url, marks:[{type:"link", attrs:{href:$url}}]} | |
| ]}; | |
| def codeBlock($t): | |
| {type:"codeBlock", attrs:{language:""}, content:[{type:"text", text:$t}]}; | |
| { | |
| type:"doc", version:1, | |
| content:[ | |
| para("Dependabot opened a pull request in the technical documentation repository."), | |
| para("Repository: " + $repo), | |
| para("Pull request: #" + $prnum + " - " + $prtitle), | |
| linkPara("Pull request URL: "; $prurl), | |
| para("Author: " + $author), | |
| para("Branch: " + $head + " -> " + $base), | |
| para("Changed files (first 50):"), | |
| codeBlock($files), | |
| para("This ticket was created automatically by GitHub Actions for Dependabot triage.") | |
| ] | |
| }') | |
| PAYLOAD=$(jq -n \ | |
| --arg proj "$JIRA_PROJECT_KEY" \ | |
| --arg summary "$SUMMARY" \ | |
| --argjson adf "$ADF_DESC" \ | |
| '{ | |
| fields: { | |
| project: { key: $proj }, | |
| summary: $summary, | |
| description: $adf, | |
| issuetype: { name: "Task" }, | |
| labels: ["dependabot","documentation","github-actions"] | |
| } | |
| }') | |
| RESP=$(curl -sS "${JIRA_CURL_OPTS[@]}" -X POST \ | |
| -H "$AUTH_HEADER" \ | |
| -H "Content-Type: application/json" \ | |
| --data "$PAYLOAD" \ | |
| "$JIRA_BASE_URL/rest/api/3/issue") | |
| ISSUE_KEY=$(echo "$RESP" | jq -r '.key // empty') | |
| ISSUE_ID=$(echo "$RESP" | jq -r '.id // empty') | |
| if [ -z "$ISSUE_KEY" ]; then | |
| echo "Failed to create Jira issue. Response:" | |
| echo "$RESP" | |
| exit 1 | |
| fi | |
| echo "issue_key=$ISSUE_KEY" >> "$GITHUB_OUTPUT" | |
| echo "issue_id=$ISSUE_ID" >> "$GITHUB_OUTPUT" | |
| echo "Created Jira issue: $ISSUE_KEY" |