Skip to content
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

feat(cdsctl,sdk): manage vcs on projects #6132

Merged
merged 6 commits into from
Apr 5, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -115,3 +115,5 @@ tidy:
done;
@echo "Running tidy on tests/fixtures/04SCWorkflowRunSimplePlugin"
@(cd tests/fixtures/04SCWorkflowRunSimplePlugin && go mod tidy)
@(cd sdk/interpolate && go mod tidy)
@(cd tools/smtpmock && go mod tidy)
1 change: 1 addition & 0 deletions cli/cdsctl/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ func projectCommands() []*cobra.Command {
projectKey(),
projectVariable(),
projectIntegration(),
projectExperimental(),
projectRepositoryManager(),
}
}
Expand Down
19 changes: 19 additions & 0 deletions cli/cdsctl/project_experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package main

import (
"github.com/spf13/cobra"

"github.com/ovh/cds/cli"
)

var projectExperimentalCmd = cli.Command{
Name: "experimental",
Aliases: []string{"exp"},
Short: "CDS Experimental commands",
}

func projectExperimental() *cobra.Command {
return cli.NewCommand(projectExperimentalCmd, nil, []*cobra.Command{
projectVCS(),
})
}
4 changes: 2 additions & 2 deletions cli/cdsctl/project_integration.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func projectIntegrationDeleteFunc(v cli.Values) error {
var projectIntegrationImportCmd = cli.Command{
Name: "import",
Short: "Import a integration configuration on a project from a yaml file",
Example: "cdsctl integration import MY-PROJECT file.yml",
Example: "cdsctl project integration import MY-PROJECT file.yml",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Expand Down Expand Up @@ -93,7 +93,7 @@ func projectIntegrationImportFunc(v cli.Values) error {
var projectIntegrationExportCmd = cli.Command{
Name: "export",
Short: "Export a integration configuration from a project to stdout",
Example: "cdsctl integration export MY-PROJECT MY-INTEGRATION-NAME > file.yaml",
Example: "cdsctl project integration export MY-PROJECT MY-INTEGRATION-NAME > file.yaml",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Expand Down
113 changes: 113 additions & 0 deletions cli/cdsctl/project_vcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package main

import (
"fmt"
"os"

"github.com/spf13/cobra"

"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk/cdsclient"
"github.com/ovh/cds/sdk/exportentities"
)

var projectVCSCmd = cli.Command{
Name: "vcs",
Aliases: []string{"vcs"},
Short: "Manage VCS on a CDS project",
}

func projectVCS() *cobra.Command {
return cli.NewCommand(projectVCSCmd, nil, []*cobra.Command{
cli.NewListCommand(projectVCSListCmd, projectVCSListFunc, nil, withAllCommandModifiers()...),
cli.NewDeleteCommand(projectVCSDeleteCmd, projectVCSDeleteFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectVCSImportCmd, projectVCSImportFunc, nil, withAllCommandModifiers()...),
cli.NewCommand(projectVCSExportCmd, projectVCSExportFunc, nil, withAllCommandModifiers()...),
})
}

var projectVCSListCmd = cli.Command{
Name: "list",
Short: "List VCS available on a project",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
}

func projectVCSListFunc(v cli.Values) (cli.ListResult, error) {
pfs, err := client.ProjectVCSList(v.GetString(_ProjectKey))
return cli.AsListResult(pfs), err
}

var projectVCSDeleteCmd = cli.Command{
Name: "delete",
Short: "Delete a VCS configuration on a project",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Args: []cli.Arg{
{Name: "name"},
},
}

func projectVCSDeleteFunc(v cli.Values) error {
return client.ProjectVCSDelete(v.GetString(_ProjectKey), v.GetString("name"))
}

var projectVCSImportCmd = cli.Command{
Name: "import",
Short: "Import a VCS configuration on a project from a yaml file",
Example: "cdsctl project vcs import MY-PROJECT file.yml",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Args: []cli.Arg{
{Name: "filename"},
},
Flags: []cli.Flag{
{Name: "force", Type: cli.FlagBool},
},
}

func projectVCSImportFunc(v cli.Values) error {
f, err := os.Open(v.GetString("filename"))
if err != nil {
return cli.WrapError(err, "unable to open file %s", v.GetString("filename"))
}
defer f.Close()

var mods []cdsclient.RequestModifier
if v.GetBool("force") {
mods = append(mods, cdsclient.Force())
}

_, err = client.ProjectVCSImport(v.GetString(_ProjectKey), f, mods...)
return err
}

var projectVCSExportCmd = cli.Command{
Name: "export",
Short: "Export a VCS configuration from a project to stdout",
Example: "cdsctl vcs export MY-PROJECT MY-VCS-SERVER-NAME > file.yaml",
Ctx: []cli.Arg{
{Name: _ProjectKey},
},
Args: []cli.Arg{
{Name: "name"},
},
}

func projectVCSExportFunc(v cli.Values) error {
pf, err := client.ProjectVCSGet(v.GetString(_ProjectKey), v.GetString("name"))
if err != nil {
return err
}

btes, err := exportentities.Marshal(pf, exportentities.FormatYAML)
if err != nil {
return err
}

fmt.Println(string(btes))
return nil
}
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-archive/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJm
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v0.0.0-20180910192245-6acdf747ae99/go.mod h1:bbYlZJ7hK1yFx9hf58LP0zeX7UjIGs20ufpu3evjr+s=
github.com/buger/jsonparser v1.1.1 h1:2PnMjfWD7wBILjqQbt530v576A/cAbQvEW9gGIpYMUs=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-download/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-group-tmpl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-kafka-publish/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 1 addition & 0 deletions contrib/grpcplugins/action/plugin-marathon/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ require (
github.com/emirpasic/gods v1.12.0 // indirect
github.com/fatih/color v1.13.0 // indirect
github.com/fsamin/go-dump v1.0.9 // indirect
github.com/ghodss/yaml v1.0.0 // indirect
github.com/go-git/gcfg v1.5.0 // indirect
github.com/go-git/go-billy/v5 v5.3.1 // indirect
github.com/go-git/go-git/v5 v5.4.2 // indirect
Expand Down
2 changes: 1 addition & 1 deletion contrib/grpcplugins/action/plugin-marathon/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down Expand Up @@ -213,6 +212,7 @@ github.com/fujiwara/shapeio v0.0.0-20170602072123-c073257dd745/go.mod h1:/WpqsrS
github.com/gambol99/go-marathon v0.0.0-20170922093320-ec4a50170df7/go.mod h1:GLyXJD41gBO/NPKVPGQbhyyC06eugGy15QEZyUkE2/s=
github.com/gambol99/go-marathon v0.7.1 h1:/dnwXQ0W0UDScpvmcdjzRz3ssnJ/5ieX/q4Xi/QHOn4=
github.com/gambol99/go-marathon v0.7.1/go.mod h1:GLyXJD41gBO/NPKVPGQbhyyC06eugGy15QEZyUkE2/s=
github.com/ghodss/yaml v1.0.0 h1:wQHKEahhL6wmXdzwWG11gIVCkOv05bNOh+Rxn0yngAk=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
github.com/gliderlabs/ssh v0.2.2 h1:6zsha5zo/TWhRhwqCD3+EarCAgZ2yN28ipRnGPnwkI0=
github.com/gliderlabs/ssh v0.2.2/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-ssh-cmd/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-tmpl/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
github.com/buger/jsonparser v1.1.1/go.mod h1:6RYKKt7H4d4+iWqouImQ9R2FZql3VbhNgx27UK13J/0=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
Expand Down
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-venom/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kB
github.com/bketelsen/crypt v0.0.3-0.20200106085610-5cbc8cc4026c/go.mod h1:MKsuJmJgSg28kpZDP6UIiPt0e0Oz0kqKNGyRaWEPv84=
github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ=
github.com/blang/semver v3.5.1+incompatible/go.mod h1:kRBLl5iJ+tD4TcOOxsy/0fnwebNt5EWlYSAyrTnjyyk=
github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869/go.mod h1:Ekp36dRnpXw/yCqJaO+ZrUyxD+3VXMFFr56k5XYrpB4=
github.com/bsm/sarama-cluster v2.1.15+incompatible h1:RkV6WiNRnqEEbp81druK8zYhmnIgdOjqSVi0+9Cnl2A=
github.com/bsm/sarama-cluster v2.1.15+incompatible/go.mod h1:r7ao+4tTNXvWm+VRpRJchr2kQhqxgmAp2iEX5W96gMM=
github.com/buger/goterm v0.0.0-20170918171949-d443b9114f9c/go.mod h1:u9UyCz2eTrSGy6fbupqJ54eY5c4IC8gREQ1053dK12U=
Expand Down
2 changes: 2 additions & 0 deletions engine/api/v2_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,8 @@ func (api *API) putVCSProjectHandler() ([]service.RbacChecker, service.Handler)
}

vcsProject.ID = vcsOld.ID
vcsProject.Created = vcsOld.Created
vcsProject.CreatedBy = vcsOld.CreatedBy

if err := vcs.Update(ctx, tx, &vcsProject); err != nil {
return err
Expand Down
66 changes: 66 additions & 0 deletions sdk/cdsclient/client_project_vcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package cdsclient

import (
"context"
"fmt"
"io"

"github.com/ghodss/yaml"

"github.com/ovh/cds/sdk"
)

func (c *client) ProjectVCSGet(projectKey string, vcsName string) (sdk.ProjectVCSServer, error) {
path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, vcsName)
var pf sdk.ProjectVCSServer
if _, err := c.GetJSON(context.Background(), path, &pf); err != nil {
return pf, err
}
return pf, nil
}

func (c *client) ProjectVCSList(projectKey string) ([]sdk.ProjectVCSServer, error) {
path := fmt.Sprintf("/v2/project/%s/vcs", projectKey)
var pfs []sdk.ProjectVCSServer
if _, err := c.GetJSON(context.Background(), path, &pfs); err != nil {
return pfs, err
}
return pfs, nil
}

func (c *client) ProjectVCSDelete(projectKey string, vcsName string) error {
path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, vcsName)
var pf sdk.ProjectVCSServer
if _, err := c.DeleteJSON(context.Background(), path, &pf); err != nil {
return err
}
return nil
}

func (c *client) ProjectVCSImport(projectKey string, content io.Reader, mods ...RequestModifier) (sdk.ProjectVCSServer, error) {
var pf sdk.ProjectVCSServer

body, err := io.ReadAll(content)
if err != nil {
return pf, err
}

if err := yaml.Unmarshal(body, &pf); err != nil {
return pf, err
}

oldvcs, _ := c.ProjectVCSGet(projectKey, pf.Name)
if oldvcs.Name == "" {
path := fmt.Sprintf("/v2/project/%s/vcs", projectKey)
if _, err := c.PostJSON(context.Background(), path, &pf, &pf, mods...); err != nil {
return pf, err
}
return pf, nil
}

path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, pf.Name)
if _, err := c.PutJSON(context.Background(), path, &pf, &pf, mods...); err != nil {
return pf, err
}
return pf, nil
}
4 changes: 4 additions & 0 deletions sdk/cdsclient/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,10 @@ type ProjectClient interface {
ProjectAccess(ctx context.Context, projectKey, sessionID string, itemType sdk.CDNItemType) error
ProjectIntegrationWorkerHookGet(projectKey string, integrationName string) (*sdk.WorkerHookProjectIntegrationModel, error)
ProjectIntegrationWorkerHooksImport(projectKey string, integrationName string, hook sdk.WorkerHookProjectIntegrationModel) error
ProjectVCSImport(projectKey string, content io.Reader, mods ...RequestModifier) (sdk.ProjectVCSServer, error)
yesnault marked this conversation as resolved.
Show resolved Hide resolved
ProjectVCSGet(projectKey string, integrationName string) (sdk.ProjectVCSServer, error)
ProjectVCSList(projectKey string) ([]sdk.ProjectVCSServer, error)
ProjectVCSDelete(projectKey string, integrationName string) error
}

// ProjectKeysClient exposes project keys related functions
Expand Down
Loading