Skip to content

Commit

Permalink
add jira project property
Browse files Browse the repository at this point in the history
ensure that job can serialize and deserialize without losing data
  • Loading branch information
jgramoll committed Aug 2, 2019
1 parent d88ee11 commit e80be59
Show file tree
Hide file tree
Showing 38 changed files with 483 additions and 113 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,10 @@ resource "jenkins_job_datadog_job_property" "main" {
job = "${jenkins_job.main.id}"
}
resource "jenkins_job_jira_project_property" "main" {
job = "${jenkins_job.main.id}"
}
```

## TODO
Expand Down
5 changes: 3 additions & 2 deletions client/cps_scm_flow_definition.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package client

type CpsScmFlowDefinition struct {
Class string `xml:"class,attr"`
Class string `xml:"class,attr"`
Id string `xml:"id,attr,omitempty"`
Plugin string `xml:"plugin,attr,omitempty"`

Id string `xml:"id,attr"`
SCM *GitSCM `xml:"scm"`
ScriptPath string `xml:"scriptPath"`
Lightweight bool `xml:"lightweight"`
Expand Down
2 changes: 1 addition & 1 deletion client/cps_scm_flow_definition_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ func TestCpsScmFlowDefinitionSerialize(t *testing.T) {
t.Fatalf("failed to serialize xml %s", err)
}
result := string(resultBytes)
expected := `<CpsScmFlowDefinition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition" id="">
expected := `<CpsScmFlowDefinition class="org.jenkinsci.plugins.workflow.cps.CpsScmFlowDefinition">
<scriptPath></scriptPath>
<lightweight>false</lightweight>
</CpsScmFlowDefinition>`
Expand Down
21 changes: 11 additions & 10 deletions client/git_scm.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,26 +15,27 @@ var ErrGitScmExtensionNotFound = errors.New("Could not find git scm extension")
var ErrGitScmUserRemoteConfigNotFound = errors.New("Could not find git scm scm user remote config")

type GitSCM struct {
XMLName xml.Name `xml:"scm"`
Class string `xml:"class,attr"`
XMLName xml.Name `xml:"scm"`
Class string `xml:"class,attr"`
Plugin string `xml:"plugin,attr,omitempty"`

ConfigVersion string `xml:"configVersion"`
UserRemoteConfigs *GitUserRemoteConfigs `xml:"userRemoteConfigs"`
Branches *GitScmBranches `xml:"branches"`

DoGenerateSubmoduleConfigurations bool `xml:"doGenerateSubmoduleConfigurations"`
// submoduleCfg
Extensions *GitScmExtensions `xml:"extensions"`
DoGenerateSubmoduleConfigurations bool `xml:"doGenerateSubmoduleConfigurations"`
SubmoduleCfg *GitScmSubmodulesConfig `xml:"submoduleCfg"`
Extensions *GitScmExtensions `xml:"extensions"`
}

func NewGitScm() *GitSCM {
return &GitSCM{
Class: "hudson.plugins.git.GitSCM",
UserRemoteConfigs: NewGitUserRemoteConfigs(),
Branches: NewGitScmBranches(),
Class: "hudson.plugins.git.GitSCM",

UserRemoteConfigs: NewGitUserRemoteConfigs(),
Branches: NewGitScmBranches(),
DoGenerateSubmoduleConfigurations: false,

Extensions: NewGitScmExtensions(),
Extensions: NewGitScmExtensions(),
}
}

Expand Down
3 changes: 2 additions & 1 deletion client/git_scm_branch_spec.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package client

type GitScmBranchSpec struct {
Id string `xml:"id,attr"`
Id string `xml:"id,attr,omitempty"`

Name string `xml:"name"`
}

