call web hook on issue or pull_request both opened or closed. and issue_comment.

This commit is contained in:
nazoking
2015-01-08 15:09:21 +09:00
parent b512e7c390
commit 321a3a72f0
7 changed files with 260 additions and 106 deletions

View File

@@ -12,11 +12,11 @@ import model.Issue
class IssuesController extends IssuesControllerBase class IssuesController extends IssuesControllerBase
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with WebHookIssueCommentService
trait IssuesControllerBase extends ControllerBase { trait IssuesControllerBase extends ControllerBase {
self: IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService self: IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator => with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with WebHookIssueCommentService =>
case class IssueCreateForm(title: String, content: Option[String], case class IssueCreateForm(title: String, content: Option[String],
assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String]) assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String])
@@ -109,9 +109,12 @@ trait IssuesControllerBase extends ControllerBase {
// record activity // record activity
recordCreateIssueActivity(owner, name, userName, issueId, form.title) recordCreateIssueActivity(owner, name, userName, issueId, form.title)
// extract references and create refer comment
getIssue(owner, name, issueId.toString).foreach { issue => getIssue(owner, name, issueId.toString).foreach { issue =>
// extract references and create refer comment
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse("")) createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""))
// call web hooks
callIssuesWebHook("opened", repository, issue, context.baseUrl, context.loginAccount.get)
} }
// notifications // notifications
@@ -364,6 +367,22 @@ trait IssuesControllerBase extends ControllerBase {
createReferComment(owner, name, issue, content) createReferComment(owner, name, issue, content)
} }
// call web hooks
action match {
case None => callIssueCommentWebHook(repository, issue, commentId, context.loginAccount.get)
case Some(act) => val webHookAction = act match {
case "open" => "opened"
case "reopen" => "reopened"
case "close" => "closed"
case _ => act
}
if(issue.isPullRequest){
callPullRequestWebHook(webHookAction, repository, issue.issueId, context.baseUrl, context.loginAccount.get)
} else {
callIssuesWebHook(webHookAction, repository, issue, context.baseUrl, context.loginAccount.get)
}
}
// notifications // notifications
Notifier() match { Notifier() match {
case f => case f =>
@@ -416,5 +435,4 @@ trait IssuesControllerBase extends ControllerBase {
hasWritePermission(owner, repoName, context.loginAccount)) hasWritePermission(owner, repoName, context.loginAccount))
} }
} }
} }

View File

