11package com .softwaremill .codebrag .repository
22
3+ import java .util .Calendar
4+
35import com .softwaremill .codebrag .repository .config .RepoData
6+ import com .softwaremill .codebrag .service .config .CodebragConfig
7+ import com .typesafe .config .{Config , ConfigFactory }
48import com .typesafe .scalalogging .slf4j .Logging
59import org .eclipse .jgit .errors .MissingObjectException
610import org .eclipse .jgit .lib .{Constants , ObjectId }
711import 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
4767object Repository {
0 commit comments