Skip to content

Commit 1e780f0

Browse files
Merge pull request #229 from sourcerer-io/develop
feat: limit max commit diff size, fix windows error, add libs
2 parents 5c547cc + 040517d commit 1e780f0

File tree

7 files changed

+56
-40
lines changed

7 files changed

+56
-40
lines changed

deploy/Jenkinsfile

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
1-
podTemplate(label: 'build-pod-sourcerer-app',
1+
// Copyright 2017 Sourcerer, Inc. All Rights Reserved.
2+
// Author: Maxim Rusak ([email protected])
3+
4+
def label = "sourcerer-app-${UUID.randomUUID().toString()}"
5+
6+
def namespace = 'sandbox'
7+
if (env.BRANCH_NAME == 'master') {
8+
namespace = 'production'
9+
} else if (env.BRANCH_NAME == 'develop') {
10+
namespace = 'staging'
11+
}
12+
13+
podTemplate(label: label,
214
containers: [
315
containerTemplate(name: 'jnlp', image: 'gcr.io/sourcerer-1377/jenkins-slave:v4', args: '${computer.jnlpmac} ${computer.name}'),
416
containerTemplate(name: 'gradle', image: 'gcr.io/sourcerer-1377/gradle:4.2.0', ttyEnabled: true, command: 'tail -f /dev/null')
517
],
618
envVars: [
7-
envVar(key: 'CONTAINER_TAG', value: "${env.BRANCH_NAME}.${env.BUILD_NUMBER}")
19+
envVar(key: 'NAMESPACE', value: namespace),
20+
envVar(key: 'CONTAINER_TAG', value: "${namespace}.${env.BUILD_NUMBER}.${System.currentTimeMillis()}")
821
],
922
volumes: [
1023
hostPathVolume(hostPath: '/var/run/docker.sock', mountPath: '/var/run/docker.sock'),
1124
hostPathVolume(hostPath: '/usr/bin/docker', mountPath: '/usr/bin/docker')
1225
]
1326
) {
14-
node('build-pod-sourcerer-app') {
15-
def namespace = 'sandbox'
16-
def plog = 'debug'
17-
18-
if (env.BRANCH_NAME == 'master') {
19-
namespace = 'production'
20-
plog = 'info'
21-
} else if (env.BRANCH_NAME == 'develop') {
22-
namespace = 'staging'
23-
plog = 'info'
24-
}
25-
27+
node(label) {
2628
stage('checkout') {
2729
checkout scm
2830
}
2931

3032
stage('build jar and test') {
3133
container('gradle') {
32-
sh("LOG=${plog} NAMESPACE=${namespace} ./do.sh build_jar_inside")
34+
sh("./do.sh build_jar_inside")
3335
}
3436
}
3537

@@ -45,7 +47,7 @@ podTemplate(label: 'build-pod-sourcerer-app',
4547

4648
stage('deploy') {
4749
println "Deploying to ${namespace} kubernetes namespace"
48-
sh("NAMESPACE=${namespace} ./do.sh deploy")
50+
sh("./do.sh deploy")
4951
}
5052
}
5153
}

do.sh

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,25 @@
11
#!/bin/bash
22

3-
#-------------------#
4-
#----- Helpers -----#
5-
#-------------------#
3+
# Copyright 2017 Sourcerer, Inc. All Rights Reserved.
4+
# Author: Maxim Rusak ([email protected])
65

76
set -x
87

9-
usage() {
10-
echo "$0 [COMMAND] [ARGUMENTS]"
11-
echo " Commands:"
12-
echo " - build_jar: build jar"
13-
echo " - build_prod_inside: build nginx container"
14-
echo " - run_jar: run jar"
15-
echo " - run_prod: start nginx container"
16-
}
17-
188
fn_exists() {
19-
type $1 2>/dev/null | grep -q 'is a function'
9+
type $1 2>/dev/null | grep -q 'is a function'
2010
}
2111

2212
COMMAND=$1
2313
shift
2414
ARGUMENTS=${@}
2515

26-
TAG="${CONTAINER_TAG:-latest}"
16+
CONTAINER_TAG="${CONTAINER_TAG:-latest}"
2717
NAMESPACE="${NAMESPACE:-sandbox}"
2818
LOG="${LOG:-debug}"
2919
VOLUME="${BUILD_VOLUME:-$PWD}"
3020
PROJECT=sourcerer-app
3121
PORT=3182
32-
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$TAG
22+
REPO_NAME=gcr.io/sourcerer-1377/$PROJECT:$CONTAINER_TAG
3323
GRADLE_VERSION=4.2.0
3424

3525
#--------------------#
@@ -40,12 +30,16 @@ GRADLE_VERSION=4.2.0
4030
build_jar_inside() {
4131
if [ "$NAMESPACE" == "sandbox" ]; then
4232
API="https://sandbox.sourcerer/api/commit"
33+
LOG="debug"
4334
elif [ "$NAMESPACE" == "staging" ]; then
4435
API="https://staging.sourcerer/api/commit"
36+
LOG="info"
4537
elif [ "$NAMESPACE" == "local" ]; then
4638
API="http://localhost:3181"
39+
LOG="debug"
4740
else
4841
API="https://sourcerer.io/api/commit"
42+
LOG="info"
4943
fi
5044
gradle -Penv=$NAMESPACE -Plog=$LOG -Papi=$API build
5145
}
@@ -88,7 +82,7 @@ push() {
8882

8983
fn_exists $COMMAND
9084
if [ $? -eq 0 ]; then
91-
$COMMAND $ARGUMENTS
85+
$COMMAND $ARGUMENTS
9286
else
93-
usage
87+
echo "Command not found"
9488
fi

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

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class CppExtractor : ExtractorInterface {
1818
ExtractorInterface.getMultipleImportsToLibraryMap(LANGUAGE_NAME)
1919
val importRegex = Regex("""^([^\n]*#include)\s[^\n]*""")
2020
val commentRegex = Regex("""^([^\n]*//)[^\n]*""")
21-
val extractImportRegex = Regex("""#include\s+["<](\w+)[/\w+]*\.\w+[">]""")
21+
val extractImportRegex = Regex("""#include\s+["<](\w+)[/\w+]*(\.\w+)?[">]""")
2222
}
2323

2424
override fun extract(files: List<DiffFile>): List<CommitStats> {
@@ -32,12 +32,19 @@ class CppExtractor : ExtractorInterface {
3232
fileContent.forEach {
3333
val res = extractImportRegex.find(it)
3434
if (res != null) {
35-
val lineLib = res.groupValues.last()
35+
val lineLib = res.groupValues
36+
.last { !it.startsWith(".") && it != ""}
3637
imports.add(lineLib)
3738
}
3839
}
39-
4040
val libraries = imports.map { MULTI_IMPORT_TO_LIB.getOrDefault(it, it) }
41+
.map { import -> when {
42+
import.startsWith("Q") -> "Qt"
43+
import.startsWith("Lzma") -> "Lzma"
44+
import.startsWith("Ogre") -> "Ogre"
45+
else -> import
46+
}}
47+
.toSet().toList()
4148
return libraries
4249
}
4350

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ object CommitCrawler {
3939
private val LOCAL_HEAD = "HEAD"
4040
private val REFS = listOf(REMOTE_HEAD, REMOTE_MASTER_BRANCH,
4141
LOCAL_MASTER_BRANCH, LOCAL_HEAD)
42+
private val MAX_DIFF_SIZE = 600000
4243

4344
fun getDefaultBranchHead(git: Git): ObjectId {
4445
for (ref in REFS) {
@@ -169,6 +170,11 @@ object CommitCrawler {
169170
.map { diff ->
170171
JgitDiff(diff, df.toFileHeader(diff).toEditList())
171172
}
173+
.filter { diff ->
174+
diff.editList.fold(0) { acc, edit ->
175+
acc + edit.lengthA + edit.lengthB
176+
} < MAX_DIFF_SIZE
177+
}
172178
subscriber.onNext(JgitPair(commit, diffEdits))
173179
commit = parentCommit
174180
}

src/main/kotlin/app/utils/FileHelper.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,8 @@ object FileHelper {
4747
}
4848

4949
fun getJarPath(): Path {
50-
val fullPathString = URLDecoder.decode(FileHelper::class.java
51-
.protectionDomain.codeSource.location.toURI().path, "UTF-8")
52-
val fullPath = Paths.get(fullPathString)
50+
val fullPathURI = FileHelper::class.java.protectionDomain.codeSource.location.toURI()
51+
val fullPath = Paths.get(fullPathURI)
5352
val root = fullPath.root
5453
// Removing jar filename.
5554
return root.resolve(fullPath.subpath(0, fullPath.nameCount - 1))

src/main/resources/data/libraries/java_libraries.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ com.airbnb.android.react.lottie
4545
zipkin
4646
com.facebook.presto
4747
dagger
48-
junit
48+
org.junit
4949
com.lmax.disruptor
5050
com.jakewharton.rxbinding2
5151
org.physical_web

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,12 @@ class ExtractorTest : Spek({
259259
}
260260
}
261261

262+
given("Qt import in cpp file") {
263+
it("extracts library name") {
264+
val lib = "Qt"
265+
val line = "#include <QFileDialog>"
266+
assertExtractsImport(lib, line, CppExtractor())
267+
}
268+
}
269+
262270
})

0 commit comments

Comments
 (0)