mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-06 21:45:50 +01:00
Improve API compatibility for SourceTree and Drone.io (#2286)
This commit is contained in:
committed by
Naoki Takezoe
parent
f7defffeab
commit
841e6d110c
58
src/main/resources/update/gitbucket-core_4.32.xml
Normal file
58
src/main/resources/update/gitbucket-core_4.32.xml
Normal file
@@ -0,0 +1,58 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<!-- add ID column to REPOSITORY table -->
|
||||||
|
|
||||||
|
<!-- drop other table's foreign keys -->
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_ACTIVITY_FK0" baseTableName="ACTIVITY"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_COLLABORATOR_FK0" baseTableName="COLLABORATOR"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_COMMIT_COMMENT_FK0" baseTableName="COMMIT_COMMENT"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK1" baseTableName="COMMIT_STATUS"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_LABEL_FK0" baseTableName="LABEL"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_MILESTONE_FK0" baseTableName="MILESTONE"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_ISSUE_FK0" baseTableName="ISSUE"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_ISSUE_ID_FK1" baseTableName="ISSUE_ID"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_FK0" baseTableName="PROTECTED_BRANCH"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_DEPLOY_KEY_FK0" baseTableName="DEPLOY_KEY"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_PRIORITY_FK0" baseTableName="PRIORITY"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_RELEASE_TAG_FK0" baseTableName="RELEASE_TAG"/>
|
||||||
|
|
||||||
|
<!-- modify REPOSITORY table -->
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_REPOSITORY_FK0" baseTableName="REPOSITORY"/>
|
||||||
|
<dropPrimaryKey tableName="REPOSITORY" constraintName="IDX_REPOSITORY_PK"/>
|
||||||
|
<addColumn tableName="REPOSITORY">
|
||||||
|
<column name="REPOSITORY_ID" type="int" nullable="false" autoIncrement="false" unique="true"/>
|
||||||
|
</addColumn>
|
||||||
|
<addPrimaryKey constraintName="IDX_REPOSITORY_PK" tableName="REPOSITORY" columnNames="REPOSITORY_ID"/>
|
||||||
|
<addAutoIncrement tableName="REPOSITORY" columnName="REPOSITORY_ID" columnDataType="int"/>
|
||||||
|
<addUniqueConstraint constraintName="IDX_REPOSITORY_1" tableName="REPOSITORY" columnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_REPOSITORY_FK0" baseTableName="REPOSITORY" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
||||||
|
|
||||||
|
<!-- Repair other table's foreign keys -->
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ACTIVITY_FK0" baseTableName="ACTIVITY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_COLLABORATOR_FK0" baseTableName="COLLABORATOR" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_COMMIT_COMMENT_FK0" baseTableName="COMMIT_COMMENT" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK1" baseTableName="COMMIT_STATUS" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_LABEL_FK0" baseTableName="LABEL" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_MILESTONE_FK0" baseTableName="MILESTONE" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_FK0" baseTableName="ISSUE" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_ID_FK1" baseTableName="ISSUE_ID" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_FK0" baseTableName="PROTECTED_BRANCH" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_DEPLOY_KEY_FK0" baseTableName="DEPLOY_KEY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_PRIORITY_FK0" baseTableName="PRIORITY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_RELEASE_TAG_FK0" baseTableName="RELEASE_TAG" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
|
||||||
|
<!-- add ID column to WEB_HOOK table -->
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK"/>
|
||||||
|
<dropPrimaryKey tableName="WEB_HOOK" constraintName="IDX_WEB_HOOK_PK"/>
|
||||||
|
<addColumn tableName="WEB_HOOK">
|
||||||
|
<column name="WEB_HOOK_ID" type="int" nullable="false" autoIncrement="false" unique="true"/>
|
||||||
|
</addColumn>
|
||||||
|
<addPrimaryKey constraintName="IDX_WEB_HOOK_PK" tableName="WEB_HOOK" columnNames="WEB_HOOK_ID"/>
|
||||||
|
<addAutoIncrement tableName="WEB_HOOK" columnName="WEB_HOOK_ID" columnDataType="int"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
<addUniqueConstraint constraintName="IDX_WEB_HOOK_1" tableName="WEB_HOOK" columnNames="USER_NAME, REPOSITORY_NAME, URL"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, URL" referencedTableName="WEB_HOOK" referencedColumnNames="USER_NAME, REPOSITORY_NAME, URL" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
</changeSet>
|
||||||
@@ -63,5 +63,6 @@ object GitBucketCoreModule
|
|||||||
new Version("4.30.1"),
|
new Version("4.30.1"),
|
||||||
new Version("4.31.0", new LiquibaseMigration("update/gitbucket-core_4.31.xml")),
|
new Version("4.31.0", new LiquibaseMigration("update/gitbucket-core_4.31.xml")),
|
||||||
new Version("4.31.1"),
|
new Version("4.31.1"),
|
||||||
new Version("4.31.2")
|
new Version("4.31.2"),
|
||||||
|
new Version("4.32.0", new LiquibaseMigration("update/gitbucket-core_4.32.xml"))
|
||||||
)
|
)
|
||||||
|
|||||||
16
src/main/scala/gitbucket/core/api/ApiEmail.scala
Normal file
16
src/main/scala/gitbucket/core/api/ApiEmail.scala
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
import gitbucket.core.model.Account
|
||||||
|
|
||||||
|
case class ApiEmail(
|
||||||
|
email: String,
|
||||||
|
primary: Boolean
|
||||||
|
) {
|
||||||
|
val verified = true
|
||||||
|
val visibility = "public"
|
||||||
|
}
|
||||||
|
|
||||||
|
object ApiEmail {
|
||||||
|
def fromMailAddresses(primaryMailAddress: String, extraMailAddresses: List[String]): List[ApiEmail] = {
|
||||||
|
ApiEmail(primaryMailAddress, true) :: extraMailAddresses.map { ApiEmail(_, false) }
|
||||||
|
}
|
||||||
|
}
|
||||||
13
src/main/scala/gitbucket/core/api/ApiPermission.scala
Normal file
13
src/main/scala/gitbucket/core/api/ApiPermission.scala
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
import gitbucket.core.service.RepositoryService
|
||||||
|
|
||||||
|
case class ApiPermission(
|
||||||
|
admin: Boolean,
|
||||||
|
push: Boolean,
|
||||||
|
pull: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
object ApiPermission {
|
||||||
|
def apply(permission: RepositoryService.RepositoryPermission): ApiPermission =
|
||||||
|
ApiPermission(permission.isOwner, permission.isDeveloper, permission.isGuest)
|
||||||
|
}
|
||||||
@@ -1,6 +1,9 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
import java.time.Instant
|
||||||
|
|
||||||
import gitbucket.core.model.{Account, Repository}
|
import gitbucket.core.model.{Account, Repository}
|
||||||
|
import gitbucket.core.service.RepositoryService
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
|
||||||
// https://developer.github.com/v3/repos/
|
// https://developer.github.com/v3/repos/
|
||||||
@@ -8,13 +11,17 @@ case class ApiRepository(
|
|||||||
name: String,
|
name: String,
|
||||||
full_name: String,
|
full_name: String,
|
||||||
description: String,
|
description: String,
|
||||||
|
id: Int,
|
||||||
watchers: Int,
|
watchers: Int,
|
||||||
forks: Int,
|
forks: Int,
|
||||||
`private`: Boolean,
|
`private`: Boolean,
|
||||||
|
fork: Boolean,
|
||||||
default_branch: String,
|
default_branch: String,
|
||||||
owner: ApiUser
|
owner: ApiUser,
|
||||||
|
created_at: java.util.Date,
|
||||||
|
updated_at: java.util.Date,
|
||||||
|
permissions: Option[ApiPermission]
|
||||||
) {
|
) {
|
||||||
val id = 0 // dummy id
|
|
||||||
val forks_count = forks
|
val forks_count = forks
|
||||||
val watchers_count = watchers
|
val watchers_count = watchers
|
||||||
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
||||||
@@ -28,6 +35,7 @@ object ApiRepository {
|
|||||||
def apply(
|
def apply(
|
||||||
repository: Repository,
|
repository: Repository,
|
||||||
owner: ApiUser,
|
owner: ApiUser,
|
||||||
|
permission: Option[RepositoryService.RepositoryPermission],
|
||||||
forkedCount: Int = 0,
|
forkedCount: Int = 0,
|
||||||
watchers: Int = 0
|
watchers: Int = 0
|
||||||
): ApiRepository =
|
): ApiRepository =
|
||||||
@@ -35,28 +43,45 @@ object ApiRepository {
|
|||||||
name = repository.repositoryName,
|
name = repository.repositoryName,
|
||||||
full_name = s"${repository.userName}/${repository.repositoryName}",
|
full_name = s"${repository.userName}/${repository.repositoryName}",
|
||||||
description = repository.description.getOrElse(""),
|
description = repository.description.getOrElse(""),
|
||||||
|
id = repository.repositoryId,
|
||||||
watchers = watchers,
|
watchers = watchers,
|
||||||
forks = forkedCount,
|
forks = forkedCount,
|
||||||
`private` = repository.isPrivate,
|
`private` = repository.isPrivate,
|
||||||
|
fork = repository.parentRepositoryName.isDefined,
|
||||||
default_branch = repository.defaultBranch,
|
default_branch = repository.defaultBranch,
|
||||||
owner = owner
|
owner = owner,
|
||||||
|
created_at = repository.registeredDate,
|
||||||
|
updated_at = repository.updatedDate,
|
||||||
|
permission.map(ApiPermission(_))
|
||||||
)
|
)
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
def apply(
|
||||||
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
|
repositoryInfo: RepositoryInfo,
|
||||||
|
owner: Account,
|
||||||
|
permission: RepositoryService.RepositoryPermission
|
||||||
|
): ApiRepository =
|
||||||
|
ApiRepository(repositoryInfo.repository, ApiUser(owner), Some(permission), forkedCount = repositoryInfo.forkedCount)
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
def apply(
|
||||||
this(repositoryInfo, ApiUser(owner))
|
repositoryInfo: RepositoryInfo,
|
||||||
|
owner: Account
|
||||||
|
): ApiRepository =
|
||||||
|
ApiRepository(repositoryInfo.repository, ApiUser(owner), None, forkedCount = repositoryInfo.forkedCount)
|
||||||
|
|
||||||
def forDummyPayload(owner: ApiUser): ApiRepository =
|
def forDummyPayload(owner: ApiUser): ApiRepository =
|
||||||
ApiRepository(
|
ApiRepository(
|
||||||
name = "dummy",
|
name = "dummy",
|
||||||
full_name = s"${owner.login}/dummy",
|
full_name = s"${owner.login}/dummy",
|
||||||
description = "",
|
description = "",
|
||||||
|
id = 0,
|
||||||
watchers = 0,
|
watchers = 0,
|
||||||
forks = 0,
|
forks = 0,
|
||||||
`private` = false,
|
`private` = false,
|
||||||
|
fork = false,
|
||||||
default_branch = "master",
|
default_branch = "master",
|
||||||
owner = owner
|
owner = owner,
|
||||||
|
new java.util.Date,
|
||||||
|
new java.util.Date,
|
||||||
|
Some(ApiPermission(RepositoryService.RepositoryPermission(true, true, true)))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
23
src/main/scala/gitbucket/core/api/ApiRepositoryWebhook.scala
Normal file
23
src/main/scala/gitbucket/core/api/ApiRepositoryWebhook.scala
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
import gitbucket.core.model.RepositoryWebHook
|
||||||
|
import gitbucket.core.model.WebHook
|
||||||
|
|
||||||
|
case class ApiRepositoryWebhook(
|
||||||
|
id: Int,
|
||||||
|
events: Seq[String],
|
||||||
|
config: ApiWebhook
|
||||||
|
) {
|
||||||
|
val active = true
|
||||||
|
val name = "web"
|
||||||
|
}
|
||||||
|
|
||||||
|
object ApiRepositoryWebhook {
|
||||||
|
def apply(repositoryWebhook: RepositoryWebHook, events: Set[WebHook.Event]): ApiRepositoryWebhook =
|
||||||
|
ApiRepositoryWebhook(
|
||||||
|
id = repositoryWebhook.webHookId,
|
||||||
|
events = events.map { e =>
|
||||||
|
e.name
|
||||||
|
}.toSeq,
|
||||||
|
config = ApiWebhook(repositoryWebhook.url, repositoryWebhook.ctype.ctype)
|
||||||
|
)
|
||||||
|
}
|
||||||
4
src/main/scala/gitbucket/core/api/ApiWebhook.scala
Normal file
4
src/main/scala/gitbucket/core/api/ApiWebhook.scala
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
import gitbucket.core.model.WebHook
|
||||||
|
|
||||||
|
case class ApiWebhook(url: String, content_type: String)
|
||||||
15
src/main/scala/gitbucket/core/api/CreateAWebhook.scala
Normal file
15
src/main/scala/gitbucket/core/api/CreateAWebhook.scala
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
case class CreateAWebhookConfig(
|
||||||
|
url: String,
|
||||||
|
content_type: String = "form",
|
||||||
|
secret: Option[String],
|
||||||
|
insecure_ssl: Option[String]
|
||||||
|
)
|
||||||
|
|
||||||
|
case class CreateAWebhook(
|
||||||
|
name: Option[String],
|
||||||
|
config: CreateAWebhookConfig,
|
||||||
|
events: Seq[String],
|
||||||
|
active: Option[Boolean]
|
||||||
|
)
|
||||||
@@ -45,6 +45,10 @@ object JsonFormat {
|
|||||||
FieldSerializer[ApiCommits.File]() +
|
FieldSerializer[ApiCommits.File]() +
|
||||||
FieldSerializer[ApiRelease]() +
|
FieldSerializer[ApiRelease]() +
|
||||||
FieldSerializer[ApiReleaseAsset]() +
|
FieldSerializer[ApiReleaseAsset]() +
|
||||||
|
FieldSerializer[ApiPermission]() +
|
||||||
|
FieldSerializer[ApiWebhook]() +
|
||||||
|
FieldSerializer[ApiRepositoryWebhook]() +
|
||||||
|
FieldSerializer[ApiEmail]() +
|
||||||
ApiBranchProtection.enforcementLevelSerializer
|
ApiBranchProtection.enforcementLevelSerializer
|
||||||
|
|
||||||
def apiPathSerializer(c: Context) =
|
def apiPathSerializer(c: Context) =
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ class ApiController
|
|||||||
with ApiRepositoryContentsControllerBase
|
with ApiRepositoryContentsControllerBase
|
||||||
with ApiRepositoryControllerBase
|
with ApiRepositoryControllerBase
|
||||||
with ApiRepositoryStatusControllerBase
|
with ApiRepositoryStatusControllerBase
|
||||||
|
with ApiRepositoryWebhookcontrollerBase
|
||||||
with ApiUserControllerBase
|
with ApiUserControllerBase
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
with AccountService
|
with AccountService
|
||||||
|
|||||||
@@ -53,8 +53,12 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
ApiPullRequest(
|
ApiPullRequest(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
pullRequest = pullRequest,
|
pullRequest = pullRequest,
|
||||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
headRepo = ApiRepository(
|
||||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
headRepo,
|
||||||
|
ApiUser(headOwner),
|
||||||
|
Some(getPermission(headRepo.userName, headRepo.repositoryName, context.loginAccount))
|
||||||
|
),
|
||||||
|
baseRepo = ApiRepository(repository, baseOwner),
|
||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository))),
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
@@ -239,8 +243,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
ApiPullRequest(
|
ApiPullRequest(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
pullRequest = pullRequest,
|
pullRequest = pullRequest,
|
||||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
headRepo = ApiRepository(headRepo, headOwner),
|
||||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
baseRepo = ApiRepository(repository, baseOwner),
|
||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository))),
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/api/v3/user/repos")(usersOnly {
|
get("/api/v3/user/repos")(usersOnly {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Option(context.loginAccount.get.userName)).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Option(context.loginAccount.get.userName)).map { r =>
|
||||||
ApiRepository(r, getAccountByUserName(r.owner).get)
|
ApiRepository(r, getAccountByUserName(r.owner).get, getPermission(r.owner, r.name, context.loginAccount))
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/api/v3/users/:userName/repos") {
|
get("/api/v3/users/:userName/repos") {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("userName"))).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("userName"))).map { r =>
|
||||||
ApiRepository(r, getAccountByUserName(r.owner).get)
|
ApiRepository(r, getAccountByUserName(r.owner).get, getPermission(r.owner, r.name, context.loginAccount))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/api/v3/orgs/:orgName/repos") {
|
get("/api/v3/orgs/:orgName/repos") {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("orgName"))).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("orgName"))).map { r =>
|
||||||
ApiRepository(r, getAccountByUserName(r.owner).get)
|
ApiRepository(r, getAccountByUserName(r.owner).get, getPermission(r.owner, r.name, context.loginAccount))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,7 +90,13 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
val repository = Database() withTransaction { session =>
|
val repository = Database() withTransaction { session =>
|
||||||
getRepository(owner, data.name)(session).get
|
getRepository(owner, data.name)(session).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get)))
|
JsonFormat(
|
||||||
|
ApiRepository(
|
||||||
|
repository,
|
||||||
|
getAccountByUserName(owner).get,
|
||||||
|
getPermission(repository.owner, repository.name, context.loginAccount)
|
||||||
|
)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ApiError(
|
ApiError(
|
||||||
"A repository with this name already exists on this account",
|
"A repository with this name already exists on this account",
|
||||||
@@ -124,7 +130,13 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
val repository = Database() withTransaction { session =>
|
val repository = Database() withTransaction { session =>
|
||||||
getRepository(groupName, data.name).get
|
getRepository(groupName, data.name).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get)))
|
JsonFormat(
|
||||||
|
ApiRepository(
|
||||||
|
repository,
|
||||||
|
getAccountByUserName(groupName).get,
|
||||||
|
getPermission(repository.owner, repository.name, context.loginAccount)
|
||||||
|
)
|
||||||
|
)
|
||||||
} else {
|
} else {
|
||||||
ApiError(
|
ApiError(
|
||||||
"A repository with this name already exists for this group",
|
"A repository with this name already exists for this group",
|
||||||
@@ -140,7 +152,13 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
* https://developer.github.com/v3/repos/#get
|
* https://developer.github.com/v3/repos/#get
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository")(referrersOnly { repository =>
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(repository.owner).get)))
|
JsonFormat(
|
||||||
|
ApiRepository(
|
||||||
|
repository,
|
||||||
|
getAccountByUserName(repository.owner).get,
|
||||||
|
getPermission(repository.owner, repository.name, context.loginAccount)
|
||||||
|
)
|
||||||
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -0,0 +1,100 @@
|
|||||||
|
package gitbucket.core.controller.api
|
||||||
|
import gitbucket.core.api.{ApiRepositoryWebhook, CreateAWebhook, JsonFormat}
|
||||||
|
import gitbucket.core.controller.ControllerBase
|
||||||
|
import gitbucket.core.model.{WebHook, WebHookContentType}
|
||||||
|
import gitbucket.core.service.WebHookService
|
||||||
|
import gitbucket.core.util.OwnerAuthenticator
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import org.scalatra.{NoContent, NotFound}
|
||||||
|
|
||||||
|
trait ApiRepositoryWebhookcontrollerBase extends ControllerBase {
|
||||||
|
self: WebHookService with OwnerAuthenticator =>
|
||||||
|
|
||||||
|
/**
|
||||||
|
* i. List hooks
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#list-hooks
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/hooks")(ownerOnly { repository =>
|
||||||
|
JsonFormat(getWebHooks(repository.owner, repository.name).map {
|
||||||
|
case (wh, events) =>
|
||||||
|
ApiRepositoryWebhook(wh, events)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ii. Get single hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#get-single-hook
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/hooks/:id")(ownerOnly { repository =>
|
||||||
|
params
|
||||||
|
.get("id")
|
||||||
|
.map { id =>
|
||||||
|
getWebHookById(repository.owner, repository.name, id.toInt)
|
||||||
|
.map {
|
||||||
|
case (hook, events) =>
|
||||||
|
JsonFormat(ApiRepositoryWebhook(hook, events))
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound)
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* iii. Create a hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#create-a-hook
|
||||||
|
*/
|
||||||
|
post("/api/v3/repos/:owner/:repository/hooks")(ownerOnly { repository =>
|
||||||
|
(for {
|
||||||
|
data <- extractFromJsonBody[CreateAWebhook]
|
||||||
|
loginAccount <- context.loginAccount
|
||||||
|
} yield {
|
||||||
|
val url = data.config.url
|
||||||
|
val events = data.events.map(WebHook.Event.valueOf(_)).toSet
|
||||||
|
val ctype = WebHookContentType.valueOf(data.config.content_type)
|
||||||
|
val webHook = addWebHook(repository.owner, repository.name, url, events, ctype, data.config.secret)
|
||||||
|
JsonFormat(ApiRepositoryWebhook(webHook, events))
|
||||||
|
}).getOrElse(NotFound())
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iv. Edit a hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#edit-a-hook
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. Test a push hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#test-a-push-hook
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vi. Ping a hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#ping-a-hook
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vii. Delete a hook
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#delete-a-hook
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
delete("/api/v3/repos/:owner/:repository/hooks/:id")(ownerOnly { repository =>
|
||||||
|
deleteWebHook(repository.owner, repository.name, params("id").toInt)
|
||||||
|
NoContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* viii. Receiving Webhooks
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#receiving-webhooks
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ix. PubSubHubbub
|
||||||
|
* https://developer.github.com/v3/repos/hooks/#pubsubhubbub
|
||||||
|
* not implemented
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiUser, CreateAUser, JsonFormat, UpdateAUser}
|
import gitbucket.core.api._
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.util.{AdminAuthenticator, UsersAuthenticator}
|
import gitbucket.core.util.{AdminAuthenticator, UsersAuthenticator}
|
||||||
@@ -111,4 +111,37 @@ trait ApiUserControllerBase extends ControllerBase {
|
|||||||
NotFound()
|
NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Emails i. List email addresses for a user
|
||||||
|
* https://developer.github.com/v3/users/emails/#list-email-addresses-for-a-user
|
||||||
|
*/
|
||||||
|
get("/api/v3/user/emails")(usersOnly {
|
||||||
|
JsonFormat(
|
||||||
|
ApiEmail.fromMailAddresses(
|
||||||
|
context.loginAccount.get.mailAddress,
|
||||||
|
getAccountExtraMailAddresses(context.loginAccount.get.userName)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ii. List public email addresses for a user
|
||||||
|
* https://developer.github.com/v3/users/emails/#list-public-email-addresses-for-a-user
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iii. Add email address(es)
|
||||||
|
* https://developer.github.com/v3/users/emails/#add-email-addresses
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iv. Delete email address(es)
|
||||||
|
* https://developer.github.com/v3/users/emails/#delete-email-addresses
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. Toggle primary email visibility
|
||||||
|
* https://developer.github.com/v3/users/emails/#toggle-primary-email-visibility
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
val isPrivate = column[Boolean]("PRIVATE")
|
val isPrivate = column[Boolean]("PRIVATE")
|
||||||
val description = column[String]("DESCRIPTION")
|
val description = column[String]("DESCRIPTION")
|
||||||
val defaultBranch = column[String]("DEFAULT_BRANCH")
|
val defaultBranch = column[String]("DEFAULT_BRANCH")
|
||||||
|
val repositoryId = column[Int]("REPOSITORY_ID", O AutoInc)
|
||||||
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
val lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE")
|
val lastActivityDate = column[java.util.Date]("LAST_ACTIVITY_DATE")
|
||||||
@@ -36,6 +37,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate,
|
updatedDate,
|
||||||
lastActivityDate,
|
lastActivityDate,
|
||||||
|
repositoryId,
|
||||||
originUserName.?,
|
originUserName.?,
|
||||||
originRepositoryName.?,
|
originRepositoryName.?,
|
||||||
parentUserName.?,
|
parentUserName.?,
|
||||||
@@ -57,6 +59,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
repository._10,
|
repository._10,
|
||||||
repository._11,
|
repository._11,
|
||||||
repository._12,
|
repository._12,
|
||||||
|
repository._13,
|
||||||
RepositoryOptions.tupled.apply(options)
|
RepositoryOptions.tupled.apply(options)
|
||||||
)
|
)
|
||||||
}, { (r: Repository) =>
|
}, { (r: Repository) =>
|
||||||
@@ -71,6 +74,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
r.registeredDate,
|
r.registeredDate,
|
||||||
r.updatedDate,
|
r.updatedDate,
|
||||||
r.lastActivityDate,
|
r.lastActivityDate,
|
||||||
|
r.repositoryId,
|
||||||
r.originUserName,
|
r.originUserName,
|
||||||
r.originRepositoryName,
|
r.originRepositoryName,
|
||||||
r.parentUserName,
|
r.parentUserName,
|
||||||
@@ -96,6 +100,7 @@ case class Repository(
|
|||||||
registeredDate: java.util.Date,
|
registeredDate: java.util.Date,
|
||||||
updatedDate: java.util.Date,
|
updatedDate: java.util.Date,
|
||||||
lastActivityDate: java.util.Date,
|
lastActivityDate: java.util.Date,
|
||||||
|
repositoryId: Int = 0,
|
||||||
originUserName: Option[String],
|
originUserName: Option[String],
|
||||||
originRepositoryName: Option[String],
|
originRepositoryName: Option[String],
|
||||||
parentUserName: Option[String],
|
parentUserName: Option[String],
|
||||||
|
|||||||
@@ -12,11 +12,15 @@ trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val token = column[Option[String]]("TOKEN")
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE")
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
|
val webHookId = column[Int]("WEB_HOOK_ID", O AutoInc)
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, url, ctype, token) <> ((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
(userName, repositoryName, url, ctype, token, webHookId) <> ((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, url: String) =
|
def byPrimaryKey(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|
||||||
|
def byId(owner: String, repository: String, id: Int) =
|
||||||
|
byRepository(owner, repository) && (this.webHookId === id.bind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -25,5 +29,6 @@ case class RepositoryWebHook(
|
|||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
url: String,
|
url: String,
|
||||||
ctype: WebHookContentType,
|
ctype: WebHookContentType,
|
||||||
token: Option[String]
|
token: Option[String],
|
||||||
|
webHookId: Int = 0
|
||||||
) extends WebHook
|
) extends WebHook
|
||||||
|
|||||||
@@ -728,6 +728,15 @@ trait RepositoryService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def getPermission(owner: String, repository: String, loginAccount: Option[Account])(
|
||||||
|
implicit s: Session
|
||||||
|
): RepositoryPermission =
|
||||||
|
RepositoryPermission(
|
||||||
|
hasOwnerRole(owner, repository, loginAccount),
|
||||||
|
hasDeveloperRole(owner, repository, loginAccount),
|
||||||
|
hasGuestRole(owner, repository, loginAccount)
|
||||||
|
)
|
||||||
|
|
||||||
private def getForkedCount(userName: String, repositoryName: String)(implicit s: Session): Int =
|
private def getForkedCount(userName: String, repositoryName: String)(implicit s: Session): Int =
|
||||||
Query(Repositories.filter { t =>
|
Query(Repositories.filter { t =>
|
||||||
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
|
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
|
||||||
@@ -778,6 +787,8 @@ trait RepositoryService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object RepositoryService {
|
object RepositoryService {
|
||||||
|
case class RepositoryPermission(isOwner: Boolean, isDeveloper: Boolean, isGuest: Boolean)
|
||||||
|
|
||||||
case class RepositoryInfo(
|
case class RepositoryInfo(
|
||||||
owner: String,
|
owner: String,
|
||||||
name: String,
|
name: String,
|
||||||
|
|||||||
@@ -74,6 +74,22 @@ trait WebHookService {
|
|||||||
.list
|
.list
|
||||||
.distinct
|
.distinct
|
||||||
|
|
||||||
|
/** get WebHook by Id */
|
||||||
|
def getWebHookById(owner: String, repository: String, id: Int)(
|
||||||
|
implicit s: Session
|
||||||
|
): Option[(RepositoryWebHook, Set[WebHook.Event])] =
|
||||||
|
RepositoryWebHooks
|
||||||
|
.filter(_.byId(owner, repository, id))
|
||||||
|
.join(RepositoryWebHookEvents)
|
||||||
|
.on { (w, t) =>
|
||||||
|
t.byRepositoryWebHook(w)
|
||||||
|
}
|
||||||
|
.map { case (w, t) => w -> t.event }
|
||||||
|
.list
|
||||||
|
.groupBy(_._1)
|
||||||
|
.mapValues(_.map(_._2).toSet)
|
||||||
|
.headOption
|
||||||
|
|
||||||
/** get All WebHook information from repository to url */
|
/** get All WebHook information from repository to url */
|
||||||
def getWebHook(owner: String, repository: String, url: String)(
|
def getWebHook(owner: String, repository: String, url: String)(
|
||||||
implicit s: Session
|
implicit s: Session
|
||||||
@@ -97,11 +113,14 @@ trait WebHookService {
|
|||||||
events: Set[WebHook.Event],
|
events: Set[WebHook.Event],
|
||||||
ctype: WebHookContentType,
|
ctype: WebHookContentType,
|
||||||
token: Option[String]
|
token: Option[String]
|
||||||
)(implicit s: Session): Unit = {
|
)(implicit s: Session): RepositoryWebHook = {
|
||||||
RepositoryWebHooks insert RepositoryWebHook(owner, repository, url, ctype, token)
|
val hook = RepositoryWebHook(owner, repository, url, ctype, token)
|
||||||
|
RepositoryWebHooks insert hook
|
||||||
events.map { event: WebHook.Event =>
|
events.map { event: WebHook.Event =>
|
||||||
RepositoryWebHookEvents insert RepositoryWebHookEvent(owner, repository, url, event)
|
RepositoryWebHookEvents insert RepositoryWebHookEvent(owner, repository, url, event)
|
||||||
}
|
event
|
||||||
|
}.toSet
|
||||||
|
hook
|
||||||
}
|
}
|
||||||
|
|
||||||
def updateWebHook(
|
def updateWebHook(
|
||||||
@@ -125,6 +144,9 @@ trait WebHookService {
|
|||||||
def deleteWebHook(owner: String, repository: String, url: String)(implicit s: Session): Unit =
|
def deleteWebHook(owner: String, repository: String, url: String)(implicit s: Session): Unit =
|
||||||
RepositoryWebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete
|
RepositoryWebHooks.filter(_.byPrimaryKey(owner, repository, url)).delete
|
||||||
|
|
||||||
|
def deleteWebHook(owner: String, repository: String, id: Int)(implicit s: Session): Unit =
|
||||||
|
RepositoryWebHooks.filter(_.byId(owner, repository, id)).delete
|
||||||
|
|
||||||
/** get All AccountWebHook informations of user */
|
/** get All AccountWebHook informations of user */
|
||||||
def getAccountWebHooks(owner: String)(implicit s: Session): List[(AccountWebHook, Set[WebHook.Event])] =
|
def getAccountWebHooks(owner: String)(implicit s: Session): List[(AccountWebHook, Set[WebHook.Event])] =
|
||||||
AccountWebHooks
|
AccountWebHooks
|
||||||
@@ -322,7 +344,7 @@ trait WebHookPullRequestService extends WebHookService {
|
|||||||
WebHookIssuesPayload(
|
WebHookIssuesPayload(
|
||||||
action = action,
|
action = action,
|
||||||
number = issue.issueId,
|
number = issue.issueId,
|
||||||
repository = ApiRepository(repository, ApiUser(repoOwner)),
|
repository = ApiRepository(repository, repoOwner),
|
||||||
issue = ApiIssue(
|
issue = ApiIssue(
|
||||||
issue,
|
issue,
|
||||||
RepositoryName(repository),
|
RepositoryName(repository),
|
||||||
|
|||||||
@@ -182,7 +182,8 @@ object ApiSpecModels {
|
|||||||
repository = repository,
|
repository = repository,
|
||||||
owner = apiUser,
|
owner = apiUser,
|
||||||
forkedCount = repositoryInfo.forkedCount,
|
forkedCount = repositoryInfo.forkedCount,
|
||||||
watchers = 0
|
watchers = 0,
|
||||||
|
permission = None
|
||||||
)
|
)
|
||||||
|
|
||||||
val apiLabel = ApiLabel(
|
val apiLabel = ApiLabel(
|
||||||
@@ -409,6 +410,8 @@ object ApiSpecModels {
|
|||||||
assets = Seq(apiReleaseAsset)
|
assets = Seq(apiReleaseAsset)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
val apiEmail = ApiEmail("root@localhost", true)
|
||||||
|
|
||||||
// JSON String for APIs
|
// JSON String for APIs
|
||||||
|
|
||||||
val jsonUser = """{
|
val jsonUser = """{
|
||||||
@@ -427,12 +430,15 @@ object ApiSpecModels {
|
|||||||
|"name":"Hello-World",
|
|"name":"Hello-World",
|
||||||
|"full_name":"octocat/Hello-World",
|
|"full_name":"octocat/Hello-World",
|
||||||
|"description":"This your first repo!",
|
|"description":"This your first repo!",
|
||||||
|
|"id":0,
|
||||||
|"watchers":0,
|
|"watchers":0,
|
||||||
|"forks":1,
|
|"forks":1,
|
||||||
|"private":false,
|
|"private":false,
|
||||||
|
|"fork":true,
|
||||||
|"default_branch":"master",
|
|"default_branch":"master",
|
||||||
|"owner":$jsonUser,
|
|"owner":$jsonUser,
|
||||||
|"id":0,
|
|"created_at":"2011-04-14T16:00:49Z",
|
||||||
|
|"updated_at":"2011-04-14T16:00:49Z",
|
||||||
|"forks_count":1,
|
|"forks_count":1,
|
||||||
|"watchers_count":0,
|
|"watchers_count":0,
|
||||||
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World",
|
|"url":"http://gitbucket.exmple.com/api/v3/repos/octocat/Hello-World",
|
||||||
@@ -687,4 +693,12 @@ object ApiSpecModels {
|
|||||||
|"author":${jsonUser},
|
|"author":${jsonUser},
|
||||||
|"assets":[${jsonReleaseAsset}]
|
|"assets":[${jsonReleaseAsset}]
|
||||||
|}""".stripMargin
|
|}""".stripMargin
|
||||||
|
|
||||||
|
val jsonEmail =
|
||||||
|
s"""{
|
||||||
|
|"email":"root@localhost",
|
||||||
|
|"primary":true,
|
||||||
|
|"verified":true,
|
||||||
|
|"visibility":"public"
|
||||||
|
|}""".stripMargin
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -79,4 +79,7 @@ class JsonFormatSpec extends FunSuite {
|
|||||||
test("apiRelease") {
|
test("apiRelease") {
|
||||||
assert(JsonFormat(apiRelease) == expected(jsonRelease))
|
assert(JsonFormat(apiRelease) == expected(jsonRelease))
|
||||||
}
|
}
|
||||||
|
test("apiEmail") {
|
||||||
|
assert(JsonFormat(apiEmail) == expected(jsonEmail))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -52,19 +52,27 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
|||||||
val formType = WebHookContentType.FORM
|
val formType = WebHookContentType.FORM
|
||||||
val jsonType = WebHookContentType.JSON
|
val jsonType = WebHookContentType.JSON
|
||||||
service.addWebHook("user1", "repo1", "http://example.com", Set(WebHook.PullRequest), formType, Some("key"))
|
service.addWebHook("user1", "repo1", "http://example.com", Set(WebHook.PullRequest), formType, Some("key"))
|
||||||
|
val hookId = 1
|
||||||
|
|
||||||
assert(
|
assert(
|
||||||
service.getWebHooks("user1", "repo1") == List(
|
service.getWebHooks("user1", "repo1") == List(
|
||||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")), Set(WebHook.PullRequest))
|
(
|
||||||
|
RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key"), hookId),
|
||||||
|
Set(WebHook.PullRequest)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
||||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")), Set(WebHook.PullRequest))
|
(
|
||||||
|
RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key"), hookId),
|
||||||
|
Set(WebHook.PullRequest)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
||||||
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key")))
|
(RepositoryWebHook("user1", "repo1", "http://example.com", formType, Some("key"), hookId))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == Nil)
|
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == Nil)
|
||||||
@@ -82,7 +90,7 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
|||||||
assert(
|
assert(
|
||||||
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
service.getWebHook("user1", "repo1", "http://example.com") == Some(
|
||||||
(
|
(
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key")),
|
RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key"), hookId),
|
||||||
Set(WebHook.Push, WebHook.Issues)
|
Set(WebHook.Push, WebHook.Issues)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -90,7 +98,7 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
|||||||
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == Nil)
|
assert(service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == Nil)
|
||||||
assert(
|
assert(
|
||||||
service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == List(
|
service.getWebHooksByEvent("user1", "repo1", WebHook.Push) == List(
|
||||||
(RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key")))
|
(RepositoryWebHook("user1", "repo1", "http://example.com", jsonType, Some("key"), hookId))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
service.deleteWebHook("user1", "repo1", "http://example.com")
|
service.deleteWebHook("user1", "repo1", "http://example.com")
|
||||||
@@ -114,9 +122,11 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
|||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
service.getWebHooks("user1", "repo1") == List(
|
service.getWebHooks("user1", "repo1") == List(
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key")) -> Set(WebHook.PullRequest),
|
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key"), 1) -> Set(
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com/2", ctype, Some("key")) -> Set(WebHook.Push),
|
WebHook.PullRequest
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key")) -> Set(
|
),
|
||||||
|
RepositoryWebHook("user1", "repo1", "http://example.com/2", ctype, Some("key"), 2) -> Set(WebHook.Push),
|
||||||
|
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key"), 3) -> Set(
|
||||||
WebHook.PullRequest,
|
WebHook.PullRequest,
|
||||||
WebHook.Push
|
WebHook.Push
|
||||||
)
|
)
|
||||||
@@ -124,8 +134,8 @@ class WebHookServiceSpec extends FunSuite with ServiceSpecBase {
|
|||||||
)
|
)
|
||||||
assert(
|
assert(
|
||||||
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
service.getWebHooksByEvent("user1", "repo1", WebHook.PullRequest) == List(
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key")),
|
RepositoryWebHook("user1", "repo1", "http://example.com/1", ctype, Some("key"), 1),
|
||||||
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key"))
|
RepositoryWebHook("user1", "repo1", "http://example.com/3", ctype, Some("key"), 3)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user