Skip to content

Commit

Permalink
Gitsync setup
Browse files Browse the repository at this point in the history
  • Loading branch information
micahlmartin committed Mar 17, 2022
1 parent 52ee9f5 commit 86e2f94
Show file tree
Hide file tree
Showing 12 changed files with 171 additions and 8 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ require (
github.com/stretchr/testify v1.7.0
github.com/t-tomalak/logrus-easy-formatter v0.0.0-20190827215021-c074f06c5816
golang.org/x/oauth2 v0.0.0-20220309155454-6242fa91716a
gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b
)

Expand Down
1 change: 1 addition & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,7 @@ gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
Expand Down
2 changes: 1 addition & 1 deletion harness/nextgen/model_connector_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ type ConnectorResponse struct {
LastModifiedAt int64 `json:"lastModifiedAt,omitempty"`
Status *ConnectorConnectivityDetails `json:"status,omitempty"`
ActivityDetails *ConnectorActivityDetails `json:"activityDetails,omitempty"`
// This indicates if this Connector is managed by Harness or not. If True, Harness can manage and modify this Connector.
// This indicates if this Connector is managed by Harness or not. If True, Harness can manage and modify this Connector.
HarnessManaged bool `json:"harnessManaged,omitempty"`
GitDetails *EntityGitDetails `json:"gitDetails,omitempty"`
EntityValidityDetails *EntityGitDetails `json:"entityValidityDetails,omitempty"`
Expand Down
16 changes: 12 additions & 4 deletions harness/nextgen/model_entity_git_details.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,16 @@ package nextgen

// This contains Validity Details of the Entity
type EntityGitDetails struct {
// Indicates if the Entity is valid
Valid bool `json:"valid,omitempty"`
// This has the Git File content if the entity is invalid
InvalidYaml string `json:"invalidYaml,omitempty"`
// Object Id of the Entity
ObjectId string `json:"objectId,omitempty"`
// Branch Name
Branch string `json:"branch,omitempty"`
// Git Sync Config Id
RepoIdentifier string `json:"repoIdentifier,omitempty"`
// Root Folder Path of the Entity
RootFolder string `json:"rootFolder,omitempty"`
// File Path of the Entity
FilePath string `json:"filePath,omitempty"`
// Name of the repo
RepoName string `json:"repoName,omitempty"`
}
60 changes: 60 additions & 0 deletions harness/nextgen/model_entity_git_details_helper.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
package nextgen

import (
"github.com/jinzhu/copier"
)

func (d *EntityGitDetailsOptions) ToPipelinesApiPostPipelineOpts() *PipelinesApiPostPipelineOpts {
opts := &PipelinesApiPostPipelineOpts{}
err := copier.Copy(opts, d)
if err != nil {
return nil
}
return opts
}

func (d *EntityGitDetailsOptions) ToPipelinesApiUpdatePipelineV2Opts() *PipelinesApiUpdatePipelineV2Opts {
opts := &PipelinesApiUpdatePipelineV2Opts{}
err := copier.Copy(opts, d)
if err != nil {
return nil
}
return opts
}

func (d *EntityGitDetailsOptions) ToPipelinesApiGetPipelineOpts() *PipelinesApiGetPipelineOpts {
opts := &PipelinesApiGetPipelineOpts{}
err := copier.Copy(opts, d)
if err != nil {
return nil
}
return opts
}

func (d *EntityGitDetailsOptions) ToPipelinesApiDeletePipelineOpts() *PipelinesApiDeletePipelineOpts {
opts := &PipelinesApiDeletePipelineOpts{}
err := copier.Copy(opts, d)
opts.LastObjectId = d.ObjectId
if err != nil {
return nil
}
return opts
}

func (d *PipelineEntityGitDetails) ToEntityGitDetails() *EntityGitDetails {
gitEntity := &EntityGitDetails{}
err := copier.Copy(gitEntity, d)
if err != nil {
return nil
}
return gitEntity
}

func (d *EntityGitDetails) IsEmpty() bool {
return d.ObjectId == "" &&
d.Branch == "" &&
d.RepoIdentifier == "" &&
d.RootFolder == "" &&
d.FilePath == "" &&
d.RepoName == ""
}
15 changes: 15 additions & 0 deletions harness/nextgen/model_entity_git_details_options.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package nextgen

import "github.com/antihax/optional"

// EntityGitDetailsOptions used for translating between the different API input options
type EntityGitDetailsOptions struct {
Branch optional.String
RepoIdentifier optional.String
RootFolder optional.String
FilePath optional.String
CommitMsg optional.String
IsNewBranch optional.Bool
BaseBranch optional.String
ObjectId optional.String
}
27 changes: 27 additions & 0 deletions harness/nextgen/model_entity_git_details_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package nextgen_test

import (
"testing"

"github.com/harness/harness-go-sdk/harness/nextgen"
"github.com/jinzhu/copier"
"github.com/stretchr/testify/require"
)

func TestSerialization(t *testing.T) {

gitEntity := &nextgen.EntityGitDetails{
ObjectId: "object_id",
Branch: "branch",
RepoIdentifier: "repo_id",
RootFolder: "root_folder",
FilePath: "file_path",
RepoName: "repo_name",
}

opts := &nextgen.PipelinesApiUpdatePipelineOpts{}

err := copier.Copy(opts, gitEntity)
require.NoError(t, err)

}
9 changes: 9 additions & 0 deletions harness/nextgen/model_pipeline.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package nextgen

type Pipeline struct {
Name string `yaml:"name"`
Identifier string `yaml:"identifier"`
ProjectIdentifier string `yaml:"projectIdentifier"`
OrgIdentifier string `yaml:"orgIdentifier"`
Yaml string `yaml:"-"`
}
5 changes: 5 additions & 0 deletions harness/nextgen/model_pipeline_yaml.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package nextgen

type PipelineData struct {
Pipeline Pipeline `yaml:"pipeline"`
}
1 change: 1 addition & 0 deletions harness/nextgen/model_pms_pipeline_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,5 @@ type PmsPipelineResponse struct {
GitDetails *PipelineEntityGitDetails `json:"gitDetails,omitempty"`
EntityValidityDetails *PipelineEntityGitDetails `json:"entityValidityDetails,omitempty"`
Modules []string `json:"modules,omitempty"`
PipelineData *PipelineData `json:"-"`
}
36 changes: 36 additions & 0 deletions harness/nextgen/model_pms_pipeline_response_serializer.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package nextgen

import (
"encoding/json"

"gopkg.in/yaml.v3"
)

func (a *PmsPipelineResponse) UnmarshalJSON(data []byte) error {

type Alias PmsPipelineResponse

aux := &struct {
*Alias
}{
Alias: (*Alias)(a),
}

err := json.Unmarshal(data, &aux)
if err != nil {
return err
}

err = yaml.Unmarshal([]byte(aux.YamlPipeline), &a.PipelineData)
// a.PipelineData.Pipeline.Yaml = string(data)

return err
}

// func (a *PmsPipelineResponse) MarshalJSON() ([]byte, error) {
// type Alias PmsPipelineResponse

// a.YamlPipeline = a.PipelineData.Pipeline.Yaml

// return json.Marshal((*Alias)(a))
// }
6 changes: 3 additions & 3 deletions harness/nextgen/model_service_response.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
package nextgen

type ServiceResponse struct {
Service *ServiceResponse `json:"service,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
LastModifiedAt int64 `json:"lastModifiedAt,omitempty"`
Service *ServiceRequest `json:"service,omitempty"`
CreatedAt int64 `json:"createdAt,omitempty"`
LastModifiedAt int64 `json:"lastModifiedAt,omitempty"`
}

0 comments on commit 86e2f94

Please sign in to comment.