Skip to content

Commit

Permalink
Log and exit if coverage report not found (#44)
Browse files Browse the repository at this point in the history
  • Loading branch information
mrfyda authored and rtfpessoa committed Jan 12, 2017
1 parent 1fa09b9 commit 055566d
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/main/scala/com/codacy/CodacyCoverageReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import com.codacy.api.{CoverageReport, Language}
import com.codacy.parsers.CoverageParserFactory
import com.codacy.transformation.PathPrefixer
import org.slf4j.LoggerFactory
import scopt.Read
import scopt.{OptionParser, Read}

import scala.util.Try

Expand Down Expand Up @@ -85,7 +85,7 @@ object CodacyCoverageReporter {

}

def buildParser = {
def buildParser: OptionParser[Config] = {
new scopt.OptionParser[Config]("codacy-coverage-reporter") {
head("codacy-coverage-reporter", getClass.getPackage.getImplementationVersion)
opt[Language.Value]('l', "language").required().action { (x, c) =>
Expand Down Expand Up @@ -120,8 +120,6 @@ object CodacyCoverageReporter {
logger.debug(s"Project token: $projectToken")
logger.info(s"Parsing coverage data...")

//TODO: Check if config.coverageReport exists

CoverageParserFactory.withCoverageReport(config.language, rootProjectDir, config.coverageReport)(transform(_)(config) {
report =>
val codacyReportFilename = s"${config.coverageReport.getAbsoluteFile.getParent}${File.separator}codacy-coverage.json"
Expand All @@ -147,13 +145,18 @@ object CodacyCoverageReporter {
}

def codacyCoverage(config: Config): Unit = {
coverageWithTokenAndCommit(config) match {
case Left(error) =>
logger.error(error)
System.exit(1)
case Right(message) =>
logger.info(message)
System.exit(0)
if (config.coverageReport.exists()) {
coverageWithTokenAndCommit(config) match {
case Left(error) =>
logger.error(error)
System.exit(1)
case Right(message) =>
logger.info(message)
System.exit(0)
}
} else {
logger.error(s"File ${config.coverageReport.getName} does not exist.")
System.exit(1)
}
}

Expand Down

0 comments on commit 055566d

Please sign in to comment.