Skip to content

support gitlab drift detection #1936

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 8 commits into from
Apr 8, 2025
Merged

Conversation

motatoes
Copy link
Contributor

@motatoes motatoes commented Apr 8, 2025

Summary by CodeRabbit

  • New Features

    • Added GitLab CI integration alongside GitHub CI, enabling the system to detect and trigger GitLab-specific workflows.
    • Enhanced drift detection support for GitLab, providing a more versatile CI experience for projects using GitLab pipelines.
    • Introduced documentation for GitLab drift detection workflow, offering configuration guidance for users.
  • Dependency Updates

    • Updated several dependencies to their latest versions, improving overall stability and performance.

Copy link
Contributor

coderabbitai bot commented Apr 8, 2025

Caution

Review failed

The pull request is closed.

Walkthrough

This pull request adds support for GitLab CI alongside the existing GitHub CI detection. It introduces a new case in a switch statement to detect GitLab CI, logs an appropriate message, and invokes a new function from a newly created GitLab package. The new GitLabCI function in the GitLab package handles environment variable validation, configuration loading, drift detection job construction, and execution via the Digger API, ensuring that the CI workflow is properly processed for GitLab environments.

Changes

File(s) Change Summary
ee/cli/cmd/.../default.go Added a new case (digger.GitLab) in the switch statement to detect GitLab CI; logs a message and calls the new GitLabCI function; added an import for the GitLab package.
ee/cli/pkg/.../gitlab/gitlab.go Introduced a new GitLab package with the GitLabCI function to manage GitLab CI/CD workflows, including environment variable checks, configuration loading, drift detection mode handling, job construction, and error management. The function logs execution steps and handles failures and panics appropriately.
Dockerfile_next Updated the ATLAS_VERSION environment variable from v0.28.0 to v0.31.0.
backend/go.mod Updated versions of several dependencies, including github.com/stretchr/testify, Azure SDK packages, and added a new dependency github.com/Azure/azure-sdk-for-go/sdk/storage/azblob.
cli/go.mod Updated versions of several dependencies, including Azure SDK packages and github.com/stretchr/testify, and added github.com/Azure/azure-sdk-for-go/sdk/storage/azblob.
ee/backend/go.mod Updated versions of several indirect dependencies, including Azure SDK packages, and added github.com/Azure/azure-sdk-for-go/sdk/storage/azblob.
ee/cli/go.mod Updated versions of several dependencies, including Azure SDK packages and github.com/stretchr/testify, and added github.com/Azure/azure-sdk-for-go/sdk/storage/azblob.
next/go.mod Updated versions of various dependencies, including Azure SDK packages, and added github.com/Azure/azure-sdk-for-go/sdk/storage/azblob. Removed dario.cat/mergo.
docs/ee/drift-detection.mdx Added a new section for GitLab drift detection workflow, detailing a configuration similar to the existing Slack workflow, including relevant variables and commands.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant DefaultCmd as defaultCmd.Run
    participant Switch as CI Environment Switch
    participant GitLabCI as gitlab.GitLabCI
    participant API as Digger API

    User->>DefaultCmd: Execute command
    DefaultCmd->>Switch: Check CI environment
    Switch-->>DefaultCmd: GitHub or GitLab detected
    alt GitLab CI detected
        DefaultCmd->>GitLabCI: Call GitLabCI(lock, policyChecker, backendApi, ...)
        GitLabCI->>GitLabCI: Log "gitlab CI detected" and load environment
        GitLabCI->>GitLabCI: Validate token and configuration
        GitLabCI->>GitLabCI: If drift-detection mode, iterate projects
        GitLabCI->>API: Execute drift detection job(s)
        API-->>GitLabCI: Return job result
        GitLabCI->>GitLabCI: Log success and completion
    else GitHub CI detected
        DefaultCmd->>/* GitHub Function */: (Handle GitHub CI)
    end
    GitLabCI-->>DefaultCmd: Return to main flow
Loading

Possibly related PRs

  • support gitlab drift detection #1936: The changes in the main PR and the retrieved PR are directly related as both introduce functionality for handling GitLab CI detection, including modifications to the same functions and classes in the default.go and gitlab.go files.

Poem

Oh what joy in code’s delight,
A GitLab path now shines so bright.
I hop along the CI lane,
With logs and checks, there’s much to gain.
Carrots and code in a merry spree,
Hoppy changes for both you and me! 🥕🐇


📜 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 1c53b22 and dcb1d8b.

⛔ Files ignored due to path filters (6)
  • backend/go.sum is excluded by !**/*.sum
  • cli/go.sum is excluded by !**/*.sum
  • ee/backend/go.sum is excluded by !**/*.sum
  • ee/cli/go.sum is excluded by !**/*.sum
  • go.work.sum is excluded by !**/*.sum
  • next/go.sum is excluded by !**/*.sum
