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

ci: post to mastodon #201

Merged
merged 6 commits into from
Jan 22, 2025
Merged

ci: post to mastodon #201

merged 6 commits into from
Jan 22, 2025

Conversation

cmeesters
Copy link
Member

@cmeesters cmeesters commented Jan 22, 2025

next attempt: filtering out the pr title string, hopefully corrected

Summary by CodeRabbit

  • Chores
    • Updated GitHub workflow script for Mastodon posting
    • Added checks for release pull requests
    • Improved version number extraction process
    • Enhanced error handling for missing PR title

Copy link
Contributor

coderabbitai bot commented Jan 22, 2025

Walkthrough

The pull request modifies the .github/workflows/post_to_mastodon.sh script to improve its handling of pull request announcements. The script now includes additional checks to verify if a pull request is a release PR by examining its title. If the PR title does not match the release pattern, the script will exit without posting to Mastodon. The version extraction process has been refined to capture the version number more accurately, while maintaining the existing validation and posting logic.

Changes

File Change Summary
.github/workflows/post_to_mastodon.sh - Added error handling for unset PR_TITLE
- Implemented conditional check for release PRs
- Updated version extraction logic
- Retained existing Mastodon posting mechanism

Possibly related PRs

Poem

🐰 A rabbit's tale of release and grace,
Mastodon posts now find their place!
Checking titles with a hop and a bound,
Version numbers carefully found.
Automation's magic, script so bright! 🚀


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: 0

🧹 Nitpick comments (2)
.github/workflows/post_to_mastodon.sh (2)

9-14: Consider a more flexible release PR pattern.

While the current pattern works for the exact format chore(main): release, consider making it more flexible to handle variations like:

  • Different scopes (e.g., chore(release))
  • Different prefixes (e.g., release:, feat:)
  • Case variations
-if [[ ! "${PR_TITLE}" =~ ^chore\(main\):\ release ]]; then
+if [[ ! "${PR_TITLE}" =~ [Rr]elease[[:space:]] ]]; then

15-17: Consider using regex capture for more robust version extraction.

While the current approach works for simple cases, it might include unwanted text if there's anything after the version number. Consider using regex capture to extract exactly the version number.

-# Extract version (everything after "release ")
-version="${PR_TITLE#*release }"
+# Extract version using regex capture
+if [[ "${PR_TITLE}" =~ [Rr]elease[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+) ]]; then
+    version="${BASH_REMATCH[1]}"
+else
+    echo "Error: Could not extract version number from PR title"
+    exit 1
+fi

This approach:

  • Extracts exactly the version number
  • Validates the format during extraction
  • Provides better error handling
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 363f130 and 496cf67.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.sh (1 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/post_to_mastodon.sh (1)
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#193
File: .github/workflows/post_to_mastodon.yml:0-0
Timestamp: 2025-01-20T09:24:03.959Z
Learning: In the snakemake-executor-plugin-slurm repository's post_to_mastodon.sh script, the version number is extracted from PR titles using the parameter expansion `${PR_TITLE##* }`, which removes everything up to the last space in the string.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing
🔇 Additional comments (1)
.github/workflows/post_to_mastodon.sh (1)

4-8: LGTM! Good environment variable validation.

The early validation of the required PR_TITLE environment variable with a clear error message is a good practice.

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 (2)
.github/workflows/post_to_mastodon.sh (2)

9-13: Consider making the PR title pattern more flexible.

The current regex pattern might be too restrictive:

  1. It requires "main" as the scope, which might not work for releases from other branches.
  2. It's case-sensitive, which could cause issues with different casing.

Consider this more flexible pattern:

-if [[ ! "${PR_TITLE}" =~ ^chore\(main\):\ release ]]; then
+if [[ ! "${PR_TITLE}" =~ ^[Cc]hore\([^)]+\):\ [Rr]elease ]]; then

15-21: Fix potential edge case in version extraction.

The current regex pattern requires whitespace after the version number, which might fail if the version is at the end of the PR title.

Consider this more robust pattern:

-if [[ "${PR_TITLE}" =~ [Rr]elease[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+) ]]; then
+if [[ "${PR_TITLE}" =~ [Rr]elease[[:space:]]+([0-9]+\.[0-9]+\.[0-9]+)[[:space:]]*$ ]]; then

This pattern ensures it matches versions at the end of the title by:

  1. Making the trailing whitespace optional with [[:space:]]*
  2. Anchoring to the end of the string with $
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 496cf67 and b6a18b5.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.sh (1 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/post_to_mastodon.sh (1)
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#193
File: .github/workflows/post_to_mastodon.yml:0-0
Timestamp: 2025-01-20T09:24:03.959Z
Learning: In the snakemake-executor-plugin-slurm repository's post_to_mastodon.sh script, the version number is extracted from PR titles using the parameter expansion `${PR_TITLE##* }`, which removes everything up to the last space in the string.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing
🔇 Additional comments (2)
.github/workflows/post_to_mastodon.sh (2)

4-8: LGTM! Good error handling.

The validation of the PR_TITLE environment variable is well-implemented with a clear error message and appropriate exit status.


9-21: Verify PR title patterns against repository history.

Let's ensure the new PR title validation aligns with the repository's conventions.

✅ Verification successful

PR title pattern validation is appropriate for new release workflow

The repository is new (created September 2023) with no release history yet. The implemented pattern chore(main): release X.Y.Z follows conventional commits format and is a standard approach for release commits.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check recent PR titles to validate our patterns

# Get recent PR titles
echo "Recent PR titles:"
gh pr list --limit 10 --json title --jq '.[].title'

# Count release PRs with current pattern
echo -e "\nRelease PRs (current pattern):"
gh pr list --limit 50 --json title --jq '.[] | select(.title | test("^chore\\(main\\):\\s+release\\s+\\d+\\.\\d+\\.\\d+\\s*$")) | .title'

# Count release PRs with suggested pattern
echo -e "\nRelease PRs (suggested pattern):"
gh pr list --limit 50 --json title --jq '.[] | select(.title | test("^[Cc]hore\\([^)]+\\):\\s+[Rr]elease\\s+\\d+\\.\\d+\\.\\d+\\s*$")) | .title'

Length of output: 613


Script:

#!/bin/bash
# Get repository info and release history
echo "Repository creation date:"
gh repo view --json createdAt --jq '.createdAt'

echo -e "\nGit tags (latest 10):"
git tag -l --sort=-creatordate | head -n 10

echo -e "\nPRs containing 'release' (case insensitive):"
gh pr list --limit 100 --search "release in:title" --json title --jq '.[].title'

Length of output: 428

@cmeesters cmeesters merged commit 7f3ca0d into main Jan 22, 2025
6 checks passed
@cmeesters cmeesters deleted the ci/Mastodon branch January 22, 2025 13:57
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