From a085e935399d0aae4e2efc6fe377d1e90dbb9a9c Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Sun, 29 Nov 2015 01:38:54 -0800 Subject: Fix #34 --- .../rorschach/auditing/AddedFilesAuditor.scala | 32 ++++++++++++++++++---- .../rorschach/server/PullRequestEventHandler.scala | 2 +- 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/main/scala/com/getbootstrap/rorschach/auditing/AddedFilesAuditor.scala b/src/main/scala/com/getbootstrap/rorschach/auditing/AddedFilesAuditor.scala index 5a53206..05ae8d3 100644 --- a/src/main/scala/com/getbootstrap/rorschach/auditing/AddedFilesAuditor.scala +++ b/src/main/scala/com/getbootstrap/rorschach/auditing/AddedFilesAuditor.scala @@ -1,21 +1,41 @@ package com.getbootstrap.rorschach.auditing +import org.eclipse.egit.github.core.CommitFile import com.getbootstrap.rorschach.util._ +import com.getbootstrap.rorschach.github.util._ object AddedFilesAuditor { - private val message = - """[The fact that this pull request adds a new file named something like `new-file.txt` indicates that you were using Bootstrap to test out Git or GitHub, rather than proposing a legitimate change.](https://github.com/twbs/rorschach/blob/master/docs/newfile.md) - |If that's accurate, please **DON'T** do that again! + private val postamble = + """If that's accurate, please **DON'T** do that again! |Instead, [use *your own personal repositories*](https://guides.github.com/activities/hello-world/) to experiment with [how to use Git or GitHub](https://help.github.com/articles/good-resources-for-learning-git-and-github/). |Using the repos of public projects (such as Bootstrap) for such experiments wastes the time of those projects' maintainers |and is thus considered rude.""".stripMargin.replaceAllLiterally("\n", " ") - def audit(addedFilepaths: Set[String]): Seq[String] = { - val filenames = addedFilepaths.map{ filepath => { + private val filenameMessage = "[The fact that this pull request adds a new file named something like `new-file.txt` indicates that you were using Bootstrap to test out Git or GitHub, rather than proposing a legitimate change.](https://github.com/twbs/rorschach/blob/master/docs/newfile.md) " + postamble + + private val undefinedMessage = """[The fact that this pull request adds a new file whose content solely consists of the word "undefined" indicates that you were using Bootstrap to test out Git or GitHub, rather than proposing a legitimate change.](https://github.com/twbs/rorschach/blob/master/docs/undefined-content.md) """ + postamble + + private val sillyUndefPatch = "@@ -0,0 +1 @@\n+undefined\n\\ No newline at end of file" + + def audit(addedFiles: Seq[CommitFile]): Seq[String] = { + auditFilenames(addedFiles.filenames) ++ auditFileContent(addedFiles) + } + + private def auditFilenames(filepaths: Set[String]): Seq[String] = { + val filenames = filepaths.map{ filepath => { filepath.onlyFilename.withoutExtension.replaceAllLiterally("-", "").replaceAllLiterally(" ", "").asciiLowerCased }} if (filenames.contains("newfile")) { - Seq(message) + Seq(filenameMessage) + } + else { + Nil + } + } + + private def auditFileContent(addedFiles: Seq[CommitFile]): Seq[String] = { + if (addedFiles.iterator.exists{ _.getPatch == sillyUndefPatch }) { + Seq(undefinedMessage) } else { Nil diff --git a/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala b/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala index 491b920..4c7d154 100644 --- a/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala +++ b/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala @@ -44,8 +44,8 @@ class PullRequestEventHandler(commenter: ActorRef) extends GitHubActorWithLoggin } case Success(files) => files } + val addedFiles = affectedFiles.filter{ _.status == Added } val modifiedFiles = affectedFiles.filter{ _.status == Modified }.filenames - val addedFiles = affectedFiles.filter{ _.status == Added }.filenames val titleMessages = TitleAuditor.audit(pr.getTitle) val branchMessages = BaseAndHeadBranchesAuditor.audit(baseBranch = bsBase.getRef, headBranch = prHead.getRef) -- cgit v1.2.3