<commit_before>package actors

import java.util.Locale
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.duration.FiniteDuration
import scala.language.postfixOps
import org.eclipse.jgit.lib.NullProgressMonitor
import org.eclipse.jgit.lib.ProgressMonitor
import org.eclipse.jgit.transport.CredentialsProvider
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
import org.xnap.commons.i18n.I18n
import org.xnap.commons.i18n.I18nFactory
import com.google.inject.Inject
import PushActor.Push
import PushActor.RequestPush
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
import log.PLMLogger
import play.api.Configuration
import play.api.Logger
import plm.core.model.tracking.GitUtils
import java.io.File

/**
 * @author matthieu
 */

object PushActor {
  def props = Props[PushActor]

  case class RequestPush(userUUID: String)
  case class Push()
}

class PushActor @Inject() (configuration: Configuration) extends Actor {
  import PushActor._

  val i18n: I18n = I18nFactory.getI18n(getClass(),"org.plm.i18n.Messages", new Locale("en"), I18nFactory.FALLBACK)

  val home: String = System.getProperty("user.home")
  val gitDirectory: String = ".plm"
  val repoUrl: String = "https://github.com/BuggleInc/PLM-data.git"

  val interval: FiniteDuration = 5 minutes

  val username: String = configuration.getString("plm.github.oauth").getOrElse("dummy-username")
  val password: String = "<PASSWORD>"

  val cp: CredentialsProvider = new UsernamePasswordCredentialsProvider(username, password)
  val progress: ProgressMonitor = NullProgressMonitor.INSTANCE

  val system = ActorSystem("application")
  val cancellable = system.scheduler.schedule(0 seconds, interval, self, Push)

  var pendingRequests: Array[String] = Array[String]()

  def receive = {
    case RequestPush(gitID: String) =>
      if(!pendingRequests.contains(gitID)) {
        pendingRequests = pendingRequests.+:(gitID)
      }
    case Push =>
      pushRepos
      pendingRequests = Array[String]()
    case _ =>
  }

  def pushRepos() {
    pendingRequests.foreach { gitID =>
      val gitUtils: GitUtils = new GitUtils(new Locale("en"))
      val repoPath: String = List(home, gitDirectory, gitID).mkString("/")
      val repoDir: File = new File(repoPath)

      val userBranchHash: String = "PLM" + GitUtils.sha1(gitID)
      gitUtils.openRepo(repoDir)
      gitUtils.pushChanges(userBranchHash, progress, cp)
    }
  }

  override def postStop() = {
    Logger.info("postStop: server stopped - pushing the repos")
    cancellable.cancel
    pushRepos
  }
}<commit_msg>cosmetics: empty the datastructure where you consume the content<commit_after>package actors

import java.util.Locale
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.duration.DurationInt
import scala.concurrent.duration.FiniteDuration
import scala.language.postfixOps
import org.eclipse.jgit.lib.NullProgressMonitor
import org.eclipse.jgit.lib.ProgressMonitor
import org.eclipse.jgit.transport.CredentialsProvider
import org.eclipse.jgit.transport.UsernamePasswordCredentialsProvider
import org.xnap.commons.i18n.I18n
import org.xnap.commons.i18n.I18nFactory
import com.google.inject.Inject
import PushActor.Push
import PushActor.RequestPush
import akka.actor.Actor
import akka.actor.ActorSystem
import akka.actor.Props
import log.PLMLogger
import play.api.Configuration
import play.api.Logger
import plm.core.model.tracking.GitUtils
import java.io.File

/**
 * @author matthieu
 */

object PushActor {
  def props = Props[PushActor]

  case class RequestPush(userUUID: String)
  case class Push()
}

class PushActor @Inject() (configuration: Configuration) extends Actor {
  import PushActor._

  val i18n: I18n = I18nFactory.getI18n(getClass(),"org.plm.i18n.Messages", new Locale("en"), I18nFactory.FALLBACK)

  val home: String = System.getProperty("user.home")
  val gitDirectory: String = ".plm"
  val repoUrl: String = "https://github.com/BuggleInc/PLM-data.git"

  val interval: FiniteDuration = 5 minutes

  val username: String = configuration.getString("plm.github.oauth").getOrElse("dummy-username")
  val password: String = "<PASSWORD>"

  val cp: CredentialsProvider = new UsernamePasswordCredentialsProvider(username, password)
  val progress: ProgressMonitor = NullProgressMonitor.INSTANCE

  val system = ActorSystem("application")
  val cancellable = system.scheduler.schedule(0 seconds, interval, self, Push)

  var pendingRequests: Array[String] = Array[String]()

  def receive = {
    case RequestPush(gitID: String) =>
      if(!pendingRequests.contains(gitID)) {
        pendingRequests = pendingRequests.+:(gitID)
      }
    case Push =>
      pushRepos
    case _ =>
  }

  def pushRepos() {
    pendingRequests.foreach { gitID =>
      val gitUtils: GitUtils = new GitUtils(new Locale("en"))
      val repoPath: String = List(home, gitDirectory, gitID).mkString("/")
      val repoDir: File = new File(repoPath)

      val userBranchHash: String = "PLM" + GitUtils.sha1(gitID)
      gitUtils.openRepo(repoDir)
      gitUtils.pushChanges(userBranchHash, progress, cp)
    }
    pendingRequests = Array[String]()
  }

  override def postStop() = {
    Logger.info("postStop: server stopped - pushing the repos")
    cancellable.cancel
    pushRepos
  }
}
{'fraction_non_alphanumeric': 0.10396131671936024, 'fraction_numerical': 0.00855495629533197, 'mean_word_length': 4.5272353545734845, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '327294', 'n_tokens_mistral': 1680, 'n_tokens_neox': 1631, 'n_words': 368}