SEGAM-77: TEST #7
This file contains 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: Create GitHub Issue from JIRA | |
on: | |
repository_dispatch: | |
types: [jira_issue_created] | |
issues: | |
types: [opened, edited] | |
jobs: | |
create-issue: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'repository_dispatch' | |
steps: | |
- name: Create GitHub Issue | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
JIRA_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
// Jira to GitHub ๋งํฌ๋ค์ด ๋ณํ ํจ์ | |
function convertJiraToGitHub(text) { | |
if (!text) return text; | |
// ํค๋ฉ ๋ณํ | |
text = text.replace(/h([1-6])\.\s/g, (_, level) => '#'.repeat(level) + ' '); | |
// ์ฝ๋ ๋ธ๋ก ๋ณํ | |
text = text.replace(/{code(:([a-z]+))?}([\s\S]*?){code}/g, (_, __, lang, code) => | |
'```' + (lang || '') + '\n' + code + '```' | |
); | |
// ํจ๋ ๋ณํ | |
text = text.replace(/{panel}([\s\S]*?){panel}/g, '> $1'); | |
// ์ธ์ฉ๊ตฌ ๋ณํ | |
text = text.replace(/bq\.\s/g, '> '); | |
// ๊ธ๋จธ๋ฆฌ ๊ธฐํธ ๋ณํ | |
text = text.replace(/^\*\s/gm, '- '); | |
// ๋งํฌ ๋ณํ | |
text = text.replace(/\[([^\|]+)\|([^\]]+)\]/g, '[$1]($2)'); | |
// ์ทจ์์ ๋ณํ | |
text = text.replace(/-([^-]+)-/g, '~~$1~~'); | |
// ๋ฐ์ค ๋ณํ | |
text = text.replace(/\+([^+]+)\+/g, '__$1__'); | |
// ์์ ํ ์คํธ ๋ณํ | |
text = text.replace(/{color:[^}]+}([^{]+){color}/g, '`$1`'); | |
// ํ ๋ณํ | |
text = text.replace(/\|\|([^\n]+)\|\|/g, '|$1|'); | |
return text; | |
} | |
const { issue } = context.payload; | |
// JIRA ์ค๋ช ์ GitHub ๋งํฌ๋ค์ด์ผ๋ก ๋ณํ | |
const convertedDescription = convertJiraToGitHub(issue.fields.description || 'No description'); | |
await github.rest.issues.create({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
title: `[${issue.key}] ${issue.fields.summary}`, | |
body: ` | |
Jira Issue: ${issue.key} | |
${convertedDescription} | |
--- | |
Priority: ${issue.fields.priority?.name || 'Not set'} | |
Status: ${issue.fields.status.name} | |
[View in Jira](${process.env.JIRA_URL}/browse/${issue.key}) | |
` | |
}); | |
convert-markdown: | |
runs-on: ubuntu-latest | |
if: github.event_name == 'issues' | |
steps: | |
- name: Setup Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version: '20' | |
- name: Install Dependencies | |
run: npm install jira2md | |
- name: Convert Markdown | |
uses: actions/github-script@v7 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const j2m = require('jira2md'); | |
const issue = context.payload.issue; | |
if (!issue) return; | |
// Convert issue body using jira2md | |
const convertedBody = j2m.to_markdown(issue.body); | |
// Only update if the conversion changed the content | |
if (convertedBody !== issue.body) { | |
await github.rest.issues.update({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue.number, | |
body: convertedBody | |
}); | |
} |