Skip to content

fix(flare_git): validate action before repo/client setup; resolve default branch via API - #363

Merged
getappz merged 2 commits into
masterfrom
task/181
Jul 28, 2026
Merged

fix(flare_git): validate action before repo/client setup; resolve default branch via API#363
getappz merged 2 commits into
masterfrom
task/181

Conversation

@getappz

@getappz getappz commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Summary

  • Validate action against a known list before resolving the repo/creating the GitHub client, so an unknown action fails on its own merits instead of surfacing as a misleading "no repo"/auth error (flare_git.rs:22).
  • Add github::repos::get_default_branch (GET /repos/{owner}/{repo}) and use it in workflow_dispatch when git_ref is omitted with an explicit repo override, resolving that repo's actual default branch via the GitHub API instead of requiring git_ref (flare_git.rs:242).

Fixes item #181 (CodeRabbit findings from PR #253's review; pre-existing code moved verbatim in that split, not introduced by it).

Test plan

  • cargo build --workspace --all-features
  • cargo clippy --workspace --all-targets --all-features -- -D warnings -A unsafe_code -A clippy::pedantic
  • cargo test --workspace --verbose (51 suites, all green)
  • cargo fmt --check

Summary by CodeRabbit

  • New Features

    • Automatically determines the repository’s default branch for workflow dispatch when no branch is specified.
    • Supports default-branch resolution for workflow dispatch when a repository is explicitly provided.
  • Bug Fixes

    • Rejects unknown actions immediately with a clear invalid-parameters error.
    • Workflow dispatch requests with repository overrides no longer fail when the branch is omitted.
  • Tests

    • Expanded unit test coverage for action validation and default-branch selection behavior.

@coderabbitai

coderabbitai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 1a31295b-ca07-45c4-b1d2-2f32997db3c4

📥 Commits

Reviewing files that changed from the base of the PR and between 0e6e4bf and 1016b9f.

📒 Files selected for processing (1)
  • src/mcp_server/flare_git.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/mcp_server/flare_git.rs

📝 Walkthrough

Walkthrough

Adds a GitHub repository helper to retrieve default branches, exports it, validates flare_git actions early, and resolves omitted workflow_dispatch refs from a repository’s remote default branch or local branch.

Changes

Flare GitHub workflow handling

Layer / File(s) Summary
GitHub default-branch lookup
src/github/mod.rs, src/github/repos.rs
Exports the repositories module, adds get_default_branch, and tests successful extraction, missing-field errors, and request paths.
Action validation and workflow branch inference
src/mcp_server/flare_git.rs
Rejects unknown actions before repository or client setup and resolves omitted workflow_dispatch refs from an explicit ref, provided repository, or local repository state. Tests cover each resolution path and early rejection.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant flare_git_impl
  participant repos_get_default_branch
  participant GitHub_Client
  flare_git_impl->>flare_git_impl: validate req.action
  flare_git_impl->>repos_get_default_branch: resolve repository default branch
  repos_get_default_branch->>GitHub_Client: GET repository
  GitHub_Client-->>repos_get_default_branch: default_branch
  repos_get_default_branch-->>flare_git_impl: branch name
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately captures the two main changes: early action validation and GitHub API default-branch resolution.
Description check ✅ Passed The description follows the template well with Summary and Test plan, but the Notes for reviewers section is not filled out.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch task/181

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🧹 Nitpick comments (2)
src/mcp_server/flare_git.rs (2)

289-296: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add regression coverage for default-branch inference.

The new explicit-repo path is not exercised by the added tests. Verify that an omitted git_ref requests the repository’s default_branch, and that the no-override path still uses local branch resolution.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp_server/flare_git.rs` around lines 289 - 296, Extend the regression
tests for the request handling around the `None => match &req.repo` logic to
cover both default-branch paths: when `repo` is explicitly provided and
`git_ref` is omitted, assert that the repository’s `default_branch` is
requested; when no repository override is provided, assert that local
`resolve_default_branch` behavior remains in use.

9-35: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Avoid maintaining the action list in multiple places.

The allowlist duplicates the action names encoded by the dispatch match and request schema. A future handler added to only one location will either be rejected early or fall through later. Parse the action once into a shared enum/validated type, or centralize the supported-action definition.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/mcp_server/flare_git.rs` around lines 9 - 35, Remove the duplicated
KNOWN_ACTIONS allowlist and centralize action validation with the existing
dispatch match and request schema. Parse req.action once into a shared enum or
validated action type, then use that result for dispatch so newly supported
handlers cannot diverge between validation and execution.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/mcp_server/flare_git.rs`:
- Around line 289-296: Extend the regression tests for the request handling
around the `None => match &req.repo` logic to cover both default-branch paths:
when `repo` is explicitly provided and `git_ref` is omitted, assert that the
repository’s `default_branch` is requested; when no repository override is
provided, assert that local `resolve_default_branch` behavior remains in use.
- Around line 9-35: Remove the duplicated KNOWN_ACTIONS allowlist and centralize
action validation with the existing dispatch match and request schema. Parse
req.action once into a shared enum or validated action type, then use that
result for dispatch so newly supported handlers cannot diverge between
validation and execution.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: 3900c0ea-8a36-4993-b101-88c405651c37

📥 Commits

Reviewing files that changed from the base of the PR and between f7eb1c4 and 0e6e4bf.

📒 Files selected for processing (3)
  • src/github/mod.rs
  • src/github/repos.rs
  • src/mcp_server/flare_git.rs

@getappz

getappz commented Jul 28, 2026

Copy link
Copy Markdown
Owner Author

Addressed the default-branch regression-coverage nitpick: extracted resolve_workflow_git_ref and added 3 unit tests covering explicit ref, repo-override (API), and no-override (local) paths.

Skipping the KNOWN_ACTIONS-dedup suggestion (centralize into a shared enum/validated type) — real long-term improvement, but a heavier refactor than this bug fix warrants; left a sync-reminder comment on the const instead. Can file a follow-up if desired.

@getappz
getappz merged commit 615674f into master Jul 28, 2026
16 checks passed
@getappz
getappz deleted the task/181 branch July 28, 2026 20:23
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