-
Notifications
You must be signed in to change notification settings - Fork 24
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Improved Mastodon Bot #183
Conversation
Caution Review failedThe pull request is closed. WalkthroughA new shell script, Changes
Sequence DiagramsequenceDiagram
participant GH as GitHub Actions
participant Script as post_to_mastodon.sh
participant Mastodon as Mastodon API
GH->>Script: Trigger on PR merge
Script->>Script: Extract version number
Script->>Script: Construct release message
Script->>Mastodon: POST notification
Mastodon-->>Script: API response
Possibly related PRs
Poem
📜 Recent review detailsConfiguration used: .coderabbit.yaml 📒 Files selected for processing (2)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
Documentation and Community
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 4
🧹 Nitpick comments (1)
.github/workflows/post_to_mastodon.sh (1)
6-17
: Consider improving message format and error handlingThe message construction could benefit from some improvements:
- Add character limit validation (Mastodon typically has a 500 character limit)
- Consider making the message template more maintainable
+# Define maximum message length +MAX_LENGTH=500 + read -d '\n' message << EndOfText Beep, Beepi - I am the #Snakemake release bot I have a new release in for the Snakemake executor for #SLURM on #HPC systems. The version now is '${version}'. See ${changelog} for details. Get the latest release from #Bioconda or #Pypi. Be sure to give it some time to be released there, too. #OpenScience #ReproducibleResearch #ReproducibleComputing EndOfText + +# Validate message length +if [ ${#message} -gt $MAX_LENGTH ]; then + echo "Error: Message exceeds Mastodon's character limit" + exit 1 +fi
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/post_to_mastodon.sh
(1 hunks).github/workflows/post_to_mastodon.yml
(1 hunks)
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/workflows/post_to_mastodon.sh
[error] 1-1: Ensure the shebang uses an absolute path to the interpreter.
(SC2239)
[error] 3-3: To expand via indirection, use arrays, ${!name} or (for sh only) eval.
(SC2082)
[error] 3-3: Parameter expansions can't start with {. Double check syntax.
(SC2296)
[error] 19-19: Parameter expansions can't start with {. Double check syntax.
(SC2296)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
♻️ Duplicate comments (3)
.github/workflows/post_to_mastodon.sh (3)
1-1
:⚠️ Potential issueFix shebang path
The shebang should use an absolute path to the interpreter.
-#!bin/bash +#!/bin/bash🧰 Tools
🪛 Shellcheck (0.10.0)
[error] 1-1: Ensure the shebang uses an absolute path to the interpreter.
(SC2239)
3-4
:⚠️ Potential issueFix version extraction and add validation
The version extraction has syntax errors and lacks validation.
-version="${${{ github.event.pull_request.title }}##* }" -changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}" +# Extract version from PR title passed as environment variable +version="${PR_TITLE##* }" + +# Validate version format +if ! [[ $version =~ ^[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Error: Invalid version format in PR title: $version" + exit 1 +fi + +# Construct changelog URL with proper quoting +changelog="https://github.com/snakemake/snakemake-executor-plugin-slurm/releases/tag/v${version}"Let's verify the version format in PR titles:
#!/bin/bash # Search for version patterns in PR titles to understand common formats gh pr list --json title --jq '.[] | .title' | grep -E '[0-9]+\.[0-9]+\.[0-9]+' -o || echo "No semantic versions found in PR titles"🧰 Tools
🪛 Shellcheck (0.10.0)
[error] 3-3: To expand via indirection, use arrays, ${!name} or (for sh only) eval.
(SC2082)
[error] 3-3: Parameter expansions can't start with {. Double check syntax.
(SC2296)
19-26
:⚠️ Potential issueImprove curl command security and error handling
The current curl command has several security concerns.
-curl -X POST -H "Authorization: Bearer ${{ secrets.MASTODONBOT }}" \ - -F "status=${message}" \ - https://fediscience.org/api/v1/statuses \ - -w "\nResponse code: %{http_code}\n" \ - -f || { - echo "Failed to post to Mastodon" - exit 1 - } +# Validate Mastodon token +if [ -z "${MASTODONBOT}" ]; then + echo "Error: MASTODONBOT secret is not set" + exit 1 +fi + +# Send post to Mastodon with proper quoting and error handling +response=$(curl -s -w "\n%{http_code}" -X POST \ + -H "Authorization: Bearer ${MASTODONBOT}" \ + -F "status=${message}" \ + "https://fediscience.org/api/v1/statuses") + +status_code=$(echo "$response" | tail -n1) +response_body=$(echo "$response" | sed '$d') + +if [ "$status_code" -ne 200 ]; then + echo "Error: Failed to post to Mastodon (HTTP ${status_code})" + echo "Response: ${response_body}" + exit 1 +fi + +echo "Successfully posted to Mastodon"🧰 Tools
🪛 Shellcheck (0.10.0)
[error] 19-19: Parameter expansions can't start with {. Double check syntax.
(SC2296)
🧹 Nitpick comments (1)
.github/workflows/post_to_mastodon.sh (1)
1-26
: Consider restructuring for improved maintainabilityThe script would benefit from:
- Moving configuration (URLs, message templates, API endpoints) to a separate file
- Breaking down functionality into reusable functions
- Adding proper logging and debugging support
Would you like me to propose a restructured version of the script that follows these principles?
🧰 Tools
🪛 Shellcheck (0.10.0)
[error] 1-1: Ensure the shebang uses an absolute path to the interpreter.
(SC2239)
[error] 3-3: To expand via indirection, use arrays, ${!name} or (for sh only) eval.
(SC2082)
[error] 3-3: Parameter expansions can't start with {. Double check syntax.
(SC2296)
[error] 19-19: Parameter expansions can't start with {. Double check syntax.
(SC2296)
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
.github/workflows/post_to_mastodon.sh
(1 hunks).github/workflows/post_to_mastodon.yml
(1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
- .github/workflows/post_to_mastodon.yml
🧰 Additional context used
🪛 Shellcheck (0.10.0)
.github/workflows/post_to_mastodon.sh
[error] 1-1: Ensure the shebang uses an absolute path to the interpreter.
(SC2239)
[error] 3-3: To expand via indirection, use arrays, ${!name} or (for sh only) eval.
(SC2082)
[error] 3-3: Parameter expansions can't start with {. Double check syntax.
(SC2296)
[error] 19-19: Parameter expansions can't start with {. Double check syntax.
(SC2296)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: testing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
.github/workflows/post_to_mastodon.sh (3)
3-10
: Add PR_TITLE environment variable validationThe script should validate that PR_TITLE is set before attempting to extract the version.
# Extract version from PR title passed as environment variable +if [ -z "${PR_TITLE}" ]; then + echo "Error: PR_TITLE environment variable is not set" + exit 1 +fi + version="${PR_TITLE##* }"
15-16
: Update MAX_TOOT_LENGTH to match Fediscience's limitThe comment indicates Fediscience's limit is 1500 characters, but the variable is set to 500.
-# Maximum character limit for Mastodon posts (on Fediscience: 1500 characters) -MAX_TOOT_LENGTH=500 +# Maximum character limit for Mastodon posts on Fediscience +MAX_TOOT_LENGTH=1500
24-24
: Fix spacing in changelog URLThere's a missing space after the URL escaping.
-See ${changelog//\'/\\\'}for details. +See ${changelog//\'/\\\' }for details.
📜 Review details
Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
.github/workflows/post_to_mastodon.sh
(1 hunks)
🧰 Additional context used
📓 Learnings (2)
📓 Common learnings
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#183
File: .github/workflows/post_to_mastodon.sh:6-17
Timestamp: 2025-01-15T14:23:31.720Z
Learning: Version strings in Snakemake releases do not contain single quotes, making quote escaping unnecessary in the post_to_mastodon.sh script.
.github/workflows/post_to_mastodon.sh (1)
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#183
File: .github/workflows/post_to_mastodon.sh:6-17
Timestamp: 2025-01-15T14:23:31.720Z
Learning: The Mastodon instance used by the Snakemake project has a higher character limit than the standard 500 characters, making strict character limit validation unnecessary in the post_to_mastodon.sh script.
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: testing
🔇 Additional comments (1)
.github/workflows/post_to_mastodon.sh (1)
48-63
: LGTM! Robust implementation of Mastodon API interactionThe code demonstrates good practices:
- Secure handling of credentials
- Proper response parsing
- Clear error messages with HTTP status codes
- Appropriate exit codes
🤖 I have created a release *beep* *boop* --- ## [0.13.0](v0.12.1...v0.13.0) (2025-01-16) ### Features * Improved Mastodon Bot ([#183](#183)) ([151b0fb](151b0fb)) --- This PR was generated with [Release Please](https://github.com/googleapis/release-please). See [documentation](https://github.com/googleapis/release-please#release-please). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
like #183 - there is a mismatch in the allowed commands <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit - **New Features** - Added an automated script to post release announcements to Mastodon - Implemented a GitHub Actions workflow to trigger Mastodon announcements after pull request merges - **Chores** - Updated `.gitignore` to include new file exclusion patterns - Refined release announcement process with improved error handling and messaging <!-- end of auto-generated comment: release notes by coderabbit.ai -->
We have a Mastodon release bot. This PR attempts to test a generic message format. It therefore also splits the action yaml into the action definition and the release script for better maintenance.
It is an experiment.
Summary by CodeRabbit
New Features
Chores
.gitignore
to includepoetry.lock
in version control and ignore files matching.aider*
.