Skip to content

Commit 26209b9

Browse files
authored
Merge pull request #441 from codacy/feature/upload-batch-size-param-CY-5727
feature: support issues-only analysis and log upload parsing failures CY-5727
2 parents e63e7c4 + a1a687d commit 26209b9

File tree

3 files changed

+17
-3
lines changed

3 files changed

+17
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ Found [Clone] 7 duplicated lines with 10 tokens:
196196
* `analyze` - Run a Codacy analysis over a directory/files
197197
* `--help` - Displays all the configuration options, their meaning and possible values.
198198
* `--verbose` - Run the tool with verbose output
199-
* `--tool` - [Choose the tool](https://docs.codacy.com/repositories-configure/codacy-configuration-file/#which-tools-can-be-configured-and-which-name-should-i-use) to analyze the code (e.g. brakeman)
199+
* `--tool` - [Choose the tool](https://docs.codacy.com/repositories-configure/codacy-configuration-file/#which-tools-can-be-configured-and-which-name-should-i-use) to analyze the code (e.g. brakeman), or "metrics", "duplication", "issues" to run only a specific tool category
200200
* `--directory` - Choose the directory to be analysed
201201
* `--codacy-api-base-url` or env.`CODACY_API_BASE_URL` - Change the Codacy installation API URL to retrieve the configuration (e.g. Enterprise installation)
202202
* `--output` - Send the output results to a file

cli/src/main/scala/com/codacy/analysis/cli/analysis/ToolSelector.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ class ToolSelector(toolRepository: ToolRepository) {
3434
case Some("duplication") =>
3535
duplicationToolsEither.map(_.map(_.to[ITool]))
3636

37+
case Some("issues") =>
38+
val toolsEither = tools(None, configuration, languages)
39+
toolsEither.map(_.map(_.to[ITool]))
40+
3741
case Some(_) =>
3842
val toolsEither = tools(toolInput, configuration, languages)
3943
toolsEither.map(_.map(_.to[ITool]))

core/src/main/scala/com/codacy/analysis/core/utils/HttpHelper.scala

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ package com.codacy.analysis.core.utils
22

33
import io.circe.parser.parse
44
import io.circe.{Json, ParsingFailure}
5-
import scalaj.http.{Http, HttpRequest, HttpResponse, HttpOptions}
5+
import org.log4s.{Logger, getLogger}
6+
import scalaj.http.{Http, HttpOptions, HttpRequest, HttpResponse}
67

78
class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeSSL: Boolean) {
89

@@ -11,6 +12,8 @@ class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeS
1112

1213
private val remoteUrl = apiUrl + "/2.0"
1314

15+
private val logger: Logger = getLogger
16+
1417
private def httpOptions = if (allowUnsafeSSL) Seq(HttpOptions.allowUnsafeSSL) else Seq.empty
1518

1619
def get(endpoint: String): Either[ParsingFailure, Json] = {
@@ -40,7 +43,14 @@ class HttpHelper(apiUrl: String, extraHeaders: Map[String, String], allowUnsafeS
4043
.headers(headers)
4144
.timeout(connectionTimeoutMs, readTimeoutMs)
4245

43-
parse(request.asString.body)
46+
val response = request.asString
47+
val bodyAsString = response.body
48+
parse(bodyAsString) match {
49+
case failure @ Left(_) =>
50+
logger.warn(s"Post to $endpoint failed. Response was a ${response.code} and returned $bodyAsString")
51+
failure
52+
case success => success
53+
}
4454
}
4555

4656
}

0 commit comments

Comments
 (0)