@@ -23,11 +23,11 @@ import model.{PullRequest, Issue}
class PullRequestsController extends PullRequestsControllerBase class PullRequestsController extends PullRequestsControllerBase
with RepositoryService with AccountService with IssuesService with PullRequestService with MilestonesService with LabelsService with RepositoryService with AccountService with IssuesService with PullRequestService with MilestonesService with LabelsService
with CommitsService with ActivityService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator with CommitsService with ActivityService with WebHookPullRequestService with ReferrerAuthenticator with CollaboratorsAuthenticator
trait PullRequestsControllerBase extends ControllerBase { trait PullRequestsControllerBase extends ControllerBase {
self: RepositoryService with AccountService with IssuesService with MilestonesService with LabelsService self: RepositoryService with AccountService with IssuesService with MilestonesService with LabelsService
with CommitsService with ActivityService with PullRequestService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator => with CommitsService with ActivityService with PullRequestService with WebHookPullRequestService with ReferrerAuthenticator with CollaboratorsAuthenticator =>
private val logger = LoggerFactory.getLogger(classOf[PullRequestsControllerBase]) private val logger = LoggerFactory.getLogger(classOf[PullRequestsControllerBase])
@@ -193,9 +193,7 @@ trait PullRequestsControllerBase extends ControllerBase {
closeIssuesFromMessage(form.message, loginAccount.userName, owner, name) closeIssuesFromMessage(form.message, loginAccount.userName, owner, name)
} }
// call web hook // call web hook
getPullRequest(repository.owner, repository.name, issueId).map{ case (issue, pr) => callPullRequestWebHook("closed", repository, issueId, context.baseUrl, context.loginAccount.get)
callPullRequestWebHook("closed", repository, issue, pr, context.baseUrl, context.loginAccount.get)
}
// notifications // notifications
Notifier().toNotify(repository, issueId, "merge"){ Notifier().toNotify(repository, issueId, "merge"){
@@ -354,9 +352,7 @@ trait PullRequestsControllerBase extends ControllerBase {
recordPullRequestActivity(repository.owner, repository.name, loginUserName, issueId, form.title) recordPullRequestActivity(repository.owner, repository.name, loginUserName, issueId, form.title)
// call web hook // call web hook
getPullRequest(repository.owner, repository.name, issueId).map{ case (issue, pr) => callPullRequestWebHook("opend", repository, issueId, context.baseUrl, context.loginAccount.get)
callPullRequestWebHook("opend", repository, issue, pr, context.baseUrl, context.loginAccount.get)
}
// notifications // notifications
Notifier().toNotify(repository, issueId, form.content.getOrElse("")){ Notifier().toNotify(repository, issueId, form.content.getOrElse("")){
@@ -480,31 +476,4 @@ trait PullRequestsControllerBase extends ControllerBase {
repository, repository,
hasWritePermission(owner, repoName, context.loginAccount)) hasWritePermission(owner, repoName, context.loginAccount))
} }
private def callPullRequestWebHook(action: String, repository: RepositoryService.RepositoryInfo, issue: Issue, pullRequest: PullRequest, baseUrl: String, sender: model.Account): Unit = {
import WebHookService._
getWebHookURLs(repository.owner, repository.name) match {
case webHookURLs if(webHookURLs.nonEmpty) =>
def findOwner(owner: String, knowns: Seq[model.Account]): Option[model.Account] = knowns.find(_.fullName == owner).orElse(getAccountByUserName(owner))
for{
baseOwner <- findOwner(repository.owner, Seq(sender))
headOwner <- findOwner(pullRequest.requestUserName, Seq(sender, baseOwner))
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl)
} yield {
val payload = WebHookPullRequestPayload(
action = action,
issue = issue,
pullRequest = pullRequest,
headRepository = headRepo,
headOwner = headOwner,
baseRepository = repository,
baseOwner = baseOwner,
sender = sender)
for(ownerAccount <- getAccountByUserName(repository.owner)){
callWebHook("pull_request", webHookURLs, payload)
}
}
case _ =>
}
}
} }

View File

@@ -7,7 +7,7 @@ import util.{LockUtil, UsersAuthenticator, OwnerAuthenticator}
import jp.sf.amateras.scalatra.forms._ import jp.sf.amateras.scalatra.forms._
import org.apache.commons.io.FileUtils import org.apache.commons.io.FileUtils
import org.scalatra.i18n.Messages import org.scalatra.i18n.Messages
import service.WebHookService.WebHookPayload import service.WebHookService.WebHookPushPayload
import util.JGitUtil.CommitInfo import util.JGitUtil.CommitInfo
import util.ControlUtil._ import util.ControlUtil._
import org.eclipse.jgit.api.Git import org.eclipse.jgit.api.Git
@@ -168,7 +168,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
getAccountByUserName(repository.owner).foreach { ownerAccount => getAccountByUserName(repository.owner).foreach { ownerAccount =>
callWebHook("push", callWebHook("push",
List(model.WebHook(repository.owner, repository.name, form.url)), List(model.WebHook(repository.owner, repository.name, form.url)),
WebHookPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount) WebHookPushPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount)
) )
} }
flash += "url" -> form.url flash += "url" -> form.url

View File

