Skip to content

Commit

Permalink
Merge pull request #231 from l3montree-dev/fix/autoSetup
Browse files Browse the repository at this point in the history
Refactor GitLab integration to accept GitLab URL and update pipeline templates
  • Loading branch information
timbastin authored Nov 27, 2024
2 parents ffeaf7a + 8faf5c7 commit a0940f0
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 26 deletions.
10 changes: 6 additions & 4 deletions internal/core/integrations/gitlab_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ func (g *gitlabIntegration) AutoSetup(ctx core.Context) error {
return errors.Wrap(err, "could not read gitlab integration")
}
accessToken := integration.AccessToken
gitlabUrl := integration.GitLabUrl

var req struct {
DevguardAssetName string `json:"devguardAssetName"`
Expand Down Expand Up @@ -436,7 +437,7 @@ func (g *gitlabIntegration) AutoSetup(ctx core.Context) error {
}

templatePath := getTemplatePath(ctx.QueryParam("scanType"))
err = setupAndPushPipeline(accessToken, projectName, templatePath)
err = setupAndPushPipeline(accessToken, gitlabUrl, projectName, templatePath)
if err != nil {
return errors.Wrap(err, "could not setup and push pipeline")
}
Expand All @@ -447,9 +448,10 @@ func (g *gitlabIntegration) AutoSetup(ctx core.Context) error {

//create a merge request
mr, _, err := client.CreateMergeRequest(ctx.Request().Context(), projectName, &gitlab.CreateMergeRequestOptions{
SourceBranch: gitlab.Ptr("devguard-autosetup"),
TargetBranch: gitlab.Ptr("main"),
Title: gitlab.Ptr("Add devguard pipeline template"),
SourceBranch: gitlab.Ptr("devguard-autosetup"),
TargetBranch: gitlab.Ptr("main"),
Title: gitlab.Ptr("Add devguard pipeline template"),
RemoveSourceBranch: gitlab.Ptr(true),
})

if err != nil {
Expand Down
6 changes: 2 additions & 4 deletions internal/core/integrations/integration_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"github.com/go-git/go-git/v5/plumbing/transport/http"
)

func setupAndPushPipeline(accessToken string, projectName string, templatePath string) error {
func setupAndPushPipeline(accessToken string, gitlabUrl string, projectName string, templatePath string) error {
dir, err := os.MkdirTemp("", "repo-clone")
if err != nil {
return fmt.Errorf("could not create temporary directory: %v", err)
Expand All @@ -24,10 +24,8 @@ func setupAndPushPipeline(accessToken string, projectName string, templatePath s
}

r, err := git.PlainClone(dir, false, &git.CloneOptions{
//URL: "[email protected]:" + projectName + ".git",
URL: "https://gitlab.com/" + projectName + ".git",
URL: gitlabUrl + "/" + projectName + ".git",
Auth: authentication,
//URL: "https://gitlab.com/l3montree/bachelorarbeit.git",
})
if err != nil {
return fmt.Errorf("could not clone repository: %v", err)
Expand Down
12 changes: 6 additions & 6 deletions templates/container_scanning_template.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
stages:
- build
- test
- build
- test

include:
- component: $CI_SERVER_FQDN/l3montree/devguard/sca@~latest
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"
- remote: "https://gitlab.com/l3montree/devguard/-/raw/main/templates/container-scanning.yml"
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"
14 changes: 7 additions & 7 deletions templates/full_template.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
stages:
- build
- test
- deploy
- build
- test
- deploy

include:
- component: $CI_SERVER_FQDN/l3montree/devguard/full@~latest
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"
- remote: "https://gitlab.com/l3montree/devguard/-/raw/main/templates/full.yml"
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"
10 changes: 5 additions & 5 deletions templates/sca_template.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
stages:
- test
- test

include:
- component: $CI_SERVER_FQDN/l3montree/devguard/software-composition-analysis@~latest
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"
- remote: "https://gitlab.com/l3montree/devguard/-/raw/main/templates/software-composition-analysis.yml"
inputs:
asset_name: "$DEVGUARD_ASSET_NAME"
token: "$DEVGUARD_TOKEN"

0 comments on commit a0940f0

Please sign in to comment.