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

fix: mastodonbot #187

Merged
merged 6 commits into from
Jan 17, 2025
Merged

fix: mastodonbot #187

merged 6 commits into from
Jan 17, 2025

Conversation

cmeesters
Copy link
Member

@cmeesters cmeesters commented Jan 17, 2025

attempt to fix the mastodon publisher:

  • that the bot does not post on merged pull request, but only on releases (it used to publish the merge and the release)
  • that the script is found (./post_to_mastodon.sh does not seem to work, perhaps $(pwd)/post_to_mastodon.sh will?)

Summary by CodeRabbit

  • Chores
    • Updated GitHub Actions workflow for Mastodon posting.
    • Modified workflow trigger to run on push to the main branch after a pull request merge.
    • Changed environment variable to use release tag name instead of pull request title.
    • Added a step to check out the repository.

Copy link
Contributor

coderabbitai bot commented Jan 17, 2025

Warning

Rate limit exceeded

@cmeesters has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 12 minutes and 15 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 68e3d95 and 2d9c5e8.

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

Walkthrough

The pull request modifies the GitHub Actions workflow for posting to Mastodon upon a push event instead of a pull request merge. The trigger for the workflow has changed from pull_request to push, specifically targeting the main branch when a pull request is closed. The job condition remains to check if the pull request was merged. Additionally, a new step has been added to check out the repository using actions/checkout@v4. The command to execute the script has been updated to an absolute path, and the environment variable for the pull request title has been changed to use the release tag name.

Changes

File Change Summary
.github/workflows/post_to_mastodon.yml - Workflow trigger changed from pull_request to push on main branch
- Environment variable PR_TITLE updated to use release tag name
- Script path updated to absolute path $GITHUB_WORKSPACE/post_to_mastodon.sh
- Added step to check out repository using actions/checkout@v4

Possibly related PRs

Suggested reviewers

  • johanneskoester

Poem

🐰 A workflow hops from branch to main,
Mastodon posts, no effort in vain!
Paths absolute, triggers refined,
Code deployment, perfectly aligned.
Rabbit's magic in GitHub's domain! 🚀


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

🔭 Outside diff range comments (2)
.github/workflows/post_to_mastodon.yml (2)

Line range hint 4-8: Workflow configuration needs revision to match requirements

There are several issues with the current workflow trigger configuration:

  1. The types: [closed] is invalid for push events (it's only valid for pull_request events)
  2. The current trigger doesn't match the PR objective of "only publishing updates on releases"

To fix these issues and align with the requirement to post only on releases, modify the trigger to:

-  push:
-    branches:
-      - main
-    types:
-      - closed
+  release:
+    types:
+      - published

Additionally, the job condition if: github.event.pull_request.merged == true will need to be removed as it won't work with release events.

🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)


Critical: Missing script and incorrect event trigger configuration

The workflow has multiple issues that need to be addressed:

  • The post_to_mastodon.sh script is missing from the repository
  • The workflow configuration mixes push and pull request event properties incorrectly:
    • Uses push event but checks github.event.pull_request.merged
    • Includes types under push event which is invalid
🔗 Analysis chain

Line range hint 1-27: Verify script compatibility with release events

Let's verify the existence and compatibility of the post_to_mastodon.sh script with release events.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check if the script exists and examine its content
if [ -f "post_to_mastodon.sh" ]; then
    echo "Script exists. Checking content:"
    cat post_to_mastodon.sh
else
    echo "Warning: post_to_mastodon.sh not found in repository"
fi

Length of output: 147


Script:

#!/bin/bash
# Search for any mastodon-related shell scripts
fd -e sh -g '*mastodon*.sh'

# Check PR files for potential script addition
gh pr view ${{ github.event.pull_request.number }} --json files -q '.files[].path'

Length of output: 158

🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between ae72d2b and 3599c24.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/post_to_mastodon.yml

4-4: "types" cannot be specified for "push" Webhook event

(events)

⏰ Context from checks skipped due to timeout of 90000ms (2)
  • GitHub Check: formatting
  • 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

🔭 Outside diff range comments (2)
.github/workflows/post_to_mastodon.yml (2)

Line range hint 4-8: Fix the workflow trigger to respond to releases.

The current trigger configuration has issues:

  1. types is not valid for push events
  2. This won't achieve the goal of posting only on releases

Apply this diff to fix the trigger:

-  push:
-    branches:
-      - main
-    types:
-      - closed
+  release:
+    types:
+      - released
🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)


Line range hint 14-14: Remove the PR merge condition.

Since we're switching to release events, the PR merge condition should be removed as it won't work with release events.

Remove this line:

-    if: github.event.pull_request.merged == true
🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 3599c24 and 07ae8de.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.yml (2 hunks)
🧰 Additional context used
🪛 actionlint (1.7.4)
.github/workflows/post_to_mastodon.yml

4-4: "types" cannot be specified for "push" Webhook event

(events)


20-20: key "uses" is duplicated in element of "steps" section. previously defined at line:19,col:9

(syntax-check)


22-22: input "timeout_minutes" is not defined in action "actions/checkout@v4". available inputs are "clean", "fetch-depth", "fetch-tags", "filter", "github-server-url", "lfs", "path", "persist-credentials", "ref", "repository", "set-safe-directory", "show-progress", "sparse-checkout", "sparse-checkout-cone-mode", "ssh-key", "ssh-known-hosts", "ssh-strict", "ssh-user", "submodules", "token"

(action)


23-23: input "max_attempts" is not defined in action "actions/checkout@v4". available inputs are "clean", "fetch-depth", "fetch-tags", "filter", "github-server-url", "lfs", "path", "persist-credentials", "ref", "repository", "set-safe-directory", "show-progress", "sparse-checkout", "sparse-checkout-cone-mode", "ssh-key", "ssh-known-hosts", "ssh-strict", "ssh-user", "submodules", "token"

(action)


24-24: input "command" is not defined in action "actions/checkout@v4". available inputs are "clean", "fetch-depth", "fetch-tags", "filter", "github-server-url", "lfs", "path", "persist-credentials", "ref", "repository", "set-safe-directory", "show-progress", "sparse-checkout", "sparse-checkout-cone-mode", "ssh-key", "ssh-known-hosts", "ssh-strict", "ssh-user", "submodules", "token"

(action)

🪛 yamllint (1.35.1)
.github/workflows/post_to_mastodon.yml

[error] 20-20: duplication of key "uses" in mapping

(key-duplicates)

⏰ 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

🔭 Outside diff range comments (2)
.github/workflows/post_to_mastodon.yml (2)

Line range hint 4-8: Fix workflow trigger to post only on releases

The current trigger configuration has several issues:

  1. The types field is not valid for push events
  2. This configuration won't achieve the goal of posting only on releases

To post only on releases, replace the trigger with:

-  push:
-    branches:
-      - main
-    types:
-      - closed
+  release:
+    types:
+      - published
🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)


Line range hint 14-14: Fix job condition for release events

The current condition checks for merged pull requests, but the workflow should run on releases.

Remove or update the condition:

-    if: github.event.pull_request.merged == true
+    if: github.event.action == 'published'
🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 07ae8de and 0321286.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.yml (2 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/post_to_mastodon.yml (1)
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#187
File: .github/workflows/post_to_mastodon.yml:0-0
Timestamp: 2025-01-17T17:27:32.446Z
Learning: In the mastodon publishing workflow for snakemake-executor-plugin-slurm, the PR_TITLE environment variable is required by the post_to_mastodon.sh script and should be preserved.
🪛 actionlint (1.7.4)
.github/workflows/post_to_mastodon.yml

4-4: "types" cannot be specified for "push" Webhook event

(events)

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

🔭 Outside diff range comments (2)
.github/workflows/post_to_mastodon.yml (2)

Line range hint 4-8: Fix workflow trigger configuration

The current trigger configuration has several issues:

  1. The types field is not valid for push events
  2. The workflow might not work as expected since github.event.pull_request context may not be available in push events

Consider using one of these approaches:

  1. For release-based posts (recommended based on PR objectives):
on:
  release:
    types: [published]
  1. For PR merge-based posts:
on:
  pull_request:
    types: [closed]
    branches:
      - main
🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)


Line range hint 14-14: Update job condition to match the trigger event

The condition github.event.pull_request.merged == true won't work with push events as the pull_request context isn't available.

If you want to post on releases (as per PR objectives), remove this condition as it's not needed. The workflow will only run when a release is published.

If you want to keep PR merge posts, switch back to pull_request event and keep this condition.

🧰 Tools
🪛 actionlint (1.7.4)

4-4: "types" cannot be specified for "push" Webhook event

(events)

🧹 Nitpick comments (1)
.github/workflows/post_to_mastodon.yml (1)

Line range hint 1-27: Align workflow with PR objectives

The PR aims to change the bot to post only on releases, but the current implementation mixes push events with PR contexts, which won't work reliably.

Here's a complete workflow aligned with the PR objectives:

name: Post to Mastodon on Release

on:
  release:
    types: [published]

permissions:
  pull-requests: read

jobs:
  post_to_mastodon:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Post to Mastodon
        uses: nick-fields/retry@v2
        with:
          timeout_minutes: 2
          max_attempts: 3
          command: |
            export MASTODONBOT="${{ secrets.MASTODONBOT }}"
            export PR_TITLE="${{ github.event.release.tag_name }}"
            $GITHUB_WORKSPACE/post_to_mastodon.sh
