mirror of
https://github.com/cita-777/metapi.git
synced 2026-10-31 19:47:31 +08:00
Bumps the github-actions group with 3 updates in the / directory: [actions/setup-node](https://github.com/actions/setup-node), [actions/labeler](https://github.com/actions/labeler) and [actions/cache](https://github.com/actions/cache). Updates `actions/setup-node` from 6 to 7 - [Release notes](https://github.com/actions/setup-node/releases) - [Commits](https://github.com/actions/setup-node/compare/v6...v7) Updates `actions/labeler` from 6 to 7 - [Release notes](https://github.com/actions/labeler/releases) - [Commits](https://github.com/actions/labeler/compare/v6...v7) Updates `actions/cache` from 5 to 6 - [Release notes](https://github.com/actions/cache/releases) - [Changelog](https://github.com/actions/cache/blob/main/RELEASES.md) - [Commits](https://github.com/actions/cache/compare/v5...v6) --- updated-dependencies: - dependency-name: actions/setup-node dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/labeler dependency-version: '7' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions - dependency-name: actions/cache dependency-version: '6' dependency-type: direct:production update-type: version-update:semver-major dependency-group: github-actions ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
72 lines
2.3 KiB
YAML
72 lines
2.3 KiB
YAML
name: Label Pull Requests
|
|
|
|
on:
|
|
pull_request_target:
|
|
types: [opened, synchronize, reopened, ready_for_review]
|
|
|
|
permissions:
|
|
contents: read
|
|
pull-requests: write
|
|
|
|
jobs:
|
|
apply-labels:
|
|
name: Apply area and size labels
|
|
runs-on: ubuntu-latest
|
|
steps:
|
|
- name: Apply area labels
|
|
uses: actions/labeler@v7
|
|
with:
|
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
|
sync-labels: false
|
|
|
|
- name: Apply size label
|
|
uses: actions/github-script@v9
|
|
with:
|
|
script: |
|
|
const owner = context.repo.owner;
|
|
const repo = context.repo.repo;
|
|
const pull_number = context.payload.pull_request.number;
|
|
const sizeLabels = ['size: XS', 'size: S', 'size: M', 'size: L', 'size: XL', 'size: XXL'];
|
|
|
|
const { data: pull } = await github.rest.pulls.get({
|
|
owner,
|
|
repo,
|
|
pull_number,
|
|
});
|
|
|
|
const totalChanges = pull.additions + pull.deletions;
|
|
let nextSize = 'size: XXL';
|
|
if (totalChanges < 50) nextSize = 'size: XS';
|
|
else if (totalChanges < 200) nextSize = 'size: S';
|
|
else if (totalChanges < 500) nextSize = 'size: M';
|
|
else if (totalChanges < 1000) nextSize = 'size: L';
|
|
else if (totalChanges < 2000) nextSize = 'size: XL';
|
|
|
|
const currentLabels = pull.labels.map((label) => label.name);
|
|
const existingSizeLabels = currentLabels.filter((label) => sizeLabels.includes(label));
|
|
const labelsToRemove = existingSizeLabels.filter((label) => label !== nextSize);
|
|
|
|
for (const label of labelsToRemove) {
|
|
try {
|
|
await github.rest.issues.removeLabel({
|
|
owner,
|
|
repo,
|
|
issue_number: pull_number,
|
|
name: label,
|
|
});
|
|
} catch (error) {
|
|
if (error.status !== 404) {
|
|
throw error;
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!currentLabels.includes(nextSize)) {
|
|
await github.rest.issues.addLabels({
|
|
owner,
|
|
repo,
|
|
issue_number: pull_number,
|
|
labels: [nextSize],
|
|
});
|
|
}
|