Skip to content

Commit 71947eb

Browse files
committed
build: add workflow to post comment to PRs without acceptance of contributing guidelines
build: update wording
1 parent d54214f commit 71947eb

File tree

2 files changed

+206
-0
lines changed

2 files changed

+206
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
#/
2+
# @license Apache-2.0
3+
#
4+
# Copyright (c) 2024 The Stdlib Authors.
5+
#
6+
# Licensed under the Apache License, Version 2.0 (the "License");
7+
# you may not use this file except in compliance with the License.
8+
# You may obtain a copy of the License at
9+
#
10+
# http://www.apache.org/licenses/LICENSE-2.0
11+
#
12+
# Unless required by applicable law or agreed to in writing, software
13+
# distributed under the License is distributed on an "AS IS" BASIS,
14+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
# See the License for the specific language governing permissions and
16+
# limitations under the License.
17+
#/
18+
19+
# Workflow name:
20+
name: check_contributing_guidelines_acceptance
21+
22+
# Workflow triggers:
23+
on:
24+
# Allow the workflow to be triggered by other workflows
25+
workflow_call:
26+
# Define the input parameters for the workflow:
27+
inputs:
28+
pull_request_number:
29+
description: 'Pull request number'
30+
required: true
31+
type: number
32+
user:
33+
required: true
34+
type: string
35+
# Define the secrets accessible by the workflow:
36+
secrets:
37+
STDLIB_BOT_GITHUB_TOKEN:
38+
description: 'stdlib-bot GitHub token to create pull request comments'
39+
required: true
40+
41+
# Trigger on pull request events:
42+
pull_request_target:
43+
types: [opened, edited, synchronize, reopened]
44+
45+
# Global permissions:
46+
permissions:
47+
# Allow read-only access to the repository contents:
48+
contents: read
49+
50+
# Allow write access to pull requests:
51+
pull-requests: write
52+
53+
# Workflow jobs:
54+
jobs:
55+
56+
# Define a job for checking the contributing guidelines acknowledgment...
57+
check_acknowledgment:
58+
59+
# Define a display name:
60+
name: 'Check Contributing Guidelines Acknowledgment'
61+
62+
# Define the type of virtual host machine:
63+
runs-on: ubuntu-latest
64+
65+
# Define the sequence of job steps...
66+
steps:
67+
# Checkout the repository:
68+
- name: 'Checkout repository'
69+
# Pin action to full length commit SHA
70+
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
71+
with:
72+
# Specify whether to remove untracked files before checking out the repository:
73+
clean: true
74+
75+
# Limit clone depth to the most recent commit:
76+
fetch-depth: 1
77+
78+
# Specify whether to download Git-LFS files:
79+
lfs: false
80+
timeout-minutes: 10
81+
82+
# Check contributing guidelines acceptance:
83+
- name: 'Check contributing guidelines acceptance'
84+
env:
85+
GITHUB_TOKEN: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
86+
PR_NUMBER: ${{ github.event.pull_request.number || inputs.pull_request_number }}
87+
run: |
88+
. "$GITHUB_WORKSPACE/.github/workflows/scripts/check_contributing_guidelines_acceptance" $PR_NUMBER
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
#!/usr/bin/env bash
2+
#
3+
# @license Apache-2.0
4+
#
5+
# Copyright (c) 2024 The Stdlib Authors.
6+
#
7+
# Licensed under the Apache License, Version 2.0 (the "License");
8+
# you may not use this file except in compliance with the License.
9+
# You may obtain a copy of the License at
10+
#
11+
# http://www.apache.org/licenses/LICENSE-2.0
12+
#
13+
# Unless required by applicable law or agreed to in writing, software
14+
# distributed under the License is distributed on an "AS IS" BASIS,
15+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
# See the License for the specific language governing permissions and
17+
# limitations under the License.
18+
19+
# Script to check if a pull request contains the checked contributing guidelines acknowledgment checkbox.
20+
#
21+
# Usage: check_contributing_guidelines PR_NUMBER
22+
#
23+
# Arguments:
24+
#
25+
# PR_NUMBER Pull request number.
26+
#
27+
# Environment variables:
28+
#
29+
# GITHUB_TOKEN GitHub token for authentication.
30+
31+
# Ensure that the exit status of pipelines is non-zero in the event that at least one of the commands in a pipeline fails:
32+
set -o pipefail
33+
34+
# VARIABLES #
35+
36+
# Get the pull request number:
37+
pr_number="$1"
38+
39+
# Set the repository name:
40+
GITHUB_REPOSITORY="stdlib-js/stdlib"
41+
42+
# Set the contributing guidelines link:
43+
CONTRIBUTING_LINK="https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md"
44+
45+
# FUNCTIONS #
46+
47+
# Error handler.
48+
#
49+
# $1 - error status
50+
on_error() {
51+
echo 'ERROR: An error was encountered during execution.' >&2
52+
exit "$1"
53+
}
54+
55+
# Prints a success message.
56+
print_success() {
57+
echo 'Success!' >&2
58+
}
59+
60+
# Main execution sequence.
61+
main() {
62+
echo "Checking contributing guidelines acknowledgment for PR #${pr_number}..."
63+
64+
# Fetch the pull request body:
65+
if ! pr_body=$(curl -s -H "Authorization: token ${GITHUB_TOKEN}" \
66+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/pulls/${pr_number}" | \
67+
jq -r .body); then
68+
echo "Failed to fetch PR body."
69+
on_error 1
70+
fi
71+
72+
# Check for the contributing guidelines checkbox:
73+
if echo "${pr_body}" | grep -qE '^\s*-\s*\[x\]\s*Read,\s*understood,\s*and\s*followed\s*the\s*\[contributing\s*guidelines\]'; then
74+
echo "Contributing guidelines acknowledged."
75+
print_success
76+
exit 0
77+
else
78+
echo "Contributing guidelines not acknowledged."
79+
80+
# Post a comment on the PR:
81+
comment="Hello! Thank you for your contribution to stdlib.
82+
83+
We noticed that the contributing guidelines acknowledgment is missing from your pull request. Here's what you need to do:
84+
85+
1. Please read our [contributing guidelines][contributing].
86+
2. Update your pull request description to include this checked box:
87+
88+
\`- [x] Read, understood, and followed the [contributing guidelines](https://github.com/stdlib-js/stdlib/blob/develop/CONTRIBUTING.md)\`
89+
90+
This acknowledgment confirms that you've read the guidelines, which include:
91+
92+
- The developer's certificate of origin
93+
- Your agreement to license your contributions under the project's terms
94+
95+
We can't review or accept contributions without this acknowledgment.
96+
97+
Thank you for your understanding and cooperation. We look forward to reviewing your contribution!
98+
99+
[contributing]: ${CONTRIBUTING_LINK}"
100+
101+
if ! curl -s -X POST \
102+
-H "Authorization: token ${GITHUB_TOKEN}" \
103+
-H "Accept: application/vnd.github.v3+json" \
104+
"https://api.github.com/repos/${GITHUB_REPOSITORY}/issues/${pr_number}/comments" \
105+
-d "{\"body\":$(echo "$comment" | jq -R -s -c .)}"; then
106+
echo "Failed to post comment on PR."
107+
on_error 1
108+
fi
109+
110+
exit 1
111+
fi
112+
}
113+
114+
# Set an error handler to print captured output and perform any clean-up tasks:
115+
trap 'on_error' ERR
116+
117+
# Run main:
118+
main

0 commit comments

Comments
 (0)