mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-14 17:35:50 +01:00
Support gollum event in web hook
This commit is contained in:
@@ -1,8 +1,10 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.model.{WebHook, WebHookEvent}
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||||
import gitbucket.core.wiki.html
|
import gitbucket.core.wiki.html
|
||||||
import gitbucket.core.service.{AccountService, ActivityService, RepositoryService, WikiService}
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
@@ -13,11 +15,12 @@ import org.eclipse.jgit.api.Git
|
|||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
class WikiController extends WikiControllerBase
|
class WikiController extends WikiControllerBase
|
||||||
with WikiService with RepositoryService with AccountService with ActivityService
|
with WikiService with RepositoryService with AccountService with ActivityService with WebHookService
|
||||||
with ReadableUsersAuthenticator with ReferrerAuthenticator
|
with ReadableUsersAuthenticator with ReferrerAuthenticator
|
||||||
|
|
||||||
trait WikiControllerBase extends ControllerBase {
|
trait WikiControllerBase extends ControllerBase {
|
||||||
self: WikiService with RepositoryService with ActivityService with ReadableUsersAuthenticator with ReferrerAuthenticator =>
|
self: WikiService with RepositoryService with AccountService with ActivityService with WebHookService
|
||||||
|
with ReadableUsersAuthenticator with ReferrerAuthenticator =>
|
||||||
|
|
||||||
case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String, id: String)
|
case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String, id: String)
|
||||||
|
|
||||||
@@ -136,6 +139,11 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
).map { commitId =>
|
).map { commitId =>
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
recordEditWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
recordEditWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
||||||
|
callWebHookOf(repository.owner, repository.name, WebHook.Gollum){
|
||||||
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
|
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(notReservedPageName(form.pageName)) {
|
if(notReservedPageName(form.pageName)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||||
@@ -155,11 +163,24 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||||
if(isEditable(repository)){
|
if(isEditable(repository)){
|
||||||
defining(context.loginAccount.get){ loginAccount =>
|
defining(context.loginAccount.get){ loginAccount =>
|
||||||
saveWikiPage(repository.owner, repository.name, form.currentPageName, form.pageName,
|
saveWikiPage(
|
||||||
form.content, loginAccount, form.message.getOrElse(""), None)
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
form.currentPageName,
|
||||||
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
form.pageName,
|
||||||
|
form.content,
|
||||||
|
loginAccount,
|
||||||
|
form.message.getOrElse(""),
|
||||||
|
None
|
||||||
|
).map { commitId =>
|
||||||
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||||
|
callWebHookOf(repository.owner, repository.name, WebHook.Gollum){
|
||||||
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
|
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(notReservedPageName(form.pageName)) {
|
if(notReservedPageName(form.pageName)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ import gitbucket.core.model.Profile._
|
|||||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||||
import org.apache.http.client.utils.URLEncodedUtils
|
import org.apache.http.client.utils.URLEncodedUtils
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util.RepositoryName
|
import gitbucket.core.util.{RepositoryName, StringUtil}
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import org.apache.http.NameValuePair
|
import org.apache.http.NameValuePair
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity
|
import org.apache.http.client.entity.UrlEncodedFormEntity
|
||||||
@@ -18,7 +18,7 @@ import org.eclipse.jgit.lib.ObjectId
|
|||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
import scala.util.{Success, Failure}
|
import scala.util.{Failure, Success}
|
||||||
import org.apache.http.HttpRequest
|
import org.apache.http.HttpRequest
|
||||||
import org.apache.http.HttpResponse
|
import org.apache.http.HttpResponse
|
||||||
import gitbucket.core.model.WebHookContentType
|
import gitbucket.core.model.WebHookContentType
|
||||||
@@ -160,7 +160,7 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
import WebHookService._
|
import WebHookService._
|
||||||
// https://developer.github.com/v3/activity/events/types/#issuesevent
|
// https://developer.github.com/v3/activity/events/types/#issuesevent
|
||||||
def callIssuesWebHook(action: String, repository: RepositoryService.RepositoryInfo, issue: Issue, baseUrl: String, sender: Account)
|
def callIssuesWebHook(action: String, repository: RepositoryService.RepositoryInfo, issue: Issue, baseUrl: String, sender: Account)
|
||||||
(implicit s: Session, context:JsonFormat.Context): Unit = {
|
(implicit s: Session, context: JsonFormat.Context): Unit = {
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Issues){
|
callWebHookOf(repository.owner, repository.name, WebHook.Issues){
|
||||||
val users = getAccountsByUserNames(Set(repository.owner, issue.openedUserName), Set(sender))
|
val users = getAccountsByUserNames(Set(repository.owner, issue.openedUserName), Set(sender))
|
||||||
for{
|
for{
|
||||||
@@ -178,7 +178,7 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def callPullRequestWebHook(action: String, repository: RepositoryService.RepositoryInfo, issueId: Int, baseUrl: String, sender: Account)
|
def callPullRequestWebHook(action: String, repository: RepositoryService.RepositoryInfo, issueId: Int, baseUrl: String, sender: Account)
|
||||||
(implicit s: Session, context:JsonFormat.Context): Unit = {
|
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.PullRequest){
|
callWebHookOf(repository.owner, repository.name, WebHook.PullRequest){
|
||||||
for{
|
for{
|
||||||
@@ -224,7 +224,7 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
}).list.groupBy(_._1).mapValues(_.map(_._2))
|
}).list.groupBy(_._1).mapValues(_.map(_._2))
|
||||||
|
|
||||||
def callPullRequestWebHookByRequestBranch(action: String, requestRepository: RepositoryService.RepositoryInfo, requestBranch: String, baseUrl: String, sender: Account)
|
def callPullRequestWebHookByRequestBranch(action: String, requestRepository: RepositoryService.RepositoryInfo, requestBranch: String, baseUrl: String, sender: Account)
|
||||||
(implicit s: Session, context:JsonFormat.Context): Unit = {
|
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
for{
|
for{
|
||||||
((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
|
((issue, issueUser, pullRequest, baseOwner, headOwner), webHooks) <- getPullRequestsByRequestForWebhook(requestRepository.owner, requestRepository.name, requestBranch)
|
||||||
@@ -246,12 +246,13 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
callWebHook(WebHook.PullRequest, webHooks, payload)
|
callWebHook(WebHook.PullRequest, webHooks, payload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
trait WebHookPullRequestReviewCommentService extends WebHookService {
|
trait WebHookPullRequestReviewCommentService extends WebHookService {
|
||||||
self: AccountService with RepositoryService with PullRequestService with IssuesService with CommitsService =>
|
self: AccountService with RepositoryService with PullRequestService with IssuesService with CommitsService =>
|
||||||
def callPullRequestReviewCommentWebHook(action: String, comment: CommitComment, repository: RepositoryService.RepositoryInfo, issueId: Int, baseUrl: String, sender: Account)
|
def callPullRequestReviewCommentWebHook(action: String, comment: CommitComment, repository: RepositoryService.RepositoryInfo, issueId: Int, baseUrl: String, sender: Account)
|
||||||
(implicit s: Session, context:JsonFormat.Context): Unit = {
|
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.PullRequestReviewComment){
|
callWebHookOf(repository.owner, repository.name, WebHook.PullRequestReviewComment){
|
||||||
for{
|
for{
|
||||||
@@ -285,7 +286,7 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
|
|||||||
|
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
def callIssueCommentWebHook(repository: RepositoryService.RepositoryInfo, issue: Issue, issueCommentId: Int, sender: Account)
|
def callIssueCommentWebHook(repository: RepositoryService.RepositoryInfo, issue: Issue, issueCommentId: Int, sender: Account)
|
||||||
(implicit s: Session, context:JsonFormat.Context): Unit = {
|
(implicit s: Session, c: JsonFormat.Context): Unit = {
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.IssueComment){
|
callWebHookOf(repository.owner, repository.name, WebHook.IssueComment){
|
||||||
for{
|
for{
|
||||||
issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString())
|
issueComment <- getComment(repository.owner, repository.name, issueCommentId.toString())
|
||||||
@@ -470,4 +471,46 @@ object WebHookService {
|
|||||||
sender = senderPayload)
|
sender = senderPayload)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// https://developer.github.com/v3/activity/events/types/#gollumevent
|
||||||
|
case class WebHookGollumPayload(
|
||||||
|
pages: Seq[WebHookGollumPagePayload],
|
||||||
|
repository: ApiRepository,
|
||||||
|
sender: ApiUser
|
||||||
|
) extends WebHookPayload
|
||||||
|
|
||||||
|
case class WebHookGollumPagePayload(
|
||||||
|
page_name: String,
|
||||||
|
title: String,
|
||||||
|
summary: Option[String] = None,
|
||||||
|
action: String, // created or edited
|
||||||
|
sha: String, // SHA of the latest commit
|
||||||
|
html_url: ApiPath
|
||||||
|
)
|
||||||
|
|
||||||
|
object WebHookGollumPayload {
|
||||||
|
def apply(
|
||||||
|
action: String,
|
||||||
|
pageName: String,
|
||||||
|
sha: String,
|
||||||
|
repository: RepositoryInfo,
|
||||||
|
repositoryUser: Account,
|
||||||
|
sender: Account
|
||||||
|
): WebHookGollumPayload = {
|
||||||
|
WebHookGollumPayload(
|
||||||
|
pages = Seq(
|
||||||
|
WebHookGollumPagePayload(
|
||||||
|
action = action,
|
||||||
|
page_name = pageName,
|
||||||
|
title = pageName,
|
||||||
|
sha = sha,
|
||||||
|
html_url = ApiPath(s"/${RepositoryName(repository).fullName}/wiki/${StringUtil.urlDecode(pageName)}")
|
||||||
|
)
|
||||||
|
),
|
||||||
|
repository = ApiRepository(repository, repositoryUser),
|
||||||
|
sender = ApiUser(sender)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
package gitbucket.core.util
|
package gitbucket.core.util
|
||||||
|
|
||||||
// TODO Move to gitbucket.core.api package?
|
// TODO Move to gitbucket.core.api package?
|
||||||
case class RepositoryName(owner:String, name:String){
|
case class RepositoryName(owner: String, name: String){
|
||||||
val fullName = s"${owner}/${name}"
|
val fullName = s"${owner}/${name}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user