passkey_fw/.github/workflows/labeler.yml

66 lines
2.0 KiB
YAML
Raw Normal View History

2024-03-25 07:54:35 +01:00
name: Labeler
on:
issues:
types: [opened]
pull_request:
types: [opened]
jobs:
label-priority:
runs-on: ubuntu-latest
steps:
- name: Label New Issue or PR
uses: actions/github-script@v7
with:
2024-03-28 06:12:07 +01:00
github-token: ${{ secrets.GITHUB_TOKEN }}
2024-03-25 07:54:35 +01:00
script: |
let label = '';
let username = '';
let issueOrPrNumber = 0;
if (context.eventName === 'issues') {
username = context.payload.issue.user.login;
issueOrPrNumber = context.payload.issue.number;
} else if (context.eventName === 'pull_request') {
username = context.payload.pull_request.user.login;
issueOrPrNumber = context.payload.pull_request.number;
}
2024-04-03 08:05:53 +02:00
try {
// Check for Adafruit membership
const adafruitResponse = await github.rest.orgs.checkMembershipForUser({
org: 'adafruit',
2024-03-25 07:54:35 +01:00
username: username
});
2024-04-03 08:05:53 +02:00
if (adafruitResponse.status === 204) {
console.log('Adafruit Member');
label = 'Prio Urgent';
2024-03-25 07:54:35 +01:00
} else {
2024-04-03 08:05:53 +02:00
// If not a Adafruit member, check if the user is a contributor
const collaboratorResponse = await github.rest.repos.checkCollaborator({
owner: context.repo.owner,
repo: context.repo.repo,
username: username
});
if (collaboratorResponse.status === 204) {
console.log('Contributor');
label = 'Prio Higher';
}
2024-03-25 07:54:35 +01:00
}
2024-04-03 08:05:53 +02:00
} catch (error) {
console.log(`Error processing user ${username}: ${error.message}`);
2024-03-25 07:54:35 +01:00
}
if (label !== '') {
await github.rest.issues.addLabels({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issueOrPrNumber,
labels: [label]
});
}