mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-01 02:56:08 +01:00
(refs #4)The base of activity timeline is completed.
This commit is contained in:
@@ -9,6 +9,16 @@ CREATE TABLE ACTIVITY(
|
|||||||
ACTIVITY_DATE TIMESTAMP NOT NULL
|
ACTIVITY_DATE TIMESTAMP NOT NULL
|
||||||
);
|
);
|
||||||
|
|
||||||
|
CREATE TABLE COMMIT_LOG (
|
||||||
|
USER_NAME VARCHAR(100) NOT NULL,
|
||||||
|
REPOSITORY_NAME VARCHAR(100) NOT NULL,
|
||||||
|
COMMIT_ID VARCHAR(40) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_PK PRIMARY KEY (ACTIVITY_ID);
|
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_PK PRIMARY KEY (ACTIVITY_ID);
|
||||||
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME) REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME);
|
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME) REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME);
|
||||||
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_FK1 FOREIGN KEY (ACTIVITY_USER_NAME) REFERENCES ACCOUNT (USER_NAME);
|
ALTER TABLE ACTIVITY ADD CONSTRAINT IDX_ACTIVITY_FK1 FOREIGN KEY (ACTIVITY_USER_NAME) REFERENCES ACCOUNT (USER_NAME);
|
||||||
|
|
||||||
|
ALTER TABLE COMMIT_LOG ADD CONSTRAINT IDX_COMMIT_LOG_PK PRIMARY KEY (USER_NAME, REPOSITORY_NAME, COMMIT_ID);
|
||||||
|
ALTER TABLE COMMIT_LOG ADD CONSTRAINT IDX_COMMIT_LOG_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME) REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME);
|
||||||
|
|
||||||
|
|||||||
@@ -13,6 +13,12 @@ object Activities extends Table[Activity]("ACTIVITY") with BasicTemplate with Fu
|
|||||||
def autoInc = userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate returning activityId
|
def autoInc = userName ~ repositoryName ~ activityUserName ~ activityType ~ message ~ additionalInfo.? ~ activityDate returning activityId
|
||||||
}
|
}
|
||||||
|
|
||||||
|
object CommitLog extends Table[(String, String, String)]("COMMIT_LOG") with BasicTemplate {
|
||||||
|
def commitId = column[String]("COMMIT_ID")
|
||||||
|
def * = userName ~ repositoryName ~ commitId
|
||||||
|
def byPrimaryKey(userName: String, repositoryName: String, commitId: String) = byRepository(userName, repositoryName) && (this.commitId is commitId.bind)
|
||||||
|
}
|
||||||
|
|
||||||
case class Activity(
|
case class Activity(
|
||||||
activityId: Int,
|
activityId: Int,
|
||||||
userName: String,
|
userName: String,
|
||||||
|
|||||||
@@ -87,14 +87,20 @@ trait ActivityService {
|
|||||||
None,
|
None,
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordCreateBranchActivity(userName: String, repositoryName: String, activityUserName: String, branchName: String) =
|
||||||
branchName: String, commits: List[util.JGitUtil.CommitInfo]) =
|
|
||||||
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
Activities.autoInc insert(userName, repositoryName, activityUserName,
|
||||||
"create_tag",
|
"create_tag",
|
||||||
s"[user:${activityUserName}] created branch [tag:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] created branch [tag:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
|
def insertCommitId(userName: String, repositoryName: String, commitId: String) = {
|
||||||
|
CommitLog insert (userName, repositoryName, commitId)
|
||||||
|
}
|
||||||
|
|
||||||
|
def existsCommitId(userName: String, repositoryName: String, commitId: String): Boolean =
|
||||||
|
Query(CommitLog).filter(_.byPrimaryKey(userName, repositoryName, commitId)).firstOption.isDefined
|
||||||
|
|
||||||
private def cut(value: String, length: Int): String =
|
private def cut(value: String, length: Int): String =
|
||||||
if(value.length > length) value.substring(0, length) + "..." else value
|
if(value.length > length) value.substring(0, length) + "..." else value
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -76,37 +76,37 @@ class CommitLogHook(owner: String, repository: String, userName: String) extends
|
|||||||
JGitUtil.withGit(Directory.getRepositoryDir(owner, repository)) { git =>
|
JGitUtil.withGit(Directory.getRepositoryDir(owner, repository)) { git =>
|
||||||
commands.asScala.foreach { command =>
|
commands.asScala.foreach { command =>
|
||||||
val commits = JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
val commits = JGitUtil.getCommitLog(git, command.getOldId.name, command.getNewId.name)
|
||||||
.filter(commit => JGitUtil.getBranchesOfCommit(git, commit.id).length == 1)
|
|
||||||
val refName = command.getRefName.split("/")
|
val refName = command.getRefName.split("/")
|
||||||
|
|
||||||
println("****************************")
|
|
||||||
println(command.getRefName)
|
|
||||||
println(command.getMessage)
|
|
||||||
println(command.getResult)
|
|
||||||
println(command.getType)
|
|
||||||
println("****************************")
|
|
||||||
|
|
||||||
// apply issue comment
|
// apply issue comment
|
||||||
if(refName(1) == "heads"){
|
val newCommits = commits.flatMap { commit =>
|
||||||
commits.foreach { commit =>
|
if(!existsCommitId(owner, repository, commit.id)){
|
||||||
|
insertCommitId(owner, repository, commit.id)
|
||||||
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
"(^|\\W)#(\\d+)(\\W|$)".r.findAllIn(commit.fullMessage).matchData.foreach { matchData =>
|
||||||
val issueId = matchData.group(2)
|
val issueId = matchData.group(2)
|
||||||
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
if(getAccountByUserName(commit.committer).isDefined && getIssue(owner, repository, issueId).isDefined){
|
||||||
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage, None)
|
createComment(owner, repository, commit.committer, issueId.toInt, commit.fullMessage, None)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
Some(commit)
|
||||||
}
|
} else None
|
||||||
|
}.toList
|
||||||
git.getRepository.getAllRefs.asScala.map { e =>
|
|
||||||
println(e._1)
|
|
||||||
}
|
|
||||||
|
|
||||||
// record activity
|
// record activity
|
||||||
if(refName(1) == "heads"){
|
if(refName(1) == "heads"){
|
||||||
recordPushActivity(owner, repository, userName, refName(2), commits)
|
command.getType match {
|
||||||
|
case ReceiveCommand.Type.CREATE => {
|
||||||
|
recordCreateBranchActivity(owner, repository, userName, refName(2))
|
||||||
|
recordPushActivity(owner, repository, userName, refName(2), newCommits)
|
||||||
|
}
|
||||||
|
case ReceiveCommand.Type.UPDATE => recordPushActivity(owner, repository, userName, refName(2), newCommits)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
} else if(refName(1) == "tags"){
|
} else if(refName(1) == "tags"){
|
||||||
recordCreateTagActivity(owner, repository, userName, refName(2), commits)
|
command.getType match {
|
||||||
|
case ReceiveCommand.Type.CREATE => recordCreateTagActivity(owner, repository, userName, refName(2), newCommits)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,18 +20,18 @@
|
|||||||
} else {
|
} else {
|
||||||
@activities.map { activity =>
|
@activities.map { activity =>
|
||||||
<div class="block">
|
<div class="block">
|
||||||
<div class="muted smal">@datetime(activity.activityDate)</div>
|
<div class="muted small">@datetime(activity.activityDate)</div>
|
||||||
<div class="strong">@activityMessage(activity.message)</div>
|
<div class="strong">@activityMessage(activity.message)</div>
|
||||||
@activity.additionalInfo.map { additionalInfo =>
|
@activity.additionalInfo.map { additionalInfo =>
|
||||||
@(activity.activityType match {
|
@(activity.activityType match {
|
||||||
case "create_wiki" => {
|
case "create_wiki" => {
|
||||||
<div>Created <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
<div class="small">Created <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
||||||
}
|
}
|
||||||
case "edit_wiki" => {
|
case "edit_wiki" => {
|
||||||
<div>Edited <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
<div class="small">Edited <a href={"%s/%s/%s/wiki/%s".format(path, activity.userName, activity.repositoryName, additionalInfo)}>{additionalInfo}</a>.</div>
|
||||||
}
|
}
|
||||||
case "push" => {
|
case "push" => {
|
||||||
<div>
|
<div class="small">
|
||||||
{additionalInfo.split("\n").map{ commit =>
|
{additionalInfo.split("\n").map{ commit =>
|
||||||
<div>
|
<div>
|
||||||
<a href={"%s/%s/%s/commit/%s".format(path, activity.userName, activity.repositoryName, commit.substring(0, 40))} class="monospace">{commit.substring(0, 7)}</a>
|
<a href={"%s/%s/%s/commit/%s".format(path, activity.userName, activity.repositoryName, commit.substring(0, 40))} class="monospace">{commit.substring(0, 7)}</a>
|
||||||
|
|||||||
Reference in New Issue
Block a user