Skip to content

Add ability to handle comments that ask for review #68

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 9, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions github/src/main/scala/scabot/github/GithubApi.scala
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ trait GithubApiTypes extends core.Core {
head: GitRef, base: GitRef, user: User, merged: Option[Boolean], mergeable: Option[Boolean], merged_by: Option[User]) {
override def toString = s"${base.repo}#$number"
}
case class Reviewers(reviewers: List[String])
//, comments: Int, commits: Int, additions: Int, deletions: Int, changed_files: Int)

case class Label(name: String, color: Option[String] = None, url: Option[String] = None) {
Expand Down Expand Up @@ -147,6 +148,7 @@ trait GithubJsonProtocol extends GithubApiTypes with DefaultJsonProtocol with co
implicit lazy val _fmtGitRef : RJF[GitRef] = jsonFormat5(GitRef)

implicit lazy val _fmtPullRequest : RJF[PullRequest] = jsonFormat14(PullRequest)
implicit lazy val _fmtReviewers : RJF[Reviewers] = jsonFormat1(Reviewers)

implicit lazy val _fmtLabel : RJF[Label] = jsonFormat3(Label)
implicit lazy val _fmtMilestone : RJF[Milestone] = jsonFormat9(Milestone.apply)
Expand Down Expand Up @@ -191,6 +193,8 @@ trait GithubApiActions extends GithubJsonProtocol with core.HttpClient {
def pullRequestCommits(nb: Int) = p[List[Commit]] (Get(api("pulls" / nb / "commits")
withQuery Map("per_page" -> "100")))
def deletePRComment(id: String) = px (Delete(api("pulls" / "comments" / id)))
def requestReview(nb: Int, reviewers: Reviewers) = px (Post(api("pulls" / nb / "requested_reviewers"), reviewers)~>
addHeader("Accept", "application/vnd.github.black-cat-preview+json"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

curious what this is about

Copy link
Contributor Author

@teldosas teldosas Feb 9, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's because the PR review API is in Early Access period see here

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah, thanks. I'd suggest commenting this and including the link, since otherwise it will be mysterious to any future maintainer

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I opened #71 for this


def issueComments(nb: Int) = p[List[IssueComment]](Get(api("issues" / nb / "comments")))
def postIssueComment(nb: Int, c: IssueComment) = p[IssueComment] (Post(api("issues" / nb / "comments"), c))
Expand Down
12 changes: 12 additions & 0 deletions server/src/main/scala/scabot/server/Actors.scala
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,11 @@ trait Actors extends github.GithubApi with jenkins.JenkinsApi with lightbend.Lig
import Commands._

if (isLGTM(comment)) synchReviewedLabel(true)
else if (isReviewRequest(comment)) {
val REVIEW_BY(reviewer) = comment.body.toLowerCase
log.debug(s"Review requested from $reviewer")
requestReview(reviewer)
}
else if (!hasCommand(comment.body)) {
log.debug(s"No command in $comment")
Future.successful("No Command found")
Expand Down Expand Up @@ -636,6 +641,13 @@ trait Actors extends github.GithubApi with jenkins.JenkinsApi with lightbend.Lig
// purposefully only at start of line to avoid conditional LGTMs
def isLGTM(comment: IssueComment): Boolean = comment.body.startsWith("LGTM")

final val REVIEW_BY = """^review (?:by )?@(\w+)""".r.unanchored
def isReviewRequest(comment: IssueComment): Boolean = comment.body.toLowerCase match {
case REVIEW_BY(_) => true
case _ => false
}
def requestReview(user: String) = githubApi.requestReview(pr, Reviewers(List(user)))

def hasCommand(body: String) = body.startsWith("/")

final val REBUILD_SHA = """^/rebuild (\w+)""".r.unanchored
Expand Down