Skip to content

test token change #1965

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

Merged
merged 3 commits into from
Jun 1, 2025
Merged

test token change #1965

merged 3 commits into from
Jun 1, 2025

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented May 31, 2025

Summary by CodeRabbit

  • Bug Fixes
    • Improved support for multiple version control systems by selecting the appropriate Git token based on the VCS type (GitHub or GitLab).

Copy link
Contributor

coderabbitai bot commented May 31, 2025

Walkthrough

The GetPolicyProvider method signatures in multiple components were updated to include a new vcsType parameter to distinguish version control system types. The AdvancedPolicyProvider now selects the Git token environment variable based on this vcsType ("github" or "gitlab"). Calls to GetPolicyProvider were updated accordingly to pass the vcsType argument. No other logic or error messages were changed.

Changes

File Change Summary
ee/cli/pkg/policy/providers.go Added vcsType parameter to GetPolicyProvider; token selection now depends on vcsType; error message references the correct token env var.
cli/pkg/spec/manual.go Updated call to GetPolicyProvider to pass spec.VCS.VcsType as an additional argument.
cli/pkg/spec/spec.go Updated call to GetPolicyProvider to pass spec.VCS.VcsType as an additional argument.
libs/spec/providers.go Added vcsType parameter to SpecPolicyProvider interface and BasicPolicyProvider implementation; parameter currently unused.

Poem

🐇 Tokens hop from place to place,
GitHub, GitLab—each a race.
A new parameter joins the game,
To fetch the token, not the same.
In code we leap, in env we trust,
For every repo, the right key must!
🔑🌿


📜 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 678f54f and 158e416.

📒 Files selected for processing (1)
  • ee/cli/pkg/policy/providers.go (2 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (1)
ee/cli/pkg/policy/providers.go (3)
libs/spec/models.go (1)
  • PolicySpec (39-41)
libs/policy/core.go (1)
  • Checker (14-19)
libs/spec/providers.go (1)
  • BasicPolicyProvider (321-321)
🪛 golangci-lint (1.64.8)
ee/cli/pkg/policy/providers.go

17-17: ineffectual assignment to token

(ineffassign)


18-18: ineffectual assignment to tokenName

(ineffassign)

⏰ Context from checks skipped due to timeout of 90000ms (3)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build
🔇 Additional comments (3)
ee/cli/pkg/policy/providers.go (3)

13-13: LGTM! Method signature correctly updated for VCS type support.

The addition of the vcsType parameter enables proper differentiation between GitHub and GitLab tokens, which aligns with the PR objectives.


42-42: LGTM! Correctly updated method call to match new signature.

The empty string parameter is appropriately added to match the updated BasicPolicyProvider.GetPolicyProvider signature.


17-29: ⚠️ Potential issue

Fix variable shadowing and improve code clarity.

The current implementation has variable shadowing issues where new local variables are declared instead of reassigning the existing parameter.

Apply this diff to fix the variable shadowing and improve readability:

-		var token = ""
-		var tokenName = ""
-		switch vcsType {
-		case "github":
-			token = os.Getenv("GITHUB_TOKEN")
-			tokenName = "GITHUB_TOKEN"
-		case "gitlab":
-			token = os.Getenv("GITLAB_TOKEN")
-			tokenName = "GITLAB_TOKEN"
-		default:
-			token = os.Getenv("GITHUB_TOKEN")
-			tokenName = "GITHUB_TOKEN"
-		}
+		var tokenName string
+		switch vcsType {
+		case "github":
+			token = os.Getenv("GITHUB_TOKEN")
+			tokenName = "GITHUB_TOKEN"
+		case "gitlab":
+			token = os.Getenv("GITLAB_TOKEN") 
+			tokenName = "GITLAB_TOKEN"
+		default:
+			token = os.Getenv("GITHUB_TOKEN")
+			tokenName = "GITHUB_TOKEN"
+		}

Likely an incorrect or invalid review comment.

🧰 Tools
🪛 golangci-lint (1.64.8)

17-17: ineffectual assignment to token

(ineffassign)


18-18: ineffectual assignment to tokenName

(ineffassign)

✨ Finishing Touches
  • 📝 Generate Docstrings

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

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

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
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

PR Summary

Identified inconsistencies in token handling within the policy provider implementation.

  • Error message in ee/cli/pkg/policy/providers.go incorrectly references 'GITHUB_TOKEN' when checking for 'GITLAB_TOKEN'
  • Inconsistent token usage between GetPolicyProvider and PolicyCheckerProviderAdvanced.Get methods
  • Missing structured logging with relevant context for error cases
  • Token validation logic needs to be unified across both methods for consistent behavior

1 file(s) reviewed, 2 comment(s)
Edit PR Review Bot Settings | Greptile

Comment on lines 17 to 20
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Error message references GITHUB_TOKEN but checks for GITLAB_TOKEN. Update error message to match the token being checked.

Suggested change
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
}
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get managent repo policy provider: GITLAB_TOKEN not specified")
}

@@ -14,7 +14,7 @@ func (p AdvancedPolicyProvider) GetPolicyProvider(policySpec lib_spec.PolicySpec
managementRepo := os.Getenv("DIGGER_MANAGEMENT_REPO")
if managementRepo != "" {
log.Printf("info: using management repo policy provider")
Copy link
Contributor

Choose a reason for hiding this comment

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

style: Log message should include management repo URL for better debugging context

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

🧹 Nitpick comments (1)
ee/cli/pkg/policy/providers.go (1)

38-40: Verify token consistency and fix typo.

There's an inconsistency between this method and AdvancedPolicyProvider.GetPolicyProvider - this method still uses GITHUB_TOKEN while the other was changed to GITLAB_TOKEN. Please verify if this inconsistency is intentional or if both methods should use the same token type.

Also, there's a typo in the error message: "managent" should be "management".

Apply this diff to fix the typo:

-		return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
+		return nil, fmt.Errorf("failed to get management repo policy provider: GITHUB_TOKEN not specified")

Please verify if this method should also be updated to use GITLAB_TOKEN for consistency.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between b2bd298 and 6a59a67.

📒 Files selected for processing (1)
  • ee/cli/pkg/policy/providers.go (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: build-and-push-image
  • GitHub Check: binary
  • GitHub Check: build-and-push-image
  • GitHub Check: build-and-push-image
  • GitHub Check: Build
  • GitHub Check: Build
  • GitHub Check: Build

Comment on lines 17 to 19
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix inconsistent error message after environment variable change.

The code now retrieves GITLAB_TOKEN but the error message still references GITHUB_TOKEN, which will confuse users during debugging. Additionally, there's a typo in "managent".

Apply this diff to fix the inconsistency and typo:

-		return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
+		return nil, fmt.Errorf("failed to get management repo policy provider: GITLAB_TOKEN not specified")
📝 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
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get managent repo policy provider: GITHUB_TOKEN not specified")
token := os.Getenv("GITLAB_TOKEN")
if token == "" {
return nil, fmt.Errorf("failed to get management repo policy provider: GITLAB_TOKEN not specified")
}
🤖 Prompt for AI Agents
In ee/cli/pkg/policy/providers.go around lines 17 to 19, the error message
incorrectly references GITHUB_TOKEN instead of GITLAB_TOKEN and contains a typo
in "managent". Update the error message to correctly say "failed to get
management repo policy provider: GITLAB_TOKEN not specified" to fix both the
environment variable name and the typo.

@motatoes motatoes merged commit b9f645e into develop Jun 1, 2025
12 checks passed
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