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

Update label.yml #4182

Merged
merged 3 commits into from
Oct 4, 2023
Merged
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
34 changes: 20 additions & 14 deletions .github/workflows/label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,22 @@ name: Add/Remove Labels

on:
pull_request_target:
types: [ opened ]
types: [opened]

jobs:
add_new_contributor_label:
if: github.event.action == 'opened'
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- uses: actions/github-script@v6
with:
script: |
const creator = context.payload.sender.login;
const opts = github.rest.issues.listForRepo.endpoint.merge({
...context.issue,
- name: Add new contributor label
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
async function run() {
const creator = github.context.payload.sender.login;
const opts = github.context.repo.issues.listForRepo.endpoint.merge({
...github.context.issue,
creator,
state: 'all',
});
Expand All @@ -27,7 +27,7 @@ jobs:
let isAlreadyContributor = false;

for (const issue of issues) {
if (issue.number === context.issue.number) {
if (issue.number === github.context.issue.number) {
continue;
}
if (issue.pull_request && issue.user.login === creator) {
Expand All @@ -37,10 +37,16 @@ jobs:
}

if (!isAlreadyContributor) {
console.log('Adding label: new contributor');
await github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: github.context.issue.number,
owner: github.context.repo.owner,
repo: github.context.repo.repo,
labels: ['new contributor'],
});
} else {
console.log('User is already a contributor, no label added.');
}
}

run(); // Call the async function to execute the code
Loading