Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
水淹萌龙
kubesphere
提交
0b4ed3f8
K
kubesphere
项目概览
水淹萌龙
/
kubesphere
与 Fork 源项目一致
Fork自
KubeSphere / kubesphere
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
K
kubesphere
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
0b4ed3f8
编写于
12月 03, 2020
作者:
LinuxSuRen
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix ks-controller panic due to missing nil checking in mutli-branch pipeline
Signed-off-by:
rick
<
rick@jenkins-zh.cn
>
上级
e16219be
变更
9
展开全部
隐藏空白更改
内联
并排
Showing
9 changed file
with
648 addition
and
506 deletion
+648
-506
pkg/simple/client/devops/jenkins/internal/bitbucket.go
pkg/simple/client/devops/jenkins/internal/bitbucket.go
+156
-0
pkg/simple/client/devops/jenkins/internal/common_test.go
pkg/simple/client/devops/jenkins/internal/common_test.go
+14
-0
pkg/simple/client/devops/jenkins/internal/git.go
pkg/simple/client/devops/jenkins/internal/git.go
+98
-0
pkg/simple/client/devops/jenkins/internal/github.go
pkg/simple/client/devops/jenkins/internal/github.go
+142
-0
pkg/simple/client/devops/jenkins/internal/gitlab.go
pkg/simple/client/devops/jenkins/internal/gitlab.go
+14
-27
pkg/simple/client/devops/jenkins/internal/pull_request.go
pkg/simple/client/devops/jenkins/internal/pull_request.go
+79
-0
pkg/simple/client/devops/jenkins/internal/pull_request_test.go
...imple/client/devops/jenkins/internal/pull_request_test.go
+28
-0
pkg/simple/client/devops/jenkins/internal/svn.go
pkg/simple/client/devops/jenkins/internal/svn.go
+107
-0
pkg/simple/client/devops/jenkins/pipeline_internal.go
pkg/simple/client/devops/jenkins/pipeline_internal.go
+10
-479
未找到文件。
pkg/simple/client/devops/jenkins/internal/bitbucket.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
(
"github.com/beevik/etree"
"k8s.io/klog"
"strconv"
"strings"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
)
func
AppendBitbucketServerSourceToEtree
(
source
*
etree
.
Element
,
gitSource
*
devopsv1alpha3
.
BitbucketServerSource
)
{
if
gitSource
==
nil
{
klog
.
Warning
(
"please provide BitbucketServer source when the sourceType is BitbucketServer"
)
return
}
source
.
CreateAttr
(
"class"
,
"com.cloudbees.jenkins.plugins.bitbucket.BitbucketSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"cloudbees-bitbucket-branch-source"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
gitSource
.
ScmId
)
source
.
CreateElement
(
"credentialsId"
)
.
SetText
(
gitSource
.
CredentialId
)
source
.
CreateElement
(
"repoOwner"
)
.
SetText
(
gitSource
.
Owner
)
source
.
CreateElement
(
"repository"
)
.
SetText
(
gitSource
.
Repo
)
source
.
CreateElement
(
"serverUrl"
)
.
SetText
(
gitSource
.
ApiUri
)
traits
:=
source
.
CreateElement
(
"traits"
)
if
gitSource
.
DiscoverBranches
!=
0
{
traits
.
CreateElement
(
"com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait>"
)
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
DiscoverBranches
))
}
if
gitSource
.
DiscoverPRFromOrigin
!=
0
{
traits
.
CreateElement
(
"com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait"
)
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
DiscoverPRFromOrigin
))
}
if
gitSource
.
DiscoverPRFromForks
!=
nil
{
forkTrait
:=
traits
.
CreateElement
(
"com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait"
)
forkTrait
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
DiscoverPRFromForks
.
Strategy
))
trustClass
:=
"com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait$"
switch
gitSource
.
DiscoverPRFromForks
.
Trust
{
case
1
:
trustClass
+=
"TrustEveryone"
case
2
:
trustClass
+=
"TrustTeamForks"
case
3
:
trustClass
+=
"TrustNobody"
default
:
trustClass
+=
"TrustEveryone"
}
forkTrait
.
CreateElement
(
"trust"
)
.
CreateAttr
(
"class"
,
trustClass
)
}
if
gitSource
.
DiscoverTags
{
traits
.
CreateElement
(
"com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait"
)
}
if
gitSource
.
CloneOption
!=
nil
{
cloneExtension
:=
traits
.
CreateElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
)
.
CreateElement
(
"extension"
)
cloneExtension
.
CreateAttr
(
"class"
,
"hudson.plugins.git.extensions.impl.CloneOption"
)
cloneExtension
.
CreateElement
(
"shallow"
)
.
SetText
(
strconv
.
FormatBool
(
gitSource
.
CloneOption
.
Shallow
))
cloneExtension
.
CreateElement
(
"noTags"
)
.
SetText
(
strconv
.
FormatBool
(
false
))
cloneExtension
.
CreateElement
(
"honorRefspec"
)
.
SetText
(
strconv
.
FormatBool
(
true
))
cloneExtension
.
CreateElement
(
"reference"
)
if
gitSource
.
CloneOption
.
Timeout
>=
0
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
CloneOption
.
Timeout
))
}
else
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
10
))
}
if
gitSource
.
CloneOption
.
Depth
>=
0
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
CloneOption
.
Depth
))
}
else
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
1
))
}
}
if
gitSource
.
RegexFilter
!=
""
{
regexTraits
:=
traits
.
CreateElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
)
regexTraits
.
CreateAttr
(
"plugin"
,
"scm-api@2.4.0"
)
regexTraits
.
CreateElement
(
"regex"
)
.
SetText
(
gitSource
.
RegexFilter
)
}
return
}
func
GetBitbucketServerSourceFromEtree
(
source
*
etree
.
Element
)
*
devopsv1alpha3
.
BitbucketServerSource
{
var
s
devopsv1alpha3
.
BitbucketServerSource
if
credential
:=
source
.
SelectElement
(
"credentialsId"
);
credential
!=
nil
{
s
.
CredentialId
=
credential
.
Text
()
}
if
repoOwner
:=
source
.
SelectElement
(
"repoOwner"
);
repoOwner
!=
nil
{
s
.
Owner
=
repoOwner
.
Text
()
}
if
repository
:=
source
.
SelectElement
(
"repository"
);
repository
!=
nil
{
s
.
Repo
=
repository
.
Text
()
}
if
apiUri
:=
source
.
SelectElement
(
"serverUrl"
);
apiUri
!=
nil
{
s
.
ApiUri
=
apiUri
.
Text
()
}
traits
:=
source
.
SelectElement
(
"traits"
)
if
branchDiscoverTrait
:=
traits
.
SelectElement
(
"com.cloudbees.jenkins.plugins.bitbucket.BranchDiscoveryTrait"
);
branchDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
branchDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
s
.
DiscoverBranches
=
strategyId
}
if
tagDiscoverTrait
:=
traits
.
SelectElement
(
"com.cloudbees.jenkins.plugins.bitbucket.TagDiscoveryTrait"
);
tagDiscoverTrait
!=
nil
{
s
.
DiscoverTags
=
true
}
if
originPRDiscoverTrait
:=
traits
.
SelectElement
(
"com.cloudbees.jenkins.plugins.bitbucket.OriginPullRequestDiscoveryTrait"
);
originPRDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
originPRDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
s
.
DiscoverPRFromOrigin
=
strategyId
}
if
forkPRDiscoverTrait
:=
traits
.
SelectElement
(
"com.cloudbees.jenkins.plugins.bitbucket.ForkPullRequestDiscoveryTrait"
);
forkPRDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
forkPRDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
trustClass
:=
forkPRDiscoverTrait
.
SelectElement
(
"trust"
)
.
SelectAttr
(
"class"
)
.
Value
trust
:=
strings
.
Split
(
trustClass
,
"$"
)
switch
trust
[
1
]
{
case
"TrustEveryone"
:
s
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
1
,
}
case
"TrustTeamForks"
:
s
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
2
,
}
case
"TrustNobody"
:
s
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
3
,
}
}
if
cloneTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
);
cloneTrait
!=
nil
{
if
cloneExtension
:=
cloneTrait
.
SelectElement
(
"extension"
);
cloneExtension
!=
nil
{
s
.
CloneOption
=
&
devopsv1alpha3
.
GitCloneOption
{}
if
value
,
err
:=
strconv
.
ParseBool
(
cloneExtension
.
SelectElement
(
"shallow"
)
.
Text
());
err
==
nil
{
s
.
CloneOption
.
Shallow
=
value
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"timeout"
)
.
Text
(),
10
,
32
);
err
==
nil
{
s
.
CloneOption
.
Timeout
=
int
(
value
)
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"depth"
)
.
Text
(),
10
,
32
);
err
==
nil
{
s
.
CloneOption
.
Depth
=
int
(
value
)
}
}
}
if
regexTrait
:=
traits
.
SelectElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
);
regexTrait
!=
nil
{
if
regex
:=
regexTrait
.
SelectElement
(
"regex"
);
regex
!=
nil
{
s
.
RegexFilter
=
regex
.
Text
()
}
}
}
return
&
s
}
pkg/simple/client/devops/jenkins/internal/common_test.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
"testing"
func
TestCommonSituation
(
t
*
testing
.
T
)
{
// make sure these functions do not panic
// I add these test cases because it's possible that users just do give the git source
AppendGitlabSourceToEtree
(
nil
,
nil
)
AppendGithubSourceToEtree
(
nil
,
nil
)
AppendBitbucketServerSourceToEtree
(
nil
,
nil
)
AppendGitSourceToEtree
(
nil
,
nil
)
AppendSingleSvnSourceToEtree
(
nil
,
nil
)
AppendSvnSourceToEtree
(
nil
,
nil
)
}
pkg/simple/client/devops/jenkins/internal/git.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
(
"github.com/beevik/etree"
"k8s.io/klog"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
"strconv"
)
func
AppendGitSourceToEtree
(
source
*
etree
.
Element
,
gitSource
*
devopsv1alpha3
.
GitSource
)
{
if
gitSource
==
nil
{
klog
.
Warning
(
"please provide Git source when the sourceType is Git"
)
return
}
source
.
CreateAttr
(
"class"
,
"jenkins.plugins.git.GitSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"git"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
gitSource
.
ScmId
)
source
.
CreateElement
(
"remote"
)
.
SetText
(
gitSource
.
Url
)
if
gitSource
.
CredentialId
!=
""
{
source
.
CreateElement
(
"credentialsId"
)
.
SetText
(
gitSource
.
CredentialId
)
}
traits
:=
source
.
CreateElement
(
"traits"
)
if
gitSource
.
DiscoverBranches
{
traits
.
CreateElement
(
"jenkins.plugins.git.traits.BranchDiscoveryTrait"
)
}
if
gitSource
.
DiscoverTags
{
traits
.
CreateElement
(
"jenkins.plugins.git.traits.TagDiscoveryTrait"
)
}
if
gitSource
.
CloneOption
!=
nil
{
cloneExtension
:=
traits
.
CreateElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
)
.
CreateElement
(
"extension"
)
cloneExtension
.
CreateAttr
(
"class"
,
"hudson.plugins.git.extensions.impl.CloneOption"
)
cloneExtension
.
CreateElement
(
"shallow"
)
.
SetText
(
strconv
.
FormatBool
(
gitSource
.
CloneOption
.
Shallow
))
cloneExtension
.
CreateElement
(
"noTags"
)
.
SetText
(
strconv
.
FormatBool
(
false
))
cloneExtension
.
CreateElement
(
"honorRefspec"
)
.
SetText
(
strconv
.
FormatBool
(
true
))
cloneExtension
.
CreateElement
(
"reference"
)
if
gitSource
.
CloneOption
.
Timeout
>=
0
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
CloneOption
.
Timeout
))
}
else
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
10
))
}
if
gitSource
.
CloneOption
.
Depth
>=
0
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
CloneOption
.
Depth
))
}
else
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
1
))
}
}
if
gitSource
.
RegexFilter
!=
""
{
regexTraits
:=
traits
.
CreateElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
)
regexTraits
.
CreateAttr
(
"plugin"
,
"scm-api@2.4.0"
)
regexTraits
.
CreateElement
(
"regex"
)
.
SetText
(
gitSource
.
RegexFilter
)
}
return
}
func
GetGitSourcefromEtree
(
source
*
etree
.
Element
)
*
devopsv1alpha3
.
GitSource
{
var
gitSource
devopsv1alpha3
.
GitSource
if
credential
:=
source
.
SelectElement
(
"credentialsId"
);
credential
!=
nil
{
gitSource
.
CredentialId
=
credential
.
Text
()
}
if
remote
:=
source
.
SelectElement
(
"remote"
);
remote
!=
nil
{
gitSource
.
Url
=
remote
.
Text
()
}
traits
:=
source
.
SelectElement
(
"traits"
)
if
branchDiscoverTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.BranchDiscoveryTrait"
);
branchDiscoverTrait
!=
nil
{
gitSource
.
DiscoverBranches
=
true
}
if
tagDiscoverTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.TagDiscoveryTrait"
);
tagDiscoverTrait
!=
nil
{
gitSource
.
DiscoverTags
=
true
}
if
cloneTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
);
cloneTrait
!=
nil
{
if
cloneExtension
:=
cloneTrait
.
SelectElement
(
"extension"
);
cloneExtension
!=
nil
{
gitSource
.
CloneOption
=
&
devopsv1alpha3
.
GitCloneOption
{}
if
value
,
err
:=
strconv
.
ParseBool
(
cloneExtension
.
SelectElement
(
"shallow"
)
.
Text
());
err
==
nil
{
gitSource
.
CloneOption
.
Shallow
=
value
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"timeout"
)
.
Text
(),
10
,
32
);
err
==
nil
{
gitSource
.
CloneOption
.
Timeout
=
int
(
value
)
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"depth"
)
.
Text
(),
10
,
32
);
err
==
nil
{
gitSource
.
CloneOption
.
Depth
=
int
(
value
)
}
}
}
if
regexTrait
:=
traits
.
SelectElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
);
regexTrait
!=
nil
{
if
regex
:=
regexTrait
.
SelectElement
(
"regex"
);
regex
!=
nil
{
gitSource
.
RegexFilter
=
regex
.
Text
()
}
}
return
&
gitSource
}
pkg/simple/client/devops/jenkins/internal/github.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
(
"github.com/beevik/etree"
"k8s.io/klog"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
"strconv"
"strings"
)
func
AppendGithubSourceToEtree
(
source
*
etree
.
Element
,
githubSource
*
devopsv1alpha3
.
GithubSource
)
{
if
githubSource
==
nil
{
klog
.
Warning
(
"please provide GitHub source when the sourceType is GitHub"
)
return
}
source
.
CreateAttr
(
"class"
,
"org.jenkinsci.plugins.github_branch_source.GitHubSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"github-branch-source"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
githubSource
.
ScmId
)
source
.
CreateElement
(
"credentialsId"
)
.
SetText
(
githubSource
.
CredentialId
)
source
.
CreateElement
(
"repoOwner"
)
.
SetText
(
githubSource
.
Owner
)
source
.
CreateElement
(
"repository"
)
.
SetText
(
githubSource
.
Repo
)
if
githubSource
.
ApiUri
!=
""
{
source
.
CreateElement
(
"apiUri"
)
.
SetText
(
githubSource
.
ApiUri
)
}
traits
:=
source
.
CreateElement
(
"traits"
)
if
githubSource
.
DiscoverBranches
!=
0
{
traits
.
CreateElement
(
"org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait"
)
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
githubSource
.
DiscoverBranches
))
}
if
githubSource
.
DiscoverPRFromOrigin
!=
0
{
traits
.
CreateElement
(
"org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait"
)
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
githubSource
.
DiscoverPRFromOrigin
))
}
if
githubSource
.
DiscoverPRFromForks
!=
nil
{
forkTrait
:=
traits
.
CreateElement
(
"org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait"
)
forkTrait
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
githubSource
.
DiscoverPRFromForks
.
Strategy
))
trustClass
:=
"org.jenkinsci.plugins.github_branch_source.ForkPullRequestDiscoveryTrait$"
if
prTrust
:=
GitHubPRDiscoverTrust
(
githubSource
.
DiscoverPRFromForks
.
Trust
);
prTrust
.
IsValid
()
{
trustClass
+=
prTrust
.
String
()
}
else
{
klog
.
Warningf
(
"invalid GitHub discover PR trust value: %d"
,
prTrust
.
Value
())
}
forkTrait
.
CreateElement
(
"trust"
)
.
CreateAttr
(
"class"
,
trustClass
)
}
if
githubSource
.
DiscoverTags
{
traits
.
CreateElement
(
"org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait"
)
}
if
githubSource
.
CloneOption
!=
nil
{
cloneExtension
:=
traits
.
CreateElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
)
.
CreateElement
(
"extension"
)
cloneExtension
.
CreateAttr
(
"class"
,
"hudson.plugins.git.extensions.impl.CloneOption"
)
cloneExtension
.
CreateElement
(
"shallow"
)
.
SetText
(
strconv
.
FormatBool
(
githubSource
.
CloneOption
.
Shallow
))
cloneExtension
.
CreateElement
(
"noTags"
)
.
SetText
(
strconv
.
FormatBool
(
false
))
cloneExtension
.
CreateElement
(
"honorRefspec"
)
.
SetText
(
strconv
.
FormatBool
(
true
))
cloneExtension
.
CreateElement
(
"reference"
)
if
githubSource
.
CloneOption
.
Timeout
>=
0
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
githubSource
.
CloneOption
.
Timeout
))
}
else
{
cloneExtension
.
CreateElement
(
"timeout"
)
.
SetText
(
strconv
.
Itoa
(
10
))
}
if
githubSource
.
CloneOption
.
Depth
>=
0
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
githubSource
.
CloneOption
.
Depth
))
}
else
{
cloneExtension
.
CreateElement
(
"depth"
)
.
SetText
(
strconv
.
Itoa
(
1
))
}
}
if
githubSource
.
RegexFilter
!=
""
{
regexTraits
:=
traits
.
CreateElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
)
regexTraits
.
CreateAttr
(
"plugin"
,
"scm-api@2.4.0"
)
regexTraits
.
CreateElement
(
"regex"
)
.
SetText
(
githubSource
.
RegexFilter
)
}
return
}
func
GetGithubSourcefromEtree
(
source
*
etree
.
Element
)
*
devopsv1alpha3
.
GithubSource
{
var
githubSource
devopsv1alpha3
.
GithubSource
if
credential
:=
source
.
SelectElement
(
"credentialsId"
);
credential
!=
nil
{
githubSource
.
CredentialId
=
credential
.
Text
()
}
if
repoOwner
:=
source
.
SelectElement
(
"repoOwner"
);
repoOwner
!=
nil
{
githubSource
.
Owner
=
repoOwner
.
Text
()
}
if
repository
:=
source
.
SelectElement
(
"repository"
);
repository
!=
nil
{
githubSource
.
Repo
=
repository
.
Text
()
}
if
apiUri
:=
source
.
SelectElement
(
"apiUri"
);
apiUri
!=
nil
{
githubSource
.
ApiUri
=
apiUri
.
Text
()
}
traits
:=
source
.
SelectElement
(
"traits"
)
if
branchDiscoverTrait
:=
traits
.
SelectElement
(
"org.jenkinsci.plugins.github__branch__source.BranchDiscoveryTrait"
);
branchDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
branchDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
githubSource
.
DiscoverBranches
=
strategyId
}
if
tagDiscoverTrait
:=
traits
.
SelectElement
(
"org.jenkinsci.plugins.github__branch__source.TagDiscoveryTrait"
);
tagDiscoverTrait
!=
nil
{
githubSource
.
DiscoverTags
=
true
}
if
originPRDiscoverTrait
:=
traits
.
SelectElement
(
"org.jenkinsci.plugins.github__branch__source.OriginPullRequestDiscoveryTrait"
);
originPRDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
originPRDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
githubSource
.
DiscoverPRFromOrigin
=
strategyId
}
if
forkPRDiscoverTrait
:=
traits
.
SelectElement
(
"org.jenkinsci.plugins.github__branch__source.ForkPullRequestDiscoveryTrait"
);
forkPRDiscoverTrait
!=
nil
{
strategyId
,
_
:=
strconv
.
Atoi
(
forkPRDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
trustClass
:=
forkPRDiscoverTrait
.
SelectElement
(
"trust"
)
.
SelectAttr
(
"class"
)
.
Value
trust
:=
strings
.
Split
(
trustClass
,
"$"
)
if
prTrust
:=
GitHubPRDiscoverTrust
(
1
)
.
ParseFromString
(
trust
[
1
]);
prTrust
.
IsValid
()
{
githubSource
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
prTrust
.
Value
(),
}
}
else
{
klog
.
Warningf
(
"invalid Gitlab discover PR trust value: %s"
,
trust
[
1
])
}
if
cloneTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
);
cloneTrait
!=
nil
{
if
cloneExtension
:=
cloneTrait
.
SelectElement
(
"extension"
);
cloneExtension
!=
nil
{
githubSource
.
CloneOption
=
&
devopsv1alpha3
.
GitCloneOption
{}
if
value
,
err
:=
strconv
.
ParseBool
(
cloneExtension
.
SelectElement
(
"shallow"
)
.
Text
());
err
==
nil
{
githubSource
.
CloneOption
.
Shallow
=
value
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"timeout"
)
.
Text
(),
10
,
32
);
err
==
nil
{
githubSource
.
CloneOption
.
Timeout
=
int
(
value
)
}
if
value
,
err
:=
strconv
.
ParseInt
(
cloneExtension
.
SelectElement
(
"depth"
)
.
Text
(),
10
,
32
);
err
==
nil
{
githubSource
.
CloneOption
.
Depth
=
int
(
value
)
}
}
}
if
regexTrait
:=
traits
.
SelectElement
(
"jenkins.scm.impl.trait.RegexSCMHeadFilterTrait"
);
regexTrait
!=
nil
{
if
regex
:=
regexTrait
.
SelectElement
(
"regex"
);
regex
!=
nil
{
githubSource
.
RegexFilter
=
regex
.
Text
()
}
}
}
return
&
githubSource
}
pkg/simple/client/devops/jenkins/internal/gitlab.go
浏览文件 @
0b4ed3f8
...
...
@@ -2,12 +2,17 @@ package internal
import
(
"github.com/beevik/etree"
"k8s.io/klog"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
"strconv"
"strings"
)
func
AppendGitlabSourceToEtree
(
source
*
etree
.
Element
,
gitSource
*
devopsv1alpha3
.
GitlabSource
)
{
if
gitSource
==
nil
{
klog
.
Warning
(
"please provide Gitlab source when the sourceType is Gitlab"
)
return
}
source
.
CreateAttr
(
"class"
,
"io.jenkins.plugins.gitlabbranchsource.GitLabSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"gitlab-branch-source"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
gitSource
.
ScmId
)
...
...
@@ -31,15 +36,11 @@ func AppendGitlabSourceToEtree(source *etree.Element, gitSource *devopsv1alpha3.
forkTrait
:=
traits
.
CreateElement
(
"io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait"
)
forkTrait
.
CreateElement
(
"strategyId"
)
.
SetText
(
strconv
.
Itoa
(
gitSource
.
DiscoverPRFromForks
.
Strategy
))
trustClass
:=
"io.jenkins.plugins.gitlabbranchsource.ForkMergeRequestDiscoveryTrait$"
switch
gitSource
.
DiscoverPRFromForks
.
Trust
{
case
1
:
trustClass
+=
"TrustMembers"
// it's difference with GitHub
case
2
:
trustClass
+=
"TrustEveryone"
case
3
:
trustClass
+=
"TrustPermission"
case
4
:
trustClass
+=
"TrustNobody"
if
prTrust
:=
PRDiscoverTrust
(
gitSource
.
DiscoverPRFromForks
.
Trust
);
prTrust
.
IsValid
()
{
trustClass
+=
prTrust
.
String
()
}
else
{
klog
.
Warningf
(
"invalid Gitlab discover PR trust value: %d"
,
prTrust
.
Value
())
}
forkTrait
.
CreateElement
(
"trust"
)
.
CreateAttr
(
"class"
,
trustClass
)
}
...
...
@@ -104,27 +105,13 @@ func GetGitlabSourceFromEtree(source *etree.Element) (gitSource *devopsv1alpha3.
strategyId
,
_
:=
strconv
.
Atoi
(
forkPRDiscoverTrait
.
SelectElement
(
"strategyId"
)
.
Text
())
trustClass
:=
forkPRDiscoverTrait
.
SelectElement
(
"trust"
)
.
SelectAttr
(
"class"
)
.
Value
trust
:=
strings
.
Split
(
trustClass
,
"$"
)
switch
trust
[
1
]
{
case
"TrustMembers"
:
// it's difference with GitHub
if
prTrust
:=
PRDiscoverTrust
(
1
)
.
ParseFromString
(
trust
[
1
]);
prTrust
.
IsValid
()
{
gitSource
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
1
,
}
case
"TrustEveryone"
:
gitSource
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
2
,
}
case
"TrustPermission"
:
gitSource
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
3
,
}
case
"TrustNobody"
:
gitSource
.
DiscoverPRFromForks
=
&
devopsv1alpha3
.
DiscoverPRFromForks
{
Strategy
:
strategyId
,
Trust
:
4
,
Trust
:
prTrust
.
Value
(),
}
}
else
{
klog
.
Warningf
(
"invalid Gitlab discover PR trust value: %s"
,
trust
[
1
])
}
if
cloneTrait
:=
traits
.
SelectElement
(
"jenkins.plugins.git.traits.CloneOptionTrait"
);
cloneTrait
!=
nil
{
...
...
pkg/simple/client/devops/jenkins/internal/pull_request.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
type
PRDiscoverTrust
int
const
(
PRDiscoverTrustMember
PRDiscoverTrust
=
1
PRDiscoverTrustEveryone
PRDiscoverTrust
=
2
PRDiscoverTrustPermission
PRDiscoverTrust
=
3
PRDiscoverTrustNobody
PRDiscoverTrust
=
4
)
type
GitHubPRDiscoverTrust
int
const
(
GitHubPRDiscoverTrustContributors
GitHubPRDiscoverTrust
=
1
)
func
(
p
PRDiscoverTrust
)
Value
()
int
{
return
int
(
p
)
}
func
(
p
PRDiscoverTrust
)
String
()
string
{
switch
p
{
case
PRDiscoverTrustMember
:
return
"TrustMembers"
case
PRDiscoverTrustEveryone
:
return
"TrustEveryone"
case
PRDiscoverTrustPermission
:
return
"TrustPermission"
case
PRDiscoverTrustNobody
:
return
"TrustNobody"
}
return
""
}
func
(
p
PRDiscoverTrust
)
ParseFromString
(
prTrust
string
)
PRDiscoverTrust
{
switch
prTrust
{
case
"TrustMembers"
:
return
PRDiscoverTrustMember
case
"TrustEveryone"
:
return
PRDiscoverTrustEveryone
case
"TrustPermission"
:
return
PRDiscoverTrustPermission
case
"TrustNobody"
:
return
PRDiscoverTrustNobody
default
:
return
-
1
}
}
func
(
p
GitHubPRDiscoverTrust
)
Value
()
int
{
return
int
(
p
)
}
func
(
p
PRDiscoverTrust
)
IsValid
()
bool
{
return
p
.
String
()
!=
""
}
func
(
p
GitHubPRDiscoverTrust
)
String
()
string
{
switch
p
{
case
GitHubPRDiscoverTrustContributors
:
return
"TrustContributors"
default
:
return
PRDiscoverTrust
(
p
)
.
String
()
}
}
func
(
p
GitHubPRDiscoverTrust
)
ParseFromString
(
prTrust
string
)
GitHubPRDiscoverTrust
{
switch
prTrust
{
case
"TrustContributors"
:
return
GitHubPRDiscoverTrustContributors
default
:
return
GitHubPRDiscoverTrust
(
PRDiscoverTrust
(
p
)
.
ParseFromString
(
prTrust
))
}
}
func
(
p
GitHubPRDiscoverTrust
)
IsValid
()
bool
{
return
PRDiscoverTrust
(
p
)
.
IsValid
()
}
pkg/simple/client/devops/jenkins/internal/pull_request_test.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
(
"github.com/stretchr/testify/assert"
"testing"
)
func
TestPRDiscoverTrust
(
t
*
testing
.
T
)
{
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
String
(),
"TrustMembers"
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
2
)
.
String
(),
"TrustEveryone"
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
3
)
.
String
(),
"TrustPermission"
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
4
)
.
String
(),
"TrustNobody"
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
-
1
)
.
IsValid
(),
false
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
Value
(),
1
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustMembers"
),
PRDiscoverTrustMember
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustEveryone"
),
PRDiscoverTrustEveryone
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustPermission"
),
PRDiscoverTrustPermission
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustNobody"
),
PRDiscoverTrustNobody
)
assert
.
Equal
(
t
,
PRDiscoverTrust
(
1
)
.
ParseFromString
(
"fake"
)
.
IsValid
(),
false
)
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
1
)
.
String
(),
"TrustContributors"
)
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
2
)
.
String
(),
PRDiscoverTrust
(
2
)
.
String
())
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
1
)
.
Value
(),
1
)
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustContributors"
),
GitHubPRDiscoverTrustContributors
)
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
1
)
.
ParseFromString
(
"TrustEveryone"
)
.
String
(),
"TrustEveryone"
)
assert
.
Equal
(
t
,
GitHubPRDiscoverTrust
(
1
)
.
ParseFromString
(
"fake"
)
.
IsValid
(),
false
)
}
pkg/simple/client/devops/jenkins/internal/svn.go
0 → 100644
浏览文件 @
0b4ed3f8
package
internal
import
(
"github.com/beevik/etree"
"k8s.io/klog"
devopsv1alpha3
"kubesphere.io/kubesphere/pkg/apis/devops/v1alpha3"
)
func
AppendSvnSourceToEtree
(
source
*
etree
.
Element
,
svnSource
*
devopsv1alpha3
.
SvnSource
)
{
if
svnSource
==
nil
{
klog
.
Warning
(
"please provide SVN source when the sourceType is SVN"
)
return
}
source
.
CreateAttr
(
"class"
,
"jenkins.scm.impl.subversion.SubversionSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"subversion"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
svnSource
.
ScmId
)
if
svnSource
.
CredentialId
!=
""
{
source
.
CreateElement
(
"credentialsId"
)
.
SetText
(
svnSource
.
CredentialId
)
}
if
svnSource
.
Remote
!=
""
{
source
.
CreateElement
(
"remoteBase"
)
.
SetText
(
svnSource
.
Remote
)
}
if
svnSource
.
Includes
!=
""
{
source
.
CreateElement
(
"includes"
)
.
SetText
(
svnSource
.
Includes
)
}
if
svnSource
.
Excludes
!=
""
{
source
.
CreateElement
(
"excludes"
)
.
SetText
(
svnSource
.
Excludes
)
}
return
}
func
AppendSingleSvnSourceToEtree
(
source
*
etree
.
Element
,
svnSource
*
devopsv1alpha3
.
SingleSvnSource
)
{
if
svnSource
==
nil
{
klog
.
Warning
(
"please provide SingleSvn source when the sourceType is SingleSvn"
)
return
}
source
.
CreateAttr
(
"class"
,
"jenkins.scm.impl.SingleSCMSource"
)
source
.
CreateAttr
(
"plugin"
,
"scm-api"
)
source
.
CreateElement
(
"id"
)
.
SetText
(
svnSource
.
ScmId
)
source
.
CreateElement
(
"name"
)
.
SetText
(
"master"
)
scm
:=
source
.
CreateElement
(
"scm"
)
scm
.
CreateAttr
(
"class"
,
"hudson.scm.SubversionSCM"
)
scm
.
CreateAttr
(
"plugin"
,
"subversion"
)
location
:=
scm
.
CreateElement
(
"locations"
)
.
CreateElement
(
"hudson.scm.SubversionSCM_-ModuleLocation"
)
if
svnSource
.
Remote
!=
""
{
location
.
CreateElement
(
"remote"
)
.
SetText
(
svnSource
.
Remote
)
}
if
svnSource
.
CredentialId
!=
""
{
location
.
CreateElement
(
"credentialsId"
)
.
SetText
(
svnSource
.
CredentialId
)
}
location
.
CreateElement
(
"local"
)
.
SetText
(
"."
)
location
.
CreateElement
(
"depthOption"
)
.
SetText
(
"infinity"
)
location
.
CreateElement
(
"ignoreExternalsOption"
)
.
SetText
(
"true"
)
location
.
CreateElement
(
"cancelProcessOnExternalsFail"
)
.
SetText
(
"true"
)
source
.
CreateElement
(
"excludedRegions"
)
source
.
CreateElement
(
"includedRegions"
)
source
.
CreateElement
(
"excludedUsers"
)
source
.
CreateElement
(
"excludedRevprop"
)
source
.
CreateElement
(
"excludedCommitMessages"
)
source
.
CreateElement
(
"workspaceUpdater"
)
.
CreateAttr
(
"class"
,
"hudson.scm.subversion.UpdateUpdater"
)
source
.
CreateElement
(
"ignoreDirPropChanges"
)
.
SetText
(
"false"
)
source
.
CreateElement
(
"filterChangelog"
)
.
SetText
(
"false"
)
source
.
CreateElement
(
"quietOperation"
)
.
SetText
(
"true"
)
return
}
func
GetSingleSvnSourceFromEtree
(
source
*
etree
.
Element
)
*
devopsv1alpha3
.
SingleSvnSource
{
var
s
devopsv1alpha3
.
SingleSvnSource
if
scm
:=
source
.
SelectElement
(
"scm"
);
scm
!=
nil
{
if
locations
:=
scm
.
SelectElement
(
"locations"
);
locations
!=
nil
{
if
moduleLocations
:=
locations
.
SelectElement
(
"hudson.scm.SubversionSCM_-ModuleLocation"
);
moduleLocations
!=
nil
{
if
remote
:=
moduleLocations
.
SelectElement
(
"remote"
);
remote
!=
nil
{
s
.
Remote
=
remote
.
Text
()
}
if
credentialId
:=
moduleLocations
.
SelectElement
(
"credentialsId"
);
credentialId
!=
nil
{
s
.
CredentialId
=
credentialId
.
Text
()
}
}
}
}
return
&
s
}
func
GetSvnSourcefromEtree
(
source
*
etree
.
Element
)
*
devopsv1alpha3
.
SvnSource
{
var
s
devopsv1alpha3
.
SvnSource
if
remote
:=
source
.
SelectElement
(
"remoteBase"
);
remote
!=
nil
{
s
.
Remote
=
remote
.
Text
()
}
if
credentialsId
:=
source
.
SelectElement
(
"credentialsId"
);
credentialsId
!=
nil
{
s
.
CredentialId
=
credentialsId
.
Text
()
}
if
includes
:=
source
.
SelectElement
(
"includes"
);
includes
!=
nil
{
s
.
Includes
=
includes
.
Text
()
}
if
excludes
:=
source
.
SelectElement
(
"excludes"
);
excludes
!=
nil
{
s
.
Excludes
=
excludes
.
Text
()
}
return
&
s
}
pkg/simple/client/devops/jenkins/pipeline_internal.go
浏览文件 @
0b4ed3f8
此差异已折叠。
点击以展开。
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录