-
Notifications
You must be signed in to change notification settings - Fork 202
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
69 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
name: Label PR size | ||
|
||
on: | ||
pull_request: | ||
types: [opened, synchronize] | ||
|
||
jobs: | ||
label_pr: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v2 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.x' | ||
|
||
- name: Install Dependencies | ||
run: pip install PyGithub | ||
|
||
- name: Run Script | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
GITHUB_REPOSITORY: ${{ github.repository }} | ||
PULL_REQUEST_NUMBER: ${{ github.event.pull_request.number }} | ||
run: python .github/workflows/size_label.py |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
# -*- coding: utf-8 -*- | ||
""" | ||
Created on Fri Jan 19 14:21:11 2024 | ||
@author: Fan-Lin | ||
""" | ||
|
||
import os | ||
from github import Github | ||
|
||
# 获取环境变量 | ||
TOKEN = os.environ['GITHUB_TOKEN'] | ||
REPO_NAME = os.environ['GITHUB_REPOSITORY'] | ||
PR_NUMBER = os.environ['PULL_REQUEST_NUMBER'] | ||
|
||
# 初始化Github对象 | ||
g = Github(TOKEN) | ||
repo = g.get_repo(REPO_NAME) | ||
pr = repo.get_pull(int(PR_NUMBER)) | ||
|
||
# 获取PR的更改行数 | ||
additions = pr.additions | ||
deletions = pr.deletions | ||
total_changes = additions + deletions | ||
|
||
# 根据更改行数设置标签 | ||
label = '' | ||
if total_changes <= 9: | ||
label = 'size/XS' | ||
elif 10 <= total_changes <= 29: | ||
label = 'size/S' | ||
elif 30 <= total_changes <= 99: | ||
label = 'size/M' | ||
elif 100 <= total_changes <= 499: | ||
label = 'size/L' | ||
elif 500 <= total_changes <= 999: | ||
label = 'size/XL' | ||
else: | ||
label = 'size/XXL' | ||
|
||
# 设置标签 | ||
pr.set_labels(label) |