Skip to content
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

add pr-size label trigger #3590

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
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
41 changes: 41 additions & 0 deletions .github/workflows/size_label.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# -*- 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)
Loading