Skip to content
This repository was archived by the owner on Mar 17, 2026. It is now read-only.

fix(cli): add platform readme link to build output#119

Merged
jyecusch merged 3 commits intonitrictech:mainfrom
davemooreuws:NIT-298
Oct 14, 2025
Merged

fix(cli): add platform readme link to build output#119
jyecusch merged 3 commits intonitrictech:mainfrom
davemooreuws:NIT-298

Conversation

@davemooreuws
Copy link
Copy Markdown
Member

Also adds a platform target function

Also adds a platform target function
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Oct 14, 2025

📝 Walkthrough

Walkthrough

Added an exported PlatformTarget type and ParsePlatformTarget(target string) in cli/internal/platforms/repository.go to parse targets of the form /@ (revision -> int). GetPlatform now uses ParsePlatformTarget (team, platform, revision) and updated format validation/error messages. In cli/pkg/app/suga.go added SugaApp.getPlatformReadmeURL(target, currentTeam string) which uses ParsePlatformTarget to build a public or private platform README path; Build now computes platformURL after Terraform generation and conditionally inserts a platform-setup step when platformURL is present. No other public APIs changed.

Possibly related PRs

Suggested reviewers

  • jyecusch
  • HomelessDinosaur
  • davemooreuws

Pre-merge checks

✅ Passed checks (3 passed)
Check name Status Explanation
Title Check ✅ Passed Title succinctly describes the primary change of adding a platform README link to the build output in the CLI, matching the implementation in this PR and providing clear context for reviewers.
Description Check ✅ Passed The description briefly notes the addition of the platform target function which aligns with the changes in this PR, so it is on-topic and relevant to the implementation.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ebd8cf2 and c8e5ae3.

📒 Files selected for processing (1)
  • cli/pkg/app/suga.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (1)
cli/pkg/app/suga.go (2)
cli/internal/platforms/repository.go (1)
  • ParsePlatformTarget (30-54)
cli/internal/api/teams.go (1)
  • Team (8-16)
🔇 Additional comments (3)
cli/pkg/app/suga.go (3)

22-22: LGTM!

Import is necessary for the new getPlatformReadmeURL method.


442-459: LGTM!

The method correctly:

  • Parses the platform target with proper error handling
  • Distinguishes between private (same team) and public (different team) platforms
  • Constructs appropriate URL paths for each case

487-508: Correctly fixes the step numbering issue!

The dynamic step building with a slice properly addresses the previous review's concern about numbering gaps. Steps now increment consecutively regardless of whether platformURL is present.


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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
cli/internal/platforms/repository.go (2)

66-91: Don’t treat public 404 as definitive; try authenticated fetch

If the platform isn’t public (public 404), it may still be accessible to the user via authenticated API. Currently it returns PlatformNotFound without attempting private fetch. This causes false negatives for cross‑team private platforms.

Apply this diff:

 	// Smart ordering: try public first if the platform team doesn't match current user's team
 	if team != r.currentTeam {
 		// Try public access first
 		publicPlatformSpec, publicErr := r.apiClient.GetPublicPlatform(team, platform, revision)
 		if publicErr == nil {
 			return publicPlatformSpec, nil
 		}
-
-		// If public fails with 404, it's definitely not found
-		if errors.Is(publicErr, api.ErrNotFound) {
-			return nil, terraform.ErrPlatformNotFound
-		}
-
-		// If public fails for other reasons, try authenticated access
+		// If public fails (including 404), try authenticated access (resource may be private)
 		platformSpec, err := r.apiClient.GetPlatform(team, platform, revision)
 		if err != nil {
 			if errors.Is(err, api.ErrNotFound) {
 				return nil, terraform.ErrPlatformNotFound
 			}
 			if errors.Is(err, api.ErrUnauthenticated) {
 				return nil, terraform.ErrUnauthenticated
 			}
 			return nil, err
 		}
 		return platformSpec, nil
 	}

93-120: Fix error mapping on fallback and remove unreachable duplicate check

When team matches current team:

  • If the initial GetPlatform error is NotFound, and public fetch fails with a non‑404, returning ErrUnauthenticated is incorrect. Return the public error (or preserve NotFound mapping).
  • The subsequent 404 check is unreachable for NotFound due to the earlier branch.

