Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
openeuler
tool-collections
提交
3d3d8fbf
T
tool-collections
项目概览
openeuler
/
tool-collections
通知
0
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
T
tool-collections
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
前往新版Gitcode,体验更适合开发者的 AI 搜索 >>
提交
3d3d8fbf
编写于
12月 29, 2019
作者:
T
TommyLike
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Update code to fetch all projects when checking sig yaml file
上级
e4786590
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
75 addition
and
48 deletion
+75
-48
.gitignore
.gitignore
+1
-0
cmd/tools/giteehandler.go
cmd/tools/giteehandler.go
+36
-38
cmd/tools/ownercheck.go
cmd/tools/ownercheck.go
+1
-1
cmd/tools/sigrepocheck.go
cmd/tools/sigrepocheck.go
+34
-6
validator
validator
+0
-0
vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go
...or/gitee.com/openeuler/go-gitee/gitee/api_repositories.go
+3
-3
未找到文件。
.gitignore
浏览文件 @
3d3d8fbf
.idea/*
\ No newline at end of file
cmd/tools/giteehandler.go
浏览文件 @
3d3d8fbf
...
@@ -21,7 +21,7 @@ import (
...
@@ -21,7 +21,7 @@ import (
"github.com/antihax/optional"
"github.com/antihax/optional"
"os"
"os"
"os/signal"
"os/signal"
"str
ings
"
"str
conv
"
"sync"
"sync"
"syscall"
"syscall"
...
@@ -91,6 +91,7 @@ func (gh *GiteeHandler) ValidateUser(wg *sync.WaitGroup, stopChannel <-chan stru
...
@@ -91,6 +91,7 @@ func (gh *GiteeHandler) ValidateUser(wg *sync.WaitGroup, stopChannel <-chan stru
fmt
.
Printf
(
"User channel finished, quiting..
\n
"
)
fmt
.
Printf
(
"User channel finished, quiting..
\n
"
)
return
return
}
else
{
}
else
{
fmt
.
Printf
(
"Starting to validate user %s
\n
"
,
u
)
if
!
gh
.
checkUserExists
(
u
)
{
if
!
gh
.
checkUserExists
(
u
)
{
*
invalid
=
append
(
*
invalid
,
u
)
*
invalid
=
append
(
*
invalid
,
u
)
}
}
...
@@ -102,26 +103,6 @@ func (gh *GiteeHandler) ValidateUser(wg *sync.WaitGroup, stopChannel <-chan stru
...
@@ -102,26 +103,6 @@ func (gh *GiteeHandler) ValidateUser(wg *sync.WaitGroup, stopChannel <-chan stru
}
}
}
}
func
(
gh
*
GiteeHandler
)
ValidateRepo
(
wg
*
sync
.
WaitGroup
,
stopChannel
<-
chan
struct
{},
rsChannel
chan
<-
string
,
repos
<-
chan
string
,
orgName
string
)
{
defer
wg
.
Done
()
for
{
select
{
case
u
,
ok
:=
<-
repos
:
if
!
ok
{
fmt
.
Printf
(
"Repo channel finished, quiting..
\n
"
)
return
}
else
{
if
!
gh
.
checkRepoExists
(
u
,
orgName
)
{
rsChannel
<-
u
}
}
case
<-
stopChannel
:
fmt
.
Println
(
"quit signal captured, quiting."
)
return
}
}
}
func
(
gh
*
GiteeHandler
)
checkUserExists
(
name
string
)
bool
{
func
(
gh
*
GiteeHandler
)
checkUserExists
(
name
string
)
bool
{
option
:=
gitee
.
GetV5UsersUsernameOpts
{
option
:=
gitee
.
GetV5UsersUsernameOpts
{
AccessToken
:
optional
.
NewString
(
gh
.
Token
),
AccessToken
:
optional
.
NewString
(
gh
.
Token
),
...
@@ -138,30 +119,47 @@ func (gh *GiteeHandler) checkUserExists(name string) bool {
...
@@ -138,30 +119,47 @@ func (gh *GiteeHandler) checkUserExists(name string) bool {
return
true
return
true
}
}
func
(
gh
*
GiteeHandler
)
checkRepoExists
(
name
,
orgName
string
)
bool
{
func
(
gh
*
GiteeHandler
)
CollectRepoPageCount
(
pageSize
int
,
enterpriseName
string
)
int
{
option
:=
gitee
.
GetV5
SearchRepositorie
sOpts
{
option
:=
gitee
.
GetV5
EnterprisesEnterpriseRepo
sOpts
{
AccessToken
:
optional
.
NewString
(
gh
.
Token
),
AccessToken
:
optional
.
NewString
(
gh
.
Token
),
Owner
:
optional
.
NewString
(
orgName
),
PerPage
:
optional
.
NewInt32
(
int32
(
pageSize
)
),
}
}
projects
,
result
,
err
:=
gh
.
GiteeClient
.
SearchApi
.
GetV5SearchRepositories
(
gh
.
Context
,
n
ame
,
&
option
)
_
,
result
,
err
:=
gh
.
GiteeClient
.
RepositoriesApi
.
GetV5EnterprisesEnterpriseRepos
(
gh
.
Context
,
enterpriseN
ame
,
&
option
)
if
err
!=
nil
||
result
.
StatusCode
!=
200
{
if
err
!=
nil
||
result
.
StatusCode
!=
200
{
fmt
.
Printf
(
"[Warning] Repo %s does not exists, or failed %v
\n
"
,
name
,
err
)
return
false
fmt
.
Printf
(
"[Error] Can't collect projects in enterprise %s, %v
\n
"
,
enterpriseName
,
err
)
return
-
1
}
}
//check total count
size
,
ok
:=
result
.
Header
[
"Total_page"
]
if
len
(
projects
)
==
0
{
if
!
ok
{
fmt
.
Printf
(
"[
Warning] can't found project %s from gitee website
\n
"
,
name
)
fmt
.
Printf
(
"[
Error] Can't collect 'Total_page' from Header %v"
,
result
.
Header
)
return
false
return
-
1
}
}
sizeInt
,
err
:=
strconv
.
ParseInt
(
size
[
0
],
10
,
0
)
if
err
!=
nil
{
fmt
.
Printf
(
"[Error] Can't convert 'Total_page' to integer %v"
,
size
)
return
-
1
}
return
int
(
sizeInt
)
}
var
projectNames
[]
string
func
(
gh
*
GiteeHandler
)
CollectRepos
(
wg
*
sync
.
WaitGroup
,
pageSize
,
totalPage
,
workerIndex
,
gap
int
,
enterpriseName
string
,
rsChannel
chan
<-
string
)
{
for
_
,
p
:=
range
projects
{
defer
wg
.
Done
()
if
p
.
FullName
==
name
{
for
i
:=
workerIndex
;
i
<=
totalPage
;
i
+=
gap
{
return
true
fmt
.
Printf
(
"Starting to fetch project lists %d/%d from enterpise %s
\n
"
,
i
,
totalPage
,
enterpriseName
)
option
:=
gitee
.
GetV5EnterprisesEnterpriseReposOpts
{
AccessToken
:
optional
.
NewString
(
gh
.
Token
),
PerPage
:
optional
.
NewInt32
(
int32
(
pageSize
)),
Page
:
optional
.
NewInt32
(
int32
(
i
)),
}
projects
,
result
,
err
:=
gh
.
GiteeClient
.
RepositoriesApi
.
GetV5EnterprisesEnterpriseRepos
(
gh
.
Context
,
enterpriseName
,
&
option
)
if
err
!=
nil
||
result
.
StatusCode
!=
200
{
fmt
.
Printf
(
"[Warning] Failed to get projects %d/%d from enterprise %s
\n
"
,
i
,
totalPage
,
enterpriseName
)
continue
}
for
_
,
p
:=
range
projects
{
rsChannel
<-
p
.
FullName
}
}
projectNames
=
append
(
projectNames
,
p
.
FullName
)
}
}
fmt
.
Printf
(
"[Warning] Unable to get repo %s information, actual search result %s
\n
"
,
name
,
strings
.
Join
(
projectNames
,
","
))
return
false
}
}
cmd/tools/ownercheck.go
浏览文件 @
3d3d8fbf
...
@@ -81,7 +81,7 @@ func CheckOwner() error {
...
@@ -81,7 +81,7 @@ func CheckOwner() error {
return
err
return
err
}
}
if
len
(
failedUser
)
!=
0
{
if
len
(
failedUser
)
!=
0
{
return
fmt
.
Errorf
(
"[Import] Failed to recognize gitee user:
%s
\n
"
,
strings
.
Join
(
failedUser
,
",
"
))
return
fmt
.
Errorf
(
"[Import] Failed to recognize gitee user:
\n
%s
\n
"
,
strings
.
Join
(
failedUser
,
"
\n
"
))
}
}
fmt
.
Printf
(
"Owners successfully verified."
)
fmt
.
Printf
(
"Owners successfully verified."
)
return
nil
return
nil
...
...
cmd/tools/sigrepocheck.go
浏览文件 @
3d3d8fbf
...
@@ -59,6 +59,8 @@ func buildSigCommand() *cobra.Command {
...
@@ -59,6 +59,8 @@ func buildSigCommand() *cobra.Command {
func
CheckSigRepo
()
error
{
func
CheckSigRepo
()
error
{
var
wg
sync
.
WaitGroup
var
wg
sync
.
WaitGroup
var
totalProjects
[]
string
var
scanProjects
[]
string
var
invalidProjects
[]
string
var
invalidProjects
[]
string
fmt
.
Printf
(
"Starting to validating all of the repos in sig file %s
\n
"
,
sigRepoCheck
.
FileName
)
fmt
.
Printf
(
"Starting to validating all of the repos in sig file %s
\n
"
,
sigRepoCheck
.
FileName
)
if
_
,
err
:=
os
.
Stat
(
sigRepoCheck
.
FileName
);
os
.
IsNotExist
(
err
)
{
if
_
,
err
:=
os
.
Stat
(
sigRepoCheck
.
FileName
);
os
.
IsNotExist
(
err
)
{
...
@@ -68,17 +70,28 @@ func CheckSigRepo() error {
...
@@ -68,17 +70,28 @@ func CheckSigRepo() error {
// Setting up gitee handler
// Setting up gitee handler
giteeHandler
:=
NewGiteeHandler
(
sigRepoCheck
.
GiteeToken
)
giteeHandler
:=
NewGiteeHandler
(
sigRepoCheck
.
GiteeToken
)
sigChannel
:=
make
(
chan
string
,
50
)
sigChannel
:=
make
(
chan
string
,
50
)
stopCh
:=
SetupSignalHandler
()
resultChannel
:=
make
(
chan
string
,
50
)
resultChannel
:=
make
(
chan
string
,
50
)
// Running 5 workers to check the repo status
go
func
()
{
go
func
()
{
for
rs
:=
range
resultChannel
{
for
rs
:=
range
resultChannel
{
invalidProjects
=
append
(
invalid
Projects
,
rs
)
totalProjects
=
append
(
total
Projects
,
rs
)
}
}
}()
}()
for
i
:=
0
;
i
<
5
;
i
++
{
go
func
()
{
for
rs
:=
range
sigChannel
{
scanProjects
=
append
(
scanProjects
,
rs
)
}
}()
// Running 5 workers to collect the projects status
size
:=
giteeHandler
.
CollectRepoPageCount
(
100
,
"open_euler"
)
if
size
<=
0
{
return
fmt
.
Errorf
(
"can't get any projects in enterprise 'open_euler'"
)
}
for
i
:=
1
;
i
<=
5
;
i
++
{
wg
.
Add
(
1
)
wg
.
Add
(
1
)
go
giteeHandler
.
ValidateRepo
(
&
wg
,
stopCh
,
resultChannel
,
sigChannel
,
"open_euler"
)
go
giteeHandler
.
CollectRepos
(
&
wg
,
100
,
size
,
i
,
5
,
"open_euler"
,
resultChannel
,
)
}
}
scanner
:=
NewDirScanner
(
""
)
scanner
:=
NewDirScanner
(
""
)
...
@@ -88,10 +101,25 @@ func CheckSigRepo() error {
...
@@ -88,10 +101,25 @@ func CheckSigRepo() error {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
for
_
,
scan
:=
range
scanProjects
{
if
!
Find
(
totalProjects
,
scan
)
{
invalidProjects
=
append
(
invalidProjects
,
scan
)
}
}
if
len
(
invalidProjects
)
!=
0
{
if
len
(
invalidProjects
)
!=
0
{
return
fmt
.
Errorf
(
"[Import] Failed to recognize gitee
projects: %s
\n
"
,
strings
.
Join
(
invalidProjects
,
",
"
))
return
fmt
.
Errorf
(
"[Import] Failed to recognize gitee
%d projects:
\n
%s
\n
"
,
len
(
invalidProjects
),
strings
.
Join
(
invalidProjects
,
"
\n
"
))
}
}
fmt
.
Printf
(
"Projects successfully verified."
)
fmt
.
Printf
(
"Projects successfully verified."
)
return
nil
return
nil
}
}
func
Find
(
slice
[]
string
,
val
string
)
bool
{
for
_
,
item
:=
range
slice
{
if
item
==
val
{
return
true
}
}
return
false
}
validator
0 → 100755
浏览文件 @
3d3d8fbf
文件已添加
vendor/gitee.com/openeuler/go-gitee/gitee/api_repositories.go
浏览文件 @
3d3d8fbf
...
@@ -760,13 +760,13 @@ type GetV5EnterprisesEnterpriseReposOpts struct {
...
@@ -760,13 +760,13 @@ type GetV5EnterprisesEnterpriseReposOpts struct {
PerPage
optional
.
Int32
PerPage
optional
.
Int32
}
}
func
(
a
*
RepositoriesApiService
)
GetV5EnterprisesEnterpriseRepos
(
ctx
context
.
Context
,
enterprise
string
,
localVarOptionals
*
GetV5EnterprisesEnterpriseReposOpts
)
(
Project
,
*
http
.
Response
,
error
)
{
func
(
a
*
RepositoriesApiService
)
GetV5EnterprisesEnterpriseRepos
(
ctx
context
.
Context
,
enterprise
string
,
localVarOptionals
*
GetV5EnterprisesEnterpriseReposOpts
)
(
[]
Project
,
*
http
.
Response
,
error
)
{
var
(
var
(
localVarHttpMethod
=
strings
.
ToUpper
(
"Get"
)
localVarHttpMethod
=
strings
.
ToUpper
(
"Get"
)
localVarPostBody
interface
{}
localVarPostBody
interface
{}
localVarFileName
string
localVarFileName
string
localVarFileBytes
[]
byte
localVarFileBytes
[]
byte
localVarReturnValue
Project
localVarReturnValue
[]
Project
)
)
// create path and map variables
// create path and map variables
...
@@ -840,7 +840,7 @@ func (a *RepositoriesApiService) GetV5EnterprisesEnterpriseRepos(ctx context.Con
...
@@ -840,7 +840,7 @@ func (a *RepositoriesApiService) GetV5EnterprisesEnterpriseRepos(ctx context.Con
}
}
if
localVarHttpResponse
.
StatusCode
==
200
{
if
localVarHttpResponse
.
StatusCode
==
200
{
var
v
Project
var
v
[]
Project
err
=
a
.
client
.
decode
(
&
v
,
localVarBody
,
localVarHttpResponse
.
Header
.
Get
(
"Content-Type"
))
err
=
a
.
client
.
decode
(
&
v
,
localVarBody
,
localVarHttpResponse
.
Header
.
Get
(
"Content-Type"
))
if
err
!=
nil
{
if
err
!=
nil
{
newErr
.
error
=
err
.
Error
()
newErr
.
error
=
err
.
Error
()
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录