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 1 commit
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 = true
from = 22
to = 5
}
}

email-notifications {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
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}
Expand All @@ -11,17 +15,25 @@ trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDe
def repoData: RepoData
def repo: org.eclipse.jgit.lib.Repository
val repoName = repoData.repoName
val config: CodebragConfig = new CodebragConfig {
def rootConfig = ConfigFactory.load()
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be better to mixin one of the traits here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, brings more simplicity to the code while reading. Going to push the modification.


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()) {
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 +54,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(config.pullSleepPeriodEnabled) {
val currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
currentHour >= config.pullSleepPeriodEnd && currentHour < config.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 = true)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about using false by default? Thus will keep backward comaptibility

lazy val pullSleepPeriodStart = getInt("codebrag.pull-sleep-period.from", 22)
lazy val pullSleepPeriodEnd = getInt("codebrag.pull-sleep-period.from", 5)
}

trait EmailNotificationConfig extends ConfigWithDefault {
Expand Down