-
Notifications
You must be signed in to change notification settings - Fork 0
jira setting #229
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
jira setting #229
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
1ac842c
chore: switch jira-github issue automation to branch-driven flow
arlen02-01 7ca6f6e
chore: align auto-created github issue template with jira fields
arlen02-01 fa87f14
fix: include parent field and use actual branch name in issue body
arlen02-01 21f1599
fix: harden jira automation with timeout and keyed concurrency
arlen02-01 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
210 changes: 210 additions & 0 deletions
210
.github/workflows/create-github-issue-from-jira-branch.yml
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| name: Create GitHub Issue from Jira Branch | ||
|
|
||
| on: | ||
| create: | ||
|
|
||
| permissions: | ||
| contents: read | ||
| issues: write | ||
|
|
||
| jobs: | ||
| extract-jira-key: | ||
| if: github.event.ref_type == 'branch' | ||
| runs-on: ubuntu-latest | ||
| outputs: | ||
| jira_key: ${{ steps.extract.outputs.jira_key }} | ||
| branch_name: ${{ steps.extract.outputs.branch_name }} | ||
| steps: | ||
| - name: Extract Jira key from branch name | ||
| id: extract | ||
| shell: bash | ||
| run: | | ||
| BRANCH_NAME="${{ github.event.ref }}" | ||
| if [[ "$BRANCH_NAME" =~ ([A-Z][A-Z0-9]+-[0-9]+) ]]; then | ||
| echo "jira_key=${BASH_REMATCH[1]}" >> "$GITHUB_OUTPUT" | ||
| echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "No Jira key found in branch: $BRANCH_NAME" | ||
| echo "jira_key=" >> "$GITHUB_OUTPUT" | ||
| echo "branch_name=$BRANCH_NAME" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| create-github-issue: | ||
| needs: extract-jira-key | ||
| if: needs.extract-jira-key.outputs.jira_key != '' | ||
| runs-on: ubuntu-latest | ||
| concurrency: | ||
| group: jira-gh-issue-${{ github.repository }}-${{ needs.extract-jira-key.outputs.jira_key }} | ||
| cancel-in-progress: false | ||
|
|
||
| steps: | ||
| - name: Fetch Jira issue summary and description | ||
| id: jira | ||
| env: | ||
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
| JIRA_KEY: ${{ needs.extract-jira-key.outputs.jira_key }} | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| RESPONSE=$(curl -sS --fail \ | ||
| --connect-timeout 10 \ | ||
| --max-time 30 \ | ||
| --retry 3 \ | ||
| --retry-delay 2 \ | ||
| --retry-all-errors \ | ||
| -u "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" \ | ||
| -H "Accept: application/json" \ | ||
| "${JIRA_BASE_URL}/rest/api/3/issue/${JIRA_KEY}?fields=summary,description,parent&expand=renderedFields") | ||
|
|
||
| SUMMARY=$(echo "$RESPONSE" | jq -r '.fields.summary // empty') | ||
| DESCRIPTION_HTML=$(echo "$RESPONSE" | jq -r '.renderedFields.description // ""') | ||
| PARENT_KEY=$(echo "$RESPONSE" | jq -r '.fields.parent.key // ""') | ||
|
|
||
| if [[ -z "$SUMMARY" ]]; then | ||
| echo "Jira issue summary is empty for key: $JIRA_KEY" | ||
| exit 1 | ||
| fi | ||
|
|
||
| DELIMITER="EOF_$(date +%s)_$RANDOM" | ||
| { | ||
| echo "summary=$SUMMARY" | ||
| echo "parent_key=$PARENT_KEY" | ||
| echo "description_html<<$DELIMITER" | ||
| echo "$DESCRIPTION_HTML" | ||
| echo "$DELIMITER" | ||
| } >> "$GITHUB_OUTPUT" | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Check existing GitHub issue for Jira key | ||
| id: dedup | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| JIRA_KEY: ${{ needs.extract-jira-key.outputs.jira_key }} | ||
| with: | ||
| script: | | ||
| const jiraKey = process.env.JIRA_KEY; | ||
| const repo = `${context.repo.owner}/${context.repo.repo}`; | ||
| const marker = `JIRA_KEY: ${jiraKey}`; | ||
| const q = `repo:${repo} "${jiraKey}"`; | ||
| const result = await github.rest.search.issuesAndPullRequests({ | ||
| q, | ||
| per_page: 20, | ||
| }); | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| const existing = result.data.items.find((item) => | ||
| !item.pull_request && | ||
| (item.title.startsWith(`[${jiraKey}]`) || item.body?.includes(marker)) | ||
| ); | ||
| if (existing) { | ||
| core.info(`Issue already exists: #${existing.number}`); | ||
| core.setOutput('exists', 'true'); | ||
| core.setOutput('number', String(existing.number)); | ||
| } else { | ||
| core.setOutput('exists', 'false'); | ||
| } | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
|
|
||
| - name: Create GitHub issue | ||
| if: steps.dedup.outputs.exists != 'true' | ||
| id: create_issue | ||
| uses: actions/github-script@v7 | ||
| env: | ||
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
| JIRA_KEY: ${{ needs.extract-jira-key.outputs.jira_key }} | ||
| JIRA_SUMMARY: ${{ steps.jira.outputs.summary }} | ||
| JIRA_PARENT_KEY: ${{ steps.jira.outputs.parent_key }} | ||
| JIRA_DESCRIPTION_HTML: ${{ steps.jira.outputs.description_html }} | ||
| BRANCH_NAME: ${{ needs.extract-jira-key.outputs.branch_name }} | ||
| with: | ||
| script: | | ||
| const jiraKey = process.env.JIRA_KEY; | ||
| const title = `[${jiraKey}] ${process.env.JIRA_SUMMARY}`; | ||
| const summaryForBranch = (process.env.JIRA_SUMMARY || '') | ||
| .trim() | ||
| .replace(/\s+/g, '-') | ||
| .replace(/[^a-zA-Z0-9/_-]/g, '-') | ||
| .replace(/-+/g, '-') | ||
| .replace(/^-|-$/g, ''); | ||
| const recommendedBranch = `${jiraKey}-${summaryForBranch || 'task'}`; | ||
| const parentKey = process.env.JIRA_PARENT_KEY || 'none'; | ||
| const actualBranch = process.env.BRANCH_NAME || recommendedBranch; | ||
| const body = [ | ||
| `JIRA_KEY: ${jiraKey}`, | ||
| '', | ||
| '### Parent Ticket Number', | ||
| parentKey, | ||
| '', | ||
| '### Branch', | ||
| `\`${actualBranch}\``, | ||
| '', | ||
| '### Description', | ||
| process.env.JIRA_DESCRIPTION_HTML || '(no description)', | ||
| '', | ||
| ].join('\n'); | ||
|
|
||
| const created = await github.rest.issues.create({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| title, | ||
| body, | ||
| }); | ||
|
|
||
| core.setOutput('number', String(created.data.number)); | ||
|
|
||
| - name: Comment GitHub issue link back to Jira | ||
| if: steps.dedup.outputs.exists != 'true' | ||
| env: | ||
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | ||
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | ||
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | ||
| JIRA_KEY: ${{ needs.extract-jira-key.outputs.jira_key }} | ||
| GH_ISSUE_NUMBER: ${{ steps.create_issue.outputs.number }} | ||
| GH_REPO: ${{ github.repository }} | ||
| GH_SERVER_URL: ${{ github.server_url }} | ||
| shell: bash | ||
| run: | | ||
| set -euo pipefail | ||
|
|
||
| GH_ISSUE_URL="${GH_SERVER_URL}/${GH_REPO}/issues/${GH_ISSUE_NUMBER}" | ||
|
|
||
| COMMENT_JSON=$(jq -n \ | ||
| --arg url "$GH_ISSUE_URL" \ | ||
| --arg no "$GH_ISSUE_NUMBER" \ | ||
| '{ | ||
| body: { | ||
| type: "doc", | ||
| version: 1, | ||
| content: [ | ||
| { | ||
| type: "paragraph", | ||
| content: [ | ||
| { type: "text", text: "GitHub issue created: " }, | ||
| { | ||
| type: "text", | ||
| text: ("#" + $no), | ||
| marks: [ | ||
| { | ||
| type: "link", | ||
| attrs: { href: $url } | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| ] | ||
| } | ||
| }') | ||
|
|
||
| curl -sS --fail \ | ||
| --connect-timeout 10 \ | ||
| --max-time 30 \ | ||
| --retry 3 \ | ||
| --retry-delay 2 \ | ||
| --retry-all-errors \ | ||
| -u "${JIRA_USER_EMAIL}:${JIRA_API_TOKEN}" \ | ||
| -H "Accept: application/json" \ | ||
| -H "Content-Type: application/json" \ | ||
| -X POST \ | ||
| --data "$COMMENT_JSON" \ | ||
| "${JIRA_BASE_URL}/rest/api/3/issue/${JIRA_KEY}/comment" > /dev/null | ||
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.