Expand Down
2 changes: 1 addition & 1 deletion client/git_scm_clean_before_checkout_extension.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ func init() {

type GitScmCleanBeforeCheckoutExtension struct {
XMLName xml.Name `xml:"hudson.plugins.git.extensions.impl.CleanBeforeCheckout"`
Id string `xml:"id,attr"`
Id string `xml:"id,attr,omitempty"`
}

func NewGitScmCleanBeforeCheckoutExtension() *GitScmCleanBeforeCheckoutExtension {
Expand Down
2 changes: 1 addition & 1 deletion client/git_scm_extensions.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (extensions *GitScmExtensions) Append(extension GitScmExtension) *GitScmExt
func (extensions *GitScmExtensions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var tok xml.Token
var err error
extensions.Items = &[]GitScmExtension{}
*extensions = *NewGitScmExtensions()
for tok, err = d.Token(); err == nil; tok, err = d.Token() {
if elem, ok := tok.(xml.StartElement); ok {
if unmarshalXML, ok := scmExtensionUnmarshalFunc[elem.Name.Local]; ok {
Expand Down
11 changes: 11 additions & 0 deletions client/git_scm_submodules_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package client

type GitScmSubmodulesConfig struct {
Class string `xml:"class,attr"`
}

func NewGitScmSubmodulesConfig() *GitScmSubmodulesConfig {
return &GitScmSubmodulesConfig{
Class: "list",
}
}
2 changes: 2 additions & 0 deletions client/job.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ var ErrJobActionNotFound = errors.New("Could not find job action")
// Job
type Job struct {
Id string
Plugin string
Name string
Disabled bool
Actions *JobActions `xml:"actions"`
Expand Down Expand Up @@ -52,6 +53,7 @@ func newJobFromConfigAndDetails(config *jobConfig, details *jobDetails) *Job {

if config != nil {
job.Id = config.Id
job.Plugin = config.Plugin
job.Actions = config.Actions
job.Disabled = config.Disabled
job.Properties = config.Properties
Expand Down
2 changes: 1 addition & 1 deletion client/job_actions.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (actions *JobActions) Append(action JobAction) *JobActions {
func (actions *JobActions) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var tok xml.Token
var err error
actions.Items = &[]JobAction{}
*actions = *NewJobActions()
for tok, err = d.Token(); err == nil; tok, err = d.Token() {
if elem, ok := tok.(xml.StartElement); ok {
if unmarshalXML, ok := jobActionUnmarshalFunc[elem.Name.Local]; ok {
Expand Down
4 changes: 3 additions & 1 deletion client/job_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,14 @@ type jobConfig struct {
KeepDependencies bool `xml:"keepDependencies"`
Properties *JobProperties `xml:"properties"`
Definition *JobDefinitionXml `xml:"definition"`
Triggers string `xml:"trigger"`
Triggers string `xml:"triggers"`
Disabled bool `xml:"disabled"`
}

func JobConfigFromJob(job *Job) *jobConfig {
return &jobConfig{
Id: job.Id,
Plugin: job.Plugin,
Actions: job.Actions,
Description: job.Description,
KeepDependencies: job.KeepDependencies,
Expand Down
18 changes: 15 additions & 3 deletions client/job_config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (

func TestJobConfigSerialize(t *testing.T) {
job := NewJob()
job.Plugin = "flow-plugin"
job.Description = "my-desc"
job.Actions = job.Actions.Append(NewJobDeclarativeJobAction())
job.Actions = job.Actions.Append(NewJobDeclarativeJobPropertyTrackerAction())
Expand Down Expand Up @@ -72,7 +73,7 @@ func TestJobConfigSerialize(t *testing.T) {
t.Fatalf("failed to serialize xml %s", err)
}
result := string(resultBytes)
expected := `<flow-definition>
expected := `<flow-definition plugin="flow-plugin">
<actions>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction></org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction>
<org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction>
Expand Down Expand Up @@ -112,12 +113,21 @@ func TestJobConfigSerialize(t *testing.T) {
<onNotBuilt>false</onNotBuilt>
</skipVote>
<silentMode>false</silentMode>
<notificationLevel></notificationLevel>
<silentStartMode>false</silentStartMode>
<escapeQuotes>true</escapeQuotes>
<nameAndEmailParameterMode>PLAIN</nameAndEmailParameterMode>
<dependencyJobsNames></dependencyJobsNames>
<commitMessageParameterMode>BASE64</commitMessageParameterMode>
<changeSubjectParameterMode>PLAIN</changeSubjectParameterMode>
<commentTextParameterMode>BASE64</commentTextParameterMode>
<buildStartMessage></buildStartMessage>
<buildFailureMessage></buildFailureMessage>
<buildSuccessfulMessage></buildSuccessfulMessage>
<buildUnstableMessage></buildUnstableMessage>
<buildNotBuiltMessage></buildNotBuiltMessage>
<buildUnsuccessfulFilepath></buildUnsuccessfulFilepath>
<customUrl></customUrl>
<serverName>__ANY__</serverName>
<triggerOnEvents class="linked-list">
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginPatchsetCreatedEvent>
Expand All @@ -130,6 +140,8 @@ func TestJobConfigSerialize(t *testing.T) {
<com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginDraftPublishedEvent></com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.events.PluginDraftPublishedEvent>
</triggerOnEvents>
<dynamicTriggerConfiguration>false</dynamicTriggerConfiguration>
<triggerConfigURL></triggerConfigURL>
<triggerInformationAction></triggerInformationAction>
</com.sonyericsson.hudson.plugins.gerrit.trigger.hudsontrigger.GerritTrigger>
</triggers>
</org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty>
Expand All @@ -153,7 +165,7 @@ func TestJobConfigSerialize(t *testing.T) {
</hudson.plugins.git.UserRemoteConfig>
</userRemoteConfigs>
<branches>
<hudson.plugins.git.BranchSpec id="">
<hudson.plugins.git.BranchSpec>
<name>branchspec</name>
</hudson.plugins.git.BranchSpec>
</branches>
Expand All @@ -165,7 +177,7 @@ func TestJobConfigSerialize(t *testing.T) {
<scriptPath></scriptPath>
<lightweight>false</lightweight>
</definition>
<trigger></trigger>
<triggers></triggers>
<disabled>false</disabled>
</flow-definition>`
if result != expected {
Expand Down
1 change: 1 addition & 0 deletions client/job_declarative_job_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func init() {
type JobDeclarativeJobAction struct {
XMLName xml.Name `xml:"org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobAction"`
Id string `xml:"id,attr,omitempty"`
Plugin string `xml:"plugin,attr,omitempty"`
}

func NewJobDeclarativeJobAction() *JobDeclarativeJobAction {
Expand Down
1 change: 1 addition & 0 deletions client/job_declarative_job_property_tracker_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ func init() {
type JobDeclarativeJobPropertyTrackerAction struct {
XMLName xml.Name `xml:"org.jenkinsci.plugins.pipeline.modeldefinition.actions.DeclarativeJobPropertyTrackerAction"`
Id string `xml:"id,attr,omitempty"`
Plugin string `xml:"plugin,attr,omitempty"`

JobProperties string `xml:"jobProperties"`
Triggers string `xml:"triggers"`
Expand Down
24 changes: 0 additions & 24 deletions client/job_definition_test.go

This file was deleted.

44 changes: 22 additions & 22 deletions client/job_gerrit_trigger.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,31 +20,31 @@ type JobGerritTrigger struct {
Id string `xml:"id,attr,omitempty"`
Plugin string `xml:"plugin,attr,omitempty"`

Spec string `xml:"spec"`
Projects *JobGerritTriggerProjects `xml:"gerritProjects"`
DynamicGerritProjects *DynamicGerritProjects `xml:"dynamicGerritProjects"`
SkipVote *JobGerritTriggerSkipVote `xml:"skipVote"`
SilentMode bool `xml:"silentMode"`
// notificationLevel
SilentStartMode bool `xml:"silentStartMode"`
EscapeQuotes bool `xml:"escapeQuotes"`
NameAndEmailParameterMode ParameterMode `xml:"nameAndEmailParameterMode"`
// dependencyJobsNames
CommitMessageParameterMode ParameterMode `xml:"commitMessageParameterMode"`
ChangeSubjectParameterMode ParameterMode `xml:"changeSubjectParameterMode"`
CommentTextParameterMode ParameterMode `xml:"commentTextParameterMode"`
// buildStartMessage
// buildFailureMessage
// buildSuccessfulMessage
// buildUnstableMessage
// buildNotBuiltMessage
// buildUnsuccessfulFilepath
// customUrl
Spec string `xml:"spec"`
Projects *JobGerritTriggerProjects `xml:"gerritProjects"`
DynamicGerritProjects *DynamicGerritProjects `xml:"dynamicGerritProjects"`
SkipVote *JobGerritTriggerSkipVote `xml:"skipVote"`
SilentMode bool `xml:"silentMode"`
NotificationLevel string `xml:"notificationLevel"`
SilentStartMode bool `xml:"silentStartMode"`
EscapeQuotes bool `xml:"escapeQuotes"`
NameAndEmailParameterMode ParameterMode `xml:"nameAndEmailParameterMode"`
DependencyJobsNames string `xml:"dependencyJobsNames"`
CommitMessageParameterMode ParameterMode `xml:"commitMessageParameterMode"`
ChangeSubjectParameterMode ParameterMode `xml:"changeSubjectParameterMode"`
CommentTextParameterMode ParameterMode `xml:"commentTextParameterMode"`
BuildStartMessage string `xml:"buildStartMessage"`
BuildFailureMessage string `xml:"buildFailureMessage"`
BuildSuccessfulMessage string `xml:"buildSuccessfulMessage"`
BuildUnstableMessage string `xml:"buildUnstableMessage"`
BuildNotBuiltMessage string `xml:"buildNotBuiltMessage"`
BuildUnsuccessfulFilepath string `xml:"buildUnsuccessfulFilepath"`
CustomUrl string `xml:"customUrl"`
ServerName string `xml:"serverName"`
TriggerOnEvents *JobGerritTriggerOnEvents `xml:"triggerOnEvents"`
DynamicTriggerConfiguration bool `xml:"dynamicTriggerConfiguration"`
// triggerConfigURL
// triggerInformationAction
TriggerConfigURL string `xml:"triggerConfigURL"`
TriggerInformationAction string `xml:"triggerInformationAction"`
}

func NewJobGerritTrigger() *JobGerritTrigger {
Expand Down
12 changes: 6 additions & 6 deletions client/job_gerrit_trigger_on_events.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ type jobGerritTriggerOnEventsUnmarshaler func(*xml.Decoder, xml.StartElement) (J
var jobGerritTriggerOnEventsUnmarshalFunc = map[string]jobGerritTriggerOnEventsUnmarshaler{}

type JobGerritTriggerOnEvents struct {
XMLName xml.Name `xml:"triggerOnEvents"`
LinkedList string `xml:"class,attr"`
Items *[]JobGerritTriggerOnEvent
XMLName xml.Name `xml:"triggerOnEvents"`
Class string `xml:"class,attr"`
Items *[]JobGerritTriggerOnEvent
}

func NewJobGerritTriggerOnEvents() *JobGerritTriggerOnEvents {
return &JobGerritTriggerOnEvents{
LinkedList: "linked-list",
Items: &[]JobGerritTriggerOnEvent{},
Class: "linked-list",
Items: &[]JobGerritTriggerOnEvent{},
}
}

Expand All @@ -32,7 +32,7 @@ func (events *JobGerritTriggerOnEvents) Append(event JobGerritTriggerOnEvent) *J
func (events *JobGerritTriggerOnEvents) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var tok xml.Token
var err error
events.Items = &[]JobGerritTriggerOnEvent{}
*events = *NewJobGerritTriggerOnEvents()
for tok, err = d.Token(); err == nil; tok, err = d.Token() {
if elem, ok := tok.(xml.StartElement); ok {
if unmarshalXML, ok := jobGerritTriggerOnEventsUnmarshalFunc[elem.Name.Local]; ok {
Expand Down
32 changes: 32 additions & 0 deletions client/job_jira_project_property.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package client

import (
"encoding/xml"
)

func init() {
propertyUnmarshalFunc["hudson.plugins.jira.JiraProjectProperty"] = unmarshalJobJiraProjectProperty
}

type JobJiraProjectProperty struct {
XMLName xml.Name `xml:"hudson.plugins.jira.JiraProjectProperty"`
Id string `xml:"id,attr,omitempty"`
Plugin string `xml:"plugin,attr,omitempty"`
}

func NewJobJiraProjectProperty() *JobJiraProjectProperty {
return &JobJiraProjectProperty{}
}

func (property *JobJiraProjectProperty) GetId() string {
return property.Id
}

func unmarshalJobJiraProjectProperty(d *xml.Decoder, start xml.StartElement) (JobProperty, error) {
property := NewJobJiraProjectProperty()
err := d.DecodeElement(property, &start)
if err != nil {
return nil, err
}
return property, nil
}
2 changes: 1 addition & 1 deletion client/job_pipeline_triggers_property.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ var ErrJobTriggerNotFound = errors.New("Could not find job pipeline trigger")

type JobPipelineTriggersProperty struct {
XMLName xml.Name `xml:"org.jenkinsci.plugins.workflow.job.properties.PipelineTriggersJobProperty"`
Id string `xml:"id,attr"`
Id string `xml:"id,attr,omitempty"`
Triggers *JobTriggers `xml:"triggers"`
}

Expand Down
2 changes: 1 addition & 1 deletion client/job_properties.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (properties *JobProperties) Append(property JobProperty) *JobProperties {
func (properties *JobProperties) UnmarshalXML(d *xml.Decoder, start xml.StartElement) error {
var tok xml.Token
var err error
properties.Items = &[]JobProperty{}
*properties = *NewJobProperties()
for tok, err = d.Token(); err == nil; tok, err = d.Token() {
if elem, ok := tok.(xml.StartElement); ok {
if unmarshalXML, ok := propertyUnmarshalFunc[elem.Name.Local]; ok {
Expand Down
Loading

0 comments on commit e80be59

Please sign in to comment.