Skip to content

Commit

Permalink
Refactoring: change var names to follow the schema
Browse files Browse the repository at this point in the history
Signed-off-by: Alexander Bezzubov <[email protected]>
  • Loading branch information
bzz committed Mar 5, 2018
1 parent 6aa19ea commit 4685675
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
~*
target/
.idea/
.vscode

metastore_db/
scylla
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/tech/sourced/gemini/Gemini.scala
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,20 @@ object URLFormatter {
"bitbucket.org" -> "https://%s/src/%s/%s",
"gitlab.com" -> "https://%s/blob/%s/%s"
)
private val default = ("", "repo: %s ref_hash: %s file: %s")
private val default = ("", "repo: %s commit: %s path: %s")

def format(repo: String, ref_hash: String, file: String): String = {
def format(repo: String, commit: String, path: String): String = {
val urlTemplateByRepo = services.find { case (h, _) => repo.startsWith(h) }.getOrElse(default)._2
val repoWithoutSuffix = repo.replaceFirst("\\.git$", "")

urlTemplateByRepo.format(repoWithoutSuffix, ref_hash, file)
urlTemplateByRepo.format(repoWithoutSuffix, commit, path)
}
}

case class Meta(sha: String, repo: String, commit: String, path: String)

case class RepoFile(repo: String, ref_hash: String, file: String, sha: String) {
override def toString: String = URLFormatter.format(repo, ref_hash, file)
case class RepoFile(repo: String, commit: String, path: String, sha: String) {
override def toString: String = URLFormatter.format(repo, commit, path)
}

case class DuplicateBlobHash(sha: String, count: Long) {
Expand Down
6 changes: 3 additions & 3 deletions src/test/scala/tech/sourced/gemini/CassandraSparkSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class CassandraSparkSpec extends FlatSpec
sha1.v should not be empty
sha1.v.head.sha should be("097f4a292c384e002c5b5ce8e15d746849af7b37") // git hash-object -w LICENSE
sha1.v.head.repo should be("null/Users/alex/src-d/gemini")
sha1.v.head.ref_hash should be("4aa29ac236c55ebbfbef149fef7054d25832717f")
sha1.v.head.commit should be("4aa29ac236c55ebbfbef149fef7054d25832717f")
}

"Query for duplicates in single repository" should "return 2 files" in {
Expand Down Expand Up @@ -113,7 +113,7 @@ class CassandraSparkSpec extends FlatSpec
val detailedReport = gemini.reportCassandraGroupBy(session).v
println("Done")

val duplicatedFileNames = detailedReport map (_.head.file)
val duplicatedFileNames = detailedReport map (_.head.path)
duplicatedFileNames.toSeq should contain theSameElementsAs expectedDuplicateFiles
}

Expand All @@ -124,7 +124,7 @@ class CassandraSparkSpec extends FlatSpec
val detailedReport = gemini.report(session).v
println("Done")

val duplicatedFileNames = detailedReport map (_.head.file)
val duplicatedFileNames = detailedReport map (_.head.path)
duplicatedFileNames.toSeq should contain theSameElementsAs expectedDuplicateFiles
}

Expand Down
8 changes: 5 additions & 3 deletions src/test/scala/tech/sourced/gemini/URLFormatterSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,18 @@ class URLFormatterSpec extends FlatSpec
with Matchers {

"URLFormatter" should "format correctly" in {
case class Input(repo: String, ref_hash: String, file: String)
case class Input(repo: String, commit: String, path: String)

val cases = Map(
Input("github.com/src-d/test", "sha1", "path/file") -> "https://github.com/src-d/test/blob/sha1/path/file",
Input("gitlab.com/src-d/test", "sha1", "path/file") -> "https://gitlab.com/src-d/test/blob/sha1/path/file",
Input("bitbucket.org/src-d/test", "sha1", "path/file") -> "https://bitbucket.org/src-d/test/src/sha1/path/file",
Input("github.com/src-d/test.git", "sha1", "path/file") -> "https://github.com/src-d/test/blob/sha1/path/file",
Input("unknown", "sha1", "path/file") -> "repo: unknown ref_hash: sha1 file: path/file"
Input("unknown", "sha1", "path/file") -> "repo: unknown commit: sha1 path: path/file"
)

for ((i, expected) <- cases) URLFormatter.format(i.repo, i.ref_hash, i.file) should be(expected)
for ((i, expected) <- cases) {
URLFormatter.format(i.repo, i.commit, i.path) should be(expected)
}
}
}

0 comments on commit 4685675

Please sign in to comment.