mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-12-24 09:20:04 +01:00
refactored ActivityService logging strategy (#2526)
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.model.activity.DeleteBranchInfo
|
||||
import gitbucket.core.pulls.html
|
||||
import gitbucket.core.service.CommitStatusService
|
||||
import gitbucket.core.service.MergeService
|
||||
@@ -272,7 +273,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
val userName = context.loginAccount.get.userName
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
git.branchDelete().setForce(true).setBranchNames(pullreq.requestBranch).call()
|
||||
recordDeleteBranchActivity(repository.owner, repository.name, userName, pullreq.requestBranch)
|
||||
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, pullreq.requestBranch)
|
||||
recordActivity(deleteBranchInfo)
|
||||
}
|
||||
createComment(
|
||||
baseRepository.owner,
|
||||
|
||||
@@ -2,6 +2,7 @@ package gitbucket.core.controller
|
||||
|
||||
import java.io.File
|
||||
|
||||
import gitbucket.core.model.activity.ReleaseInfo
|
||||
import gitbucket.core.service.{
|
||||
AccountService,
|
||||
ActivityService,
|
||||
@@ -127,7 +128,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
||||
}
|
||||
|
||||
recordReleaseActivity(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||
val releaseInfo = ReleaseInfo(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||
recordActivity(releaseInfo)
|
||||
|
||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
||||
})
|
||||
|
||||
@@ -13,6 +13,7 @@ import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.model.WebHookContentType
|
||||
import gitbucket.core.model.activity.RenameRepositoryInfo
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.Messages
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -377,12 +378,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
// Update database and move git repository
|
||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
||||
// Record activity log
|
||||
recordRenameRepositoryActivity(
|
||||
val renameInfo = RenameRepositoryInfo(
|
||||
repository.owner,
|
||||
form.repositoryName,
|
||||
repository.name,
|
||||
context.loginAccount.get.userName
|
||||
context.loginAccount.get.userName,
|
||||
repository.name
|
||||
)
|
||||
recordActivity(renameInfo)
|
||||
}
|
||||
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||
} else Forbidden()
|
||||
@@ -398,12 +400,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
// Update database and move git repository
|
||||
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
||||
// Record activity log
|
||||
recordRenameRepositoryActivity(
|
||||
val renameInfo = RenameRepositoryInfo(
|
||||
form.newOwner,
|
||||
repository.name,
|
||||
repository.owner,
|
||||
context.loginAccount.get.userName
|
||||
context.loginAccount.get.userName,
|
||||
repository.owner
|
||||
)
|
||||
recordActivity(renameInfo)
|
||||
}
|
||||
redirect(s"/${form.newOwner}/${repository.name}")
|
||||
} else Forbidden()
|
||||
|
||||
@@ -7,6 +7,7 @@ import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.repo.html
|
||||
import gitbucket.core.helper
|
||||
import gitbucket.core.model.activity.DeleteBranchInfo
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
||||
import gitbucket.core.util._
|
||||
@@ -833,7 +834,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
if (repository.repository.defaultBranch != branchName) {
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
git.branchDelete().setForce(true).setBranchNames(branchName).call()
|
||||
recordDeleteBranchActivity(repository.owner, repository.name, userName, branchName)
|
||||
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, branchName)
|
||||
recordActivity(deleteBranchInfo)
|
||||
}
|
||||
}
|
||||
redirect(s"/${repository.owner}/${repository.name}/branches")
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.model.WebHook
|
||||
import gitbucket.core.model.activity.{CreateWikiPageInfo, EditWikiPageInfo}
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||
import gitbucket.core.wiki.html
|
||||
@@ -13,6 +14,7 @@ import gitbucket.core.util.Directory._
|
||||
import org.scalatra.forms._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
import scala.util.Using
|
||||
|
||||
class WikiController
|
||||
@@ -185,13 +187,9 @@ trait WikiControllerBase extends ControllerBase {
|
||||
).foreach {
|
||||
commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
recordEditWikiPageActivity(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
form.pageName,
|
||||
commitId
|
||||
)
|
||||
val wikiEditInfo =
|
||||
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
||||
recordActivity(wikiEditInfo)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
@@ -229,7 +227,9 @@ trait WikiControllerBase extends ControllerBase {
|
||||
).foreach {
|
||||
commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||
val createWikiPageInfo =
|
||||
CreateWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||
recordActivity(createWikiPageInfo)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
|
||||
trait BaseActivityInfo {
|
||||
|
||||
def toActivity: Activity
|
||||
|
||||
protected def trimInfoString(str: String, maxLen: Int): String =
|
||||
if (str.length > maxLen) s"${str.substring(0, maxLen)}..."
|
||||
else str
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||
|
||||
final case class PushInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String,
|
||||
commits: List[CommitInfo]
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"push",
|
||||
s"[user:$activityUserName] pushed to [branch:$userName/$repositoryName#$branchName] at [repo:$userName/$repositoryName]",
|
||||
Some(buildCommitSummary(commits)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
|
||||
private[this] def buildCommitSummary(commits: List[CommitInfo]): String =
|
||||
commits
|
||||
.take(5)
|
||||
.map(commit => s"${commit.id}:${commit.shortMessage}")
|
||||
.mkString("\n")
|
||||
}
|
||||
|
||||
final case class CreateBranchInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_branch",
|
||||
s"[user:$activityUserName] created branch [branch:$userName/$repositoryName#$branchName] at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class DeleteBranchInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_branch",
|
||||
s"[user:$activityUserName] deleted branch $branchName at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,69 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class IssueCommentInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
comment: String,
|
||||
issueId: Int
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(trimInfoString(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class PullRequestCommentInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
comment: String,
|
||||
issueId: Int
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:$activityUserName] commented on pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||
Some(trimInfoString(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class CommitCommentInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
comment: String,
|
||||
commitId: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_commit",
|
||||
s"[user:$activityUserName] commented on commit [commit:$userName/$repositoryName@$commitId]",
|
||||
Some(trimInfoString(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class ForkInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
forkedUserName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"fork",
|
||||
s"[user:$activityUserName] forked [repo:$userName/$repositoryName] to [repo:$forkedUserName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,132 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class CreateIssueInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"open_issue",
|
||||
s"[user:$activityUserName] opened issue [issue:$userName/$repositoryName#$issueId]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class CloseIssueInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"close_issue",
|
||||
s"[user:$activityUserName] closed issue [issue:$userName/$repositoryName#$issueId]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class ReopenIssueInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"reopen_issue",
|
||||
s"[user:$activityUserName] reopened issue [issue:$userName/$repositoryName#$issueId]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class OpenPullRequestInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"open_pullreq",
|
||||
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class ClosePullRequestInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"close_issue",
|
||||
s"[user:$activityUserName] closed pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class ReopenPullRequestInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"reopen_issue",
|
||||
s"[user:$activityUserName] reopened pull request [issue:$userName/$repositoryName#$issueId]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class MergeInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
message: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"merge_pullreq",
|
||||
s"[user:$activityUserName] merged pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||
Some(message),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class ReleaseInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
releaseName: String,
|
||||
tagName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"release",
|
||||
s"[user:$activityUserName] released [release:$userName/$repositoryName/$tagName:$releaseName] at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,84 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class CreateRepositoryInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_repository",
|
||||
s"[user:$activityUserName] created [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class DeleteRepositoryInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_repository",
|
||||
s"[user:$activityUserName] deleted [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class TransferRepositoryInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
oldUserName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"transfer_repository",
|
||||
s"[user:$activityUserName] transferred [repo:$oldUserName/$repositoryName] to [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class RenameRepositoryInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
oldRepositoryName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"rename_repository",
|
||||
s"[user:$activityUserName] renamed [repo:$userName/$oldRepositoryName] at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,46 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class CreateTagInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
tagName: String,
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_tag",
|
||||
s"[user:$activityUserName] created tag [tag:$userName/$repositoryName#$tagName] at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class DeleteTagInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
tagName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_tag",
|
||||
s"[user:$activityUserName] deleted tag $tagName at [repo:$userName/$repositoryName]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
package gitbucket.core.model.activity
|
||||
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.model.Activity
|
||||
import gitbucket.core.model.Profile.currentDate
|
||||
|
||||
final case class CreateWikiPageInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
pageName: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_wiki",
|
||||
s"[user:$activityUserName] created the [repo:$userName/$repositoryName] wiki",
|
||||
Some(pageName),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
|
||||
final case class EditWikiPageInfo(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
pageName: String,
|
||||
commitId: String
|
||||
) extends BaseActivityInfo {
|
||||
|
||||
override def toActivity: Activity =
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"edit_wiki",
|
||||
s"[user:$activityUserName] edited the [repo:$userName/$repositoryName] wiki",
|
||||
Some(s"$pageName:$commitId"),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
}
|
||||
@@ -14,6 +14,7 @@ import java.nio.charset.StandardCharsets
|
||||
import java.util.UUID
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.activity.BaseActivityInfo
|
||||
import org.apache.commons.io.input.ReversedLinesFileReader
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
@@ -97,478 +98,6 @@ trait ActivityService {
|
||||
}
|
||||
}
|
||||
|
||||
def recordCreateRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_repository",
|
||||
s"[user:${activityUserName}] created [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordDeleteRepositoryActivity(userName: String, repositoryName: String, activityUserName: String): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_repository",
|
||||
s"[user:${activityUserName}] deleted [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordTransferRepositoryActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
oldUserName: String,
|
||||
activityUserName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"transfer_repository",
|
||||
s"[user:${activityUserName}] transfered [repo:${oldUserName}/${repositoryName}] to [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordRenameRepositoryActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
oldRepositoryName: String,
|
||||
activityUserName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"rename_repository",
|
||||
s"[user:${activityUserName}] renamed [repo:${userName}/${oldRepositoryName}] at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCreateIssueActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"open_issue",
|
||||
s"[user:${activityUserName}] opened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCloseIssueActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"close_issue",
|
||||
s"[user:${activityUserName}] closed issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordClosePullRequestActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"close_issue",
|
||||
s"[user:${activityUserName}] closed pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordReopenIssueActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"reopen_issue",
|
||||
s"[user:${activityUserName}] reopened issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordReopenPullRequestActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"reopen_issue",
|
||||
s"[user:${activityUserName}] reopened pull request [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCommentIssueActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
comment: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(cut(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCommentPullRequestActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
comment: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_issue",
|
||||
s"[user:${activityUserName}] commented on pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(cut(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCommentCommitActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
commitId: String,
|
||||
comment: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"comment_commit",
|
||||
s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]",
|
||||
Some(cut(comment, 200)),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCreateWikiPageActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
pageName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_wiki",
|
||||
s"[user:${activityUserName}] created the [repo:${userName}/${repositoryName}] wiki",
|
||||
Some(pageName),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordEditWikiPageActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
pageName: String,
|
||||
commitId: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"edit_wiki",
|
||||
s"[user:${activityUserName}] edited the [repo:${userName}/${repositoryName}] wiki",
|
||||
Some(pageName + ":" + commitId),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordPushActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String,
|
||||
commits: List[JGitUtil.CommitInfo]
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"push",
|
||||
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||
Some(
|
||||
commits
|
||||
.take(5)
|
||||
.map { commit =>
|
||||
commit.id + ":" + commit.shortMessage
|
||||
}
|
||||
.mkString("\n")
|
||||
),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCreateTagActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
tagName: String,
|
||||
commits: List[JGitUtil.CommitInfo]
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_tag",
|
||||
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordDeleteTagActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
tagName: String,
|
||||
commits: List[JGitUtil.CommitInfo]
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_tag",
|
||||
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordCreateBranchActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"create_branch",
|
||||
s"[user:${activityUserName}] created branch [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordDeleteBranchActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
branchName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"delete_branch",
|
||||
s"[user:${activityUserName}] deleted branch ${branchName} at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordForkActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
forkedUserName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"fork",
|
||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordPullRequestActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
title: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"open_pullreq",
|
||||
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(title),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordMergeActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
issueId: Int,
|
||||
message: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"merge_pullreq",
|
||||
s"[user:${activityUserName}] merged pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||
Some(message),
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
def recordReleaseActivity(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
activityUserName: String,
|
||||
releaseName: String,
|
||||
tagName: String
|
||||
): Unit = {
|
||||
writeLog(
|
||||
Activity(
|
||||
userName,
|
||||
repositoryName,
|
||||
activityUserName,
|
||||
"release",
|
||||
s"[user:${activityUserName}] released [release:${userName}/${repositoryName}/${tagName}:${releaseName}] at [repo:${userName}/${repositoryName}]",
|
||||
None,
|
||||
currentDate,
|
||||
UUID.randomUUID().toString
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private def cut(value: String, length: Int): String =
|
||||
if (value.length > length) value.substring(0, length) + "..." else value
|
||||
def recordActivity[T <: { def toActivity: Activity }](info: T): Unit =
|
||||
writeLog(info.toActivity)
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import gitbucket.core.model.{Account, CommitComment}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.Profile.dateColumnType
|
||||
import gitbucket.core.model.activity.{CommitCommentInfo, PullRequestCommentInfo}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.Directory._
|
||||
@@ -80,13 +81,9 @@ trait CommitsService {
|
||||
case Some(issueId) =>
|
||||
getPullRequest(repository.owner, repository.name, issueId).foreach {
|
||||
case (issue, pullRequest) =>
|
||||
recordCommentPullRequestActivity(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issueId,
|
||||
content
|
||||
)
|
||||
val pullRequestCommentInfo =
|
||||
PullRequestCommentInfo(repository.owner, repository.name, loginAccount.userName, content, issueId)
|
||||
recordActivity(pullRequestCommentInfo)
|
||||
PluginRegistry().getPullRequestHooks.foreach(_.addedComment(commentId, content, issue, repository))
|
||||
callPullRequestReviewCommentWebHook(
|
||||
"create",
|
||||
@@ -99,13 +96,9 @@ trait CommitsService {
|
||||
)
|
||||
}
|
||||
case None =>
|
||||
recordCommentCommitActivity(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
commitId,
|
||||
content
|
||||
)
|
||||
val commitCommentInfo =
|
||||
CommitCommentInfo(repository.owner, repository.name, loginAccount.userName, content, commitId)
|
||||
recordActivity(commitCommentInfo)
|
||||
}
|
||||
|
||||
commentId
|
||||
|
||||
@@ -3,6 +3,14 @@ package gitbucket.core.service
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.Issue
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.{
|
||||
CloseIssueInfo,
|
||||
ClosePullRequestInfo,
|
||||
IssueCommentInfo,
|
||||
PullRequestCommentInfo,
|
||||
ReopenIssueInfo,
|
||||
ReopenPullRequestInfo
|
||||
}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
@@ -29,25 +37,31 @@ trait HandleCommentService {
|
||||
case (owner, name) =>
|
||||
val userName = loginAccount.userName
|
||||
|
||||
val (action, actionActivity) = actionOpt
|
||||
actionOpt.collect {
|
||||
case "close" if !issue.closed =>
|
||||
updateClosed(owner, name, issue.issueId, true)
|
||||
case "reopen" if issue.closed =>
|
||||
updateClosed(owner, name, issue.issueId, false)
|
||||
}
|
||||
|
||||
val (action, _) = actionOpt
|
||||
.collect {
|
||||
case "close" if (!issue.closed) =>
|
||||
true ->
|
||||
(Some("close") -> Some(
|
||||
if (issue.isPullRequest) recordClosePullRequestActivity _
|
||||
else recordCloseIssueActivity _
|
||||
))
|
||||
case "reopen" if (issue.closed) =>
|
||||
false ->
|
||||
(Some("reopen") -> Some(
|
||||
if (issue.isPullRequest) recordReopenPullRequestActivity _
|
||||
else recordReopenIssueActivity _
|
||||
))
|
||||
}
|
||||
.map {
|
||||
case (closed, t) =>
|
||||
updateClosed(owner, name, issue.issueId, closed)
|
||||
t
|
||||
case "close" if !issue.closed =>
|
||||
val info = if (issue.isPullRequest) {
|
||||
ClosePullRequestInfo(owner, name, userName, issue.issueId, issue.title)
|
||||
} else {
|
||||
CloseIssueInfo(owner, name, userName, issue.issueId, issue.title)
|
||||
}
|
||||
recordActivity(info)
|
||||
Some("close") -> info
|
||||
case "reopen" if issue.closed =>
|
||||
val info = if (issue.isPullRequest) {
|
||||
ReopenPullRequestInfo(owner, name, userName, issue.issueId, issue.title)
|
||||
} else {
|
||||
ReopenIssueInfo(owner, name, userName, issue.issueId, issue.title)
|
||||
}
|
||||
recordActivity(info)
|
||||
Some("reopen") -> info
|
||||
}
|
||||
.getOrElse(None -> None)
|
||||
|
||||
@@ -68,8 +82,12 @@ trait HandleCommentService {
|
||||
)
|
||||
|
||||
// record comment activity
|
||||
if (issue.isPullRequest) recordCommentPullRequestActivity(owner, name, userName, issue.issueId, content)
|
||||
else recordCommentIssueActivity(owner, name, userName, issue.issueId, content)
|
||||
val commentInfo = if (issue.isPullRequest) {
|
||||
PullRequestCommentInfo(owner, name, userName, content, issue.issueId)
|
||||
} else {
|
||||
IssueCommentInfo(owner, name, userName, content, issue.issueId)
|
||||
}
|
||||
recordActivity(commentInfo)
|
||||
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, content, loginAccount)
|
||||
@@ -77,10 +95,6 @@ trait HandleCommentService {
|
||||
id
|
||||
}
|
||||
|
||||
actionActivity.foreach { f =>
|
||||
f(owner, name, userName, issue.issueId, issue.title)
|
||||
}
|
||||
|
||||
// call web hooks
|
||||
action match {
|
||||
case None =>
|
||||
@@ -120,5 +134,4 @@ trait HandleCommentService {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package gitbucket.core.service
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.{Account, Issue}
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.CreateIssueInfo
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.Implicits._
|
||||
@@ -51,7 +52,8 @@ trait IssueCreationService {
|
||||
}
|
||||
|
||||
// record activity
|
||||
recordCreateIssueActivity(owner, name, userName, issueId, title)
|
||||
val createIssueInfo = CreateIssueInfo(owner, name, userName, issueId, title)
|
||||
recordActivity(createIssueInfo)
|
||||
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, title + " " + body.getOrElse(""), loginAccount)
|
||||
|
||||
@@ -8,6 +8,7 @@ import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.{JGitUtil, LockUtil}
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.{CloseIssueInfo, MergeInfo, PushInfo}
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import org.eclipse.jgit.merge.{MergeStrategy, Merger, RecursiveMerger}
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -200,13 +201,14 @@ trait MergeService {
|
||||
}
|
||||
|
||||
// record activity
|
||||
recordPushActivity(
|
||||
val pushInfo = PushInfo(
|
||||
localUserName,
|
||||
localRepositoryName,
|
||||
loginAccount.userName,
|
||||
localBranch,
|
||||
commits
|
||||
)
|
||||
recordActivity(pushInfo)
|
||||
|
||||
// close issue by commit message
|
||||
if (localBranch == localRepository.repository.defaultBranch) {
|
||||
@@ -215,13 +217,14 @@ trait MergeService {
|
||||
.foreach { issueId =>
|
||||
getIssue(localRepository.owner, localRepository.name, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", localRepository, issue, loginAccount, settings)
|
||||
recordCloseIssueActivity(
|
||||
val closeIssueInfo = CloseIssueInfo(
|
||||
localRepository.owner,
|
||||
localRepository.name,
|
||||
localUserName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(
|
||||
_.closedByCommitComment(issue, localRepository, commit.fullMessage, loginAccount)
|
||||
@@ -277,7 +280,8 @@ trait MergeService {
|
||||
updateClosed(repository.owner, repository.name, issueId, true)
|
||||
|
||||
// record activity
|
||||
recordMergeActivity(repository.owner, repository.name, loginAccount.userName, issueId, message)
|
||||
val mergeInfo = MergeInfo(repository.owner, repository.name, loginAccount.userName, issueId, message)
|
||||
recordActivity(mergeInfo)
|
||||
|
||||
val (commits, _) = getRequestCompareInfo(
|
||||
repository.owner,
|
||||
@@ -344,13 +348,14 @@ trait MergeService {
|
||||
).foreach { issueId =>
|
||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", repository, issue, loginAccount, context.settings)
|
||||
recordCloseIssueActivity(
|
||||
val closeIssueInfo = CloseIssueInfo(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(_.closedByCommitComment(issue, repository, commit.fullMessage, loginAccount))
|
||||
}
|
||||
@@ -365,13 +370,14 @@ trait MergeService {
|
||||
).foreach { issueId =>
|
||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", repository, issue, loginAccount, context.settings)
|
||||
recordCloseIssueActivity(
|
||||
val closeIssueInfo = CloseIssueInfo(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount))
|
||||
}
|
||||
@@ -380,13 +386,14 @@ trait MergeService {
|
||||
.foreach { issueId =>
|
||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", repository, issue, loginAccount, context.settings)
|
||||
recordCloseIssueActivity(
|
||||
val closeIssueInfo = CloseIssueInfo(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(_.closedByCommitComment(issue, repository, issueContent, loginAccount))
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import difflib.{Delta, DiffUtils}
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.api.JsonFormat
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.activity.OpenPullRequestInfo
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.Directory._
|
||||
@@ -135,13 +136,14 @@ trait PullRequestService {
|
||||
)
|
||||
|
||||
// record activity
|
||||
recordPullRequestActivity(
|
||||
val openPullRequestInfo = OpenPullRequestInfo(
|
||||
originRepository.owner,
|
||||
originRepository.name,
|
||||
loginAccount.userName,
|
||||
issueId,
|
||||
baseIssue.title
|
||||
)
|
||||
recordActivity(openPullRequestInfo)
|
||||
|
||||
// call web hook
|
||||
callPullRequestWebHook("opened", originRepository, issueId, loginAccount, settings)
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gitbucket.core.service
|
||||
import gitbucket.core.api.JsonFormat
|
||||
import gitbucket.core.model.{Account, WebHook}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.{CloseIssueInfo, PushInfo}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.service.WebHookService.WebHookPushPayload
|
||||
@@ -182,7 +182,8 @@ trait RepositoryCommitFileService {
|
||||
// record activity
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
val commitInfo = new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))
|
||||
recordPushActivity(repository.owner, repository.name, loginAccount.userName, branch, List(commitInfo))
|
||||
val pushInfo = PushInfo(repository.owner, repository.name, loginAccount.userName, branch, List(commitInfo))
|
||||
recordActivity(pushInfo)
|
||||
|
||||
// create issue comment by commit message
|
||||
createIssueComment(repository.owner, repository.name, commitInfo)
|
||||
@@ -192,13 +193,14 @@ trait RepositoryCommitFileService {
|
||||
closeIssuesFromMessage(message, committerName, repository.owner, repository.name).foreach { issueId =>
|
||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", repository, issue, loginAccount, settings)
|
||||
recordCloseIssueActivity(
|
||||
val closeIssueInfo = CloseIssueInfo(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(_.closedByCommitComment(issue, repository, message, loginAccount))
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import java.nio.file.Files
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.{CreateRepositoryInfo, ForkInfo}
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.{FileUtil, JGitUtil, LockUtil}
|
||||
import gitbucket.core.model.{Account, Role}
|
||||
@@ -160,7 +161,7 @@ trait RepositoryCreationService {
|
||||
createWikiRepository(loginAccount, owner, name)
|
||||
|
||||
// Record activity
|
||||
recordCreateRepositoryActivity(owner, name, loginUserName)
|
||||
recordActivity(CreateRepositoryInfo(owner, name, loginUserName))
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.created(owner, name))
|
||||
@@ -229,7 +230,8 @@ trait RepositoryCreationService {
|
||||
}
|
||||
|
||||
// Record activity
|
||||
recordForkActivity(repository.owner, repository.name, loginUserName, accountName)
|
||||
val forkInfo = ForkInfo(repository.owner, repository.name, loginUserName, accountName)
|
||||
recordActivity(forkInfo)
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.forked(repository.owner, accountName, repository.name))
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util
|
||||
import java.util.Date
|
||||
|
||||
import scala.util.Using
|
||||
|
||||
import gitbucket.core.api
|
||||
import gitbucket.core.model.WebHook
|
||||
import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry}
|
||||
@@ -16,6 +15,16 @@ import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.activity.{
|
||||
CloseIssueInfo,
|
||||
CreateBranchInfo,
|
||||
CreateTagInfo,
|
||||
CreateWikiPageInfo,
|
||||
DeleteBranchInfo,
|
||||
DeleteTagInfo,
|
||||
EditWikiPageInfo,
|
||||
PushInfo
|
||||
}
|
||||
// Imported names have higher precedence than names, defined in other files.
|
||||
// If Database is not bound by explicit import, then "Database" refers to the Database introduced by the wildcard import above.
|
||||
import gitbucket.core.servlet.Database
|
||||
@@ -322,13 +331,9 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
||||
closeIssuesFromMessage(commit.fullMessage, pusher, owner, repository).foreach { issueId =>
|
||||
getIssue(owner, repository, issueId.toString).foreach { issue =>
|
||||
callIssuesWebHook("closed", repositoryInfo, issue, pusherAccount, settings)
|
||||
recordCloseIssueActivity(
|
||||
owner,
|
||||
repository,
|
||||
pusherAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title
|
||||
)
|
||||
val closeIssueInfo =
|
||||
CloseIssueInfo(owner, repository, pusherAccount.userName, issue.issueId, issue.title)
|
||||
recordActivity(closeIssueInfo)
|
||||
PluginRegistry().getIssueHooks
|
||||
.foreach(_.closedByCommitComment(issue, repositoryInfo, commit.fullMessage, pusherAccount))
|
||||
}
|
||||
@@ -356,17 +361,25 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
||||
// record activity
|
||||
if (refName(1) == "heads") {
|
||||
command.getType match {
|
||||
case ReceiveCommand.Type.CREATE => recordCreateBranchActivity(owner, repository, pusher, branchName)
|
||||
case ReceiveCommand.Type.UPDATE => recordPushActivity(owner, repository, pusher, branchName, newCommits)
|
||||
case ReceiveCommand.Type.DELETE => recordDeleteBranchActivity(owner, repository, pusher, branchName)
|
||||
case _ =>
|
||||
case ReceiveCommand.Type.CREATE =>
|
||||
val createBranchInfo = CreateBranchInfo(owner, repository, pusher, branchName)
|
||||
recordActivity(createBranchInfo)
|
||||
case ReceiveCommand.Type.UPDATE =>
|
||||
val pushInfo = PushInfo(owner, repository, pusher, branchName, newCommits)
|
||||
recordActivity(pushInfo)
|
||||
case ReceiveCommand.Type.DELETE =>
|
||||
val deleteBranchInfo = DeleteBranchInfo(owner, repository, pusher, branchName)
|
||||
recordActivity(deleteBranchInfo)
|
||||
case _ =>
|
||||
}
|
||||
} else if (refName(1) == "tags") {
|
||||
command.getType match {
|
||||
case ReceiveCommand.Type.CREATE =>
|
||||
recordCreateTagActivity(owner, repository, pusher, branchName, newCommits)
|
||||
val createTagInfo = CreateTagInfo(owner, repository, pusher, branchName)
|
||||
recordActivity(createTagInfo)
|
||||
case ReceiveCommand.Type.DELETE =>
|
||||
recordDeleteTagActivity(owner, repository, pusher, branchName, newCommits)
|
||||
val deleteTagInfo = DeleteTagInfo(owner, repository, pusher, branchName)
|
||||
recordActivity(deleteTagInfo)
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
@@ -475,20 +488,22 @@ class WikiCommitHook(owner: String, repository: String, pusher: String, baseUrl:
|
||||
updateLastActivityDate(owner, repository)
|
||||
action match {
|
||||
case "created" =>
|
||||
recordCreateWikiPageActivity(
|
||||
val createWikiPageInfo = CreateWikiPageInfo(
|
||||
owner,
|
||||
repository,
|
||||
commit.committerName,
|
||||
fileName.dropRight(".md".length)
|
||||
)
|
||||
recordActivity(createWikiPageInfo)
|
||||
case "edited" =>
|
||||
recordEditWikiPageActivity(
|
||||
val editWikiPageInfo = EditWikiPageInfo(
|
||||
owner,
|
||||
repository,
|
||||
commit.committerName,
|
||||
fileName.dropRight(".md".length),
|
||||
commit.id
|
||||
)
|
||||
recordActivity(editWikiPageInfo)
|
||||
case _ =>
|
||||
}
|
||||
(action, fileName, commit.id)
|
||||
|
||||
Reference in New Issue
Block a user