mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-30 10:06:07 +01:00
Compare commits
1 Commits
4.36.2
...
disable-gi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f16f395539 |
@@ -5,10 +5,6 @@ trim_trailing_whitespace = true
|
|||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
end_of_line = lf
|
|
||||||
|
|
||||||
[*.md]
|
|
||||||
trim_trailing_whitespace = false
|
|
||||||
|
|
||||||
[*.java]
|
[*.java]
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|||||||
4
.github/CODEOWNERS
vendored
4
.github/CODEOWNERS
vendored
@@ -1,4 +0,0 @@
|
|||||||
* @takezoe
|
|
||||||
|
|
||||||
build.sbt @xuwei-k
|
|
||||||
project/* @xuwei-k
|
|
||||||
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,6 @@
|
|||||||
# The guidelines for contributing
|
# The guidelines for contributing
|
||||||
|
|
||||||
- At first, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues and pull requests whether there is a same request in the past.
|
- At first, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues and pull requests whether there is a same request in the past.
|
||||||
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles. If you don't wanna waste your time to make a pull request, ask us about your idea at [gitter room](https://gitter.im/gitbucket/gitbucket) before starting your work.
|
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles. If you don't wanna waste your time to make a pull request, ask us about your idea at [gitter room](https://gitter.im/gitbucket/gitbucket) before staring your work.
|
||||||
- You can edit the GitBucket documentation on Wiki if you have a GitHub account. When you find any mistakes or lacks in the documentation, please update it directly.
|
- You can edit the GitBucket documentation on Wiki if you have a GitHub account. When you find any mistakes or lacks in the documentation, please update it directly.
|
||||||
- All your contributions are handled as [Apache Software License, Version 2.0](https://github.com/gitbucket/gitbucket/blob/master/LICENSE). When you create a pull request or update the documentation, we assume you agreed this clause.
|
- All your contributions are handled as [Apache Software License, Version 2.0](https://github.com/gitbucket/gitbucket/blob/master/LICENSE). When you create a pull request or update the documentation, we assume you agreed this clause.
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
@@ -12,7 +12,7 @@
|
|||||||
**Deployment mode**: *explain here how you use GitBucket : standalone app, under webcontainer (which one), with an http frontend (nginx, httpd, ...)*
|
**Deployment mode**: *explain here how you use GitBucket : standalone app, under webcontainer (which one), with an http frontend (nginx, httpd, ...)*
|
||||||
|
|
||||||
**Problem description**:
|
**Problem description**:
|
||||||
- *be as explicit as you can*
|
- *be as explicit has you can*
|
||||||
- *describe the problem and its symptoms*
|
- *describe the problem and its symptoms*
|
||||||
- *explain how to reproduce*
|
- *explain how to reproduce*
|
||||||
- *attach whatever information that can help understanding the context (screen capture, log files)*
|
- *attach whatever information that can help understanding the context (screen capture, log files)*
|
||||||
|
|||||||
6
.github/dependabot.yml
vendored
6
.github/dependabot.yml
vendored
@@ -1,6 +0,0 @@
|
|||||||
version: 2
|
|
||||||
updates:
|
|
||||||
- package-ecosystem: "github-actions"
|
|
||||||
directory: "/"
|
|
||||||
schedule:
|
|
||||||
interval: "weekly"
|
|
||||||
24
.github/workflows/build.yml
vendored
24
.github/workflows/build.yml
vendored
@@ -1,35 +1,25 @@
|
|||||||
name: build
|
name: build
|
||||||
|
|
||||||
on: [push, pull_request]
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ master ]
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
timeout-minutes: 30
|
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java: [8, 11]
|
java: [8, 11]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v2
|
||||||
- name: Cache
|
|
||||||
uses: actions/cache@v2.1.6
|
|
||||||
env:
|
|
||||||
cache-name: cache-sbt-libs
|
|
||||||
with:
|
|
||||||
path: |
|
|
||||||
~/.ivy2/cache
|
|
||||||
~/.sbt
|
|
||||||
~/.cache/coursier/v1
|
|
||||||
key: build-${{ env.cache-name }}-${{ hashFiles('build.sbt') }}
|
|
||||||
- name: Set up JDK
|
- name: Set up JDK
|
||||||
uses: actions/setup-java@v2
|
uses: actions/setup-java@v1
|
||||||
with:
|
with:
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
distribution: adopt
|
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
||||||
- name: Scala 3
|
|
||||||
run: sbt '++ 3.0.1!' update # TODO
|
|
||||||
- name: Build executable
|
- name: Build executable
|
||||||
run: sbt executable
|
run: sbt executable
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
|
|||||||
7
.gitignore
vendored
7
.gitignore
vendored
@@ -10,7 +10,6 @@ lib_managed/
|
|||||||
src_managed/
|
src_managed/
|
||||||
project/boot/
|
project/boot/
|
||||||
project/plugins/project/
|
project/plugins/project/
|
||||||
.bsp/
|
|
||||||
|
|
||||||
# Scala-IDE specific
|
# Scala-IDE specific
|
||||||
.scala_dependencies
|
.scala_dependencies
|
||||||
@@ -29,8 +28,4 @@ project/plugins/project/
|
|||||||
# Metals specific
|
# Metals specific
|
||||||
.metals
|
.metals
|
||||||
.bloop
|
.bloop
|
||||||
**/metals.sbt
|
project/metals.sbt
|
||||||
|
|
||||||
# Visual Studio Code specific
|
|
||||||
.vscode
|
|
||||||
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
updates.limit = 3
|
|
||||||
|
|
||||||
updates.includeScala = true
|
|
||||||
|
|
||||||
updates.pin = [
|
|
||||||
{ groupId = "org.eclipse.jetty", version = "9." }
|
|
||||||
]
|
|
||||||
64
CHANGELOG.md
64
CHANGELOG.md
@@ -1,63 +1,15 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to the project will be documented in this file.
|
All changes to the project will be documented in this file.
|
||||||
|
|
||||||
### 4.36.2 - 16 Aug 2021
|
### 4.33.0 - 31 Dec 2019
|
||||||
- Escape user name in avatar image tag
|
|
||||||
|
|
||||||
### 4.36.1 - 22 Jul 2021
|
|
||||||
- Bump gitbucket-gist-plugin to 4.21.0
|
|
||||||
|
|
||||||
### 4.36.0 - 17 Jul 2021
|
|
||||||
- Tag selector in the repository viewer
|
|
||||||
- Link issues/pull requests of other repositories
|
|
||||||
- Files and lines can be linked in the diff view
|
|
||||||
- Option to disable XSS protection
|
|
||||||
|
|
||||||
### 4.35.3 - 14 Jan 2021
|
|
||||||
- Fix a bug that Wiki page cannot be deleted
|
|
||||||
- Fix a deployment issue on Tomcat
|
|
||||||
|
|
||||||
### 4.35.2 - 30 Dec 2020
|
|
||||||
- Upgrade gitbucket-notifications-plugin to 1.10.0
|
|
||||||
- Upgrade oauth2-oidc-sdk to 8.29.1 to solve dependency issue
|
|
||||||
|
|
||||||
### 4.35.1 - 29 Dec 2020
|
|
||||||
- Fix database migration issue which happens if webhook is configured
|
|
||||||
- Call push webhook when pull request is merged
|
|
||||||
- Show commit status at commits tab of pull request
|
|
||||||
|
|
||||||
### 4.35.0 - 25 Dec 2020
|
|
||||||
- Editor and source viewer color theme
|
|
||||||
- Auto completion for issues and pull requests
|
|
||||||
- Upload image from clipboard
|
|
||||||
- Close multiple issues by commit comment
|
|
||||||
- Create pull request from online editor
|
|
||||||
- Milestone overview
|
|
||||||
- Commit status at various places
|
|
||||||
- WebAPI coverage improvements
|
|
||||||
|
|
||||||
## 4.34.0 - 26 Jul 2020
|
|
||||||
- Enhancement admin settings UI
|
|
||||||
- File upload settings
|
|
||||||
- Restrict repository operations
|
|
||||||
- User-defined CSS
|
|
||||||
- Limit the repository list in the sidebar
|
|
||||||
- Improve MariaDB support
|
|
||||||
- Improve activity logging
|
|
||||||
- CLI option to persist session on disk in the standalone mode
|
|
||||||
- Web API updates
|
|
||||||
- Add [list commits API](https://developer.github.com/v3/repos/commits/#list-commits)
|
|
||||||
- Bundled plugins updates
|
|
||||||
- [gitbucket-gist-plugin](https://github.com/gitbucket/gitbucket-gist-plugin) 4.18.0 -> 4.19.0
|
|
||||||
- [gitbucket-notifications-plugin](https://github.com/gitbucket/gitbucket-notifications-plugin) 1.8.0 -> 1.9.0
|
|
||||||
|
|
||||||
## 4.33.0 - 31 Dec 2019
|
|
||||||
- All CLI options are configurable by environment variables
|
- All CLI options are configurable by environment variables
|
||||||
- Folding pull request files
|
- Folding pull request files
|
||||||
- WebHook security options
|
- WebHook security options
|
||||||
- Add assignee and assignees properties to some Web APIs' response
|
- Add assignee and assignees properties to some Web APIs' response
|
||||||
|
|
||||||
## 4.32.0 - 7 Aug 2019
|
### 4.32.0 - 7 Aug 2019
|
||||||
|
|
||||||
- Bump to Scala 2.13.0 and Scalatra 2.7.0
|
- Bump to Scala 2.13.0 and Scalatra 2.7.0
|
||||||
- Draft pull request
|
- Draft pull request
|
||||||
- Drop network installation of plugins
|
- Drop network installation of plugins
|
||||||
@@ -65,20 +17,20 @@ All changes to the project will be documented in this file.
|
|||||||
- Apply default priority to pull requests
|
- Apply default priority to pull requests
|
||||||
- Focus title after clicking issue / pull request edit button
|
- Focus title after clicking issue / pull request edit button
|
||||||
|
|
||||||
## 4.31.2 - 7 Apr 2019
|
### 4.31.2 - 7 Apr 2019
|
||||||
- Bug and security fix
|
- Bug and security fix
|
||||||
|
|
||||||
## 4.31.1 - 17 Mar 2019
|
### 4.31.1 - 17 Mar 2019
|
||||||
- Bug fix
|
- Bug fix
|
||||||
|
|
||||||
## 4.31.0 - 17 Mar 2019
|
### 4.31.0 - 17 Mar 2019
|
||||||
- Docker support in CI plugin
|
- Docker support in CI plugin
|
||||||
- Verify GPG key signed commit
|
- Verify GPG key signed commit
|
||||||
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
||||||
- OGP (Open Graph protocol) support
|
- OGP (Open Graph protocol) support
|
||||||
- Username completion with avatars
|
- Username completion with avatars
|
||||||
|
|
||||||
## 4.30.1 - 22 Dec 2018
|
### 4.30.1 - 22 Dec 2018
|
||||||
- Bug fix for several WebHooks and Web API
|
- Bug fix for several WebHooks and Web API
|
||||||
|
|
||||||
## 4.30.0 - 15 Dec 2018
|
## 4.30.0 - 15 Dec 2018
|
||||||
@@ -165,7 +117,7 @@ All changes to the project will be documented in this file.
|
|||||||
- Submodule links to web page
|
- Submodule links to web page
|
||||||
- Clarify close/reopen button
|
- Clarify close/reopen button
|
||||||
|
|
||||||
## 4.20.0 - 23 Dec 2017
|
# 4.20.0 - 23 Dec 2017
|
||||||
- Squash and rebase merge strategy for pull requests
|
- Squash and rebase merge strategy for pull requests
|
||||||
- Quick pull request creation
|
- Quick pull request creation
|
||||||
- Download patch from the diff view
|
- Download patch from the diff view
|
||||||
|
|||||||
29
README.md
29
README.md
@@ -8,8 +8,6 @@ GitBucket is a Git web platform powered by Scala offering:
|
|||||||
- High extensibility by plugins
|
- High extensibility by plugins
|
||||||
- API compatibility with GitHub
|
- API compatibility with GitHub
|
||||||
|
|
||||||

|
|
||||||
|
|
||||||
You can try an [online demo](https://gitbucket.herokuapp.com/) *(ID: root / Pass: root)* of GitBucket, and also get the latest information at [GitBucket News](https://gitbucket.github.io/gitbucket-news/).
|
You can try an [online demo](https://gitbucket.herokuapp.com/) *(ID: root / Pass: root)* of GitBucket, and also get the latest information at [GitBucket News](https://gitbucket.github.io/gitbucket-news/).
|
||||||
|
|
||||||
Features
|
Features
|
||||||
@@ -24,6 +22,8 @@ The current version of GitBucket provides many features such as:
|
|||||||
- Account and group management with LDAP integration
|
- Account and group management with LDAP integration
|
||||||
- a Plug-in system
|
- a Plug-in system
|
||||||
|
|
||||||
|
If you want to try the development version of GitBucket, see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/readme.md).
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
--------
|
--------
|
||||||
GitBucket requires **Java8**. You have to install it, if it is not already installed.
|
GitBucket requires **Java8**. You have to install it, if it is not already installed.
|
||||||
@@ -48,31 +48,20 @@ GitBucket has a plug-in system that allows extra functionality. Officially the f
|
|||||||
|
|
||||||
You can find more plugins made by the community at [GitBucket community plugins](https://gitbucket-plugins.github.io/).
|
You can find more plugins made by the community at [GitBucket community plugins](https://gitbucket-plugins.github.io/).
|
||||||
|
|
||||||
Building and Development
|
|
||||||
-----------
|
|
||||||
If you want to try the development version of GitBucket, or want to contribute to the project, please see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/readme.md).
|
|
||||||
It provides instructions on building from source and on setting up an IDE for debugging.
|
|
||||||
It also contains documentation of the core concepts used within the project.
|
|
||||||
|
|
||||||
Support
|
Support
|
||||||
--------
|
--------
|
||||||
|
|
||||||
- If you have any questions about GitBucket, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues whether there is a same question or request in the past.
|
- If you have any questions about GitBucket, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues whether there is a same question or request in the past.
|
||||||
- If you can't find same question and report, send it to our [Gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
- If you can't find same question and report, send it to [gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
||||||
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
||||||
|
|
||||||
What's New in 4.36.x
|
What's New in 4.33.x
|
||||||
-------------
|
-------------
|
||||||
### 4.36.2 - 16 Aug 2021
|
### 4.33.0 - 31 Dec 2019
|
||||||
- Escape user name in avatar image tag
|
|
||||||
|
|
||||||
### 4.36.1 - 22 Jul 2021
|
- All CLI options are configurable by environment variables
|
||||||
- Bump gitbucket-gist-plugin to 4.21.0
|
- Folding pull request files
|
||||||
|
- WebHook security options
|
||||||
### 4.36.0 - 17 Jul 2021
|
- Add assignee and assignees properties to some Web APIs' response
|
||||||
- Tag selector in the repository viewer
|
|
||||||
- Link issues/pull requests of other repositories
|
|
||||||
- Files and lines can be linked in the diff view
|
|
||||||
- Option to disable XSS protection
|
|
||||||
|
|
||||||
See the [change log](CHANGELOG.md) for all of the updates.
|
See the [change log](CHANGELOG.md) for all of the updates.
|
||||||
|
|||||||
125
build.sbt
125
build.sbt
@@ -1,21 +1,23 @@
|
|||||||
import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
|
import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
|
||||||
import com.jsuereth.sbtpgp.PgpKeys._
|
import com.typesafe.sbt.pgp.PgpKeys._
|
||||||
|
|
||||||
val Organization = "io.github.gitbucket"
|
val Organization = "io.github.gitbucket"
|
||||||
val Name = "gitbucket"
|
val Name = "gitbucket"
|
||||||
val GitBucketVersion = "4.36.2"
|
val GitBucketVersion = "4.33.0"
|
||||||
val ScalatraVersion = "2.8.0"
|
val ScalatraVersion = "2.7.0-RC1"
|
||||||
val JettyVersion = "9.4.43.v20210629"
|
val JettyVersion = "9.4.30.v20200611"
|
||||||
val JgitVersion = "5.12.0.202106070339-r"
|
val JgitVersion = "5.8.0.202006091008-r"
|
||||||
|
|
||||||
lazy val root = (project in file("."))
|
lazy val root = (project in file("."))
|
||||||
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
||||||
|
.settings(
|
||||||
|
)
|
||||||
|
|
||||||
sourcesInBase := false
|
sourcesInBase := false
|
||||||
organization := Organization
|
organization := Organization
|
||||||
name := Name
|
name := Name
|
||||||
version := GitBucketVersion
|
version := GitBucketVersion
|
||||||
scalaVersion := "2.13.6"
|
scalaVersion := "2.13.1"
|
||||||
|
|
||||||
scalafmtOnCompile := true
|
scalafmtOnCompile := true
|
||||||
|
|
||||||
@@ -28,85 +30,68 @@ resolvers ++= Seq(
|
|||||||
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
)
|
)
|
||||||
|
|
||||||
libraryDependencySchemes += "org.scala-lang.modules" %% "scala-xml" % "always"
|
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
||||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
||||||
"org.scalatra" %% "scalatra" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
||||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
||||||
"org.scalatra" %% "scalatra-forms" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
"org.scalatra" %% "scalatra-forms" % ScalatraVersion,
|
||||||
"org.json4s" %% "json4s-jackson" % "4.0.3" cross CrossVersion.for3Use2_13,
|
"org.json4s" %% "json4s-jackson" % "3.6.9",
|
||||||
"commons-io" % "commons-io" % "2.11.0",
|
"commons-io" % "commons-io" % "2.7",
|
||||||
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
||||||
"io.github.gitbucket" % "markedj" % "1.0.16",
|
"io.github.gitbucket" % "markedj" % "1.0.16",
|
||||||
"org.apache.commons" % "commons-compress" % "1.21",
|
"org.apache.commons" % "commons-compress" % "1.20",
|
||||||
"org.apache.commons" % "commons-email" % "1.5",
|
"org.apache.commons" % "commons-email" % "1.5",
|
||||||
"commons-net" % "commons-net" % "3.8.0",
|
"commons-net" % "commons-net" % "3.6",
|
||||||
"org.apache.httpcomponents" % "httpclient" % "4.5.13",
|
"org.apache.httpcomponents" % "httpclient" % "4.5.12",
|
||||||
"org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
"org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
||||||
"org.apache.tika" % "tika-core" % "2.0.0",
|
"org.apache.tika" % "tika-core" % "1.24.1",
|
||||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12" cross CrossVersion.for3Use2_13,
|
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12",
|
||||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
"com.h2database" % "h2" % "1.4.199",
|
"com.h2database" % "h2" % "1.4.199",
|
||||||
"org.mariadb.jdbc" % "mariadb-java-client" % "2.7.4",
|
"org.mariadb.jdbc" % "mariadb-java-client" % "2.6.0",
|
||||||
"org.postgresql" % "postgresql" % "42.2.23",
|
"org.postgresql" % "postgresql" % "42.2.6",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.2.5",
|
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
||||||
"com.zaxxer" % "HikariCP" % "4.0.3" exclude ("org.slf4j", "slf4j-api"),
|
"com.zaxxer" % "HikariCP" % "3.4.5",
|
||||||
"com.typesafe" % "config" % "1.4.1",
|
"com.typesafe" % "config" % "1.4.0",
|
||||||
|
"com.typesafe.akka" %% "akka-actor" % "2.5.27",
|
||||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
||||||
"io.github.java-diff-utils" % "java-diff-utils" % "4.10",
|
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
||||||
"org.cache2k" % "cache2k-all" % "1.6.0.Final",
|
"org.cache2k" % "cache2k-all" % "1.2.4.Final",
|
||||||
"net.coobird" % "thumbnailator" % "0.4.14",
|
"com.enragedginger" %% "akka-quartz-scheduler" % "1.8.1-akka-2.5.x" exclude ("com.mchange", "c3p0") exclude ("com.zaxxer", "HikariCP-java6"),
|
||||||
|
"net.coobird" % "thumbnailator" % "0.4.11",
|
||||||
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
||||||
"com.nimbusds" % "oauth2-oidc-sdk" % "9.12",
|
"com.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
|
||||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
||||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||||
"junit" % "junit" % "4.13.2" % "test",
|
"junit" % "junit" % "4.13" % "test",
|
||||||
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test" cross CrossVersion.for3Use2_13,
|
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
||||||
"org.mockito" % "mockito-core" % "3.11.2" % "test",
|
"org.mockito" % "mockito-core" % "3.3.3" % "test",
|
||||||
"com.dimafeng" %% "testcontainers-scala" % "0.39.5" % "test",
|
"com.dimafeng" %% "testcontainers-scala" % "0.37.0" % "test",
|
||||||
"org.testcontainers" % "mysql" % "1.16.0" % "test",
|
"org.testcontainers" % "mysql" % "1.14.3" % "test",
|
||||||
"org.testcontainers" % "postgresql" % "1.16.0" % "test",
|
"org.testcontainers" % "postgresql" % "1.14.3" % "test",
|
||||||
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
||||||
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
||||||
"org.ec4j.core" % "ec4j-core" % "0.3.0",
|
"org.ec4j.core" % "ec4j-core" % "0.0.3"
|
||||||
"org.kohsuke" % "github-api" % "1.132" % "test"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
libraryDependencies ~= {
|
|
||||||
_.map {
|
|
||||||
case x if x.name == "twirl-api" =>
|
|
||||||
x cross CrossVersion.for3Use2_13
|
|
||||||
case x =>
|
|
||||||
x
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Compiler settings
|
// Compiler settings
|
||||||
scalacOptions := Seq(
|
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
|
||||||
"-deprecation",
|
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
||||||
"-language:postfixOps",
|
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||||
"-opt:l:method",
|
|
||||||
"-feature",
|
|
||||||
"-Wunused:imports",
|
|
||||||
"-Wconf:cat=unused&src=twirl/.*:s,cat=unused&src=scala/gitbucket/core/model/[^/]+\\.scala:s"
|
|
||||||
)
|
|
||||||
compile / javacOptions ++= Seq("-target", "8", "-source", "8")
|
|
||||||
Jetty / javaOptions += "-Dlogback.configurationFile=/logback-dev.xml"
|
|
||||||
|
|
||||||
// Test settings
|
// Test settings
|
||||||
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
||||||
Test / javaOptions += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
||||||
Test / testOptions += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
||||||
Test / fork := true
|
fork in Test := true
|
||||||
|
|
||||||
// Packaging options
|
// Packaging options
|
||||||
packageOptions += Package.MainClass("JettyLauncher")
|
packageOptions += Package.MainClass("JettyLauncher")
|
||||||
|
|
||||||
// Assembly settings
|
// Assembly settings
|
||||||
assembly / test := {}
|
test in assembly := {}
|
||||||
assembly / assemblyMergeStrategy := {
|
assemblyMergeStrategy in assembly := {
|
||||||
case PathList("META-INF", xs @ _*) =>
|
case PathList("META-INF", xs @ _*) =>
|
||||||
(xs map { _.toLowerCase }) match {
|
(xs map { _.toLowerCase }) match {
|
||||||
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
||||||
@@ -137,12 +122,6 @@ libraryDependencies ++= Seq(
|
|||||||
"org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
|
"org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Run package task before test to generate target/webapp for integration test
|
|
||||||
Test / test := {
|
|
||||||
_root_.sbt.Keys.`package`.value
|
|
||||||
(Test / test).value
|
|
||||||
}
|
|
||||||
|
|
||||||
val executableKey = TaskKey[File]("executable")
|
val executableKey = TaskKey[File]("executable")
|
||||||
executableKey := {
|
executableKey := {
|
||||||
import java.util.jar.Attributes.{Name => AttrName}
|
import java.util.jar.Attributes.{Name => AttrName}
|
||||||
@@ -171,7 +150,7 @@ executableKey := {
|
|||||||
IO unzip (warFile, temp)
|
IO unzip (warFile, temp)
|
||||||
|
|
||||||
// include launcher classes
|
// include launcher classes
|
||||||
val classDir = (Compile / Keys.classDirectory).value
|
val classDir = (Keys.classDirectory in Compile).value
|
||||||
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
||||||
launchClasses foreach { name =>
|
launchClasses foreach { name =>
|
||||||
IO copyFile (classDir / name, temp / name)
|
IO copyFile (classDir / name, temp / name)
|
||||||
@@ -202,7 +181,7 @@ executableKey := {
|
|||||||
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
||||||
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
||||||
val outputFile = workDir / warName
|
val outputFile = workDir / warName
|
||||||
IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest, None)
|
IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
|
||||||
|
|
||||||
// generate checksums
|
// generate checksums
|
||||||
Seq(
|
Seq(
|
||||||
@@ -274,7 +253,12 @@ pomExtra := (
|
|||||||
</developers>
|
</developers>
|
||||||
)
|
)
|
||||||
|
|
||||||
Test / testOptions ++= {
|
licenseOverrides := {
|
||||||
|
case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
|
||||||
|
LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
|
||||||
|
}
|
||||||
|
|
||||||
|
testOptions in Test ++= {
|
||||||
if (scala.util.Properties.isWin) {
|
if (scala.util.Properties.isWin) {
|
||||||
Seq(
|
Seq(
|
||||||
Tests.Exclude(
|
Tests.Exclude(
|
||||||
@@ -287,8 +271,3 @@ Test / testOptions ++= {
|
|||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Jetty / javaOptions ++= Seq(
|
|
||||||
"-Xdebug",
|
|
||||||
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Authentication in Controller
|
|||||||
========
|
========
|
||||||
GitBucket provides many [authenticators](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/util/Authenticator.scala) to access controlling in the controller.
|
GitBucket provides many [authenticators](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/util/Authenticator.scala) to access controlling in the controller.
|
||||||
|
|
||||||
For example, in the case of `RepositoryViewerController`,
|
For example, in the case of `RepositoryViwerController`,
|
||||||
it references three authenticators: `ReadableUsersAuthenticator`, `ReferrerAuthenticator` and `CollaboratorsAuthenticator`.
|
it references three authenticators: `ReadableUsersAuthenticator`, `ReferrerAuthenticator` and `CollaboratorsAuthenticator`.
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
@@ -19,13 +19,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
Authenticators provide a method to add guard to actions in the controller:
|
Authenticators provides a method to add guard to actions in the controller:
|
||||||
|
|
||||||
- `ReadableUsersAuthenticator` provides `readableUsersOnly` method
|
- `ReadableUsersAuthenticator` provides `readableUsersOnly` method
|
||||||
- `ReferrerAuthenticator` provides `referrersOnly` method
|
- `ReferrerAuthenticator` provides `referrersOnly` method
|
||||||
- `CollaboratorsAuthenticator` provides `collaboratorsOnly` method
|
- `CollaboratorsAuthenticator` provides `collaboratorsOnly` method
|
||||||
|
|
||||||
These methods are available in each action as below:
|
These methods are available in each actions as below:
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
// Allows only the repository owner (or manager for group repository) and administrators.
|
// Allows only the repository owner (or manager for group repository) and administrators.
|
||||||
@@ -38,7 +38,7 @@ get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
|||||||
...
|
...
|
||||||
})
|
})
|
||||||
|
|
||||||
// Allows only signed-in users which can access the repository.
|
// Allows only signed in users which can access the repository.
|
||||||
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
@@ -50,11 +50,11 @@ Currently, GitBucket provides below authenticators:
|
|||||||
|--------------------------|-----------------|--------------------------------------------------------------------------------------|
|
|--------------------------|-----------------|--------------------------------------------------------------------------------------|
|
||||||
|OneselfAuthenticator |oneselfOnly |Allows only oneself and administrators. |
|
|OneselfAuthenticator |oneselfOnly |Allows only oneself and administrators. |
|
||||||
|OwnerAuthenticator |ownerOnly |Allows only the repository owner and administrators. |
|
|OwnerAuthenticator |ownerOnly |Allows only the repository owner and administrators. |
|
||||||
|UsersAuthenticator |usersOnly |Allows only signed-in users. |
|
|UsersAuthenticator |usersOnly |Allows only signed in users. |
|
||||||
|AdminAuthenticator |adminOnly |Allows only administrators. |
|
|AdminAuthenticator |adminOnly |Allows only administrators. |
|
||||||
|CollaboratorsAuthenticator|collaboratorsOnly|Allows only collaborators and administrators. |
|
|CollaboratorsAuthenticator|collaboratorsOnly|Allows only collaborators and administrators. |
|
||||||
|ReferrerAuthenticator |referrersOnly |Allows only the repository owner (or manager for group repository) and administrators.|
|
|ReferrerAuthenticator |referrersOnly |Allows only the repository owner (or manager for group repository) and administrators.|
|
||||||
|ReadableUsersAuthenticator|readableUsersOnly|Allows only signed-in users which can access the repository. |
|
|ReadableUsersAuthenticator|readableUsersOnly|Allows only signed in users which can access the repository. |
|
||||||
|GroupManagerAuthenticator |managersOnly |Allows only the group managers. |
|
|GroupManagerAuthenticator |managersOnly |Allows only the group managers. |
|
||||||
|
|
||||||
Of course, if you make a new plugin, you can implement your own authenticator according to requirement in your plugin.
|
Of course, if you make a new plugin, you can define a your own authenticator according to requirement in your plugin.
|
||||||
@@ -2,7 +2,7 @@ Automatic Schema Updating
|
|||||||
========
|
========
|
||||||
GitBucket updates database schema automatically using [Solidbase](https://github.com/gitbucket/solidbase) in the first run after the upgrading.
|
GitBucket updates database schema automatically using [Solidbase](https://github.com/gitbucket/solidbase) in the first run after the upgrading.
|
||||||
|
|
||||||
To release a new version of GitBucket, add the version definition to [gitbucket.core.GitBucketCoreModule](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/GitBucketCoreModule.scala) at first.
|
To release a new version of GitBucket, add the version definition to the [gitbucket.core.GitBucketCoreModule](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/GitBucketCoreModule.scala) at first.
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
object GitBucketCoreModule extends Module("gitbucket-core",
|
object GitBucketCoreModule extends Module("gitbucket-core",
|
||||||
@@ -17,7 +17,7 @@ object GitBucketCoreModule extends Module("gitbucket-core",
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, add a XML file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) with a filename defined in `GitBucketCoreModule`.
|
Next, add a XML file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) with a filenane defined in `GitBucketCoreModule`.
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -31,9 +31,9 @@ Next, add a XML file which updates database schema into [/src/main/resources/upd
|
|||||||
</changeSet>
|
</changeSet>
|
||||||
```
|
```
|
||||||
|
|
||||||
Solidbase stores the current version to `VERSIONS` table and checks it at start-up. If the stored version different from the actual version, it executes differences between the stored version and the actual version.
|
Solidbase stores the current version to `VERSIONS` table and checks it at start-up. If the stored version differs from the actual version, it executes differences between the stored version and the actual version.
|
||||||
|
|
||||||
We can add the SQL file instead of the XML file using `SqlMigration`. It tries to load a SQL file from classpath in the following order:
|
We can add the SQL file instead of the XML file using `SqlMigration`. It try to load a SQL file from classpath as following order:
|
||||||
|
|
||||||
1. Specified path (if specified)
|
1. Specified path (if specified)
|
||||||
2. `${moduleId}_${version}_${database}.sql`
|
2. `${moduleId}_${version}_${database}.sql`
|
||||||
@@ -51,4 +51,4 @@ object GitBucketCoreModule extends Module("gitbucket-core",
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
See more details at [README of Solidbase](https://github.com/gitbucket/solidbase).
|
See more details [README of Solidbase](https://github.com/gitbucket/solidbase).
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ $ sbt ~jetty:start
|
|||||||
|
|
||||||
Then access `http://localhost:8080/` in your browser. The default administrator account is `root` and password is `root`.
|
Then access `http://localhost:8080/` in your browser. The default administrator account is `root` and password is `root`.
|
||||||
|
|
||||||
Source code modifications are detected and a reloading happens automatically. You can modify the logging configuration by editing `src/main/resources/logback-dev.xml`.
|
Source code modifications are detected and a reloaded happens automatically. You can modify the logging configuration by editing `src/main/resources/logback-dev.xml`.
|
||||||
|
|
||||||
Build war file
|
Build war file
|
||||||
--------
|
--------
|
||||||
|
|
||||||
To build a war file, run the following command:
|
To build war file, run the following command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ sbt package
|
$ sbt package
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
sbt.version=1.5.5
|
sbt.version=1.3.12
|
||||||
|
|||||||
@@ -1,11 +1,10 @@
|
|||||||
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
||||||
|
|
||||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.3")
|
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.0")
|
||||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "1.0.0")
|
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
||||||
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
||||||
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
|
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
||||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.8.2")
|
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
||||||
|
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
|
||||||
addDependencyTreePlugin
|
|
||||||
|
|||||||
@@ -19,14 +19,19 @@ public class JettyLauncher {
|
|||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
|
||||||
String host = getEnvironmentVariable("gitbucket.host");
|
String host = null;
|
||||||
String port = getEnvironmentVariable("gitbucket.port");
|
String port = null;
|
||||||
InetSocketAddress address;
|
InetSocketAddress address = null;
|
||||||
String contextPath = getEnvironmentVariable("gitbucket.prefix");
|
String contextPath = "/";
|
||||||
String tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
String tmpDirPath="";
|
||||||
boolean forceHttps = false;
|
boolean forceHttps = false;
|
||||||
boolean saveSessions = false;
|
boolean saveSessions = false;
|
||||||
|
|
||||||
|
host = getEnvironmentVariable("gitbucket.host");
|
||||||
|
port = getEnvironmentVariable("gitbucket.port");
|
||||||
|
contextPath = getEnvironmentVariable("gitbucket.prefix");
|
||||||
|
tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
||||||
|
|
||||||
for(String arg: args) {
|
for(String arg: args) {
|
||||||
if(arg.equals("--save_sessions")) {
|
if(arg.equals("--save_sessions")) {
|
||||||
saveSessions = true;
|
saveSessions = true;
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ public class PatchUtil {
|
|||||||
public static String apply(String source, String patch, FileHeader fh)
|
public static String apply(String source, String patch, FileHeader fh)
|
||||||
throws IOException, PatchApplyException {
|
throws IOException, PatchApplyException {
|
||||||
RawText rt = new RawText(source.getBytes("UTF-8"));
|
RawText rt = new RawText(source.getBytes("UTF-8"));
|
||||||
List<String> oldLines = new ArrayList<>(rt.size());
|
List<String> oldLines = new ArrayList<String>(rt.size());
|
||||||
for (int i = 0; i < rt.size(); i++)
|
for (int i = 0; i < rt.size(); i++)
|
||||||
oldLines.add(rt.getString(i));
|
oldLines.add(rt.getString(i));
|
||||||
List<String> newLines = new ArrayList<>(oldLines);
|
List<String> newLines = new ArrayList<String>(oldLines);
|
||||||
for (HunkHeader hh : fh.getHunks()) {
|
for (HunkHeader hh : fh.getHunks()) {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
out.write(patch.getBytes("UTF-8"), hh.getStartOffset(), hh.getEndOffset() - hh.getStartOffset());
|
out.write(patch.getBytes("UTF-8"), hh.getStartOffset(), hh.getEndOffset() - hh.getStartOffset());
|
||||||
RawText hrt = new RawText(out.toByteArray());
|
RawText hrt = new RawText(out.toByteArray());
|
||||||
List<String> hunkLines = new ArrayList<>(hrt.size());
|
List<String> hunkLines = new ArrayList<String>(hrt.size());
|
||||||
for (int i = 0; i < hrt.size(); i++)
|
for (int i = 0; i < hrt.size(); i++)
|
||||||
hunkLines.add(hrt.getString(i));
|
hunkLines.add(hrt.getString(i));
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
notifications:1.10.0
|
notifications:1.8.0
|
||||||
gist:4.21.0
|
gist:4.18.0
|
||||||
emoji:4.6.0
|
emoji:4.6.0
|
||||||
pages:1.9.0
|
pages:1.8.0
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<changeSet>
|
|
||||||
<dropTable tableName="ACTIVITY" />
|
|
||||||
</changeSet>
|
|
||||||
@@ -1,39 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<changeSet>
|
|
||||||
<!--================================================================================================-->
|
|
||||||
<!-- WEB_HOOK -->
|
|
||||||
<!--================================================================================================-->
|
|
||||||
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
|
||||||
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK"/>
|
|
||||||
<dropPrimaryKey constraintName="IDX_WEB_HOOK_PK" tableName="WEB_HOOK"/>
|
|
||||||
|
|
||||||
<createTable tableName="WEB_HOOK_2">
|
|
||||||
<column name="HOOK_ID" type="int" nullable="true" autoIncrement="true" unique="false" primaryKeyName="IDX_WEB_HOOK_PK" primaryKey="true" />
|
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
|
||||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
|
||||||
<column name="URL" type="varchar(200)" nullable="false"/>
|
|
||||||
<column name="TOKEN" type="varchar(100)" nullable="true"/>
|
|
||||||
<column name="CTYPE" type="varchar(10)" nullable="true"/>
|
|
||||||
</createTable>
|
|
||||||
|
|
||||||
<sql>
|
|
||||||
INSERT INTO WEB_HOOK_2 (USER_NAME, REPOSITORY_NAME, URL, TOKEN, CTYPE) SELECT USER_NAME, REPOSITORY_NAME, URL, TOKEN, CTYPE FROM WEB_HOOK
|
|
||||||
</sql>
|
|
||||||
|
|
||||||
<renameTable newTableName="WEB_HOOK_BK" oldTableName="WEB_HOOK"/>
|
|
||||||
<renameTable newTableName="WEB_HOOK" oldTableName="WEB_HOOK_2"/>
|
|
||||||
|
|
||||||
<addUniqueConstraint constraintName="IDX_WEB_HOOK_1" tableName="WEB_HOOK" columnNames="USER_NAME, REPOSITORY_NAME, URL"/>
|
|
||||||
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
|
||||||
<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"/>
|
|
||||||
|
|
||||||
<!--================================================================================================-->
|
|
||||||
<!-- ACCOUNT_PREFERENCE -->
|
|
||||||
<!--================================================================================================-->
|
|
||||||
<createTable tableName="ACCOUNT_PREFERENCE">
|
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
|
||||||
<column name="HIGHLIGHTER_THEME" type="varchar(100)" nullable="false" defaultValue="prettify"/>
|
|
||||||
</createTable>
|
|
||||||
<addPrimaryKey constraintName="IDX_ACCOUNT_PREFERENCE_PK" tableName="ACCOUNT_PREFERENCE" columnNames="USER_NAME"/>
|
|
||||||
<addForeignKeyConstraint constraintName="IDX_ACCOUNT_PREFERENCE_FK0" baseTableName="ACCOUNT_PREFERENCE" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
|
||||||
</changeSet>
|
|
||||||
@@ -1,6 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<changeSet>
|
|
||||||
<addColumn tableName="REPOSITORY">
|
|
||||||
<column name="SAFE_MODE" type="boolean" nullable="false" defaultValue="true"/>
|
|
||||||
</addColumn>
|
|
||||||
</changeSet>
|
|
||||||
@@ -2,6 +2,7 @@ import java.util.EnumSet
|
|||||||
import javax.servlet._
|
import javax.servlet._
|
||||||
|
|
||||||
import gitbucket.core.controller.{ReleaseController, _}
|
import gitbucket.core.controller.{ReleaseController, _}
|
||||||
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
import gitbucket.core.service.SystemSettingsService
|
import gitbucket.core.service.SystemSettingsService
|
||||||
import gitbucket.core.servlet._
|
import gitbucket.core.servlet._
|
||||||
import gitbucket.core.util.Directory
|
import gitbucket.core.util.Directory
|
||||||
|
|||||||
@@ -1,21 +1,7 @@
|
|||||||
package gitbucket.core
|
package gitbucket.core
|
||||||
|
|
||||||
import java.io.FileOutputStream
|
import io.github.gitbucket.solidbase.migration.{SqlMigration, LiquibaseMigration}
|
||||||
import java.nio.charset.StandardCharsets
|
import io.github.gitbucket.solidbase.model.{Version, Module}
|
||||||
import java.sql.Connection
|
|
||||||
import java.util.UUID
|
|
||||||
|
|
||||||
import gitbucket.core.model.Activity
|
|
||||||
import gitbucket.core.util.Directory.ActivityLog
|
|
||||||
import gitbucket.core.util.JDBCUtil
|
|
||||||
import io.github.gitbucket.solidbase.Solidbase
|
|
||||||
import io.github.gitbucket.solidbase.migration.{LiquibaseMigration, Migration, SqlMigration}
|
|
||||||
import io.github.gitbucket.solidbase.model.{Module, Version}
|
|
||||||
import org.json4s.{Formats, NoTypeHints}
|
|
||||||
import org.json4s.jackson.Serialization
|
|
||||||
import org.json4s.jackson.Serialization.write
|
|
||||||
|
|
||||||
import scala.util.Using
|
|
||||||
|
|
||||||
object GitBucketCoreModule
|
object GitBucketCoreModule
|
||||||
extends Module(
|
extends Module(
|
||||||
@@ -79,45 +65,5 @@ object GitBucketCoreModule
|
|||||||
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")),
|
new Version("4.32.0", new LiquibaseMigration("update/gitbucket-core_4.32.xml")),
|
||||||
new Version("4.33.0"),
|
new Version("4.33.0")
|
||||||
new Version(
|
|
||||||
"4.34.0",
|
|
||||||
new Migration() {
|
|
||||||
override def migrate(moduleId: String, version: String, context: java.util.Map[String, AnyRef]): Unit = {
|
|
||||||
implicit val formats: Formats = Serialization.formats(NoTypeHints)
|
|
||||||
import JDBCUtil._
|
|
||||||
|
|
||||||
val conn = context.get(Solidbase.CONNECTION).asInstanceOf[Connection]
|
|
||||||
val list = conn.select("SELECT * FROM ACTIVITY ORDER BY ACTIVITY_ID") {
|
|
||||||
rs =>
|
|
||||||
Activity(
|
|
||||||
activityId = UUID.randomUUID().toString,
|
|
||||||
userName = rs.getString("USER_NAME"),
|
|
||||||
repositoryName = rs.getString("REPOSITORY_NAME"),
|
|
||||||
activityUserName = rs.getString("ACTIVITY_USER_NAME"),
|
|
||||||
activityType = rs.getString("ACTIVITY_TYPE"),
|
|
||||||
message = rs.getString("MESSAGE"),
|
|
||||||
additionalInfo = {
|
|
||||||
val additionalInfo = rs.getString("ADDITIONAL_INFO")
|
|
||||||
if (rs.wasNull()) None else Some(additionalInfo)
|
|
||||||
},
|
|
||||||
activityDate = rs.getTimestamp("ACTIVITY_DATE")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
Using.resource(new FileOutputStream(ActivityLog, true)) { out =>
|
|
||||||
list.foreach { activity =>
|
|
||||||
out.write((write(activity) + "\n").getBytes(StandardCharsets.UTF_8))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
|
||||||
new LiquibaseMigration("update/gitbucket-core_4.34.xml")
|
|
||||||
),
|
|
||||||
new Version("4.35.0", new LiquibaseMigration("update/gitbucket-core_4.35.xml")),
|
|
||||||
new Version("4.35.1"),
|
|
||||||
new Version("4.35.2"),
|
|
||||||
new Version("4.35.3"),
|
|
||||||
new Version("4.36.0", new LiquibaseMigration("update/gitbucket-core_4.36.xml")),
|
|
||||||
new Version("4.36.1"),
|
|
||||||
new Version("4.36.2")
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,12 +22,3 @@ case class ApiBranchForList(
|
|||||||
name: String,
|
name: String,
|
||||||
commit: ApiBranchCommit
|
commit: ApiBranchCommit
|
||||||
)
|
)
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-branches-for-head-commit
|
|
||||||
*/
|
|
||||||
case class ApiBranchForHeadCommit(
|
|
||||||
name: String,
|
|
||||||
commit: ApiBranchCommit,
|
|
||||||
`protected`: Boolean
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -4,11 +4,7 @@ import gitbucket.core.service.ProtectedBranchService
|
|||||||
import org.json4s._
|
import org.json4s._
|
||||||
|
|
||||||
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
||||||
case class ApiBranchProtection(
|
case class ApiBranchProtection(enabled: Boolean, required_status_checks: Option[ApiBranchProtection.Status]) {
|
||||||
url: Option[ApiPath], // for output
|
|
||||||
enabled: Boolean,
|
|
||||||
required_status_checks: Option[ApiBranchProtection.Status]
|
|
||||||
) {
|
|
||||||
def status: ApiBranchProtection.Status = required_status_checks.getOrElse(ApiBranchProtection.statusNone)
|
def status: ApiBranchProtection.Status = required_status_checks.getOrElse(ApiBranchProtection.statusNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,36 +15,13 @@ object ApiBranchProtection {
|
|||||||
|
|
||||||
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtection =
|
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtection =
|
||||||
ApiBranchProtection(
|
ApiBranchProtection(
|
||||||
url = Some(
|
|
||||||
ApiPath(
|
|
||||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection"
|
|
||||||
)
|
|
||||||
),
|
|
||||||
enabled = info.enabled,
|
enabled = info.enabled,
|
||||||
required_status_checks = Some(
|
required_status_checks = Some(
|
||||||
Status(
|
Status(EnforcementLevel(info.enabled && info.contexts.nonEmpty, info.includeAdministrators), info.contexts)
|
||||||
Some(
|
|
||||||
ApiPath(
|
|
||||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection/required_status_checks"
|
|
||||||
)
|
|
||||||
),
|
|
||||||
EnforcementLevel(info.enabled && info.contexts.nonEmpty, info.includeAdministrators),
|
|
||||||
info.contexts,
|
|
||||||
Some(
|
|
||||||
ApiPath(
|
|
||||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection/required_status_checks/contexts"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val statusNone = Status(None, Off, Seq.empty, None)
|
val statusNone = Status(Off, Seq.empty)
|
||||||
case class Status(
|
case class Status(enforcement_level: EnforcementLevel, contexts: Seq[String])
|
||||||
url: Option[ApiPath], // for output
|
|
||||||
enforcement_level: EnforcementLevel,
|
|
||||||
contexts: Seq[String],
|
|
||||||
contexts_url: Option[ApiPath] // for output
|
|
||||||
)
|
|
||||||
sealed class EnforcementLevel(val name: String)
|
sealed class EnforcementLevel(val name: String)
|
||||||
case object Off extends EnforcementLevel("off")
|
case object Off extends EnforcementLevel("off")
|
||||||
case object NonAdmins extends EnforcementLevel("non_admins")
|
case object NonAdmins extends EnforcementLevel("non_admins")
|
||||||
@@ -66,7 +39,7 @@ object ApiBranchProtection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit val enforcementLevelSerializer: CustomSerializer[EnforcementLevel] = new CustomSerializer[EnforcementLevel](
|
implicit val enforcementLevelSerializer = new CustomSerializer[EnforcementLevel](
|
||||||
format =>
|
format =>
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object ApiContents {
|
|||||||
"file",
|
"file",
|
||||||
fileInfo.name,
|
fileInfo.name,
|
||||||
fileInfo.path,
|
fileInfo.path,
|
||||||
fileInfo.id.getName,
|
fileInfo.commitId,
|
||||||
Some(Base64.getEncoder.encodeToString(arr)),
|
Some(Base64.getEncoder.encodeToString(arr)),
|
||||||
Some("base64")
|
Some("base64")
|
||||||
)(repositoryName)
|
)(repositoryName)
|
||||||
|
|||||||
@@ -1,49 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
import gitbucket.core.model.{Milestone, Repository}
|
|
||||||
import gitbucket.core.util.RepositoryName
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#milestones
|
|
||||||
*/
|
|
||||||
case class ApiMilestone(
|
|
||||||
url: ApiPath,
|
|
||||||
html_url: ApiPath,
|
|
||||||
// label_url: ApiPath,
|
|
||||||
id: Int,
|
|
||||||
number: Int,
|
|
||||||
state: String,
|
|
||||||
title: String,
|
|
||||||
description: String,
|
|
||||||
// creator: ApiUser, // MILESTONE table does not have created user column
|
|
||||||
open_issues: Int,
|
|
||||||
closed_issues: Int,
|
|
||||||
// created_at: Option[Date],
|
|
||||||
// updated_at: Option[Date],
|
|
||||||
closed_at: Option[Date],
|
|
||||||
due_on: Option[Date]
|
|
||||||
)
|
|
||||||
|
|
||||||
object ApiMilestone {
|
|
||||||
def apply(
|
|
||||||
repository: Repository,
|
|
||||||
milestone: Milestone,
|
|
||||||
open_issue_count: Int = 0,
|
|
||||||
closed_issue_count: Int = 0
|
|
||||||
): ApiMilestone =
|
|
||||||
ApiMilestone(
|
|
||||||
url = ApiPath(s"/api/v3/repos/${RepositoryName(repository).fullName}/milestones/${milestone.milestoneId}"),
|
|
||||||
html_url = ApiPath(s"/${RepositoryName(repository).fullName}/milestone/${milestone.milestoneId}"),
|
|
||||||
// label_url = ApiPath(s"/api/v3/repos/${RepositoryName(repository).fullName}/milestones/${milestone_number}/labels"),
|
|
||||||
id = milestone.milestoneId,
|
|
||||||
number = milestone.milestoneId, // use milestoneId as number
|
|
||||||
state = if (milestone.closedDate.isDefined) "closed" else "open",
|
|
||||||
title = milestone.title,
|
|
||||||
description = milestone.description.getOrElse(""),
|
|
||||||
open_issues = open_issue_count,
|
|
||||||
closed_issues = closed_issue_count,
|
|
||||||
closed_at = milestone.closedDate,
|
|
||||||
due_on = milestone.dueDate
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
import gitbucket.core.plugin.PluginInfo
|
import gitbucket.core.plugin.{PluginRegistry, PluginInfo}
|
||||||
|
|
||||||
case class ApiPlugin(
|
case class ApiPlugin(
|
||||||
id: String,
|
id: String,
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ case class ApiRepository(
|
|||||||
forks: Int,
|
forks: Int,
|
||||||
`private`: Boolean,
|
`private`: Boolean,
|
||||||
default_branch: String,
|
default_branch: String,
|
||||||
owner: ApiUser,
|
owner: ApiUser
|
||||||
has_issues: Boolean
|
|
||||||
) {
|
) {
|
||||||
val id = 0 // dummy id
|
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}")
|
||||||
|
val http_url = ApiPath(s"/git/${full_name}.git")
|
||||||
val clone_url = ApiPath(s"/git/${full_name}.git")
|
val clone_url = ApiPath(s"/git/${full_name}.git")
|
||||||
val html_url = ApiPath(s"/${full_name}")
|
val html_url = ApiPath(s"/${full_name}")
|
||||||
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
||||||
@@ -39,16 +39,11 @@ object ApiRepository {
|
|||||||
forks = forkedCount,
|
forks = forkedCount,
|
||||||
`private` = repository.isPrivate,
|
`private` = repository.isPrivate,
|
||||||
default_branch = repository.defaultBranch,
|
default_branch = repository.defaultBranch,
|
||||||
owner = owner,
|
owner = owner
|
||||||
has_issues = if (repository.options.issuesOption == "DISABLE") false else true
|
|
||||||
)
|
)
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
||||||
ApiRepository(
|
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
|
||||||
repositoryInfo.repository,
|
|
||||||
owner,
|
|
||||||
forkedCount = repositoryInfo.forkedCount
|
|
||||||
)
|
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
||||||
this(repositoryInfo, ApiUser(owner))
|
this(repositoryInfo, ApiUser(owner))
|
||||||
@@ -62,7 +57,6 @@ object ApiRepository {
|
|||||||
forks = 0,
|
forks = 0,
|
||||||
`private` = false,
|
`private` = false,
|
||||||
default_branch = "master",
|
default_branch = "master",
|
||||||
owner = owner,
|
owner = owner
|
||||||
has_issues = true
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
case class ApiRepositoryCollaborator(
|
|
||||||
permission: String,
|
|
||||||
user: ApiUser
|
|
||||||
)
|
|
||||||
@@ -1,29 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
import gitbucket.core.util.RepositoryName
|
|
||||||
|
|
||||||
case class ApiTagCommit(
|
|
||||||
sha: String,
|
|
||||||
url: ApiPath
|
|
||||||
)
|
|
||||||
|
|
||||||
case class ApiTag(
|
|
||||||
name: String,
|
|
||||||
commit: ApiTagCommit,
|
|
||||||
zipball_url: ApiPath,
|
|
||||||
tarball_url: ApiPath
|
|
||||||
)
|
|
||||||
|
|
||||||
object ApiTag {
|
|
||||||
def apply(
|
|
||||||
tagName: String,
|
|
||||||
repositoryName: RepositoryName,
|
|
||||||
commitId: String
|
|
||||||
): ApiTag =
|
|
||||||
ApiTag(
|
|
||||||
name = tagName,
|
|
||||||
commit = ApiTagCommit(sha = commitId, url = ApiPath(s"/${repositoryName.fullName}/commits/${commitId}")),
|
|
||||||
zipball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.zip"),
|
|
||||||
tarball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.tar.gz")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,44 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#webhooks
|
|
||||||
*/
|
|
||||||
case class ApiWebhookConfig(
|
|
||||||
content_type: String,
|
|
||||||
// insecure_ssl: String,
|
|
||||||
url: String
|
|
||||||
)
|
|
||||||
|
|
||||||
case class ApiWebhook(
|
|
||||||
`type`: String,
|
|
||||||
id: Int,
|
|
||||||
name: String,
|
|
||||||
active: Boolean,
|
|
||||||
events: List[String],
|
|
||||||
config: ApiWebhookConfig,
|
|
||||||
// updated_at: Option[Date],
|
|
||||||
// created_at: Option[Date],
|
|
||||||
url: ApiPath,
|
|
||||||
// test_url: ApiPath,
|
|
||||||
// ping_url: ApiPath,
|
|
||||||
// last_response: ...
|
|
||||||
)
|
|
||||||
|
|
||||||
object ApiWebhook {
|
|
||||||
def apply(
|
|
||||||
_type: String,
|
|
||||||
hook: RepositoryWebHook,
|
|
||||||
hookEvents: Set[WebHook.Event]
|
|
||||||
): ApiWebhook =
|
|
||||||
ApiWebhook(
|
|
||||||
`type` = _type,
|
|
||||||
id = hook.hookId,
|
|
||||||
name = "web", // dummy
|
|
||||||
active = true, // dummy
|
|
||||||
events = hookEvents.toList.map(_.name),
|
|
||||||
config = ApiWebhookConfig(hook.ctype.code, hook.url),
|
|
||||||
url = ApiPath(s"/api/v3/${hook.userName}/${hook.repositoryName}/hooks/${hook.hookId}")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,14 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
import java.util.Date
|
|
||||||
|
|
||||||
case class CreateAMilestone(
|
|
||||||
title: String,
|
|
||||||
state: String = "open",
|
|
||||||
description: Option[String],
|
|
||||||
due_on: Option[Date]
|
|
||||||
) {
|
|
||||||
def isValid: Boolean = {
|
|
||||||
title.length <= 100 && title.matches("[a-zA-Z0-9\\-\\+_.]+")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -15,11 +15,3 @@ case class CreateAPullRequestAlt(
|
|||||||
base: String,
|
base: String,
|
||||||
maintainer_can_modify: Option[Boolean]
|
maintainer_can_modify: Option[Boolean]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class UpdateAPullRequest(
|
|
||||||
title: Option[String],
|
|
||||||
body: Option[String],
|
|
||||||
state: Option[String],
|
|
||||||
base: Option[String],
|
|
||||||
maintainer_can_modify: Option[Boolean],
|
|
||||||
)
|
|
||||||
|
|||||||
@@ -1,7 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
|
||||||
* api form
|
|
||||||
*/
|
|
||||||
case class CreateARef(ref: String, sha: String)
|
|
||||||
@@ -1,35 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
case class CreateARepositoryWebhookConfig(
|
|
||||||
url: String,
|
|
||||||
content_type: String = "form",
|
|
||||||
insecure_ssl: String = "0",
|
|
||||||
secret: Option[String]
|
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook
|
|
||||||
*/
|
|
||||||
case class CreateARepositoryWebhook(
|
|
||||||
name: String = "web",
|
|
||||||
config: CreateARepositoryWebhookConfig,
|
|
||||||
events: List[String] = List("push"),
|
|
||||||
active: Boolean = true
|
|
||||||
) {
|
|
||||||
def isValid: Boolean = {
|
|
||||||
config.content_type == "form" || config.content_type == "json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case class UpdateARepositoryWebhook(
|
|
||||||
name: String = "web",
|
|
||||||
config: CreateARepositoryWebhookConfig,
|
|
||||||
events: List[String] = List("push"),
|
|
||||||
add_events: List[String] = List(),
|
|
||||||
remove_events: List[String] = List(),
|
|
||||||
active: Boolean = true
|
|
||||||
) {
|
|
||||||
def isValid: Boolean = {
|
|
||||||
config.content_type == "form" || config.content_type == "json"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,23 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request
|
|
||||||
*/
|
|
||||||
case class MergeAPullRequest(
|
|
||||||
commit_title: Option[String],
|
|
||||||
commit_message: Option[String],
|
|
||||||
/* TODO: Not Implemented
|
|
||||||
sha: Option[String],*/
|
|
||||||
merge_method: Option[String]
|
|
||||||
)
|
|
||||||
|
|
||||||
case class SuccessToMergePrResponse(
|
|
||||||
sha: String,
|
|
||||||
merged: Boolean,
|
|
||||||
message: String
|
|
||||||
)
|
|
||||||
|
|
||||||
case class FailToMergePrResponse(
|
|
||||||
documentation_url: String,
|
|
||||||
message: String
|
|
||||||
)
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
/**
|
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
|
|
||||||
* api form
|
|
||||||
*/
|
|
||||||
case class UpdateARef(sha: String, force: Boolean)
|
|
||||||
@@ -35,7 +35,6 @@ class AccountController
|
|||||||
with WebHookService
|
with WebHookService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
with RepositoryCreationService
|
with RepositoryCreationService
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait AccountControllerBase extends AccountManagementControllerBase {
|
trait AccountControllerBase extends AccountManagementControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
@@ -82,8 +81,6 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
case class PersonalTokenForm(note: String)
|
case class PersonalTokenForm(note: String)
|
||||||
|
|
||||||
case class SyntaxHighlighterThemeForm(theme: String)
|
|
||||||
|
|
||||||
val newForm = mapping(
|
val newForm = mapping(
|
||||||
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
||||||
@@ -124,10 +121,6 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||||
)(PersonalTokenForm.apply)
|
)(PersonalTokenForm.apply)
|
||||||
|
|
||||||
val syntaxHighlighterThemeForm = mapping(
|
|
||||||
"highlighterTheme" -> trim(label("Theme", text(required)))
|
|
||||||
)(SyntaxHighlighterThemeForm.apply)
|
|
||||||
|
|
||||||
case class NewGroupForm(
|
case class NewGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
@@ -434,7 +427,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).foreach { x =>
|
getAccountByUserName(userName).map { x =>
|
||||||
val (tokenId, token) = generateAccessToken(userName, form.note)
|
val (tokenId, token) = generateAccessToken(userName, form.note)
|
||||||
flash.update("generatedToken", (tokenId, token))
|
flash.update("generatedToken", (tokenId, token))
|
||||||
}
|
}
|
||||||
@@ -448,29 +441,6 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect(s"/${userName}/_application")
|
redirect(s"/${userName}/_application")
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* Display the user preference settings page
|
|
||||||
*/
|
|
||||||
get("/:userName/_preferences")(oneselfOnly {
|
|
||||||
val userName = params("userName")
|
|
||||||
val currentTheme = getAccountPreference(userName) match {
|
|
||||||
case Some(accountHighlighter) => accountHighlighter.highlighterTheme
|
|
||||||
case _ => "github-v2"
|
|
||||||
}
|
|
||||||
getAccountByUserName(userName).map { x =>
|
|
||||||
html.preferences(x, currentTheme)
|
|
||||||
} getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Update the syntax highlighter setting of user
|
|
||||||
*/
|
|
||||||
post("/:userName/_preferences/highlighter", syntaxHighlighterThemeForm)(oneselfOnly { form =>
|
|
||||||
val userName = params("userName")
|
|
||||||
addOrUpdateAccountPreference(userName, form.theme)
|
|
||||||
redirect(s"/${userName}/_preferences")
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/:userName/_hooks")(managersOnly {
|
get("/:userName/_hooks")(managersOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { account =>
|
getAccountByUserName(userName).map { account =>
|
||||||
@@ -551,8 +521,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val url = params("url")
|
val url = params("url")
|
||||||
val token = Some(params("token"))
|
val token = Some(params("token"))
|
||||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||||
val dummyWebHookInfo =
|
val dummyWebHookInfo = RepositoryWebHook(userName, "dummy", url, ctype, token)
|
||||||
RepositoryWebHook(userName = userName, repositoryName = "dummy", url = url, ctype = ctype, token = token)
|
|
||||||
val dummyPayload = {
|
val dummyPayload = {
|
||||||
val ownerAccount = getAccountByUserName(userName).get
|
val ownerAccount = getAccountByUserName(userName).get
|
||||||
WebHookPushPayload.createDummyPayload(ownerAccount)
|
WebHookPushPayload.createDummyPayload(ownerAccount)
|
||||||
@@ -629,9 +598,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get("/groups/new")(usersOnly {
|
get("/groups/new")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
html.creategroup(List(GroupMember("", context.loginAccount.get.userName, true)))
|
||||||
html.creategroup(List(GroupMember("", loginAccount.userName, true)))
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/groups/new", newGroupForm)(usersOnly { form =>
|
post("/groups/new", newGroupForm)(usersOnly { form =>
|
||||||
@@ -652,20 +619,22 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:groupName/_editgroup")(managersOnly {
|
get("/:groupName/_editgroup")(managersOnly {
|
||||||
val groupName = params("groupName")
|
defining(params("groupName")) { groupName =>
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, true).map { account =>
|
||||||
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:groupName/_deletegroup")(managersOnly {
|
get("/:groupName/_deletegroup")(managersOnly {
|
||||||
val groupName = params("groupName")
|
defining(params("groupName")) {
|
||||||
// Remove from GROUP_MEMBER
|
groupName =>
|
||||||
updateGroupMembers(groupName, Nil)
|
// Remove from GROUP_MEMBER
|
||||||
// Disable group
|
updateGroupMembers(groupName, Nil)
|
||||||
getAccountByUserName(groupName, false).foreach { account =>
|
// Disable group
|
||||||
updateGroup(groupName, account.description, account.url, true)
|
getAccountByUserName(groupName, false).foreach { account =>
|
||||||
}
|
updateGroup(groupName, account.description, account.url, true)
|
||||||
|
}
|
||||||
// // Remove repositories
|
// // Remove repositories
|
||||||
// getRepositoryNamesOfUser(groupName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(groupName).foreach { repositoryName =>
|
||||||
// deleteRepository(groupName, repositoryName)
|
// deleteRepository(groupName, repositoryName)
|
||||||
@@ -673,25 +642,28 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
||||||
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
||||||
// }
|
// }
|
||||||
|
}
|
||||||
redirect("/")
|
redirect("/")
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:groupName/_editgroup", editGroupForm)(managersOnly { form =>
|
post("/:groupName/_editgroup", editGroupForm)(managersOnly { form =>
|
||||||
val groupName = params("groupName")
|
defining(
|
||||||
val members = form.members
|
params("groupName"),
|
||||||
.split(",")
|
form.members
|
||||||
.map {
|
.split(",")
|
||||||
_.split(":") match {
|
.map {
|
||||||
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
_.split(":") match {
|
||||||
|
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.toList
|
||||||
.toList
|
) {
|
||||||
|
case (groupName, members) =>
|
||||||
|
getAccountByUserName(groupName, true).map { account =>
|
||||||
|
updateGroup(groupName, form.description, form.url, false)
|
||||||
|
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
// Update GROUP_MEMBER
|
||||||
updateGroup(groupName, form.description, form.url, false)
|
updateGroupMembers(form.groupName, members)
|
||||||
|
|
||||||
// Update GROUP_MEMBER
|
|
||||||
updateGroupMembers(form.groupName, members)
|
|
||||||
// // Update COLLABORATOR for group repositories
|
// // Update COLLABORATOR for group repositories
|
||||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||||
// removeCollaborators(form.groupName, repositoryName)
|
// removeCollaborators(form.groupName, repositoryName)
|
||||||
@@ -700,104 +672,87 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
|
|
||||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||||
|
|
||||||
flash.update("info", "Account information has been updated.")
|
flash.update("info", "Account information has been updated.")
|
||||||
redirect(s"/${groupName}/_editgroup")
|
redirect(s"/${groupName}/_editgroup")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the new repository form.
|
* Show the new repository form.
|
||||||
*/
|
*/
|
||||||
get("/new")(usersOnly {
|
get("/new")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
html.newrepo(getGroupsByUserName(context.loginAccount.get.userName), context.settings.isCreateRepoOptionPublic)
|
||||||
html.newrepo(getGroupsByUserName(loginAccount.userName), context.settings.isCreateRepoOptionPublic)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new repository.
|
* Create new repository.
|
||||||
*/
|
*/
|
||||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||||
context.withLoginAccount {
|
if (context.settings.repositoryOperation.create || context.loginAccount.get.isAdmin) {
|
||||||
loginAccount =>
|
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||||
if (context.settings.repositoryOperation.create || loginAccount.isAdmin) {
|
if (getRepository(form.owner, form.name).isEmpty) {
|
||||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
createRepository(
|
||||||
if (getRepository(form.owner, form.name).isDefined) {
|
context.loginAccount.get,
|
||||||
// redirect to the repository if repository already exists
|
form.owner,
|
||||||
redirect(s"/${form.owner}/${form.name}")
|
form.name,
|
||||||
} else if (!canCreateRepository(form.owner, loginAccount)) {
|
form.description,
|
||||||
// Permission error
|
form.isPrivate,
|
||||||
Forbidden()
|
form.initOption,
|
||||||
} else {
|
form.sourceUrl
|
||||||
// create repository asynchronously
|
)
|
||||||
createRepository(
|
}
|
||||||
loginAccount,
|
}
|
||||||
form.owner,
|
// redirect to the repository
|
||||||
form.name,
|
redirect(s"/${form.owner}/${form.name}")
|
||||||
form.description,
|
} else Forbidden()
|
||||||
form.isPrivate,
|
|
||||||
form.initOption,
|
|
||||||
form.sourceUrl
|
|
||||||
)
|
|
||||||
// redirect to the repository
|
|
||||||
redirect(s"/${form.owner}/${form.name}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else Forbidden()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
val loginAccount = context.loginAccount.get
|
||||||
loginAccount =>
|
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
val loginUserName = loginAccount.userName
|
||||||
val loginUserName = loginAccount.userName
|
val groups = getGroupsByUserName(loginUserName)
|
||||||
val groups = getGroupsByUserName(loginUserName)
|
groups match {
|
||||||
groups match {
|
case _: List[String] =>
|
||||||
case _: List[String] =>
|
val managerPermissions = groups.map { group =>
|
||||||
val managerPermissions = groups.map { group =>
|
val members = getGroupMembers(group)
|
||||||
val members = getGroupMembers(group)
|
context.loginAccount.exists(
|
||||||
context.loginAccount.exists(
|
x =>
|
||||||
x =>
|
members.exists { member =>
|
||||||
members.exists { member =>
|
member.userName == x.userName && member.isManager
|
||||||
member.userName == x.userName && member.isManager
|
|
||||||
}
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
helper.html.forkrepository(
|
)
|
||||||
repository,
|
|
||||||
(groups zip managerPermissions).sortBy(_._1)
|
|
||||||
)
|
|
||||||
case _ => redirect(s"/${loginUserName}")
|
|
||||||
}
|
}
|
||||||
} else BadRequest()
|
helper.html.forkrepository(
|
||||||
}
|
repository,
|
||||||
|
(groups zip managerPermissions).sortBy(_._1)
|
||||||
|
)
|
||||||
|
case _ => redirect(s"/${loginUserName}")
|
||||||
|
}
|
||||||
|
} else BadRequest()
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
val loginAccount = context.loginAccount.get
|
||||||
loginAccount =>
|
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
val loginUserName = loginAccount.userName
|
||||||
val loginUserName = loginAccount.userName
|
val accountName = form.accountName
|
||||||
val accountName = form.accountName
|
|
||||||
|
|
||||||
if (getRepository(accountName, repository.name).isDefined) {
|
if (getRepository(accountName, repository.name).isDefined ||
|
||||||
// redirect to the repository if repository already exists
|
(accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))) {
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
// redirect to the repository if repository already exists
|
||||||
} else if (!canCreateRepository(accountName, loginAccount)) {
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
// Permission error
|
} else {
|
||||||
Forbidden()
|
// fork repository asynchronously
|
||||||
} else {
|
forkRepository(accountName, repository, loginUserName)
|
||||||
// fork repository asynchronously
|
// redirect to the repository
|
||||||
forkRepository(accountName, repository, loginUserName)
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
// redirect to the repository
|
}
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
} else Forbidden()
|
||||||
}
|
|
||||||
} else Forbidden()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
private def existsAccount: Constraint = new Constraint() {
|
private def existsAccount: Constraint = new Constraint() {
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ class ApiController
|
|||||||
with ApiIssueCommentControllerBase
|
with ApiIssueCommentControllerBase
|
||||||
with ApiIssueControllerBase
|
with ApiIssueControllerBase
|
||||||
with ApiIssueLabelControllerBase
|
with ApiIssueLabelControllerBase
|
||||||
with ApiIssueMilestoneControllerBase
|
|
||||||
with ApiOrganizationControllerBase
|
with ApiOrganizationControllerBase
|
||||||
with ApiPullRequestControllerBase
|
with ApiPullRequestControllerBase
|
||||||
with ApiReleaseControllerBase
|
with ApiReleaseControllerBase
|
||||||
@@ -23,7 +22,6 @@ 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
|
||||||
@@ -54,7 +52,6 @@ class ApiController
|
|||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait ApiControllerBase extends ControllerBase {
|
trait ApiControllerBase extends ControllerBase {
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,6 @@ import org.eclipse.jgit.revwalk.RevCommit
|
|||||||
import org.eclipse.jgit.treewalk._
|
import org.eclipse.jgit.treewalk._
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.json4s.Formats
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides generic features for controller implementations.
|
* Provides generic features for controller implementations.
|
||||||
@@ -44,7 +43,7 @@ abstract class ControllerBase
|
|||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(getClass)
|
private val logger = LoggerFactory.getLogger(getClass)
|
||||||
|
|
||||||
implicit val jsonFormats: Formats = gitbucket.core.api.JsonFormat.jsonFormats
|
implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats
|
||||||
|
|
||||||
before("/api/v3/*") {
|
before("/api/v3/*") {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -158,8 +157,11 @@ abstract class ControllerBase
|
|||||||
org.scalatra.Unauthorized(
|
org.scalatra.Unauthorized(
|
||||||
redirect(
|
redirect(
|
||||||
"/signin?redirect=" + StringUtil.urlEncode(
|
"/signin?redirect=" + StringUtil.urlEncode(
|
||||||
request.getRequestURI
|
defining(request.getQueryString) { queryString =>
|
||||||
.substring(request.getContextPath.length) + Option(request.getQueryString).map("?" + _).getOrElse("")
|
request.getRequestURI.substring(request.getContextPath.length) + (if (queryString != null)
|
||||||
|
"?" + queryString
|
||||||
|
else "")
|
||||||
|
}
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -253,7 +255,7 @@ abstract class ControllerBase
|
|||||||
repository: RepositoryService.RepositoryInfo
|
repository: RepositoryService.RepositoryInfo
|
||||||
): Unit = {
|
): Unit = {
|
||||||
JGitUtil.getObjectLoaderFromId(git, objectId) { loader =>
|
JGitUtil.getObjectLoaderFromId(git, objectId) { loader =>
|
||||||
contentType = FileUtil.getSafeMimeType(path, repository.repository.options.safeMode)
|
contentType = FileUtil.getSafeMimeType(path)
|
||||||
|
|
||||||
if (loader.isLarge) {
|
if (loader.isLarge) {
|
||||||
response.setContentLength(loader.getSize.toInt)
|
response.setContentLength(loader.getSize.toInt)
|
||||||
@@ -300,27 +302,20 @@ case class Context(
|
|||||||
}
|
}
|
||||||
val sidebarCollapse = request.getSession.getAttribute("sidebar-collapse") != null
|
val sidebarCollapse = request.getSession.getAttribute("sidebar-collapse") != null
|
||||||
|
|
||||||
def withLoginAccount(f: Account => Any): Any = {
|
|
||||||
loginAccount match {
|
|
||||||
case Some(loginAccount) => f(loginAccount)
|
|
||||||
case None => Unauthorized()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object from cache.
|
* Get object from cache.
|
||||||
*
|
*
|
||||||
* If object has not been cached with the specified key then retrieves by given action.
|
* If object has not been cached with the specified key then retrieves by given action.
|
||||||
* Cached object are available during a request.
|
* Cached object are available during a request.
|
||||||
*/
|
*/
|
||||||
def cache[A](key: String)(action: => A): A = {
|
def cache[A](key: String)(action: => A): A =
|
||||||
val cacheKey = Keys.Request.Cache(key)
|
defining(Keys.Request.Cache(key)) { cacheKey =>
|
||||||
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
||||||
val newObject = action
|
val newObject = action
|
||||||
request.setAttribute(cacheKey, newObject)
|
request.setAttribute(cacheKey, newObject)
|
||||||
newObject
|
newObject
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -426,7 +421,7 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
"new"
|
"new"
|
||||||
)
|
)
|
||||||
|
|
||||||
protected def reservedNames: Constraint = new Constraint() {
|
protected def reservedNames(): Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (allReservedNames.contains(value.toLowerCase)) {
|
if (allReservedNames.contains(value.toLowerCase)) {
|
||||||
Some(s"${value} is reserved")
|
Some(s"${value} is reserved")
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.dashboard.html
|
import gitbucket.core.dashboard.html
|
||||||
import gitbucket.core.model.Account
|
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -22,76 +21,51 @@ class DashboardController
|
|||||||
with WebHookPullRequestService
|
with WebHookPullRequestService
|
||||||
with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestReviewCommentService
|
||||||
with MilestonesService
|
with MilestonesService
|
||||||
with CommitStatusService
|
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait DashboardControllerBase extends ControllerBase {
|
trait DashboardControllerBase extends ControllerBase {
|
||||||
self: IssuesService
|
self: IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator =>
|
||||||
with PullRequestService
|
|
||||||
with RepositoryService
|
|
||||||
with AccountService
|
|
||||||
with CommitStatusService
|
|
||||||
with UsersAuthenticator =>
|
|
||||||
|
|
||||||
get("/dashboard/repos")(usersOnly {
|
get("/dashboard/repos")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
val repos = getVisibleRepositories(
|
||||||
val repos = getVisibleRepositories(
|
context.loginAccount,
|
||||||
context.loginAccount,
|
None,
|
||||||
None,
|
withoutPhysicalInfo = true,
|
||||||
withoutPhysicalInfo = true,
|
limit = context.settings.limitVisibleRepositories
|
||||||
limit = context.settings.limitVisibleRepositories
|
)
|
||||||
)
|
html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos)
|
||||||
html.repos(getGroupNames(loginAccount.userName), repos, repos)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues")(usersOnly {
|
get("/dashboard/issues")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchIssues("created_by")
|
||||||
searchIssues(loginAccount, "created_by")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/assigned")(usersOnly {
|
get("/dashboard/issues/assigned")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchIssues("assigned")
|
||||||
searchIssues(loginAccount, "assigned")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/created_by")(usersOnly {
|
get("/dashboard/issues/created_by")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchIssues("created_by")
|
||||||
searchIssues(loginAccount, "created_by")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/mentioned")(usersOnly {
|
get("/dashboard/issues/mentioned")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchIssues("mentioned")
|
||||||
searchIssues(loginAccount, "mentioned")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls")(usersOnly {
|
get("/dashboard/pulls")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchPullRequests("created_by")
|
||||||
searchPullRequests(loginAccount, "created_by")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/created_by")(usersOnly {
|
get("/dashboard/pulls/created_by")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchPullRequests("created_by")
|
||||||
searchPullRequests(loginAccount, "created_by")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/assigned")(usersOnly {
|
get("/dashboard/pulls/assigned")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchPullRequests("assigned")
|
||||||
searchPullRequests(loginAccount, "assigned")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/mentioned")(usersOnly {
|
get("/dashboard/pulls/mentioned")(usersOnly {
|
||||||
context.withLoginAccount { loginAccount =>
|
searchPullRequests("mentioned")
|
||||||
searchPullRequests(loginAccount, "mentioned")
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
||||||
@@ -104,20 +78,19 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(loginAccount: Account, filter: String) = {
|
private def searchIssues(filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
|
|
||||||
val userName = loginAccount.userName
|
val userName = context.loginAccount.get.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
||||||
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val issues = searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, userRepos: _*)
|
|
||||||
|
|
||||||
html.issues(
|
html.issues(
|
||||||
issues.map(issue => (issue, None)),
|
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, userRepos: _*),
|
||||||
page,
|
page,
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, userRepos: _*),
|
countIssue(condition.copy(state = "open"), false, userRepos: _*),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, userRepos: _*),
|
countIssue(condition.copy(state = "closed"), false, userRepos: _*),
|
||||||
filter match {
|
filter match {
|
||||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
@@ -134,32 +107,20 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchPullRequests(loginAccount: Account, filter: String) = {
|
private def searchPullRequests(filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
import PullRequestService._
|
import PullRequestService._
|
||||||
|
|
||||||
val userName = loginAccount.userName
|
val userName = context.loginAccount.get.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
||||||
val allRepos = getAllRepositories(userName)
|
val allRepos = getAllRepositories(userName)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val issues = searchIssue(
|
|
||||||
condition,
|
|
||||||
IssueSearchOption.PullRequests,
|
|
||||||
(page - 1) * PullRequestLimit,
|
|
||||||
PullRequestLimit,
|
|
||||||
allRepos: _*
|
|
||||||
)
|
|
||||||
val status = issues.map { issue =>
|
|
||||||
issue.commitId.flatMap { commitId =>
|
|
||||||
getCommitStatusWithSummary(issue.issue.userName, issue.issue.repositoryName, commitId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
html.pulls(
|
html.pulls(
|
||||||
issues.zip(status),
|
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, allRepos: _*),
|
||||||
page,
|
page,
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, allRepos: _*),
|
countIssue(condition.copy(state = "open"), true, allRepos: _*),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, allRepos: _*),
|
countIssue(condition.copy(state = "closed"), true, allRepos: _*),
|
||||||
filter match {
|
filter match {
|
||||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import gitbucket.core.model.Account
|
|||||||
import gitbucket.core.service.{AccountService, ReleaseService, RepositoryService}
|
import gitbucket.core.service.{AccountService, ReleaseService, RepositoryService}
|
||||||
import gitbucket.core.servlet.Database
|
import gitbucket.core.servlet.Database
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@@ -17,7 +18,6 @@ import org.apache.commons.io.{FileUtils, IOUtils}
|
|||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
import gitbucket.core.service.SystemSettingsService
|
import gitbucket.core.service.SystemSettingsService
|
||||||
import slick.jdbc.JdbcBackend.Session
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Ajax based file upload functionality.
|
* Provides Ajax based file upload functionality.
|
||||||
@@ -37,10 +37,10 @@ class FileUploadController
|
|||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
FileUtil.isImage(_)
|
FileUtil.isImage
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class FileUploadController
|
|||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -65,7 +65,7 @@ class FileUploadController
|
|||||||
getAttachedDir(params("owner"), params("repository")),
|
getAttachedDir(params("owner"), params("repository")),
|
||||||
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
||||||
),
|
),
|
||||||
file.get()
|
file.get
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -131,7 +131,7 @@ class FileUploadController
|
|||||||
} getOrElse BadRequest()
|
} getOrElse BadRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/release/:owner/:repository/*") {
|
post("/release/:owner/:repository/:tag") {
|
||||||
setMultipartConfigForLargeFile()
|
setMultipartConfigForLargeFile()
|
||||||
session
|
session
|
||||||
.get(Keys.Session.LoginAccount)
|
.get(Keys.Session.LoginAccount)
|
||||||
@@ -139,12 +139,12 @@ class FileUploadController
|
|||||||
case _: Account =>
|
case _: Account =>
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val tag = multiParams("splat").head
|
val tag = params("tag")
|
||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
||||||
file.get()
|
file.get
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -178,7 +178,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
||||||
implicit val session: Session = Database.getSession(request)
|
implicit val session = Database.getSession(request)
|
||||||
getRepository(owner, repository) match {
|
getRepository(owner, repository) match {
|
||||||
case Some(x) =>
|
case Some(x) =>
|
||||||
x.repository.options.wikiOption match {
|
x.repository.options.wikiOption match {
|
||||||
@@ -191,13 +191,14 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def execute(f: (FileItem, String) => Unit, mimeTypeChecker: (String) => Boolean) =
|
private def execute(f: (FileItem, String) => Unit, mimeTypeChcker: (String) => Boolean) =
|
||||||
fileParams.get("file") match {
|
fileParams.get("file") match {
|
||||||
case Some(file) if mimeTypeChecker(file.name) =>
|
case Some(file) if (mimeTypeChcker(file.name)) =>
|
||||||
val fileId = FileUtil.generateFileId
|
defining(FileUtil.generateFileId) { fileId =>
|
||||||
f(file, fileId)
|
f(file, fileId)
|
||||||
contentType = "text/plain"
|
contentType = "text/plain"
|
||||||
Ok(fileId)
|
Ok(fileId)
|
||||||
|
}
|
||||||
case _ => BadRequest()
|
case _ => BadRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import gitbucket.core.helper.xml
|
|||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view.helpers._
|
import gitbucket.core.view.helpers._
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
@@ -28,7 +29,6 @@ class IndexController
|
|||||||
with AccessTokenService
|
with AccessTokenService
|
||||||
with AccountFederationService
|
with AccountFederationService
|
||||||
with OpenIDConnectService
|
with OpenIDConnectService
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait IndexControllerBase extends ControllerBase {
|
trait IndexControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -78,7 +78,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
.getOrElse {
|
.getOrElse {
|
||||||
gitbucket.core.html.index(
|
gitbucket.core.html.index(
|
||||||
getRecentPublicActivities(),
|
getRecentActivities(),
|
||||||
getVisibleRepositories(None, withoutPhysicalInfo = true),
|
getVisibleRepositories(None, withoutPhysicalInfo = true),
|
||||||
showBannerToCreatePersonalAccessToken = false
|
showBannerToCreatePersonalAccessToken = false
|
||||||
)
|
)
|
||||||
@@ -161,7 +161,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/activities.atom") {
|
get("/activities.atom") {
|
||||||
contentType = "application/atom+xml; type=feed"
|
contentType = "application/atom+xml; type=feed"
|
||||||
xml.feed(getRecentPublicActivities())
|
xml.feed(getRecentActivities())
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/sidebar-collapse") {
|
post("/sidebar-collapse") {
|
||||||
@@ -212,10 +212,8 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
.map { t =>
|
.map { t =>
|
||||||
Map(
|
Map(
|
||||||
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(
|
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(t.userName)}</b> ${StringUtil
|
||||||
StringUtil.cutTail(t.userName, 25, "...")
|
.escapeHtml(t.fullName)}",
|
||||||
)}</b> ${StringUtil
|
|
||||||
.escapeHtml(StringUtil.cutTail(t.fullName, 25, "..."))}",
|
|
||||||
"value" -> t.userName
|
"value" -> t.userName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -236,49 +234,50 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
// TODO Move to RepositoryViewrController?
|
// TODO Move to RepositoryViewrController?
|
||||||
get("/:owner/:repository/search")(referrersOnly { repository =>
|
get("/:owner/:repository/search")(referrersOnly { repository =>
|
||||||
val query = params.getOrElse("q", "").trim
|
defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")) {
|
||||||
val target = params.getOrElse("type", "code")
|
case (query, target) =>
|
||||||
val page = try {
|
val page = try {
|
||||||
val i = params.getOrElse("page", "1").toInt
|
val i = params.getOrElse("page", "1").toInt
|
||||||
if (i <= 0) 1 else i
|
if (i <= 0) 1 else i
|
||||||
} catch {
|
} catch {
|
||||||
case _: NumberFormatException => 1
|
case e: NumberFormatException => 1
|
||||||
}
|
}
|
||||||
|
|
||||||
target.toLowerCase match {
|
target.toLowerCase match {
|
||||||
case "issues" =>
|
case "issues" =>
|
||||||
gitbucket.core.search.html.issues(
|
gitbucket.core.search.html.issues(
|
||||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, false) else Nil,
|
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, false) else Nil,
|
||||||
false,
|
false,
|
||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
|
|
||||||
case "pulls" =>
|
case "pulls" =>
|
||||||
gitbucket.core.search.html.issues(
|
gitbucket.core.search.html.issues(
|
||||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, true) else Nil,
|
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, true) else Nil,
|
||||||
true,
|
true,
|
||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
|
|
||||||
case "wiki" =>
|
case "wiki" =>
|
||||||
gitbucket.core.search.html.wiki(
|
gitbucket.core.search.html.wiki(
|
||||||
if (query.nonEmpty) searchWikiPages(repository.owner, repository.name, query) else Nil,
|
if (query.nonEmpty) searchWikiPages(repository.owner, repository.name, query) else Nil,
|
||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
|
|
||||||
case _ =>
|
case _ =>
|
||||||
gitbucket.core.search.html.code(
|
gitbucket.core.search.html.code(
|
||||||
if (query.nonEmpty) searchFiles(repository.owner, repository.name, query) else Nil,
|
if (query.nonEmpty) searchFiles(repository.owner, repository.name, query) else Nil,
|
||||||
query,
|
query,
|
||||||
page,
|
page,
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.issues.html
|
import gitbucket.core.issues.html
|
||||||
import gitbucket.core.model.Account
|
|
||||||
import gitbucket.core.service.IssuesService._
|
import gitbucket.core.service.IssuesService._
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
@@ -30,7 +30,6 @@ class IssuesController
|
|||||||
with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestReviewCommentService
|
||||||
with CommitsService
|
with CommitsService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait IssuesControllerBase extends ControllerBase {
|
trait IssuesControllerBase extends ControllerBase {
|
||||||
self: IssuesService
|
self: IssuesService
|
||||||
@@ -95,224 +94,211 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
||||||
val issueId = params("id")
|
defining(repository.owner, repository.name, params("id")) {
|
||||||
getIssue(repository.owner, repository.name, issueId) map {
|
case (owner, name, issueId) =>
|
||||||
issue =>
|
getIssue(owner, name, issueId) map {
|
||||||
if (issue.isPullRequest) {
|
issue =>
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
if (issue.isPullRequest) {
|
||||||
} else {
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
html.issue(
|
} else {
|
||||||
issue,
|
html.issue(
|
||||||
getComments(repository.owner, repository.name, issueId.toInt),
|
issue,
|
||||||
getIssueLabels(repository.owner, repository.name, issueId.toInt),
|
getComments(owner, name, issueId.toInt),
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
getIssueLabels(owner, name, issueId.toInt),
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name),
|
getAssignableUserNames(owner, name),
|
||||||
getPriorities(repository.owner, repository.name),
|
getMilestonesWithIssueCount(owner, name),
|
||||||
getLabels(repository.owner, repository.name),
|
getPriorities(owner, name),
|
||||||
isIssueEditable(repository),
|
getLabels(owner, name),
|
||||||
isIssueManageable(repository),
|
isIssueEditable(repository),
|
||||||
isIssueCommentManageable(repository),
|
isIssueManageable(repository),
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
||||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||||
html.create(
|
defining(repository.owner, repository.name) {
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
case (owner, name) =>
|
||||||
getMilestones(repository.owner, repository.name),
|
html.create(
|
||||||
getPriorities(repository.owner, repository.name),
|
getAssignableUserNames(owner, name),
|
||||||
getDefaultPriority(repository.owner, repository.name),
|
getMilestones(owner, name),
|
||||||
getLabels(repository.owner, repository.name),
|
getPriorities(owner, name),
|
||||||
isIssueManageable(repository),
|
getDefaultPriority(owner, name),
|
||||||
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
getLabels(owner, name),
|
||||||
repository
|
isIssueManageable(repository),
|
||||||
)
|
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
||||||
|
repository
|
||||||
|
)
|
||||||
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||||
loginAccount =>
|
val issue = createIssue(
|
||||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
repository,
|
||||||
val issue = createIssue(
|
form.title,
|
||||||
repository,
|
form.content,
|
||||||
form.title,
|
form.assignedUserName,
|
||||||
form.content,
|
form.milestoneId,
|
||||||
form.assignedUserName,
|
form.priorityId,
|
||||||
form.milestoneId,
|
form.labelNames.toSeq.flatMap(_.split(",")),
|
||||||
form.priorityId,
|
context.loginAccount.get
|
||||||
form.labelNames.toSeq.flatMap(_.split(",")),
|
)
|
||||||
loginAccount
|
|
||||||
)
|
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
||||||
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
} else Unauthorized()
|
||||||
} else Unauthorized()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
||||||
context.withLoginAccount {
|
defining(repository.owner, repository.name) {
|
||||||
loginAccount =>
|
case (owner, name) =>
|
||||||
getIssue(repository.owner, repository.name, params("id")).map {
|
getIssue(owner, name, params("id")).map {
|
||||||
issue =>
|
issue =>
|
||||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
if (isEditableContent(owner, name, issue.openedUserName)) {
|
||||||
if (issue.title != title) {
|
if (issue.title != title) {
|
||||||
// update issue
|
// update issue
|
||||||
updateIssue(repository.owner, repository.name, issue.issueId, title, issue.content)
|
updateIssue(owner, name, issue.issueId, title, issue.content)
|
||||||
// extract references and create refer comment
|
// extract references and create refer comment
|
||||||
createReferComment(repository.owner, repository.name, issue.copy(title = title), title, loginAccount)
|
createReferComment(owner, name, issue.copy(title = title), title, context.loginAccount.get)
|
||||||
createComment(
|
createComment(
|
||||||
repository.owner,
|
owner,
|
||||||
repository.name,
|
name,
|
||||||
loginAccount.userName,
|
context.loginAccount.get.userName,
|
||||||
issue.issueId,
|
issue.issueId,
|
||||||
issue.title + "\r\n" + title,
|
issue.title + "\r\n" + title,
|
||||||
"change_title"
|
"change_title"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||||
context.withLoginAccount {
|
defining(repository.owner, repository.name) {
|
||||||
loginAccount =>
|
case (owner, name) =>
|
||||||
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
getIssue(owner, name, params("id")).map { issue =>
|
||||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
if (isEditableContent(owner, name, issue.openedUserName)) {
|
||||||
// update issue
|
// update issue
|
||||||
updateIssue(repository.owner, repository.name, issue.issueId, issue.title, content)
|
updateIssue(owner, name, issue.issueId, issue.title, content)
|
||||||
// extract references and create refer comment
|
// extract references and create refer comment
|
||||||
createReferComment(repository.owner, repository.name, issue, content.getOrElse(""), loginAccount)
|
createReferComment(owner, name, issue, content.getOrElse(""), context.loginAccount.get)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
loginAccount =>
|
val actionOpt =
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
||||||
val actionOpt =
|
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
||||||
params
|
case (issue, id) =>
|
||||||
.get("action")
|
redirect(
|
||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||||
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
)
|
||||||
case (issue, id) =>
|
}
|
||||||
redirect(
|
} getOrElse NotFound()
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} getOrElse NotFound()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
loginAccount =>
|
val actionOpt =
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
||||||
val actionOpt =
|
handleComment(issue, form.content, repository, actionOpt) map {
|
||||||
params
|
case (issue, id) =>
|
||||||
.get("action")
|
redirect(
|
||||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||||
handleComment(issue, form.content, repository, actionOpt) map {
|
)
|
||||||
case (issue, id) =>
|
}
|
||||||
redirect(
|
} getOrElse NotFound()
|
||||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} getOrElse NotFound()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
defining(repository.owner, repository.name) {
|
||||||
loginAccount =>
|
case (owner, name) =>
|
||||||
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
getComment(owner, name, params("id")).map { comment =>
|
||||||
if (isEditableContent(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
||||||
updateComment(comment.issueId, comment.commentId, form.content)
|
updateComment(comment.issueId, comment.commentId, form.content)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/issue_comments/_data/${comment.commentId}")
|
redirect(s"/${owner}/${name}/issue_comments/_data/${comment.commentId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount { loginAccount =>
|
defining(repository.owner, repository.name) {
|
||||||
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
case (owner, name) =>
|
||||||
if (isDeletableComment(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
getComment(owner, name, params("id")).map { comment =>
|
||||||
Ok(deleteComment(repository.owner, repository.name, comment.issueId, comment.commentId))
|
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
||||||
} else Unauthorized()
|
Ok(deleteComment(comment.issueId, comment.commentId))
|
||||||
} getOrElse NotFound()
|
} else Unauthorized()
|
||||||
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
getIssue(repository.owner, repository.name, params("id")) map {
|
||||||
loginAccount =>
|
x =>
|
||||||
getIssue(repository.owner, repository.name, params("id")) map {
|
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName)) {
|
||||||
x =>
|
params.get("dataType") collect {
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName, loginAccount)) {
|
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
||||||
params.get("dataType") collect {
|
} getOrElse {
|
||||||
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
contentType = formats("json")
|
||||||
} getOrElse {
|
org.json4s.jackson.Serialization.write(
|
||||||
contentType = formats("json")
|
Map(
|
||||||
org.json4s.jackson.Serialization.write(
|
"title" -> x.title,
|
||||||
Map(
|
"content" -> Markdown.toHtml(
|
||||||
"title" -> x.title,
|
markdown = x.content getOrElse "No description given.",
|
||||||
"content" -> Markdown.toHtml(
|
repository = repository,
|
||||||
markdown = x.content getOrElse "No description given.",
|
branch = repository.repository.defaultBranch,
|
||||||
repository = repository,
|
enableWikiLink = false,
|
||||||
branch = repository.repository.defaultBranch,
|
enableRefsLink = true,
|
||||||
enableWikiLink = false,
|
enableAnchor = true,
|
||||||
enableRefsLink = true,
|
enableLineBreaks = true,
|
||||||
enableAnchor = true,
|
enableTaskList = true,
|
||||||
enableLineBreaks = true,
|
hasWritePermission = true
|
||||||
enableTaskList = true,
|
|
||||||
hasWritePermission = true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
} else Unauthorized()
|
)
|
||||||
} getOrElse NotFound()
|
}
|
||||||
}
|
} else Unauthorized()
|
||||||
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
getComment(repository.owner, repository.name, params("id")) map {
|
||||||
loginAccount =>
|
x =>
|
||||||
getComment(repository.owner, repository.name, params("id")) map {
|
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName)) {
|
||||||
x =>
|
params.get("dataType") collect {
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||||
params.get("dataType") collect {
|
} getOrElse {
|
||||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
contentType = formats("json")
|
||||||
} getOrElse {
|
org.json4s.jackson.Serialization.write(
|
||||||
contentType = formats("json")
|
Map(
|
||||||
org.json4s.jackson.Serialization.write(
|
"content" -> view.Markdown.toHtml(
|
||||||
Map(
|
markdown = x.content,
|
||||||
"content" -> view.Markdown.toHtml(
|
repository = repository,
|
||||||
markdown = x.content,
|
branch = repository.repository.defaultBranch,
|
||||||
repository = repository,
|
enableWikiLink = false,
|
||||||
branch = repository.repository.defaultBranch,
|
enableRefsLink = true,
|
||||||
enableWikiLink = false,
|
enableAnchor = true,
|
||||||
enableRefsLink = true,
|
enableLineBreaks = true,
|
||||||
enableAnchor = true,
|
enableTaskList = true,
|
||||||
enableLineBreaks = true,
|
hasWritePermission = true
|
||||||
enableTaskList = true,
|
|
||||||
hasWritePermission = true
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
} else Unauthorized()
|
)
|
||||||
} getOrElse NotFound()
|
}
|
||||||
}
|
} else Unauthorized()
|
||||||
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/new/label")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/new/label")(writableUsersOnly { repository =>
|
||||||
@@ -322,15 +308,17 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
defining(params("id").toInt) { issueId =>
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
||||||
val issueId = params("id").toInt
|
defining(params("id").toInt) { issueId =>
|
||||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/assign")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/assign")(writableUsersOnly { repository =>
|
||||||
@@ -363,27 +351,23 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/state")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/state")(writableUsersOnly { repository =>
|
||||||
val action = params.get("value")
|
defining(params.get("value")) {
|
||||||
action match {
|
action =>
|
||||||
case Some("open") =>
|
action match {
|
||||||
executeBatch(repository) { issueId =>
|
case Some("open") =>
|
||||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
executeBatch(repository) { issueId =>
|
||||||
handleComment(issue, None, repository, Some("reopen"))
|
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||||
}
|
handleComment(issue, None, repository, Some("reopen"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case Some("close") =>
|
||||||
|
executeBatch(repository) { issueId =>
|
||||||
|
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||||
|
handleComment(issue, None, repository, Some("close"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _ => BadRequest()
|
||||||
}
|
}
|
||||||
if (params("uri").nonEmpty) {
|
|
||||||
redirect(params("uri"))
|
|
||||||
}
|
|
||||||
case Some("close") =>
|
|
||||||
executeBatch(repository) { issueId =>
|
|
||||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
|
||||||
handleComment(issue, None, repository, Some("close"))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (params("uri").nonEmpty) {
|
|
||||||
redirect(params("uri"))
|
|
||||||
}
|
|
||||||
case _ => BadRequest()
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -392,35 +376,32 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
executeBatch(repository) { issueId =>
|
executeBatch(repository) { issueId =>
|
||||||
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
||||||
if (params("uri").nonEmpty) {
|
|
||||||
redirect(params("uri"))
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/assign")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/assign")(writableUsersOnly { repository =>
|
||||||
val value = assignedUserName("value")
|
defining(assignedUserName("value")) { value =>
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||||
}
|
}
|
||||||
if (params("uri").nonEmpty) {
|
|
||||||
redirect(params("uri"))
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
||||||
val value = milestoneId("value")
|
defining(milestoneId("value")) { value =>
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
||||||
val value = priorityId("value")
|
defining(priorityId("value")) { value =>
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updatePriorityId(repository.owner, repository.name, _, value, true)
|
updatePriorityId(repository.owner, repository.name, _, value, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -435,29 +416,6 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
|
||||||
* JSON API for issue and PR completion.
|
|
||||||
*/
|
|
||||||
ajaxGet("/:owner/:repository/_issue/proposals")(writableUsersOnly { repository =>
|
|
||||||
contentType = formats("json")
|
|
||||||
org.json4s.jackson.Serialization.write(
|
|
||||||
Map(
|
|
||||||
"options" -> (
|
|
||||||
getOpenIssues(repository.owner, repository.name)
|
|
||||||
.map { t =>
|
|
||||||
Map(
|
|
||||||
"label" -> s"""${if (t.isPullRequest) "<i class='octicon octicon-git-pull-request'></i>"
|
|
||||||
else "<i class='octicon octicon-issue-opened'></i>"}<b> #${StringUtil
|
|
||||||
.escapeHtml(t.issueId.toString)} ${StringUtil
|
|
||||||
.escapeHtml(StringUtil.cutTail(t.title, 50, "..."))}</b>""",
|
|
||||||
"value" -> t.issueId.toString
|
|
||||||
)
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
||||||
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
@@ -467,56 +425,41 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
params("from") match {
|
params("from") match {
|
||||||
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||||
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
||||||
case _ =>
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
||||||
val page = IssueSearchCondition.page(request)
|
defining(repository.owner, repository.name) {
|
||||||
// retrieve search condition
|
case (owner, repoName) =>
|
||||||
val condition = IssueSearchCondition(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
// search issues
|
|
||||||
val issues =
|
|
||||||
searchIssue(
|
|
||||||
condition,
|
|
||||||
IssueSearchOption.Issues,
|
|
||||||
(page - 1) * IssueLimit,
|
|
||||||
IssueLimit,
|
|
||||||
repository.owner -> repository.name
|
|
||||||
)
|
|
||||||
|
|
||||||
html.list(
|
// retrieve search condition
|
||||||
"issues",
|
val condition = IssueSearchCondition(request)
|
||||||
issues.map(issue => (issue, None)),
|
|
||||||
page,
|
html.list(
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
"issues",
|
||||||
getMilestones(repository.owner, repository.name),
|
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, owner -> repoName),
|
||||||
getPriorities(repository.owner, repository.name),
|
page,
|
||||||
getLabels(repository.owner, repository.name),
|
getAssignableUserNames(owner, repoName),
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
getMilestones(owner, repoName),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
getPriorities(owner, repoName),
|
||||||
condition,
|
getLabels(owner, repoName),
|
||||||
repository,
|
countIssue(condition.copy(state = "open"), false, owner -> repoName),
|
||||||
isIssueEditable(repository),
|
countIssue(condition.copy(state = "closed"), false, owner -> repoName),
|
||||||
isIssueManageable(repository)
|
condition,
|
||||||
)
|
repository,
|
||||||
|
isIssueEditable(repository),
|
||||||
|
isIssueManageable(repository)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether an issue or a comment is editable by a logged-in user.
|
* Tests whether an issue or a comment is editable by a logged-in user.
|
||||||
*/
|
*/
|
||||||
private def isEditableContent(owner: String, repository: String, author: String, loginAccount: Account)(
|
private def isEditableContent(owner: String, repository: String, author: String)(
|
||||||
implicit context: Context
|
implicit context: Context
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Tests whether an issue comment is deletable by a logged-in user.
|
|
||||||
*/
|
|
||||||
private def isDeletableComment(owner: String, repository: String, author: String, loginAccount: Account)(
|
|
||||||
implicit context: Context
|
|
||||||
): Boolean = {
|
|
||||||
hasOwnerRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,18 +1,10 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.issues.milestones.html
|
import gitbucket.core.issues.milestones.html
|
||||||
import gitbucket.core.service.IssuesService.{IssueLimit, IssueSearchCondition}
|
import gitbucket.core.service.{AccountService, MilestonesService, RepositoryService}
|
||||||
import gitbucket.core.service.{
|
|
||||||
AccountService,
|
|
||||||
CommitStatusService,
|
|
||||||
IssueSearchOption,
|
|
||||||
MilestonesService,
|
|
||||||
RepositoryService
|
|
||||||
}
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.view.helpers.{getAssignableUserNames, getLabels, getPriorities, searchIssue}
|
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
@@ -21,16 +13,11 @@ class MilestonesController
|
|||||||
with MilestonesService
|
with MilestonesService
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
with AccountService
|
with AccountService
|
||||||
with CommitStatusService
|
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
|
|
||||||
trait MilestonesControllerBase extends ControllerBase {
|
trait MilestonesControllerBase extends ControllerBase {
|
||||||
self: MilestonesService
|
self: MilestonesService with RepositoryService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||||
with RepositoryService
|
|
||||||
with CommitStatusService
|
|
||||||
with ReferrerAuthenticator
|
|
||||||
with WritableUsersAuthenticator =>
|
|
||||||
|
|
||||||
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
||||||
|
|
||||||
@@ -49,41 +36,6 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/milestone/:id")(referrersOnly { repository =>
|
|
||||||
val milestone = getMilestone(repository.owner, repository.name, params("id").toInt)
|
|
||||||
val page = IssueSearchCondition.page(request)
|
|
||||||
val condition = IssueSearchCondition(
|
|
||||||
request,
|
|
||||||
milestone.get.title
|
|
||||||
)
|
|
||||||
val issues = searchIssue(
|
|
||||||
condition,
|
|
||||||
IssueSearchOption.Both,
|
|
||||||
(page - 1) * IssueLimit,
|
|
||||||
IssueLimit,
|
|
||||||
repository.owner -> repository.name
|
|
||||||
)
|
|
||||||
val status = issues.map { issue =>
|
|
||||||
issue.commitId.flatMap { commitId =>
|
|
||||||
getCommitStatusWithSummary(issue.issue.userName, issue.issue.repositoryName, commitId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
html.milestone(
|
|
||||||
condition.state,
|
|
||||||
issues.zip(status),
|
|
||||||
page,
|
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
|
||||||
getPriorities(repository.owner, repository.name),
|
|
||||||
getLabels(repository.owner, repository.name),
|
|
||||||
condition,
|
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
|
||||||
.filter(p => p._1.milestoneId == milestone.get.milestoneId),
|
|
||||||
repository,
|
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/:owner/:repository/issues/milestones/new")(writableUsersOnly {
|
get("/:owner/:repository/issues/milestones/new")(writableUsersOnly {
|
||||||
html.edit(None, _)
|
html.edit(None, _)
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -32,7 +32,6 @@ trait PreProcessControllerBase extends ControllerBase {
|
|||||||
get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||||
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||||
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
||||||
!context.currentPath.startsWith("/plugin-assets") &&
|
|
||||||
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
||||||
context.currentPath.startsWith(path)
|
context.currentPath.startsWith(path)
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@@ -1,6 +1,5 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.model.activity.DeleteBranchInfo
|
|
||||||
import gitbucket.core.pulls.html
|
import gitbucket.core.pulls.html
|
||||||
import gitbucket.core.service.CommitStatusService
|
import gitbucket.core.service.CommitStatusService
|
||||||
import gitbucket.core.service.MergeService
|
import gitbucket.core.service.MergeService
|
||||||
@@ -8,6 +7,7 @@ import gitbucket.core.service.IssuesService._
|
|||||||
import gitbucket.core.service.PullRequestService._
|
import gitbucket.core.service.PullRequestService._
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
@@ -36,7 +36,6 @@ class PullRequestsController
|
|||||||
with MergeService
|
with MergeService
|
||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait PullRequestsControllerBase extends ControllerBase {
|
trait PullRequestsControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -57,7 +56,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
with PrioritiesService =>
|
with PrioritiesService =>
|
||||||
|
|
||||||
val pullRequestForm = mapping(
|
val pullRequestForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required))),
|
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||||
"content" -> trim(label("Content", optional(text()))),
|
"content" -> trim(label("Content", optional(text()))),
|
||||||
"targetUserName" -> trim(text(required, maxlength(100))),
|
"targetUserName" -> trim(text(required, maxlength(100))),
|
||||||
"targetBranch" -> trim(text(required, maxlength(100))),
|
"targetBranch" -> trim(text(required, maxlength(100))),
|
||||||
@@ -110,29 +109,24 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
val owner = repository.owner
|
||||||
|
val name = repository.name
|
||||||
|
getPullRequest(owner, name, issueId) map {
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdFrom,
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdTo
|
|
||||||
)
|
|
||||||
|
|
||||||
html.conversation(
|
html.conversation(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
commits.flatten,
|
commits.flatten,
|
||||||
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
||||||
diffs.size,
|
diffs.size,
|
||||||
getIssueLabels(repository.owner, repository.name, issueId),
|
getIssueLabels(owner, name, issueId),
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
getAssignableUserNames(owner, name),
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name),
|
getMilestonesWithIssueCount(owner, name),
|
||||||
getPriorities(repository.owner, repository.name),
|
getPriorities(owner, name),
|
||||||
getLabels(repository.owner, repository.name),
|
getLabels(owner, name),
|
||||||
isEditable(repository),
|
isEditable(repository),
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
||||||
@@ -166,29 +160,18 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
val owner = repository.owner
|
||||||
|
val name = repository.name
|
||||||
|
getPullRequest(owner, name, issueId) map {
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdFrom,
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdTo
|
|
||||||
)
|
|
||||||
|
|
||||||
val commitsWithStatus = commits.map { day =>
|
|
||||||
day.map { commit =>
|
|
||||||
(commit, getCommitStatusWithSummary(repository.owner, repository.name, commit.id))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
html.commits(
|
html.commits(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
commitsWithStatus,
|
commits,
|
||||||
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
||||||
diffs.size,
|
diffs.size,
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
repository
|
repository
|
||||||
@@ -200,24 +183,19 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
val owner = repository.owner
|
||||||
|
val name = repository.name
|
||||||
|
getPullRequest(owner, name, issueId) map {
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(
|
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdFrom,
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pullreq.commitIdTo
|
|
||||||
)
|
|
||||||
|
|
||||||
html.files(
|
html.files(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
diffs,
|
diffs,
|
||||||
commits.flatten,
|
commits.flatten,
|
||||||
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
@@ -228,35 +206,39 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
getPullRequest(repository.owner, repository.name, issueId) map {
|
val owner = repository.owner
|
||||||
|
val name = repository.name
|
||||||
|
getPullRequest(owner, name, issueId) map {
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val conflictMessage = LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
val conflictMessage = LockUtil.lock(s"${owner}/${name}") {
|
||||||
checkConflict(repository.owner, repository.name, pullreq.branch, issueId)
|
checkConflict(owner, name, pullreq.branch, issueId)
|
||||||
}
|
}
|
||||||
val hasMergePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
val hasMergePermission = hasDeveloperRole(owner, name, context.loginAccount)
|
||||||
val branchProtection = getProtectedBranchInfo(repository.owner, repository.name, pullreq.branch)
|
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.branch)
|
||||||
val mergeStatus = PullRequestService.MergeStatus(
|
val mergeStatus = PullRequestService.MergeStatus(
|
||||||
conflictMessage = conflictMessage,
|
conflictMessage = conflictMessage,
|
||||||
commitStatuses = getCommitStatuses(repository.owner, repository.name, pullreq.commitIdTo),
|
commitStatues = getCommitStatues(owner, name, pullreq.commitIdTo),
|
||||||
branchProtection = branchProtection,
|
branchProtection = branchProtection,
|
||||||
branchIsOutOfDate = JGitUtil.getShaByRef(repository.owner, repository.name, pullreq.branch) != Some(
|
branchIsOutOfDate = JGitUtil.getShaByRef(owner, name, pullreq.branch) != Some(pullreq.commitIdFrom),
|
||||||
pullreq.commitIdFrom
|
needStatusCheck = context.loginAccount
|
||||||
),
|
.map { u =>
|
||||||
needStatusCheck = context.loginAccount.forall { u =>
|
branchProtection.needStatusCheck(u.userName)
|
||||||
branchProtection.needStatusCheck(u.userName)
|
}
|
||||||
},
|
.getOrElse(true),
|
||||||
hasUpdatePermission = hasDeveloperRole(
|
hasUpdatePermission = hasDeveloperRole(
|
||||||
pullreq.requestUserName,
|
pullreq.requestUserName,
|
||||||
pullreq.requestRepositoryName,
|
pullreq.requestRepositoryName,
|
||||||
context.loginAccount
|
context.loginAccount
|
||||||
) &&
|
) &&
|
||||||
context.loginAccount.exists { u =>
|
context.loginAccount
|
||||||
!getProtectedBranchInfo(
|
.map { u =>
|
||||||
pullreq.requestUserName,
|
!getProtectedBranchInfo(
|
||||||
pullreq.requestRepositoryName,
|
pullreq.requestUserName,
|
||||||
pullreq.requestBranch
|
pullreq.requestRepositoryName,
|
||||||
).needStatusCheck(u.userName)
|
pullreq.requestBranch
|
||||||
},
|
).needStatusCheck(u.userName)
|
||||||
|
}
|
||||||
|
.getOrElse(false),
|
||||||
hasMergePermission = hasMergePermission,
|
hasMergePermission = hasMergePermission,
|
||||||
commitIdTo = pullreq.commitIdTo
|
commitIdTo = pullreq.commitIdTo
|
||||||
)
|
)
|
||||||
@@ -289,8 +271,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val userName = context.loginAccount.get.userName
|
val userName = context.loginAccount.get.userName
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.branchDelete().setForce(true).setBranchNames(pullreq.requestBranch).call()
|
git.branchDelete().setForce(true).setBranchNames(pullreq.requestBranch).call()
|
||||||
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, pullreq.requestBranch)
|
recordDeleteBranchActivity(repository.owner, repository.name, userName, pullreq.requestBranch)
|
||||||
recordActivity(deleteBranchInfo)
|
|
||||||
}
|
}
|
||||||
createComment(
|
createComment(
|
||||||
baseRepository.owner,
|
baseRepository.owner,
|
||||||
@@ -373,22 +354,23 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount { loginAccount =>
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
params("id").toIntOpt.flatMap { issueId =>
|
val owner = repository.owner
|
||||||
mergePullRequest(
|
val name = repository.name
|
||||||
repository,
|
|
||||||
issueId,
|
mergePullRequest(
|
||||||
loginAccount,
|
repository,
|
||||||
form.message,
|
issueId,
|
||||||
form.strategy,
|
context.loginAccount.get,
|
||||||
form.isDraft,
|
form.message,
|
||||||
context.settings
|
form.strategy,
|
||||||
) match {
|
form.isDraft,
|
||||||
case Right(objectId) => redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
context.settings
|
||||||
case Left(message) => Some(BadRequest(message))
|
) match {
|
||||||
}
|
case Right(objectId) => redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||||
} getOrElse NotFound()
|
case Left(message) => Some(BadRequest(message))
|
||||||
}
|
}
|
||||||
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
||||||
@@ -490,7 +472,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
||||||
},
|
},
|
||||||
commits.flatten
|
commits.flatten
|
||||||
.flatMap(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false))
|
.map(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false))
|
||||||
|
.flatten
|
||||||
.toList,
|
.toList,
|
||||||
originId,
|
originId,
|
||||||
forkedId,
|
forkedId,
|
||||||
@@ -557,14 +540,15 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
defining(repository.owner, repository.name) {
|
||||||
loginAccount =>
|
case (owner, name) =>
|
||||||
val manageable = isManageable(repository)
|
val manageable = isManageable(repository)
|
||||||
|
val loginUserName = context.loginAccount.get.userName
|
||||||
|
|
||||||
val issueId = insertIssue(
|
val issueId = insertIssue(
|
||||||
owner = repository.owner,
|
owner = repository.owner,
|
||||||
repository = repository.name,
|
repository = repository.name,
|
||||||
loginUser = loginAccount.userName,
|
loginUser = loginUserName,
|
||||||
title = form.title,
|
title = form.title,
|
||||||
content = form.content,
|
content = form.content,
|
||||||
assignedUserName = if (manageable) form.assignedUserName else None,
|
assignedUserName = if (manageable) form.assignedUserName else None,
|
||||||
@@ -583,14 +567,14 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
commitIdFrom = form.commitIdFrom,
|
commitIdFrom = form.commitIdFrom,
|
||||||
commitIdTo = form.commitIdTo,
|
commitIdTo = form.commitIdTo,
|
||||||
isDraft = form.isDraft,
|
isDraft = form.isDraft,
|
||||||
loginAccount = loginAccount,
|
loginAccount = context.loginAccount.get,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
)
|
)
|
||||||
|
|
||||||
// insert labels
|
// insert labels
|
||||||
if (manageable) {
|
if (manageable) {
|
||||||
form.labelNames.foreach { value =>
|
form.labelNames.foreach { value =>
|
||||||
val labels = getLabels(repository.owner, repository.name)
|
val labels = getLabels(owner, name)
|
||||||
value.split(",").foreach { labelName =>
|
value.split(",").foreach { labelName =>
|
||||||
labels.find(_.labelName == labelName).map { label =>
|
labels.find(_.labelName == labelName).map { label =>
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
||||||
@@ -599,7 +583,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -646,41 +630,30 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
html.proposals(proposedBranches, targetRepository, repository)
|
html.proposals(proposedBranches, targetRepository, repository)
|
||||||
})
|
})
|
||||||
|
|
||||||
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) = {
|
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) =
|
||||||
val page = IssueSearchCondition.page(request)
|
defining(repository.owner, repository.name) {
|
||||||
// retrieve search condition
|
case (owner, repoName) =>
|
||||||
val condition = IssueSearchCondition(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
// search issues
|
|
||||||
val issues = searchIssue(
|
|
||||||
condition,
|
|
||||||
IssueSearchOption.PullRequests,
|
|
||||||
(page - 1) * PullRequestLimit,
|
|
||||||
PullRequestLimit,
|
|
||||||
repository.owner -> repository.name
|
|
||||||
)
|
|
||||||
// commit status
|
|
||||||
val status = issues.map { issue =>
|
|
||||||
issue.commitId.flatMap { commitId =>
|
|
||||||
getCommitStatusWithSummary(repository.owner, repository.name, commitId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
gitbucket.core.issues.html.list(
|
// retrieve search condition
|
||||||
"pulls",
|
val condition = IssueSearchCondition(request)
|
||||||
issues.zip(status),
|
|
||||||
page,
|
gitbucket.core.issues.html.list(
|
||||||
getAssignableUserNames(repository.owner, repository.name),
|
"pulls",
|
||||||
getMilestones(repository.owner, repository.name),
|
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, owner -> repoName),
|
||||||
getPriorities(repository.owner, repository.name),
|
page,
|
||||||
getLabels(repository.owner, repository.name),
|
getAssignableUserNames(owner, repoName),
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, repository.owner -> repository.name),
|
getMilestones(owner, repoName),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, repository.owner -> repository.name),
|
getPriorities(owner, repoName),
|
||||||
condition,
|
getLabels(owner, repoName),
|
||||||
repository,
|
countIssue(condition.copy(state = "open"), true, owner -> repoName),
|
||||||
isEditable(repository),
|
countIssue(condition.copy(state = "closed"), true, owner -> repoName),
|
||||||
isManageable(repository)
|
condition,
|
||||||
)
|
repository,
|
||||||
}
|
isEditable(repository),
|
||||||
|
isManageable(repository)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether an logged-in user can manage pull requests.
|
* Tests whether an logged-in user can manage pull requests.
|
||||||
|
|||||||
@@ -2,15 +2,7 @@ package gitbucket.core.controller
|
|||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import gitbucket.core.model.activity.ReleaseInfo
|
import gitbucket.core.service.{AccountService, ActivityService, PaginationHelper, ReleaseService, RepositoryService}
|
||||||
import gitbucket.core.service.{
|
|
||||||
AccountService,
|
|
||||||
ActivityService,
|
|
||||||
PaginationHelper,
|
|
||||||
ReleaseService,
|
|
||||||
RepositoryService,
|
|
||||||
RequestCache
|
|
||||||
}
|
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -30,7 +22,6 @@ class ReleaseController
|
|||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait ReleaseControllerBase extends ControllerBase {
|
trait ReleaseControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -63,8 +54,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/*")(referrersOnly { repository =>
|
get("/:owner/:repository/releases/:tag")(referrersOnly { repository =>
|
||||||
val tagName = multiParams("splat").head
|
val tagName = params("tag")
|
||||||
getRelease(repository.owner, repository.name, tagName)
|
getRelease(repository.owner, repository.name, tagName)
|
||||||
.map { release =>
|
.map { release =>
|
||||||
html.release(
|
html.release(
|
||||||
@@ -77,8 +68,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/*/assets/:fileId")(referrersOnly { repository =>
|
get("/:owner/:repository/releases/:tag/assets/:fileId")(referrersOnly { repository =>
|
||||||
val tagName = multiParams("splat").head
|
val tagName = params("tag")
|
||||||
val fileId = params("fileId")
|
val fileId = params("fileId")
|
||||||
(for {
|
(for {
|
||||||
_ <- repository.tags.find(_.name == tagName)
|
_ <- repository.tags.find(_.name == tagName)
|
||||||
@@ -93,8 +84,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
}).getOrElse(NotFound())
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/*/create")(writableUsersOnly { repository =>
|
get("/:owner/:repository/releases/:tag/create")(writableUsersOnly { repository =>
|
||||||
val tagName = multiParams("splat").head
|
val tagName = params("tag")
|
||||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||||
|
|
||||||
repository.tags
|
repository.tags
|
||||||
@@ -105,35 +96,32 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/*/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/releases/:tag/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
val tagName = params("tag")
|
||||||
loginAccount =>
|
val loginAccount = context.loginAccount.get
|
||||||
val tagName = multiParams("splat").head
|
|
||||||
|
|
||||||
// Insert into RELEASE
|
// Insert into RELEASE
|
||||||
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
||||||
|
|
||||||
// Insert into RELEASE_ASSET
|
// Insert into RELEASE_ASSET
|
||||||
val files = params.toMap.collect {
|
val files = params.toMap.collect {
|
||||||
case (name, value) if name.startsWith("file:") =>
|
case (name, value) if name.startsWith("file:") =>
|
||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
}
|
|
||||||
files.foreach {
|
|
||||||
case (fileId, fileName) =>
|
|
||||||
val size =
|
|
||||||
new File(
|
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
|
||||||
FileUtil.checkFilename(tagName + "/" + fileId)
|
|
||||||
).length
|
|
||||||
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
|
||||||
}
|
|
||||||
|
|
||||||
val releaseInfo = ReleaseInfo(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
|
||||||
recordActivity(releaseInfo)
|
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
|
||||||
}
|
}
|
||||||
|
files.foreach {
|
||||||
|
case (fileId, fileName) =>
|
||||||
|
val size =
|
||||||
|
new File(
|
||||||
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
|
FileUtil.checkFilename(tagName + "/" + fileId)
|
||||||
|
).length
|
||||||
|
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
||||||
|
}
|
||||||
|
|
||||||
|
recordReleaseActivity(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||||
|
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/changelog/*...*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/changelog/*...*")(writableUsersOnly { repository =>
|
||||||
@@ -152,8 +140,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
commitLog
|
commitLog
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/*/edit")(writableUsersOnly { repository =>
|
get("/:owner/:repository/releases/:tag/edit")(writableUsersOnly { repository =>
|
||||||
val tagName = multiParams("splat").head
|
val tagName = params("tag")
|
||||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||||
|
|
||||||
(for {
|
(for {
|
||||||
@@ -170,54 +158,52 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
}).getOrElse(NotFound())
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/*/edit", releaseForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/releases/:tag/edit", releaseForm)(writableUsersOnly {
|
||||||
context.withLoginAccount {
|
(form, repository) =>
|
||||||
loginAccount =>
|
val tagName = params("tag")
|
||||||
val tagName = multiParams("splat").head
|
val loginAccount = context.loginAccount.get
|
||||||
|
|
||||||
getRelease(repository.owner, repository.name, tagName)
|
getRelease(repository.owner, repository.name, tagName)
|
||||||
.map {
|
.map { release =>
|
||||||
release =>
|
// Update RELEASE
|
||||||
// Update RELEASE
|
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
||||||
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
|
||||||
|
|
||||||
// Delete and Insert RELEASE_ASSET
|
// Delete and Insert RELEASE_ASSET
|
||||||
val assets = getReleaseAssets(repository.owner, repository.name, tagName)
|
val assets = getReleaseAssets(repository.owner, repository.name, tagName)
|
||||||
deleteReleaseAssets(repository.owner, repository.name, tagName)
|
deleteReleaseAssets(repository.owner, repository.name, tagName)
|
||||||
|
|
||||||
val files = params.toMap.collect {
|
val files = params.toMap.collect {
|
||||||
case (name, value) if name.startsWith("file:") =>
|
case (name, value) if name.startsWith("file:") =>
|
||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
}
|
|
||||||
files.foreach {
|
|
||||||
case (fileId, fileName) =>
|
|
||||||
val size =
|
|
||||||
new File(
|
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
|
||||||
FileUtil.checkFilename(tagName + "/" + fileId)
|
|
||||||
).length
|
|
||||||
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
|
||||||
}
|
|
||||||
|
|
||||||
assets.foreach { asset =>
|
|
||||||
if (!files.exists { case (fileId, _) => fileId == asset.fileName }) {
|
|
||||||
val file = new File(
|
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
|
||||||
FileUtil.checkFilename(release.tag + "/" + asset.fileName)
|
|
||||||
)
|
|
||||||
FileUtils.forceDelete(file)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
|
||||||
}
|
}
|
||||||
.getOrElse(NotFound())
|
files.foreach {
|
||||||
}
|
case (fileId, fileName) =>
|
||||||
|
val size =
|
||||||
|
new File(
|
||||||
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
|
FileUtil.checkFilename(tagName + "/" + fileId)
|
||||||
|
).length
|
||||||
|
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
||||||
|
}
|
||||||
|
|
||||||
|
assets.foreach { asset =>
|
||||||
|
if (!files.exists { case (fileId, _) => fileId == asset.fileName }) {
|
||||||
|
val file = new File(
|
||||||
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
|
FileUtil.checkFilename(release.tag + "/" + asset.fileName)
|
||||||
|
)
|
||||||
|
FileUtils.forceDelete(file)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/*/delete")(writableUsersOnly { repository =>
|
post("/:owner/:repository/releases/:tag/delete")(writableUsersOnly { repository =>
|
||||||
val tagName = multiParams("splat").head
|
val tagName = params("tag")
|
||||||
getRelease(repository.owner, repository.name, tagName).foreach { release =>
|
getRelease(repository.owner, repository.name, tagName).foreach { release =>
|
||||||
FileUtils.deleteDirectory(
|
FileUtils.deleteDirectory(
|
||||||
new File(getReleaseFilesDir(repository.owner, repository.name), FileUtil.checkFilename(release.tag))
|
new File(getReleaseFilesDir(repository.owner, repository.name), FileUtil.checkFilename(release.tag))
|
||||||
@@ -228,6 +214,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
||||||
|
|
||||||
import gitbucket.core.service.ReleaseService._
|
import gitbucket.core.service.ReleaseService._
|
||||||
|
|
||||||
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import java.time.{LocalDateTime, ZoneOffset}
|
import java.time.{LocalDateTime, ZoneId, ZoneOffset}
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
import gitbucket.core.settings.html
|
import gitbucket.core.settings.html
|
||||||
@@ -13,7 +13,6 @@ import gitbucket.core.util.SyntaxSugars._
|
|||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.model.WebHookContentType
|
import gitbucket.core.model.WebHookContentType
|
||||||
import gitbucket.core.model.activity.RenameRepositoryInfo
|
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@@ -31,10 +30,8 @@ class RepositorySettingsController
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
with ActivityService
|
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait RepositorySettingsControllerBase extends ControllerBase {
|
trait RepositorySettingsControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -43,7 +40,6 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
with ActivityService
|
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator =>
|
with UsersAuthenticator =>
|
||||||
|
|
||||||
@@ -57,8 +53,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
externalWikiUrl: Option[String],
|
externalWikiUrl: Option[String],
|
||||||
allowFork: Boolean,
|
allowFork: Boolean,
|
||||||
mergeOptions: Seq[String],
|
mergeOptions: Seq[String],
|
||||||
defaultMergeOption: String,
|
defaultMergeOption: String
|
||||||
safeMode: Boolean
|
|
||||||
)
|
)
|
||||||
|
|
||||||
val optionsForm = mapping(
|
val optionsForm = mapping(
|
||||||
@@ -70,8 +65,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"externalWikiUrl" -> trim(label("External Wiki URL", optional(text(maxlength(200))))),
|
"externalWikiUrl" -> trim(label("External Wiki URL", optional(text(maxlength(200))))),
|
||||||
"allowFork" -> trim(label("Allow Forking", boolean())),
|
"allowFork" -> trim(label("Allow Forking", boolean())),
|
||||||
"mergeOptions" -> mergeOptions,
|
"mergeOptions" -> mergeOptions,
|
||||||
"defaultMergeOption" -> trim(label("Default merge strategy", text(required))),
|
"defaultMergeOption" -> trim(label("Default merge strategy", text(required)))
|
||||||
"safeMode" -> trim(label("XSS protection", boolean()))
|
|
||||||
)(OptionsForm.apply).verifying { form =>
|
)(OptionsForm.apply).verifying { form =>
|
||||||
if (!form.mergeOptions.contains(form.defaultMergeOption)) {
|
if (!form.mergeOptions.contains(form.defaultMergeOption)) {
|
||||||
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
||||||
@@ -103,7 +97,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"events" -> webhookEvents,
|
"events" -> webhookEvents,
|
||||||
"ctype" -> label("ctype", text()),
|
"ctype" -> label("ctype", text()),
|
||||||
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
||||||
)((url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
)(
|
||||||
|
(url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token)
|
||||||
|
)
|
||||||
|
|
||||||
// for rename repository
|
// for rename repository
|
||||||
case class RenameRepositoryForm(repositoryName: String)
|
case class RenameRepositoryForm(repositoryName: String)
|
||||||
@@ -152,8 +148,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
form.externalWikiUrl,
|
form.externalWikiUrl,
|
||||||
form.allowFork,
|
form.allowFork,
|
||||||
form.mergeOptions,
|
form.mergeOptions,
|
||||||
form.defaultMergeOption,
|
form.defaultMergeOption
|
||||||
form.safeMode
|
|
||||||
)
|
)
|
||||||
flash.update("info", "Repository settings has been updated.")
|
flash.update("info", "Repository settings has been updated.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||||
@@ -181,15 +176,14 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/** Branch protection for branch */
|
/** Branch protection for branch */
|
||||||
get("/:owner/:repository/settings/branches/*")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository =>
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
val branch = params("splat")
|
val branch = params("branch")
|
||||||
|
|
||||||
if (!repository.branchList.contains(branch)) {
|
if (!repository.branchList.contains(branch)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||||
} else {
|
} else {
|
||||||
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||||
val lastWeeks = getRecentStatusContexts(
|
val lastWeeks = getRecentStatuesContexts(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
Date.from(LocalDateTime.now.minusWeeks(1).toInstant(ZoneOffset.UTC))
|
Date.from(LocalDateTime.now.minusWeeks(1).toInstant(ZoneOffset.UTC))
|
||||||
@@ -231,13 +225,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the web hook edit page.
|
* Display the web hook edit page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/new")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks/new")(ownerOnly { repository =>
|
||||||
val webhook = RepositoryWebHook(
|
val webhook = RepositoryWebHook(repository.owner, repository.name, "", WebHookContentType.FORM, None)
|
||||||
userName = repository.owner,
|
|
||||||
repositoryName = repository.name,
|
|
||||||
url = "",
|
|
||||||
ctype = WebHookContentType.FORM,
|
|
||||||
token = None
|
|
||||||
)
|
|
||||||
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -263,10 +251,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Send the test request to registered web hook URLs.
|
* Send the test request to registered web hook URLs.
|
||||||
*/
|
*/
|
||||||
ajaxPost("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
ajaxPost("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
||||||
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] =
|
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] = h.map { h =>
|
||||||
h.map { h =>
|
Array(h.getName, h.getValue)
|
||||||
Array(h.getName, h.getValue)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
@@ -280,13 +267,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
val url = params("url")
|
val url = params("url")
|
||||||
val token = Some(params("token"))
|
val token = Some(params("token"))
|
||||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||||
val dummyWebHookInfo = RepositoryWebHook(
|
val dummyWebHookInfo = RepositoryWebHook(repository.owner, repository.name, url, ctype, token)
|
||||||
userName = repository.owner,
|
|
||||||
repositoryName = repository.name,
|
|
||||||
url = url,
|
|
||||||
ctype = ctype,
|
|
||||||
token = token
|
|
||||||
)
|
|
||||||
val dummyPayload = {
|
val dummyPayload = {
|
||||||
val ownerAccount = getAccountByUserName(repository.owner).get
|
val ownerAccount = getAccountByUserName(repository.owner).get
|
||||||
val commits =
|
val commits =
|
||||||
@@ -345,7 +326,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
.map(
|
.map(
|
||||||
res =>
|
res =>
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine.getStatusCode,
|
"status" -> res.getStatusLine(),
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity()),
|
||||||
"headers" -> _headers(res.getAllHeaders())
|
"headers" -> _headers(res.getAllHeaders())
|
||||||
)
|
)
|
||||||
@@ -388,62 +369,36 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Rename repository.
|
* Rename repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
if (context.settings.repositoryOperation.rename || context.loginAccount.get.isAdmin) {
|
||||||
loginAccount =>
|
if (repository.name != form.repositoryName) {
|
||||||
if (context.settings.repositoryOperation.rename || loginAccount.isAdmin) {
|
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
||||||
if (repository.name != form.repositoryName) {
|
}
|
||||||
// Update database and move git repository
|
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
} else Forbidden()
|
||||||
// Record activity log
|
|
||||||
val renameInfo = RenameRepositoryInfo(
|
|
||||||
repository.owner,
|
|
||||||
form.repositoryName,
|
|
||||||
loginAccount.userName,
|
|
||||||
repository.name
|
|
||||||
)
|
|
||||||
recordActivity(renameInfo)
|
|
||||||
}
|
|
||||||
redirect(s"/${repository.owner}/${form.repositoryName}")
|
|
||||||
} else Forbidden()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfer repository ownership.
|
* Transfer repository ownership.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
if (context.settings.repositoryOperation.transfer || context.loginAccount.get.isAdmin) {
|
||||||
loginAccount =>
|
// Change repository owner
|
||||||
if (context.settings.repositoryOperation.transfer || loginAccount.isAdmin) {
|
if (repository.owner != form.newOwner) {
|
||||||
// Change repository owner
|
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
||||||
if (repository.owner != form.newOwner) {
|
}
|
||||||
// Update database and move git repository
|
redirect(s"/${form.newOwner}/${repository.name}")
|
||||||
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
} else Forbidden()
|
||||||
// Record activity log
|
|
||||||
val renameInfo = RenameRepositoryInfo(
|
|
||||||
form.newOwner,
|
|
||||||
repository.name,
|
|
||||||
loginAccount.userName,
|
|
||||||
repository.owner
|
|
||||||
)
|
|
||||||
recordActivity(renameInfo)
|
|
||||||
}
|
|
||||||
redirect(s"/${form.newOwner}/${repository.name}")
|
|
||||||
} else Forbidden()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the repository.
|
* Delete the repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
||||||
context.withLoginAccount { loginAccount =>
|
if (context.settings.repositoryOperation.delete || context.loginAccount.get.isAdmin) {
|
||||||
if (context.settings.repositoryOperation.delete || loginAccount.isAdmin) {
|
// Delete the repository and related files
|
||||||
// Delete the repository and related files
|
deleteRepository(repository.repository)
|
||||||
deleteRepository(repository.repository)
|
redirect(s"/${repository.owner}")
|
||||||
redirect(s"/${repository.owner}")
|
} else Forbidden()
|
||||||
} else Forbidden()
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -480,34 +435,32 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Provides duplication check for web hook url.
|
* Provides duplication check for web hook url.
|
||||||
*/
|
*/
|
||||||
private def webHook(needExists: Boolean): Constraint =
|
private def webHook(needExists: Boolean): Constraint = new Constraint() {
|
||||||
new Constraint() {
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
||||||
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
Some(if (needExists) {
|
||||||
Some(if (needExists) {
|
"URL had not been registered yet."
|
||||||
"URL had not been registered yet."
|
|
||||||
} else {
|
|
||||||
"URL had been registered already."
|
|
||||||
})
|
|
||||||
} else {
|
} else {
|
||||||
None
|
"URL had been registered already."
|
||||||
}
|
})
|
||||||
}
|
} else {
|
||||||
|
None
|
||||||
private def webhookEvents =
|
|
||||||
new ValueType[Set[WebHook.Event]] {
|
|
||||||
def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Set[WebHook.Event] = {
|
|
||||||
WebHook.Event.values.flatMap { t =>
|
|
||||||
params.get(name + "." + t.name).map(_ => t)
|
|
||||||
}.toSet
|
|
||||||
}
|
}
|
||||||
def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] =
|
}
|
||||||
if (convert(name, params, messages).isEmpty) {
|
|
||||||
Seq(name -> messages("error.required").format(name))
|
private def webhookEvents = new ValueType[Set[WebHook.Event]] {
|
||||||
} else {
|
def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Set[WebHook.Event] = {
|
||||||
Nil
|
WebHook.Event.values.flatMap { t =>
|
||||||
}
|
params.get(name + "." + t.name).map(_ => t)
|
||||||
|
}.toSet
|
||||||
}
|
}
|
||||||
|
def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] =
|
||||||
|
if (convert(name, params, messages).isEmpty) {
|
||||||
|
Seq(name -> messages("error.required").format(name))
|
||||||
|
} else {
|
||||||
|
Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Provides Constraint to validate the collaborator name.
|
// * Provides Constraint to validate the collaborator name.
|
||||||
@@ -527,77 +480,70 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Duplicate check for the rename repository name.
|
* Duplicate check for the rename repository name.
|
||||||
*/
|
*/
|
||||||
private def renameRepositoryName: Constraint =
|
private def renameRepositoryName: Constraint = new Constraint() {
|
||||||
new Constraint() {
|
override def validate(
|
||||||
override def validate(
|
name: String,
|
||||||
name: String,
|
value: String,
|
||||||
value: String,
|
params: Map[String, Seq[String]],
|
||||||
params: Map[String, Seq[String]],
|
messages: Messages
|
||||||
messages: Messages
|
): Option[String] = {
|
||||||
): Option[String] = {
|
for {
|
||||||
for {
|
repoName <- params.optionValue("repository") if repoName != value
|
||||||
repoName <- params.optionValue("repository") if repoName != value
|
userName <- params.optionValue("owner")
|
||||||
userName <- params.optionValue("owner")
|
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
||||||
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
} yield {
|
||||||
} yield {
|
"Repository already exists."
|
||||||
"Repository already exists."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
private def featureOption: Constraint =
|
private def featureOption: Constraint = new Constraint() {
|
||||||
new Constraint() {
|
override def validate(
|
||||||
override def validate(
|
name: String,
|
||||||
name: String,
|
value: String,
|
||||||
value: String,
|
params: Map[String, Seq[String]],
|
||||||
params: Map[String, Seq[String]],
|
messages: Messages
|
||||||
messages: Messages
|
): Option[String] =
|
||||||
): Option[String] =
|
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
||||||
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Constraint to validate the repository transfer user.
|
* Provides Constraint to validate the repository transfer user.
|
||||||
*/
|
*/
|
||||||
private def transferUser: Constraint =
|
private def transferUser: Constraint = new Constraint() {
|
||||||
new Constraint() {
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
getAccountByUserName(value) match {
|
||||||
getAccountByUserName(value) match {
|
case None => Some("User does not exist.")
|
||||||
case None => Some("User does not exist.")
|
case Some(x) =>
|
||||||
case Some(x) =>
|
if (x.userName == params("owner")) {
|
||||||
if (x.userName == params("owner")) {
|
Some("This is current repository owner.")
|
||||||
Some("This is current repository owner.")
|
} else {
|
||||||
} else {
|
params.get("repository").flatMap { repositoryName =>
|
||||||
params.get("repository").flatMap { repositoryName =>
|
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
||||||
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
"User already has same repository."
|
||||||
"User already has same repository."
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def mergeOptions =
|
private def mergeOptions = new ValueType[Seq[String]] {
|
||||||
new ValueType[Seq[String]] {
|
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
||||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
params.getOrElse("mergeOptions", Nil)
|
||||||
params.getOrElse("mergeOptions", Nil)
|
}
|
||||||
}
|
override def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] = {
|
||||||
override def validate(
|
val mergeOptions = params.getOrElse("mergeOptions", Nil)
|
||||||
name: String,
|
if (mergeOptions.isEmpty) {
|
||||||
params: Map[String, Seq[String]],
|
Seq("mergeOptions" -> "At least one option must be enabled.")
|
||||||
messages: Messages
|
} else if (!mergeOptions.forall(x => Seq("merge-commit", "squash", "rebase").contains(x))) {
|
||||||
): Seq[(String, String)] = {
|
Seq("mergeOptions" -> "mergeOptions are invalid.")
|
||||||
val mergeOptions = params.getOrElse("mergeOptions", Nil)
|
} else {
|
||||||
if (mergeOptions.isEmpty) {
|
Nil
|
||||||
Seq("mergeOptions" -> "At least one option must be enabled.")
|
|
||||||
} else if (!mergeOptions.forall(x => Seq("merge-commit", "squash", "rebase").contains(x))) {
|
|
||||||
Seq("mergeOptions" -> "mergeOptions are invalid.")
|
|
||||||
} else {
|
|
||||||
Nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -9,6 +9,7 @@ import gitbucket.core.service.{AccountService, RepositoryService}
|
|||||||
import gitbucket.core.ssh.SshServer
|
import gitbucket.core.ssh.SshServer
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.apache.commons.mail.EmailException
|
import org.apache.commons.mail.EmailException
|
||||||
@@ -47,6 +48,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
)(RepositoryOperation.apply),
|
)(RepositoryOperation.apply),
|
||||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||||
"notification" -> trim(label("Notification", boolean())),
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
|
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
||||||
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
||||||
"ssh" -> mapping(
|
"ssh" -> mapping(
|
||||||
"enabled" -> trim(label("SSH access", boolean())),
|
"enabled" -> trim(label("SSH access", boolean())),
|
||||||
@@ -107,10 +109,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"timeout" -> trim(label("Timeout", long(required))),
|
"timeout" -> trim(label("Timeout", long(required))),
|
||||||
"largeMaxFileSize" -> trim(label("Max file size for large file", long(required))),
|
"largeMaxFileSize" -> trim(label("Max file size for large file", long(required))),
|
||||||
"largeTimeout" -> trim(label("Timeout for large file", long(required)))
|
"largeTimeout" -> trim(label("Timeout for large file", long(required)))
|
||||||
)(Upload.apply),
|
)(Upload.apply)
|
||||||
"repositoryViewer" -> mapping(
|
|
||||||
"maxFiles" -> trim(label("Max files", number(required)))
|
|
||||||
)(RepositoryViewerSettings.apply)
|
|
||||||
)(SystemSettings.apply).verifying { settings =>
|
)(SystemSettings.apply).verifying { settings =>
|
||||||
Vector(
|
Vector(
|
||||||
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
||||||
@@ -361,8 +360,8 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users")(adminOnly {
|
get("/admin/users")(adminOnly {
|
||||||
val includeRemoved = params.get("includeRemoved").exists(_.toBoolean)
|
val includeRemoved = params.get("includeRemoved").map(_.toBoolean).getOrElse(false)
|
||||||
val includeGroups = params.get("includeGroups").exists(_.toBoolean)
|
val includeGroups = params.get("includeGroups").map(_.toBoolean).getOrElse(false)
|
||||||
val users = getAllUsers(includeRemoved, includeGroups)
|
val users = getAllUsers(includeRemoved, includeGroups)
|
||||||
val members = users.collect {
|
val members = users.collect {
|
||||||
case account if (account.isGroupAccount) =>
|
case account if (account.isGroupAccount) =>
|
||||||
@@ -462,28 +461,31 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
||||||
val groupName = params("groupName")
|
defining(params("groupName")) { groupName =>
|
||||||
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
||||||
val groupName = params("groupName")
|
defining(
|
||||||
val members = form.members
|
params("groupName"),
|
||||||
.split(",")
|
form.members
|
||||||
.map {
|
.split(",")
|
||||||
_.split(":") match {
|
.map {
|
||||||
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
_.split(":") match {
|
||||||
|
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
.toList
|
||||||
.toList
|
) {
|
||||||
|
case (groupName, members) =>
|
||||||
|
getAccountByUserName(groupName, true).map {
|
||||||
|
account =>
|
||||||
|
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||||
|
|
||||||
getAccountByUserName(groupName, true).map {
|
if (form.isRemoved) {
|
||||||
account =>
|
// Remove from GROUP_MEMBER
|
||||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
updateGroupMembers(form.groupName, Nil)
|
||||||
|
|
||||||
if (form.isRemoved) {
|
|
||||||
// Remove from GROUP_MEMBER
|
|
||||||
updateGroupMembers(form.groupName, Nil)
|
|
||||||
// // Remove repositories
|
// // Remove repositories
|
||||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||||
// deleteRepository(groupName, repositoryName)
|
// deleteRepository(groupName, repositoryName)
|
||||||
@@ -491,9 +493,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
||||||
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
||||||
// }
|
// }
|
||||||
} else {
|
} else {
|
||||||
// Update GROUP_MEMBER
|
// Update GROUP_MEMBER
|
||||||
updateGroupMembers(form.groupName, members)
|
updateGroupMembers(form.groupName, members)
|
||||||
// // Update COLLABORATOR for group repositories
|
// // Update COLLABORATOR for group repositories
|
||||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||||
// removeCollaborators(form.groupName, repositoryName)
|
// removeCollaborators(form.groupName, repositoryName)
|
||||||
@@ -501,12 +503,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
// addCollaborator(form.groupName, repositoryName, userName)
|
// addCollaborator(form.groupName, repositoryName, userName)
|
||||||
// }
|
// }
|
||||||
// }
|
// }
|
||||||
}
|
}
|
||||||
|
|
||||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/data")(adminOnly {
|
get("/admin/data")(adminOnly {
|
||||||
@@ -554,11 +557,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
protected def disableByNotYourself(paramName: String): Constraint =
|
protected def disableByNotYourself(paramName: String): Constraint =
|
||||||
new Constraint() {
|
new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
for {
|
params.get(paramName).flatMap { userName =>
|
||||||
userName <- params.get(paramName)
|
if (userName == context.loginAccount.get.userName && params.get("removed") == Some("true"))
|
||||||
loginAccount <- context.loginAccount
|
Some("You can't disable your account yourself")
|
||||||
if userName == loginAccount.userName && params.get("removed") == Some("true")
|
else
|
||||||
} yield "You can't disable your account yourself"
|
None
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.model.WebHook
|
import gitbucket.core.model.WebHook
|
||||||
import gitbucket.core.model.activity.{CreateWikiPageInfo, DeleteWikiInfo, EditWikiPageInfo}
|
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||||
import gitbucket.core.wiki.html
|
import gitbucket.core.wiki.html
|
||||||
@@ -14,7 +13,6 @@ import gitbucket.core.util.Directory._
|
|||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
class WikiController
|
class WikiController
|
||||||
@@ -26,7 +24,6 @@ class WikiController
|
|||||||
with WebHookService
|
with WebHookService
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with RequestCache
|
|
||||||
|
|
||||||
trait WikiControllerBase extends ControllerBase {
|
trait WikiControllerBase extends ControllerBase {
|
||||||
self: WikiService
|
self: WikiService
|
||||||
@@ -136,38 +133,32 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
if (isEditable(repository)) {
|
||||||
loginAccount =>
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
if (isEditable(repository)) {
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
|
||||||
|
|
||||||
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, Some(pageName))) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, Some(pageName))) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
if (isEditable(repository)) {
|
||||||
loginAccount =>
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
if (isEditable(repository)) {
|
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
|
||||||
|
|
||||||
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, None)) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, None)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_edit")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_edit")(readableUsersOnly { repository =>
|
||||||
@@ -178,9 +169,9 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
if (isEditable(repository)) {
|
||||||
loginAccount =>
|
defining(context.loginAccount.get) {
|
||||||
if (isEditable(repository)) {
|
loginAccount =>
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -193,9 +184,13 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
).foreach {
|
).foreach {
|
||||||
commitId =>
|
commitId =>
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
val wikiEditInfo =
|
recordEditWikiPageActivity(
|
||||||
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
repository.owner,
|
||||||
recordActivity(wikiEditInfo)
|
repository.name,
|
||||||
|
loginAccount.userName,
|
||||||
|
form.pageName,
|
||||||
|
commitId
|
||||||
|
)
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
@@ -207,8 +202,8 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
}
|
||||||
}
|
} else Unauthorized()
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
||||||
@@ -218,9 +213,9 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||||
context.withLoginAccount {
|
if (isEditable(repository)) {
|
||||||
loginAccount =>
|
defining(context.loginAccount.get) {
|
||||||
if (isEditable(repository)) {
|
loginAccount =>
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -233,9 +228,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
).foreach {
|
).foreach {
|
||||||
commitId =>
|
commitId =>
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
val createWikiPageInfo =
|
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||||
CreateWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
|
||||||
recordActivity(createWikiPageInfo)
|
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
@@ -248,35 +241,28 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
}
|
||||||
}
|
} else Unauthorized()
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
if (isEditable(repository)) {
|
||||||
loginAccount =>
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
if (isEditable(repository)) {
|
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
|
||||||
deleteWikiPage(
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
pageName,
|
|
||||||
loginAccount.fullName,
|
|
||||||
loginAccount.mailAddress,
|
|
||||||
s"Destroyed ${pageName}"
|
|
||||||
)
|
|
||||||
val deleteWikiInfo = DeleteWikiInfo(
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
loginAccount.userName,
|
|
||||||
pageName
|
|
||||||
)
|
|
||||||
recordActivity(deleteWikiInfo)
|
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
defining(context.loginAccount.get) { loginAccount =>
|
||||||
} else Unauthorized()
|
deleteWikiPage(
|
||||||
}
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pageName,
|
||||||
|
loginAccount.fullName,
|
||||||
|
loginAccount.mailAddress,
|
||||||
|
s"Destroyed ${pageName}"
|
||||||
|
)
|
||||||
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
|
}
|
||||||
|
} else Unauthorized()
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
||||||
|
|||||||
@@ -1,13 +1,10 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiObject, ApiRef, CreateARef, JsonFormat, UpdateARef}
|
import gitbucket.core.api.{ApiObject, ApiRef, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.ReferrerAuthenticator
|
import gitbucket.core.util.ReferrerAuthenticator
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
|
||||||
import org.eclipse.jgit.lib.RefUpdate.Result
|
|
||||||
import org.scalatra.{BadRequest, NoContent, UnprocessableEntity}
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
@@ -20,7 +17,7 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* i. Get a reference
|
* i. Get a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference
|
* https://developer.github.com/v3/git/refs/#get-a-reference
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/git/ref/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/git/ref/*")(referrersOnly { repository =>
|
||||||
getRef()
|
getRef()
|
||||||
@@ -58,79 +55,21 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Get all references
|
* ii. Get all references
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#list-matching-references
|
* https://developer.github.com/v3/git/refs/#get-all-references
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Create a reference
|
* iii. Create a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
* https://developer.github.com/v3/git/refs/#create-a-reference
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { _ =>
|
|
||||||
extractFromJsonBody[CreateARef].map {
|
|
||||||
data =>
|
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
|
||||||
val ref = git.getRepository.findRef(data.ref)
|
|
||||||
if (ref == null) {
|
|
||||||
val update = git.getRepository.updateRef(data.ref)
|
|
||||||
update.setNewObjectId(ObjectId.fromString(data.sha))
|
|
||||||
val result = update.update()
|
|
||||||
result match {
|
|
||||||
case Result.NEW => JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
|
||||||
case _ => UnprocessableEntity(result.name())
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
UnprocessableEntity("Ref already exists.")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} getOrElse BadRequest()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iv. Update a reference
|
* iv. Update a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
|
* https://developer.github.com/v3/git/refs/#update-a-reference
|
||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { _ =>
|
|
||||||
val refName = multiParams("splat").mkString("/")
|
|
||||||
extractFromJsonBody[UpdateARef].map {
|
|
||||||
data =>
|
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
|
||||||
val ref = git.getRepository.findRef(refName)
|
|
||||||
if (ref == null) {
|
|
||||||
UnprocessableEntity("Ref does not exist.")
|
|
||||||
} else {
|
|
||||||
val update = git.getRepository.updateRef(ref.getName)
|
|
||||||
update.setNewObjectId(ObjectId.fromString(data.sha))
|
|
||||||
update.setForceUpdate(data.force)
|
|
||||||
val result = update.update()
|
|
||||||
result match {
|
|
||||||
case Result.FORCED | Result.FAST_FORWARD | Result.NO_CHANGE =>
|
|
||||||
JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
|
||||||
case _ => UnprocessableEntity(result.name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} getOrElse BadRequest()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Delete a reference
|
* v. Delete a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#delete-a-reference
|
* https://developer.github.com/v3/git/refs/#delete-a-reference
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { _ =>
|
|
||||||
val refName = multiParams("splat").mkString("/")
|
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
|
||||||
val ref = git.getRepository.findRef(refName)
|
|
||||||
if (ref == null) {
|
|
||||||
UnprocessableEntity("Ref does not exist.")
|
|
||||||
} else {
|
|
||||||
val update = git.getRepository.updateRef(ref.getName)
|
|
||||||
update.setForceUpdate(true)
|
|
||||||
val result = update.delete()
|
|
||||||
result match {
|
|
||||||
case Result.FORCED => NoContent()
|
|
||||||
case _ => UnprocessableEntity(result.name())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import gitbucket.core.controller.{Context, ControllerBase}
|
|||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
||||||
import org.scalatra.ActionResult
|
|
||||||
|
|
||||||
trait ApiIssueCommentControllerBase extends ControllerBase {
|
trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
@@ -15,8 +14,8 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator =>
|
with ReferrerAuthenticator =>
|
||||||
/*
|
/*
|
||||||
* i. List issue comments for a repository
|
* i. List comments on an issue
|
||||||
* https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
|
* https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -31,90 +30,18 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Get an issue comment
|
* ii. List comments in a repository
|
||||||
* https://docs.github.com/en/rest/reference/issues#get-an-issue-comment
|
* https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/issues/comments/:id")(referrersOnly { repository =>
|
|
||||||
val commentId = params("id").toInt
|
|
||||||
getCommentForApi(repository.owner, repository.name, commentId) match {
|
|
||||||
case Some((issueComment, user, issue)) =>
|
|
||||||
JsonFormat(
|
|
||||||
ApiComment(issueComment, RepositoryName(repository), issue.issueId, ApiUser(user), issue.isPullRequest)
|
|
||||||
)
|
|
||||||
case _ => NotFound()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iii. Update an issue comment
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#update-an-issue-comment
|
|
||||||
*/
|
|
||||||
patch("/api/v3/repos/:owner/:repository/issues/comments/:id")(readableUsersOnly { repository =>
|
|
||||||
val commentId = params("id")
|
|
||||||
val result = for {
|
|
||||||
issueComment <- getComment(repository.owner, repository.name, commentId)
|
|
||||||
issue <- getIssue(repository.owner, repository.name, issueComment.issueId.toString)
|
|
||||||
} yield {
|
|
||||||
if (isEditable(repository.owner, repository.name, issueComment.commentedUserName)) {
|
|
||||||
val body = extractFromJsonBody[CreateAComment].map(_.body)
|
|
||||||
updateCommentByApi(repository, issue, issueComment.commentId.toString, body)
|
|
||||||
getComment(repository.owner, repository.name, commentId) match {
|
|
||||||
case Some(issueComment) =>
|
|
||||||
JsonFormat(
|
|
||||||
ApiComment(
|
|
||||||
issueComment,
|
|
||||||
RepositoryName(repository),
|
|
||||||
issue.issueId,
|
|
||||||
ApiUser(context.loginAccount.get),
|
|
||||||
issue.isPullRequest
|
|
||||||
)
|
|
||||||
)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
Unauthorized()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result match {
|
|
||||||
case Some(response) => response
|
|
||||||
case None => NotFound()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iv. Delete a comment
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#delete-an-issue-comment
|
|
||||||
*/
|
|
||||||
delete("/api/v3/repos/:owner/:repo/issues/comments/:id")(readableUsersOnly { repository =>
|
|
||||||
val maybeDeleteResponse: Option[Either[ActionResult, Option[Int]]] =
|
|
||||||
for {
|
|
||||||
commentId <- params("id").toIntOpt
|
|
||||||
comment <- getComment(repository.owner, repository.name, commentId.toString)
|
|
||||||
issue <- getIssue(repository.owner, repository.name, comment.issueId.toString)
|
|
||||||
} yield {
|
|
||||||
if (isEditable(repository.owner, repository.name, comment.commentedUserName)) {
|
|
||||||
val maybeDeletedComment = deleteCommentByApi(repository, comment, issue)
|
|
||||||
Right(maybeDeletedComment.map(_.commentId))
|
|
||||||
} else {
|
|
||||||
Left(Unauthorized())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
maybeDeleteResponse
|
|
||||||
.map {
|
|
||||||
case Right(maybeDeletedCommentId) => maybeDeletedCommentId.getOrElse(NotFound())
|
|
||||||
case Left(err) => err
|
|
||||||
}
|
|
||||||
.getOrElse(NotFound())
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* v. List issue comments
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#list-issue-comments
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Create an issue comment
|
* iii. Get a single comment
|
||||||
* https://docs.github.com/en/rest/reference/issues#create-an-issue-comment
|
* https://developer.github.com/v3/issues/comments/#get-a-single-comment
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iv. Create a comment
|
||||||
|
* https://developer.github.com/v3/issues/comments/#create-a-comment
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/issues/:id/comments")(readableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/issues/:id/comments")(readableUsersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -137,6 +64,16 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. Edit a comment
|
||||||
|
* https://developer.github.com/v3/issues/comments/#edit-a-comment
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vi. Delete a comment
|
||||||
|
* https://developer.github.com/v3/issues/comments/#delete-a-comment
|
||||||
|
*/
|
||||||
|
|
||||||
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import gitbucket.core.model.{Account, Issue}
|
|||||||
import gitbucket.core.service.{AccountService, IssueCreationService, IssuesService, MilestonesService}
|
import gitbucket.core.service.{AccountService, IssueCreationService, IssuesService, MilestonesService}
|
||||||
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
||||||
import gitbucket.core.service.PullRequestService.PullRequestLimit
|
import gitbucket.core.service.PullRequestService.PullRequestLimit
|
||||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName, UsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
|
||||||
trait ApiIssueControllerBase extends ControllerBase {
|
trait ApiIssueControllerBase extends ControllerBase {
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[Seq[String]]
|
data <- extractFromJsonBody[Seq[String]];
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
} yield {
|
} yield {
|
||||||
data.map { labelName =>
|
data.map { labelName =>
|
||||||
@@ -160,7 +160,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[Seq[String]]
|
data <- extractFromJsonBody[Seq[String]];
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
} yield {
|
} yield {
|
||||||
deleteAllIssueLabels(repository.owner, repository.name, issueId, true)
|
deleteAllIssueLabels(repository.owner, repository.name, issueId, true)
|
||||||
|
|||||||
@@ -1,118 +0,0 @@
|
|||||||
package gitbucket.core.controller.api
|
|
||||||
import gitbucket.core.api._
|
|
||||||
import gitbucket.core.controller.ControllerBase
|
|
||||||
import gitbucket.core.service.MilestonesService
|
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
|
||||||
import gitbucket.core.util.Implicits._
|
|
||||||
import org.scalatra.NoContent
|
|
||||||
|
|
||||||
trait ApiIssueMilestoneControllerBase extends ControllerBase {
|
|
||||||
self: MilestonesService with WritableUsersAuthenticator with ReferrerAuthenticator =>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* i. List milestones
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#list-milestones
|
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/milestones")(referrersOnly { repository =>
|
|
||||||
val state = params.getOrElse("state", "all")
|
|
||||||
// TODO "sort", "direction" params should be implemented.
|
|
||||||
val apiMilestones = (for (milestoneWithIssue <- getMilestonesWithIssueCount(repository.owner, repository.name)
|
|
||||||
.sortBy(p => p._1.milestoneId))
|
|
||||||
yield {
|
|
||||||
ApiMilestone(
|
|
||||||
repository.repository,
|
|
||||||
milestoneWithIssue._1,
|
|
||||||
milestoneWithIssue._2,
|
|
||||||
milestoneWithIssue._3
|
|
||||||
)
|
|
||||||
}).reverse
|
|
||||||
state match {
|
|
||||||
case "all" => JsonFormat(apiMilestones)
|
|
||||||
case "open" | "closed" =>
|
|
||||||
JsonFormat(
|
|
||||||
apiMilestones.filter(p => p.state == state)
|
|
||||||
)
|
|
||||||
case _ => NotFound()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ii. Create a milestone
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#create-a-milestone
|
|
||||||
*/
|
|
||||||
post("/api/v3/repos/:owner/:repository/milestones")(writableUsersOnly { repository =>
|
|
||||||
(for {
|
|
||||||
data <- extractFromJsonBody[CreateAMilestone] if data.isValid
|
|
||||||
milestoneId = createMilestone(
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
data.title,
|
|
||||||
data.description,
|
|
||||||
data.due_on
|
|
||||||
)
|
|
||||||
apiMilestone <- getApiMilestone(repository, milestoneId)
|
|
||||||
} yield {
|
|
||||||
JsonFormat(apiMilestone)
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iii. Get a milestone
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#get-a-milestone
|
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/milestones/:number")(referrersOnly { repository =>
|
|
||||||
val milestoneId = params("number").toInt // use milestoneId as number
|
|
||||||
(for (apiMilestone <- getApiMilestone(repository, milestoneId)) yield {
|
|
||||||
JsonFormat(apiMilestone)
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iv.Update a milestone
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#update-a-milestone
|
|
||||||
*/
|
|
||||||
patch("/api/v3/repos/:owner/:repository/milestones/:number")(writableUsersOnly { repository =>
|
|
||||||
val milestoneId = params("number").toInt
|
|
||||||
(for {
|
|
||||||
data <- extractFromJsonBody[CreateAMilestone] if data.isValid
|
|
||||||
milestone <- getMilestone(repository.owner, repository.name, milestoneId)
|
|
||||||
_ = (data.state, milestone.closedDate) match {
|
|
||||||
case ("open", Some(_)) =>
|
|
||||||
openMilestone(milestone)
|
|
||||||
case ("closed", None) =>
|
|
||||||
closeMilestone(milestone)
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
milestone <- getMilestone(repository.owner, repository.name, milestoneId)
|
|
||||||
_ = updateMilestone(milestone.copy(title = data.title, description = data.description, dueDate = data.due_on))
|
|
||||||
apiMilestone <- getApiMilestone(repository, milestoneId)
|
|
||||||
} yield {
|
|
||||||
JsonFormat(apiMilestone)
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* v. Delete a milestone
|
|
||||||
* https://docs.github.com/en/rest/reference/issues#delete-a-milestone
|
|
||||||
*/
|
|
||||||
delete("/api/v3/repos/:owner/:repository/milestones/:number")(writableUsersOnly { repository =>
|
|
||||||
val milestoneId = params("number").toInt // use milestoneId as number
|
|
||||||
deleteMilestone(repository.owner, repository.name, milestoneId)
|
|
||||||
NoContent()
|
|
||||||
})
|
|
||||||
|
|
||||||
private def getApiMilestone(repository: RepositoryInfo, milestoneId: Int): Option[ApiMilestone] = {
|
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
|
||||||
.find(p => p._1.milestoneId == milestoneId)
|
|
||||||
.map(
|
|
||||||
milestoneWithIssue =>
|
|
||||||
ApiMilestone(
|
|
||||||
repository.repository,
|
|
||||||
milestoneWithIssue._1,
|
|
||||||
milestoneWithIssue._2,
|
|
||||||
milestoneWithIssue._3
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiGroup, CreateAGroup, JsonFormat}
|
import gitbucket.core.api.{ApiGroup, CreateAGroup, ApiRepository, ApiUser, JsonFormat}
|
||||||
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.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import gitbucket.core.util.Implicits._
|
|||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.{Conflict, MethodNotAllowed, NoContent, Ok}
|
import org.scalatra.NoContent
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
@@ -161,28 +161,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Update a pull request
|
* v. Update a pull request
|
||||||
* https://docs.github.com/en/rest/reference/pulls#update-a-pull-request
|
* https://developer.github.com/v3/pulls/#update-a-pull-request
|
||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/pulls/:id")(referrersOnly { repository =>
|
|
||||||
(for {
|
|
||||||
issueId <- params("id").toIntOpt
|
|
||||||
account <- context.loginAccount
|
|
||||||
settings = context.settings
|
|
||||||
data <- extractFromJsonBody[UpdateAPullRequest]
|
|
||||||
} yield {
|
|
||||||
updatePullRequestsByApi(
|
|
||||||
repository,
|
|
||||||
issueId,
|
|
||||||
account,
|
|
||||||
settings,
|
|
||||||
data.title,
|
|
||||||
data.body,
|
|
||||||
data.state,
|
|
||||||
data.base
|
|
||||||
)
|
|
||||||
JsonFormat(getApiPullRequest(repository, issueId))
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. List commits on a pull request
|
* vi. List commits on a pull request
|
||||||
@@ -230,79 +210,15 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
||||||
NoContent
|
NoContent
|
||||||
} else {
|
} else {
|
||||||
NotFound()
|
NotFound
|
||||||
}
|
}
|
||||||
}).getOrElse(NotFound())
|
}).getOrElse(NotFound)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. Merge a pull request (Merge Button)
|
* ix. Merge a pull request (Merge Button)
|
||||||
* https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request
|
* https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
|
||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/pulls/:id/merge")(referrersOnly { repository =>
|
|
||||||
(for {
|
|
||||||
//TODO: crash when body is empty
|
|
||||||
//TODO: Implement sha parameter
|
|
||||||
data <- extractFromJsonBody[MergeAPullRequest]
|
|
||||||
issueId <- params("id").toIntOpt
|
|
||||||
(issue, pullReq) <- getPullRequest(repository.owner, repository.name, issueId)
|
|
||||||
} yield {
|
|
||||||
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
|
||||||
Conflict(
|
|
||||||
JsonFormat(
|
|
||||||
FailToMergePrResponse(
|
|
||||||
message = "Head branch was modified. Review and try the merge again.",
|
|
||||||
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
if (issue.closed) {
|
|
||||||
MethodNotAllowed(
|
|
||||||
JsonFormat(
|
|
||||||
FailToMergePrResponse(
|
|
||||||
message = "Pull Request is not mergeable, Closed",
|
|
||||||
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val strategy =
|
|
||||||
if (data.merge_method.getOrElse("merge-commit") == "merge") "merge-commit"
|
|
||||||
else data.merge_method.getOrElse("merge-commit")
|
|
||||||
mergePullRequest(
|
|
||||||
repository,
|
|
||||||
issueId,
|
|
||||||
context.loginAccount.get,
|
|
||||||
data.commit_message.getOrElse(""), //TODO: Implement commit_title
|
|
||||||
strategy,
|
|
||||||
pullReq.isDraft,
|
|
||||||
context.settings
|
|
||||||
) match {
|
|
||||||
case Right(objectId) =>
|
|
||||||
Ok(
|
|
||||||
JsonFormat(
|
|
||||||
SuccessToMergePrResponse(
|
|
||||||
sha = objectId.toString,
|
|
||||||
merged = true,
|
|
||||||
message = "Pull Request successfully merged"
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
case Left(message) =>
|
|
||||||
MethodNotAllowed(
|
|
||||||
JsonFormat(
|
|
||||||
FailToMergePrResponse(
|
|
||||||
message = "Pull Request is not mergeable",
|
|
||||||
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
|
||||||
)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. Labels, assignees, and milestones
|
* x. Labels, assignees, and milestones
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import java.io.File
|
import java.io.{ByteArrayInputStream, File}
|
||||||
|
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
@@ -7,8 +7,9 @@ import gitbucket.core.service.{AccountService, ReleaseService}
|
|||||||
import gitbucket.core.util.Directory.getReleaseFilesDir
|
import gitbucket.core.util.Directory.getReleaseFilesDir
|
||||||
import gitbucket.core.util.{FileUtil, ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
import gitbucket.core.util.{FileUtil, ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.SyntaxSugars.defining
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.scalatra.NoContent
|
import org.scalatra.{Created, NoContent}
|
||||||
|
|
||||||
trait ApiReleaseControllerBase extends ControllerBase {
|
trait ApiReleaseControllerBase extends ControllerBase {
|
||||||
self: AccountService with ReleaseService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
self: AccountService with ReleaseService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||||
@@ -86,7 +87,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* vi. Edit a release
|
* vi. Edit a release
|
||||||
* https://developer.github.com/v3/repos/releases/#edit-a-release
|
* https://developer.github.com/v3/repos/releases/#edit-a-release
|
||||||
* Incompatibility info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
* Incompatiblity info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
patch("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -103,7 +104,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* vii. Delete a release
|
* vii. Delete a release
|
||||||
* https://developer.github.com/v3/repos/releases/#delete-a-release
|
* https://developer.github.com/v3/repos/releases/#delete-a-release
|
||||||
* Incompatibility info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
* Incompatiblity info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
delete("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
||||||
val tag = params("tag")
|
val tag = params("tag")
|
||||||
@@ -119,40 +120,41 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
* ix. Upload a release asset
|
* ix. Upload a release asset
|
||||||
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly {
|
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly { repository =>
|
||||||
repository =>
|
val name = params("name")
|
||||||
val name = params("name")
|
val tag = params("tag")
|
||||||
val tag = params("tag")
|
getRelease(repository.owner, repository.name, tag)
|
||||||
getRelease(repository.owner, repository.name, tag)
|
.map {
|
||||||
.map { release =>
|
release =>
|
||||||
val fileId = FileUtil.generateFileId
|
defining(FileUtil.generateFileId) { fileId =>
|
||||||
val buf = new Array[Byte](request.inputStream.available())
|
val buf = new Array[Byte](request.inputStream.available())
|
||||||
request.inputStream.read(buf)
|
request.inputStream.read(buf)
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
new File(
|
new File(
|
||||||
getReleaseFilesDir(repository.owner, repository.name),
|
getReleaseFilesDir(repository.owner, repository.name),
|
||||||
FileUtil.checkFilename(tag + "/" + fileId)
|
FileUtil.checkFilename(tag + "/" + fileId)
|
||||||
),
|
),
|
||||||
buf
|
buf
|
||||||
)
|
)
|
||||||
createReleaseAsset(
|
createReleaseAsset(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
tag,
|
tag,
|
||||||
fileId,
|
fileId,
|
||||||
name,
|
name,
|
||||||
request.contentLength.getOrElse(0),
|
request.contentLength.getOrElse(0),
|
||||||
context.loginAccount.get
|
context.loginAccount.get
|
||||||
)
|
)
|
||||||
getReleaseAsset(repository.owner, repository.name, tag, fileId)
|
getReleaseAsset(repository.owner, repository.name, tag, fileId)
|
||||||
.map { asset =>
|
.map { asset =>
|
||||||
JsonFormat(ApiReleaseAsset(asset, RepositoryName(repository)))
|
JsonFormat(ApiReleaseAsset(asset, RepositoryName(repository)))
|
||||||
}
|
}
|
||||||
.getOrElse {
|
.getOrElse {
|
||||||
ApiError("Unknown error")
|
ApiError("Unknown error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.getOrElse(NotFound())
|
}
|
||||||
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -7,8 +7,6 @@ import gitbucket.core.util.Directory._
|
|||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.JGitUtil.getBranches
|
import gitbucket.core.util.JGitUtil.getBranches
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.NoContent
|
|
||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
||||||
@@ -24,7 +22,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* i. List branches
|
* i. List branches
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-branches
|
* https://developer.github.com/v3/repos/branches/#list-branches
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/branches")(referrersOnly { repository =>
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
@@ -43,8 +41,8 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get a branch
|
* ii. Get branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-a-branch
|
* https://developer.github.com/v3/repos/branches/#get-branch
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
@@ -67,206 +65,147 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Get branch protection
|
* iii. Get branch protection
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-branch-protection
|
* https://developer.github.com/v3/repos/branches/#get-branch-protection
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches/:branch/protection")(referrersOnly { repository =>
|
|
||||||
val branch = params("branch")
|
|
||||||
if (repository.branchList.contains(branch)) {
|
|
||||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
|
||||||
JsonFormat(
|
|
||||||
ApiBranchProtection(protection)
|
|
||||||
)
|
|
||||||
} else { NotFound() }
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iv. Update branch protection
|
* iv. Update branch protection
|
||||||
* https://docs.github.com/en/rest/reference/repos#update-branch-protection
|
* https://developer.github.com/v3/repos/branches/#update-branch-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Delete branch protection
|
* v. Remove branch protection
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-branch-protection
|
* https://developer.github.com/v3/repos/branches/#remove-branch-protection
|
||||||
*/
|
|
||||||
delete("/api/v3/repos/:owner/:repository/branches/:branch/protection")(writableUsersOnly { repository =>
|
|
||||||
val branch = params("branch")
|
|
||||||
if (repository.branchList.contains(branch)) {
|
|
||||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
|
||||||
if (protection.enabled) {
|
|
||||||
disableBranchProtection(repository.owner, repository.name, branch)
|
|
||||||
NoContent()
|
|
||||||
} else NotFound()
|
|
||||||
} else NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vi. Get admin branch protection
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-admin-branch-protection
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vii. Set admin branch protection
|
* vi. Get required status checks of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#set-admin-branch-protection
|
* https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* viii. Delete admin branch protection
|
* vii. Update required status checks of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-admin-branch-protection
|
* https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. Get pull request review protection
|
* viii. Remove required status checks of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-pull-request-review-protection
|
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. Update pull request review protection
|
* ix. List required status checks contexts of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#update-pull-request-review-protection
|
* https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xi. Delete pull request review protection
|
* x. Replace required status checks contexts of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-pull-request-review-protection
|
* https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xii. Get commit signature protection
|
* xi. Add required status checks contexts of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-commit-signature-protection
|
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiii. Create commit signature protection
|
* xii. Remove required status checks contexts of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-commit-signature-protection
|
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiv. Delete commit signature protection
|
* xiii. Get pull request review enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-commit-signature-protection
|
* https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xv. Get status checks protection
|
* xiv. Update pull request review enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-status-checks-protection
|
* https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/branches/:branch/protection/required_status_checks")(referrersOnly {
|
|
||||||
repository =>
|
|
||||||
val branch = params("branch")
|
|
||||||
if (repository.branchList.contains(branch)) {
|
|
||||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
|
||||||
JsonFormat(
|
|
||||||
ApiBranchProtection(protection).required_status_checks
|
|
||||||
)
|
|
||||||
} else { NotFound() }
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* xvi. Update status check protection
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#update-status-check-protection
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xvii. Remove status check protection
|
* xv. Remove pull request review enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#remove-status-check-protection
|
* https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xviii. Get all status check contexts
|
* xvi. Get required signatures of protected branch
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-all-status-check-contexts
|
* https://developer.github.com/v3/repos/branches/#get-required-signatures-of-protected-branch
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/branches/:branch/protection/required_status_checks/contexts")(referrersOnly {
|
|
||||||
repository =>
|
|
||||||
val branch = params("branch")
|
|
||||||
if (repository.branchList.contains(branch)) {
|
|
||||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
|
||||||
if (protection.enabled) {
|
|
||||||
protection.contexts.toList
|
|
||||||
} else NotFound()
|
|
||||||
} else NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* xix. Add status check contexts
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#add-status-check-contexts
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xx. Set status check contexts
|
* xvii. Add required signatures of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#set-status-check-contexts
|
* https://developer.github.com/v3/repos/branches/#add-required-signatures-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxi. Remove status check contexts
|
* xviii. Remove required signatures of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#remove-status-check-contexts
|
* https://developer.github.com/v3/repos/branches/#remove-required-signatures-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxii. Get access restrictions
|
* xix. Get admin enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxiii. Delete access restrictions
|
* xx. Add admin enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxiv. Get apps with access to the protected branch
|
* xxi. Remove admin enforcement of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-apps-with-access-to-the-protected-branch
|
* https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxv. Add app access restrictions
|
* xxii. Get restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#add-app-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxvi. Set app access restrictions
|
* xxiii. Remove restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#set-app-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxvii. Remove app access restrictions
|
* xxiv. List team restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#remove-app-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxviii. Get teams with access to the protected branch
|
* xxv. Replace team restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-teams-with-access-to-the-protected-branch
|
* https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxix. Add team access restrictions
|
* xxvi. Add team restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#add-team-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxx. Set team access restrictions
|
* xxvii. Remove team restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#set-team-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxxi. Remove team access restrictions
|
* xxviii. List user restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#remove-team-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxxii. Get users with access to the protected branch
|
* xxix. Replace user restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-users-with-access-to-the-protected-branch
|
* https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxxiii. Add user access restrictions
|
* xxx. Add user restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#add-user-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxxiv. Set user access restrictions
|
* xxxi. Remove user restrictions of protected branch
|
||||||
* https://docs.github.com/en/rest/reference/repos#set-user-access-restrictions
|
* https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* xxxv. Remove user access restrictions
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#remove-user-access-restrictions
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{AddACollaborator, ApiRepositoryCollaborator, ApiUser, JsonFormat}
|
import gitbucket.core.api.{AddACollaborator, ApiUser, JsonFormat}
|
||||||
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.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -10,8 +10,8 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
self: RepositoryService with AccountService with ReferrerAuthenticator with OwnerAuthenticator =>
|
self: RepositoryService with AccountService with ReferrerAuthenticator with OwnerAuthenticator =>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* i. List repository collaborators
|
* i. List collaborators
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#list-repository-collaborators
|
* https://developer.github.com/v3/repos/collaborators/#list-collaborators
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/collaborators")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/collaborators")(referrersOnly { repository =>
|
||||||
// TODO Should ApiUser take permission? getCollaboratorUserNames does not return owner group members.
|
// TODO Should ApiUser take permission? getCollaboratorUserNames does not return owner group members.
|
||||||
@@ -19,40 +19,19 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
getCollaboratorUserNames(params("owner"), params("repository")).map(u => ApiUser(getAccountByUserName(u).get))
|
getCollaboratorUserNames(params("owner"), params("repository")).map(u => ApiUser(getAccountByUserName(u).get))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Check if a user is a collaborator
|
* ii. Check if a user is a collaborator
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#check-if-a-user-is-a-repository-collaborator
|
* https://developer.github.com/v3/repos/collaborators/#check-if-a-user-is-a-collaborator
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/collaborators/:userName")(referrersOnly { repository =>
|
|
||||||
(for (account <- getAccountByUserName(params("userName"))) yield {
|
|
||||||
if (getCollaboratorUserNames(repository.owner, repository.name).contains(account.userName)) {
|
|
||||||
NoContent()
|
|
||||||
} else {
|
|
||||||
NotFound()
|
|
||||||
}
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Get repository permissions for a user
|
* iii. Review a user's permission level
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-repository-permissions-for-a-user
|
* https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/collaborators/:userName/permission")(referrersOnly { repository =>
|
|
||||||
(for {
|
|
||||||
account <- getAccountByUserName(params("userName"))
|
|
||||||
collaborator <- getCollaborators(repository.owner, repository.name)
|
|
||||||
.find(p => p._1.collaboratorName == account.userName)
|
|
||||||
} yield {
|
|
||||||
JsonFormat(
|
|
||||||
ApiRepositoryCollaborator(collaborator._1.role, ApiUser(account))
|
|
||||||
)
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iv. Add a repository collaborator
|
* iv. Add user as a collaborator
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#add-a-repository-collaborator
|
* https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
|
||||||
* requested #1586
|
* requested #1586
|
||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||||
@@ -65,8 +44,8 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Remove a repository collaborator
|
* v. Remove user as a collaborator
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-a-repository-collaborator
|
* https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator
|
||||||
* requested #1586
|
* requested #1586
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
delete("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiBranchCommit, ApiBranchForHeadCommit, ApiCommits, JsonFormat}
|
import gitbucket.core.api.{ApiCommits, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service.{AccountService, CommitsService, ProtectedBranchService}
|
import gitbucket.core.service.{AccountService, CommitsService}
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.JGitUtil.{CommitInfo, getBranches, getBranchesOfCommit}
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
|
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
||||||
self: AccountService with CommitsService with ProtectedBranchService with ReferrerAuthenticator =>
|
self: AccountService with CommitsService with ReferrerAuthenticator =>
|
||||||
/*
|
/*
|
||||||
* i. List commits on a repository
|
* i. List commits on a repository
|
||||||
* https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
* https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
||||||
@@ -23,7 +22,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
val owner = repository.owner
|
val owner = repository.owner
|
||||||
val name = repository.name
|
val name = repository.name
|
||||||
// TODO: The following parameters need to be implemented. [:path, :author, :since, :until]
|
// TODO: The following parameters need to be implemented. [:path, :author, :since, :until]
|
||||||
val sha = params.getOrElse("sha", "refs/heads/master")
|
val sha = if (request.body.nonEmpty) (parse(request.body) \ "sha").extract[String] else "refs/heads/master";
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
||||||
git =>
|
git =>
|
||||||
val repo = git.getRepository
|
val repo = git.getRepository
|
||||||
@@ -40,7 +39,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
diffs = JGitUtil.getDiffs(git, commitInfo.parents.headOption, commitInfo.id, false, true),
|
diffs = JGitUtil.getDiffs(git, commitInfo.parents.headOption, commitInfo.id, false, true),
|
||||||
author = getAccount(commitInfo.authorName, commitInfo.authorEmailAddress),
|
author = getAccount(commitInfo.authorName, commitInfo.authorEmailAddress),
|
||||||
committer = getAccount(commitInfo.committerName, commitInfo.committerEmailAddress),
|
committer = getAccount(commitInfo.committerName, commitInfo.committerEmailAddress),
|
||||||
commentCount = getCommitComment(repository.owner, repository.name, commitInfo.id).size
|
commentCount = getCommitComment(repository.owner, repository.name, commitInfo.id.toString).size
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@@ -108,25 +107,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Commit signature verification
|
* v. Commit signature verification
|
||||||
* https://developer.github.com/v3/repos/commits/#commit-signature-verification
|
* https://developer.github.com/v3/repos/commits/#commit-signature-verification
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
|
||||||
* vi. List branches for HEAD commit
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-branches-for-head-commit
|
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/commits/:sha/branches-where-head")(referrersOnly { repository =>
|
|
||||||
val sha = params("sha")
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
|
||||||
val apiBranchForCommits = for {
|
|
||||||
branch <- getBranchesOfCommit(git, sha)
|
|
||||||
br <- getBranches(git, branch, repository.repository.originUserName.isEmpty).find(_.name == branch)
|
|
||||||
} yield {
|
|
||||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
|
||||||
ApiBranchForHeadCommit(branch, ApiBranchCommit(br.commitId), protection.enabled)
|
|
||||||
}
|
|
||||||
JsonFormat(apiBranchForCommits)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,41 +1,26 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiCommit, ApiContents, ApiError, CreateAFile, JsonFormat}
|
import gitbucket.core.api.{ApiContents, ApiError, CreateAFile, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.JGitUtil.{CommitInfo, FileInfo, getContentFromId, getFileList}
|
import gitbucket.core.util.JGitUtil.{FileInfo, getContentFromId, getFileList}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
||||||
self: ReferrerAuthenticator with WritableUsersAuthenticator with RepositoryCommitFileService =>
|
self: ReferrerAuthenticator with WritableUsersAuthenticator with RepositoryCommitFileService =>
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* i. Get a repository README
|
* i. Get the README
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-a-repository-readme
|
* https://developer.github.com/v3/repos/contents/#get-the-readme
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/readme")(referrersOnly { repository =>
|
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
|
||||||
git =>
|
|
||||||
val refStr = params.getOrElse("ref", repository.repository.defaultBranch)
|
|
||||||
val files = getFileList(git, refStr, ".", maxFiles = context.settings.repositoryViewer.maxFiles)
|
|
||||||
files // files should be sorted alphabetically.
|
|
||||||
.find { file =>
|
|
||||||
!file.isDirectory && RepositoryService.readmeFiles.contains(file.name.toLowerCase)
|
|
||||||
} match {
|
|
||||||
case Some(x) => getContents(repository = repository, path = x.name, refStr = refStr, ignoreCase = true)
|
|
||||||
case _ => NotFound()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get contents
|
* ii. Get contents
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-repository-content
|
* https://developer.github.com/v3/repos/contents/#get-contents
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/contents")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/contents")(referrersOnly { repository =>
|
||||||
getContents(repository, ".", params.getOrElse("ref", repository.repository.defaultBranch))
|
getContents(repository, ".", params.getOrElse("ref", repository.repository.defaultBranch))
|
||||||
@@ -43,38 +28,27 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get contents
|
* ii. Get contents
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-repository-content
|
* https://developer.github.com/v3/repos/contents/#get-contents
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/contents/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/contents/*")(referrersOnly { repository =>
|
||||||
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getFileInfo(git: Git, revision: String, pathStr: String, ignoreCase: Boolean): Option[FileInfo] = {
|
private def getContents(repository: RepositoryService.RepositoryInfo, path: String, refStr: String) = {
|
||||||
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
def getFileInfo(git: Git, revision: String, pathStr: String): Option[FileInfo] = {
|
||||||
case -1 =>
|
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
||||||
(".", pathStr)
|
case -1 =>
|
||||||
case n =>
|
(".", pathStr)
|
||||||
(pathStr.take(n), pathStr.drop(n + 1))
|
case n =>
|
||||||
|
(pathStr.take(n), pathStr.drop(n + 1))
|
||||||
|
}
|
||||||
|
getFileList(git, revision, dirName).find(f => f.name.equals(fileName))
|
||||||
}
|
}
|
||||||
if (ignoreCase) {
|
|
||||||
getFileList(git, revision, dirName, maxFiles = context.settings.repositoryViewer.maxFiles)
|
|
||||||
.find(_.name.toLowerCase.equals(fileName.toLowerCase))
|
|
||||||
} else {
|
|
||||||
getFileList(git, revision, dirName, maxFiles = context.settings.repositoryViewer.maxFiles)
|
|
||||||
.find(_.name.equals(fileName))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def getContents(
|
|
||||||
repository: RepositoryService.RepositoryInfo,
|
|
||||||
path: String,
|
|
||||||
refStr: String,
|
|
||||||
ignoreCase: Boolean = false
|
|
||||||
) = {
|
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
val fileList = getFileList(git, refStr, path, maxFiles = context.settings.repositoryViewer.maxFiles)
|
val fileList = getFileList(git, refStr, path)
|
||||||
if (fileList.isEmpty) { // file or NotFound
|
if (fileList.isEmpty) { // file or NotFound
|
||||||
getFileInfo(git, refStr, path, ignoreCase)
|
getFileInfo(git, refStr, path)
|
||||||
.flatMap { f =>
|
.flatMap { f =>
|
||||||
val largeFile = params.get("large_file").exists(s => s.equals("true"))
|
val largeFile = params.get("large_file").exists(s => s.equals("true"))
|
||||||
val content = getContentFromId(git, f.id, largeFile)
|
val content = getContentFromId(git, f.id, largeFile)
|
||||||
@@ -126,88 +100,56 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/*
|
||||||
/**
|
|
||||||
* iii. Create a file or iv. Update a file
|
* iii. Create a file or iv. Update a file
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
|
* https://developer.github.com/v3/repos/contents/#create-a-file
|
||||||
|
* https://developer.github.com/v3/repos/contents/#update-a-file
|
||||||
* if sha is presented, update a file else create a file.
|
* if sha is presented, update a file else create a file.
|
||||||
* requested #2112
|
* requested #2112
|
||||||
*/
|
*/
|
||||||
|
|
||||||
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
||||||
context.withLoginAccount {
|
JsonFormat(for {
|
||||||
loginAccount =>
|
data <- extractFromJsonBody[CreateAFile]
|
||||||
JsonFormat(for {
|
} yield {
|
||||||
data <- extractFromJsonBody[CreateAFile]
|
val branch = data.branch.getOrElse(repository.repository.defaultBranch)
|
||||||
} yield {
|
val commit = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val branch = data.branch.getOrElse(repository.repository.defaultBranch)
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
val commit = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
revCommit.name
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
}
|
||||||
revCommit.name
|
val paths = multiParams("splat").head.split("/")
|
||||||
}
|
val path = paths.take(paths.size - 1).toList.mkString("/")
|
||||||
val paths = multiParams("splat").head.split("/")
|
if (data.sha.isDefined && data.sha.get != commit) {
|
||||||
val path = paths.take(paths.size - 1).toList.mkString("/")
|
ApiError("The blob SHA is not matched.", Some("https://developer.github.com/v3/repos/contents/#update-a-file"))
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
} else {
|
||||||
git =>
|
val objectId = commitFile(
|
||||||
val fileInfo = getFileInfo(git, commit, path, false)
|
repository,
|
||||||
|
branch,
|
||||||
fileInfo match {
|
path,
|
||||||
case Some(f) if !data.sha.contains(f.id.getName) =>
|
Some(paths.last),
|
||||||
ApiError(
|
data.sha.map(_ => paths.last),
|
||||||
"The blob SHA is not matched.",
|
StringUtil.base64Decode(data.content),
|
||||||
Some("https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents")
|
data.message,
|
||||||
)
|
commit,
|
||||||
case _ =>
|
context.loginAccount.get,
|
||||||
val (commitId, blobId) = commitFile(
|
data.committer.map(_.name).getOrElse(context.loginAccount.get.fullName),
|
||||||
repository,
|
data.committer.map(_.email).getOrElse(context.loginAccount.get.mailAddress),
|
||||||
branch,
|
context.settings
|
||||||
path,
|
)
|
||||||
Some(paths.last),
|
ApiContents("file", paths.last, path, objectId.name, None, None)(RepositoryName(repository))
|
||||||
data.sha.map(_ => paths.last),
|
}
|
||||||
StringUtil.base64Decode(data.content),
|
})
|
||||||
data.message,
|
|
||||||
commit,
|
|
||||||
loginAccount,
|
|
||||||
data.committer.map(_.name).getOrElse(loginAccount.fullName),
|
|
||||||
data.committer.map(_.email).getOrElse(loginAccount.mailAddress),
|
|
||||||
context.settings
|
|
||||||
)
|
|
||||||
|
|
||||||
blobId match {
|
|
||||||
case None =>
|
|
||||||
ApiError("Failed to commit a file.", None)
|
|
||||||
case Some(blobId) =>
|
|
||||||
Map(
|
|
||||||
"content" -> ApiContents(
|
|
||||||
"file",
|
|
||||||
paths.last,
|
|
||||||
path,
|
|
||||||
blobId.name,
|
|
||||||
Some(data.content),
|
|
||||||
Some("base64")
|
|
||||||
)(RepositoryName(repository)),
|
|
||||||
"commit" -> ApiCommit(
|
|
||||||
git,
|
|
||||||
RepositoryName(repository),
|
|
||||||
new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Delete a file
|
* v. Delete a file
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-a-file
|
* https://developer.github.com/v3/repos/contents/#delete-a-file
|
||||||
* should be implemented
|
* should be implemented
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Download a repository archive (tar/zip)
|
* vi. Get archive link
|
||||||
* https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-tar
|
* https://developer.github.com/v3/repos/contents/#get-archive-link
|
||||||
* https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-zip
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import gitbucket.core.util._
|
|||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.Forbidden
|
|
||||||
|
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
import scala.concurrent.duration.Duration
|
import scala.concurrent.duration.Duration
|
||||||
@@ -27,7 +26,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* i. List your repositories
|
* i. List your repositories
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user
|
* https://developer.github.com/v3/repos/#list-your-repositories
|
||||||
*/
|
*/
|
||||||
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 =>
|
||||||
@@ -37,7 +36,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. List user repositories
|
* ii. List user repositories
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repositories-for-a-user
|
* https://developer.github.com/v3/repos/#list-user-repositories
|
||||||
*/
|
*/
|
||||||
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 =>
|
||||||
@@ -47,7 +46,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* iii. List organization repositories
|
* iii. List organization repositories
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-organization-repositories
|
* https://developer.github.com/v3/repos/#list-organization-repositories
|
||||||
*/
|
*/
|
||||||
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 =>
|
||||||
@@ -55,24 +54,21 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/*
|
||||||
* iv. List all public repositories
|
* iv. List all public repositories
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-public-repositories
|
* https://developer.github.com/v3/repos/#list-all-public-repositories
|
||||||
|
* Not implemented
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repositories") {
|
|
||||||
JsonFormat(getPublicRepositories().map { r =>
|
|
||||||
ApiRepository(r, getAccountByUserName(r.owner).get)
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Create
|
* v. Create
|
||||||
|
* https://developer.github.com/v3/repos/#create
|
||||||
* Implemented with two methods (user/orgs)
|
* Implemented with two methods (user/orgs)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create user repository
|
* Create user repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-a-repository-for-the-authenticated-user
|
* https://developer.github.com/v3/repos/#create
|
||||||
*/
|
*/
|
||||||
post("/api/v3/user/repos")(usersOnly {
|
post("/api/v3/user/repos")(usersOnly {
|
||||||
val owner = context.loginAccount.get.userName
|
val owner = context.loginAccount.get.userName
|
||||||
@@ -80,12 +76,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
||||||
} yield {
|
} yield {
|
||||||
LockUtil.lock(s"${owner}/${data.name}") {
|
LockUtil.lock(s"${owner}/${data.name}") {
|
||||||
if (getRepository(owner, data.name).isDefined) {
|
if (getRepository(owner, data.name).isEmpty) {
|
||||||
ApiError(
|
|
||||||
"A repository with this name already exists on this account",
|
|
||||||
Some("https://developer.github.com/v3/repos/#create")
|
|
||||||
)
|
|
||||||
} else {
|
|
||||||
val f = createRepository(
|
val f = createRepository(
|
||||||
context.loginAccount.get,
|
context.loginAccount.get,
|
||||||
owner,
|
owner,
|
||||||
@@ -100,6 +91,11 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
getRepository(owner, data.name)(session).get
|
getRepository(owner, data.name)(session).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get)))
|
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get)))
|
||||||
|
} else {
|
||||||
|
ApiError(
|
||||||
|
"A repository with this name already exists on this account",
|
||||||
|
Some("https://developer.github.com/v3/repos/#create")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
@@ -107,22 +103,15 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create group repository
|
* Create group repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-an-organization-repository
|
* https://developer.github.com/v3/repos/#create
|
||||||
*/
|
*/
|
||||||
post("/api/v3/orgs/:org/repos")(usersOnly {
|
post("/api/v3/orgs/:org/repos")(managersOnly {
|
||||||
val groupName = params("org")
|
val groupName = params("org")
|
||||||
(for {
|
(for {
|
||||||
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
||||||
} yield {
|
} yield {
|
||||||
LockUtil.lock(s"${groupName}/${data.name}") {
|
LockUtil.lock(s"${groupName}/${data.name}") {
|
||||||
if (getRepository(groupName, data.name).isDefined) {
|
if (getRepository(groupName, data.name).isEmpty) {
|
||||||
ApiError(
|
|
||||||
"A repository with this name already exists for this group",
|
|
||||||
Some("https://developer.github.com/v3/repos/#create")
|
|
||||||
)
|
|
||||||
} else if (!canCreateRepository(groupName, context.loginAccount.get)) {
|
|
||||||
Forbidden()
|
|
||||||
} else {
|
|
||||||
val f = createRepository(
|
val f = createRepository(
|
||||||
context.loginAccount.get,
|
context.loginAccount.get,
|
||||||
groupName,
|
groupName,
|
||||||
@@ -136,6 +125,11 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
getRepository(groupName, data.name).get
|
getRepository(groupName, data.name).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get)))
|
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get)))
|
||||||
|
} else {
|
||||||
|
ApiError(
|
||||||
|
"A repository with this name already exists for this group",
|
||||||
|
Some("https://developer.github.com/v3/repos/#create")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
@@ -143,7 +137,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Get
|
* vi. Get
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-a-repository
|
* 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, ApiUser(getAccountByUserName(repository.owner).get)))
|
||||||
@@ -151,52 +145,47 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* vii. Edit
|
* vii. Edit
|
||||||
* https://docs.github.com/en/rest/reference/repos#update-a-repository
|
* https://developer.github.com/v3/repos/#edit
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* viii. List all topics for a repository
|
* viii. List all topics for a repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-all-repository-topics
|
* https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. Replace all topics for a repository
|
* ix. Replace all topics for a repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#replace-all-repository-topics
|
* https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. List contributors
|
* x. List contributors
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-contributors
|
* https://developer.github.com/v3/repos/#list-contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xi. List languages
|
* xi. List languages
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-languages
|
* https://developer.github.com/v3/repos/#list-languages
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xii. List teams
|
* xii. List teams
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-teams
|
* https://developer.github.com/v3/repos/#list-teams
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiii. List repository tags
|
* xiii. List tags
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-tags
|
* https://developer.github.com/v3/repos/#list-tags
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/tags")(referrersOnly { repository =>
|
|
||||||
JsonFormat(
|
|
||||||
repository.tags.map(tagInfo => ApiTag(tagInfo.name, RepositoryName(repository), tagInfo.id))
|
|
||||||
)
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiv. Delete a repository
|
* xiv. Delete a repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-a-repository
|
* https://developer.github.com/v3/repos/#delete-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xv. Transfer a repository
|
* xv. Transfer a repository
|
||||||
* https://docs.github.com/en/rest/reference/repos#transfer-a-repository
|
* https://developer.github.com/v3/repos/#transfer-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ trait ApiRepositoryStatusControllerBase extends ControllerBase {
|
|||||||
ref <- params.get("ref")
|
ref <- params.get("ref")
|
||||||
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(getCommitStatusesWithCreator(repository.owner, repository.name, sha).map {
|
JsonFormat(getCommitStatuesWithCreator(repository.owner, repository.name, sha).map {
|
||||||
case (status, creator) =>
|
case (status, creator) =>
|
||||||
ApiCommitStatus(status, ApiUser(creator))
|
ApiCommitStatus(status, ApiUser(creator))
|
||||||
})
|
})
|
||||||
@@ -73,7 +73,7 @@ trait ApiRepositoryStatusControllerBase extends ControllerBase {
|
|||||||
owner <- getAccountByUserName(repository.owner)
|
owner <- getAccountByUserName(repository.owner)
|
||||||
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
||||||
} yield {
|
} yield {
|
||||||
val statuses = getCommitStatusesWithCreator(repository.owner, repository.name, sha)
|
val statuses = getCommitStatuesWithCreator(repository.owner, repository.name, sha)
|
||||||
JsonFormat(ApiCombinedCommitStatus(sha, statuses, ApiRepository(repository, owner)))
|
JsonFormat(ApiCombinedCommitStatus(sha, statuses, ApiRepository(repository, owner)))
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -1,120 +0,0 @@
|
|||||||
package gitbucket.core.controller.api
|
|
||||||
import gitbucket.core.api._
|
|
||||||
import gitbucket.core.controller.ControllerBase
|
|
||||||
import gitbucket.core.model.{WebHook, WebHookContentType}
|
|
||||||
import gitbucket.core.service.{RepositoryService, WebHookService}
|
|
||||||
import gitbucket.core.util._
|
|
||||||
import gitbucket.core.util.Implicits._
|
|
||||||
import org.scalatra.NoContent
|
|
||||||
|
|
||||||
trait ApiRepositoryWebhookControllerBase extends ControllerBase {
|
|
||||||
self: RepositoryService with WebHookService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
|
||||||
|
|
||||||
/*
|
|
||||||
* i. List repository webhooks
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-webhooks
|
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/hooks")(referrersOnly { repository =>
|
|
||||||
val apiWebhooks = for {
|
|
||||||
(hook, events) <- getWebHooks(repository.owner, repository.name)
|
|
||||||
} yield {
|
|
||||||
ApiWebhook("Repository", hook, events)
|
|
||||||
}
|
|
||||||
JsonFormat(apiWebhooks)
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* ii. Create a repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook
|
|
||||||
*/
|
|
||||||
post("/api/v3/repos/:owner/:repository/hooks")(writableUsersOnly { repository =>
|
|
||||||
(for {
|
|
||||||
data <- extractFromJsonBody[CreateARepositoryWebhook] if data.isValid
|
|
||||||
ctype = if (data.config.content_type == "form") WebHookContentType.FORM else WebHookContentType.JSON
|
|
||||||
events = data.events.map(p => WebHook.Event.valueOf(p)).toSet
|
|
||||||
} yield {
|
|
||||||
addWebHook(
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
data.config.url,
|
|
||||||
events,
|
|
||||||
ctype,
|
|
||||||
data.config.secret
|
|
||||||
)
|
|
||||||
getWebHook(repository.owner, repository.name, data.config.url) match {
|
|
||||||
case Some(createdHook) => JsonFormat(ApiWebhook("Repository", createdHook._1, createdHook._2))
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iii. Get a repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#get-a-repository-webhook
|
|
||||||
*/
|
|
||||||
get("/api/v3/repos/:owner/:repository/hooks/:id")(referrersOnly { repository =>
|
|
||||||
val hookId = params("id").toInt
|
|
||||||
getWebHookById(hookId) match {
|
|
||||||
case Some(hook) => JsonFormat(ApiWebhook("Repository", hook._1, hook._2))
|
|
||||||
case _ => NotFound()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iv. Update a repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#update-a-repository-webhook
|
|
||||||
*/
|
|
||||||
patch("/api/v3/repos/:owner/:repository/hooks/:id")(writableUsersOnly { repository =>
|
|
||||||
val hookId = params("id").toInt
|
|
||||||
(for {
|
|
||||||
data <- extractFromJsonBody[UpdateARepositoryWebhook] if data.isValid
|
|
||||||
ctype = data.config.content_type match {
|
|
||||||
case "json" => WebHookContentType.JSON
|
|
||||||
case _ => WebHookContentType.FORM
|
|
||||||
}
|
|
||||||
} yield {
|
|
||||||
val events = (data.events ++ data.add_events)
|
|
||||||
.filterNot(p => data.remove_events.contains(p))
|
|
||||||
.map(p => WebHook.Event.valueOf(p))
|
|
||||||
.toSet
|
|
||||||
updateWebHookByApi(
|
|
||||||
hookId,
|
|
||||||
repository.owner,
|
|
||||||
repository.name,
|
|
||||||
data.config.url,
|
|
||||||
events,
|
|
||||||
ctype,
|
|
||||||
data.config.secret
|
|
||||||
)
|
|
||||||
getWebHookById(hookId) match {
|
|
||||||
case Some(updatedHook) => JsonFormat(ApiWebhook("Repository", updatedHook._1, updatedHook._2))
|
|
||||||
case _ =>
|
|
||||||
}
|
|
||||||
}) getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* v. Delete a repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#delete-a-repository-webhook
|
|
||||||
*/
|
|
||||||
delete("/api/v3/repos/:owner/:repository/hooks/:id")(writableUsersOnly { repository =>
|
|
||||||
val hookId = params("id").toInt
|
|
||||||
getWebHookById(hookId) match {
|
|
||||||
case Some(_) =>
|
|
||||||
deleteWebHookById(params("id").toInt)
|
|
||||||
NoContent()
|
|
||||||
case _ => NotFound()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vi. Ping a repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#ping-a-repository-webhook
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vi. Test the push repository webhook
|
|
||||||
* https://docs.github.com/en/rest/reference/repos#test-the-push-repository-webhook
|
|
||||||
*/
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -104,7 +104,7 @@ trait ApiUserControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
delete("/api/v3/users/:userName/suspended")(adminOnly {
|
delete("/api/v3/users/:userName/suspended")(adminOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName, true) match {
|
getAccountByUserName(userName) match {
|
||||||
case Some(targetAccount) =>
|
case Some(targetAccount) =>
|
||||||
updateAccount(targetAccount.copy(isRemoved = false))
|
updateAccount(targetAccount.copy(isRemoved = false))
|
||||||
NoContent()
|
NoContent()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait AccessTokenComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
val tokenHash = column[String]("TOKEN_HASH")
|
val tokenHash = column[String]("TOKEN_HASH")
|
||||||
val note = column[String]("NOTE")
|
val note = column[String]("NOTE")
|
||||||
def * = (accessTokenId, userName, tokenHash, note).<>(AccessToken.tupled, AccessToken.unapply)
|
def * = (accessTokenId, userName, tokenHash, note) <> (AccessToken.tupled, AccessToken.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case class AccessToken(
|
case class AccessToken(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ trait AccountComponent { self: Profile =>
|
|||||||
groupAccount,
|
groupAccount,
|
||||||
removed,
|
removed,
|
||||||
description.?
|
description.?
|
||||||
).<>(Account.tupled, Account.unapply)
|
) <> (Account.tupled, Account.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountExtraMailAddressComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
||||||
def * =
|
def * =
|
||||||
(userName, extraMailAddress).<>(AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
(userName, extraMailAddress) <> (AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountFederationComponent { self: Profile =>
|
|||||||
val issuer = column[String]("ISSUER")
|
val issuer = column[String]("ISSUER")
|
||||||
val subject = column[String]("SUBJECT")
|
val subject = column[String]("SUBJECT")
|
||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
def * = (issuer, subject, userName).<>(AccountFederation.tupled, AccountFederation.unapply)
|
def * = (issuer, subject, userName) <> (AccountFederation.tupled, AccountFederation.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
||||||
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
||||||
|
|||||||
@@ -1,21 +0,0 @@
|
|||||||
package gitbucket.core.model
|
|
||||||
|
|
||||||
trait AccountPreferenceComponent { self: Profile =>
|
|
||||||
import profile.api._
|
|
||||||
|
|
||||||
lazy val AccountPreferences = TableQuery[AccountPreferences]
|
|
||||||
|
|
||||||
class AccountPreferences(tag: Tag) extends Table[AccountPreference](tag, "ACCOUNT_PREFERENCE") {
|
|
||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
|
||||||
val highlighterTheme = column[String]("HIGHLIGHTER_THEME")
|
|
||||||
def * =
|
|
||||||
(userName, highlighterTheme).<>(AccountPreference.tupled, AccountPreference.unapply)
|
|
||||||
|
|
||||||
def byPrimaryKey(userName: String): Rep[Boolean] = this.userName === userName.bind
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
case class AccountPreference(
|
|
||||||
userName: String,
|
|
||||||
highlighterTheme: String = "prettify"
|
|
||||||
)
|
|
||||||
@@ -3,7 +3,7 @@ package gitbucket.core.model
|
|||||||
trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
|
|
||||||
private implicit val whContentTypeColumnType: BaseColumnType[WebHookContentType] =
|
private implicit val whContentTypeColumnType =
|
||||||
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
||||||
|
|
||||||
lazy val AccountWebHooks = TableQuery[AccountWebHooks]
|
lazy val AccountWebHooks = TableQuery[AccountWebHooks]
|
||||||
@@ -12,7 +12,7 @@ trait AccountWebHookComponent 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")
|
||||||
def * = (userName, url, ctype, token).<>((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
def * = (userName, url, ctype, token) <> ((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait AccountWebHookEventComponent extends TemplateComponent { self: Profile =>
|
trait AccountWebHookEventComponent extends TemplateComponent {
|
||||||
|
self: Profile =>
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import gitbucket.core.model.Profile.AccountWebHooks
|
import gitbucket.core.model.Profile.AccountWebHooks
|
||||||
|
|
||||||
@@ -12,7 +14,7 @@ trait AccountWebHookEventComponent extends TemplateComponent { self: Profile =>
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
|
|
||||||
def * = (userName, url, event).<>((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
def * = (userName, url, event) <> ((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
||||||
|
|
||||||
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
|
|
||||||
|
|||||||
@@ -1,9 +1,5 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
/**
|
|
||||||
* ActivityComponent has been deprecated, but keep it for binary compatibility.
|
|
||||||
*/
|
|
||||||
@deprecated("ActivityComponent has been deprecated, but keep it for binary compatibility.", "4.34.0")
|
|
||||||
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
@@ -11,7 +7,14 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val Activities = TableQuery[Activities]
|
lazy val Activities = TableQuery[Activities]
|
||||||
|
|
||||||
class Activities(tag: Tag) extends Table[Activity](tag, "ACTIVITY") with BasicTemplate {
|
class Activities(tag: Tag) extends Table[Activity](tag, "ACTIVITY") with BasicTemplate {
|
||||||
def * = ???
|
val activityId = column[Int]("ACTIVITY_ID", O AutoInc)
|
||||||
|
val activityUserName = column[String]("ACTIVITY_USER_NAME")
|
||||||
|
val activityType = column[String]("ACTIVITY_TYPE")
|
||||||
|
val message = column[String]("MESSAGE")
|
||||||
|
val additionalInfo = column[String]("ADDITIONAL_INFO")
|
||||||
|
val activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
||||||
|
def * =
|
||||||
|
(userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,5 +26,5 @@ case class Activity(
|
|||||||
message: String,
|
message: String,
|
||||||
additionalInfo: Option[String],
|
additionalInfo: Option[String],
|
||||||
activityDate: java.util.Date,
|
activityDate: java.util.Date,
|
||||||
activityId: String
|
activityId: Int = 0
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
|||||||
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
||||||
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
||||||
val role = column[String]("ROLE")
|
val role = column[String]("ROLE")
|
||||||
def * = (userName, repositoryName, collaboratorName, role).<>(Collaborator.tupled, Collaborator.unapply)
|
def * = (userName, repositoryName, collaboratorName, role) <> (Collaborator.tupled, Collaborator.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
||||||
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
||||||
|
|||||||
@@ -20,8 +20,7 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
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")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate)
|
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate) <> (IssueComment.tupled, IssueComment.unapply)
|
||||||
.<>(IssueComment.tupled, IssueComment.unapply)
|
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
@@ -75,7 +74,7 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
originalCommitId,
|
originalCommitId,
|
||||||
originalOldLine,
|
originalOldLine,
|
||||||
originalNewLine
|
originalNewLine
|
||||||
).<>(CommitComment.tupled, CommitComment.unapply)
|
) <> (CommitComment.tupled, CommitComment.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,7 @@ trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
|||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
implicit val commitStateColumnType: BaseColumnType[CommitState] =
|
implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name, i => CommitState(i))
|
||||||
MappedColumnType.base[CommitState, String](b => b.name, i => CommitState(i))
|
|
||||||
|
|
||||||
lazy val CommitStatuses = TableQuery[CommitStatuses]
|
lazy val CommitStatuses = TableQuery[CommitStatuses]
|
||||||
class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate {
|
class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate {
|
||||||
@@ -30,7 +29,7 @@ trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
|||||||
creator,
|
creator,
|
||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate
|
updatedDate
|
||||||
).<>((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
) <> ((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
||||||
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -78,7 +77,7 @@ object CommitState {
|
|||||||
|
|
||||||
val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE)
|
val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE)
|
||||||
|
|
||||||
private val map: Map[String, CommitState] = values.map(e => e.name -> e).toMap
|
private val map: Map[String, CommitState] = values.map(enum => enum.name -> enum).toMap
|
||||||
|
|
||||||
def apply(name: String): CommitState = map(name)
|
def apply(name: String): CommitState = map(name)
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ trait DeployKeyComponent extends TemplateComponent { self: Profile =>
|
|||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite).<>(DeployKey.tupled, DeployKey.unapply)
|
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite) <> (DeployKey.tupled, DeployKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ trait GpgKeyComponent { self: Profile =>
|
|||||||
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, keyId, gpgKeyId, title, publicKey).<>(GpgKey.tupled, GpgKey.unapply)
|
def * = (userName, keyId, gpgKeyId, title, publicKey) <> (GpgKey.tupled, GpgKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, keyId: Int) =
|
def byPrimaryKey(userName: String, keyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait GroupMemberComponent { self: Profile =>
|
|||||||
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val isManager = column[Boolean]("MANAGER")
|
val isManager = column[Boolean]("MANAGER")
|
||||||
def * = (groupName, userName, isManager).<>(GroupMember.tupled, GroupMember.unapply)
|
def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
|||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate,
|
updatedDate,
|
||||||
pullRequest
|
pullRequest
|
||||||
).<>(Issue.tupled, Issue.unapply)
|
) <> (Issue.tupled, Issue.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val IssueLabels = TableQuery[IssueLabels]
|
lazy val IssueLabels = TableQuery[IssueLabels]
|
||||||
|
|
||||||
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
||||||
def * = (userName, repositoryName, issueId, labelId).<>(IssueLabel.tupled, IssueLabel.unapply)
|
def * = (userName, repositoryName, issueId, labelId) <> (IssueLabel.tupled, IssueLabel.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
||||||
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
||||||
override val labelName = column[String]("LABEL_NAME")
|
override val labelName = column[String]("LABEL_NAME")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * = (userName, repositoryName, labelId, labelName, color).<>(Label.tupled, Label.unapply)
|
def * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
|||||||
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
||||||
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate)
|
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate) <> (Milestone.tupled, Milestone.unapply)
|
||||||
.<>(Milestone.tupled, Milestone.unapply)
|
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,8 +13,7 @@ trait PriorityComponent extends TemplateComponent { self: Profile =>
|
|||||||
val isDefault = column[Boolean]("IS_DEFAULT")
|
val isDefault = column[Boolean]("IS_DEFAULT")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color)
|
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color) <> (Priority.tupled, Priority.unapply)
|
||||||
.<>(Priority.tupled, Priority.unapply)
|
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
||||||
|
|||||||
@@ -10,17 +10,15 @@ trait Profile {
|
|||||||
/**
|
/**
|
||||||
* java.util.Date Mapped Column Types
|
* java.util.Date Mapped Column Types
|
||||||
*/
|
*/
|
||||||
implicit val dateColumnType: BaseColumnType[java.util.Date] =
|
implicit val dateColumnType = MappedColumnType.base[java.util.Date, java.sql.Timestamp](
|
||||||
MappedColumnType.base[java.util.Date, java.sql.Timestamp](
|
d => new java.sql.Timestamp(d.getTime),
|
||||||
d => new java.sql.Timestamp(d.getTime),
|
t => new java.util.Date(t.getTime)
|
||||||
t => new java.util.Date(t.getTime)
|
)
|
||||||
)
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* WebHookBase.Event Column Types
|
* WebHookBase.Event Column Types
|
||||||
*/
|
*/
|
||||||
implicit val eventColumnType: BaseColumnType[WebHook.Event] =
|
implicit val eventColumnType = MappedColumnType.base[WebHook.Event, String](_.name, WebHook.Event.valueOf(_))
|
||||||
MappedColumnType.base[WebHook.Event, String](_.name, WebHook.Event.valueOf(_))
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends Column to add conditional condition
|
* Extends Column to add conditional condition
|
||||||
@@ -72,6 +70,5 @@ trait CoreProfile
|
|||||||
with ReleaseTagComponent
|
with ReleaseTagComponent
|
||||||
with ReleaseAssetComponent
|
with ReleaseAssetComponent
|
||||||
with AccountExtraMailAddressComponent
|
with AccountExtraMailAddressComponent
|
||||||
with AccountPreferenceComponent
|
|
||||||
|
|
||||||
object Profile extends CoreProfile
|
object Profile extends CoreProfile
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
||||||
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
||||||
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
||||||
def * = (userName, repositoryName, branch, statusCheckAdmin).<>(ProtectedBranch.tupled, ProtectedBranch.unapply)
|
def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply)
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
||||||
byBranch(userName, repositoryName, branch)
|
byBranch(userName, repositoryName, branch)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
||||||
@@ -20,7 +20,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
with BranchTemplate {
|
with BranchTemplate {
|
||||||
val context = column[String]("CONTEXT")
|
val context = column[String]("CONTEXT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, branch, context).<>(ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
(userName, repositoryName, branch, context) <> (ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
|||||||
commitIdFrom,
|
commitIdFrom,
|
||||||
commitIdTo,
|
commitIdTo,
|
||||||
isDraft
|
isDraft
|
||||||
).<>(PullRequest.tupled, PullRequest.unapply)
|
) <> (PullRequest.tupled, PullRequest.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
||||||
byIssue(userName, repositoryName, issueId)
|
byIssue(userName, repositoryName, issueId)
|
||||||
|
|||||||
@@ -2,7 +2,9 @@ package gitbucket.core.model
|
|||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
trait ReleaseAssetComponent extends TemplateComponent { self: Profile =>
|
trait ReleaseAssetComponent extends TemplateComponent {
|
||||||
|
self: Profile =>
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
@@ -19,8 +21,7 @@ trait ReleaseAssetComponent extends TemplateComponent { self: Profile =>
|
|||||||
val updatedDate = column[Date]("UPDATED_DATE")
|
val updatedDate = column[Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate)
|
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate) <> (ReleaseAsset.tupled, ReleaseAsset.unapply)
|
||||||
.<>(ReleaseAsset.tupled, ReleaseAsset.unapply)
|
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
||||||
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait ReleaseTagComponent extends TemplateComponent { self: Profile =>
|
trait ReleaseTagComponent extends TemplateComponent {
|
||||||
|
self: Profile =>
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
@@ -15,8 +17,7 @@ trait ReleaseTagComponent extends TemplateComponent { self: Profile =>
|
|||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate)
|
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate) <> (ReleaseTag.tupled, ReleaseTag.unapply)
|
||||||
.<>(ReleaseTag.tupled, ReleaseTag.unapply)
|
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
byRepository(owner, repository) && (this.tag === tag.bind)
|
byRepository(owner, repository) && (this.tag === tag.bind)
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
val allowFork = column[Boolean]("ALLOW_FORK")
|
val allowFork = column[Boolean]("ALLOW_FORK")
|
||||||
val mergeOptions = column[String]("MERGE_OPTIONS")
|
val mergeOptions = column[String]("MERGE_OPTIONS")
|
||||||
val defaultMergeOption = column[String]("DEFAULT_MERGE_OPTION")
|
val defaultMergeOption = column[String]("DEFAULT_MERGE_OPTION")
|
||||||
val safeMode = column[Boolean]("SAFE_MODE")
|
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(
|
(
|
||||||
@@ -42,58 +41,47 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
parentUserName.?,
|
parentUserName.?,
|
||||||
parentRepositoryName.?
|
parentRepositoryName.?
|
||||||
),
|
),
|
||||||
(
|
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions, defaultMergeOption)
|
||||||
issuesOption,
|
).shaped <> ({
|
||||||
externalIssuesUrl.?,
|
case (repository, options) =>
|
||||||
wikiOption,
|
Repository(
|
||||||
externalWikiUrl.?,
|
repository._1,
|
||||||
allowFork,
|
repository._2,
|
||||||
mergeOptions,
|
repository._3,
|
||||||
defaultMergeOption,
|
repository._4,
|
||||||
safeMode
|
repository._5,
|
||||||
)
|
repository._6,
|
||||||
).shaped.<>(
|
repository._7,
|
||||||
{
|
repository._8,
|
||||||
case (repository, options) =>
|
repository._9,
|
||||||
Repository(
|
repository._10,
|
||||||
repository._1,
|
repository._11,
|
||||||
repository._2,
|
repository._12,
|
||||||
repository._3,
|
RepositoryOptions.tupled.apply(options)
|
||||||
repository._4,
|
)
|
||||||
repository._5,
|
}, { (r: Repository) =>
|
||||||
repository._6,
|
Some(
|
||||||
repository._7,
|
(
|
||||||
repository._8,
|
|
||||||
repository._9,
|
|
||||||
repository._10,
|
|
||||||
repository._11,
|
|
||||||
repository._12,
|
|
||||||
RepositoryOptions.tupled.apply(options)
|
|
||||||
)
|
|
||||||
}, { (r: Repository) =>
|
|
||||||
Some(
|
|
||||||
(
|
(
|
||||||
(
|
r.userName,
|
||||||
r.userName,
|
r.repositoryName,
|
||||||
r.repositoryName,
|
r.isPrivate,
|
||||||
r.isPrivate,
|
r.description,
|
||||||
r.description,
|
r.defaultBranch,
|
||||||
r.defaultBranch,
|
r.registeredDate,
|
||||||
r.registeredDate,
|
r.updatedDate,
|
||||||
r.updatedDate,
|
r.lastActivityDate,
|
||||||
r.lastActivityDate,
|
r.originUserName,
|
||||||
r.originUserName,
|
r.originRepositoryName,
|
||||||
r.originRepositoryName,
|
r.parentUserName,
|
||||||
r.parentUserName,
|
r.parentRepositoryName
|
||||||
r.parentRepositoryName
|
),
|
||||||
),
|
(
|
||||||
(
|
RepositoryOptions.unapply(r.options).get
|
||||||
RepositoryOptions.unapply(r.options).get
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
)
|
||||||
)
|
})
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
||||||
}
|
}
|
||||||
@@ -122,6 +110,5 @@ case class RepositoryOptions(
|
|||||||
externalWikiUrl: Option[String],
|
externalWikiUrl: Option[String],
|
||||||
allowFork: Boolean,
|
allowFork: Boolean,
|
||||||
mergeOptions: String,
|
mergeOptions: String,
|
||||||
defaultMergeOption: String,
|
defaultMergeOption: String
|
||||||
safeMode: Boolean
|
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,32 +3,26 @@ package gitbucket.core.model
|
|||||||
trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
|
|
||||||
implicit val whContentTypeColumnType: BaseColumnType[WebHookContentType] =
|
implicit val whContentTypeColumnType =
|
||||||
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
||||||
|
|
||||||
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
||||||
|
|
||||||
class RepositoryWebHooks(tag: Tag) extends Table[RepositoryWebHook](tag, "WEB_HOOK") with BasicTemplate {
|
class RepositoryWebHooks(tag: Tag) extends Table[RepositoryWebHook](tag, "WEB_HOOK") with BasicTemplate {
|
||||||
val hookId = column[Int]("HOOK_ID", O AutoInc)
|
|
||||||
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")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, hookId, url, ctype, token)
|
(userName, repositoryName, url, ctype, token) <> ((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
||||||
.<>((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
|
||||||
|
|
||||||
def byRepositoryUrl(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(id: Int) =
|
|
||||||
(this.hookId === id.bind)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case class RepositoryWebHook(
|
case class RepositoryWebHook(
|
||||||
userName: String,
|
userName: String,
|
||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
hookId: Int = 0,
|
|
||||||
url: String,
|
url: String,
|
||||||
ctype: WebHookContentType,
|
ctype: WebHookContentType,
|
||||||
token: Option[String]
|
token: Option[String]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ trait RepositoryWebHookEventComponent extends TemplateComponent { self: Profile
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, url, event).<>((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
(userName, repositoryName, url, event) <> ((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
||||||
|
|
||||||
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait SshKeyComponent { self: Profile =>
|
|||||||
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, sshKeyId, title, publicKey).<>(SshKey.tupled, SshKey.unapply)
|
def * = (userName, sshKeyId, title, publicKey) <> (SshKey.tupled, SshKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ object WebHookContentType {
|
|||||||
|
|
||||||
val values: Vector[WebHookContentType] = Vector(JSON, FORM)
|
val values: Vector[WebHookContentType] = Vector(JSON, FORM)
|
||||||
|
|
||||||
private val map: Map[String, WebHookContentType] = values.map(e => e.code -> e).toMap
|
private val map: Map[String, WebHookContentType] = values.map(enum => enum.code -> enum).toMap
|
||||||
|
|
||||||
def apply(code: String): WebHookContentType = map(code)
|
def apply(code: String): WebHookContentType = map(code)
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +0,0 @@
|
|||||||
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
|
|
||||||
}
|
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user