<commit_before>package com.softwaremill.codebrag.activities.finders

import org.bson.types.ObjectId
import com.softwaremill.codebrag.common.paging.PagingCriteria
import com.softwaremill.codebrag.dao.commitinfo.CommitInfoDAO
import com.softwaremill.codebrag.domain.User
import com.softwaremill.codebrag.dao.user.UserDAO
import com.typesafe.scalalogging.slf4j.Logging
import CommitToViewImplicits._
import com.softwaremill.codebrag.cache.{UserReviewedCommitsCache, BranchCommitsCache, BranchCommitCacheEntry}
import com.softwaremill.codebrag.service.config.ReviewProcessConfig
import org.joda.time.DateTime
import com.softwaremill.codebrag.domain.CommitAuthorClassification._
import com.softwaremill.codebrag.dao.finders.views.CommitListView

class ToReviewCommitsFinder(
  config: ReviewProcessConfig,
  repoCache: BranchCommitsCache,
  reviewedCommitsCache: UserReviewedCommitsCache,
  commitsInfoDao: CommitInfoDAO,
  val userDao: UserDAO) extends Logging with AuthorDataAppender with FullBranchNameResolver {

  def find(userId: ObjectId, branchName: String, pagingCriteria: PagingCriteria[String]): CommitListView = {
    val toReview = getSHAsOfCommitsToReview(userId, resolveFullBranchName(branchName))
    val page = pagingCriteria.extractPageFrom(toReview)
    val commits = commitsInfoDao.findByShaList(page.items)
    addAuthorData(CommitListView(commits, page.beforeCount, page.afterCount))
  }

  def count(userId: ObjectId, branchName: String): Long = {
    getSHAsOfCommitsToReview(userId, resolveFullBranchName(branchName)).size
  }

  def countForCurrentBranch(userId: ObjectId): Long = {
    val fullBranchName = repoCache.repository.getCheckedOutBranchName
    count(userId, fullBranchName)
  }

  private def getSHAsOfCommitsToReview(userId: ObjectId, fullBranchName: String): List[String] = {
    userDao.findById(userId).map(findShaToReview(fullBranchName, _)).getOrElse(List.empty)
  }

  private def findShaToReview(fullBranchName: String, user: User): List[String] = {
    val userBoundaryDate = reviewedCommitsCache.getUserEntry(user.id).toReviewStartDate
    val commitsInBranch = repoCache.getBranchCommits(fullBranchName)
    commitsInBranch
      .filterNot(userOrDoneCommits(_, user))
      .takeWhile(commitsEarlierThanUserDate(_, userBoundaryDate))
      .filter(notYetFullyReviewed)
      .map(_.sha)
      .reverse
  }
  
  def userOrDoneCommits(commitEntry: BranchCommitCacheEntry, user: User) = {
    commitAuthoredByUser(commitEntry, user) || userAlreadyReviewed(user.id, commitEntry)
  }


  def commitsEarlierThanUserDate(commitEntry: BranchCommitCacheEntry, userBoundaryDate: DateTime): Boolean = {
    commitEntry.commitDate.isAfter(userBoundaryDate) || commitEntry.commitDate.isEqual(userBoundaryDate)
  }

  def notYetFullyReviewed(commitEntry: BranchCommitCacheEntry): Boolean = {
    reviewedCommitsCache.usersWhoReviewed(commitEntry.sha).size < config.requiredReviewersCount
  }
<commit_msg>Minor - name change<commit_after>package com.softwaremill.codebrag.activities.finders

import org.bson.types.ObjectId
import com.softwaremill.codebrag.common.paging.PagingCriteria
import com.softwaremill.codebrag.dao.commitinfo.CommitInfoDAO
import com.softwaremill.codebrag.domain.User
import com.softwaremill.codebrag.dao.user.UserDAO
import com.typesafe.scalalogging.slf4j.Logging
import CommitToViewImplicits._
import com.softwaremill.codebrag.cache.{UserReviewedCommitsCache, BranchCommitsCache, BranchCommitCacheEntry}
import com.softwaremill.codebrag.service.config.ReviewProcessConfig
import org.joda.time.DateTime
import com.softwaremill.codebrag.domain.CommitAuthorClassification._
import com.softwaremill.codebrag.dao.finders.views.CommitListView

class ToReviewCommitsFinder(
  config: ReviewProcessConfig,
  repoCache: BranchCommitsCache,
  reviewedCommitsCache: UserReviewedCommitsCache,
  commitsInfoDao: CommitInfoDAO,
  val userDao: UserDAO) extends Logging with AuthorDataAppender with FullBranchNameResolver {

  def find(userId: ObjectId, branchName: String, pagingCriteria: PagingCriteria[String]): CommitListView = {
    val toReview = getSHAsOfCommitsToReview(userId, resolveFullBranchName(branchName))
    val page = pagingCriteria.extractPageFrom(toReview)
    val commits = commitsInfoDao.findByShaList(page.items)
    addAuthorData(CommitListView(commits, page.beforeCount, page.afterCount))
  }

  def count(userId: ObjectId, branchName: String): Long = {
    getSHAsOfCommitsToReview(userId, resolveFullBranchName(branchName)).size
  }

  def countForCurrentBranch(userId: ObjectId): Long = {
    val fullBranchName = repoCache.repository.getCheckedOutBranchName
    count(userId, fullBranchName)
  }

  private def getSHAsOfCommitsToReview(userId: ObjectId, fullBranchName: String): List[String] = {
    userDao.findById(userId).map(findShaToReview(fullBranchName, _)).getOrElse(List.empty)
  }

  private def findShaToReview(fullBranchName: String, user: User): List[String] = {
    val userBoundaryDate = reviewedCommitsCache.getUserEntry(user.id).toReviewStartDate
    val commitsInBranch = repoCache.getBranchCommits(fullBranchName)
    commitsInBranch
      .filterNot(userOrDoneCommits(_, user))
      .takeWhile(commitsAfterUserDate(_, userBoundaryDate))
      .filter(notYetFullyReviewed)
      .map(_.sha)
      .reverse
  }
  
  def userOrDoneCommits(commitEntry: BranchCommitCacheEntry, user: User) = {
    commitAuthoredByUser(commitEntry, user) || userAlreadyReviewed(user.id, commitEntry)
  }


  def commitsAfterUserDate(commitEntry: BranchCommitCacheEntry, userBoundaryDate: DateTime): Boolean = {
    commitEntry.commitDate.isAfter(userBoundaryDate) || commitEntry.commitDate.isEqual(userBoundaryDate)
  }

  def notYetFullyReviewed(commitEntry: BranchCommitCacheEntry): Boolean = {
    reviewedCommitsCache.usersWhoReviewed(commitEntry.sha).size < config.requiredReviewersCount
  }

{'fraction_non_alphanumeric': 0.08608932833276509, 'fraction_numerical': 0.00034094783498124785, 'mean_word_length': 6.324594257178527, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2567645', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1834, 'n_words': 278}