func GetVersionDetails()

in internal/platform/sarifVersioning.go [36:83]


func GetVersionDetails(pwd string) (sarif.VersionControlDetails, error) {
	ret := sarif.VersionControlDetails{}
	if os.Getenv("QODANA_REMOTE_URL") != "" {
		ret.RepositoryUri = os.Getenv("QODANA_REMOTE_URL") // TODO : reuse consts
	} else {
		uri, err := getRepositoryUri(pwd)
		if err != nil {
			return ret, err
		}
		ret.RepositoryUri = uri
	}

	ret.Branch = os.Getenv("QODANA_BRANCH")
	if ret.Branch == "" {
		branch, err := getBranchName(pwd)
		if err != nil {
			return ret, err
		}
		ret.Branch = branch
	}
	// Sometimes in CI the HEAD is detached even on push-based runs.
	// As a last resort, try to pick up the branch name from pre-defined environment variables.
	if ret.Branch == "" {
		ci := cienvironment.DetectCIEnvironment()
		if ci != nil && ci.Git != nil {
			ret.Branch = ci.Git.Branch
		}
	}

	if os.Getenv("QODANA_REVISION") != "" {
		ret.RevisionId = os.Getenv("QODANA_REVISION")
	} else {
		rev, err := getRevisionId(pwd)
		if err != nil {
			return ret, err
		}
		ret.RevisionId = rev
	}

	ret.Properties = &sarif.PropertyBag{}
	ret.Properties.AdditionalProperties = map[string]interface{}{
		"repoUrl":         ret.RepositoryUri,
		"vcsType":         "Git",
		"lastAuthorName":  getLastAuthorName(pwd),
		"lastAuthorEmail": getAuthorEmail(pwd),
	}
	return ret, nil
}