omitempty

This commit is contained in:
runzexia
2019-04-28 11:49:52 +08:00
parent b448a8ca95
commit 04fc601d0e
4 changed files with 53 additions and 67 deletions

View File

@@ -34,12 +34,12 @@ const (
type DevOpsProject struct {
ProjectId string `json:"project_id" db:"project_id"`
Name string `json:"name"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
Creator string `json:"creator"`
CreateTime time.Time `json:"create_time"`
Status string `json:"status"`
Visibility string `json:"visibility"`
Extra string `json:"extra"`
Visibility string `json:"visibility,omitempty"`
Extra string `json:"extra,omitempty"`
Workspace string `json:"workspace"`
}

View File

@@ -28,7 +28,7 @@ const (
type JenkinsCredential struct {
Id string `json:"id"`
Type string `json:"type"`
DisplayName string `json:"display_name"`
DisplayName string `json:"display_name,omitempty"`
Fingerprint *struct {
FileName string `json:"file_name,omitempty"`
Hash string `json:"hash,omitempty"`
@@ -36,55 +36,47 @@ type JenkinsCredential struct {
Name string `json:"name,omitempty"`
Ranges struct {
Ranges []*struct {
Start int `json:"start"`
End int `json:"end"`
} `json:"ranges"`
} `json:"ranges"`
Start int `json:"start,omitempty"`
End int `json:"end,omitempty"`
} `json:"ranges,omitempty"`
} `json:"ranges,omitempty"`
} `json:"usage,omitempty"`
} `json:"fingerprint,omitempty"`
Description string `json:"description"`
Domain string `json:"domain"`
Description string `json:"description,omitempty"`
Domain string `json:"domain,omitempty"`
CreateTime *time.Time `json:"create_time,omitempty"`
Creator string `json:"creator,omitempty"`
UsernamePasswordCredential *UsernamePasswordCredential `json:"username_password"`
SshCredential *SshCredential `json:"ssh"`
SecretTextCredential *SecretTextCredential `json:"secret_text"`
KubeconfigCredential *KubeconfigCredential `json:"kubeconfig"`
UsernamePasswordCredential *UsernamePasswordCredential `json:"username_password,omitempty"`
SshCredential *SshCredential `json:"ssh,omitempty"`
SecretTextCredential *SecretTextCredential `json:"secret_text,omitempty"`
KubeconfigCredential *KubeconfigCredential `json:"kubeconfig,omitempty"`
}
type UsernamePasswordCredential struct {
Id string `json:"id"`
Username string `json:"username"`
Username string `json:"username,omitempty"`
Password string `json:"password,omitempty"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
}
type SshCredential struct {
Id string `json:"id"`
Username string `json:"username"`
Passphrase string `json:"passphrase"`
PrivateKey string `json:"private_key" mapstructure:"private_key"`
Description string `json:"description"`
Username string `json:"username,omitempty"`
Passphrase string `json:"passphrase,omitempty"`
PrivateKey string `json:"private_key,omitempty" mapstructure:"private_key"`
Description string `json:"description,omitempty"`
}
type SecretTextCredential struct {
Id string `json:"id"`
Secret string `json:"secret"`
Description string `json:"description"`
Secret string `json:"secret,omitempty"`
Description string `json:"description,omitempty"`
}
type KubeconfigCredential struct {
Id string `json:"id"`
Content string `json:"content"`
Description string `json:"description"`
}
type DeleteCredentialRequest struct {
Domain string `json:"domain"`
}
type CopySshCredentialRequest struct {
Id string `json:"id"`
Content string `json:"content,omitempty"`
Description string `json:"description,omitempty"`
}
const (

View File

@@ -106,17 +106,18 @@ func AddProjectMember(projectId, operator string, member *DevOpsProjectMembershi
Where(db.And(
db.Eq(DevOpsProjectMembershipUsernameColumn, member.Username),
db.Eq(DevOpsProjectMembershipProjectIdColumn, projectId))).LoadOne(membership)
if err != nil && err != db.ErrNotFound {
glog.Errorf("%+v", err)
return nil, restful.NewError(http.StatusInternalServerError, err.Error())
}
// if user could be founded in db, user have been added to project
if err != db.ErrNotFound {
if err == nil {
err = fmt.Errorf("user [%s] have been added to project", member.Username)
glog.Errorf("%+v", err)
return nil, restful.NewError(http.StatusBadRequest, err.Error())
}
if err != nil && err != db.ErrNotFound {
glog.Errorf("%+v", err)
return nil, restful.NewError(http.StatusInternalServerError, err.Error())
}
globalRole, err := jenkinsClinet.GetGlobalRole(JenkinsAllUserRoleName)
if err != nil {
glog.Errorf("%+v", err)

View File

@@ -54,31 +54,31 @@ type SonarStatus struct {
type ProjectPipeline struct {
Type string `json:"type"`
Pipeline *NoScmPipeline `json:"pipeline"`
MultiBranchPipeline *MultiBranchPipeline `json:"multi_branch_pipeline"`
Pipeline *NoScmPipeline `json:"pipeline,omitempty"`
MultiBranchPipeline *MultiBranchPipeline `json:"multi_branch_pipeline,omitempty"`
}
type NoScmPipeline struct {
Name string `json:"name"`
Description string `json:"description"`
Discarder *DiscarderProperty `json:"discarder"`
Parameters []*Parameter `json:"parameters"`
DisableConcurrent bool `json:"disable_concurrent" mapstructure:"disable_concurrent"`
TimerTrigger *TimerTrigger `json:"timer_trigger" mapstructure:"timer_trigger"`
RemoteTrigger *RemoteTrigger `json:"remote_trigger" mapstructure:"remote_trigger"`
Jenkinsfile string `json:"jenkinsfile"`
Description string `json:"descriptio,omitempty"`
Discarder *DiscarderProperty `json:"discarder,omitempty"`
Parameters []*Parameter `json:"parameters,omitempty"`
DisableConcurrent bool `json:"disable_concurrent,omitempty" mapstructure:"disable_concurrent"`
TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger"`
RemoteTrigger *RemoteTrigger `json:"remote_trigger,omitempty" mapstructure:"remote_trigger"`
Jenkinsfile string `json:"jenkinsfile,omitempty"`
}
type MultiBranchPipeline struct {
Name string `json:"name"`
Description string `json:"description"`
Discarder *DiscarderProperty `json:"discarder"`
TimerTrigger *TimerTrigger `json:"timer_trigger" mapstructure:"timer_trigger"`
Description string `json:"description,omitempty"`
Discarder *DiscarderProperty `json:"discarder,omitempty"`
TimerTrigger *TimerTrigger `json:"timer_trigger,omitempty" mapstructure:"timer_trigger"`
SourceType string `json:"source_type"`
GitSource *GitSource `json:"git_source"`
GitHubSource *GithubSource `json:"github_source"`
SvnSource *SvnSource `json:"svn_source"`
SingleSvnSource *SingleSvnSource `json:"single_svn_source"`
GitSource *GitSource `json:"git_source,omitempty"`
GitHubSource *GithubSource `json:"github_source,omitempty"`
SvnSource *SvnSource `json:"svn_source,omitempty"`
SingleSvnSource *SingleSvnSource `json:"single_svn_source,omitempty"`
ScriptPath string `json:"script_path" mapstructure:"script_path"`
}
@@ -103,7 +103,7 @@ type GithubSource struct {
}
type GitCloneOption struct {
Shallow bool `json:"shallow" mapstructure:"shallow"`
Shallow bool `json:"shallow,omitempty" mapstructure:"shallow"`
Timeout int `json:"timeout,omitempty" mapstructure:"timeout"`
Depth int `json:"depth,omitempty" mapstructure:"depth"`
}
@@ -119,28 +119,21 @@ type SingleSvnSource struct {
CredentialId string `json:"credential_id,omitempty" mapstructure:"credential_id"`
}
type ScmInfo struct {
Type string `json:"type"`
Repo string `json:"repo"`
ApiUri string `json:"api_uri,omitempty"`
Path string `json:"path"`
}
type GithubDiscoverPRFromForks struct {
Strategy int `json:"strategy" mapstructure:"strategy"`
Trust int `json:"trust" mapstructure:"trust"`
Strategy int `json:"strategy,omitempty" mapstructure:"strategy"`
Trust int `json:"trust,omitempty" mapstructure:"trust"`
}
type DiscarderProperty struct {
DaysToKeep string `json:"days_to_keep" mapstructure:"days_to_keep"`
NumToKeep string `json:"num_to_keep" mapstructure:"num_to_keep"`
DaysToKeep string `json:"days_to_keep,omitempty" mapstructure:"days_to_keep"`
NumToKeep string `json:"num_to_keep,omitempty" mapstructure:"num_to_keep"`
}
type Parameter struct {
Name string `json:"name"`
DefaultValue string `json:"default_value,omitempty" mapstructure:"default_value"`
Type string `json:"type"`
Description string `json:"description"`
Description string `json:"description,omitempty"`
}
type TimerTrigger struct {
@@ -152,7 +145,7 @@ type TimerTrigger struct {
}
type RemoteTrigger struct {
Token string `json:"token"`
Token string `json:"token,omitempty"`
}
func replaceXmlVersion(config, oldVersion, targetVersion string) string {