Skip to content

vuki test 5

vuki test 5 #11

name: Label Issues and PRs on Open/Reopen
on:
issues:
types: [opened, reopened] # Trigger when an issue is opened or reopened
pull_request:
types: [opened, reopened] # Trigger when a PR is opened or reopened
jobs:
labelIssuePR:
name: Apply Label to Issues and PRs
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Add Label to Issue or PR
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
// Check if it's an issue or a PR
if (context.eventName === 'issues') {
// Add label to issue
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
labels: ['needs-team-review']
});
} else if (context.eventName === 'pull_request') {
// Add label to PR
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.payload.pull_request.number,
labels: ['needs-team-review']
});
}
result-encoding: string
id: result
- name: Get result
run: echo "${{steps.result.outputs.result}}"
- name: Check if author is external and label accordingly
uses: actions/github-script@v7
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const author = context.payload.pull_request.user.login;
const owner = context.repo.owner;
const repo = context.repo.repo;
let isCollaborator = false;
// Check if the author is a collaborator in the repository
try {
await github.rest.repos.checkCollaborator({
owner: owner,
repo: repo,
username: author
});
isCollaborator = true;
} catch (error) {
isCollaborator = false;
}
// If the author is not a collaborator, mark as "external"
if (!isCollaborator) {
await github.rest.issues.addLabels({
owner: owner,
repo: repo,
issue_number: context.payload.pull_request.number,
labels: ['external']
});
}