-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
52ee9f5
commit 86e2f94
Showing
12 changed files
with
171 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 == "" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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:"-"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package nextgen | ||
|
||
type PipelineData struct { | ||
Pipeline Pipeline `yaml:"pipeline"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)) | ||
// } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters