Skip to content

Commit

Permalink
add PR-size-label tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Fan-Lin committed Jan 19, 2024
1 parent 66104fc commit 37ef599
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
27 changes: 27 additions & 0 deletions .github/workflows/label_pr_size.yml
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
42 changes: 42 additions & 0 deletions .github/workflows/size_label.py
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)

0 comments on commit 37ef599

Please sign in to comment.