Skip to content

Commit 6264042

Browse files
committed
chore: clean-up script
--- 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: passed - 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 69d4f4b commit 6264042

File tree

1 file changed

+39
-38
lines changed

1 file changed

+39
-38
lines changed

.github/workflows/scripts/references_good_first_issue

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818

1919
# Script to check whether a PR references an issue with label "Good First Issue".
2020
#
21-
# Usage: references_good_first_issue PR_NUMBER
21+
# Usage: references_good_first_issue <pr_number>
2222
#
2323
# Arguments:
2424
#
25-
# PR_NUMBER Pull request number.
25+
# pr_number Pull request number.
2626
#
2727
# Environment variables:
2828
#
@@ -34,19 +34,15 @@ set -o pipefail
3434

3535
# VARIABLES #
3636

37-
# Get the pull request number:
37+
# Resolve the pull request number:
3838
pr_number="$1"
3939

4040
# GitHub API base URL:
41-
GITHUB_API_URL="https://api.github.com"
41+
github_api_url="https://api.github.com"
4242

4343
# Repository owner and name:
44-
REPO_OWNER="stdlib-js"
45-
REPO_NAME="stdlib"
46-
47-
# Exit codes:
48-
SUCCESS=0
49-
ERROR=1
44+
repo_owner="stdlib-js"
45+
repo_name="stdlib"
5046

5147

5248
# FUNCTIONS #
@@ -59,7 +55,7 @@ on_error() {
5955
exit "$1"
6056
}
6157

62-
# Makes GitHub API requests.
58+
# Performs a GitHub API request.
6359
#
6460
# $1 - HTTP method (GET or POST)
6561
# $2 - API endpoint
@@ -73,66 +69,71 @@ github_api() {
7369
local headers=()
7470

7571
# If GITHUB_TOKEN is set, add the Authorization header:
76-
if [ -n "$GITHUB_TOKEN" ]; then
77-
headers+=("-H" "Authorization: token $GITHUB_TOKEN")
72+
if [ -n "${GITHUB_TOKEN}" ]; then
73+
headers+=("-H" "Authorization: token ${GITHUB_TOKEN}")
7874
fi
7975

8076
# Determine the HTTP method and construct the curl command accordingly...
81-
case "$method" in
77+
case "${method}" in
8278
GET)
83-
curl -s "${headers[@]}" "$GITHUB_API_URL$endpoint"
79+
curl -s "${headers[@]}" "${github_api_url}${endpoint}"
8480
;;
8581
POST)
8682
# For POST requests, always set the Content-Type header:
8783
headers+=("-H" "Content-Type: application/json")
8884

8985
# If data is provided, include it in the request:
90-
if [ -n "$data" ]; then
91-
curl -s -X POST "${headers[@]}" -d "$data" "$GITHUB_API_URL$endpoint"
86+
if [ -n "${data}" ]; then
87+
curl -s -X POST "${headers[@]}" -d "${data}" "${github_api_url}${endpoint}"
9288
else
9389
# Handle cases where POST data is required but not provided:
94-
echo "POST request requires data."
95-
on_error $ERROR
90+
echo "ERROR: POST request requires data."
91+
on_error 1
9692
fi
9793
;;
9894
*)
99-
echo "Invalid HTTP method: $method"
100-
on_error $ERROR
95+
echo "ERROR: Invalid HTTP method: ${method}."
96+
on_error 1
10197
;;
10298
esac
10399
}
104100

105101
# Main execution sequence.
106102
main() {
107-
if [ -z "$pr_number" ]; then
108-
echo "ERROR: Pull request number is required" >&2
109-
on_error $ERROR
103+
local issue_numbers
104+
local issue_details
105+
local pr_details
106+
local pr_body
107+
local issue
108+
local bool
109+
110+
if [ -z "${pr_number}" ]; then
111+
echo "ERROR: Pull request number is required." >&2
112+
on_error 1
110113
fi
111114

112115
# Fetch pull request details:
113-
pr_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/pulls/$pr_number")
114-
pr_title=$(echo "$pr_details" | jq -r '.title')
115-
pr_body=$(echo "$pr_details" | jq -r '.body')
116+
pr_details=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/pulls/${pr_number}")
117+
pr_body=$(echo "${pr_details}" | jq -r '.body')
116118

117-
issue_numbers=$(echo $pr_body | grep -Ei '#[0-9]+' | grep -oEi '[0-9]+' | sort | uniq)
118-
if [ -z "$issue_numbers" ]; then
119+
issue_numbers=$(echo "${pr_body}" | grep -Ei '#[0-9]+' | grep -oEi '[0-9]+' | sort | uniq)
120+
if [ -z "${issue_numbers}" ]; then
119121
echo 'false'
120-
exit $SUCCESS
122+
exit 0
121123
fi
122124

123-
for issue in $issue_numbers; do
124-
issue_details=$(github_api "GET" "/repos/$REPO_OWNER/$REPO_NAME/issues/$issue")
125+
for issue in ${issue_numbers}; do
126+
issue_details=$(github_api "GET" "/repos/${repo_owner}/${repo_name}/issues/${issue}")
125127

126-
bool=$(echo $issue_details | jq '.labels | any(.name == "Good First Issue")')
127-
if [ "$bool" == 'true' ]; then
128+
bool=$(echo "${issue_details}" | jq '.labels | any(.name == "Good First Issue")')
129+
if [ "${bool}" == 'true' ]; then
128130
echo 'true'
129-
exit $SUCCESS
131+
exit 0
130132
fi
131133
done
132134

133135
echo 'false'
134-
exit $SUCCESS
136+
exit 0
135137
}
136138

137-
# Call main with all command-line arguments:
138-
main "$@"
139+
main

0 commit comments

Comments
 (0)