Skip to content

Commit 5e8bb0a

Browse files
release: 0.1.0
2 parents 22394d7 + 84d2948 commit 5e8bb0a

File tree

11 files changed

+199
-11
lines changed

11 files changed

+199
-11
lines changed

README.md

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,31 @@
77
</h1>
88

99
<h3 align="center">
10-
Sourcerer app creates an intelligent profile for software engineers.<br/>
11-
Get early access on <a href="https://sourcerer.io">Sourcerer</a>.
10+
Sourcerer app creates an intelligent profile for software engineers
1211
</h3>
1312
<br>
1413

14+
What is it?
15+
===========
16+
17+
Once you feed it some git repos, you will get a beautiful profile that will help
18+
you learn things about yourself, connect to others, and become a better
19+
engineer. Example profiles: <https://sourcerer.io/sergey>,
20+
<https://sourcerer.io/frankie>, <https://sourcerer.io/ice1snice>.
21+
22+
Profile is the first step. Some of the things on our roadmap:
23+
news that is relevant to your code, engineers to follow and learn from,
24+
technology and libraries you should know about, projects
25+
that could use your help.
26+
27+
Both open source and closed source repos are fine. Sourcerer app does not upload
28+
source code anywhere, and it never will. The app looks at repos locally on your
29+
machine, and then sends stats to sourcerer.io. The best way to verify is to
30+
look at the code. [src/main/proto/sourcerer.proto](https://github.com/sourcerer-io/sourcerer-app/blob/develop/src/main/proto/sourcerer.proto)
31+
is a good start as it describes the client-server protocol.
32+
33+
You will need an account, sign up on <https://sourcerer.io/>
34+
1535
Prerequirements
1636
=================
1737

@@ -57,4 +77,4 @@ $ java -jar build/libs/sourcerer-app.jar
5777
Contribution
5878
============
5979

60-
We welcome contributions to Sourcerer App by the community. Check the [Contribution guide](https://github.com/sourcerer-io/sourcerer-app/blob/master/CONTRIBUTING.md)) for more information.
80+
We welcome contributions to Sourcerer App by the community. Check the [Contribution guide](https://github.com/sourcerer-io/sourcerer-app/blob/master/CONTRIBUTING.md) for more information.

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ buildConfig {
3636
buildConfigField 'String', 'PROFILE_URL', 'https://sourcerer.io/'
3737

3838
// App version.
39-
buildConfigField 'int', 'VERSION_CODE', '2'
40-
buildConfigField 'String', 'VERSION', '0.0.2'
39+
buildConfigField 'int', 'VERSION_CODE', '3'
40+
buildConfigField 'String', 'VERSION', '0.1.0'
4141

4242
// Logging.
4343
buildConfigField 'String', 'ENV', project.hasProperty('env') ? env : 'production'

src/install/install

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#!/usr/bin/env bash
12
# Copyright 2017 Sourcerer, Inc. All Rights Reserved.
23
# License: MIT, https://github.com/sourcerer-io/sourcerer-app/blob/master/LICENSE.md
34
# Source code: https://github.com/sourcerer-io
@@ -21,6 +22,7 @@ mkdir -p $JAR_DIR
2122
curl -s $DOWNLOAD_URL > $JAR_DIR/sourcerer.jar
2223

2324
cat <<EOF > $SCRIPT_DIR/sourcerer
25+
#!/usr/bin/env bash
2426
# Copyright 2017 Sourcerer, Inc. All Rights Reserved.
2527
# License: MIT, https://github.com/sourcerer-io/sourcerer-app/blob/master/LICENSE.md
2628
# Source code: https://github.com/sourcerer-io

src/main/kotlin/app/FactCodes.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright 2017 Sourcerer Inc. All Rights Reserved.
22
// Author: Anatoly Kislov ([email protected])
3+
// Author: Liubov Yaronskaya ([email protected])
34

45
package app
56

67
object FactCodes {
78
val COMMIT_DAY_WEEK = 1 // Day of week fun fact and graph.
89
val COMMIT_DAY_TIME = 2 // Day time fun fact.
10+
911
val COMMIT_LINE_NUM_AVG = 8 // Average number of lines per commit fun fact.
1012
val COMMIT_NUM = 9 // Used for averaging COMMIT_LINE_NUM_AVG between repos.
1113
// A map of line numbers to commits number. Used in a commit histogram.
@@ -17,4 +19,8 @@ object FactCodes {
1719
val REPO_DATE_START = 5 // Repo summary info. Date of first contribution.
1820
val REPO_DATE_END = 6 // Repo summary info. Date of last contribution.
1921
val REPO_TEAM_SIZE = 7 // Repo summary info. Number of contributors.
22+
val VARIABLE_NAMING = 13 // Variables naming fun fact.
23+
val VARIABLE_NAMING_SNAKE_CASE = 0
24+
val VARIABLE_NAMING_CAMEL_CASE = 1
25+
val VARIABLE_NAMING_OTHER = 2
2026
}

src/main/kotlin/app/extractors/GoExtractor.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,10 @@ class GoExtractor : ExtractorInterface {
3737
val contentJoined = fileContent.joinToString(separator = "")
3838
multipleImportRegex.findAll(contentJoined).forEach { matchResult ->
3939
imports.addAll(matchResult.groupValues.last()
40-
.split(Regex("""(\t+|\n+|\s+)"""))
40+
.split(Regex("""(\t+|\n+|\s+|")"""))
4141
.filter { it.isNotEmpty() }
42-
.map { it -> it.replace("\"", "") })
42+
.map { it -> it.replace("\"", "") }
43+
.map { it -> if (it.contains("github.com")) it.split("/")[2] else it})
4344
}
4445

4546
return imports.toList()

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/main/kotlin/app/hashers/FactHasher.kt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
// Copyright 2017 Sourcerer Inc. All Rights Reserved.
22
// Author: Anatoly Kislov ([email protected])
3+
// Author: Liubov Yaronskaya ([email protected])
34

45
package app.hashers
56

67
import app.FactCodes
78
import app.Logger
89
import app.api.Api
10+
import app.extractors.Extractor
911
import app.model.Author
1012
import app.model.Commit
1113
import app.model.Fact
@@ -30,6 +32,7 @@ class FactHasher(private val serverRepo: Repo = Repo(),
3032
private val fsLineLenAvg = hashMapOf<String, Double>()
3133
private val fsLineNum = hashMapOf<String, Long>()
3234
private val fsLinesPerCommits = hashMapOf<String, Array<Int>>()
35+
private val fsVariableNaming = hashMapOf<String, Array<Int>>()
3336

3437
init {
3538
for (author in emails) {
@@ -43,6 +46,7 @@ class FactHasher(private val serverRepo: Repo = Repo(),
4346
fsLineNum.put(author, 0)
4447
// TODO(anatoly): Do the bin computations on the go.
4548
fsLinesPerCommits.put(author, Array(rehashes.size) {0})
49+
fsVariableNaming.put(author, Array(3) { 0 })
4650
}
4751
}
4852

@@ -102,6 +106,21 @@ class FactHasher(private val serverRepo: Repo = Repo(),
102106
fsLineNum[email] = fsLineNum[email]!! + lines.size
103107

104108
fsLinesPerCommits[email]!![numCommits - 1] += lines.size
109+
110+
lines.forEach { line ->
111+
val tokens = Extractor().tokenize(line)
112+
val underscores = tokens.count { it.contains('_') }
113+
val camelCases = tokens.count {
114+
!it.contains('_') && it.contains(Regex("[a-z][A-Z]"))
115+
}
116+
val others = tokens.size - underscores - camelCases
117+
fsVariableNaming[email]!![FactCodes.VARIABLE_NAMING_SNAKE_CASE] +=
118+
underscores
119+
fsVariableNaming[email]!![FactCodes.VARIABLE_NAMING_CAMEL_CASE] +=
120+
camelCases
121+
fsVariableNaming[email]!![FactCodes.VARIABLE_NAMING_OTHER] +=
122+
others
123+
}
105124
}
106125

107126
private fun createFacts(): List<Fact> {
@@ -116,6 +135,11 @@ class FactHasher(private val serverRepo: Repo = Repo(),
116135
fs.add(Fact(serverRepo, FactCodes.COMMIT_DAY_WEEK, day,
117136
count.toString(), author))
118137
}}
138+
fsVariableNaming[email]?.forEachIndexed { naming, count -> if (count > 0) {
139+
fs.add(Fact(serverRepo, FactCodes.VARIABLE_NAMING, naming,
140+
count.toString(), author))
141+
}}
142+
119143
fs.add(Fact(serverRepo, FactCodes.REPO_DATE_START, 0,
120144
fsRepoDateStart[email].toString(), author))
121145
fs.add(Fact(serverRepo, FactCodes.REPO_DATE_END, 0,

src/test/kotlin/test/tests/extractors/ExtractorTest.kt

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,36 @@ class ExtractorTest : Spek({
188188
assertExtractsImport(lib, line2, PythonExtractor())
189189
}
190190
}
191+
192+
given("one line import in go file") {
193+
it("extracts library name") {
194+
val lib = "macagon"
195+
val line = "import \"macagon\""
196+
assertExtractsImport(lib, line, GoExtractor())
197+
}
198+
}
199+
200+
given("multiline import in go file") {
201+
it("extracts library name") {
202+
val lib = "macagon"
203+
val lines = listOf("import (",
204+
"\"macagon\"",
205+
"\"github.com/astaxie/beego\"",
206+
")")
207+
val actualLineImports = GoExtractor().extractImports(lines)
208+
assertTrue(lib in actualLineImports)
209+
}
210+
}
211+
212+
given("github url as import in go file") {
213+
it("extracts library name") {
214+
val lib = "beego"
215+
val lines = listOf("import (",
216+
"\"macagon\"",
217+
"\"github.com/astaxie/beego\"",
218+
")")
219+
val actualLineImports = GoExtractor().extractImports(lines)
220+
assertTrue(lib in actualLineImports)
221+
}
222+
}
191223
})

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)