From 57300ef4374a96e146afa4fc949aee794aef6a6f Mon Sep 17 00:00:00 2001 From: Philipp Burckhardt Date: Fri, 24 Jan 2025 19:05:37 -0500 Subject: [PATCH] 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 --- --- .github/workflows/slash_commands.yml | 42 ++++++++++++++++++---------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/.github/workflows/slash_commands.yml b/.github/workflows/slash_commands.yml index 258449d2a2a3..d3098b1f5b75 100644 --- a/.github/workflows/slash_commands.yml +++ b/.github/workflows/slash_commands.yml @@ -59,21 +59,33 @@ jobs: # Add initial reaction to comment with slash command: - name: 'Add initial reaction' - run: | - COMMENT="${{ github.event.comment.body }}" - if [[ $COMMENT =~ ^/stdlib\ (help|check-files|update-copyright-years|lint-autofix|merge|rebase) ]]; then - curl -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/comments/${{ github.event.comment.id }}/reactions" \ - -d '{"content":"eyes"}' - else - curl -X POST \ - -H "Accept: application/vnd.github.v3+json" \ - -H "Authorization: Bearer ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }}" \ - "https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/comments" \ - -d '{"body":"@${{ github.event.comment.user.login }}, slash command not recognized. Please use `/stdlib help` to view available commands."}' - fi + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 + with: + github-token: ${{ secrets.STDLIB_BOT_GITHUB_TOKEN }} + script: | + const commentBody = github.event.comment.body.trim(); + const RE_COMMANDS = /^\/stdlib\s+(help|check-files|update-copyright-years|lint-autofix|merge|rebase)$/i; + const isRecognizedCommand = RE_COMMANDS.test( commentBody ); + + if ( isRecognizedCommand ) { + await github.rest.reactions.createForIssueComment({ + 'owner': context.repo.owner, + 'repo': context.repo.repo, + 'comment_id': github.event.comment.id, + 'content': 'eyes' + }); + } else { + // Include the full user comment as a Markdown quote block in response: + const lines = commentBody.split( '\n' ); + const quote = lines.map( line => `> ${line}` ).join( '\n' ); + + await github.rest.issues.createComment({ + 'owner': context.repo.owner, + 'repo': context.repo.repo, + 'issue_number': github.event.issue.number, + 'body': `${quote}\n\n@${github.event.comment.user.login}, slash command not recognized. Please use \`/stdlib help\` to view available commands.` + }); + } # Define a job for checking for required files: check_files: