Skip to content

chore(os): add a task to create PRs for OS sync #29

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

gberenice
Copy link
Member

@gberenice gberenice commented Jun 24, 2025

what

why

  • Speeds up bulk sync.

references

  • N/A

Summary by CodeRabbit

  • New Features

    • Introduced automated creation of GitHub pull requests from the sync branch to main for selected modules.
    • Added a composite workflow to streamline syncing, pushing, and PR creation for specified modules.
  • Improvements

    • Enhanced branch synchronization logic to better handle existing branches and ensure local and remote branches stay aligned.
    • Updated push operations to ensure changes are committed and pushed from the correct branch.
  • Chores

    • Updated configuration to include a new package dependency.
    • Removed an unused module from the default modules list.

@gberenice gberenice requested a review from a team as a code owner June 24, 2025 17:13
@gberenice gberenice requested a review from Gowiem June 24, 2025 17:13
Copy link

coderabbitai bot commented Jun 24, 2025

Walkthrough

This change updates the aqua.yaml configuration by adding the cli/cli package at version v2.74.2 with the [gh] tag. In lib/os-modules/Taskfile.yaml, the terraform-github-organization module is removed from the default modules list. The pull-and-branch task is modified to check out and reset the sync branch if it exists and is divergent. The push task now explicitly checks out the sync branch before pushing. Two new tasks, pr and sync-and-pr, are introduced to automate pull request creation and orchestrate the full sync, push, and PR workflow, respectively.

Possibly related PRs

✨ Finishing Touches
🧪 Generate Unit Tests
  • Create PR with Unit Tests
  • Post Copyable Unit Tests in Comment
  • Commit Unit Tests in branch chore/os-pr-task

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ 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.
    • Explain this complex logic.
    • 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 explain this code block.
    • @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 explain its main purpose.
    • @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.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

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.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @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

@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: 3

🧹 Nitpick comments (3)
aqua.yaml (1)

10-11: GitHub CLI addition looks good – consider pinning by digest for stronger supply-chain guarantees

