Skip to content

Support more tags scenarios#925

Merged
lucacome merged 3 commits intomainfrom
feat/tags
Apr 23, 2026
Merged

Support more tags scenarios#925
lucacome merged 3 commits intomainfrom
feat/tags

Conversation

@lucacome
Copy link
Copy Markdown
Owner

@lucacome lucacome commented Apr 23, 2026

Summary by CodeRabbit

  • Bug Fixes

    • Release publishing now correctly distinguishes tag vs branch runs, preferring appropriate drafts or published releases and using the correct commit for release targeting.
  • Tests

    • Expanded test coverage for many release scenarios, including tag vs branch edge cases, draft vs published precedence, and creation/update behaviors to prevent regressions.

@github-actions github-actions Bot added enhancement New feature or request tests labels Apr 23, 2026
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

Warning

Rate limit exceeded

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

Your organization is not enrolled in usage-based pricing. Contact your admin to enable usage-based pricing to continue reviews beyond the rate limit, or try again in 45 minutes and 15 seconds.

⌛ 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.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1422215d-f528-4492-a040-9e628ac6fcef

📥 Commits

Reviewing files that changed from the base of the PR and between 7d44f54 and 0e0727b.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (2)
  • __tests__/release.test.ts
  • src/release.ts

Walkthrough

Adds an explicit releaseData.isTag flag, uses context.sha in fixtures, and refactors release upsert logic to treat tag-triggered and branch-triggered runs differently when selecting/updating/creating releases; tests expanded to cover new selection and precedence behaviors.

Changes

Cohort / File(s) Summary
Test Fixture
__fixtures__/github.ts
Added sha: 'abc123' to the mocked GitHub context.
Tests
__tests__/release.test.ts
Updated tests to include releaseData.isTag; added cases for tag vs branch runs (including branch named "tag"), precedence between drafts and published releases, update/create behaviors, and expectations using target_commitish: 'abc123' for tag runs.
Release Logic
src/release.ts
Added isTag to ReleaseData; refactored selection to use releaseToUpdate: tag runs prefer same-tag draft → same-tag published → create; branch runs match drafts by tag_name+target_commitish or any draft for branch; target_commitish and draft calculation adjusted; update path now uses releaseToUpdate.id.

Sequence Diagram(s)

sequenceDiagram
    participant Runner as GitHub Actions Runner
    participant ReleaseSvc as release.ts
    participant GitHubAPI as GitHub API
    participant Context as Action Context

    Runner->>Context: provide event refs and context.sha
    Runner->>ReleaseSvc: call createOrUpdateRelease(releaseData with isTag)
    ReleaseSvc->>GitHubAPI: list releases (filter by tag/branch)
    GitHubAPI-->>ReleaseSvc: return releases list
    alt isTag true
        ReleaseSvc->>ReleaseSvc: prefer same-tag draft, else same-tag published
    else isTag false
        ReleaseSvc->>ReleaseSvc: match drafts by tag_name+target_commitish or branch drafts
    end
    alt update existing
        ReleaseSvc->>GitHubAPI: update release (id, target_commitish/from context.sha)
    else create new
        ReleaseSvc->>GitHubAPI: create release (target_commitish from context.sha or branch)
    end
    GitHubAPI-->>ReleaseSvc: release created/updated
    ReleaseSvc-->>Runner: return release result
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

Poem

🐇 I found a tag, or maybe not—

draft first, then published sought.
With context SHA I hop and cheer,
choose the release that’s best and clear. 🎉

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title 'Support more tags scenarios' is vague and does not specifically describe the main implementation changes in the changeset. Consider revising the title to be more specific about the changes, such as 'Distinguish tag vs branch runs with isTag flag in release logic' or 'Add isTag flag to differentiate tag-triggered and branch-triggered releases'.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/tags

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

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

