Skip to content

Commit 8ceaf86

Browse files
committed
Create notification plugin.
1 parent 4e269e9 commit 8ceaf86

File tree

9 files changed

+183
-0
lines changed

9 files changed

+183
-0
lines changed

.gitignore

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,25 @@
11
*.class
22
*.log
3+
4+
# sbt specific
5+
dist/*
6+
target/
7+
lib_managed/
8+
src_managed/
9+
project/boot/
10+
project/plugins/project/
11+
12+
# Scala-IDE specific
13+
.scala_dependencies
14+
.classpath
15+
.project
16+
.cache
17+
.settings
18+
19+
# IntelliJ specific
20+
.idea/
21+
.idea_modules/
22+
23+
# Ensime
24+
.ensime
25+
.ensime_cache/

build.sbt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
name := "gitbucket-notifications-plugin"
2+
3+
organization := "io.github.gitbucket"
4+
version := "1.0.0"
5+
scalaVersion := "2.12.2"
6+
7+
libraryDependencies ++= Seq(
8+
"io.github.gitbucket" %% "gitbucket" % "4.14.0-SNAPSHOT" % "provided",
9+
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided"
10+
)
11+
12+
scalacOptions ++= Seq("-feature", "-deprecation")
13+
useJCenter := true

project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.15
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<changeSet>
3+
<!--================================================================================================-->
4+
<!-- ISSUE_NOTIFICATION -->
5+
<!--================================================================================================-->
6+
<createTable tableName="ISSUE_NOTIFICATION">
7+
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
8+
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
9+
<column name="ISSUE_ID" type="int" nullable="false"/>
10+
<column name="NOTIFICATION_USER_NAME" type="varchar(100)" nullable="false"/>
11+
<column name="SUBSCRIBED" type="boolean" nullable="false"/>
12+
</createTable>
13+
14+
<addPrimaryKey constraintName="IDX_ISSUE_NOTIFICATION_PK" tableName="ISSUE_NOTIFICATION" columnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID, NOTIFICATION_USER_NAME"/>
15+
<addForeignKeyConstraint constraintName="IDX_ISSUE_NOTIFICATION_FK0" baseTableName="ISSUE_NOTIFICATION" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
16+
<addForeignKeyConstraint constraintName="IDX_ISSUE_NOTIFICATION_FK1" baseTableName="ISSUE_NOTIFICATION" baseColumnNames="NOTIFICATION_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
17+
18+
<!--================================================================================================-->
19+
<!-- WATCH -->
20+
<!--================================================================================================-->
21+
<createTable tableName="WATCH">
22+
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
23+
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
24+
<column name="NOTIFICATION_USER_NAME" type="varchar(100)" nullable="false"/>
25+
<column name="NOTIFICATION" type="varchar(20)" nullable="false"/>
26+
</createTable>
27+
28+
<addPrimaryKey constraintName="IDX_WATCH_PK" tableName="WATCH" columnNames="USER_NAME, REPOSITORY_NAME, NOTIFICATION_USER_NAME"/>
29+
<addForeignKeyConstraint constraintName="IDX_WATCH_FK0" baseTableName="WATCH" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
30+
<addForeignKeyConstraint constraintName="IDX_WATCH_FK1" baseTableName="WATCH" baseColumnNames="NOTIFICATION_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
31+
32+
</changeSet>

src/main/scala/Plugin.scala

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import gitbucket.core.plugin._
2+
import io.github.gitbucket.solidbase.migration.LiquibaseMigration
3+
import io.github.gitbucket.solidbase.model.Version
4+
5+
class Plugin extends gitbucket.core.plugin.Plugin {
6+
7+
override val pluginId: String = "notifications"
8+
9+
override val pluginName: String = "Notifications Plugin"
10+
11+
override val description: String = "Provides Notifications feature on GitBucket."
12+
13+
override val versions: List[Version] = List(
14+
new Version("1.0.0",
15+
new LiquibaseMigration("update/gitbucket-notifications_1.0.xml")
16+
)
17+
)
18+
19+
20+
override val accountHooks: Seq[AccountHook] = Seq(
21+
)
22+
23+
override val repositoryHooks: Seq[RepositoryHook] = Seq(
24+
)
25+
26+
override val issueHooks: Seq[IssueHook] = Seq(
27+
)
28+
29+
override val pullRequestHooks: Seq[PullRequestHook] = Seq(
30+
)
31+
32+
33+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package gitbucket.notifications.model
2+
3+
trait IssueNotificationComponent { self: gitbucket.core.model.Profile =>
4+
import profile.api._
5+
6+
lazy val IssueNotifications = TableQuery[IssueNotifications]
7+
8+
class IssueNotifications(tag: Tag) extends Table[IssueNotification](tag, "ISSUE_NOTIFICATION") {
9+
val userName = column[String]("USER_NAME")
10+
val repositoryName = column[String]("REPOSITORY_NAME")
11+
val issueId = column[Int]("ISSUE_ID")
12+
val notificationUserName = column[String]("NOTIFICATION_USER_NAME")
13+
val subscribed = column[Boolean]("SUBSCRIBED")
14+
def * = (userName, repositoryName, issueId, notificationUserName, subscribed) <> (IssueNotification.tupled, IssueNotification.unapply)
15+
}
16+
}
17+
18+
case class IssueNotification(
19+
userName: String,
20+
repositoryName: String,
21+
issueId: Int,
22+
notificationUserName: String,
23+
subscribed: Boolean
24+
)
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package gitbucket.notifications.model
2+
3+
import gitbucket.core.model._
4+
5+
object Profile extends CoreProfile
6+
with IssueNotificationComponent
7+
with WatchComponent
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package gitbucket.notifications.model
2+
3+
trait WatchComponent { self: gitbucket.core.model.Profile =>
4+
import profile.api._
5+
6+
implicit val watchNotificationType = MappedColumnType.base[Watch.Notification, String](_.code, Watch.Notification.valueOf)
7+
8+
lazy val Watches = TableQuery[Watches]
9+
10+
class Watches(tag: Tag) extends Table[Watch](tag, "WATCH") {
11+
val userName = column[String]("USER_NAME")
12+
val repositoryName = column[String]("REPOSITORY_NAME")
13+
val notificationUserName = column[String]("NOTIFICATION_USER_NAME")
14+
val notification = column[Watch.Notification]("NOTIFICATION")
15+
def * = (userName, repositoryName, notificationUserName, notification) <> ((Watch.apply _).tupled, Watch.unapply)
16+
}
17+
}
18+
19+
case class Watch(
20+
userName: String,
21+
repositoryName: String,
22+
notificationUserName: String,
23+
notification: Watch.Notification
24+
)
25+
26+
object Watch {
27+
abstract sealed class Notification(val code: String)
28+
case object Watching extends Notification("watching")
29+
case object NotWatching extends Notification("not_watching")
30+
case object Ignoring extends Notification("ignoring")
31+
32+
private[model] object Notification {
33+
private val values: Seq[Notification] = Seq(Watching, NotWatching, Ignoring)
34+
def valueOf(code: String): Notification = values.find(_.code == code).get
35+
}
36+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package gitbucket.notifications.service
2+
3+
import gitbucket.core.plugin._
4+
import gitbucket.notifications.model.Profile._
5+
import profile.blockingApi._
6+
7+
trait NotificationsAccountHook extends AccountHook {
8+
9+
override def deleted(userName: String)(implicit session: Session): Unit = {
10+
IssueNotifications.filter(_.notificationUserName === userName.bind).delete
11+
Watches.filter(_.notificationUserName === userName.bind).delete
12+
}
13+
14+
}

0 commit comments

Comments
 (0)