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
4 changes: 2 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
version: 2.1

orbs:
codacy: codacy/base@12.1.2
codacy: codacy/base@12.2.0

references:
circleci_job: &circleci_job
docker:
- image: circleci/circleci-cli:0.1.29041
- image: circleci/circleci-cli:0.1.32638
working_directory: ~/workdir

commands:
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,7 @@ musl.tar.gz
src/graal/bundle
project/metals.sbt
site
.bsp
.bsp

#Ignore vscode AI rules
.github/copilot-instructions.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import play.api.libs.json._
import com.codacy.api.util.JsonOps
import scalaj.http.{Http, HttpOptions}

import java.net.URL
import java.net.{URI, URL}
import scala.util.{Failure, Success, Try}
import scala.util.control.NonFatal

Expand All @@ -23,11 +23,12 @@ class CodacyClient(
private val tokens = Map.empty[String, String] ++
apiToken.map(t => "api-token" -> t) ++
projectToken.map(t => "project-token" -> t) ++
// This is deprecated and is kept for backward compatibility. It will removed in the context of CY-1272
// This is deprecated and is kept for backward compatibility. It will be removed in the context of CY-1272
apiToken.map(t => "api_token" -> t) ++
projectToken.map(t => "project_token" -> t)

private val remoteUrl = new URL(new URL(apiUrl.getOrElse("https://api.codacy.com")), "/2.0").toString()
private val baseUri = new URI(apiUrl.getOrElse("https://api.codacy.com"))
private val remoteUrl = baseUri.resolve("/2.0").toURL.toString

private def httpOptions = if (allowUnsafeSSL) Seq(HttpOptions.allowUnsafeSSL) else Seq.empty

Expand Down Expand Up @@ -66,7 +67,8 @@ class CodacyClient(
case success => success
}
} catch {
case NonFatal(ex) => retryPost(request, value, timeoutOpt, sleepTime, numRetries.map(x => x - 1), ex.getMessage)
case NonFatal(ex) =>
retryPost(request, value, timeoutOpt, sleepTime, numRetries.map(x => x - 1), ex.getMessage)
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/main/scala/com/codacy/rules/ConfigurationRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.codacy.api.OrganizationProvider
import com.codacy.api.client.RequestTimeout

import java.io.File
import java.net.URL
import java.net.{URI, URL}
import scala.util.Try
import wvlet.log.LogSupport
import com.codacy.configuration.parser.{BaseCommandConfig, CommandConfiguration, Final, Report}
Expand Down Expand Up @@ -176,7 +176,13 @@ class ConfigurationRules(cmdConfig: CommandConfiguration, envVars: Map[String, S
* @return true for valid url, false if not
*/
private[rules] def validUrl(baseUrl: String): Boolean = {
Try(new URL(baseUrl)).toOption.isDefined
Try(new URI(baseUrl.trim)).toOption.exists { uri =>
val scheme = uri.getScheme
val host = uri.getHost
scheme != null &&
(scheme.equalsIgnoreCase("http") || scheme.equalsIgnoreCase("https")) &&
host != null && host.nonEmpty
}
}

/**
Expand Down
18 changes: 7 additions & 11 deletions src/main/scala/com/codacy/rules/ReportRules.scala
Original file line number Diff line number Diff line change
Expand Up @@ -329,17 +329,13 @@ class ReportRules(coverageServices: => CoverageServices, gitFileFetcher: GitFile
report: CoverageReport
)(config: ReportConfig, commitUUID: String, acceptableFileNames: Either[String, Seq[String]]): CoverageReport = {
val transformations: Seq[Transformation] = acceptableFileNames
.fold(
error => {
logger.warn(s"Report files will not be matched against git files, reason: $error")
Seq(new PathPrefixer(config.prefix))
},
filenames =>
Seq(new PathPrefixer(config.prefix), {
val acceptableFileNamesMap = filenames.groupBy(getFilenameFromPath).view.toMap
new GitFileNameUpdaterAndFilter(acceptableFileNamesMap)
})
)
.fold(error => {
logger.warn(s"Report files will not be matched against git files, reason: $error")
Seq(new PathPrefixer(config.prefix))
}, filenames => {
val acceptableFileNamesMap = filenames.groupBy(getFilenameFromPath).view.toMap
Seq(new GitFileNameUpdaterAndFilter(acceptableFileNamesMap), new PathPrefixer(config.prefix))
})

transformations.foldLeft(report) { (report, transformation) =>
transformation.execute(report)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class GitHubActionProviderSpec extends AnyWordSpec with Matchers with EitherValu
val envVars = Map(
"GITHUB_EVENT_NAME" -> "pull_request",
"GITHUB_SHA" -> invalidPullRequestCommitUuid,
"GITHUB_EVENT_PATH" -> "src/test/resources/invalid-github-action-pull-request-event.json"
"GITHUB_EVENT_PATH" -> "src/test/resources/invalid-github-action-event.json"
)
val commitUuidEither = provider.getValidCommitUUID(envVars)
commitUuidEither should be(Symbol("left"))
Expand Down