Skip to content

Commit

Permalink
Update and rename LeetCode.yml to IssueCloseAction.yml
Browse files Browse the repository at this point in the history
  • Loading branch information
fkdl0048 authored Oct 15, 2024
1 parent 2c22a63 commit 78598b3
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 73 deletions.
74 changes: 74 additions & 0 deletions .github/workflows/IssueCloseAction.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: 이슈 닫힘 시 라벨별로 파일 생성

on:
issues:
types: [closed]

permissions:
contents: write

jobs:
create_files_by_label:
runs-on: ubuntu-latest

steps:
- name: 레포지토리 체크아웃
uses: actions/checkout@v3
with:
fetch-depth: 0 # 전체 커밋 기록을 가져옵니다.

- name: 이슈 정보 가져오기
id: issue_data
uses: actions/github-script@v6
with:
script: |
const issue = context.payload.issue;
core.setOutput('title', issue.title || 'untitled');
core.setOutput('body', issue.body || '');
core.setOutput('number', issue.number || '');
const labels = issue.labels.map(label => label.name);
core.setOutput('labels', labels.join(','));
- name: 라벨이 있는지 확인
if: ${{ steps.issue_data.outputs.labels == '' }}
run: |
echo "이슈에 라벨이 없습니다. 작업을 종료합니다."
exit 0
- name: 이슈 본문에서 코드 추출
id: extract_code
run: |
echo '이슈 본문에서 코드를 추출합니다...'
echo "${{ steps.issue_data.outputs.body }}" > issue_body.txt
code=$(grep -zoP '```(?:cpp)?\s*\n([\s\S]*?)\n```' issue_body.txt | sed -e 's/```cpp//' -e 's/```//' -e 's/^[[:space:]]*//' -e 's/[[:space:]]*$//')
if [ -z "$code" ]; then
echo "코드 블록을 찾을 수 없습니다. 작업을 종료합니다."
exit 1
fi
echo "$code" > code.cpp
- name: 라벨별로 파일 생성
run: |
labels="${{ steps.issue_data.outputs.labels }}"
IFS=',' read -ra LABEL_ARRAY <<< "$labels"
title="${{ steps.issue_data.outputs.title }}"
sanitized_title=$(echo "$title" | tr '[:upper:]' '[:lower:]' | tr ' ' '_' | tr -cd '[:alnum:]_.-')
for label in "${LABEL_ARRAY[@]}"; do
sanitized_label=$(echo "$label" | tr '[:upper:]' '[:lower:]' | tr ' ' '_' | tr -cd '[:alnum:]_.-')
folder="$sanitized_label"
mkdir -p "$folder"
cp code.cpp "$folder/$sanitized_title.cpp"
echo "파일 생성: $folder/$sanitized_title.cpp"
done
- name: 변경 사항 커밋 및 푸시
uses: EndBug/add-and-commit@v9
with:
message: "이슈 #${{ steps.issue_data.outputs.number }}에서 솔루션 추가"
add: "*/*.cpp"
author_name: GitHub Action
author_email: [email protected]
committer_name: GitHub Action
committer_email: [email protected]
pull_strategy: NO_REBASE # 푸시 전에 git pull을 수행합니다.
token: ${{ secrets.GITHUB_TOKEN }}
73 changes: 0 additions & 73 deletions .github/workflows/LeetCode.yml

This file was deleted.

0 comments on commit 78598b3

Please sign in to comment.