Skip to content
This repository has been archived by the owner on Aug 4, 2021. It is now read-only.

Fix mibexsoftware#102 add renamed binary files and excluded file cases #118

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,12 @@
</dependency>

<!-- Unit tests -->
<dependency>
<groupId>org.scalatest</groupId>
<artifactId>scalatest_2.11</artifactId>
<version>3.0.7</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.specs2</groupId>
<artifactId>specs2_${scala.version}</artifactId>
Expand Down
13 changes: 12 additions & 1 deletion src/main/scala/ch/mibex/bitbucket/sonar/diff/GitDiffParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ object GitDiffParser extends RegexParsers {

case class FileChange(oldFile: String, newFile: String)

case class ExcludePattern(pattern: String)

sealed trait Diff
case class BinaryDiff() extends Diff
case class GitDiff(gitDiffHeader: FileChange, header: ExtendedDiffHeader, hunks: List[Hunk]) extends Diff {
Expand Down Expand Up @@ -57,10 +59,16 @@ object GitDiffParser extends RegexParsers {

def readUpToNextDiffOrEnd = """(?s).+?(?=((?:diff --git)|$))\n?""".r

def binaryDiff: Parser[BinaryDiff] = gitDiffHeader ~ extendedDiffHeader ~ "GIT binary patch" ~ readUpToNextDiffOrEnd ^^ {
def binaryDiff: Parser[BinaryDiff] = gitDiffHeader ~ extendedDiffHeader ~ (("GIT binary patch" ~ readUpToNextDiffOrEnd) | binaryFilesDiff | excludedFile) ^^ {
_ => BinaryDiff()
}

def binaryFilesDiff: Parser[FileChange] = "Binary files " ~> ("""(?:a/)?""".r ~> binaryFilePath <~ " and ") ~ ("""(?:b/)?""".r ~> binaryFilePath <~ " differ") <~ nl ^^ {
case oldF ~ newF => FileChange(oldF, newF)
}

def excludedFile: Parser[ExcludePattern] = "File excluded by pattern " ~> """"(.+?)"""".r <~ nl ^^ { p => ExcludePattern(p) }

def gitDiff: Parser[GitDiff] = gitDiffHeader ~ extendedDiffHeader ~ hunks ^^ {
case fc ~ h ~ hs => GitDiff(fc, h, hs)
}
Expand Down Expand Up @@ -103,6 +111,9 @@ object GitDiffParser extends RegexParsers {

def filePath: Parser[String] = """.+?(?=(\sb/)|(\r?\n))""".r

// Match anything until " and " or " differ"
def binaryFilePath: Parser[String] = """.+?(?=(\sand\s)|(\sdiffer\r?\n))""".r

def similarity: Parser[Int] = """\d{1,3}""".r ^^ { _.toInt }

def hash: Parser[String] = """[0-9a-f]{7,}""".r
Expand Down
17 changes: 17 additions & 0 deletions src/test/resources/diffs/diff-binary-files.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git a/solutions/_templates/hybrid-solution/mvn/login/assets/finantix-logo.png b/solutions/_templates/hybrid/mvn/login/assets/finantix-logo.png
similarity index 100%
rename from solutions/_templates/hybrid-solution/mvn/login/assets/finantix-logo.png
rename to solutions/_templates/hybrid/mvn/login/assets/finantix-logo.png
Binary files a/solutions/_templates/hybrid-solution/mvn/login/assets/finantix-logo.png and b/solutions/_templates/hybrid/mvn/login/assets/finantix-logo.png differ
diff --git a/main.zip b/main.zip
deleted file mode 100644
index 57676e4..0000000
Binary files a/main.zip and /dev/null differ
diff --git a/bitbucket/bitbucket-webhook b/bitbucket/bitbucket-webhook
new file mode 100755
index 0000000..3c461a4
Binary files /dev/null and b/bitbucket/bitbucket-webhook differ
diff --git a/devops/sonarqube/specnet3719.pkl b/devops/sonarqube/specnet3719.pkl
new file mode 100644
index 0000000..2aa668f
Binary files /dev/null and b/devops/sonarqube/specnet3719.pkl differ
3 changes: 3 additions & 0 deletions src/test/resources/diffs/diff-excluded-file.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
diff --git a/ui/pnpm-lock.yaml b/ui/pnpm-lock.yaml
index d1549e0..06b7b7d 100644
File excluded by pattern "pnpm-lock.yaml"
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ch.mibex.bitbucket.sonar.diff

import org.scalatest.FunSuite

class GitDiffParserTest extends FunSuite {
private def readFile(path: String) =
scala.io.Source.fromInputStream(getClass.getResourceAsStream(path)).mkString.replaceAll("\u0085", "")

test("The Binary files differ case should be correctly parsed") {
val response = GitDiffParser.parse(readFile("/diffs/diff-binary-files.txt"))
assert(response.isRight)
}

test("The File excluded by pattern case should be correctly parsed") {
val response = GitDiffParser.parse(readFile("/diffs/diff-excluded-file.txt"))
assert(response.isRight)
}
}