Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/twbs/rorschach.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Rebert <code@chrisrebert.com>2015-11-29 12:38:54 +0300
committerChris Rebert <code@chrisrebert.com>2015-11-29 12:38:54 +0300
commita085e935399d0aae4e2efc6fe377d1e90dbb9a9c (patch)
tree9024c95a4ef4efcf49a3e13b86c11ab0fc78cd97
parente6531ae380c1540252c5c751a730d7e511b5e1ee (diff)
Fix #34
-rw-r--r--src/main/scala/com/getbootstrap/rorschach/auditing/AddedFilesAuditor.scala32
-rw-r--r--src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala2
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)