Skip to content

Commit da7198b

Browse files
committed
build: label pull requests from first-time contributors
--- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: na - task: lint_package_json status: na - task: lint_repl_help status: na - task: lint_javascript_src status: na - task: lint_javascript_cli status: na - task: lint_javascript_examples status: na - task: lint_javascript_tests status: na - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: na - task: lint_typescript_tests status: na - task: lint_license_headers status: passed --- --- type: pre_push_report description: Results of running various checks prior to pushing changes. report: - task: run_javascript_examples status: na - task: run_c_examples status: na - task: run_cpp_examples status: na - task: run_javascript_readme_examples status: na - task: run_c_benchmarks status: na - task: run_cpp_benchmarks status: na - task: run_fortran_benchmarks status: na - task: run_javascript_benchmarks status: na - task: run_julia_benchmarks status: na - task: run_python_benchmarks status: na - task: run_r_benchmarks status: na - task: run_javascript_tests status: na ---
1 parent 60983a6 commit da7198b

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

.github/workflows/labeler.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ on:
2424
pull_request_target:
2525
types:
2626
- opened
27+
- closed
2728
- synchronize
2829
- reopened
2930
- edited
@@ -64,6 +65,24 @@ jobs:
6465
configuration-path: .github/labeler.yml
6566
repo-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
6667

68+
# Add "First-time Contributor" label if PR is from a first-time contributor:
69+
- name: 'Add "First-time Contributor" label if PR is from a first-time contributor'
70+
if: ${{ ( github.event.action == 'opened' || github.event.action == 'reopened' ) && github.event.pull_request.author_association == 'FIRST_TIME_CONTRIBUTOR' }}
71+
# Pin action to full-length commit SHA
72+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
73+
with:
74+
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
75+
script: |
76+
const labels = context.payload.pull_request.labels.map( label => label.name );
77+
if ( !labels.includes( 'First-time Contributor' ) ) {
78+
await github.rest.issues.addLabels({
79+
'owner': context.repo.owner,
80+
'repo': context.repo.repo,
81+
'issue_number': context.payload.pull_request.number,
82+
'labels': [ 'First-time Contributor' ]
83+
});
84+
}
85+
6786
# Add "Needs Review" label when PR is opened and not a draft:
6887
- name: 'Add "Needs Review" label if PR is opened and not draft'
6988
if: ${{ github.event.action == 'opened' && github.event.pull_request.draft == false }}
@@ -133,3 +152,35 @@ jobs:
133152
console.log( 'Error removing label %s: %s', label, error.message );
134153
}
135154
}
155+
156+
# Remove "First-time Contributor" label from other open PRs if PR is merged:
157+
- name: 'Remove "First-time Contributor" label from other open PRs if PR is merged'
158+
if: ${{ github.event.action == 'closed' && github.event.pull_request.merged == true }}
159+
# Pin action to full length commit SHA
160+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
161+
with:
162+
github-token: ${{ secrets.CHATBOT_GITHUB_TOKEN }}
163+
script: |
164+
const prAuthor = context.payload.pull_request.user.login;
165+
166+
const { data: pullRequests } = await github.rest.pulls.list({
167+
'owner': context.repo.owner,
168+
'repo': context.repo.repo,
169+
'state': 'open'
170+
});
171+
172+
// Remove "First-time Contributor" label from any other open PRs by the same author:
173+
for ( const pull of pullRequests ) {
174+
if ( pull.user.login === prAuthor ) {
175+
try {
176+
await github.rest.issues.removeLabel({
177+
'owner': context.repo.owner,
178+
'repo': context.repo.repo,
179+
'issue_number': pull.number,
180+
'name': 'First-time Contributor'
181+
});
182+
} catch ( error ) {
183+
console.log( 'Error removing "First-time Contributor" label from PR #%d: %s', pull.number, error.message );
184+
}
185+
}
186+
}

0 commit comments

Comments
 (0)