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
path: root/src
diff options
context:
space:
mode:
authorChris Rebert <code@chrisrebert.com>2015-11-29 09:58:42 +0300
committerChris Rebert <code@chrisrebert.com>2015-11-29 09:58:58 +0300
commit5c7b52236802686835230ca8c38a9cb2f1f3ef13 (patch)
tree68a8f40665645bfe297a2d78dd0b6d9d2f118b30 /src
parent086e33cb2cd9819cdc466beb6dbdf9ddc5631944 (diff)
Fix #32
Diffstat (limited to 'src')
-rw-r--r--src/main/scala/com/getbootstrap/rorschach/auditing/TitleAuditor.scala25
-rw-r--r--src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala8
-rw-r--r--src/main/scala/com/getbootstrap/rorschach/util/package.scala6
3 files changed, 35 insertions, 4 deletions
diff --git a/src/main/scala/com/getbootstrap/rorschach/auditing/TitleAuditor.scala b/src/main/scala/com/getbootstrap/rorschach/auditing/TitleAuditor.scala
new file mode 100644
index 0000000..0936423
--- /dev/null
+++ b/src/main/scala/com/getbootstrap/rorschach/auditing/TitleAuditor.scala
@@ -0,0 +1,25 @@
+package com.getbootstrap.rorschach.auditing
+
+import com.getbootstrap.rorschach.util._
+
+object TitleAuditor {
+ private val message =
+ """[The title of this pull request strongly suggests 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/title.md)
+ |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(title: String): Seq[String] = {
+ if (
+ title == "Merge pull request #1 from twbs/master"
+ || title.startsWith("Create ")
+ || title.asciiLowerCased == "master"
+ ) {
+ Seq(message)
+ }
+ 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 055fb5c..724f96b 100644
--- a/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala
+++ b/src/main/scala/com/getbootstrap/rorschach/server/PullRequestEventHandler.scala
@@ -1,12 +1,11 @@
package com.getbootstrap.rorschach.server
-import com.getbootstrap.rorschach.auditing.{BaseAndHeadBranchesAuditor, ModifiedFilesAuditor}
-
import scala.collection.JavaConverters._
import scala.util.{Try,Success,Failure}
import akka.actor.ActorRef
import org.eclipse.egit.github.core._
import org.eclipse.egit.github.core.service.{CommitService, OrganizationService}
+import com.getbootstrap.rorschach.auditing._
import com.getbootstrap.rorschach.github._
import com.getbootstrap.rorschach.github.util._
@@ -39,6 +38,8 @@ class PullRequestEventHandler(commenter: ActorRef) extends GitHubActorWithLoggin
val head = prHead.commitSha
val foreignRepoId = prHead.getRepo.repositoryId
+ val titleMessages = TitleAuditor.audit(pr.getTitle)
+ val branchMessages = BaseAndHeadBranchesAuditor.audit(baseBranch = bsBase.getRef, headBranch = prHead.getRef)
val fileMessages = modifiedFilesFor(foreignRepoId, base, head) match {
case Failure(exc) => {
log.error(exc, s"Could not get modified files for commits ${base}...${head} for ${foreignRepoId}")
@@ -48,9 +49,8 @@ class PullRequestEventHandler(commenter: ActorRef) extends GitHubActorWithLoggin
ModifiedFilesAuditor.audit(modifiedFiles)
}
}
- val branchMessages = BaseAndHeadBranchesAuditor.audit(baseBranch = bsBase.getRef, headBranch = prHead.getRef)
- val allMessages = fileMessages ++ branchMessages
+ val allMessages = titleMessages ++ branchMessages ++ fileMessages
if (allMessages.nonEmpty) {
commenter ! PullRequestFeedback(destinationRepo, pr.number, pr.getUser, allMessages)
}
diff --git a/src/main/scala/com/getbootstrap/rorschach/util/package.scala b/src/main/scala/com/getbootstrap/rorschach/util/package.scala
index 0768e9f..2844af5 100644
--- a/src/main/scala/com/getbootstrap/rorschach/util/package.scala
+++ b/src/main/scala/com/getbootstrap/rorschach/util/package.scala
@@ -13,4 +13,10 @@ package object util {
implicit class Utf8ByteArray(bytes: Array[Byte]) {
def utf8String: Try[String] = Try { new String(bytes, utf8) }
}
+
+ implicit class CaseSensitiveString(str: String) {
+ import java.util.Locale
+
+ def asciiLowerCased: String = str.toLowerCase(Locale.ENGLISH)
+ }
}