The new entry cleanly installs cli/[email protected] and tags it for selective installs.
If you want fully reproducible builds, Aqua also supports pinning by image digest (name: cli/[email protected]#<sha>). This prevents unexpected hash changes even if the upstream retags the same version.

Nothing blocking, just a heads-up.

lib/os-modules/Taskfile.yaml (2)

141-147: Skip empty commits to avoid noisy errors

git commit -m … exits with status 1 when there’s nothing to commit, which can bubble up if a future set -e is introduced. Consider guarding the commit:

- git add .
- git commit -m "chore: update with the latest template state"
+ git add .
+ if ! git diff --cached --quiet; then
+   git commit -m "chore: update with the latest template state"
+ else
+   echo "ℹ️  No changes detected — skipping commit"
+ fi

Keeps the log clean and future-proofs the task.


260-262: Nice orchestration task – consider set -euo pipefail wrapper

sync-and-pr stitches the whole flow together neatly.
Adding strict bash flags at the top of each inline script (set -euo pipefail) would stop the chain on the first failure, saving time and avoiding inconsistent states.

Not critical for merging but worth a follow-up.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 7a7bca4 and 20c3ad0.

📒 Files selected for processing (2)
  • aqua.yaml (1 hunks)
  • lib/os-modules/Taskfile.yaml (4 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`**/*.yaml`: You are well-versed in writing and reviewing YAML configurations for the Task tool (https://taskfile.dev/). Provide recommendations for clarity, maintainability, and a...

**/*.yaml: You are well-versed in writing and reviewing YAML configurations for the Task tool (https://taskfile.dev/).
Provide recommendations for clarity, maintainability, and adherence to Taskfile best practices, including usage of variables, environment blocks, and includes.
These configurations may also contain embedded Bash scripts or commands.
Demonstrate bash scripting best practices such as error handling, secure variable expansions, and clear documentation.

  • aqua.yaml
  • lib/os-modules/Taskfile.yaml

Comment on lines +190 to +205
commits_ahead=$(git rev-list --count main..{{.SYNC_BRANCH}})
if [ "$commits_ahead" -eq 0 ]; then
echo "⏭️ No commits ahead of main, skipping PR creation for $module"
cd -
continue
fi

echo "📋 Creating pull request..."
gh pr create \
--title "{{.PR_TITLE}}" \
--body "{{.PR_BODY}}" \
--base main \
--head {{.SYNC_BRANCH}} \
--repo "masterpointio/$module"

cd -
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Handle existing PRs to make the task idempotent

gh pr create exits non-zero if a PR from the same head already exists, causing the loop to abort. A quick resilience upgrade:

- gh pr create \
+# If PR exists, this will no-op; otherwise it creates one.
+gh pr view {{.SYNC_BRANCH}} --head {{.SYNC_BRANCH}} >/dev/null 2>&1 || \
+gh pr create \
   --title "{{.PR_TITLE}}" \
   --body "{{.PR_BODY}}" \
   --base main \
   --head {{.SYNC_BRANCH}} \
   --repo "masterpointio/$module"

Keeps the workflow repeatable without manual cleanup.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
commits_ahead=$(git rev-list --count main..{{.SYNC_BRANCH}})
if [ "$commits_ahead" -eq 0 ]; then
echo "⏭️ No commits ahead of main, skipping PR creation for $module"
cd -
continue
fi
echo "📋 Creating pull request..."
gh pr create \
--title "{{.PR_TITLE}}" \
--body "{{.PR_BODY}}" \
--base main \
--head {{.SYNC_BRANCH}} \
--repo "masterpointio/$module"
cd -
echo "📋 Creating pull request..."
# If a PR for this branch already exists, no-op; otherwise create one.
gh pr view {{.SYNC_BRANCH}} --head {{.SYNC_BRANCH}} >/dev/null 2>&1 || \
gh pr create \
--title "{{.PR_TITLE}}" \
--body "{{.PR_BODY}}" \
--base main \
--head {{.SYNC_BRANCH}} \
--repo "masterpointio/$module"
cd -
🤖 Prompt for AI Agents
In lib/os-modules/Taskfile.yaml around lines 190 to 205, the script uses `gh pr
create` which fails if a PR from the same head branch already exists, causing
the loop to abort. Modify the script to first check if a PR from the current
head branch exists using `gh pr list` or handle the error from `gh pr create`
gracefully. If a PR exists, skip creation and continue the loop to make the task
idempotent and prevent aborting on duplicate PRs.

Comment on lines +183 to +189
current_branch=$(git branch --show-current)
if [ "$current_branch" != "{{.SYNC_BRANCH}}" ]; then
echo "⚠️ Warning: Not on {{.SYNC_BRANCH}} branch. Current branch: $current_branch"
echo "🔄 Checking out {{.SYNC_BRANCH}}..."
git checkout {{.SYNC_BRANCH}}
fi

Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Branch-safety check: bail out early instead of continuing on wrong branch

The current logic merely warns when the user happens to be on a different branch, then checks out {{.SYNC_BRANCH}}. If the checkout fails (e.g., branch missing), the script still proceeds and gh pr create will mis-behave. Prefer failing fast:

- git checkout {{.SYNC_BRANCH}}
+ if ! git checkout {{.SYNC_BRANCH}}; then
+   echo "❌ Failed to switch to {{.SYNC_BRANCH}} – skipping PR for $module"
+   cd -; continue
+ fi

Improves robustness across all repos.

📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
current_branch=$(git branch --show-current)
if [ "$current_branch" != "{{.SYNC_BRANCH}}" ]; then
echo "⚠️ Warning: Not on {{.SYNC_BRANCH}} branch. Current branch: $current_branch"
echo "🔄 Checking out {{.SYNC_BRANCH}}..."
git checkout {{.SYNC_BRANCH}}
fi
current_branch=$(git branch --show-current)
if [ "$current_branch" != "{{.SYNC_BRANCH}}" ]; then
echo "⚠️ Warning: Not on {{.SYNC_BRANCH}} branch. Current branch: $current_branch"
echo "🔄 Checking out {{.SYNC_BRANCH}}..."
if ! git checkout {{.SYNC_BRANCH}}; then
echo "❌ Failed to switch to {{.SYNC_BRANCH}} – skipping PR for $module"
cd -; continue
fi
fi
🤖 Prompt for AI Agents
In lib/os-modules/Taskfile.yaml around lines 183 to 189, the script checks out
the sync branch if the current branch differs but does not handle checkout
failures. Modify the script to immediately exit with an error if the checkout
command fails, preventing further execution on the wrong branch. This can be
done by adding a check after the git checkout command and using an exit
statement to fail fast if the checkout is unsuccessful.

Comment on lines 95 to +104
if git branch --list "{{.SYNC_BRANCH}}" | grep -q "{{.SYNC_BRANCH}}" && [ "{{.DELETE_EXISTING_SYNC_BRANCH}}" = "false" ]; then
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, skipping creation."
echo "⏭️ Branch {{.SYNC_BRANCH}} already exists, checking it out."
git checkout {{.SYNC_BRANCH}}

# Check if local and remote branches have diverged
if git status --porcelain -b | grep -q "ahead\|behind\|diverged"; then
echo "⚠️ Local and remote branches have diverged. Resetting to remote branch..."
git fetch origin {{.SYNC_BRANCH}}
git reset --hard origin/{{.SYNC_BRANCH}}
fi
Copy link

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

Divergence check risks clobbering local commits

git status --porcelain -b flags any “ahead/behind” state and then hard-resets to the remote, which will silently drop local commits if the branch is only ahead of origin.

A safer pattern is to reset only when the branch is behind or has actually diverged:

- if git status --porcelain -b | grep -q "ahead\|behind\|diverged"; then
-   echo "⚠️  Local and remote branches have diverged. Resetting to remote branch..."
-   git fetch origin {{.SYNC_BRANCH}}
-   git reset --hard origin/{{.SYNC_BRANCH}}
+ # Count commits left (behind) and right (ahead) of remote
+ if [ "$(git rev-list --left-right --count {{.SYNC_BRANCH}}...origin/{{.SYNC_BRANCH}} | awk '{print $1}')" -gt 0 ]; then
+   echo "🔄 Local branch is behind remote. Resetting hard to remote state…"
+   git fetch origin {{.SYNC_BRANCH}}
+   git reset --hard origin/{{.SYNC_BRANCH}}
+ fi

This preserves un-pushed work while still self-healing in the “behind” scenario.

Committable suggestion skipped: line range outside the PR's diff.

🤖 Prompt for AI Agents
In lib/os-modules/Taskfile.yaml around lines 95 to 104, the current divergence
check resets the branch hard whenever it is ahead, behind, or diverged, which
risks losing local commits. Modify the condition to reset only if the branch is
behind or diverged, excluding the ahead-only case. Adjust the git status check
to detect only "behind" or "diverged" states before performing the hard reset to
preserve un-pushed local commits.

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