support CreateEvent in webhook

This commit is contained in:
guyon
2017-12-21 15:21:22 +09:00
parent 3f8069638c
commit 39e1ac2398
5 changed files with 48 additions and 5 deletions

View File

@@ -53,5 +53,5 @@ object ApiCommit{
committer = ApiPersonIdent.committer(commit) committer = ApiPersonIdent.committer(commit)
)(repositoryName, urlIsHtmlUrl) )(repositoryName, urlIsHtmlUrl)
} }
def forPushPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = apply(git, repositoryName, commit, true) def forWebhookPayload(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = apply(git, repositoryName, commit, true)
} }

View File

@@ -51,7 +51,7 @@ object ApiRepository{
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository = def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
this(repositoryInfo.repository, ApiUser(owner)) this(repositoryInfo.repository, ApiUser(owner))
def forPushPayload(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository = def forWebhookPayload(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
ApiRepository(repositoryInfo.repository, owner, forkedCount=repositoryInfo.forkedCount, urlIsHtmlUrl=true) ApiRepository(repositoryInfo.repository, owner, forkedCount=repositoryInfo.forkedCount, urlIsHtmlUrl=true)
def forDummyPayload(owner: ApiUser): ApiRepository = def forDummyPayload(owner: ApiUser): ApiRepository =

View File

@@ -362,6 +362,35 @@ trait WebHookIssueCommentService extends WebHookPullRequestService {
object WebHookService { object WebHookService {
trait WebHookPayload trait WebHookPayload
// https://developer.github.com/v3/activity/events/types/#createevent
case class WebHookCreatePayload(
sender: ApiUser,
description: String,
ref: String,
ref_type: String,
master_branch: String,
repository: ApiRepository
) extends FieldSerializable with WebHookPayload {
val pusher_type = "user"
}
object WebHookCreatePayload {
def apply(git: Git, sender: Account, refName: String, repositoryInfo: RepositoryInfo,
commits: List[CommitInfo], repositoryOwner: Account,
ref: String, refType: String): WebHookCreatePayload =
WebHookCreatePayload(
sender = ApiUser(sender),
ref = ref,
ref_type = refType,
description = repositoryInfo.repository.description.getOrElse(""),
master_branch = repositoryInfo.repository.defaultBranch,
repository = ApiRepository.forWebhookPayload(
repositoryInfo,
owner= ApiUser(repositoryOwner))
)
}
// https://developer.github.com/v3/activity/events/types/#pushevent // https://developer.github.com/v3/activity/events/types/#pushevent
case class WebHookPushPayload( case class WebHookPushPayload(
pusher: ApiPusher, pusher: ApiPusher,
@@ -391,8 +420,8 @@ object WebHookService {
ref = refName, ref = refName,
before = ObjectId.toString(oldId), before = ObjectId.toString(oldId),
after = ObjectId.toString(newId), after = ObjectId.toString(newId),
commits = commits.map{ commit => ApiCommit.forPushPayload(git, RepositoryName(repositoryInfo), commit) }, commits = commits.map{ commit => ApiCommit.forWebhookPayload(git, RepositoryName(repositoryInfo), commit) },
repository = ApiRepository.forPushPayload( repository = ApiRepository.forWebhookPayload(
repositoryInfo, repositoryInfo,
owner= ApiUser(repositoryOwner)) owner= ApiUser(repositoryOwner))
) )

View File

@@ -306,6 +306,18 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
newId = command.getNewId(), oldId = command.getOldId()) newId = command.getNewId(), oldId = command.getOldId())
} }
} }
if (command.getType == ReceiveCommand.Type.CREATE) {
callWebHookOf(owner, repository, WebHook.Create) {
for {
pusherAccount <- getAccountByUserName(pusher)
ownerAccount <- getAccountByUserName(owner)
} yield {
val refType = if (refName(1) == "tags") "tag" else "branch"
WebHookCreatePayload(git, pusherAccount, command.getRefName, repositoryInfo, newCommits, ownerAccount,
ref = branchName, refType = refType)
}
}
}
// call post-commit hook // call post-commit hook
PluginRegistry().getReceiveHooks.foreach(_.postReceive(owner, repository, receivePack, command, pusher)) PluginRegistry().getReceiveHooks.foreach(_.postReceive(owner, repository, receivePack, command, pusher))

View File

@@ -48,7 +48,9 @@
</div> </div>
<!-- <!--
<label class="checkbox"><input type="checkbox" @check("events",CommitComment) />Commit comment <small class="help-block">Commit or diff commented on. </small> </label> <label class="checkbox"><input type="checkbox" @check("events",CommitComment) />Commit comment <small class="help-block">Commit or diff commented on. </small> </label>
<label class="checkbox"><input type="checkbox" @check("events",Create) />Create <small class="help-block">Branch, or tag created. </small> </label> -->
<label class="checkbox"><input type="checkbox" @check("events",Create) />Create <small class="help-block normal">Branch, or tag created. </small> </label>
<!--
<label class="checkbox"><input type="checkbox" @check("events",Delete) />Delete <small class="help-block">Branch, or tag deleted. </small> </label> <label class="checkbox"><input type="checkbox" @check("events",Delete) />Delete <small class="help-block">Branch, or tag deleted. </small> </label>
<label class="checkbox"><input type="checkbox" @check("events",Deployment) />Deployment <small class="help-block">Repository deployed. </small> </label> <label class="checkbox"><input type="checkbox" @check("events",Deployment) />Deployment <small class="help-block">Repository deployed. </small> </label>
<label class="checkbox"><input type="checkbox" @check("events",DeploymentStatus) />Deployment status <small class="help-block">Deployment status updated from the API. </small> </label> <label class="checkbox"><input type="checkbox" @check("events",DeploymentStatus) />Deployment status <small class="help-block">Deployment status updated from the API. </small> </label>