<commit_before>package com.softwaremill.codebrag.rest

import com.typesafe.scalalogging.slf4j.Logging
import com.softwaremill.codebrag.service.config.{RepositoryConfig, CodebragConfig}
import com.softwaremill.codebrag.dao.{RepositoryStatusDAO, UserDAO}
import org.bson.types.ObjectId
import com.softwaremill.codebrag.service.user.Authenticator
import com.softwaremill.codebrag.service.commits.RepoDataProducer
import org.scalatra.BadRequest
import com.softwaremill.codebrag.domain.RepositoryStatus

class RepoStatusServlet(val authenticator: Authenticator, repoDataProducer: RepoDataProducer, repoStatusDao: RepositoryStatusDAO) extends JsonServletWithAuthentication with Logging {

  get("/") {
    repoDataProducer.createFromConfiguration() match {
      case Some(repoData) => {
        repoStatusDao.getRepoStatus(repoData.repositoryName) match {
          case Some(status) => Map("repoStatus" -> status)
          case None => {
            logger.debug(s"No status found for ${repoData.repositoryName}, assuming it is first run and repo is being cloned at the moment.")
            Map("repoStatus" -> RepositoryStatus.notReady(repoData.repositoryName))
          }
        }
      }
      case None => BadRequest("Cannot get repository information from configuration")
    }
  }

}

object RepoStatusServlet {
  val Mapping = "repoStatus"
}<commit_msg>Tiny refactor of RepoStatusServlet - extract methods for readability<commit_after>package com.softwaremill.codebrag.rest

import com.typesafe.scalalogging.slf4j.Logging
import com.softwaremill.codebrag.service.config.{RepositoryConfig, CodebragConfig}
import com.softwaremill.codebrag.dao.{RepositoryStatusDAO, UserDAO}
import org.bson.types.ObjectId
import com.softwaremill.codebrag.service.user.Authenticator
import com.softwaremill.codebrag.service.commits.{RepoData, RepoDataProducer}
import org.scalatra.BadRequest
import com.softwaremill.codebrag.domain.RepositoryStatus

class RepoStatusServlet(val authenticator: Authenticator, repoDataProducer: RepoDataProducer, repoStatusDao: RepositoryStatusDAO) extends JsonServletWithAuthentication with Logging {

  get("/") {
    repoDataProducer.createFromConfiguration() match {
      case Some(repoData) => getRepositoryStatus(repoData)
      case None => BadRequest("Cannot get repository information from configuration")
    }
  }


  def getRepositoryStatus(repoData: RepoData): Map[String, RepositoryStatus] = {
    repoStatusDao.getRepoStatus(repoData.repositoryName) match {
      case Some(status) => Map("repoStatus" -> status)
      case None => {
        logger.debug(s"No status found for ${repoData.repositoryName}, assuming it is first run and repo is being cloned at the moment.")
        Map("repoStatus" -> RepositoryStatus.notReady(repoData.repositoryName))
      }
    }
  }
}

object RepoStatusServlet {
  val Mapping = "repoStatus"
}
{'fraction_non_alphanumeric': 0.09075043630017451, 'fraction_numerical': 0.0006980802792321117, 'mean_word_length': 4.8370672097759675, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 15, 'https://': 0, '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': '4048479', 'n_tokens_mistral': 832, 'n_tokens_neox': 820, 'n_words': 170}