Copy link
Copy Markdown
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

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@src/release.ts`:
- Line 79: The current isTagRun calculation (const isTagRun = releaseData.branch
=== 'tag') mistakenly treats a branch literally named "tag" as a tag-triggered
run; change the logic to derive tagness from the ref (e.g., check context.ref or
releaseData.ref for a "refs/tags/" prefix) or add an explicit boolean
(releaseData.isTag) and set that from the ref upstream, then replace uses of
isTagRun/releaseData.branch-based checks with the new ref-derived check or
releaseData.isTag so tag-run matching and context.sha targeting use actual tag
refs rather than the literal branch name.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 931d70ae-0944-4815-ab33-6cc5f02ca333

📥 Commits

Reviewing files that changed from the base of the PR and between 39ce3de and f35a678.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (3)
  • __fixtures__/github.ts
  • __tests__/release.test.ts
  • src/release.ts

Comment thread src/release.ts Outdated
@lucacome
Copy link
Copy Markdown
Owner Author

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 23, 2026

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
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.

🧹 Nitpick comments (2)
src/release.ts (1)

106-107: Optional: prefer ?? over || for the target_commitish fallback.

releaseToUpdate?.target_commitish || context.sha will also fall back to context.sha for an empty-string target_commitish. In practice the GitHub API won't return an empty string here, so this is a nit — but ?? more precisely expresses "only fall back when undefined/null", matching the intent and the releaseToUpdate?.draft === false check on the line above.

♻️ Proposed tweak
-  const targetCommitish = isTagRun ? releaseToUpdate?.target_commitish || context.sha : releaseData.branch
+  const targetCommitish = isTagRun ? (releaseToUpdate?.target_commitish ?? context.sha) : releaseData.branch
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/release.ts` around lines 106 - 107, The fallback for target_commitish
should use the nullish coalescing operator so only null/undefined trigger the
default; change the assignment of targetCommitish (currently using
releaseToUpdate?.target_commitish || context.sha) to use
releaseToUpdate?.target_commitish ?? context.sha so an empty-string value won't
be treated as missing while keeping intent aligned with the draft check
(releaseToUpdate?.draft === false).
__tests__/release.test.ts (1)

696-768: Nit: consider asserting target_commitish fallback source explicitly.

These two tests assert target_commitish: 'abc123', which comes from the __fixtures__/github.ts context.sha. That coupling is fine, but a short inline comment (similar to the one at line 537) noting "falls back to context.sha when no matching release exists" would make the intent obvious to future readers and prevent accidental breakage if the fixture SHA is ever changed.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@__tests__/release.test.ts` around lines 696 - 768, Add a short inline comment
in the two tests that assert target_commitish: 'abc123' explaining that the
value is the fixture context.sha fallback when no matching release exists;
update the assertions near the calls to createOrUpdateRelease (in the tests that
check mockCreate toHaveBeenCalledWith expect.objectContaining({ tag_name:
'v2.0.0', target_commitish: 'abc123', draft: true })) to include the comment
"falls back to context.sha when no matching release exists" and reference the
fixture __fixtures__/github.ts context.sha so future maintainers know why
'abc123' is expected.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@__tests__/release.test.ts`:
- Around line 696-768: Add a short inline comment in the two tests that assert
target_commitish: 'abc123' explaining that the value is the fixture context.sha
fallback when no matching release exists; update the assertions near the calls
to createOrUpdateRelease (in the tests that check mockCreate
toHaveBeenCalledWith expect.objectContaining({ tag_name: 'v2.0.0',
target_commitish: 'abc123', draft: true })) to include the comment "falls back
to context.sha when no matching release exists" and reference the fixture
__fixtures__/github.ts context.sha so future maintainers know why 'abc123' is
expected.

In `@src/release.ts`:
- Around line 106-107: The fallback for target_commitish should use the nullish
coalescing operator so only null/undefined trigger the default; change the
assignment of targetCommitish (currently using releaseToUpdate?.target_commitish
|| context.sha) to use releaseToUpdate?.target_commitish ?? context.sha so an
empty-string value won't be treated as missing while keeping intent aligned with
the draft check (releaseToUpdate?.draft === false).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 06725ef4-8206-4c38-aaaa-91d06508474e

📥 Commits

Reviewing files that changed from the base of the PR and between f35a678 and 7d44f54.

⛔ Files ignored due to path filters (2)
  • dist/index.js is excluded by !**/dist/**
  • dist/index.js.map is excluded by !**/dist/**, !**/*.map
📒 Files selected for processing (2)
  • __tests__/release.test.ts
  • src/release.ts

@lucacome lucacome enabled auto-merge (squash) April 23, 2026 05:34
@lucacome lucacome merged commit 277d615 into main Apr 23, 2026
15 checks passed
@lucacome lucacome deleted the feat/tags branch April 23, 2026 05:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant