зеркало из https://github.com/twbs/no-carrier.git
initial scaffolding
This commit is contained in:
Коммит
fca34b188b
|
@ -0,0 +1,8 @@
|
|||
# Enforce Unix newlines
|
||||
*.conf text eol=lf
|
||||
*.sbt text eol=lf
|
||||
*.scala text eol=lf
|
||||
*.sh text eol=lf
|
||||
*.md text eol=lf
|
||||
*.txt text eol=lf
|
||||
*.yml text eol=lf
|
|
@ -0,0 +1,18 @@
|
|||
*.class
|
||||
*.log
|
||||
|
||||
# sbt specific
|
||||
.cache/
|
||||
.history/
|
||||
.lib/
|
||||
dist/*
|
||||
target/
|
||||
lib_managed/
|
||||
src_managed/
|
||||
project/boot/
|
||||
project/plugins/project/
|
||||
|
||||
# Scala-IDE specific
|
||||
.scala_dependencies
|
||||
.worksheet
|
||||
.idea
|
|
@ -0,0 +1,3 @@
|
|||
language: scala
|
||||
scala:
|
||||
- 2.10.3
|
|
@ -0,0 +1,21 @@
|
|||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2014 Christopher Rebert
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
|
@ -0,0 +1,4 @@
|
|||
import AssemblyKeys._
|
||||
|
||||
assemblySettings
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
name := "no-carrier"
|
||||
|
||||
version := "1.0"
|
||||
|
||||
scalaVersion := "2.10.4"
|
||||
|
||||
mainClass := Some("com.getbootstrap.no_carrier.Main")
|
||||
|
||||
resolvers ++= Seq("snapshots", "releases").map(Resolver.sonatypeRepo)
|
||||
|
||||
libraryDependencies += "org.eclipse.mylyn.github" % "org.eclipse.egit.github.core" % "2.1.5"
|
||||
|
||||
libraryDependencies += "org.specs2" %% "specs2" % "2.3.12" % "test"
|
||||
|
||||
scalacOptions := Seq("-unchecked", "-deprecation", "-feature", "–Xlint", "-encoding", "utf8")
|
||||
|
||||
scalacOptions in Test ++= Seq("-Yrangepos")
|
||||
|
||||
// parallelExecution in Test := false
|
||||
|
||||
Revolver.settings
|
|
@ -0,0 +1,3 @@
|
|||
addSbtPlugin("io.spray" % "sbt-revolver" % "0.7.1")
|
||||
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.11.2")
|
|
@ -0,0 +1,41 @@
|
|||
package com.getbootstrap.no_carrier
|
||||
|
||||
import scala.util.{Success,Failure}
|
||||
import scala.util.Try
|
||||
import org.eclipse.egit.github.core.RepositoryId
|
||||
import com.getbootstrap.no_carrier.github.{IssueFilters, IssueLabel, Credentials}
|
||||
import com.getbootstrap.no_carrier.github.issues_filter.{All=>AllIssues}
|
||||
import com.getbootstrap.no_carrier.github.issue_state.{All=>OpenOrClosed}
|
||||
import com.getbootstrap.no_carrier.github.util._
|
||||
|
||||
|
||||
object Main extends App {
|
||||
val arguments = args.toSeq
|
||||
val argsPort = arguments match {
|
||||
case Seq(portStr: String) => {
|
||||
Try{ portStr.toInt } match {
|
||||
case Failure(_) => {
|
||||
System.err.println("USAGE: no-carrier <username> <password> <owner/repo> <label> <duration>")
|
||||
System.exit(1)
|
||||
None // dead code
|
||||
}
|
||||
case Success(portNum) => Some(portNum)
|
||||
}
|
||||
}
|
||||
case Seq() => None
|
||||
}
|
||||
implicit val repoId = RepositoryId.createFromId("twbs/bootstrap")
|
||||
val credentials = Credentials("username", "pass")
|
||||
val client = credentials.client
|
||||
implicit val issueService = client.issuesService
|
||||
val labels = Set(new IssueLabel("awaiting reply"))
|
||||
val filters = IssueFilters(filter = AllIssues, state = OpenOrClosed, labels = labels)
|
||||
val issues = issueService.issuesWhere(repoId, filters)
|
||||
for { issue <- issues } {
|
||||
for { event <- issue.events } {
|
||||
event.getEvent
|
||||
"labeled"
|
||||
"unlabeled"
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,11 @@
|
|||
package com.getbootstrap.no_carrier.github
|
||||
|
||||
import org.eclipse.egit.github.core.client.GitHubClient
|
||||
|
||||
case class Credentials(username: String, password: String) {
|
||||
def client = {
|
||||
val c = new GitHubClient()
|
||||
c.setCredentials(username, password)
|
||||
c
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
package com.getbootstrap.no_carrier.github
|
||||
|
||||
import com.getbootstrap.no_carrier.github.issue_state.IssueStateForSearch
|
||||
import com.getbootstrap.no_carrier.github.issues_filter.IssuesFilter
|
||||
|
||||
case class IssueFilters(filter: IssuesFilter, state: IssueStateForSearch, labels: Set[IssueLabel]) {
|
||||
def asFilterData: Map[String, String] = Map(
|
||||
"filter" -> filter.codename,
|
||||
"state" -> state.codename,
|
||||
"labels" -> labels.map{ label => label.name }.mkString(",")
|
||||
)
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.getbootstrap.no_carrier.github
|
||||
|
||||
class IssueLabel(val name: String) extends AnyVal
|
|
@ -0,0 +1,3 @@
|
|||
package com.getbootstrap.no_carrier.github
|
||||
|
||||
class IssueNumber(val number: Int) extends AnyVal
|
|
@ -0,0 +1,18 @@
|
|||
package com.getbootstrap.no_carrier.github.issue_state
|
||||
|
||||
sealed trait IssueStateForSearch {
|
||||
def codename: String
|
||||
}
|
||||
|
||||
object All extends IssueStateForSearch {
|
||||
override def codename = "all"
|
||||
}
|
||||
|
||||
sealed trait IssueState extends IssueStateForSearch
|
||||
|
||||
object Open extends IssueState {
|
||||
override def codename = "open"
|
||||
}
|
||||
object Closed extends IssueState {
|
||||
override def codename = "closed"
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
package com.getbootstrap.no_carrier.github.issues_filter
|
||||
|
||||
sealed trait IssuesFilter {
|
||||
def codename: String
|
||||
}
|
||||
object AssignedToYou extends IssuesFilter {
|
||||
override val codename = "assigned"
|
||||
}
|
||||
object CreatedByYou extends IssuesFilter {
|
||||
override val codename = "created"
|
||||
}
|
||||
object MentioningYou extends IssuesFilter {
|
||||
override val codename = "mentioned"
|
||||
}
|
||||
object SubscribedToByYou extends IssuesFilter {
|
||||
override val codename = "subscribed"
|
||||
}
|
||||
object All extends IssuesFilter {
|
||||
override val codename = "all"
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package com.getbootstrap.no_carrier.github
|
||||
|
||||
import scala.collection.JavaConverters._
|
||||
import org.eclipse.egit.github.core.{RepositoryId, Issue}
|
||||
import org.eclipse.egit.github.core.client.GitHubClient
|
||||
import org.eclipse.egit.github.core.service.IssueService
|
||||
|
||||
package object util {
|
||||
implicit class RichClient(client: GitHubClient) {
|
||||
def issuesService = new IssueService(client)
|
||||
}
|
||||
implicit class RichIssueService(issueService: IssueService) {
|
||||
private def pageIssues(repo: RepositoryId, filters: IssueFilters) = issueService.pageIssues(repo, filters.asFilterData.asJava)
|
||||
def issuesWhere(repo: RepositoryId, filters: IssueFilters): Iterator[Issue] = {
|
||||
val pageIter = pageIssues(repo, filters)
|
||||
val issuesIter = pageIter.iterator().asScala.flatten
|
||||
issuesIter
|
||||
}
|
||||
private def eventPages(repo: RepositoryId, issueNum: IssueNumber) = issueService.pageIssueEvents(repo.getOwner, repo.getName, issueNum.number)
|
||||
def eventsFor(repo: RepositoryId, issueNum: IssueNumber) = issueService.eventPages(repo, issueNum).iterator().asScala.flatten
|
||||
}
|
||||
implicit class RichIssue(issue: Issue) {
|
||||
def number: IssueNumber = new IssueNumber(issue.getNumber)
|
||||
def events(implicit issueService: IssueService, repo: RepositoryId) = issueService.eventsFor(repo, issue.number)
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче