Skip to content

ci: add pr langauge labeler #335

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Aug 20, 2024
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions .github/workflows/integration.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,77 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: fernandrone/[email protected]

labeling-languages:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

보통 작업 이름은 build, test, lint 처럼 동사형으로 짓는 게 GitHub Actions에서 좀 더 일반적인 관행인 것 같습니다. 다음과 같이 변경하면 어떨까요?

Suggested change
labeling-languages:
label-lang:

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

네 깔끔하네요! 변경하였습니다~ 이제 머지도 하겠습니다!

runs-on: ubuntu-latest
continue-on-error: true
steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Create package.json
run: echo '{}' > package.json

- name: Install dependencies
run: npm install @octokit/rest node-fetch

- name: Detect languages and add labels
env:
GITHUB_TOKEN: ${{ github.token }}
PR_NUM: ${{ github.event.number }}
run: |
node --input-type=module -e "
import { Octokit } from '@octokit/rest';
import path from 'path';
import fetch from 'node-fetch';

const octokit = new Octokit({
auth: process.env.GITHUB_TOKEN,
request: { fetch }
});

const extensionsToLanguages = {
js: 'js',
ts: 'ts',
py: 'py',
java: 'java',
kt: 'kotlin',
cpp: 'c++',
go: 'go',
exs: 'elixir',
swift: 'swift'
// 필요한 다른 확장자와 언어 매핑 추가
};

async function run() {
const { data: files } = await octokit.pulls.listFiles({
owner: process.env.GITHUB_REPOSITORY.split('/')[0],
repo: process.env.GITHUB_REPOSITORY.split('/')[1],
pull_number: process.env.PR_NUM,
});

const languages = new Set();
files.forEach(file => {
const ext = path.extname(file.filename).slice(1);
if (extensionsToLanguages[ext]) {
languages.add(extensionsToLanguages[ext]);
}
});

if (languages.size > 0) {
await octokit.issues.addLabels({
owner: process.env.GITHUB_REPOSITORY.split('/')[0],
repo: process.env.GITHUB_REPOSITORY.split('/')[1],
issue_number: process.env.PR_NUM,
labels: Array.from(languages),
});
}
}

run().catch(err => console.error(err));
"