Skip to content

Commit 57300ef

Browse files
committed
build: rewrite as GitHub client script and include full quote for unknown commands
--- 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: passed - 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: passed ---
1 parent 3446619 commit 57300ef

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

.github/workflows/slash_commands.yml

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -59,21 +59,33 @@ jobs:
5959
6060
# Add initial reaction to comment with slash command:
6161
- name: 'Add initial reaction'
62-
run: |
63-
COMMENT="${{ github.event.comment.body }}"
64-
if [[ $COMMENT =~ ^/stdlib\ (help|check-files|update-copyright-years|lint-autofix|merge|rebase) ]]; then
65-
curl -X POST \
66-
-H "Accept: application/vnd.github.v3+json" \
67-
-H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \
68-
"https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \
69-
-d '{"content":"eyes"}'
70-
else
71-
curl -X POST \
72-
-H "Accept: application/vnd.github.v3+json" \
73-
-H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \
74-
"https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \
75-
-d '{"body":"@${{ github.event.comment.user.login }}, slash command not recognized. Please use `/stdlib help` to view available commands."}'
76-
fi
62+
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
63+
with:
64+
github-token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}
65+
script: |
66+
const commentBody = github.event.comment.body.trim();
67+
const RE_COMMANDS = /^\/stdlib\s+(help|check-files|update-copyright-years|lint-autofix|merge|rebase)$/i;
68+
const isRecognizedCommand = RE_COMMANDS.test( commentBody );
69+
70+
if ( isRecognizedCommand ) {
71+
await github.rest.reactions.createForIssueComment({
72+
'owner': context.repo.owner,
73+
'repo': context.repo.repo,
74+
'comment_id': github.event.comment.id,
75+
'content': 'eyes'
76+
});
77+
} else {
78+
// Include the full user comment as a Markdown quote block in response:
79+
const lines = commentBody.split( '\n' );
80+
const quote = lines.map( line => `> ${line}` ).join( '\n' );
81+
82+
await github.rest.issues.createComment({
83+
'owner': context.repo.owner,
84+
'repo': context.repo.repo,
85+
'issue_number': github.event.issue.number,
86+
'body': `${quote}\n\n@${github.event.comment.user.login}, slash command not recognized. Please use \`/stdlib help\` to view available commands.`
87+
});
88+
}
7789
7890
# Define a job for checking for required files:
7991
check_files:

0 commit comments

Comments
 (0)