Skip to content

Commit

Permalink
🤖 CREATE JPC 4TH BOT AND TEAMPLATE FILE
Browse files Browse the repository at this point in the history
  • Loading branch information
hadevyi committed Jan 1, 2025
1 parent 72b7d1b commit 517abe1
Show file tree
Hide file tree
Showing 7 changed files with 206 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .github/ISSUE_TEMPLATE/📄-algorithms-issue-templete.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
---
name: "\U0001F4C4 Algorithms Issue Templete"
about: 알고리즘 문제 업데이트를 위한 템플릿
title: "[YYMMDD] 사이트 - 제목"
---

### 문제 개요

- 사이트 : SW Expert Academy / Baekjoon / CodeTree / Programmers
- 제목 :
- 링크 :
25 changes: 25 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
## 💿 풀이 문제
<!-- #<이슈번호> 로 꼭 입력해주세요. -->

## 📝 풀이 후기
<!-- 어려웠다. 쉬웠다 등 모두 좋습니다. -->

## 📚 문제 풀이 핵심 키워드
<!-- 시간 단축 및 구현 중심 등의 내용 모두 좋습니다. -->
-

## 🤔 리뷰로 궁금한 점
<!-- 확인받고 싶은 기준을 작성해주시면 좋습니다. -->
<!-- 운영자에게 리뷰를 받고 싶다면, Reviewer에 @hadevyi를 태그해주세요. -->

## 🧑‍💻 제출자 확인 사항
<!-- Merge가 되면, Branch를 꼭 삭제해주세요 -->
- [ ] Convention(commit, pr 제목)이 올바른가요?
- [ ] 괄호 내 안내문은 삭제하셨나요?
- [ ] 본인의 체감 난도 Label을 등록했나요?
- [x] 제출자 확인 사항을 모두 확인하셨나요?

## 🕵️ 리뷰어 확인 사항
<!-- 코드리뷰를 신청하지 않은 인원은 '리뷰어 확인 사항'을 모두 삭제해주세요. -->
1. 컨벤션이 올바르지 않다면, Request Changes 해주세요.
2. 제출자의 풀이코드의 좋은 점 혹은 개선사항을 남기고 Approve 해주세요.
54 changes: 54 additions & 0 deletions .github/scripts/label-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
const core = require('@actions/core');
const github = require('@actions/github');

async function run() {
try {
const token = process.env.GH_TOKEN;
if (!token) {
throw new Error('GitHub token is not provided');
}

const octokit = github.getOctokit(token);
const context = github.context;
const { owner, repo } = context.repo;
const pull_number = context.issue.number;

const { data: files } = await octokit.rest.pulls.listFiles({
owner,
repo,
pull_number
});

// 파일 확장자와 라벨 매핑
const labelMap = {
'.java': 'Java',
'.py': 'Python',
'.js': 'JavaScript',
'.cpp': 'C++'
};

// 변경된 파일 목록 출력 및 라벨 추가
const labels = new Set();
files.forEach(file => {
// 확장자에 따른 라벨 추가
Object.keys(labelMap).forEach(ext => {
if (file.filename.endsWith(ext)) {
labels.add(labelMap[ext]);
}
});
});

if (labels.size > 0) {
await octokit.rest.issues.addLabels({
owner,
repo,
issue_number: pull_number,
labels: Array.from(labels),
});
}
} catch (error) {
core.setFailed(error.message);
}
}

run();
48 changes: 48 additions & 0 deletions .github/scripts/reviewer-pr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
const core = require('@actions/core');
const github = require('@actions/github');

// 특정 이름이 주어졌을 때, 해당 이름이 속한 팀의 다른 인원을 반환하는 함수입니다.
function findTeamMembers(teams, name) {
for (let team of teams) {
if (team.includes(name)) {
return team.filter(member => member !== name);
}
}
return []; // 이름이 팀에 속하지 않을 경우 빈 배열 반환
}

async function run() {
try {
const token = process.env.GH_TOKEN;
const reviwerTeam = process.env.REVIWER_TEAM;
const author = process.env.ACTOR;

console.log(author);

if (!token) {
throw new Error('GitHub token is not provided');
}

const octokit = github.getOctokit(token);
const context = github.context;
const { owner, repo } = context.repo;
const pull_number = context.issue.number;

reviewers = findTeamMembers(reviwerTeam.split('|').map(team => team.split(',')), author);
console.log(reviewers);

if (reviewers.length > 0) {
await octokit.rest.pulls.requestReviewers({
owner,
repo,
pull_number,
reviewers
});
}

} catch (error) {
core.setFailed(error.message);
}
}

run();
13 changes: 13 additions & 0 deletions .github/workflows/Auto-Assignees-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: Auto Assignees Pull Request

on:
pull_request:
types: [opened]

jobs:
assign:
runs-on: ubuntu-latest
steps:
- uses: hkusu/review-assign-action@v1
with:
assignees: ${{ github.actor }} # assign pull request author
26 changes: 26 additions & 0 deletions .github/workflows/Auto-Labeling-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Label PR based on file extensions

on:
pull_request:
types: [opened]

jobs:
label:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18' # 최신 LTS 버전으로 설정 (현재 LTS 버전: 18)

- name: Install dependencies
run: npm install @actions/core @actions/github

- name: Run custom script
run: node .github/scripts/label-pr.js
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
29 changes: 29 additions & 0 deletions .github/workflows/Auto-Reviewer-PR.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Reviewer PR based on file extensions

on:
pull_request:
types: [opened]

jobs:
label:
runs-on: ubuntu-latest

steps:
- name: Checkout repository
uses: actions/checkout@v2

- name: Set up Node.js
uses: actions/setup-node@v2
with:
node-version: '18' # 최신 LTS 버전으로 설정 (현재 LTS 버전: 18)

- name: Install dependencies
run: npm install @actions/core @actions/github

- name: Run custom script
run: node .github/scripts/reviewer-pr.js
env:
GH_TOKEN: ${{ secrets.GH_TOKEN }}
REVIWER_TEAM: ${{ vars.REVIWER_TEAM }}
ACTOR: ${{ github.actor }}

0 comments on commit 517abe1

Please sign in to comment.