Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/core/container.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `container.go` coverage is below the threshold 50%

Check warning on line 1 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `container.go` coverage is below the threshold 50%
* Copyright 2021-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -30,6 +30,7 @@
"strings"

"github.com/JetBrains/qodana-cli/internal/cloud"
"github.com/JetBrains/qodana-cli/internal/platform/git"
"github.com/docker/docker/api/types/image"
"github.com/docker/docker/api/types/network"

Expand Down Expand Up @@ -72,7 +73,7 @@
)

// runQodanaContainer runs the analysis in a Docker container from a Qodana image.
func runQodanaContainer(ctx context.Context, c corescan.Context) int {

Check warning on line 76 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `runQodanaContainer` coverage is below the threshold 50%

Check warning on line 76 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `runQodanaContainer` coverage is below the threshold 50%
dockerAnalyzer, ok := c.Analyser().(*product.DockerAnalyzer)
if !ok {
log.Fatalf("Context is not a DockerAnalyzer")
Expand Down Expand Up @@ -135,7 +136,7 @@
}

// CheckImage checks the linter image and prints warnings if necessary.
func CheckImage(linter string) {

Check warning on line 139 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `CheckImage` coverage is below the threshold 50%

Check warning on line 139 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `CheckImage` coverage is below the threshold 50%
if strings.Contains(version.Version, "nightly") || strings.Contains(version.Version, "dev") {
return
}
Expand All @@ -160,7 +161,7 @@
}
}

