Discussion TODOs to Issues (25.09.10 Updated) #7
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: Discussion TODOs to Issues (New Format) | |
| on: | |
| discussion: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| discussions: read | |
| jobs: | |
| discussion_todos_to_issues: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Create issues from TODOs and link as sub-issues | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const discussion = context.payload.discussion; | |
| if (discussion.category.name !== "ํ์๋ก") { | |
| console.log("์นดํ ๊ณ ๋ฆฌ๊ฐ ํ์๋ก์ด ์๋๋ฏ๋ก ์ข ๋ฃํฉ๋๋ค."); | |
| return; | |
| } | |
| const lines = discussion.body.split('\n'); | |
| let inTodoSection = false; | |
| let currentAssignee = null; | |
| let parentIssueData = null; | |
| for (let i = 0; i < lines.length; i++) { | |
| const line = lines[i]; | |
| if (/^#+\s*TODO/i.test(line.trim())) { | |
| inTodoSection = true; | |
| currentAssignee = null; | |
| parentIssueData = null; | |
| continue; | |
| } | |
| if (inTodoSection && /^#+\s*\S+/.test(line.trim()) && !/^#+\s*TODO/i.test(line.trim())) { | |
| inTodoSection = false; | |
| currentAssignee = null; | |
| parentIssueData = null; | |
| continue; | |
| } | |
| if (!inTodoSection) continue; | |
| // ๋ด๋น์๋ฅผ ์ฐพ๋ ์ ๊ท์ | |
| const assigneeMatch = line.trim().match(/\*\*.*\(@([\w-]+)\)\*\*/); | |
| if (assigneeMatch) { | |
| currentAssignee = assigneeMatch[1]; | |
| parentIssueData = null; | |
| continue; | |
| } | |
| const todoMatch = line.match(/^(\s*)- \[ \] (.+)/); | |
| if (todoMatch && currentAssignee) { | |
| const indent = todoMatch[1].length; | |
| const todoText = todoMatch[2].trim(); | |
| // ๋ด์ฉ์ด ์๋ ์ฒดํฌ๋ฐ์ค๋ ์ด์๋ก ๋ง๋ค์ง ์์ | |
| if (!todoText) continue; | |
| if (indent === 0) { | |
| // ๋ถ๋ชจ ์ด์ ์์ฑ | |
| const issue = await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: todoText, | |
| body: `์ด ์ด์๋ ํ์๋ก Discussion์์ ์๋ ์์ฑ๋์์ต๋๋ค.\n\n[์๋ณธ Discussion ๋งํฌ](${discussion.html_url})`, | |
| assignees: [currentAssignee], | |
| labels: ["ํ์๋ก-TODO"] | |
| }); | |
| parentIssueData = issue.data; | |
| } else if (indent >= 2 && parentIssueData) { | |
| // 1. sub-issue ์์ฑ | |
| const subIssue = await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: todoText, | |
| body: `๋ถ๋ชจ ์ด์: #${parentIssueData.number}\n\n์ด ์ด์๋ ํ์๋ก Discussion์์ ์๋ ์์ฑ๋์์ต๋๋ค.\n\n[์๋ณธ Discussion ๋งํฌ](${discussion.html_url})`, | |
| assignees: [currentAssignee], | |
| labels: ["ํ์๋ก-TODO", "sub-issue"] | |
| }); | |
| // 2. ๋ถ๋ชจ ์ด์ ๋ณธ๋ฌธ์ sub-issue๋ฅผ ์ฒดํฌ๋ฐ์ค๋ก ์ถ๊ฐํ์ฌ ์ ๋ฐ์ดํธ | |
| const newBody = parentIssueData.body + `\n- [ ] #${subIssue.data.number}`; | |
| await github.rest.issues.update({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: parentIssueData.number, | |
| body: newBody | |
| }); | |
| parentIssueData.body = newBody; | |
| } | |
| } | |
| } |