diff --git a/project/build.scala b/project/build.scala index 3fe6111..94cb2ab 100644 --- a/project/build.scala +++ b/project/build.scala @@ -51,7 +51,7 @@ "org.json4s" %% "json4s-jackson" % "3.2.11", "jp.sf.amateras" %% "scalatra-forms" % "0.2.0", "commons-io" % "commons-io" % "2.4", - "io.github.gitbucket" % "markedj" % "1.0.5-SNAPSHOT", + "io.github.gitbucket" % "markedj" % "1.0.5", "org.apache.commons" % "commons-compress" % "1.9", "org.apache.commons" % "commons-email" % "1.3.3", "org.apache.httpcomponents" % "httpclient" % "4.3.6", diff --git a/src/main/scala/gitbucket/core/api/ApiPullRequestReviewComment.scala b/src/main/scala/gitbucket/core/api/ApiPullRequestReviewComment.scala new file mode 100644 index 0000000..55d1fe9 --- /dev/null +++ b/src/main/scala/gitbucket/core/api/ApiPullRequestReviewComment.scala @@ -0,0 +1,61 @@ +package gitbucket.core.api + +import gitbucket.core.util.RepositoryName +import gitbucket.core.model.CommitComment + +import java.util.Date + +/** + * https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent + */ +case class ApiPullRequestReviewComment( + id: Int, // 29724692 + // "diff_hunk": "@@ -1 +1 @@\n-# public-repo", + path: String, // "README.md", + // "position": 1, + // "original_position": 1, + commit_id: String, // "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + // "original_commit_id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c", + user: ApiUser, + body: String, // "Maybe you should use more emojji on this line.", + created_at: Date, // "2015-05-05T23:40:27Z", + updated_at: Date // "2015-05-05T23:40:27Z", +)(repositoryName:RepositoryName, issueId: Int) extends FieldSerializable { + // "url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/comments/29724692", + val url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/pulls/comments/${id}") + // "html_url": "https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692", + val html_url = ApiPath(s"/${repositoryName.fullName}/pull/${issueId}#discussion_r${id}") + // "pull_request_url": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/1", + val pull_request_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/pulls/${issueId}") + + /* + "_links": { + "self": { + "href": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/comments/29724692" + }, + "html": { + "href": "https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692" + }, + "pull_request": { + "href": "https://api.github.com/repos/baxterthehacker/public-repo/pulls/1" + } + } + */ + val _links = Map( + "self" -> Map("href" -> url), + "html" -> Map("href" -> html_url), + "pull_request" -> Map("href" -> pull_request_url)) +} + +object ApiPullRequestReviewComment{ + def apply(comment: CommitComment, commentedUser: ApiUser, repositoryName: RepositoryName, issueId: Int): ApiPullRequestReviewComment = + new ApiPullRequestReviewComment( + id = comment.commentId, + path = comment.fileName.getOrElse(""), + commit_id = comment.commitId, + user = commentedUser, + body = comment.content, + created_at = comment.registeredDate, + updated_at = comment.updatedDate + )(repositoryName, issueId) +} diff --git a/src/main/scala/gitbucket/core/controller/AccountController.scala b/src/main/scala/gitbucket/core/controller/AccountController.scala index e516a03..da05f0e 100644 --- a/src/main/scala/gitbucket/core/controller/AccountController.scala +++ b/src/main/scala/gitbucket/core/controller/AccountController.scala @@ -212,6 +212,7 @@ // // Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY // removeUserRelatedData(userName) + removeUserRelatedData(userName) updateAccount(account.copy(isRemoved = true)) } diff --git a/src/main/scala/gitbucket/core/controller/IndexController.scala b/src/main/scala/gitbucket/core/controller/IndexController.scala index deb3982..a96e604 100644 --- a/src/main/scala/gitbucket/core/controller/IndexController.scala +++ b/src/main/scala/gitbucket/core/controller/IndexController.scala @@ -104,7 +104,7 @@ }) /** - * JSON APU for checking user existence. + * JSON API for checking user existence. */ post("/_user/existence")(usersOnly { getAccountByUserName(params("userName")).isDefined diff --git a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala index 02a7850..9b9b752 100644 --- a/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala +++ b/src/main/scala/gitbucket/core/controller/RepositoryViewerController.scala @@ -32,7 +32,7 @@ class RepositoryViewerController extends RepositoryViewerControllerBase with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService - with WebHookPullRequestService + with WebHookPullRequestService with WebHookPullRequestReviewCommentService /** * The repository viewer. @@ -40,7 +40,7 @@ trait RepositoryViewerControllerBase extends ControllerBase { self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService with CommitStatusService - with WebHookPullRequestService => + with WebHookPullRequestService with WebHookPullRequestReviewCommentService => ArchiveCommand.registerFormat("zip", new ZipFormat) ArchiveCommand.registerFormat("tar.gz", new TgzFormat) @@ -396,12 +396,14 @@ val id = params("id") val commentId = createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName, form.content, form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId) + val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get form.issueId match { - case Some(issueId) => recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content) + case Some(issueId) => + recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content) + callPullRequestReviewCommentWebHook("create", comment, repository, issueId, context.baseUrl, context.loginAccount.get) case None => recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content) } - helper.html.commitcomment(getCommitComment(repository.owner, repository.name, commentId.toString).get, - hasWritePermission(repository.owner, repository.name, context.loginAccount), repository) + helper.html.commitcomment(comment, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository) }) ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository => diff --git a/src/main/scala/gitbucket/core/controller/UserManagementController.scala b/src/main/scala/gitbucket/core/controller/UserManagementController.scala index 26c9f88..d20da15 100644 --- a/src/main/scala/gitbucket/core/controller/UserManagementController.scala +++ b/src/main/scala/gitbucket/core/controller/UserManagementController.scala @@ -100,12 +100,12 @@ if(form.isRemoved){ // Remove repositories - getRepositoryNamesOfUser(userName).foreach { repositoryName => - deleteRepository(userName, repositoryName) - FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName)) - FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName)) - FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName)) - } +// getRepositoryNamesOfUser(userName).foreach { repositoryName => +// deleteRepository(userName, repositoryName) +// FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName)) +// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName)) +// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName)) +// } // Remove from GROUP_MEMBER, COLLABORATOR and REPOSITORY removeUserRelatedData(userName) } diff --git a/src/main/scala/gitbucket/core/service/WebHookService.scala b/src/main/scala/gitbucket/core/service/WebHookService.scala index c168395..53d0abe 100644 --- a/src/main/scala/gitbucket/core/service/WebHookService.scala +++ b/src/main/scala/gitbucket/core/service/WebHookService.scala @@ -1,7 +1,7 @@ package gitbucket.core.service import gitbucket.core.api._ -import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent} +import gitbucket.core.model.{WebHook, Account, Issue, PullRequest, IssueComment, WebHookEvent, CommitComment} import gitbucket.core.model.Profile._ import profile.simple._ import gitbucket.core.util.JGitUtil.CommitInfo @@ -212,6 +212,35 @@ } } +trait WebHookPullRequestReviewCommentService extends WebHookService { + 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)(implicit s: Session, context:JsonFormat.Context): Unit = { + import WebHookService._ + callWebHookOf(repository.owner, repository.name, WebHook.PullRequestReviewComment){ + for{ + (issue, pullRequest) <- getPullRequest(repository.owner, repository.name, issueId) + users = getAccountsByUserNames(Set(repository.owner, pullRequest.requestUserName, issue.openedUserName), Set(sender)) + baseOwner <- users.get(repository.owner) + headOwner <- users.get(pullRequest.requestUserName) + issueUser <- users.get(issue.openedUserName) + headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName, baseUrl) + } yield { + WebHookPullRequestReviewCommentPayload( + action = action, + comment = comment, + issue = issue, + issueUser = issueUser, + pullRequest = pullRequest, + headRepository = headRepo, + headOwner = headOwner, + baseRepository = repository, + baseOwner = baseOwner, + sender = sender) + } + } + } +} + trait WebHookIssueCommentService extends WebHookPullRequestService { self: AccountService with RepositoryService with PullRequestService with IssuesService => @@ -341,4 +370,38 @@ comment = ApiComment(comment, RepositoryName(repository), issue.issueId, ApiUser(commentUser), issue.isPullRequest), sender = ApiUser(sender)) } + + // https://developer.github.com/v3/activity/events/types/#pullrequestreviewcommentevent + case class WebHookPullRequestReviewCommentPayload( + action: String, + comment: ApiPullRequestReviewComment, + pull_request: ApiPullRequest, + repository: ApiRepository, + sender: ApiUser + ) extends WebHookPayload + + object WebHookPullRequestReviewCommentPayload{ + def apply( + action: String, + comment: CommitComment, + issue: Issue, + issueUser: Account, + pullRequest: PullRequest, + headRepository: RepositoryInfo, + headOwner: Account, + baseRepository: RepositoryInfo, + baseOwner: Account, + sender: Account + ) : WebHookPullRequestReviewCommentPayload = { + val headRepoPayload = ApiRepository(headRepository, headOwner) + val baseRepoPayload = ApiRepository(baseRepository, baseOwner) + val senderPayload = ApiUser(sender) + WebHookPullRequestReviewCommentPayload( + action = action, + comment = ApiPullRequestReviewComment(comment, senderPayload, RepositoryName(baseRepository), issue.issueId), + pull_request = ApiPullRequest(issue, pullRequest, headRepoPayload, baseRepoPayload, ApiUser(issueUser)), + repository = baseRepoPayload, + sender = senderPayload) + } + } } diff --git a/src/main/twirl/gitbucket/core/helper/account.scala.html b/src/main/twirl/gitbucket/core/helper/account.scala.html index 4b62e72..8a6570c 100644 --- a/src/main/twirl/gitbucket/core/helper/account.scala.html +++ b/src/main/twirl/gitbucket/core/helper/account.scala.html @@ -1,6 +1,6 @@ @(id: String, width: Int)(implicit context: gitbucket.core.controller.Context) @import context._ - +