@@ -17,7 +17,7 @@ import org.eclipse.jgit.treewalk._
import jp.sf.amateras.scalatra.forms._ import jp.sf.amateras.scalatra.forms._
import org.eclipse.jgit.dircache.DirCache import org.eclipse.jgit.dircache.DirCache
import org.eclipse.jgit.revwalk.RevCommit import org.eclipse.jgit.revwalk.RevCommit
import service.WebHookService.WebHookPayload import service.WebHookService.WebHookPushPayload
class RepositoryViewerController extends RepositoryViewerControllerBase class RepositoryViewerController extends RepositoryViewerControllerBase
with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
@@ -504,13 +504,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
// call web hook // call web hook
val commit = new JGitUtil.CommitInfo(JGitUtil.getRevCommitFromId(git, commitId)) val commit = new JGitUtil.CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))
getWebHookURLs(repository.owner, repository.name) match { callWebHookOf(repository.owner, repository.name, "push") {
case webHookURLs if(webHookURLs.nonEmpty) => getAccountByUserName(repository.owner).map{ ownerAccount =>
for(ownerAccount <- getAccountByUserName(repository.owner)){ WebHookPushPayload(git, loginAccount, headName, repository, List(commit), ownerAccount)
callWebHook("push", webHookURLs,
WebHookPayload(git, loginAccount, headName, repository, List(commit), ownerAccount))
} }
case _ =>
} }
} }
} }

View File

@@ -77,6 +77,16 @@ trait AccountService {
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] = def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
Accounts filter(t => (t.userName === userName.bind) && (t.removed === false.bind, !includeRemoved)) firstOption Accounts filter(t => (t.userName === userName.bind) && (t.removed === false.bind, !includeRemoved)) firstOption
def getAccountsByUserNames(userNames: Set[String], knowns:Set[Account], includeRemoved: Boolean = false)(implicit s: Session): Map[String, Account] = {
val map = knowns.map(a => a.userName -> a).toMap
val needs = userNames -- map.keySet
if(needs.isEmpty){
map
}else{
map ++ Accounts.filter(t => (t.userName inSetBind needs) && (t.removed === false.bind, !includeRemoved)).list.map(a => a.userName -> a).toMap
}
}
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] = def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
Accounts filter(t => (t.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) && (t.removed === false.bind, !includeRemoved)) firstOption Accounts filter(t => (t.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) && (t.removed === false.bind, !includeRemoved)) firstOption

View File

