Merge pull request #8 from saitho/feature/branch-configuration

Pass branch name to Sonar
Este commit está contenido en:
Rogan
2019-11-21 18:54:26 +08:00
cometido por GitHub
Se han modificado 4 ficheros con 39 adiciones y 20 borrados

Ver fichero

@@ -60,6 +60,7 @@ Safety first, the host and token are stored in Drone Secrets.
* DEBUG: Display INFO logs + more details at DEBUG level. * DEBUG: Display INFO logs + more details at DEBUG level.
* TRACE: Display DEBUG logs + the timings of all ElasticSearch queries and Web API calls executed by the SonarQube Scanner. * TRACE: Display DEBUG logs + the timings of all ElasticSearch queries and Web API calls executed by the SonarQube Scanner.
* `showProfiling`: Display logs to see where the analyzer spends time. Default value `false` * `showProfiling`: Display logs to see where the analyzer spends time. Default value `false`
* `branchAnalysis`: Pass currently analysed branch to SonarQube. (Must not be active for initial scan!) Default value `false`
# Notes # Notes

Archivo binario no mostrado.

26
main.go
Ver fichero

@@ -43,6 +43,11 @@ func main() {
Usage: "Project version", Usage: "Project version",
EnvVar: "DRONE_BUILD_NUMBER", EnvVar: "DRONE_BUILD_NUMBER",
}, },
cli.StringFlag{
Name: "branch",
Usage: "Project branch",
EnvVar: "DRONE_BRANCH",
},
cli.StringFlag{ cli.StringFlag{
Name: "timeout", Name: "timeout",
Usage: "Web request timeout", Usage: "Web request timeout",
@@ -77,6 +82,11 @@ func main() {
Value: "false", Value: "false",
EnvVar: "PLUGIN_SHOWPROFILING", EnvVar: "PLUGIN_SHOWPROFILING",
}, },
cli.BoolFlag{
Name: "branchAnalysis",
Usage: "execute branchAnalysis",
EnvVar: "PLUGIN_BRANCHANALYSIS",
},
} }
app.Run(os.Args) app.Run(os.Args)
@@ -90,13 +100,15 @@ func run(c *cli.Context) {
Host: c.String("host"), Host: c.String("host"),
Token: c.String("token"), Token: c.String("token"),
Version: c.String("ver"), Version: c.String("ver"),
Timeout: c.String("timeout"), Branch: c.String("branch"),
Sources: c.String("sources"), Timeout: c.String("timeout"),
Inclusions: c.String("inclusions"), Sources: c.String("sources"),
Exclusions: c.String("exclusions"), Inclusions: c.String("inclusions"),
Level: c.String("level"), Exclusions: c.String("exclusions"),
showProfiling: c.String("showProfiling"), Level: c.String("level"),
showProfiling: c.String("showProfiling"),
branchAnalysis: c.Bool("branchAnalysis"),
}, },
} }

Ver fichero

@@ -1,25 +1,27 @@
package main package main
import ( import (
"strings"
"fmt" "fmt"
"os/exec" "os/exec"
"strings"
) )
type ( type (
Config struct { Config struct {
Key string Key string
Name string Name string
Host string Host string
Token string Token string
Version string Version string
Sources string Branch string
Timeout string Sources string
Inclusions string Timeout string
Exclusions string Inclusions string
Level string Exclusions string
showProfiling string Level string
showProfiling string
branchAnalysis bool
} }
Plugin struct { Plugin struct {
Config Config Config Config
@@ -41,8 +43,12 @@ func (p Plugin) Exec() error {
"-Dsonar.log.level=" + p.Config.Level, "-Dsonar.log.level=" + p.Config.Level,
"-Dsonar.showProfiling=" + p.Config.showProfiling, "-Dsonar.showProfiling=" + p.Config.showProfiling,
"-Dsonar.scm.provider=git", "-Dsonar.scm.provider=git",
} }
if p.Config.branchAnalysis {
args = append(args, "-Dsonar.branch.name="+p.Config.Branch)
}
cmd := exec.Command("sonar-scanner", args...) cmd := exec.Command("sonar-scanner", args...)
// fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " ")) // fmt.Printf("==> Executing: %s\n", strings.Join(cmd.Args, " "))
output, err := cmd.CombinedOutput() output, err := cmd.CombinedOutput()