Skip to content

feat(campaign): ensure branch names are prefixed with 'turbolift-' correctly #177

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 2 commits into
base: main
Choose a base branch
from

Conversation

sledigabel
Copy link
Collaborator

  • Updated logic in campaign.go to apply the 'turbolift-' prefix without duplication.
  • Added TestBranchNamePrefixLogic in campaign_test.go to verify prefix logic.
  • Restored original tests and copyright header in campaign_test.go.

…rectly

- Updated logic in `campaign.go` to apply the 'turbolift-' prefix without duplication.
- Added `TestBranchNamePrefixLogic` in `campaign_test.go` to verify prefix logic.
- Restored original tests and copyright header in `campaign_test.go`.
@sledigabel sledigabel changed the title fix(campaign): ensure branch names are prefixed with 'turbolift-' correctly feat(campaign): ensure branch names are prefixed with 'turbolift-' correctly Jul 22, 2025
@sledigabel sledigabel marked this pull request as ready for review July 22, 2025 14:53
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR updates the campaign branch naming logic to ensure all branch names are consistently prefixed with 'turbolift-' without creating duplicates when the prefix already exists.

  • Modified the campaign name assignment logic to apply the 'turbolift-' prefix intelligently
  • Added comprehensive test coverage for the branch name prefix logic with edge cases
  • Minor formatting improvements to import ordering in the test file

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
internal/campaign/campaign.go Updated Name field assignment to use prefix logic that prevents duplication
internal/campaign/campaign_test.go Added test function and helper to verify prefix behavior with various inputs
Comments suppressed due to low confidence (1)

internal/campaign/campaign_test.go:273

  • The test uses a local helper function ApplyBranchNamePrefix that duplicates the logic from campaign.go instead of testing the actual production code. This creates a risk where the test passes but the actual implementation differs. Consider testing the actual OpenCampaign function or extracting the prefix logic to a shared function that both production and test code can use.
// ApplyBranchNamePrefix is a helper function to simulate the branch name prefix logic.

@@ -70,7 +70,7 @@ func OpenCampaign(options *CampaignOptions) (*Campaign, error) {
}

return &Campaign{
Name: dirBasename,
Name: "turbolift-" + strings.TrimPrefix(dirBasename, "turbolift-"),
Copy link
Preview

Copilot AI Jul 22, 2025

Choose a reason for hiding this comment

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

[nitpick] The prefix logic is implemented inline using string concatenation and TrimPrefix. This approach works but could be more readable and maintainable if extracted to a dedicated function, especially since there's already a test helper function with similar logic.

Suggested change
Name: "turbolift-" + strings.TrimPrefix(dirBasename, "turbolift-"),
Name: sanitizeCampaignName(dirBasename),

Copilot uses AI. Check for mistakes.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

great idea.

…rectly

- Updated logic in `campaign.go` to apply the 'turbolift-' prefix without duplication.
- Added `TestBranchNamePrefixLogic` in `campaign_test.go` to verify prefix logic.
- Restored original tests and copyright header in `campaign_test.go`.
if name == "" {
return prefix
}
if len(name) >= len(prefix) && name[:len(prefix)] == prefix {
Copy link
Collaborator

Choose a reason for hiding this comment

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

This feels a bit clever - why not use strings.HasPrefix?

@@ -55,6 +54,17 @@ func NewCampaignOptions() *CampaignOptions {
}
}

func ApplyCampaignNamePrefix(name string) string {
const prefix = "turbolift-"
if name == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

If name is empty we're probably in a situation we should not allow ourselves to be in...

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.

2 participants