Skip to content

Commit 1391650

Browse files
authored
Merge pull request #378 from codacy/skip-commit-uuid-validation
Skip commit UUID validation
2 parents 898409c + 7506d37 commit 1391650

4 files changed

Lines changed: 29 additions & 3 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ Found [Clone] 7 duplicated lines with 10 tokens:
211211
* `--output` - Send the output results to a file
212212
* `--format` [default: text] - Change the output format (e.g. json)
213213
* `--commit-uuid` [default: latest commit of current git branch] - Set the commit UUID that will receive the results on Codacy
214+
* `--skip-commit-uuid-validation` [default: false] - Force using a commit UUID even if it doesn't belong to the current git branch.
214215
* `--upload` [default: false] - Request to push results to Codacy
215216
* `--parallel` [default: 2] - Number of tools to run in parallel
216217
* `--max-allowed-issues` [default: 0] - Maximum number of issues allowed for the analysis to succeed

cli/src/main/scala/com/codacy/analysis/cli/command/AnalyseCommand.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ class AnalyseCommand(analyze: Analyze,
119119
{ repository =>
120120
for {
121121
_ <- validateNoUncommitedChanges(repository, configuration.upload.upload)
122-
_ <- validateGitCommitUuid(repository, analyze.commitUuid)
122+
_ <- validateGitCommitUuid(repository, analyze.commitUuid, analyze.skipCommitUuidValidationValue)
123123
} yield ()
124124
})
125125
}
@@ -146,11 +146,12 @@ class AnalyseCommand(analyze: Analyze,
146146
}
147147

148148
private def validateGitCommitUuid(repository: Repository,
149-
commitUuidOpt: Option[Commit.Uuid]): Either[CLIError, Unit] = {
149+
commitUuidOpt: Option[Commit.Uuid],
150+
skipCommitUuidValidationValue: Boolean): Either[CLIError, Unit] = {
150151
(for {
151152
gitCommit <- repository.latestCommit.toOption
152153
paramCommitUuid <- commitUuidOpt
153-
if gitCommit.commitUuid != paramCommitUuid
154+
if (!skipCommitUuidValidationValue && gitCommit.commitUuid != paramCommitUuid)
154155
} yield {
155156
val error = CLIError.CommitUuidsDoNotMatch(paramCommitUuid, gitCommit.commitUuid)
156157
logger.error(error.message)

cli/src/main/scala/com/codacy/analysis/cli/command/CLIApp.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ final case class Analyze(
142142
output: Option[File] = Option.empty,
143143
@ExtraName("c") @ValueDescription("The commit UUID of the commit that will be analysed")
144144
commitUuid: Option[Commit.Uuid] = Option.empty,
145+
@ExtraName("s") @ValueDescription("[default: false] - Force using a commit UUID")
146+
skipCommitUuidValidation: Int @@ Counter = Tag.of(0),
145147
@ExtraName("u") @ValueDescription("If the results should be uploaded to the API")
146148
upload: Int @@ Counter = Tag.of(0),
147149
@ExtraName("p") @ValueDescription("The number of tools to run in parallel")
@@ -172,6 +174,8 @@ final case class Analyze(
172174
val allowNetworkValue: Boolean = allowNetwork.## > 0
173175
val forceFilePermissionsValue: Boolean = forceFilePermissions.## > 0
174176
val ghCodeScanningCompatValue: Boolean = ghCodeScanningCompat.## > 0
177+
val skipCommitUuidValidationValue: Boolean = skipCommitUuidValidation.## > 0
178+
175179
}
176180

177181
final case class ValidateConfiguration(@Recurse

cli/src/test/scala/com/codacy/analysis/cli/CLISpec.scala

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,26 @@ class CLISpec extends Specification with NoLanguageFeatures with FileMatchers {
347347
}
348348
}
349349

350+
"does not fail when the uuid of the current commit of the git project does not match the one provided by parameter but fails for other reason" in {
351+
withTemporaryGitRepo { directory =>
352+
(for {
353+
_ <- File.temporaryFile(parent = Some(directory))
354+
} yield {
355+
val analyze = Analyze(
356+
options = CommonOptions(),
357+
api = APIOptions(projectToken = Some("hey, im a token"), codacyApiBaseUrl = Some("https://codacy.com")),
358+
tool = None,
359+
directory = Option(directory),
360+
upload = Tag.of(0),
361+
extras = ExtraOptions(),
362+
commitUuid = Option(Commit.Uuid("Aw geez Rick, this isnt the commit uuid!")),
363+
skipCommitUuidValidation = Tag.of(1),
364+
toolTimeout = None)
365+
cli.run(analyze) must beEqualTo(ExitStatus.ExitCodes.failedAnalysis)
366+
}).get
367+
}
368+
}
369+
350370
"cleanup config files after cli run" in {
351371
(for {
352372
directory <- File.temporaryDirectory()

0 commit comments

Comments
 (0)