<commit_before>package com.softwaremill.codebrag.rest

import org.scalatra._
import com.softwaremill.codebrag.service.user.Authenticator
import json.JacksonJsonSupport
import swagger.{Swagger, SwaggerSupport}
import com.softwaremill.codebrag.dao.CommitInfoDAO
import com.softwaremill.codebrag.service.github.{GitHubCommitInfoConverter, GitHubCommitImportService}
import org.eclipse.egit.github.core.service.CommitService

import com.softwaremill.codebrag.service.comments.CommentService
import com.softwaremill.codebrag.dao.reporting._
import org.bson.types.ObjectId
import com.softwaremill.codebrag.common.ObjectIdGenerator
import com.softwaremill.codebrag.service.diff.DiffService
import com.softwaremill.codebrag.dao.reporting.CommitListDTO
import scala.Some
import com.softwaremill.codebrag.dao.reporting.CommentListDTO
import com.softwaremill.codebrag.service.diff.FileWithDiff
import com.softwaremill.codebrag.service.comments.command.AddComment

class CommitsServlet(val authenticator: Authenticator, commitInfoDao: CommitInfoDAO,
                     commitListFinder: CommitListFinder,
                     commentListFinder: CommentListFinder,
                     commentService: CommentService, val swagger: Swagger,
                     diffService: DiffService)
  extends JsonServletWithAuthentication with CommitsServletSwaggerDefinition with JacksonJsonSupport {

  get("/") {
    // for all /commits/*
    halt(404)
  }

  post("/:id/comments", operation(addCommentOperation)) {
    haltIfNotAuthenticated
    val commitId = params("id")
    val messageBody = (parsedBody \ "body").extract[String]
    val command = AddComment(new ObjectId(commitId), user.login, messageBody)
    AddCommentResponse(commentService.addCommentToCommit(command))
  }

  get("/:id/comments", operation(getCommentsOperation)) {
    haltIfNotAuthenticated
    val commitId = params("id")
    commentListFinder.findAllForCommit(new ObjectId(commitId))
  }

  get("/", operation(getCommitsOperation)) {
    // for /commits?type=* only
    haltIfNotAuthenticated
    params.get("type") match {<commit_msg>Reject empty comment body on server side<commit_after>package com.softwaremill.codebrag.rest

import org.scalatra._
import com.softwaremill.codebrag.service.user.Authenticator
import json.JacksonJsonSupport
import swagger.{Swagger, SwaggerSupport}
import com.softwaremill.codebrag.dao.CommitInfoDAO
import com.softwaremill.codebrag.service.github.{GitHubCommitInfoConverter, GitHubCommitImportService}
import org.eclipse.egit.github.core.service.CommitService

import com.softwaremill.codebrag.service.comments.CommentService
import com.softwaremill.codebrag.dao.reporting._
import org.bson.types.ObjectId
import com.softwaremill.codebrag.common.ObjectIdGenerator
import com.softwaremill.codebrag.service.diff.DiffService
import com.softwaremill.codebrag.dao.reporting.CommitListDTO
import scala.Some
import com.softwaremill.codebrag.dao.reporting.CommentListDTO
import com.softwaremill.codebrag.service.diff.FileWithDiff
import com.softwaremill.codebrag.service.comments.command.AddComment

class CommitsServlet(val authenticator: Authenticator, commitInfoDao: CommitInfoDAO,
                     commitListFinder: CommitListFinder,
                     commentListFinder: CommentListFinder,
                     commentService: CommentService, val swagger: Swagger,
                     diffService: DiffService)
  extends JsonServletWithAuthentication with CommitsServletSwaggerDefinition with JacksonJsonSupport {

  get("/") {
    // for all /commits/*
    halt(404)
  }

  post("/:id/comments", operation(addCommentOperation)) {
    haltIfNotAuthenticated
    val commitId = params("id")
    val messageBody = extractNotEmptyString("body")
    val command = AddComment(new ObjectId(commitId), user.login, messageBody)
    AddCommentResponse(commentService.addCommentToCommit(command))
  }

  get("/:id/comments", operation(getCommentsOperation)) {
    haltIfNotAuthenticated
    val commitId = params("id")
    commentListFinder.findAllForCommit(new ObjectId(commitId))
  }

  get("/", operation(getCommitsOperation)) {
    // for /commits?type=* only
    haltIfNotAuthenticated
    params.get("type") match {
{'fraction_non_alphanumeric': 0.09023984801709807, 'fraction_numerical': 0.0014248397055331276, 'mean_word_length': 4.777777777777778, 'pattern_counts': {'":': 0, '<': 3, '<?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': '5834903', 'n_tokens_mistral': 1226, 'n_tokens_neox': 1208, 'n_words': 203}