Skip to content

Commit

Permalink
Rename user flag #3431
Browse files Browse the repository at this point in the history
  • Loading branch information
fritschldwg committed Dec 13, 2023
1 parent e02fab9 commit 7462aea
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 22 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/)
- Multiple values for options need to be separated by comma [#3434](https://github.com/MaibornWolff/codecharta/pull/3434)
- Changed the short-form of the `--no-issues` flag in the SourceCodeParser from `-i` to `-ni` [#3434](https://github.com/MaibornWolff/codecharta/pull/3434)
- Clarify sonar user token question [#3445](https://github.com/MaibornWolff/codecharta/pull/3445)
- Changed the `--user` flag to `--user-token` in SonarImporter [#3445](https://github.com/MaibornWolff/codecharta/pull/3445)

### Fixed 🐞

Expand Down
4 changes: 2 additions & 2 deletions analysis/import/SonarImporter/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Generates visualisation data from SonarQube data through an API call to a SonarQ
| `--merge-modules` | merges modules in multi-module projects |
| `-nc, --not-compressed` | save uncompressed output File |
| `-o, --output-file=<outputFile>` | output File |
| `-u, --user=<user>` | user token for connecting to remote sonar instance |
| `-u, --user-token=<userToken>` | user token for connecting to remote sonar instance |

```
Usage: ccsh sonarimport [-h] [--merge-modules] [-nc] [-o=<outputFile>]
[-u=<user>] [-m=<metrics>]... URL PROJECT_ID
[-u=<userToken>] [-m=<metrics>]... URL PROJECT_ID
```

## Examples
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ class ParserDialog {
hint = "de.foo:bar"
)

val user: String = KInquirer.promptInput(
val userToken: String = KInquirer.promptInput(
message = "What is the sonar user token (sonar.login) required to connect to the remote Sonar instance?",
hint = "sqp_0a81f6490875e062f79ccdeace23ac3c68dac6e"
)
)

val outputFileName: String = KInquirer.promptInput(
message = "What is the name of the output file?",
Expand All @@ -47,7 +47,7 @@ class ParserDialog {
return listOfNotNull(
hostUrl,
projectKey,
if (user.isEmpty()) null else "--user=$user",
if (userToken.isEmpty()) null else "--user-token=$userToken",
"--output-file=$outputFileName",
if (metrics.isEmpty()) null else "--metrics=${eraseWhitespace(metrics)}",
if (isCompressed) null else "--not-compressed",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ class SonarImporterMain(
)
private var metrics = mutableListOf<String>()

@CommandLine.Option(names = ["-u", "--user"], description = ["user token for connecting to remote sonar instance"])
private var user = ""
@CommandLine.Option(names = ["-u", "--user-token"], description = ["user token for connecting to remote sonar instance"])
private var userToken = ""

@CommandLine.Option(
names = ["-nc", "--not-compressed"],
Expand All @@ -86,9 +86,9 @@ class SonarImporterMain(
private fun createMeasuresAPIImporter(): SonarMeasuresAPIImporter {
if (url.endsWith("/")) url = url.substring(0, url.length - 1)
val baseUrl = URL(url)
val version = SonarVersionAPIDatasource(user, baseUrl).getSonarqubeVersion()
val measuresDatasource = SonarMeasuresAPIDatasource(user, baseUrl, version)
val metricsDatasource = SonarMetricsAPIDatasource(user, baseUrl)
val version = SonarVersionAPIDatasource(userToken, baseUrl).getSonarqubeVersion()
val measuresDatasource = SonarMeasuresAPIDatasource(userToken, baseUrl, version)
val metricsDatasource = SonarMetricsAPIDatasource(userToken, baseUrl)
val sonarCodeURLLinker = SonarCodeURLLinker(baseUrl)
val translator = SonarMetricTranslatorFactory.createMetricTranslator()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class ParserDialogTest {
fun `should output correct arguments`() {
val hostUrl = "https://sonar.foo"
val projectKey = "de.foo:bar"
val user = "c123d456"
val userToken = "c123d456"
val outputFileName = "codecharta.cc.json"
val metrics = "metric1, metric2"
val compress = false
Expand All @@ -34,7 +34,7 @@ class ParserDialogTest {
mockkStatic("com.github.kinquirer.components.InputKt")
every {
KInquirer.promptInput(any(), any(), any())
} returns hostUrl andThen projectKey andThen user andThen outputFileName andThen metrics
} returns hostUrl andThen projectKey andThen userToken andThen outputFileName andThen metrics
mockkStatic("com.github.kinquirer.components.ConfirmKt")
every {
KInquirer.promptConfirm(any(), any())
Expand All @@ -46,7 +46,7 @@ class ParserDialogTest {
val parseResult = commandLine.parseArgs(*parserArguments.toTypedArray())
assertEquals(parseResult.matchedPositional(0).getValue<String>(), hostUrl)
assertEquals(parseResult.matchedPositional(1).getValue<String>(), projectKey)
assertEquals(parseResult.matchedOption("user").getValue<String>(), user)
assertEquals(parseResult.matchedOption("user-token").getValue<String>(), userToken)
assertEquals(parseResult.matchedOption("output-file").getValue<String>(), outputFileName)
assertEquals(
parseResult.matchedOption("metrics").getValue<ArrayList<String>>(),
Expand All @@ -60,7 +60,7 @@ class ParserDialogTest {
fun `should omit the metrics flag if the metrics are empty`() {
val hostUrl = "https://sonar.foo"
val projectKey = "de.foo:bar"
val user = "c123d456"
val userToken = "c123d456"
val outputFileName = "codecharta.cc.json"
val metrics = ""
val compress = false
Expand All @@ -69,7 +69,7 @@ class ParserDialogTest {
mockkStatic("com.github.kinquirer.components.InputKt")
every {
KInquirer.promptInput(any(), any(), any())
} returns hostUrl andThen projectKey andThen user andThen outputFileName andThen metrics
} returns hostUrl andThen projectKey andThen userToken andThen outputFileName andThen metrics
mockkStatic("com.github.kinquirer.components.ConfirmKt")
every {
KInquirer.promptConfirm(any(), any())
Expand All @@ -81,18 +81,18 @@ class ParserDialogTest {
val parseResult = commandLine.parseArgs(*parserArguments.toTypedArray())
assertEquals(parseResult.matchedPositional(0).getValue<String>(), hostUrl)
assertEquals(parseResult.matchedPositional(1).getValue<String>(), projectKey)
assertEquals(parseResult.matchedOption("user").getValue<String>(), user)
assertEquals(parseResult.matchedOption("user-token").getValue<String>(), userToken)
assertEquals(parseResult.matchedOption("output-file").getValue<String>(), outputFileName)
assertNull(parseResult.matchedOption("metrics"))
assertEquals(parseResult.matchedOption("not-compressed").getValue<Boolean>(), compress)
assertEquals(parseResult.matchedOption("merge-modules").getValue<Boolean>(), mergeModules)
}

@Test
fun `should omit the user flag if user is empty`() {
fun `should omit the user-tooen flag if user-token is empty`() {
val hostUrl = "https://sonar.foo"
val projectKey = "de.foo:bar"
val user = ""
val userToken = ""
val outputFileName = "codecharta.cc.json"
val metrics = "metric1, metric2"
val compress = false
Expand All @@ -101,7 +101,7 @@ class ParserDialogTest {
mockkStatic("com.github.kinquirer.components.InputKt")
every {
KInquirer.promptInput(any(), any(), any())
} returns hostUrl andThen projectKey andThen user andThen outputFileName andThen metrics
} returns hostUrl andThen projectKey andThen userToken andThen outputFileName andThen metrics
mockkStatic("com.github.kinquirer.components.ConfirmKt")
every {
KInquirer.promptConfirm(any(), any())
Expand All @@ -113,7 +113,7 @@ class ParserDialogTest {
val parseResult = commandLine.parseArgs(*parserArguments.toTypedArray())
assertEquals(parseResult.matchedPositional(0).getValue<String>(), hostUrl)
assertEquals(parseResult.matchedPositional(1).getValue<String>(), projectKey)
assertNull(parseResult.matchedOption("user"))
assertNull(parseResult.matchedOption("user-token"))
assertEquals(parseResult.matchedOption("output-file").getValue<String>(), outputFileName)
assertEquals(
parseResult.matchedOption("metrics").getValue<ArrayList<String>>(),
Expand Down
4 changes: 2 additions & 2 deletions gh-pages/_docs/04-05-sonarimporter.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ The Sonar-Importer generates visualisation data from SonarQube data through an A
| `--merge-modules` | merges modules in multi-module projects |
| `-nc, --not-compressed` | save uncompressed output File |
| `-o, --output-file=<outputFile>` | output File |
| `-u, --user=<user>` | user token for connecting to remote sonar instance |
| `-u, --user-token=<userToken>` | user token for connecting to remote sonar instance |

```
Usage: ccsh sonarimport [-h] [--merge-modules] [-nc] [-o=<outputFile>]
[-u=<user>] [-m=<metrics>]... URL PROJECT_ID
[-u=<userToken>] [-m=<metrics>]... URL PROJECT_ID
```

### Examples
Expand Down

0 comments on commit 7462aea

Please sign in to comment.