Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

introduce debuggable flag #24

Merged
merged 1 commit into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/src/main/java/io/github/tarek360/app/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io.github.tarek360.rules.core.Level.ERROR
fun main(_args: Array<String>) {

val configuration = koshry {
debuggable = true

rules {
rule = protectedFileRule {
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/github/tarek360/core/Logger.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tarek360.core

const val DEBUGGABLE = false
var debuggableLogger = false

val logger: Logger = Logger()

Expand All @@ -15,7 +15,7 @@ class Logger {
}

fun d(msg: () -> String?) {
if (DEBUGGABLE) {
if (debuggableLogger) {
println("$ANSI_WHITE${msg()}$ANSI_RESET")
}
}
Expand Down
31 changes: 19 additions & 12 deletions core/src/main/java/io/github/tarek360/core/cl/CommanderImpl.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,26 @@ import java.io.BufferedReader

class CommanderImpl : Commander {

override fun executeCL(command: String): List<String> {
return execute(command)
}
override fun executeCL(command: String): List<String> {
return execute(command)
}

override fun executeSh(filePath: String) {
override fun executeSh(filePath: String) {

}
}

private fun execute(command: String): List<String> {
logger.d { "command executed: {$command}" }
val proc = Runtime.getRuntime().exec(command)
val lines = proc.inputStream.bufferedReader().use(BufferedReader::readLines)
proc.waitFor()
return lines
}
private fun execute(command: String): List<String> {
logger.d { "COMMAND EXECUTED: {$command}" }
val proc = Runtime.getRuntime().exec(command)
val lines = proc.inputStream.bufferedReader().use(BufferedReader::readLines)
proc.waitFor()
if (lines.isEmpty()) {
logger.e { "COMMAND {$command} HAS NO OUTPUT!" }
} else {
logger.d { "COMMAND OUTPUT LINES:" }
lines.forEach { logger.d { "- $it" } }
logger.d { "------------- OUTPUT END!\n" }
}
return lines
}
}
20 changes: 13 additions & 7 deletions githost/src/main/java/io/github/tarek360/githost/GitHost.kt
Original file line number Diff line number Diff line change
@@ -1,19 +1,25 @@
package io.github.tarek360.githost

interface GitHost {
import io.github.tarek360.core.logger

abstract class GitHost {

init {
logger.d { "GitHost name: ${this.javaClass.typeName}" }
}

/**
*@return Comment URL
*/
fun postComment(comment: Comment): String?
abstract fun postComment(comment: Comment): String?

fun updateComment(comment: Comment, commentId: Int): String?
abstract fun updateComment(comment: Comment, commentId: Int): String?

fun postStatus(status: Status)
abstract fun postStatus(status: Status)

fun pushFile(filePath: String, branchName: String, commitMsg: String)
abstract fun pushFile(filePath: String, branchName: String, commitMsg: String)

fun getPullRequestInfo(): PullRequest?
abstract fun getPullRequestInfo(): PullRequest?

fun getPullRequestComments(): List<GitHostComment>?
abstract fun getPullRequestComments(): List<GitHostComment>?
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ package io.github.tarek360.githost

import io.github.tarek360.core.logger

class UnknownGitHost : GitHost {
class UnknownGitHost : GitHost() {

init {
logger.e { "Unknown GitHostType" }
}

override fun postComment(comment: Comment): String? {
logger.w { "Unknown GitHost: Koshry can't post the report" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import java.net.HttpURLConnection.HTTP_CREATED

var baseUrl = ""

class GitHub(private val gitHostInfo: GitHostInfo, isEnterprise: Boolean = false) : GitHost {
class GitHub(private val gitHostInfo: GitHostInfo, isEnterprise: Boolean = false) : GitHost() {

init {
// if it's not mocked web server
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.tarek360.githost.network

import io.github.tarek360.core.DEBUGGABLE
import io.github.tarek360.core.debuggableLogger
import io.github.tarek360.core.logger
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
Expand All @@ -10,7 +10,7 @@ val okhttp: OkHttpClient by lazy {
val logger = HttpLoggingInterceptor(HttpLoggingInterceptor.Logger { m -> logger.d { m } })
logger.level = HttpLoggingInterceptor.Level.BASIC
val okhttpBuilder = OkHttpClient.Builder()
if(DEBUGGABLE){
if(debuggableLogger){
okhttpBuilder.addInterceptor(logger)
}
okhttpBuilder.build()
Expand Down
7 changes: 7 additions & 0 deletions koshry/src/main/java/io/github/tarek360/koshry/Dsl.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.github.tarek360.koshry

import io.github.tarek360.core.debuggableLogger
import io.github.tarek360.rules.core.Rule
import io.github.tarek360.rules.core.RuleDsl

Expand All @@ -18,6 +19,12 @@ class KoshryBuilder {
var baseSha = ""
var headSha = ""

var debuggable = false
set(value) {
field = value
debuggableLogger = value
}

private val rules = ArrayList<Rule>()

fun rules(block: RULES.() -> Unit) {
Expand Down
4 changes: 2 additions & 2 deletions koshry/src/main/java/io/github/tarek360/koshry/Koshry.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Koshry {
val runner = KoshryRunner()
if (ci != null) {
logger.i { "${ci.javaClass.simpleName} is detected!" }
logger.i { "Koshry started running on ${ci.javaClass.simpleName}.." }
logger.i { "Koshry has started to run on ${ci.javaClass.simpleName}.." }

val gitHostInfo = GitHostInfoProvider(ci, CommanderImpl(), GitRemoteUrlParser()).provide()

Expand All @@ -23,7 +23,7 @@ class Koshry {

runner.runOnCi(ci, koshryConfig, gitHostInfo, gitHostController)
} else {
logger.i { "Koshry started running locally.." }
logger.i { "Koshry has started to run locally.." }
runner.runLocally(koshryConfig)
}
}
Expand Down
4 changes: 4 additions & 0 deletions koshry/src/main/java/io/github/tarek360/koshry/RulesMan.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ class RulesMan(
rules: List<Rule>)
: Comment {

if (baseSha.isBlank() || headSha.isBlank()) {
return Comment("No SHA, No diff, No Report", true)
}

var shouldFail = false
val gitDiff = GitDiffProvider.provide(baseSha, headSha)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,11 @@ open class GitHostInfoProvider(private val ci: Ci,
logger.e { "Cant't find owner name and/or repo name in environment variables." }
}
if (token == null) {
logger.e { "Cant't 'KOSHRY_GIT_HOST_TOKEN' in environment variables." }
logger.e { "Cant't find 'KOSHRY_GIT_HOST_TOKEN' in environment variables." }
}

logger.d { "pullRequestId $pullRequestId, ownerNameRepoName $ownerNameRepoName, token $token" }

return GitHostInfo(
domain = gitRemoteOrigin?.domain,
ownerNameRepoName = ownerNameRepoName,
Expand Down