📒 Files selected for processing (8)
  • Dockerfile_next (1 hunks)
  • backend/go.mod (3 hunks)
  • cli/go.mod (3 hunks)
  • docs/ee/drift-detection.mdx (1 hunks)
  • ee/backend/go.mod (3 hunks)
  • ee/cli/go.mod (3 hunks)
  • ee/cli/pkg/gitlab/gitlab.go (1 hunks)
  • next/go.mod (9 hunks)

🪧 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.
    • Generate unit testing code for this file.
    • 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 generate unit testing code for this file.
    • @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 generate unit testing code.
    • @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.

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 resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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

This PR integrates GitLab drift detection support by modifying drift handling in the default command and adding a dedicated GitLab implementation.

  • Added a new GitLab drift detection implementation in /ee/cli/pkg/gitlab/gitlab.go that gathers environment variables, loads config, and schedules drift jobs.
  • Modified /ee/cli/cmd/digger/default.go to detect GitLab CI and invoke gitlab.GitLabCI.
  • Updated go.work.sum to include the new kong dependency checksum.
  • Noted issues: an unreachable defer block and an unused parameter in the GitLab implementation.

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

Comment on lines 126 to 132
usage.ReportErrorAndExit(repoOwner, "Digger finished successfully", 0)

defer func() {
if r := recover(); r != nil {
usage.ReportErrorAndExit(repoOwner, fmt.Sprintf("Panic occurred. %s", r), 1)
}
}()
Copy link
Contributor

Choose a reason for hiding this comment

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

logic: Defer block placed after ReportErrorAndExit is unreachable. Consider moving defer above exit call.

Suggested change
usage.ReportErrorAndExit(repoOwner, "Digger finished successfully", 0)
defer func() {
if r := recover(); r != nil {
usage.ReportErrorAndExit(repoOwner, fmt.Sprintf("Panic occurred. %s", r), 1)
}
}()
defer func() {
if r := recover(); r != nil {
usage.ReportErrorAndExit(repoOwner, fmt.Sprintf("Panic occurred. %s", r), 1)
}
}()
usage.ReportErrorAndExit(repoOwner, "Digger finished successfully", 0)

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: 0

🧹 Nitpick comments (4)
ee/cli/cmd/digger/default.go (2)

13-13: Add a clarifying package comment or rationale.
The new import for gitlab is straightforward; consider adding a short comment describing its role to ease future code navigation, especially for developers unfamiliar with the GitLab integration.


71-73: Ensure consistent logging and handling.
The new switch case for digger.GitLab behaves similarly to GitHub. Good work on maintaining consistency. One improvement: unify the logging style (e.g., use log.Printf) and consider capturing the current actor or job context, as done for GitHub.

ee/cli/pkg/gitlab/gitlab.go (2)

1-19: Unify import statements and logging approach.
You employ a mix of fmt.Println, log.Printf, and println throughout this new file. Consider switching entirely to log.Printf for easier log parsing and consistency across the codebase.


47-133: Consider modularizing for clarity and maintainability.
The single GitLabCI function is lengthy and includes environment parsing, config loading, drift detection logic, and job execution. Splitting it into smaller functions (e.g., for config loading vs. job orchestration) could enhance readability and reuse.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 71aee64 and 1c53b22.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (2)
  • ee/cli/cmd/digger/default.go (2 hunks)
  • ee/cli/pkg/gitlab/gitlab.go (1 hunks)
🧰 Additional context used
🧬 Code Graph Analysis (2)
ee/cli/cmd/digger/default.go (2)
cli/pkg/digger/digger.go (1)
  • GitLab (37-37)
ee/cli/pkg/gitlab/gitlab.go (1)
  • GitLabCI (21-133)
ee/cli/pkg/gitlab/gitlab.go (6)
libs/digger_config/digger_config.go (1)
  • LoadDiggerConfig (214-243)
cli/pkg/usage/usage.go (1)
  • ReportErrorAndExit (111-118)
libs/policy/policy.go (1)
  • NoOpPolicyChecker (31-32)
libs/ci/gitlab/gitlab.go (2)
  • ParseGitLabContext (61-74)
  • NewGitLabService (76-101)
libs/scheduler/aws.go (1)
  • GetStateAndCommandProviders (364-387)
cli/pkg/digger/digger.go (1)
  • RunJob (563-732)
🔇 Additional comments (1)
ee/cli/pkg/gitlab/gitlab.go (1)

21-46: Handle empty environment variables more robustly.
When gitlabToken is empty, you only print a message without terminating. If GitLab operations rely on the token, consider failing fast or explaining read-only scenarios. Similarly, consider validating repoOwner or repoName to avoid unexpected nil references when constructing repoFullName.

@motatoes motatoes merged commit 8a4389b into develop Apr 8, 2025
11 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