-
Notifications
You must be signed in to change notification settings - Fork 279
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #202 from sourcerer-io/develop
feat: release new processing flow
- Loading branch information
Showing
14 changed files
with
292 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// Copyright 2018 Sourcerer Inc. All Rights Reserved. | ||
// Author: Liubov Yaronskaya (lyaronskaya@sourcerer.io) | ||
|
||
package app.extractors | ||
|
||
import app.model.CommitStats | ||
import app.model.DiffFile | ||
|
||
class CssExtractor : ExtractorInterface { | ||
companion object { | ||
val LANGUAGE_NAME = "css" | ||
val FILE_EXTS = listOf("css", "scss", "less", "sass") | ||
} | ||
|
||
override fun extract(files: List<DiffFile>): List<CommitStats> { | ||
files.map { file -> file.language = LANGUAGE_NAME } | ||
val stats = FILE_EXTS.filter { it != "css" }.map { extension -> | ||
val result = files.filter { it.extension == extension } | ||
.fold(Pair(0, 0)) { total, file -> | ||
val currentNumAdded = file.getAllAdded() | ||
.filter { it.isNotBlank() }.size | ||
val currentNumDeleted = file.getAllDeleted() | ||
.filter { it.isNotBlank() }.size | ||
Pair(total.first + currentNumAdded, | ||
total.second + currentNumDeleted)}.toList() | ||
|
||
CommitStats(numLinesAdded = result[0], | ||
numLinesDeleted = result[1], | ||
type = Extractor.TYPE_LIBRARY, | ||
tech = extension) | ||
}.filter { it.numLinesAdded > 0 || it.numLinesDeleted > 0 } | ||
|
||
return stats + super.extract(files) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.model | ||
|
||
import app.Protos | ||
import com.google.protobuf.InvalidProtocolBufferException | ||
import java.security.InvalidParameterException | ||
|
||
/** | ||
* Used to describe processing of multiple repos. | ||
*/ | ||
data class Process( | ||
var id: Int = 0, | ||
var requestNumEntries: Int = 0, | ||
var entries: List<ProcessEntry> = mutableListOf() | ||
) { | ||
@Throws(InvalidParameterException::class) | ||
constructor(proto: Protos.Process) : this() { | ||
id = proto.id | ||
requestNumEntries = proto.requestNumEntries | ||
entries = proto.entriesList.map { ProcessEntry(it) } | ||
} | ||
|
||
@Throws(InvalidProtocolBufferException::class) | ||
constructor(bytes: ByteArray) : this(Protos.Process.parseFrom(bytes)) | ||
|
||
constructor(serialized: String) : this(serialized.toByteArray()) | ||
|
||
fun getProto(): Protos.Process { | ||
return Protos.Process.newBuilder() | ||
.setId(id) | ||
.setRequestNumEntries(requestNumEntries) | ||
.addAllEntries(entries.map { it.getProto() }) | ||
.build() | ||
} | ||
|
||
fun serialize(): ByteArray { | ||
return getProto().toByteArray() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package app.model | ||
|
||
import app.Protos | ||
import com.google.protobuf.InvalidProtocolBufferException | ||
import java.security.InvalidParameterException | ||
|
||
/** | ||
* Used to describe processing of a single repo. | ||
*/ | ||
data class ProcessEntry( | ||
var id: Int = 0, | ||
var status: Int = 0, | ||
var errorCode: Int = 0 | ||
) { | ||
@Throws(InvalidParameterException::class) | ||
constructor(proto: Protos.ProcessEntry) : this() { | ||
id = proto.id | ||
status = proto.status | ||
errorCode = proto.errorCode | ||
} | ||
|
||
@Throws(InvalidProtocolBufferException::class) | ||
constructor(bytes: ByteArray) : this(Protos.ProcessEntry.parseFrom(bytes)) | ||
|
||
constructor(serialized: String) : this(serialized.toByteArray()) | ||
|
||
fun getProto(): Protos.ProcessEntry { | ||
return Protos.ProcessEntry.newBuilder() | ||
.setId(id) | ||
.setStatus(status) | ||
.setErrorCode(errorCode) | ||
.build() | ||
} | ||
|
||
fun serialize(): ByteArray { | ||
return getProto().toByteArray() | ||
} | ||
} |
Oops, something went wrong.