Skip to content
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

Merged
merged 8 commits into from
Jan 16, 2025
Merged

feat: Improved Mastodon Bot #183

merged 8 commits into from
Jan 16, 2025

Conversation

cmeesters
Copy link
Member

@cmeesters cmeesters commented Jan 15, 2025

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

    • Added an automated Mastodon release notification script for the Snakemake SLURM executor plugin.
    • Updated GitHub Actions workflow to utilize the new script for posting release updates to Mastodon automatically.
  • Chores

    • Enhanced the release communication process by abstracting the posting logic into a dedicated shell script for Mastodon notifications.
    • Updated .gitignore to include poetry.lock in version control and ignore files matching .aider*.

Copy link
Contributor

coderabbitai bot commented Jan 15, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

A new shell script, post_to_mastodon.sh, has been added to automate posting release notifications to Mastodon for the Snakemake executor plugin for SLURM. The script extracts the version number from the pull request title, constructs a changelog URL, and formats a multi-line message with relevant hashtags. The GitHub Actions workflow has been updated to call this script instead of using an inline curl command, maintaining the same control flow while improving modularity and error handling.

Changes

File Change Summary
.github/workflows/post_to_mastodon.sh New shell script for automated Mastodon release notifications, including version extraction, message formatting, and API interaction.
.github/workflows/post_to_mastodon.yml Updated workflow to call external script for posting to Mastodon instead of inline command, with environment variable setup for token and PR title.
.gitignore Removed line ignoring poetry.lock (now included in version control) and added line to ignore files matching .aider*.

Sequence Diagram

sequenceDiagram
    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
Loading

Possibly related PRs

Poem

🐰 A Rabbit's Release Delight 🚀
In workflows swift, a script takes flight,
Mastodon's realm, our version's might!
From GitHub's merge, a message springs,
Of science open, what progress brings!
Release the code, let knowledge soar! 📢


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 66f02df and ffbcea5.

📒 Files selected for processing (2)
  • .github/workflows/post_to_mastodon.sh (1 hunks)
  • .gitignore (2 hunks)

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?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 handling

The message construction could benefit from some improvements:

  1. Add character limit validation (Mastodon typically has a 500 character limit)
  2. 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

📥 Commits

Reviewing files that changed from the base of the PR and between da8e6ba and 32dbef3.

📒 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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 issue

Fix 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 issue

Fix 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 issue

Improve 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 maintainability

The script would benefit from:

  1. Moving configuration (URLs, message templates, API endpoints) to a separate file
  2. Breaking down functionality into reusable functions
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between 32dbef3 and 92e4893.

📒 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

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 validation

The 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 limit

The 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 URL

There'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

📥 Commits

Reviewing files that changed from the base of the PR and between 92e4893 and 66f02df.

📒 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 interaction

The code demonstrates good practices:

  • Secure handling of credentials
  • Proper response parsing
  • Clear error messages with HTTP status codes
  • Appropriate exit codes

@cmeesters cmeesters merged commit 151b0fb into main Jan 16, 2025
4 of 5 checks passed
@cmeesters cmeesters deleted the feat/Mastodonbot branch January 16, 2025 17:06
cmeesters pushed a commit that referenced this pull request Jan 16, 2025
🤖 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>
@cmeesters cmeesters mentioned this pull request Jan 16, 2025
cmeesters added a commit that referenced this pull request Jan 16, 2025
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 -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant