Skip to content

Commit

Permalink
feat(cdsctl,sdk): manage vcs on projects (#6132)
Browse files Browse the repository at this point in the history
* feat(cdsctl,sdk): manage vcs on projects

Signed-off-by: Yvonnick Esnault <[email protected]>
  • Loading branch information
yesnault authored Apr 5, 2022
1 parent 042861d commit d3c2b12
Show file tree
Hide file tree
Showing 26 changed files with 399 additions and 15 deletions.
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)
24 changes: 24 additions & 0 deletions cli/cdsctl/experimental.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package main

import (
"github.com/spf13/cobra"

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

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

func experimentalCommands() []*cobra.Command {
return []*cobra.Command{
experimentalProject(),
}
}

func experimental() *cobra.Command {
return cli.NewCommand(experimentalCmd, nil, experimentalCommands())
}
18 changes: 18 additions & 0 deletions cli/cdsctl/experimental_project.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package main

import (
"github.com/spf13/cobra"

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

var experimentalProjectCmd = cli.Command{
Name: "project",
Short: "CDS Experimental project commands",
}

func experimentalProject() *cobra.Command {
return cli.NewCommand(experimentalProjectCmd, nil, []*cobra.Command{
projectVCS(),
})
}
114 changes: 114 additions & 0 deletions cli/cdsctl/experimental_project_vcs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
package main

import (
"context"
"fmt"
"os"

"github.com/spf13/cobra"

yaml "github.com/ghodss/yaml"
"github.com/ovh/cds/cli"
"github.com/ovh/cds/sdk/cdsclient"
)

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(context.Background(), 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(context.Background(), 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(context.Background(), 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(context.Background(), v.GetString(_ProjectKey), v.GetString("name"))
if err != nil {
return err
}

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

fmt.Println(string(btes))
return nil
}
1 change: 1 addition & 0 deletions cli/cdsctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {
encrypt(),
contexts(),
environment(),
experimental(),
events(),
group(),
health(),
Expand Down
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
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
1 change: 0 additions & 1 deletion contrib/grpcplugins/action/plugin-npm-audit-parser/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-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(ctx context.Context, projectKey string, vcsName string) (sdk.VCSProject, error) {
path := fmt.Sprintf("/v2/project/%s/vcs/%s", projectKey, vcsName)
var pf sdk.VCSProject
if _, err := c.GetJSON(ctx, path, &pf); err != nil {
return pf, err
}
return pf, nil
}

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

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

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

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(ctx, projectKey, pf.Name)
if oldvcs.Name == "" {
path := fmt.Sprintf("/v2/project/%s/vcs", projectKey)
if _, err := c.PostJSON(ctx, 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(ctx, 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(ctx context.Context, projectKey string, content io.Reader, mods ...RequestModifier) (sdk.VCSProject, error)
ProjectVCSGet(ctx context.Context, projectKey string, integrationName string) (sdk.VCSProject, error)
ProjectVCSList(ctx context.Context, projectKey string) ([]sdk.VCSProject, error)
ProjectVCSDelete(ctx context.Context, projectKey string, integrationName string) error
}

// ProjectKeysClient exposes project keys related functions
Expand Down
Loading

0 comments on commit d3c2b12

Please sign in to comment.