Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,5 +79,5 @@ H2 console
When using the embedded SQL storage, it may be useful to browse the tables. H2 provides consoles, which can be run
as follows:

1. For a web console, run from sbt: `codebrag-dao/run-h2-console`
1. For a web console, run from sbt: `codebrag-dao/runH2Console`
2. For a command line console, run `java -Dconfig.file=codebrag.conf -cp [path to the fat JAR] com.softwaremill.codebrag.dao.sql.H2ShellConsole`
7 changes: 7 additions & 0 deletions codebrag-rest/src/main/resources/application.conf.template
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ codebrag {

# number of people who need to review a commit (1, 2, ..., all)
required-reviewers-count = 1

# Period during within the repositories won't be fetch
pull-sleep-period {
enabled = false
from = 22
to = 5
}
}

email-notifications {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,38 @@
package com.softwaremill.codebrag.repository

import java.util.Calendar

import com.softwaremill.codebrag.repository.config.RepoData
import com.softwaremill.codebrag.service.config.CodebragConfig
import com.typesafe.config.{Config, ConfigFactory}
import com.typesafe.scalalogging.slf4j.Logging
import org.eclipse.jgit.errors.MissingObjectException
import org.eclipse.jgit.lib.{Constants, ObjectId}
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}

trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDeltaLoader with BranchesModel {
trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDeltaLoader with BranchesModel
with CodebragConfig {

def rootConfig: Config = ConfigFactory.load()
def repoData: RepoData
def repo: org.eclipse.jgit.lib.Repository
val repoName = repoData.repoName

val repoName = repoData.repoName
def pullChanges() {
logger.debug(s"Pulling changes for ${repoData.repoLocation}")
try {
pullChangesForRepo()
logger.debug(s"Changes pulled succesfully")
} catch {
case e: Exception => {
logger.error(s"Cannot pull changes for repo ${repoData.repoLocation} because of: ${e.getMessage}")
throw e

if(canPullAtThisTime()) {
logger.debug(s"Pulling changes for ${repoData.repoLocation}")
try {
pullChangesForRepo()
logger.debug(s"Changes pulled succesfully")
} catch {
case e: Exception => {
logger.error(s"Cannot pull changes for repo ${repoData.repoLocation} because of: ${e.getMessage}")
throw e
}
}
} else {
logger.debug("Current time configuration doesn't allow to pull changes.")
}
}

Expand All @@ -42,6 +53,15 @@ trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDe
protected def pullChangesForRepo()

protected def branchNameToSHA(objId: ObjectId) = ObjectId.toString(objId)

protected def canPullAtThisTime(): Boolean = {
if(this.pullSleepPeriodEnabled) {
val currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
currentHour >= this.pullSleepPeriodEnd && currentHour < this.pullSleepPeriodStart
} else {
true
}
}
}

object Repository {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ trait CodebragConfig extends ConfigWithDefault with StatsConfig with EmailNotifi

lazy val invitationExpiryTime: ReadablePeriod = Period.millis(getMilliseconds("codebrag.invitation-expiry-time", 24.hours.toMillis).toInt)

lazy val pullSleepPeriodEnabled = getBoolean("codebrag.pull-sleep-period.enabled", default = false)
lazy val pullSleepPeriodStart = getInt("codebrag.pull-sleep-period.from", 22)
lazy val pullSleepPeriodEnd = getInt("codebrag.pull-sleep-period.to", 5)
}

trait EmailNotificationConfig extends ConfigWithDefault {
Expand Down