forked from AI21Labs/ai21-python
-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (122 loc) · 4.31 KB
/
labeler.yml
File metadata and controls
132 lines (122 loc) · 4.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: "Pull Request Labeler"
on:
pull_request_review:
types: [submitted]
pull_request_review_comment:
types: [created, deleted]
pull_request_target:
types: [opened, edited, reopened, synchronize]
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
if: github.event.action == 'synchronize'
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Labeler
uses: actions/labeler@v5
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}
- name: Fetch all branches
run: git fetch --all
- name: Determine base and head branches
id: branches
run: |
base_branch=$(jq -r '.pull_request.base.ref' "$GITHUB_EVENT_PATH")
head_branch=$(jq -r '.pull_request.head.ref' "$GITHUB_EVENT_PATH")
echo $base_branch
echo $head_branch
echo "base_branch=$base_branch" >> $GITHUB_ENV
echo "head_branch=$head_branch" >> $GITHUB_ENV
- name: Calculate diff size
id: diff
env:
BASE_BRANCH: ${{ env.base_branch }}
HEAD_BRANCH: ${{ env.head_branch }}
run: |
echo $BASE_BRANCH
echo $HEAD_BRANCH
git checkout $HEAD_BRANCH
git fetch origin $BASE_BRANCH
diff_output=$(git diff --shortstat origin/$BASE_BRANCH...$HEAD_BRANCH)
echo $diff_output
insertions=$(echo $diff_output | awk '{print ($4 == "" ? 0 : $4)}')
deletions=$(echo $diff_output | awk '{print ($6 == "" ? 0 : $6)}')
changed_lines=$((insertions + deletions))
echo $changed_lines
echo "changed_lines=$changed_lines" >> $GITHUB_ENV
- name: Determine label
env:
CHANGED_LINES: ${{ env.changed_lines }}
id: label
run: |
changed_lines=$CHANGED_LINES
if [ "$changed_lines" -le 9 ]; then
label="size:s"
elif [ "$changed_lines" -le 50 ]; then
label="size:m"
elif [ "$changed_lines" -le 100 ]; then
label="size:l"
elif [ "$changed_lines" -le 500 ]; then
label="size:xl"
else
label="size:xxl"
fi
echo "label=$label" >> $GITHUB_ENV
- name: Fetch current labels
id: fetch_labels
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const { data: labels } = await github.rest.issues.listLabelsOnIssue({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
});
return labels.map(label => label.name);
- name: Remove old size labels
id: remove_labels
uses: actions/github-script@v7
env:
NEW_SIZE_LABEL: ${{ env.label }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const sizeLabels = ['size:s', 'size:m', 'size:l', 'size:xl', 'size:xxl'];
const newLabel = "${{ env.NEW_SIZE_LABEL }}";
const currentLabels = ${{ steps.fetch_labels.outputs.result }};
const labelsToRemove = currentLabels.filter(label => sizeLabels.includes(label) && label !== newLabel);
for (const label of labelsToRemove) {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: label,
});
}
- name: Add label to PR
uses: actions-ecosystem/action-add-labels@v1
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
labels: ${{ env.label }}
- name: Remove lgtm label on new commits
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
try {
await github.rest.issues.removeLabel({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
name: 'lgtm'
});
} catch (error) {
if (error.status !== 404) {
throw error;
}
}