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 09:58:42 +0300
committerChris Rebert <code@chrisrebert.com>2015-11-29 09:58:58 +0300
commit5c7b52236802686835230ca8c38a9cb2f1f3ef13 (patch)
tree68a8f40665645bfe297a2d78dd0b6d9d2f118b30
parent086e33cb2cd9819cdc466beb6dbdf9ddc5631944 (diff)
Fix #32
-rw-r--r--docs/title.md13
-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
4 files changed, 48 insertions, 4 deletions
diff --git a/docs/title.md b/docs/title.md
new file mode 100644
index 0000000..c830d60
--- /dev/null
+++ b/docs/title.md
@@ -0,0 +1,13 @@
+This warning is triggered if the title of a pull request:
+
+* Is exactly "master" (ignoring case)
+* Is exactly "Merge pull request #1 from twbs/master"
+* Starts with "Create" (which is used [when creating a new file from the GitHub web UI](https://help.github.com/articles/creating-new-files/))
+
+These sorts of titles are strongly correlated with pull requests which were created to test out Git or GitHub, rather than proposing any legitimate change to Bootstrap.
+
+If you want to test out Git or GitHub, **[create your own personal repository](https://guides.github.com/activities/hello-world/) and conduct your experiments there instead**, where they won't bother anyone. Using the repositories of public projects (such as Bootstrap) for such experiments wastes the time of those projects' maintainers and is thus considered rude & annoying. Which is why your pull request was automatically closed.
+
+To learn more about using Git or GitHub, check out the links on the following GitHub Help page: https://help.github.com/categories/bootcamp/
+
+(If your legitimate pull request accidentally triggered this message: Our apologies for the inconvenience! You can either open a new pull request with a different title, or ask one of [the Bootstrap Core Team members](http://getbootstrap.com/about/#team) to manually reopen your auto-closed pull request. And thanks for contributing to Bootstrap!)
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)
+ }
}