Odd Even Linked List #2
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: 이슈 닫힘 시 LeetCode 파일 생성 | |
on: | |
issues: | |
types: [closed] | |
permissions: | |
contents: write | |
jobs: | |
create_leetcode_file: | |
runs-on: ubuntu-latest | |
steps: | |
- name: 이슈에 LeetCode 라벨이 있는지 확인 | |
id: check_label | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const labels = context.payload.issue.labels; | |
const hasLabel = labels.some(label => label.name === 'LeetCode'); | |
core.setOutput('hasLabel', hasLabel); | |
- name: LeetCode 라벨이 없으면 중지 | |
if: steps.check_label.outputs.hasLabel != 'true' | |
run: | | |
echo "이슈에 LeetCode 라벨이 없습니다. 작업을 종료합니다." | |
exit 0 | |
- name: 레포지토리 체크아웃 | |
uses: actions/checkout@v3 | |
- name: 이슈 본문에서 코드 추출 및 파일 생성 | |
id: create_file | |
uses: actions/github-script@v6 | |
with: | |
script: | | |
const fs = require('fs'); | |
const issueBody = context.payload.issue.body; | |
const codeBlockRegex = /```(?:cpp)?\n([\s\S]*?)\n```/g; | |
let code = ''; | |
let match; | |
while ((match = codeBlockRegex.exec(issueBody)) !== null) { | |
code += match[1] + '\n'; | |
} | |
const title = context.payload.issue.title; | |
const sanitizedTitle = title.toLowerCase().replace(/ /g, '_').replace(/[^a-z0-9_.-]/g, ''); | |
const filepath = `LeetCode/${sanitizedTitle}.cpp`; | |
fs.mkdirSync('LeetCode', { recursive: true }); | |
fs.writeFileSync(filepath, code); | |
core.setOutput('filepath', filepath); | |
core.setOutput('issue_number', context.payload.issue.number); | |
- name: 변경 사항 커밋 및 푸시 | |
uses: EndBug/add-and-commit@v9 | |
with: | |
message: "이슈 #${{ steps.create_file.outputs.issue_number }}에서 LeetCode 솔루션 추가" | |
add: "${{ steps.create_file.outputs.filepath }}" | |
author_name: GitHub Action | |
author_email: [email protected] | |
committer_name: GitHub Action | |
committer_email: [email protected] | |
token: ${{ secrets.GITHUB_TOKEN }} |