Skip to content

feat: gitlab scm#4345

Merged
markphelps merged 12 commits into
v2from
v2-scm-gitlab
Jun 12, 2025
Merged

feat: gitlab scm#4345
markphelps merged 12 commits into
v2from
v2-scm-gitlab

Conversation

@markphelps

@markphelps markphelps commented Jun 10, 2025

Copy link
Copy Markdown
Collaborator

Screen Shot 2025-06-10 at 17 14 04

Screen Shot 2025-06-10 at 17 13 45

Config

storage:
  default:
    name: "local" 
  gitlab:
    name: "gitlab"
    remote: "https://gitlab.com/markphelps/flipt-features"
    branch: "main"
    credentials: "gitlab"

environments:
  local:
    name: "local"
    default: true

  gitlab:
    name: "gitlab"
    storage: "gitlab"
    directory: "features"
    scm:
      type: gitlab
      credentials: gitlab

credentials:
  gitlab:
    type: "access_token"
    access_token: ${FLIPT_GITLAB_TOKEN}

TODO

  • There was a bug on startup where the default namespace didnt exist in my gitlab repo. Need to check on this
  • Merge proposals dont work yet, cant list changes.

Might be due to how we're reusing the auth (basic) for the clone and API which might not be supported for GitLab

We also need to document that you can use one set of auth creds for git operations (like cloning) when configuring storage and another set when integrating with the SCM API (like access token)

^ This was the case. Now we convert the credential to the correct format expected by both Git and the SCM API

So now you can configure your creds for GitHub/GitLab (and probably Gitea) as access_token and this will work for both vanilla git operations (fetch/branch/push) as well as in the SCM clients themselves for creating PRs/etc

Signed-off-by: Mark Phelps <[email protected]>
@github-actions

github-actions Bot commented Jun 10, 2025

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Proto / proto-lint (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed✅ passed✅ passed❌ failed (12)Jun 12, 2025, 2:28 PM

Signed-off-by: Mark Phelps <[email protected]>
@codecov

codecov Bot commented Jun 10, 2025

Copy link
Copy Markdown

Codecov Report

Attention: Patch coverage is 48.32041% with 200 lines in your changes missing coverage. Please review.

Project coverage is 53.46%. Comparing base (5588468) to head (d89cb49).
Report is 16 commits behind head on v2.

Files with missing lines Patch % Lines
...terprise/storage/environments/git/gitlab/gitlab.go 60.45% 64 Missing and 6 partials ⚠️
...terprise/storage/environments/git/github/github.go 20.45% 35 Missing ⚠️
internal/storage/environments/environments.go 0.00% 35 Missing ⚠️
...enterprise/storage/environments/git/gitea/gitea.go 32.65% 33 Missing ⚠️
...nternal/enterprise/storage/environments/git/url.go 57.14% 10 Missing and 5 partials ⚠️
internal/storage/environments/git/store.go 0.00% 10 Missing ⚠️
internal/credentials/credentials.go 93.93% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##               v2    #4345      +/-   ##
==========================================
+ Coverage   50.65%   53.46%   +2.81%     
==========================================
  Files         122      118       -4     
  Lines       13200    12425     -775     
==========================================
- Hits         6686     6643      -43     
+ Misses       5950     5297     -653     
+ Partials      564      485      -79     
Flag Coverage Δ
unittests 53.46% <48.32%> (+2.81%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@markphelps

Copy link
Copy Markdown
Collaborator Author

I tested in a gitlab project that this successfully creates a Merge Request (their PRs) and puts it in draft mode via the title

I will look into and fix the potential bug with it not pushing the default namespace in another PR

@markphelps
markphelps marked this pull request as ready for review June 11, 2025 14:08
@markphelps
markphelps requested a review from a team as a code owner June 11, 2025 14:08
@markphelps
markphelps requested a review from erka June 11, 2025 14:08
Comment thread internal/credentials/credentials.go
Comment thread rpc/v2/environments/environments.proto
Signed-off-by: Mark Phelps <[email protected]>
@dosubot dosubot Bot added the size:XXL This PR changes 1000+ lines, ignoring generated files. label Jun 11, 2025
@markphelps
markphelps requested a review from Copilot June 11, 2025 14:23

This comment was marked as outdated.

Signed-off-by: Mark Phelps <[email protected]>
@markphelps markphelps changed the title feat: work on gitlab support feat: gitlab scm Jun 11, 2025
Comment thread internal/enterprise/storage/environments/git/gitea/gitea.go
Comment thread rpc/v2/environments/environments.proto Outdated
Comment thread internal/enterprise/storage/environments/git/github/github.go Outdated
Signed-off-by: Mark Phelps <[email protected]>
@markphelps
markphelps requested review from Copilot and erka June 12, 2025 13:38

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

Adds GitLab as a supported SCM for environment storage, refactors URL parsing, and unifies authentication handling across providers.

  • Introduce gitlab in SCM types, configuration schemas, and environment gRPC messages.
  • Refactor URL parsing to a generic ParseGitURL and update the factory to branch on GitLab.
  • Implement GitLab SCM client with authentication options, tests, and mocks; update credentials to normalize token auth across Git, GitHub, GitLab, and Gitea.

Reviewed Changes

Copilot reviewed 26 out of 26 changed files in this pull request and generated no comments.

Show a summary per file
File Description
internal/storage/environments/git/store.go Expose new Scm field on EnvironmentConfiguration.
internal/storage/environments/environments.go Handle GitLabSCMType in the EnvironmentFactory switch.
internal/storage/environments/environments_test.go Remove outdated Gitea URL parsing tests.
internal/server/analytics/prometheus/prometheus_mock.go Alias Prometheus import for mock.
internal/enterprise/storage/environments/git/url.go Add ParseGitURL with SSH fallback.
internal/enterprise/storage/environments/git/url_test.go Add tests covering ParseGitURL.
internal/enterprise/storage/environments/git/gitlab/gitlab.go Implement GitLab SCM client, auth setup, and logging.
internal/enterprise/storage/environments/git/gitlab/gitlab_test.go Add comprehensive GitLab SCM client tests.
internal/enterprise/storage/environments/git/gitlab/gitlab_mock.go Generate mocks for GitLab services.
internal/enterprise/storage/environments/git/github/github.go Update GitHub SCM to use unified options and token auth.
internal/enterprise/storage/environments/git/github/github_test.go Remove now-irrelevant SCM field checks.
internal/enterprise/storage/environments/git/gitea/gitea.go Update Gitea SCM client, unify auth options, add logging.
internal/enterprise/storage/environments/git/gitea/gitea_test.go Remove obsolete SCM field checks and add logger injection.
internal/credentials/credentials.go Consolidate GitAuthentication and APIAuthentication methods.
internal/credentials/credentials_test.go Update credential tests for Git and API auth.
internal/config/environments.go Add GitLabSCMType and extend validation.
config/flipt.schema.json Extend JSON schema with "gitlab" in SCM enum.
config/flipt.schema.cue Extend CUE schema with "gitlab" in SCM type.
go.mod Add GitLab API client dependency and bump misc. modules.
.mockery.yml Include GitLab interfaces for mock generation.
Comments suppressed due to low confidence (4)

internal/enterprise/storage/environments/git/gitea/gitea.go:126

  • Typo in variable name comparition; consider renaming to comparison for clarity and consistency.
comparition, _, err := s.client.CompareCommits(s.repoOwner, s.repoName, req.Base, req.Head)

internal/storage/environments/git/store.go:133

  • The new Scm field is added to EnvironmentConfiguration but there are no unit tests covering its value—consider adding tests for GitHub, GitLab, and Gitea scenarios.
Scm:       scm,

internal/credentials/credentials.go:123

  • [nitpick] Returning an empty APIAuth for SSH credentials may silently disable API authentication; consider returning an explicit error or clearly documenting that SSH is unsupported for API calls.
return &APIAuth{

internal/enterprise/storage/environments/git/gitlab/gitlab.go:11

  • Importing "iter" without a full module path will fail to resolve; please correct the import to the actual package path (e.g., "go.flipt.io/flipt/internal/iter").
"iter"

@erka erka left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

nice

Signed-off-by: Mark Phelps <[email protected]>
@markphelps
markphelps merged commit 21672f0 into v2 Jun 12, 2025
14 of 20 checks passed
@markphelps
markphelps deleted the v2-scm-gitlab branch June 12, 2025 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:XXL This PR changes 1000+ lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants