-
Notifications
You must be signed in to change notification settings - Fork 0
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
Showing
52 changed files
with
2,029 additions
and
96 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
dist/ | ||
vendor/ | ||
.envrc | ||
terraform-provider-jenkins |
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,22 @@ | ||
package client | ||
|
||
type CpsScmFlowDefinition struct { | ||
Class string `xml:"class,attr"` | ||
|
||
Id string `xml:"id,attr"` | ||
SCM *GitSCM `xml:"scm"` | ||
ScriptPath string `xml:"scriptPath"` | ||
Lightweight bool `xml:"lightweight"` | ||
} | ||
|
||
func NewCpsScmFlowDefinition() *CpsScmFlowDefinition { | ||
return &CpsScmFlowDefinition{ | ||
Class: "org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition", | ||
} | ||
} | ||
|
||
// func (definition *CpsScmFlowDefinition) MarshalXML(e *xml.Encoder, start xml.StartElement) error { | ||
// start.Name.Local = "asdf" | ||
// e. | ||
// return nil | ||
// } |
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,22 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/xml" | ||
"testing" | ||
) | ||
|
||
func TestCpsScmFlowDefinitionSerialize(t *testing.T) { | ||
definition := NewCpsScmFlowDefinition() | ||
resultBytes, err := xml.MarshalIndent(definition, "", "\t") | ||
if err != nil { | ||
t.Fatalf("failed to serialize xml %s", err) | ||
} | ||
result := string(resultBytes) | ||
expected := `<CpsScmFlowDefinition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" id=""> | ||
<scriptPath></scriptPath> | ||
<lightweight>false</lightweight> | ||
</CpsScmFlowDefinition>` | ||
if result != expected { | ||
t.Fatalf("job definition should be %s, was %s", expected, result) | ||
} | ||
} |
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,29 @@ | ||
package client | ||
|
||
type GitUserRemoteConfigs struct { | ||
Items *[]*GitUserRemoteConfig `xml:"hudson.plugins.git.UserRemoteConfig"` | ||
} | ||
|
||
func NewGitUserRemoteConfigs() *GitUserRemoteConfigs { | ||
return &GitUserRemoteConfigs{ | ||
Items: &[]*GitUserRemoteConfig{}, | ||
} | ||
} | ||
|
||
func (configs *GitUserRemoteConfigs) Append(config *GitUserRemoteConfig) *GitUserRemoteConfigs { | ||
var newConfigItems []*GitUserRemoteConfig | ||
if (configs.Items != nil) { | ||
newConfigItems = append(*configs.Items, config) | ||
} else { | ||
newConfigItems = append(newConfigItems, config) | ||
} | ||
newConfigs := NewGitUserRemoteConfigs() | ||
newConfigs.Items = &newConfigItems | ||
return newConfigs | ||
} | ||
|
||
type GitUserRemoteConfig struct { | ||
Refspec string `xml:"refspec"` | ||
Url string `xml:"url"` | ||
CredentialsId string `xml:"credentialsId"` | ||
} |
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 |
---|---|---|
@@ -1,21 +1,48 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/xml" | ||
"fmt" | ||
) | ||
|
||
// JenkinsError Error response from jenkins | ||
type JenkinsError struct { | ||
ErrorMsg string `xml:"error"` | ||
Exception string `xml:"exception"` | ||
Message string `xml:"message"` | ||
Status int `xml:"status"` | ||
Timestamp int64 `xml:"timestamp"` | ||
Body string `xml:"body"` | ||
XMLName xml.Name `xml:"html"` | ||
Title string | ||
Message string | ||
} | ||
|
||
// For error interface | ||
func (r *JenkinsError) Error() string { | ||
return fmt.Sprintf("%d %v: %v%v\n%v", r.Status, r.ErrorMsg, r.Message, | ||
r.Body, r.Exception) | ||
return fmt.Sprintf("%v: %v", r.Title, r.Message) | ||
} | ||
|
||
func (jenkinsError *JenkinsError) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error { | ||
var tok xml.Token | ||
var err error | ||
for tok, err = d.Token(); err == nil; tok, err = d.Token() { | ||
if elem, ok := tok.(xml.StartElement); ok { | ||
switch elem.Name.Local { | ||
case "title": | ||
tok, err = d.Token() | ||
if err != nil { | ||
return err | ||
} | ||
if char, ok := tok.(xml.CharData); ok { | ||
jenkinsError.Title = string(char) | ||
} | ||
case "p": | ||
fallthrough | ||
case "pre": | ||
tok, err = d.Token() | ||
if err != nil { | ||
return err | ||
} | ||
if char, ok := tok.(xml.CharData); ok { | ||
jenkinsError.Message += string(char) | ||
} | ||
} | ||
} | ||
} | ||
return 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
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 |
---|---|---|
@@ -1,18 +1,31 @@ | ||
package client | ||
|
||
import "encoding/xml" | ||
import ( | ||
"encoding/xml" | ||
) | ||
|
||
type jobConfig struct { | ||
XMLName xml.Name `xml:"flow-definition"` | ||
Id string `xml:"id,attr"` | ||
Plugin string `xml:"plugin,attr"` | ||
|
||
// actions | ||
Description string `xml:"description"` | ||
// keepDependencies | ||
// properties | ||
Definition *JobDefinition `xml:"definition"` | ||
Triggers *[]*Trigger `xml:"triggers"` | ||
Disabled bool `xml:"disabled"` | ||
Properties *JobProperties `xml:"properties"` | ||
Definition *JobDefinitionXml `xml:"definition"` | ||
// Triggers *[]*Trigger `xml:"triggers"` | ||
Disabled bool `xml:"disabled"` | ||
} | ||
|
||
func JobConfigFromJob(job *Job) *jobConfig { | ||
return &jobConfig{} | ||
return &jobConfig{ | ||
Id: job.Id, | ||
Description: job.Description, | ||
Disabled: job.Disabled, | ||
Properties: job.Properties, | ||
Definition: &JobDefinitionXml{ | ||
Item: job.Definition, | ||
}, | ||
} | ||
} |
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,24 @@ | ||
package client | ||
|
||
import ( | ||
"encoding/xml" | ||
"testing" | ||
) | ||
|
||
func TestJobConfigSerialize(t *testing.T) { | ||
job := NewJob() | ||
config := JobConfigFromJob(job) | ||
resultBytes, err := xml.MarshalIndent(config, "", "\t") | ||
if err != nil { | ||
t.Fatalf("failed to serialize xml %s", err) | ||
} | ||
result := string(resultBytes) | ||
expected := `<flow-definition id="" plugin="workflow-job@2.33"> | ||
<description></description> | ||
<properties></properties> | ||
<disabled>false</disabled> | ||
</flow-definition>` | ||
if result != expected { | ||
t.Fatalf("job definition should be %s, was %s", expected, result) | ||
} | ||
} |
Oops, something went wrong.