🧰 Tools
🪛 actionlint (1.7.4)

24-24: got unexpected character '#' while lexing expression, expecting 'a'..'z', 'A'..'Z', '_', '0'..'9', ''', '}', '(', ')', '[', ']', '.', '!', '<', '>', '=', '&', '|', '*', ',', ' '

(expression)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 0321286 and 68e3d95.

📒 Files selected for processing (1)
  • .github/workflows/post_to_mastodon.yml (2 hunks)
🧰 Additional context used
📓 Learnings (1)
.github/workflows/post_to_mastodon.yml (1)
Learnt from: cmeesters
PR: snakemake/snakemake-executor-plugin-slurm#187
File: .github/workflows/post_to_mastodon.yml:0-0
Timestamp: 2025-01-17T17:27:32.446Z
Learning: In the mastodon publishing workflow for snakemake-executor-plugin-slurm, the PR_TITLE environment variable is required by the post_to_mastodon.sh script and should be preserved.
🪛 actionlint (1.7.4)
.github/workflows/post_to_mastodon.yml

4-4: "types" cannot be specified for "push" Webhook event

(events)


24-24: got unexpected character '#' while lexing expression, expecting 'a'..'z', 'A'..'Z', '_', '0'..'9', ''', '}', '(', ')', '[', ']', '.', '!', '<', '>', '=', '&', '|', '*', ',', ' '

(expression)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: testing

export MASTODONBOT="${{ secrets.MASTODONBOT }}"
export PR_TITLE="${{ github.event.pull_request.title }}"
./post_to_mastodon.sh
export PR_TITLE="${{ github.event.release.tag_name#v }}"
Copy link
Contributor

@coderabbitai coderabbitai bot Jan 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue

Fix the release tag name expression

The current syntax #v for removing the 'v' prefix is incorrect. GitHub Actions expressions don't support this string manipulation.

Use this approach instead:

export PR_TITLE="${{ github.event.release.tag_name }}"
# Then in the script, use shell parameter expansion to remove 'v' prefix
PR_TITLE=${PR_TITLE#v}

Or move the prefix removal to the script to keep the workflow simpler:

export PR_TITLE="${{ github.event.release.tag_name }}"

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks. done. hopefully.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cmeesters The changes look good! The workflow file now correctly handles the release tag name.

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Check the current content of the workflow file
cat .github/workflows/post_to_mastodon.yml

Length of output: 662


If you found this review helpful, would you consider giving us a shout-out on X?
Thank you for using CodeRabbit!

@cmeesters cmeesters merged commit 9c2fd03 into main Jan 17, 2025
5 checks passed
@cmeesters cmeesters deleted the fix/Mastodonbot branch January 17, 2025 18:43
cmeesters pushed a commit that referenced this pull request Jan 17, 2025
🤖 I have created a release *beep* *boop*
---


##
[0.14.1](v0.14.0...v0.14.1)
(2025-01-17)


### Bug Fixes

* mastodonbot
([#187](#187))
([9c2fd03](9c2fd03))

---
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
Copy link
Member Author

@coderabbitai I am a little disappointed: The aim was that this action runs upon a branch's merger to the main branch. However, it did not run at all. Any ideas why? Perhaps suggestions?

Copy link
Contributor

coderabbitai bot commented Jan 18, 2025

Tip

For best results, initiate chat on the files or code changes.

@cmeesters I found several issues in the workflow configuration that explain why it's not running:

  1. The types: [closed] is incorrectly placed under the push event (it's only valid for pull_request events)
  2. The condition github.event.pull_request.merged won't work with push events as the PR context isn't available
  3. The workflow tries to use github.event.release.tag_name but isn't triggered on release events

Here's the corrected workflow configuration:

name: Post to Mastodon on PR Merge

on:
  pull_request:
    types:
      - closed
    branches:
      - main

permissions:
  pull-requests: read

jobs:
  post_to_mastodon:
    if: github.event.pull_request.merged == true
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - name: Post to Mastodon
        uses: nick-fields/retry@v2
        with:
          timeout_minutes: 2
          max_attempts: 3
          command: |
            export MASTODONBOT="${{ secrets.MASTODONBOT }}"
            export PR_TITLE="${{ github.event.pull_request.title }}"
            $GITHUB_WORKSPACE/post_to_mastodon.sh

The main changes:

  1. Changed trigger to pull_request event with types: [closed]
  2. Kept the merge check as it works with pull_request events
  3. Used github.event.pull_request.title instead of release tag name

This should now run whenever a PR is merged to the main branch. Would you like me to explain any part in more detail?

🔗 Analysis chain
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Fetch the workflow file
cat .github/workflows/post_to_mastodon.yml

Length of output: 662

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