func fixDarwinCaches(cacheDir string) {

Check warning on line 164 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `fixDarwinCaches` coverage is below the threshold 50%

Check warning on line 164 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `fixDarwinCaches` coverage is below the threshold 50%
if //goland:noinspection GoBoolExpressions
runtime.GOOS == "darwin" {
err := removePortSocket(cacheDir)
Expand All @@ -171,7 +172,7 @@
}

// removePortSocket removes .port from the system dir to resolve QD-7383.
func removePortSocket(systemDir string) error {

Check warning on line 175 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `removePortSocket` coverage is below the threshold 50%

Check warning on line 175 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `removePortSocket` coverage is below the threshold 50%
ideaDir := filepath.Join(systemDir, "idea")
files, err := os.ReadDir(ideaDir)
if err != nil {
Expand All @@ -192,7 +193,7 @@
}

// encodeAuthToBase64 serializes the auth configuration as JSON base64 payload
func encodeAuthToBase64(authConfig registry.AuthConfig) (string, error) {

Check warning on line 196 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `encodeAuthToBase64` coverage is below the threshold 50%

Check warning on line 196 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `encodeAuthToBase64` coverage is below the threshold 50%
buf, err := json.Marshal(authConfig)
if err != nil {
return "", err
Expand All @@ -211,7 +212,7 @@
)
}

func isDockerUnauthorizedError(errMsg string) bool {

Check warning on line 215 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `isDockerUnauthorizedError` coverage is below the threshold 50%

Check warning on line 215 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `isDockerUnauthorizedError` coverage is below the threshold 50%
errMsg = strutil.Lower(errMsg)
return strings.Contains(errMsg, "unauthorized") || strings.Contains(errMsg, "denied") || strings.Contains(
errMsg,
Expand All @@ -220,7 +221,7 @@
}

// pullImage pulls docker image.
func pullImage(ctx context.Context, client client.APIClient, ref string) {

Check warning on line 224 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `pullImage` coverage is below the threshold 50%

Check warning on line 224 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `pullImage` coverage is below the threshold 50%
reader, err := client.ImagePull(ctx, ref, image.PullOptions{})
if err != nil && isDockerUnauthorizedError(err.Error()) {
cfg, err := cliconfig.Load("")
Expand Down Expand Up @@ -257,7 +258,7 @@
}

// ContainerCleanup cleans up Qodana containers.
func ContainerCleanup() {

Check warning on line 261 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `ContainerCleanup` coverage is below the threshold 50%

Check warning on line 261 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `ContainerCleanup` coverage is below the threshold 50%
if containerName != "qodana-cli" { // if containerName is not set, it means that the container was not created!
ctx := context.Background()
docker, err := qdcontainer.NewContainerClient(ctx)
Expand All @@ -281,11 +282,11 @@
}

// getDockerOptions returns qodana docker container options.
func getDockerOptions(c corescan.Context, image string) *backend.ContainerCreateConfig {

Check warning on line 285 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `getDockerOptions` coverage is below the threshold 50%

Check warning on line 285 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `getDockerOptions` coverage is below the threshold 50%
cmdOpts := GetIdeArgs(c)

updateScanContextEnv := func(key string, value string) { c = c.WithEnvExtractedFromOsEnv(key, value) }

Check warning on line 288 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in getDockerOptions)` coverage is below the threshold 50%

Check warning on line 288 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in getDockerOptions)` coverage is below the threshold 50%
qdenv.ExtractQodanaEnvironment(updateScanContextEnv)
qdenv.ExtractQodanaEnvironment(git.GetGitEnv(c.RepositoryRoot(), c.LogDir()), updateScanContextEnv)

dockerEnv := c.Env()
qodanaCloudUploadToken := c.QodanaUploadToken()
Expand Down Expand Up @@ -449,7 +450,7 @@
return userFromContext // Do not modify explicit user input
}

func generateDebugDockerRunCommand(cfg *backend.ContainerCreateConfig) string {

Check warning on line 453 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `generateDebugDockerRunCommand` coverage is below the threshold 50%

Check warning on line 453 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `generateDebugDockerRunCommand` coverage is below the threshold 50%
var cmdBuilder strings.Builder
cmdBuilder.WriteString("docker run ")
if cfg.HostConfig != nil && cfg.HostConfig.AutoRemove {
Expand Down Expand Up @@ -495,7 +496,7 @@
}

// getContainerExitCode returns the exit code of the docker container.
func getContainerExitCode(ctx context.Context, client client.APIClient, id string) int64 {

Check warning on line 499 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `getContainerExitCode` coverage is below the threshold 50%

Check warning on line 499 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `getContainerExitCode` coverage is below the threshold 50%
statusCh, errCh := client.ContainerWait(ctx, id, container.WaitConditionNextExit)
select {
case err := <-errCh:
Expand All @@ -509,7 +510,7 @@
}

// runContainer runs the container.
func runContainer(ctx context.Context, client client.APIClient, opts *backend.ContainerCreateConfig) {

Check warning on line 513 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `runContainer` coverage is below the threshold 50%

Check warning on line 513 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `runContainer` coverage is below the threshold 50%
createResp, err := client.ContainerCreate(
ctx,
opts.Config,
Expand All @@ -527,7 +528,7 @@
}

// extractDockerVolumes extracts the source and target of the volume to mount.
func extractDockerVolumes(volume string) (string, string) {

Check warning on line 531 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `extractDockerVolumes` coverage is below the threshold 50%

Check warning on line 531 in internal/core/container.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `extractDockerVolumes` coverage is below the threshold 50%
if //goland:noinspection GoBoolExpressions
runtime.GOOS == "windows" {
parts := strings.Split(volume, ":")
Expand Down
43 changes: 35 additions & 8 deletions internal/core/corescan/env_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,13 +70,15 @@ func Test_ExtractEnvironmentVariables(t *testing.T) {
}

for _, tc := range []struct {
ci string
variables map[string]string
jobUrlExpected string
envExpected string
remoteUrlExpected string
revisionExpected string
branchExpected string
ci string
variables map[string]string
jobUrlExpected string
envExpected string
remoteUrlExpected string
repositoryUrlExpected string
revisionExpected string
branchExpected string
gitEnv qdenv.GitEnv
}{
{
ci: "no CI detected",
Expand Down Expand Up @@ -213,6 +215,23 @@ func Test_ExtractEnvironmentVariables(t *testing.T) {
envExpected: fmt.Sprintf("bitbucket:%s", version.Version),
jobUrlExpected: "https://bitbucket.org/sa/entrypoint/pipelines/results/123456789",
},
{
ci: "local-git",
gitEnv: qdenv.GitEnv{
RemoteUrl: "https://qodana.jetbrains.com/never-gonna-give-you-up",
RepositoryUrl: "https://qodana.jetbrains.com/never-gonna-give-you-up",
Revision: revisionExpected,
Branch: branchExpected,
},
variables: map[string]string{
qdenv.QodanaEnv: "local-git",
},
envExpected: "local-git",
remoteUrlExpected: "https://qodana.jetbrains.com/never-gonna-give-you-up",
repositoryUrlExpected: "https://qodana.jetbrains.com/never-gonna-give-you-up",
revisionExpected: revisionExpected,
branchExpected: branchExpected,
},
} {
t.Run(
tc.ci, func(t *testing.T) {
Expand Down Expand Up @@ -246,7 +265,7 @@ func Test_ExtractEnvironmentVariables(t *testing.T) {
environment.name, func(t *testing.T) {
qdenv.InitializeQodanaGlobalEnv(qdenv.EmptyEnvProvider())

qdenv.ExtractQodanaEnvironment(environment.set)
qdenv.ExtractQodanaEnvironment(tc.gitEnv, environment.set)
currentQodanaEnv := environment.get(qdenv.QodanaEnv)
if currentQodanaEnv != tc.envExpected {
t.Errorf("%s: Expected %s, got %s", environment.name, tc.envExpected, currentQodanaEnv)
Expand All @@ -267,6 +286,14 @@ func Test_ExtractEnvironmentVariables(t *testing.T) {
environment.get(qdenv.QodanaRemoteUrl),
)
}
if environment.get(qdenv.QodanaRepoUrl) != tc.repositoryUrlExpected {
t.Errorf(
"%s: Expected %s, got %s",
environment.name,
tc.repositoryUrlExpected,
environment.get(qdenv.QodanaRepoUrl),
)
}
if environment.get(qdenv.QodanaRevision) != tc.revisionExpected {
t.Errorf(
"%s: Expected %s, got %s",
Expand Down
2 changes: 1 addition & 1 deletion internal/core/startup/prepare.go
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*

Check warning on line 1 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `prepare.go` coverage is below the threshold 50%

Check warning on line 1 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `prepare.go` coverage is below the threshold 50%
* Copyright 2021-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
Expand Down Expand Up @@ -49,7 +49,7 @@
}

// PrepareHost gets the current user, creates the necessary folders for the analysis.
func PrepareHost(commonCtx commoncontext.Context) PreparedHost {

Check warning on line 52 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `PrepareHost` coverage is below the threshold 50%

Check warning on line 52 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `PrepareHost` coverage is below the threshold 50%
prod := product.Product{}
cloudUploadToken := commonCtx.QodanaToken
ideDir := ""
Expand Down Expand Up @@ -77,7 +77,7 @@
if commonCtx.Analyzer.DownloadDist() {
linter := commonCtx.Analyzer.GetLinter()
msg.PrintProcess(
func(spinner *pterm.SpinnerPrinter) {

Check warning on line 80 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in PrepareHost)` coverage is below the threshold 50%

Check warning on line 80 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in PrepareHost)` coverage is below the threshold 50%
if spinner != nil {
spinner.ShowTimer = false // We will update interactive spinner
}
Expand Down Expand Up @@ -110,13 +110,13 @@
return result
}

func prepareLocalIdeSettingsAndGetQodanaCloudUploadToken(

Check warning on line 113 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareLocalIdeSettingsAndGetQodanaCloudUploadToken` coverage is below the threshold 50%

Check warning on line 113 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareLocalIdeSettingsAndGetQodanaCloudUploadToken` coverage is below the threshold 50%
commonCtx commoncontext.Context,
ideDir string,
) (product.Product, string) {
prod := product.GuessProduct(ideDir, commonCtx.Analyzer)

qdenv.ExtractQodanaEnvironment(qdenv.SetEnv)
qdenv.ExtractQodanaEnvironment(git.GetGitEnv(commonCtx.RepositoryRoot, commonCtx.LogDir()), qdenv.SetEnv)
isTokenRequired := tokenloader.IsCloudTokenRequired(commonCtx)
token := tokenloader.LoadCloudUploadToken(commonCtx, false, isTokenRequired, true)
cloud.SetupLicenseToken(token)
Expand All @@ -143,7 +143,7 @@
SyncConfigCache(prod, commonCtx.ConfDirPath(), commonCtx.CacheDir, true)
}

func prepareQodanaTokenForNative(token string) {

Check warning on line 146 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareQodanaTokenForNative` coverage is below the threshold 50%

Check warning on line 146 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareQodanaTokenForNative` coverage is below the threshold 50%
_, isSet := os.LookupEnv(qdenv.QodanaToken)
if !isSet {
err := os.Setenv(qdenv.QodanaToken, token)
Expand All @@ -153,7 +153,7 @@
}
}

func prepareCustomPlugins(prod product.Product) {

Check warning on line 156 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareCustomPlugins` coverage is below the threshold 50%

Check warning on line 156 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareCustomPlugins` coverage is below the threshold 50%
if runtime.GOOS == "darwin" && !prod.Analyzer.IsContainer() {
if info := getIde(prod.Analyzer); info != nil {
err := downloadCustomPlugins(info.Link, filepath.Dir(prod.CustomPluginsPath()), nil)
Expand All @@ -164,7 +164,7 @@
}
}

func prepareContainerSpecificDirectories(prod product.Product, cacheDir string, confDir string) {

Check warning on line 167 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareContainerSpecificDirectories` coverage is below the threshold 50%

Check warning on line 167 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareContainerSpecificDirectories` coverage is below the threshold 50%
homeDir, err := os.UserHomeDir()
if err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -212,7 +212,7 @@
}
}

func prepareDirectories(cacheDir string, logDir string, confDir string) {

Check warning on line 215 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareDirectories` coverage is below the threshold 50%

Check warning on line 215 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `prepareDirectories` coverage is below the threshold 50%
MakeDirAll(cacheDir)
MakeDirAll(logDir)

Expand All @@ -229,7 +229,7 @@
}
}

func addKeepassIDEConfig(ideaOptions string) {

Check warning on line 232 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `addKeepassIDEConfig` coverage is below the threshold 50%

Check warning on line 232 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `addKeepassIDEConfig` coverage is below the threshold 50%
if //goland:noinspection ALL
runtime.GOOS != "darwin" && runtime.GOOS != "windows" {
writeFileIfNew(filepath.Join(ideaOptions, "security.xml"), securityXml)
Expand Down Expand Up @@ -276,7 +276,7 @@
}
return cp.Untouchable
},
OnSymlink: func(src string) cp.SymlinkAction {

Check warning on line 279 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in SyncIdeaCache)` coverage is below the threshold 50%

Check warning on line 279 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `(anonymous function in SyncIdeaCache)` coverage is below the threshold 50%
return cp.Skip
},
}
Expand All @@ -293,7 +293,7 @@
return nil
}

func writeFileIfNew(filepath string, content string) {

Check warning on line 296 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `writeFileIfNew` coverage is below the threshold 50%

Check warning on line 296 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `writeFileIfNew` coverage is below the threshold 50%
if _, err := os.Stat(filepath); os.IsNotExist(err) {
if err := os.WriteFile(filepath, []byte(content), 0o755); err != nil {
log.Fatal(err)
Expand Down Expand Up @@ -324,7 +324,7 @@
}

// fixWindowsPlugins quick-fix for Windows 241 distributions
func fixWindowsPlugins(ideDir string) {

Check warning on line 327 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `fixWindowsPlugins` coverage is below the threshold 50%

Check warning on line 327 in internal/core/startup/prepare.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `fixWindowsPlugins` coverage is below the threshold 50%
if runtime.GOOS == "windows" && strings.Contains(ideDir, "241") {
pluginsClasspath := filepath.Join(ideDir, "plugins", "plugin-classpath.txt")
if _, err := os.Stat(pluginsClasspath); err == nil {
Expand Down
43 changes: 43 additions & 0 deletions internal/platform/git/env.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*

Check warning on line 1 in internal/platform/git/env.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `env.go` coverage is below the threshold 50%

Check warning on line 1 in internal/platform/git/env.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

File `env.go` coverage is below the threshold 50%
* Copyright 2021-2024 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package git

import (
"strings"

"github.com/JetBrains/qodana-cli/internal/platform/qdenv"
)

func GetGitEnv(gitRoot string, logDir string) qdenv.GitEnv {

Check warning on line 25 in internal/platform/git/env.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetGitEnv` coverage is below the threshold 50%

Check warning on line 25 in internal/platform/git/env.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetGitEnv` coverage is below the threshold 50%
var env = &qdenv.GitEnv{}
remUrl, err := RemoteUrl(gitRoot, logDir)
if err == nil {
env.RemoteUrl = remUrl
if strings.HasPrefix(remUrl, "https://") {
env.RepositoryUrl = remUrl
}
}
brnch, err := Branch(gitRoot, logDir)
if err == nil {
env.Branch = brnch
}
revisions := Revisions(gitRoot)
if len(revisions) > 0 {
env.Revision = revisions[len(revisions)-1]
}
return *env
}
33 changes: 32 additions & 1 deletion internal/platform/qdenv/qdenv.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
// QodanaLicenseOnlyToken !!! QODANA_LICENSE_ONLY_TOKEN is accessed only by env !!!
QodanaLicenseOnlyToken = "QODANA_LICENSE_ONLY_TOKEN"
QodanaRemoteUrl = "QODANA_REMOTE_URL"
QodanaRepoUrl = "QODANA_REPO_URL"
QodanaDockerEnv = "QODANA_DOCKER"
QodanaToolEnv = "QODANA_TOOL"
QodanaConfEnv = "QODANA_CONF"
Expand Down Expand Up @@ -64,6 +65,14 @@
QodanaToken = "QODANA_TOKEN"
)

// GitEnv contains information about the current git repository.
type GitEnv struct {
RemoteUrl string
RepositoryUrl string
Branch string
Revision string
}

type qodanaGlobalEnv struct {
env map[string]string
}
Expand Down Expand Up @@ -138,7 +147,7 @@
}

// ExtractQodanaEnvironment extracts Qodana environment variables from the current environment.
func ExtractQodanaEnvironment(setEnvironmentFunc func(string, string)) {
func ExtractQodanaEnvironment(gitEnv GitEnv, setEnvironmentFunc func(string, string)) {
if license := os.Getenv(QodanaLicense); license != "" {
setEnvironmentFunc(QodanaLicense, license)
}
Expand Down Expand Up @@ -178,14 +187,36 @@
qEnv = "bitbucket"
setEnvironmentFunc(QodanaJobUrl, GetBitBucketJobUrl())
}
setDefaultQodanaGitEnvironment(gitEnv, setEnvironmentFunc)
setEnvironmentFunc(QodanaEnv, fmt.Sprintf("%s:%s", qEnv, version.Version))
}

func setDefaultQodanaGitEnvironment(gitEnv GitEnv, setEnvironmentFunc func(string, string)) {
if remoteUrl := os.Getenv(QodanaRemoteUrl); remoteUrl == "" {
if gitEnv.RemoteUrl != "" {
setEnvironmentFunc(QodanaRemoteUrl, gitEnv.RemoteUrl)
}
if gitEnv.RepositoryUrl != "" {
setEnvironmentFunc(QodanaRepoUrl, gitEnv.RepositoryUrl)
}
}
if branch := os.Getenv(QodanaBranch); branch == "" {
if gitEnv.Branch != "" {
setEnvironmentFunc(QodanaBranch, gitEnv.Branch)
}
}
if revision := os.Getenv(QodanaRevision); revision == "" {
if gitEnv.Revision != "" {
setEnvironmentFunc(QodanaRevision, gitEnv.Revision)
}
}
}

func GetCIName(ci *cienvironment.CiEnvironment) string {
return strings.ReplaceAll(strings.ToLower(ci.Name), " ", "-")
}

func validateRemoteUrl(remote string, qEnv string) string {

Check warning on line 219 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `validateRemoteUrl` coverage is below the threshold 50%

Check warning on line 219 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `validateRemoteUrl` coverage is below the threshold 50%
if strings.HasPrefix(qEnv, "space") {
return getSpaceRemoteUrl()
}
Expand All @@ -201,7 +232,7 @@
return remote
}

func validateBranch(branch string, env string) string {

Check warning on line 235 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `validateBranch` coverage is below the threshold 50%

Check warning on line 235 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `validateBranch` coverage is below the threshold 50%
if branch == "" {
switch env {
case "github-actions":
Expand Down Expand Up @@ -230,7 +261,7 @@
return ciUrl
}

func UnsetRubyVariables() {

Check warning on line 264 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `UnsetRubyVariables` coverage is below the threshold 50%

Check warning on line 264 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `UnsetRubyVariables` coverage is below the threshold 50%
variables := []string{GemHome, BundleAppConfig}
for _, variable := range variables {
if err := os.Unsetenv(variable); err != nil {
Expand Down Expand Up @@ -283,7 +314,7 @@
}

// IsBitBucketPipe returns true if the current environment is in a working BitBucket Pipe.
func IsBitBucketPipe() bool {

Check warning on line 317 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `IsBitBucketPipe` coverage is below the threshold 50%

Check warning on line 317 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `IsBitBucketPipe` coverage is below the threshold 50%
return os.Getenv("BITBUCKET_PIPE_STORAGE_DIR") != "" || os.Getenv("BITBUCKET_PIPE_SHARED_STORAGE_DIR") != ""
}

Expand All @@ -296,7 +327,7 @@
}

// GetBitBucketCommit returns the BitBucket commit hash.
func GetBitBucketCommit() string {

Check warning on line 330 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketCommit` coverage is below the threshold 50%

Check warning on line 330 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketCommit` coverage is below the threshold 50%
return os.Getenv("BITBUCKET_COMMIT")
}

Expand All @@ -305,10 +336,10 @@
return os.Getenv("BITBUCKET_REPO_FULL_NAME")
}

func GetBitBucketRepoOwner() string {

Check warning on line 339 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketRepoOwner` coverage is below the threshold 50%

Check warning on line 339 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketRepoOwner` coverage is below the threshold 50%
return strutil.SafeSplit(GetBitBucketRepoFullName(), "/", 0)
}

func GetBitBucketRepoName() string {

Check warning on line 343 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketRepoName` coverage is below the threshold 50%

Check warning on line 343 in internal/platform/qdenv/qdenv.go

View workflow job for this annotation

GitHub Actions / Qodana for Go

Check GO source code coverage

Method `GetBitBucketRepoName` coverage is below the threshold 50%
return strutil.SafeSplit(GetBitBucketRepoFullName(), "/", 1)
}
Loading