Skip to content

Commit 2fac764

Browse files
preflight to reduce duplicate lines density
1 parent a79f5b2 commit 2fac764

File tree

1 file changed

+44
-13
lines changed

1 file changed

+44
-13
lines changed

plugin.go

Lines changed: 44 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,31 @@ func GetProjectKey(key string) string {
398398
return projectKey
399399
}
400400

401+
func PreFlightGetLatestTaskID(config Config) (string, error) {
402+
// token := os.Getenv("PLUGIN_SONAR_TOKEN")
403+
404+
var statusID string
405+
var err error
406+
if config.PRKey != "" {
407+
fmt.Printf("==> PR Key: " + config.PRKey + "\n")
408+
statusID, err = getStatusV2("pr", config.PRKey, config.Host, config.Key)
409+
} else if config.Branch != "" {
410+
fmt.Printf("==> Branch: " + config.Branch + "\n")
411+
statusID, err = getStatusV2("branch", config.Branch, config.Host, config.Key)
412+
} else {
413+
fmt.Printf("==> Project Key: " + config.Key + "\n")
414+
statusID, err = getStatusID(config.TaskId, config.Host, config.Key)
415+
}
416+
417+
if err != nil {
418+
fmt.Printf("\n\n==> Error getting the latest scanID\n\n")
419+
fmt.Printf("Error: %s", err.Error())
420+
return "", err
421+
}
422+
423+
return statusID, nil
424+
}
425+
401426
func (p Plugin) Exec() error {
402427
// Initial values
403428
args := []string{
@@ -601,25 +626,31 @@ func (p Plugin) Exec() error {
601626
fmt.Printf("#######################################\n")
602627

603628
// statusID, err := getStatusID(p.Config.TaskId, p.Config.Host, p.Config.Key)
604-
var statusID string
629+
// var statusID string
630+
// var err error
631+
// if p.Config.PRKey != "" {
632+
// fmt.Printf("==> PR Key: " + p.Config.PRKey + "\n")
633+
// statusID, err = getStatusV2("pr", p.Config.PRKey, p.Config.Host, p.Config.Key)
634+
// } else if p.Config.Branch != "" {
635+
// fmt.Printf("==> Branch: " + p.Config.Branch + "\n")
636+
// statusID, err = getStatusV2("branch", p.Config.Branch, p.Config.Host, p.Config.Key)
637+
// } else {
638+
// fmt.Printf("==> Project Key: " + p.Config.Key + "\n")
639+
// statusID, err = getStatusID(p.Config.TaskId, p.Config.Host, p.Config.Key)
640+
// }
641+
642+
// if err != nil {
643+
// fmt.Printf("\n\n==> Error getting the latest scanID\n\n")
644+
// fmt.Printf("Error: %s", err.Error())
645+
// return err
646+
// }
605647
var err error
606-
if p.Config.PRKey != "" {
607-
fmt.Printf("==> PR Key: " + p.Config.PRKey + "\n")
608-
statusID, err = getStatusV2("pr", p.Config.PRKey, p.Config.Host, p.Config.Key)
609-
} else if p.Config.Branch != "" {
610-
fmt.Printf("==> Branch: " + p.Config.Branch + "\n")
611-
statusID, err = getStatusV2("branch", p.Config.Branch, p.Config.Host, p.Config.Key)
612-
} else {
613-
fmt.Printf("==> Project Key: " + p.Config.Key + "\n")
614-
statusID, err = getStatusID(p.Config.TaskId, p.Config.Host, p.Config.Key)
615-
}
616-
648+
status, err = PreFlightGetLatestTaskID(p.Config)
617649
if err != nil {
618650
fmt.Printf("\n\n==> Error getting the latest scanID\n\n")
619651
fmt.Printf("Error: %s", err.Error())
620652
return err
621653
}
622-
status = statusID
623654
} else {
624655
fmt.Printf("Starting Analisys")
625656
fmt.Printf("\n")

0 commit comments

Comments
 (0)