提交 2a4471b8 编写于 作者: T TommyLike 提交者: Gitee

!1 Support ignore projects when validating via command parameters '-i'

Merge pull request !1 from TommyLike/feature/support-ignore-projects
......@@ -35,11 +35,13 @@ type Sig struct {
type DirScanner struct {
DirName string
ignoreProjects []string
}
func NewDirScanner(dir string) *DirScanner {
func NewDirScanner(dir string, projects []string) *DirScanner {
return &DirScanner{
DirName: dir,
ignoreProjects: projects,
}
}
......@@ -97,7 +99,11 @@ func (ds *DirScanner) ScanSigYaml(filename string, projects chan<- string) error
for _,s := range sig.Sigs {
for _, repo := range s.Repositories {
projects <- repo
if Find(ds.ignoreProjects, repo) {
fmt.Printf("[Warning] Project %s will be ignored due to --ignoreproject options %v\n", repo, ds.ignoreProjects)
} else {
projects <- repo
}
}
}
return nil
......
......@@ -74,14 +74,15 @@ func CheckOwner() error {
wg.Add(1)
go giteeHandler.ValidateUser(&wg, stopCh, userChannel, &failedUser)
scanner := NewDirScanner(checkOwnerFlags.DirName)
var emptyProjects []string
scanner := NewDirScanner(checkOwnerFlags.DirName, emptyProjects)
err := scanner.ScanAllOwners(checkOwnerFlags.FileName, userChannel)
wg.Wait()
if err != nil {
return err
}
if len(failedUser) != 0 {
return fmt.Errorf("[Import] Failed to recognize gitee user:\n %s\n", strings.Join(failedUser,"\n"))
return fmt.Errorf("[Error] Failed to recognize gitee user:\n %s\n", strings.Join(failedUser,"\n"))
}
fmt.Printf("Owners successfully verified.")
return nil
......
......@@ -27,6 +27,7 @@ import (
type SigRepoCheck struct {
FileName string
GiteeToken string
IgnoreProjects string
}
......@@ -36,6 +37,7 @@ var sigRepoCheck = &SigRepoCheck{}
func SigInitRunFlags(cmd *cobra.Command) {
cmd.Flags().StringVarP(&sigRepoCheck.FileName, "filename", "f", "", "the file name of sig file")
cmd.Flags().StringVarP(&sigRepoCheck.GiteeToken, "giteetoken", "g", "", "the gitee token")
cmd.Flags().StringVarP(&sigRepoCheck.IgnoreProjects, "ignoreprojects", "i", "", "the projects should be ignored, splitted via ','")
}
func buildSigCommand() *cobra.Command {
......@@ -64,6 +66,7 @@ func CheckSigRepo() error {
var scanProjects []string
var invalidProjects []string
fmt.Printf("Starting to validating all of the repos in sig file %s\n", sigRepoCheck.FileName)
fmt.Printf("Found projects to ignore %v\n", sigRepoCheck.IgnoreProjects)
if _, err := os.Stat(sigRepoCheck.FileName); os.IsNotExist(err) {
return fmt.Errorf("sig file not existed %s", sigRepoCheck.FileName)
}
......@@ -98,8 +101,8 @@ func CheckSigRepo() error {
wg.Add(1)
go giteeHandler.CollectRepos(&wg,100, size, i, 5 , "open_euler", resultChannel, )
}
scanner := NewDirScanner("")
projects := strings.Split(sigRepoCheck.IgnoreProjects, ",")
scanner := NewDirScanner("", projects)
err := scanner.ScanSigYaml(sigRepoCheck.FileName, sigChannel)
//Wait all gitee query threads to be finished
wg.Wait()
......@@ -118,7 +121,7 @@ func CheckSigRepo() error {
}
}
if len(invalidProjects) != 0 {
return fmt.Errorf("[Import] Failed to recognize gitee %d projects:\n %s\n", len(invalidProjects), strings.Join(invalidProjects,"\n"))
return fmt.Errorf("[Error] Failed to recognize gitee %d projects:\n %s\n", len(invalidProjects), strings.Join(invalidProjects,"\n"))
}
fmt.Printf("Projects successfully verified.")
return nil
......
文件已删除
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册