From 5c7b52236802686835230ca8c38a9cb2f1f3ef13 Mon Sep 17 00:00:00 2001 From: Chris Rebert Date: Sat, 28 Nov 2015 22:58:42 -0800 Subject: Fix #32 --- docs/title.md | 13 +++++++++++ .../rorschach/auditing/TitleAuditor.scala | 25 ++++++++++++++++++++++ .../rorschach/server/PullRequestEventHandler.scala | 8 +++---- .../com/getbootstrap/rorschach/util/package.scala | 6 ++++++ 4 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 docs/title.md create mode 100644 src/main/scala/com/getbootstrap/rorschach/auditing/TitleAuditor.scala 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) + } } -- cgit v1.2.3