Skip to content
This repository was archived by the owner on Apr 27, 2023. It is now read-only.

Commit 689fbff

Browse files
committed
Merge pull request #76 from twasyl/master
Adding the possibility to not pull changes for repositories for a given period and fix readme
2 parents 0b24ab6 + 18ebd49 commit 689fbff

4 files changed

Lines changed: 41 additions & 11 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,5 +79,5 @@ H2 console
7979
When using the embedded SQL storage, it may be useful to browse the tables. H2 provides consoles, which can be run
8080
as follows:
8181

82-
1. For a web console, run from sbt: `codebrag-dao/run-h2-console`
82+
1. For a web console, run from sbt: `codebrag-dao/runH2Console`
8383
2. For a command line console, run `java -Dconfig.file=codebrag.conf -cp [path to the fat JAR] com.softwaremill.codebrag.dao.sql.H2ShellConsole`

codebrag-rest/src/main/resources/application.conf.template

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ codebrag {
2525

2626
# number of people who need to review a commit (1, 2, ..., all)
2727
required-reviewers-count = 1
28+
29+
# Period during within the repositories won't be fetch
30+
pull-sleep-period {
31+
enabled = false
32+
from = 22
33+
to = 5
34+
}
2835
}
2936

3037
email-notifications {

codebrag-service/src/main/scala/com/softwaremill/codebrag/repository/Repository.scala

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,38 @@
11
package com.softwaremill.codebrag.repository
22

3+
import java.util.Calendar
4+
35
import com.softwaremill.codebrag.repository.config.RepoData
6+
import com.softwaremill.codebrag.service.config.CodebragConfig
7+
import com.typesafe.config.{Config, ConfigFactory}
48
import com.typesafe.scalalogging.slf4j.Logging
59
import org.eclipse.jgit.errors.MissingObjectException
610
import org.eclipse.jgit.lib.{Constants, ObjectId}
711
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}
812

9-
trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDeltaLoader with BranchesModel {
13+
trait Repository extends Logging with RepositorySnapshotLoader with RepositoryDeltaLoader with BranchesModel
14+
with CodebragConfig {
1015

16+
def rootConfig: Config = ConfigFactory.load()
1117
def repoData: RepoData
1218
def repo: org.eclipse.jgit.lib.Repository
13-
val repoName = repoData.repoName
1419

20+
val repoName = repoData.repoName
1521
def pullChanges() {
16-
logger.debug(s"Pulling changes for ${repoData.repoLocation}")
17-
try {
18-
pullChangesForRepo()
19-
logger.debug(s"Changes pulled succesfully")
20-
} catch {
21-
case e: Exception => {
22-
logger.error(s"Cannot pull changes for repo ${repoData.repoLocation} because of: ${e.getMessage}")
23-
throw e
22+
23+
if(canPullAtThisTime()) {
24+
logger.debug(s"Pulling changes for ${repoData.repoLocation}")
25+
try {
26+
pullChangesForRepo()
27+
logger.debug(s"Changes pulled succesfully")
28+
} catch {
29+
case e: Exception => {
30+
logger.error(s"Cannot pull changes for repo ${repoData.repoLocation} because of: ${e.getMessage}")
31+
throw e
32+
}
2433
}
34+
} else {
35+
logger.debug("Current time configuration doesn't allow to pull changes.")
2536
}
2637
}
2738

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

4455
protected def branchNameToSHA(objId: ObjectId) = ObjectId.toString(objId)
56+
57+
protected def canPullAtThisTime(): Boolean = {
58+
if(this.pullSleepPeriodEnabled) {
59+
val currentHour = Calendar.getInstance().get(Calendar.HOUR_OF_DAY);
60+
currentHour >= this.pullSleepPeriodEnd && currentHour < this.pullSleepPeriodStart
61+
} else {
62+
true
63+
}
64+
}
4565
}
4666

4767
object Repository {

codebrag-service/src/main/scala/com/softwaremill/codebrag/service/config/CodebragConfig.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ trait CodebragConfig extends ConfigWithDefault with StatsConfig with EmailNotifi
1717

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

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

2225
trait EmailNotificationConfig extends ConfigWithDefault {

0 commit comments

Comments
 (0)