@@ -2,7 +2,7 @@ package service
import model.Profile._ import model.Profile._
import profile.simple._ import profile.simple._
import model.{WebHook, Account, Issue, PullRequest} import model.{WebHook, Account, Issue, PullRequest, IssueComment}
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import service.RepositoryService.RepositoryInfo import service.RepositoryService.RepositoryInfo
import util.JGitUtil import util.JGitUtil
@@ -12,6 +12,7 @@ import org.eclipse.jgit.api.Git
import org.apache.http.message.BasicNameValuePair import org.apache.http.message.BasicNameValuePair
import org.apache.http.client.entity.UrlEncodedFormEntity import org.apache.http.client.entity.UrlEncodedFormEntity
import org.apache.http.NameValuePair import org.apache.http.NameValuePair
import java.util.Date
trait WebHookService { trait WebHookService {
import WebHookService._ import WebHookService._
@@ -27,6 +28,13 @@ trait WebHookService {
def deleteWebHookURL(owner: String, repository: String, url :String)(implicit s: Session): Unit = def deleteWebHookURL(owner: String, repository: String, url :String)(implicit s: Session): Unit =
WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete WebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete
def callWebHookOf(owner: String, repository: String, eventName: String)(makePayload: => Option[WebHookPayload])(implicit s: Session): Unit = {
val webHookURLs = getWebHookURLs(owner, repository)
if(webHookURLs.nonEmpty){
makePayload.map(callWebHook(eventName, webHookURLs, _))
}
}
def callWebHook(eventName: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = { def callWebHook(eventName: String, webHookURLs: List[WebHook], payload: WebHookPayload): Unit = {
import org.json4s._ import org.json4s._
import org.json4s.jackson.Serialization import org.json4s.jackson.Serialization
@@ -67,13 +75,85 @@ trait WebHookService {
} }
logger.debug("end callWebHook") logger.debug("end callWebHook")
} }
}
trait WebHookPullRequestService extends WebHookService {
self: AccountService with RepositoryService with PullRequestService with IssuesService =>
// https://developer.github.com/v3/activity/events/types/#issuesevent
def callIssuesWebHook(action: String, repository: RepositoryService.RepositoryInfo, issue: Issue, baseUrl: String, sender: model.Account)(implicit s: Session): Unit = {
import WebHookService._
callWebHookOf(repository.owner, repository.name, "issues"){
val users = getAccountsByUserNames(Set(repository.owner, issue.userName), Set(sender))
for{
repoOwner <- users.get(repository.owner)
issueUser <- users.get(issue.userName)
} yield {
WebHookIssuesPayload(
action = action,
number = issue.issueId,
repository = WebHookRepository(repository, WebHookApiUser(repoOwner)),
issue = WebHookIssue(issue, WebHookApiUser(issueUser)),
sender = WebHookApiUser(sender))
}
}
}
def callPullRequestWebHook(action: String, repository: RepositoryService.RepositoryInfo, issueId: Int, baseUrl: String, sender: model.Account)(implicit s: Session): Unit = {
import WebHookService._
callWebHookOf(repository.owner, repository.name, "pull_request"){
for{
(issue, pullRequest) <- getPullRequest(repository.owner, repository.name, issueId)
users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName), Set(sender))
baseOwner <- users.get(repository.owner)
headOwner <- users.get(pullRequest.requestUserName)
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl)
} yield {
WebHookPullRequestPayload(
action = action,
issue = issue,
pullRequest = pullRequest,
headRepository = headRepo,
headOwner = headOwner,
baseRepository = repository,
baseOwner = baseOwner,
sender = sender)
}
}
}
}
trait WebHookIssueCommentService extends WebHookPullRequestService {
self: AccountService with RepositoryService with PullRequestService with IssuesService =>
def callIssueCommentWebHook(repository: RepositoryService.RepositoryInfo, issue: Issue, issueCommentId: Int, sender: model.Account)(implicit s: Session): Unit = {
import WebHookService._
callWebHookOf(repository.owner, repository.name, "issue_comment"){
for{
issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString())
users = getAccountsByUserNames(Set(issue.userName, repository.owner, issueComment.userName), Set(sender))
issueUser <- users.get(issue.userName)
repoOwner <- users.get(repository.owner)
commenter <- users.get(issueComment.userName)
} yield {
WebHookIssueCommentPayload(
issue = issue,
issueUser = issueUser,
comment = issueComment,
commentUser = commenter,
repository = repository,
repositoryUser = repoOwner,
sender = sender)
}
}
}
} }
object WebHookService { object WebHookService {
trait WebHookPayload trait WebHookPayload
// https://developer.github.com/v3/activity/events/types/#pushevent
case class WebHookPushPayload( case class WebHookPushPayload(
pusher: WebHookApiUser, pusher: WebHookApiUser,
ref: String, ref: String,
@@ -81,9 +161,9 @@ object WebHookService {
repository: WebHookRepository repository: WebHookRepository
) extends WebHookPayload ) extends WebHookPayload
object WebHookPayload { object WebHookPushPayload {
def apply(git: Git, pusher: Account, refName: String, repositoryInfo: RepositoryInfo, def apply(git: Git, pusher: Account, refName: String, repositoryInfo: RepositoryInfo,
commits: List[CommitInfo], repositoryOwner: Account): WebHookPayload = commits: List[CommitInfo], repositoryOwner: Account): WebHookPushPayload =
WebHookPushPayload( WebHookPushPayload(
WebHookApiUser(pusher), WebHookApiUser(pusher),
refName, refName,
@@ -95,10 +175,76 @@ object WebHookService {
) )
} }
// https://developer.github.com/v3/activity/events/types/#issuesevent
case class WebHookIssuesPayload(
action: String,
number: Int,
repository: WebHookRepository,
issue: WebHookIssue,
sender: WebHookApiUser) extends WebHookPayload
// https://developer.github.com/v3/activity/events/types/#pullrequestevent
case class WebHookPullRequestPayload(
action: String,
number: Int,
repository: WebHookRepository,
pull_request: WebHookPullRequest,
sender: WebHookApiUser
) extends WebHookPayload
object WebHookPullRequestPayload{
def apply(action: String,
issue: Issue,
pullRequest: PullRequest,
headRepository: RepositoryInfo,
headOwner: Account,
baseRepository: RepositoryInfo,
baseOwner: Account,
sender: model.Account): WebHookPullRequestPayload = {
val headRepoPayload = WebHookRepository(headRepository, headOwner)
val baseRepoPayload = WebHookRepository(baseRepository, baseOwner)
val senderPayload = WebHookApiUser(sender)
val pr = WebHookPullRequest(issue, pullRequest, headRepoPayload, baseRepoPayload, senderPayload)
WebHookPullRequestPayload(
action = action,
number = issue.issueId,
repository = pr.base.repo,
pull_request = pr,
sender = senderPayload
)
}
}
// https://developer.github.com/v3/activity/events/types/#issuecommentevent
case class WebHookIssueCommentPayload(
action: String,
repository: WebHookRepository,
issue: WebHookIssue,
comment: WebHookComment,
sender: WebHookApiUser
) extends WebHookPayload
object WebHookIssueCommentPayload{
def apply(
issue: Issue,
issueUser: Account,
comment: IssueComment,
commentUser: Account,
repository: RepositoryInfo,
repositoryUser: Account,
sender: Account): WebHookIssueCommentPayload =
WebHookIssueCommentPayload(
action = "created",
repository = WebHookRepository(repository, repositoryUser),
issue = WebHookIssue(issue, WebHookApiUser(issueUser)),
comment = WebHookComment(comment, WebHookApiUser(commentUser)),
sender = WebHookApiUser(sender))
}
case class WebHookCommit( case class WebHookCommit(
id: String, id: String,
message: String, message: String,
timestamp: String, timestamp: String, // "2014-10-09T17:10:36-07:00",
url: String, url: String,
added: List[String], added: List[String],
removed: List[String], removed: List[String],
@@ -144,12 +290,17 @@ object WebHookService {
) )
} }
case class WebHookCommitUser(
name: String,
email: String)
// https://developer.github.com/v3/repos/
case class WebHookRepository( case class WebHookRepository(
name: String, name: String,
url: String, url: String,
description: String, description: String,
watchers: Int, watchers: Int,
forks: Int, forks: Int, // forks_count
`private`: Boolean, `private`: Boolean,
owner: WebHookApiUser) owner: WebHookApiUser)
@@ -164,46 +315,15 @@ object WebHookService {
`private` = repositoryInfo.repository.isPrivate, `private` = repositoryInfo.repository.isPrivate,
owner = owner owner = owner
) )
def apply(repositoryInfo: RepositoryInfo, owner: Account): WebHookRepository =
this(repositoryInfo, WebHookApiUser(owner))
} }
case class WebHookCommitUser( // https://developer.github.com/v3/pulls/
name: String,
email: String)
case class WebHookPullRequestPayload(
val action: String,
val number: Int,
val repository: WebHookRepository,
val pull_request: WebHookPullRequest,
val sender: WebHookApiUser
) extends WebHookPayload
object WebHookPullRequestPayload{
def apply(action: String,
issue: Issue,
pullRequest: PullRequest,
headRepository: RepositoryInfo,
headOwner: Account,
baseRepository: RepositoryInfo,
baseOwner: Account,
sender: model.Account): WebHookPullRequestPayload = {
val headRepoPayload = WebHookRepository(headRepository, owner=WebHookApiUser(headOwner))
val baseRepoPayload = WebHookRepository(baseRepository, owner=WebHookApiUser(baseOwner))
val senderPayload = WebHookApiUser(sender)
val pr = WebHookPullRequest(issue, pullRequest, headRepoPayload, baseRepoPayload, senderPayload)
WebHookPullRequestPayload(
action = action,
number = issue.issueId,
repository = pr.base.repo,
pull_request = pr,
sender = senderPayload
)
}
}
case class WebHookPullRequest( case class WebHookPullRequest(
number: Int, number: Int,
updated_at: String, updated_at: Date,
created_at: Date,
head: WebHookPullRequestCommit, head: WebHookPullRequestCommit,
base: WebHookPullRequestCommit, base: WebHookPullRequestCommit,
mergeable: Option[Boolean], mergeable: Option[Boolean],
@@ -215,7 +335,8 @@ object WebHookService {
object WebHookPullRequest{ object WebHookPullRequest{
def apply(issue: Issue, pullRequest: PullRequest, headRepo: WebHookRepository, baseRepo: WebHookRepository, user: WebHookApiUser): WebHookPullRequest = WebHookPullRequest( def apply(issue: Issue, pullRequest: PullRequest, headRepo: WebHookRepository, baseRepo: WebHookRepository, user: WebHookApiUser): WebHookPullRequest = WebHookPullRequest(
number = issue.issueId, number = issue.issueId,
updated_at = issue.updatedDate.toString(), updated_at = issue.updatedDate,
created_at = issue.registeredDate,
head = WebHookPullRequestCommit( head = WebHookPullRequestCommit(
sha = pullRequest.commitIdTo, sha = pullRequest.commitIdTo,
ref = pullRequest.requestBranch, ref = pullRequest.requestBranch,
@@ -242,11 +363,53 @@ object WebHookService {
object WebHookPullRequestCommit{ object WebHookPullRequestCommit{
def apply(sha: String, def apply(sha: String,
ref: String, ref: String,
repo: WebHookRepository): WebHookPullRequestCommit = WebHookPullRequestCommit( repo: WebHookRepository): WebHookPullRequestCommit =
WebHookPullRequestCommit(
label = s"${repo.owner.login}:${ref}", label = s"${repo.owner.login}:${ref}",
sha = sha, sha = sha,
ref = ref, ref = ref,
repo = repo, repo = repo,
user = repo.owner) user = repo.owner)
} }
// https://developer.github.com/v3/issues/
case class WebHookIssue(
number: Int,
title: String,
user: WebHookApiUser,
// labels,
state: String,
created_at: Date,
updated_at: Date,
body: String)
object WebHookIssue{
def apply(issue: Issue, user: WebHookApiUser): WebHookIssue =
WebHookIssue(
number = issue.issueId,
title = issue.title,
user = user,
state = if(issue.closed){ "closed" }else{ "open" },
body = issue.content.getOrElse(""),
created_at = issue.registeredDate,
updated_at = issue.updatedDate)
}
// https://developer.github.com/v3/issues/comments/
case class WebHookComment(
id: Int,
user: WebHookApiUser,
body: String,
created_at: Date,
updated_at: Date)
object WebHookComment{
def apply(comment: IssueComment, user: WebHookApiUser): WebHookComment =
WebHookComment(
id = comment.commentId,
user = user,
body = comment.content,
created_at = comment.registeredDate,
updated_at = comment.updatedDate)
}
} }

View File

@@ -180,15 +180,12 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
} }
// call web hook // call web hook
getWebHookURLs(owner, repository) match { callWebHookOf(owner, repository, "push"){
case webHookURLs if(webHookURLs.nonEmpty) =>
for(pusherAccount <- getAccountByUserName(pusher); for(pusherAccount <- getAccountByUserName(pusher);
ownerAccount <- getAccountByUserName(owner); ownerAccount <- getAccountByUserName(owner);
repositoryInfo <- getRepository(owner, repository, baseUrl)){ repositoryInfo <- getRepository(owner, repository, baseUrl)) yield {
callWebHook("push", webHookURLs, WebHookPushPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount)
WebHookPayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount))
} }
case _ =>
} }
} }
} }