Refactor as below to map errors correctly and avoid duplication.

 	// Try authenticated access first
 	platformSpec, err := r.apiClient.GetPlatform(team, platform, revision)
 	if err != nil {
-		// If authentication failed, try public platform access
-		if errors.Is(err, api.ErrUnauthenticated) || errors.Is(err, api.ErrNotFound) {
-			publicPlatformSpec, publicErr := r.apiClient.GetPublicPlatform(team, platform, revision)
-			if publicErr != nil {
-				// If public access also fails with 404, return platform not found
-				if errors.Is(publicErr, api.ErrNotFound) {
-					return nil, terraform.ErrPlatformNotFound
-				}
-				// Return the original authentication error for other public access failures
-				return nil, terraform.ErrUnauthenticated
-			}
-			return publicPlatformSpec, nil
-		}
-
-		// If its a 404, then return platform not found error
-		if errors.Is(err, api.ErrNotFound) {
-			return nil, terraform.ErrPlatformNotFound
-		}
-
-		// return the original error to the engine
-		return nil, err
+		switch {
+		case errors.Is(err, api.ErrUnauthenticated):
+			// Fallback to public if auth failed
+			publicSpec, publicErr := r.apiClient.GetPublicPlatform(team, platform, revision)
+			if publicErr == nil {
+				return publicSpec, nil
+			}
+			// If not public or other failure, keep unauthenticated semantics
+			if errors.Is(publicErr, api.ErrNotFound) {
+				return nil, terraform.ErrUnauthenticated
+			}
+			return nil, terraform.ErrUnauthenticated
+		case errors.Is(err, api.ErrNotFound):
+			// Try public in case it exists publicly
+			publicSpec, publicErr := r.apiClient.GetPublicPlatform(team, platform, revision)
+			if publicErr == nil {
+				return publicSpec, nil
+			}
+			if errors.Is(publicErr, api.ErrNotFound) {
+				return nil, terraform.ErrPlatformNotFound
+			}
+			// Preserve the public error context for non-404 failures
+			return nil, publicErr
+		default:
+			// return the original error to the engine
+			return nil, err
+		}
 	}
 
 	return platformSpec, nil
🧹 Nitpick comments (2)
cli/pkg/app/suga.go (1)

442-460: Doc/behavior mismatch and URL completeness

The comment says “README page,” but the URL omits a readme path or revision. If the README is revision‑specific or lives under a subpath (e.g., /readme), this may link to a generic platform page. Verify the intended path and whether revision should be included.

cli/internal/platforms/repository.go (1)

28-55: Clarify doc and minor parsing nits

  • Comment says “Returns nil if the format is invalid” but the function returns an error; clarify to “returns an error.”
  • Optional: precompile the regex as a package var to avoid recompilation on each call.

Apply this minimal doc tweak:

-// ParsePlatformTarget parses a platform target string in the format <team>/<platform>@<revision>
-// Returns nil if the format is invalid
+// ParsePlatformTarget parses a platform target string in the format <team>/<platform>@<revision>.
+// Returns a non-nil error if the format is invalid.
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 9eeea52 and c4ff328.

📒 Files selected for processing (2)
  • cli/internal/platforms/repository.go (2 hunks)
  • cli/pkg/app/suga.go (3 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
cli/pkg/app/suga.go (2)
cli/internal/platforms/repository.go (1)
  • ParsePlatformTarget (30-54)
cli/internal/api/teams.go (1)
  • Team (8-16)
cli/internal/platforms/repository.go (3)
cli/internal/api/models.go (1)
  • Platform (70-79)
cli/internal/version/version.go (1)
  • CommandName (13-13)
engines/terraform/platform.go (1)
  • PlatformSpec (41-54)
🔇 Additional comments (2)
cli/pkg/app/suga.go (1)

22-22: Import looks good

New dependency is used by getPlatformReadmeURL.

cli/internal/platforms/repository.go (1)

21-27: Struct addition LGTM

PlatformTarget fields and export scope look appropriate.

Comment thread cli/pkg/app/suga.go
@davemooreuws davemooreuws requested a review from jyecusch October 14, 2025 22:09
Comment thread cli/pkg/app/suga.go Outdated
@jyecusch jyecusch merged commit 391e891 into nitrictech:main Oct 14, 2025
2 checks passed
@nitric-bot
Copy link
Copy Markdown

🎉 This PR is included in version 0.1.27 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants