Skip to content

Commit 05b2f82

Browse files
authored
fix(longevity) - warped data collected (APP-172) (#95)
1 parent 342736b commit 05b2f82

File tree

3 files changed

+62
-4
lines changed

3 files changed

+62
-4
lines changed

src/main/kotlin/app/hashers/CodeLongevity.kt

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class CodeLine(val repo: Repository,
8686
* Email address of the line's author.
8787
*/
8888
val email : String
89-
get() = to.commit.authorIdent.emailAddress
89+
get() = from.commit.authorIdent.emailAddress
9090

9191
/**
9292
* True if the line is deleted.
@@ -103,9 +103,11 @@ class CodeLine(val repo: Repository,
103103
val td = df.format(Date(to.commit.getCommitTime().toLong() * 1000))
104104
val fc = "${from.commit.getName()} '${from.commit.getShortMessage()}'"
105105
val tc = "${to.commit.getName()} '${to.commit.getShortMessage()}'"
106-
val state = if (isDeleted) "deleted in" else "last known as"
106+
val revState = if (isDeleted) "deleted in" else "last known as"
107+
val state = if (isDeleted) "deleted" else "alive"
107108
return "Line '$text' - '${from.file}:${from.line}' added in $fc $fd\n" +
108-
" ${state} '${to.file}:${to.line}' in $tc $td"
109+
" ${revState} '${to.file}:${to.line}' in $tc $td,\n" +
110+
" age: ${age} ms - $state"
109111
}
110112
}
111113

src/test/kotlin/test/tests/hashers/CodeLongevityTest.kt

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -486,4 +486,60 @@ class CodeLongevityTest : Spek({
486486
testRepo.destroy()
487487
}
488488
}
489+
490+
given("'longevity stats #2'") {
491+
val testRepoPath = "../CodeLongevity_lngstats2"
492+
val testRepo = TestRepo(testRepoPath)
493+
val testRehash = "rehash_lngstats1"
494+
val fileName = "test1.txt"
495+
val author1 = Author(testRepo.userName, testRepo.userEmail)
496+
val author2 = Author("Vasya Pupkin", "[email protected]")
497+
val emails = hashSetOf(author1.email, author2.email)
498+
499+
var serverRepo = Repo(rehash = testRehash)
500+
val mockApi = MockApi(mockRepo = serverRepo)
501+
502+
testRepo.createFile(fileName, listOf("line1", "line2"))
503+
testRepo.commit(message = "initial commit",
504+
author = author1,
505+
date = Calendar.Builder().setTimeOfDay(0, 0, 0).build().time)
506+
507+
testRepo.deleteLines(fileName, 1, 1)
508+
testRepo.commit(message = "delete line",
509+
author = author2,
510+
date = Calendar.Builder().setTimeOfDay(0, 1, 0).build().time)
511+
512+
CodeLongevity(serverRepo, emails, testRepo.git,
513+
{ _ -> fail("exception") }).updateStats(mockApi)
514+
515+
it("'t1'") {
516+
println(mockApi.receivedFacts)
517+
assertTrue(mockApi.receivedFacts.contains(
518+
Fact(repo = serverRepo,
519+
code = FactCodes.LINE_LONGEVITY_REPO,
520+
value = (60).toString())
521+
))
522+
523+
assertTrue(mockApi.receivedFacts.contains(
524+
Fact(repo = serverRepo,
525+
code = FactCodes.LINE_LONGEVITY,
526+
author = author1,
527+
value = (60).toString())
528+
))
529+
530+
assertTrue(mockApi.receivedFacts.contains(
531+
Fact(repo = serverRepo,
532+
code = FactCodes.LINE_LONGEVITY,
533+
author = author2,
534+
value = (0).toString())
535+
))
536+
}
537+
538+
afterGroup {
539+
CodeLongevity(
540+
Repo(rehash = testRehash), emails, testRepo.git,
541+
{ _ -> fail("exception") }).dropSavedData()
542+
testRepo.destroy()
543+
}
544+
}
489545
})

src/test/kotlin/test/tests/hashers/CommitHasherTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ class CommitHasherTest : Spek({
154154
val observable = CommitCrawler.getObservable(gitHasher, repo)
155155
CommitHasher(repo, mockApi, repo.commits.map {it.rehash}, emails)
156156
.updateFromObservable(observable, { e -> errors.add(e) })
157-
157+
158158
it ("has no errors") {
159159
assertEquals(0, errors.size)
160160
}

0 commit comments

Comments
 (0)