Skip to content

Commit 323c6d4

Browse files
feat: saving of author names (#156)
* feat: sending of author name * fix: emailstate * fix: email add * fix: author contrustor
1 parent 0b0d154 commit 323c6d4

File tree

5 files changed

+31
-11
lines changed

5 files changed

+31
-11
lines changed

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

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
package app.hashers
55

66
import app.Logger
7+
import app.model.Author
78
import app.model.Commit
89
import app.model.DiffContent
910
import app.model.DiffFile
@@ -49,8 +50,8 @@ object CommitCrawler {
4950
throw Exception("No remote default or local master branch found")
5051
}
5152

52-
fun fetchRehashesAndEmails(git: Git):
53-
Pair<LinkedList<String>, HashSet<String>> {
53+
fun fetchRehashesAndAuthors(git: Git):
54+
Pair<LinkedList<String>, HashSet<Author>> {
5455
val head: RevCommit = RevWalk(git.repository)
5556
.parseCommit(getDefaultBranchHead(git))
5657

@@ -59,17 +60,31 @@ object CommitCrawler {
5960

6061
val commitsRehashes = LinkedList<String>()
6162
val emails = hashSetOf<String>()
63+
val names = hashMapOf<String, String>()
6264

6365
var commit: RevCommit? = revWalk.next()
6466
while (commit != null) {
6567
commitsRehashes.add(DigestUtils.sha256Hex(commit.name))
66-
emails.add(commit.authorIdent.emailAddress)
68+
val email = commit.authorIdent.emailAddress
69+
val name = commit.authorIdent.name
70+
if (!emails.contains(email)) {
71+
emails.add(email)
72+
names.put(email, name)
73+
} else {
74+
if (name.length > names[email]!!.length) {
75+
names[email] = name
76+
}
77+
}
78+
6779
commit.disposeBody()
6880
commit = revWalk.next()
6981
}
7082
revWalk.dispose()
7183

72-
return Pair(commitsRehashes, emails)
84+
val authors = emails.map { email -> Author(names[email]!!, email) }
85+
.toHashSet()
86+
87+
return Pair(commitsRehashes, authors)
7388
}
7489

7590
fun getJGitObservable(git: Git,

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class RepoHasher(private val localRepo: LocalRepo, private val api: Api,
3131
Logger.info { "Hashing of repo started" }
3232
val git = loadGit(localRepo.path)
3333
try {
34-
val (rehashes, emails) = CommitCrawler.fetchRehashesAndEmails(git)
34+
val (rehashes, authors) = CommitCrawler.fetchRehashesAndAuthors(git)
3535

3636
localRepo.parseGitConfig(git.repository.config)
3737
initServerRepo(rehashes.last)
@@ -43,8 +43,9 @@ class RepoHasher(private val localRepo: LocalRepo, private val api: Api,
4343
postRepoFromServer()
4444

4545
// Send all repo emails for invites.
46-
postAuthorsToServer(emails)
46+
postAuthorsToServer(authors)
4747

48+
val emails = authors.map { author -> author.email }.toHashSet()
4849
val filteredEmails = filterEmails(emails)
4950

5051
// Common error handling for subscribers.
@@ -106,9 +107,10 @@ class RepoHasher(private val localRepo: LocalRepo, private val api: Api,
106107
Logger.debug { serverRepo.toString() }
107108
}
108109

109-
private fun postAuthorsToServer(emails: HashSet<String>) {
110-
api.postAuthors(emails.map { email ->
111-
Author(email = email, repo = serverRepo)
110+
private fun postAuthorsToServer(authors: HashSet<Author>) {
111+
api.postAuthors(authors.map { author ->
112+
author.repo = serverRepo
113+
author
112114
}).onErrorThrow()
113115
}
114116

src/main/kotlin/app/model/Author.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ data class Author(
1818
@Throws(InvalidParameterException::class)
1919
constructor(proto: Protos.Author) : this() {
2020
email = proto.email
21+
name = proto.name
2122
repo = Repo(proto.repoRehash)
2223
}
2324

@@ -29,6 +30,7 @@ data class Author(
2930
fun getProto(): Protos.Author {
3031
return Protos.Author.newBuilder()
3132
.setEmail(email)
33+
.setName(name)
3234
.setRepoRehash(repo.rehash)
3335
.build()
3436
}

src/main/kotlin/app/ui/EmailState.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ class EmailState constructor(private val context: Context,
5252
configEmails.add(email)
5353
}
5454
// Fetch and save emails from repo for "no-email" warning.
55-
val (_, emails) = CommitCrawler.fetchRehashesAndEmails(git)
56-
reposEmails.put(repo, emails)
55+
val (_, authors) = CommitCrawler.fetchRehashesAndAuthors(git)
56+
reposEmails.put(repo, authors.map { it.email }.toHashSet())
5757
} catch (e: Exception) {
5858
Logger.error(e, "Error while parsing repo")
5959
} finally {

src/main/proto/sourcerer.proto

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ message FactGroup {
7575
// Used to authors for invitational procedures.
7676
message Author {
7777
string email = 1;
78+
string name = 3;
7879
string repo_rehash = 2;
7980
}
8081

0 commit comments

Comments
 (0)