mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-10-29 17:46:27 +01:00
Compare commits
1 Commits
revert_pul
...
disable-gi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f16f395539 |
@@ -5,10 +5,6 @@ trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
end_of_line = lf
|
||||
|
||||
[*.md]
|
||||
trim_trailing_whitespace = false
|
||||
|
||||
[*.java]
|
||||
trim_trailing_whitespace = true
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
# update scalafmt
|
||||
3d5ca44d66c77a46770a65a895c9737c542690f6
|
||||
|
||||
# Scala Steward: Reformat with scalafmt 3.8.2
|
||||
f1360f44c61f8e12666965c10e79f11cd75d6d30
|
||||
|
||||
# Scala Steward: Reformat with scalafmt 3.9.7
|
||||
a54fb4960ff0762738f4895cdc29bf2715a57f87
|
||||
5
.github/CODEOWNERS
vendored
5
.github/CODEOWNERS
vendored
@@ -1,5 +0,0 @@
|
||||
* @takezoe
|
||||
|
||||
build.sbt @xuwei-k
|
||||
project/* @xuwei-k
|
||||
.github/workflows/* @xuwei-k
|
||||
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,6 @@
|
||||
# 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.
|
||||
- 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.
|
||||
- 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.
|
||||
|
||||
18
.github/ISSUE_TEMPLATE.md
vendored
Normal file
18
.github/ISSUE_TEMPLATE.md
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
### Before submitting an issue to GitBucket I have first:
|
||||
|
||||
- [ ] read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
||||
- [ ] searched for similar already existing issue
|
||||
- [ ] read the documentation and [wiki](https://github.com/gitbucket/gitbucket/wiki)
|
||||
|
||||
*(if you have performed all the above, remove the paragraph and continue describing the issue with template below)*
|
||||
|
||||
## Issue
|
||||
**Impacted version**: xxxx
|
||||
|
||||
**Deployment mode**: *explain here how you use GitBucket : standalone app, under webcontainer (which one), with an http frontend (nginx, httpd, ...)*
|
||||
|
||||
**Problem description**:
|
||||
- *be as explicit has you can*
|
||||
- *describe the problem and its symptoms*
|
||||
- *explain how to reproduce*
|
||||
- *attach whatever information that can help understanding the context (screen capture, log files)*
|
||||
1
.github/ISSUE_TEMPLATE/config.yml
vendored
1
.github/ISSUE_TEMPLATE/config.yml
vendored
@@ -1 +0,0 @@
|
||||
blank_issues_enabled: false
|
||||
41
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
41
.github/ISSUE_TEMPLATE/issue_template.yml
vendored
@@ -1,41 +0,0 @@
|
||||
name: Report issue
|
||||
description: Report a problem or feature request with GitBucket
|
||||
body:
|
||||
- type: markdown
|
||||
attributes:
|
||||
value: |
|
||||
### Before submitting an issue to GitBucket, please ensure you have:
|
||||
- Read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
||||
- Searched for similar existing issues
|
||||
- Read the documentation and [wiki](https://github.com/gitbucket/gitbucket/wiki)
|
||||
- You can use [Gitter chat room](https://gitter.im/gitbucket/gitbucket) instead of GitHub Issues for casual discussion or inquiry
|
||||
|
||||
- type: checkboxes
|
||||
id: prerequisites
|
||||
attributes:
|
||||
label: Prerequisites
|
||||
options:
|
||||
- label: I have read the contribution guidelines
|
||||
- label: I have searched for similar issues
|
||||
- label: I have read the documentation and wiki
|
||||
|
||||
- type: input
|
||||
id: impacted_version
|
||||
attributes:
|
||||
label: Impacted version
|
||||
description: Which version of GitBucket is affected?
|
||||
placeholder: e.g. 4.37.0
|
||||
|
||||
- type: input
|
||||
id: deployment_mode
|
||||
attributes:
|
||||
label: Deployment mode
|
||||
description: How do you use GitBucket? (standalone app, under webcontainer, with an HTTP frontend, etc.)
|
||||
placeholder: e.g. Standalone app, Tomcat, nginx
|
||||
|
||||
- type: textarea
|
||||
id: problem_description
|
||||
attributes:
|
||||
label: Problem description
|
||||
description: Be as explicit as you can. Describe the problem, its symptoms, how to reproduce, and attach any relevant information (screenshots, logs, etc.)
|
||||
placeholder: Describe the problem and how to reproduce it
|
||||
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"
|
||||
33
.github/workflows/build.yml
vendored
33
.github/workflows/build.yml
vendored
@@ -1,42 +1,29 @@
|
||||
name: build
|
||||
|
||||
on: [push, pull_request]
|
||||
on:
|
||||
push:
|
||||
branches: [ master ]
|
||||
pull_request:
|
||||
branches: [ master ]
|
||||
|
||||
jobs:
|
||||
build:
|
||||
runs-on: ubuntu-latest
|
||||
timeout-minutes: 30
|
||||
strategy:
|
||||
fail-fast: false
|
||||
matrix:
|
||||
java: [17, 21]
|
||||
java: [8, 11]
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- name: Cache
|
||||
uses: actions/cache@v4
|
||||
env:
|
||||
cache-name: cache-sbt-libs
|
||||
with:
|
||||
path: |
|
||||
~/.ivy2/cache
|
||||
~/.sbt
|
||||
~/.cache/coursier/v1
|
||||
key: build-${{ env.cache-name }}-${{ hashFiles('build.sbt') }}
|
||||
- uses: actions/checkout@v2
|
||||
- name: Set up JDK
|
||||
uses: actions/setup-java@v4
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: ${{ matrix.java }}
|
||||
distribution: adopt
|
||||
- name: Setup sbt launcher
|
||||
uses: sbt/setup-sbt@v1
|
||||
- name: Run tests
|
||||
run: sbt scalafmtSbtCheck scalafmtCheckAll test
|
||||
- name: Scala 3
|
||||
run: sbt '++ 3.x' update # TODO
|
||||
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
||||
- name: Build executable
|
||||
run: sbt executable
|
||||
- name: Upload artifacts
|
||||
uses: actions/upload-artifact@v4
|
||||
uses: actions/upload-artifact@v2
|
||||
with:
|
||||
name: gitbucket-java${{ matrix.java }}-${{ github.sha }}
|
||||
path: ./target/executable/gitbucket.*
|
||||
|
||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -2,9 +2,6 @@
|
||||
*.log
|
||||
.ensime
|
||||
.ensime_cache
|
||||
.DS_Store
|
||||
.java-version
|
||||
.tmp
|
||||
|
||||
# sbt specific
|
||||
dist/*
|
||||
@@ -13,7 +10,6 @@ lib_managed/
|
||||
src_managed/
|
||||
project/boot/
|
||||
project/plugins/project/
|
||||
.bsp/
|
||||
|
||||
# Scala-IDE specific
|
||||
.scala_dependencies
|
||||
@@ -32,8 +28,4 @@ project/plugins/project/
|
||||
# Metals specific
|
||||
.metals
|
||||
.bloop
|
||||
**/metals.sbt
|
||||
|
||||
# Visual Studio Code specific
|
||||
.vscode
|
||||
|
||||
project/metals.sbt
|
||||
@@ -1,8 +0,0 @@
|
||||
updates.limit = 3
|
||||
|
||||
updates.includeScala = true
|
||||
|
||||
updates.pin = [
|
||||
{ groupId = "org.eclipse.jetty", version = "10." }
|
||||
{ groupId = "org.mariadb.jdbc", version = "2." }
|
||||
]
|
||||
@@ -1,24 +1,12 @@
|
||||
version = "3.9.9"
|
||||
version = "1.5.1"
|
||||
project.git = true
|
||||
|
||||
maxColumn = 120
|
||||
docstrings.style = keep
|
||||
docstrings = JavaDoc
|
||||
|
||||
align.tokens = ["%", "%%", {code = "=>", owner = "Case"}]
|
||||
align.openParenCallSite = false
|
||||
align.openParenDefnSite = false
|
||||
continuationIndent.callSite = 2
|
||||
continuationIndent.defnSite = 2
|
||||
danglingParentheses.preset = true
|
||||
runner.dialect = scala213source3
|
||||
rewrite.trailingCommas.style = keep
|
||||
fileOverride {
|
||||
"glob:**/*.sbt" {
|
||||
runner.dialect = scala212
|
||||
rewrite.scala3.convertToNewSyntax = false
|
||||
}
|
||||
}
|
||||
rewrite.scala3.convertToNewSyntax = true
|
||||
runner.dialectOverride.allowSignificantIndentation = false
|
||||
runner.dialectOverride.allowAsForImportRename = false
|
||||
runner.dialectOverride.allowStarWildcardImport = false
|
||||
danglingParentheses = true
|
||||
|
||||
163
CHANGELOG.md
163
CHANGELOG.md
@@ -1,162 +1,15 @@
|
||||
# Changelog
|
||||
All changes to the project will be documented in this file.
|
||||
|
||||
## 4.43.0 - 29 Jun 2025
|
||||
- Upgrade H2 database from 1.x to 2.x
|
||||
### 4.33.0 - 31 Dec 2019
|
||||
|
||||
Note that upgrading from h2 1.x to 2.x requires data file migration: https://www.h2database.com/html/migration-to-v2.html
|
||||
|
||||
It can't be done automatically using GitBucket's auto migration mechanism because it relies on database itself. So, users who use h2 will have to dump and recreate their database manually with the following steps:
|
||||
```bash
|
||||
# Export database using the current version of H2
|
||||
$ curl -O https://repo1.maven.org/maven2/com/h2database/h2/1.4.199/h2-1.4.199.jar
|
||||
$ java -cp h2-1.4.199.jar org.h2.tools.Script -url "jdbc:h2:~/.gitbucket/data" -user sa -password sa -script dump.sql
|
||||
|
||||
# Recreate database using the new version of H2
|
||||
$ curl -O https://repo1.maven.org/maven2/com/h2database/h2/2.3.232/h2-2.3.232.jar
|
||||
$ java -cp h2-2.3.232.jar org.h2.tools.RunScript -url "jdbc:h2:~/.gitbucket/data" -user sa -password sa -script dump.sql
|
||||
```
|
||||
|
||||
In addition, if `~/.gitbucket/database.conf` has the following configuration, remove `;MVCC=true` from `url`.
|
||||
```
|
||||
db {
|
||||
url = "jdbc:h2:${DatabaseHome};MVCC=true" // => "jdbc:h2:${DatabaseHome}"
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
## 4.42.1 - 20 Jan 2025
|
||||
- Fix LDAP issue with SSL
|
||||
|
||||
## 4.42.0 - 30 Dec 2024
|
||||
- Increase max branch name length 100 -> 255
|
||||
- Fix some GitHub incompatible Web APIs
|
||||
- Apply user-defined CSS after all plugins
|
||||
- Improve performance of listing commit logs
|
||||
- Drop Java 11 support. Java 17 is now required
|
||||
|
||||
## 4.41.0 - 18 May 2024
|
||||
- Simplify pull request UI
|
||||
- Keyword search for issues and pull requests
|
||||
- New settings for max files and lines limit in showing diff
|
||||
- Adjust the default branch automatically when cloning external repository
|
||||
- Fix layout of branch selector
|
||||
- Performance improvement for listing branches
|
||||
- Upgrade internal libraries
|
||||
|
||||
## 4.40.0 - 22 Oct 2023
|
||||
- Configurable default branch name
|
||||
- Support custom fields of issues and pull requests in search condition
|
||||
- Create pull request from default branch of forked repositories
|
||||
- News feed shows activities of all visible repositories
|
||||
- Drop Java 8 support
|
||||
- Improve git push performance
|
||||
|
||||
## 4.39.0 - 29 Apr 2023
|
||||
- Support enum type in custom fields of Issues and Pull requests
|
||||
- Hide large diffs by default
|
||||
- Add new options to make it possible to run GitBucket using multiple machines
|
||||
- Fix many API issues
|
||||
|
||||
## 4.38.4 - 2 Nov 2022
|
||||
- Downgrade MariaDB JDBC drive to avoid unknown error
|
||||
|
||||
## 4.38.3 - 30 Oct 2022
|
||||
- Fix several issues around multiple assignees in issues and pull requests
|
||||
- Fix IllegalStateException when returning unknown avatar image
|
||||
|
||||
## 4.38.2 - 20 Sep 2022
|
||||
- Resurrect assignee icons on the issue list
|
||||
|
||||
## 4.38.1 - 10 Sep 2022
|
||||
- Fix comment diff in Chrome 105
|
||||
- Fix Markdown table CSS
|
||||
- Fix HTML rendering of multiple asignees
|
||||
|
||||
## 4.38.0 - 3 Sep 2022
|
||||
- Support multiple assignees for Issues and Pull requests
|
||||
- Custom fields for issues and pull requests
|
||||
- Reset password by users
|
||||
- Allow to configure Jetty idle timeout in standalone mode
|
||||
- Horizontal scroll for too wide tables in Markdown
|
||||
- Hide header content on signin and register page
|
||||
- Fix the default charset of the online editor in the repository viewer
|
||||
- Fix the milestone count
|
||||
- Some improvements and bugfixes for WebAPI and WebHook
|
||||
|
||||
## 4.37.2 - 16 Jan 2022
|
||||
- Fixed a security issue reported by [Positive Technologies](https://www.ptsecurity.com/ww-en/). Great thanks for their detailed report and close support!
|
||||
|
||||
## 4.37.1 - 14 Dec 2021
|
||||
- Update gist-plugin and notification-plugin
|
||||
- Fix SSHCommand extension point for apache-sshd 2.x
|
||||
|
||||
## 4.37.0 - 11 Dec 2021
|
||||
- Enhance Git Reference APIs
|
||||
- Add milestone data to issue list API
|
||||
- Support "all" in issue list API
|
||||
- Support EDDSA in signed commit verification
|
||||
- Support custom SSH url
|
||||
- Relax max passward length limitation
|
||||
- Relax max webhook url length limitation
|
||||
|
||||
## 4.36.2 - 16 Aug 2021
|
||||
- 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
|
||||
- Folding pull request files
|
||||
- WebHook security options
|
||||
- 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
|
||||
- Draft pull request
|
||||
- Drop network installation of plugins
|
||||
@@ -164,20 +17,20 @@ db {
|
||||
- Apply default priority to pull requests
|
||||
- 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
|
||||
|
||||
## 4.31.1 - 17 Mar 2019
|
||||
### 4.31.1 - 17 Mar 2019
|
||||
- Bug fix
|
||||
|
||||
## 4.31.0 - 17 Mar 2019
|
||||
### 4.31.0 - 17 Mar 2019
|
||||
- Docker support in CI plugin
|
||||
- Verify GPG key signed commit
|
||||
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
||||
- OGP (Open Graph protocol) support
|
||||
- Username completion with avatars
|
||||
|
||||
## 4.30.1 - 22 Dec 2018
|
||||
### 4.30.1 - 22 Dec 2018
|
||||
- Bug fix for several WebHooks and Web API
|
||||
|
||||
## 4.30.0 - 15 Dec 2018
|
||||
@@ -264,7 +117,7 @@ db {
|
||||
- Submodule links to web page
|
||||
- Clarify close/reopen button
|
||||
|
||||
## 4.20.0 - 23 Dec 2017
|
||||
# 4.20.0 - 23 Dec 2017
|
||||
- Squash and rebase merge strategy for pull requests
|
||||
- Quick pull request creation
|
||||
- Download patch from the diff view
|
||||
|
||||
49
README.md
49
README.md
@@ -1,4 +1,4 @@
|
||||
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/actions/workflows/build.yml) [](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
|
||||
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/actions?query=workflow%3Abuild+branch%3Amaster) [](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/gitbucket_2.13) [](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
|
||||
=========
|
||||
|
||||
GitBucket is a Git web platform powered by Scala offering:
|
||||
@@ -8,7 +8,7 @@ GitBucket is a Git web platform powered by Scala offering:
|
||||
- High extensibility by plugins
|
||||
- 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/).
|
||||
|
||||
Features
|
||||
--------
|
||||
@@ -22,14 +22,16 @@ The current version of GitBucket provides many features such as:
|
||||
- Account and group management with LDAP integration
|
||||
- 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
|
||||
--------
|
||||
GitBucket requires **Java 17**. 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.
|
||||
|
||||
1. Download the latest **gitbucket.war** from [the releases page](https://github.com/gitbucket/gitbucket/releases) and run it by `java -jar gitbucket.war`.
|
||||
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
|
||||
|
||||
You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc). Note that GitBucket doesn't support Jakarta EE yet.
|
||||
You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc)
|
||||
|
||||
For more information about installation on Mac or Windows Server (with IIS), or configuration of Apache or Nginx and also integration with other tools or services such as Jenkins or Slack, see [Wiki](https://github.com/gitbucket/gitbucket/wiki).
|
||||
|
||||
@@ -46,43 +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/).
|
||||
|
||||
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
|
||||
--------
|
||||
|
||||
- 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 chat 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.
|
||||
|
||||
What's New in 4.43.x
|
||||
What's New in 4.33.x
|
||||
-------------
|
||||
## 4.43.0 - 29 Jun 2025
|
||||
- Upgrade H2 database from 1.x to 2.x
|
||||
### 4.33.0 - 31 Dec 2019
|
||||
|
||||
Note that upgrading from h2 1.x to 2.x requires data file migration: https://www.h2database.com/html/migration-to-v2.html
|
||||
- All CLI options are configurable by environment variables
|
||||
- Folding pull request files
|
||||
- WebHook security options
|
||||
- Add assignee and assignees properties to some Web APIs' response
|
||||
|
||||
It can't be done automatically using GitBucket's auto migration mechanism because it relies on database itself. So, users who use h2 will have to dump and recreate their database manually with the following steps:
|
||||
```bash
|
||||
# Export database using the current version of H2
|
||||
$ curl -O https://repo1.maven.org/maven2/com/h2database/h2/1.4.199/h2-1.4.199.jar
|
||||
$ java -cp h2-1.4.199.jar org.h2.tools.Script -url "jdbc:h2:~/.gitbucket/data" -user sa -password sa -script dump.sql
|
||||
|
||||
# Recreate database using the new version of H2
|
||||
$ curl -O https://repo1.maven.org/maven2/com/h2database/h2/2.3.232/h2-2.3.232.jar
|
||||
$ java -cp h2-2.3.232.jar org.h2.tools.RunScript -url "jdbc:h2:~/.gitbucket/data" -user sa -password sa -script dump.sql
|
||||
```
|
||||
|
||||
In addition, if `~/.gitbucket/database.conf` has the following configuration, remove `;MVCC=true` from `url`.
|
||||
```
|
||||
db {
|
||||
url = "jdbc:h2:${DatabaseHome};MVCC=true" // => "jdbc:h2:${DatabaseHome}"
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
See the [change log](CHANGELOG.md) for all the past updates.
|
||||
See the [change log](CHANGELOG.md) for all of the updates.
|
||||
|
||||
218
build.sbt
218
build.sbt
@@ -1,108 +1,97 @@
|
||||
import com.jsuereth.sbtpgp.PgpKeys._
|
||||
import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
|
||||
import com.typesafe.sbt.pgp.PgpKeys._
|
||||
|
||||
val Organization = "io.github.gitbucket"
|
||||
val Name = "gitbucket"
|
||||
val GitBucketVersion = "4.43.0"
|
||||
val ScalatraVersion = "3.1.2"
|
||||
val JettyVersion = "10.0.25"
|
||||
val JgitVersion = "6.10.1.202505221210-r"
|
||||
val GitBucketVersion = "4.33.0"
|
||||
val ScalatraVersion = "2.7.0-RC1"
|
||||
val JettyVersion = "9.4.30.v20200611"
|
||||
val JgitVersion = "5.8.0.202006091008-r"
|
||||
|
||||
lazy val root = (project in file("."))
|
||||
.enablePlugins(SbtTwirl, ContainerPlugin)
|
||||
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
||||
.settings(
|
||||
)
|
||||
|
||||
sourcesInBase := false
|
||||
organization := Organization
|
||||
name := Name
|
||||
version := GitBucketVersion
|
||||
scalaVersion := "2.13.16"
|
||||
scalaVersion := "2.13.1"
|
||||
|
||||
crossScalaVersions += "3.7.2"
|
||||
|
||||
// scalafmtOnCompile := true
|
||||
scalafmtOnCompile := true
|
||||
|
||||
coverageExcludedPackages := ".*\\.html\\..*"
|
||||
|
||||
// dependency settings
|
||||
resolvers ++= Seq(
|
||||
Classpaths.typesafeReleases,
|
||||
Resolver.jcenterRepo,
|
||||
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||
)
|
||||
|
||||
libraryDependencies ++= Seq(
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
||||
"org.scalatra" %% "scalatra-javax" % ScalatraVersion,
|
||||
"org.scalatra" %% "scalatra-json-javax" % ScalatraVersion,
|
||||
"org.scalatra" %% "scalatra-forms-javax" % ScalatraVersion,
|
||||
"org.json4s" %% "json4s-jackson" % "4.1.0-M8",
|
||||
"commons-io" % "commons-io" % "2.20.0",
|
||||
"io.github.gitbucket" % "solidbase" % "1.1.0",
|
||||
"io.github.gitbucket" % "markedj" % "1.0.20",
|
||||
"org.tukaani" % "xz" % "1.10",
|
||||
"org.apache.commons" % "commons-compress" % "1.28.0",
|
||||
"org.apache.commons" % "commons-email" % "1.6.0",
|
||||
"commons-net" % "commons-net" % "3.12.0",
|
||||
"org.apache.httpcomponents" % "httpclient" % "4.5.14",
|
||||
"org.apache.sshd" % "apache-sshd" % "2.15.0" exclude ("org.slf4j", "slf4j-jdk14") exclude (
|
||||
"org.apache.sshd",
|
||||
"sshd-mina"
|
||||
) exclude ("org.apache.sshd", "sshd-netty")
|
||||
exclude ("org.apache.sshd", "sshd-spring-sftp"),
|
||||
"org.apache.tika" % "tika-core" % "3.2.2",
|
||||
"com.github.takezoe" %% "blocking-slick" % "0.0.14",
|
||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||
"com.h2database" % "h2" % "2.3.232",
|
||||
"org.mariadb.jdbc" % "mariadb-java-client" % "2.7.12",
|
||||
"org.postgresql" % "postgresql" % "42.7.7",
|
||||
"ch.qos.logback" % "logback-classic" % "1.5.18",
|
||||
"com.zaxxer" % "HikariCP" % "7.0.1" exclude ("org.slf4j", "slf4j-api"),
|
||||
"com.typesafe" % "config" % "1.4.4",
|
||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
||||
"io.github.java-diff-utils" % "java-diff-utils" % "4.16",
|
||||
"org.cache2k" % "cache2k-all" % "1.6.0.Final",
|
||||
"net.coobird" % "thumbnailator" % "0.4.20",
|
||||
"com.github.zafarkhaja" % "java-semver" % "0.10.2",
|
||||
"com.nimbusds" % "oauth2-oidc-sdk" % "11.27",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||
"junit" % "junit" % "4.13.2" % "test",
|
||||
"org.scalatra" %% "scalatra-scalatest-javax" % ScalatraVersion % "test",
|
||||
"org.mockito" % "mockito-core" % "5.18.0" % "test",
|
||||
"com.dimafeng" %% "testcontainers-scala" % "0.43.0" % "test",
|
||||
"org.testcontainers" % "mysql" % "1.21.3" % "test",
|
||||
"org.testcontainers" % "postgresql" % "1.21.3" % "test",
|
||||
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
||||
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
||||
"org.ec4j.core" % "ec4j-core" % "1.1.1",
|
||||
"org.kohsuke" % "github-api" % "1.329" % "test"
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
||||
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
||||
"org.scalatra" %% "scalatra-forms" % ScalatraVersion,
|
||||
"org.json4s" %% "json4s-jackson" % "3.6.9",
|
||||
"commons-io" % "commons-io" % "2.7",
|
||||
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
||||
"io.github.gitbucket" % "markedj" % "1.0.16",
|
||||
"org.apache.commons" % "commons-compress" % "1.20",
|
||||
"org.apache.commons" % "commons-email" % "1.5",
|
||||
"commons-net" % "commons-net" % "3.6",
|
||||
"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.tika" % "tika-core" % "1.24.1",
|
||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12",
|
||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||
"com.h2database" % "h2" % "1.4.199",
|
||||
"org.mariadb.jdbc" % "mariadb-java-client" % "2.6.0",
|
||||
"org.postgresql" % "postgresql" % "42.2.6",
|
||||
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
||||
"com.zaxxer" % "HikariCP" % "3.4.5",
|
||||
"com.typesafe" % "config" % "1.4.0",
|
||||
"com.typesafe.akka" %% "akka-actor" % "2.5.27",
|
||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
||||
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
||||
"org.cache2k" % "cache2k-all" % "1.2.4.Final",
|
||||
"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.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||
"junit" % "junit" % "4.13" % "test",
|
||||
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
||||
"org.mockito" % "mockito-core" % "3.3.3" % "test",
|
||||
"com.dimafeng" %% "testcontainers-scala" % "0.37.0" % "test",
|
||||
"org.testcontainers" % "mysql" % "1.14.3" % "test",
|
||||
"org.testcontainers" % "postgresql" % "1.14.3" % "test",
|
||||
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
||||
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
||||
"org.ec4j.core" % "ec4j-core" % "0.0.3"
|
||||
)
|
||||
|
||||
// Compiler settings
|
||||
scalacOptions := Seq(
|
||||
"-deprecation",
|
||||
"-language:postfixOps",
|
||||
"-opt:l:method",
|
||||
"-feature",
|
||||
"-Wunused:imports",
|
||||
"-Wconf:cat=unused&src=twirl/.*:s,cat=unused&src=scala/gitbucket/core/model/[^/]+\\.scala:s"
|
||||
)
|
||||
scalacOptions ++= {
|
||||
scalaBinaryVersion.value match {
|
||||
case "2.13" =>
|
||||
Seq("-Xsource:3-cross")
|
||||
case _ =>
|
||||
Nil
|
||||
}
|
||||
}
|
||||
compile / javacOptions ++= Seq("-target", "11", "-source", "11")
|
||||
Container / javaOptions += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
|
||||
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
||||
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||
|
||||
// Test settings
|
||||
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
||||
Test / javaOptions += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
||||
Test / testOptions += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
||||
Test / fork := true
|
||||
javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
||||
testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
||||
fork in Test := true
|
||||
|
||||
// Packaging options
|
||||
packageOptions += Package.MainClass("JettyLauncher")
|
||||
|
||||
// Assembly settings
|
||||
assembly / test := {}
|
||||
assembly / assemblyMergeStrategy := {
|
||||
test in assembly := {}
|
||||
assemblyMergeStrategy in assembly := {
|
||||
case PathList("META-INF", xs @ _*) =>
|
||||
(xs map { _.toLowerCase }) match {
|
||||
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
||||
@@ -113,8 +102,8 @@ assembly / assemblyMergeStrategy := {
|
||||
|
||||
// Exclude a war file from published artifacts
|
||||
signedArtifacts := {
|
||||
signedArtifacts.value.filterNot { case (_, file) =>
|
||||
file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
|
||||
signedArtifacts.value.filterNot {
|
||||
case (_, file) => file.getName.endsWith(".war") || file.getName.endsWith(".war.asc")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,22 +111,17 @@ signedArtifacts := {
|
||||
val ExecutableConfig = config("executable").hide
|
||||
Keys.ivyConfigurations += ExecutableConfig
|
||||
libraryDependencies ++= Seq(
|
||||
"org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-io" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
|
||||
"org.eclipse.jetty" % "jetty-security" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-continuation" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-server" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-xml" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-http" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-servlet" % JettyVersion % "executable",
|
||||
"org.eclipse.jetty" % "jetty-io" % 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")
|
||||
executableKey := {
|
||||
import java.util.jar.Attributes.{Name => AttrName}
|
||||
@@ -156,11 +140,9 @@ executableKey := {
|
||||
// include jetty classes
|
||||
val jettyJars = Keys.update.value select configurationFilter(name = ExecutableConfig.name)
|
||||
jettyJars foreach { jar =>
|
||||
IO unzip (
|
||||
jar,
|
||||
temp,
|
||||
(name: String) => (name startsWith "javax/") || (name startsWith "org/") || (name startsWith "META-INF/services/")
|
||||
)
|
||||
IO unzip (jar, temp, (name: String) =>
|
||||
(name startsWith "javax/") ||
|
||||
(name startsWith "org/"))
|
||||
}
|
||||
|
||||
// include original war file
|
||||
@@ -168,7 +150,7 @@ executableKey := {
|
||||
IO unzip (warFile, temp)
|
||||
|
||||
// include launcher classes
|
||||
val classDir = (Compile / Keys.classDirectory).value
|
||||
val classDir = (Keys.classDirectory in Compile).value
|
||||
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
||||
launchClasses foreach { name =>
|
||||
IO copyFile (classDir / name, temp / name)
|
||||
@@ -185,7 +167,7 @@ executableKey := {
|
||||
val url = "https://github.com/" +
|
||||
s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
|
||||
log info s"Download: ${url}"
|
||||
IO transfer (new java.net.URI(url).toURL.openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
||||
IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
||||
case _ => ()
|
||||
}
|
||||
}
|
||||
@@ -199,16 +181,17 @@ executableKey := {
|
||||
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
||||
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
||||
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
|
||||
Seq(
|
||||
"md5" -> "MD5",
|
||||
"sha1" -> "SHA-1",
|
||||
"sha256" -> "SHA-256"
|
||||
).foreach { case (extension, algorithm) =>
|
||||
val checksumFile = workDir / (warName + "." + extension)
|
||||
Checksums generate (outputFile, checksumFile, algorithm)
|
||||
).foreach {
|
||||
case (extension, algorithm) =>
|
||||
val checksumFile = workDir / (warName + "." + extension)
|
||||
Checksums generate (outputFile, checksumFile, algorithm)
|
||||
}
|
||||
|
||||
// done
|
||||
@@ -216,9 +199,9 @@ executableKey := {
|
||||
outputFile
|
||||
}
|
||||
publishTo := {
|
||||
val centralSnapshots = "https://central.sonatype.com/repository/maven-snapshots/"
|
||||
if (isSnapshot.value) Some("central-snapshots" at centralSnapshots)
|
||||
else localStaging.value
|
||||
val nexus = "https://oss.sonatype.org/"
|
||||
if (version.value.trim.endsWith("SNAPSHOT")) Some("snapshots" at nexus + "content/repositories/snapshots")
|
||||
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
|
||||
}
|
||||
publishMavenStyle := true
|
||||
pomIncludeRepository := { _ =>
|
||||
@@ -270,7 +253,12 @@ pomExtra := (
|
||||
</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) {
|
||||
Seq(
|
||||
Tests.Exclude(
|
||||
@@ -283,13 +271,3 @@ Test / testOptions ++= {
|
||||
Nil
|
||||
}
|
||||
}
|
||||
|
||||
Container / javaOptions ++= Seq(
|
||||
"-Dlogback.configurationFile=/logback-dev.xml",
|
||||
"-Xdebug",
|
||||
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000",
|
||||
"-Dorg.eclipse.jetty.annotations.AnnotationParser.LEVEL=OFF",
|
||||
// "-Ddev-features=keep-session"
|
||||
)
|
||||
Container / containerLibs := Seq(("org.eclipse.jetty" % "jetty-runner" % JettyVersion).intransitive())
|
||||
Container / containerMain := "org.eclipse.jetty.runner.Runner"
|
||||
|
||||
@@ -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.
|
||||
|
||||
For example, in the case of `RepositoryViewerController`,
|
||||
For example, in the case of `RepositoryViwerController`,
|
||||
it references three authenticators: `ReadableUsersAuthenticator`, `ReferrerAuthenticator` and `CollaboratorsAuthenticator`.
|
||||
|
||||
```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
|
||||
- `ReferrerAuthenticator` provides `referrersOnly` method
|
||||
- `CollaboratorsAuthenticator` provides `collaboratorsOnly` method
|
||||
|
||||
These methods are available in each action as below:
|
||||
These methods are available in each actions as below:
|
||||
|
||||
```scala
|
||||
// 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) =>
|
||||
...
|
||||
})
|
||||
@@ -50,11 +50,11 @@ Currently, GitBucket provides below authenticators:
|
||||
|--------------------------|-----------------|--------------------------------------------------------------------------------------|
|
||||
|OneselfAuthenticator |oneselfOnly |Allows only oneself 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. |
|
||||
|CollaboratorsAuthenticator|collaboratorsOnly|Allows only collaborators 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. |
|
||||
|
||||
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.
|
||||
|
||||
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
|
||||
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 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>
|
||||
```
|
||||
|
||||
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)
|
||||
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).
|
||||
|
||||
25
doc/build.md
25
doc/build.md
@@ -1,7 +1,7 @@
|
||||
How to build and run from the source tree
|
||||
========
|
||||
|
||||
First of all, Install [sbt](https://www.scala-sbt.org/index.html).
|
||||
First of all, Install [sbt](http://www.scala-sbt.org/index.html).
|
||||
|
||||
```shell
|
||||
$ brew install sbt
|
||||
@@ -13,31 +13,17 @@ Run for Development
|
||||
If you want to test GitBucket, type the following command in the root directory of the source tree.
|
||||
|
||||
```shell
|
||||
$ sbt ~container:start
|
||||
$ sbt ~jetty:start
|
||||
```
|
||||
|
||||
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`.
|
||||
|
||||
Note that HttpSession is cleared when auto-reloading happened.
|
||||
This is a bit annoying when developing features that requires sign-in.
|
||||
You can keep HttpSession even if GitBucket is restarted by enabling this configuration in `build.sbt`:
|
||||
https://github.com/gitbucket/gitbucket/blob/3dcc0aee3c4413b05be7c03476626cb202674afc/build.sbt#L292
|
||||
|
||||
Or by launching GitBucket with the following command:
|
||||
```shell
|
||||
sbt '; set Container/javaOptions += "-Ddev-features=keep-session" ; ~container:start'
|
||||
```
|
||||
|
||||
Note that this feature serializes HttpSession on the local disk and assigns all requests to the same session
|
||||
which means you cannot test multi users behavior in this mode.
|
||||
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
|
||||
--------
|
||||
|
||||
To build a war file, run the following command:
|
||||
To build war file, run the following command:
|
||||
|
||||
```shell
|
||||
$ sbt package
|
||||
@@ -51,8 +37,7 @@ To build an executable war file, run
|
||||
$ sbt executable
|
||||
```
|
||||
|
||||
at the top of the source tree. It generates executable `gitbucket.war` into `target/executable`.
|
||||
We release this war file as release artifact.
|
||||
at the top of the source tree. It generates executable `gitbucket.war` into `target/executable`. We release this war file as release artifact.
|
||||
|
||||
Run tests spec
|
||||
---------
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
Debug GitBucket on IntelliJ
|
||||
========
|
||||
Add following configuration for allowing remote debugging to `build.sbt`:
|
||||
Add following configuration for allowing remote debugging to `buils.sbt`:
|
||||
|
||||
```scala
|
||||
javaOptions in Jetty ++= Seq(
|
||||
@@ -12,7 +12,7 @@ javaOptions in Jetty ++= Seq(
|
||||
Run GitBucket:
|
||||
|
||||
```shell
|
||||
$ sbt ~container:start
|
||||
$ sbt ~jetty:start
|
||||
```
|
||||
|
||||
In IntelliJ, create remote debug configuration as follows. Make sure port number is same as above configuration.
|
||||
|
||||
@@ -5,17 +5,13 @@ GitBucket persists all data into __HOME/.gitbucket__ in default (In 1.9 or befor
|
||||
This directory has following structure:
|
||||
|
||||
```
|
||||
* /HOME/.gitbucket
|
||||
* gitbucket.conf
|
||||
* database.conf
|
||||
* activity.log
|
||||
* data.mv.db, data.trace.db (H2 data files if the default embed H2 is used)
|
||||
* /HOME/gitbucket
|
||||
* /repositories
|
||||
* /USER_NAME
|
||||
* /REPO_NAME.git (substance of repository. GitServlet sees this directory)
|
||||
* /REPO_NAME.wiki.git (wiki repository)
|
||||
* /REPO_NAME
|
||||
* /issues (files attached to issue)
|
||||
* /issues (files which are attached to issue)
|
||||
* /lfs (LFS managed files)
|
||||
* /data
|
||||
* /USER_NAME
|
||||
@@ -24,8 +20,6 @@ This directory has following structure:
|
||||
* /plugins
|
||||
* plugin.jar
|
||||
* /.installed (copied available plugins from the parent directory automatically)
|
||||
* /sessions
|
||||
* HTTP session data created (if '--save_sessions' option is used in the standalone mode)
|
||||
* /tmp
|
||||
* /_upload
|
||||
* /SESSION_ID (removed at session timeout)
|
||||
|
||||
@@ -38,26 +38,15 @@ Generate release files
|
||||
|
||||
For plug-in development, we have to publish the GitBucket jar file to the Maven central repository before release GitBucket itself.
|
||||
|
||||
First, start the sbt shell:
|
||||
First, hit following command to publish artifacts to the sonatype OSS repository:
|
||||
|
||||
```bash
|
||||
$ sbt publishSigned
|
||||
```
|
||||
|
||||
Next, upload artifacts to Sonatype's Central Portal with the following command:
|
||||
Then logged-in to https://oss.sonatype.org/, close and release the repository.
|
||||
|
||||
```bash
|
||||
$ sbt sonaUpload
|
||||
```
|
||||
|
||||
Then logged-in to https://central.sonatype.com/ and publish the deployment.
|
||||
|
||||
You need to wait up to a day until default bundled plugins:
|
||||
|
||||
- https://github.com/gitbucket/gitbucket-notifications-plugin
|
||||
- https://github.com/gitbucket/gitbucket-gist-plugin
|
||||
- https://github.com/gitbucket/gitbucket-pages-plugin
|
||||
- https://github.com/gitbucket/gitbucket-emoji-plugin
|
||||
You need to wait up to a day until [gitbucket-notification-plugin](https://plugins.gitbucket-community.org/) which is default bundled plugin is built for new version of GitBucket.
|
||||
|
||||
### Make release war file
|
||||
|
||||
@@ -66,4 +55,5 @@ Run `sbt executable`. The release war file and fingerprint are generated into `t
|
||||
```bash
|
||||
$ sbt executable
|
||||
```
|
||||
|
||||
Create new release from the corresponded tag on GitHub, then upload generated jar file and fingerprints to the release.
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 112 KiB After Width: | Height: | Size: 203 KiB |
@@ -1,6 +1,6 @@
|
||||
Mapping and Validation
|
||||
========
|
||||
GitBucket uses [scalatra-forms](https://scalatra.org/guides/2.8/formats/forms.html) to validate request parameters and map them to the scala object. This is inspired by Play2 form mapping / validation.
|
||||
GitBucket uses [scalatra-forms](http://scalatra.org/guides/2.6/formats/forms.html) to validate request parameters and map them to the scala object. This is inspired by Play2 form mapping / validation.
|
||||
|
||||
At first, define the mapping as following:
|
||||
|
||||
|
||||
@@ -1 +1 @@
|
||||
sbt.version=1.11.4
|
||||
sbt.version=1.3.12
|
||||
|
||||
@@ -1,11 +1,10 @@
|
||||
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
||||
|
||||
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.5")
|
||||
addSbtPlugin("org.playframework.twirl" % "sbt-twirl" % "2.0.9")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.3.1")
|
||||
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
||||
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.3.1")
|
||||
addSbtPlugin("com.github.sbt" % "sbt-license-report" % "1.7.0")
|
||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.3.1")
|
||||
|
||||
addDependencyTreePlugin
|
||||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.0")
|
||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
||||
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
|
||||
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
|
||||
|
||||
@@ -1,107 +1,51 @@
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.server.ConnectionFactory;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.Handler;
|
||||
import org.eclipse.jetty.server.HttpConfiguration;
|
||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||
import org.eclipse.jetty.server.SecureRequestCustomizer;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.ServerConnector;
|
||||
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.server.handler.SecuredRedirectHandler;
|
||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||
import org.eclipse.jetty.server.session.FileSessionDataStore;
|
||||
import org.eclipse.jetty.server.session.SessionCache;
|
||||
import org.eclipse.jetty.server.session.SessionHandler;
|
||||
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.InetAddress;
|
||||
import java.net.URL;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.security.ProtectionDomain;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.function.Function;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static java.util.function.Function.identity;
|
||||
import static java.util.stream.Collectors.toSet;
|
||||
|
||||
public class JettyLauncher {
|
||||
|
||||
private interface Defaults {
|
||||
|
||||
String CONNECTORS = "http";
|
||||
String HOST = "0.0.0.0";
|
||||
|
||||
int HTTP_PORT = 8080;
|
||||
int HTTPS_PORT = 8443;
|
||||
|
||||
boolean REDIRECT_HTTPS = false;
|
||||
}
|
||||
|
||||
private interface Connectors {
|
||||
|
||||
String HTTP = "http";
|
||||
String HTTPS = "https";
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
|
||||
String connectors = getEnvironmentVariable("gitbucket.connectors");
|
||||
String host = getEnvironmentVariable("gitbucket.host");
|
||||
String port = getEnvironmentVariable("gitbucket.port");
|
||||
String securePort = getEnvironmentVariable("gitbucket.securePort");
|
||||
String keyStorePath = getEnvironmentVariable("gitbucket.keyStorePath");
|
||||
String keyStorePassword = getEnvironmentVariable("gitbucket.keyStorePassword");
|
||||
String keyManagerPassword = getEnvironmentVariable("gitbucket.keyManagerPassword");
|
||||
String redirectHttps = getEnvironmentVariable("gitbucket.redirectHttps");
|
||||
String contextPath = getEnvironmentVariable("gitbucket.prefix");
|
||||
String tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
||||
String jettyIdleTimeout = getEnvironmentVariable("gitbucket.jettyIdleTimeout");
|
||||
String host = null;
|
||||
String port = null;
|
||||
InetSocketAddress address = null;
|
||||
String contextPath = "/";
|
||||
String tmpDirPath="";
|
||||
boolean forceHttps = false;
|
||||
boolean saveSessions = false;
|
||||
|
||||
host = getEnvironmentVariable("gitbucket.host");
|
||||
port = getEnvironmentVariable("gitbucket.port");
|
||||
contextPath = getEnvironmentVariable("gitbucket.prefix");
|
||||
tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
||||
|
||||
for(String arg: args) {
|
||||
if (arg.equals("--save_sessions")) {
|
||||
if(arg.equals("--save_sessions")) {
|
||||
saveSessions = true;
|
||||
}
|
||||
if (arg.equals("--disable_news_feed")) {
|
||||
System.setProperty("gitbucket.disableNewsFeed", "true");
|
||||
}
|
||||
if (arg.equals("--disable_cache")) {
|
||||
System.setProperty("gitbucket.disableCache", "true");
|
||||
}
|
||||
if(arg.startsWith("--") && arg.contains("=")) {
|
||||
String[] dim = arg.split("=", 2);
|
||||
if(dim.length == 2) {
|
||||
String[] dim = arg.split("=");
|
||||
if(dim.length >= 2) {
|
||||
switch (dim[0]) {
|
||||
case "--connectors":
|
||||
connectors = dim[1];
|
||||
break;
|
||||
case "--host":
|
||||
host = dim[1];
|
||||
break;
|
||||
case "--port":
|
||||
port = dim[1];
|
||||
break;
|
||||
case "--secure_port":
|
||||
securePort = dim[1];
|
||||
break;
|
||||
case "--key_store_path":
|
||||
keyStorePath = dim[1];
|
||||
break;
|
||||
case "--key_store_password":
|
||||
keyStorePassword = dim[1];
|
||||
break;
|
||||
case "--key_manager_password":
|
||||
keyManagerPassword = dim[1];
|
||||
break;
|
||||
case "--redirect_https":
|
||||
redirectHttps = dim[1];
|
||||
break;
|
||||
case "--prefix":
|
||||
contextPath = dim[1];
|
||||
break;
|
||||
@@ -114,9 +58,6 @@ public class JettyLauncher {
|
||||
case "--plugin_dir":
|
||||
System.setProperty("gitbucket.pluginDir", dim[1]);
|
||||
break;
|
||||
case "--jetty_idle_timeout":
|
||||
jettyIdleTimeout = dim[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -126,74 +67,38 @@ public class JettyLauncher {
|
||||
contextPath = "/" + contextPath;
|
||||
}
|
||||
|
||||
final String hostName = InetAddress.getByName(fallback(host, Defaults.HOST)).getHostName();
|
||||
|
||||
final Server server = new Server();
|
||||
|
||||
final Set<String> connectorsSet = Stream.of(fallback(connectors, Defaults.CONNECTORS)
|
||||
.toLowerCase().split(",")).map(String::trim).collect(toSet());
|
||||
|
||||
final List<ServerConnector> connectorInstances = new ArrayList<>();
|
||||
|
||||
final HttpConfiguration httpConfig = new HttpConfiguration();
|
||||
httpConfig.setSendServerVersion(false);
|
||||
if (connectorsSet.contains(Connectors.HTTPS)) {
|
||||
httpConfig.setSecurePort(fallback(securePort, Defaults.HTTPS_PORT, Integer::parseInt));
|
||||
}
|
||||
if (jettyIdleTimeout != null && jettyIdleTimeout.trim().length() != 0) {
|
||||
httpConfig.setIdleTimeout(Long.parseLong(jettyIdleTimeout.trim()));
|
||||
if(host != null) {
|
||||
address = new InetSocketAddress(host, getPort(port));
|
||||
} else {
|
||||
httpConfig.setIdleTimeout(300000L); // default is 5min
|
||||
address = new InetSocketAddress(getPort(port));
|
||||
}
|
||||
|
||||
if (connectorsSet.contains(Connectors.HTTP)) {
|
||||
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
|
||||
connector.setHost(hostName);
|
||||
connector.setPort(fallback(port, Defaults.HTTP_PORT, Integer::parseInt));
|
||||
Server server = new Server(address);
|
||||
|
||||
connectorInstances.add(connector);
|
||||
// SelectChannelConnector connector = new SelectChannelConnector();
|
||||
// if(host != null) {
|
||||
// connector.setHost(host);
|
||||
// }
|
||||
// connector.setMaxIdleTime(1000 * 60 * 60);
|
||||
// connector.setSoLingerTime(-1);
|
||||
// connector.setPort(port);
|
||||
// server.addConnector(connector);
|
||||
|
||||
// Disabling Server header
|
||||
for (Connector connector : server.getConnectors()) {
|
||||
for (ConnectionFactory factory : connector.getConnectionFactories()) {
|
||||
if (factory instanceof HttpConnectionFactory) {
|
||||
((HttpConnectionFactory) factory).getHttpConfiguration().setSendServerVersion(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (connectorsSet.contains(Connectors.HTTPS)) {
|
||||
final SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
|
||||
|
||||
sslContextFactory.setKeyStorePath(requireNonNull(keyStorePath,
|
||||
"You must specify a path to an SSL keystore via the --key_store_path command line argument" +
|
||||
" or GITBUCKET_KEYSTOREPATH environment variable."));
|
||||
|
||||
sslContextFactory.setKeyStorePassword(requireNonNull(keyStorePassword,
|
||||
"You must specify a an SSL keystore password via the --key_store_password argument" +
|
||||
" or GITBUCKET_KEYSTOREPASSWORD environment variable."));
|
||||
|
||||
sslContextFactory.setKeyManagerPassword(requireNonNull(keyManagerPassword,
|
||||
"You must specify a key manager password via the --key_manager_password' argument" +
|
||||
" or GITBUCKET_KEYMANAGERPASSWORD environment variable."));
|
||||
|
||||
final HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
|
||||
httpsConfig.addCustomizer(new SecureRequestCustomizer());
|
||||
|
||||
final ServerConnector connector = new ServerConnector(server,
|
||||
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
|
||||
new HttpConnectionFactory(httpsConfig));
|
||||
|
||||
connector.setHost(hostName);
|
||||
connector.setPort(fallback(securePort, Defaults.HTTPS_PORT, Integer::parseInt));
|
||||
|
||||
connectorInstances.add(connector);
|
||||
}
|
||||
|
||||
require(!connectorInstances.isEmpty(),
|
||||
"No server connectors could be configured, please check your --connectors command line argument" +
|
||||
" or GITBUCKET_CONNECTORS environment variable.");
|
||||
|
||||
server.setConnectors(connectorInstances.toArray(new ServerConnector[0]));
|
||||
|
||||
WebAppContext context = new WebAppContext();
|
||||
|
||||
if(saveSessions) {
|
||||
File sessDir = new File(getGitBucketHome(), "sessions");
|
||||
if(!sessDir.exists()){
|
||||
mkdir(sessDir);
|
||||
sessDir.mkdirs();
|
||||
}
|
||||
SessionHandler sessions = context.getSessionHandler();
|
||||
SessionCache cache = new DefaultSessionCache(sessions);
|
||||
@@ -207,7 +112,7 @@ public class JettyLauncher {
|
||||
if(tmpDirPath == null || tmpDirPath.equals("")){
|
||||
tmpDir = new File(getGitBucketHome(), "tmp");
|
||||
if(!tmpDir.exists()){
|
||||
mkdir(tmpDir);
|
||||
tmpDir.mkdirs();
|
||||
}
|
||||
} else {
|
||||
tmpDir = new File(tmpDirPath);
|
||||
@@ -231,16 +136,13 @@ public class JettyLauncher {
|
||||
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
|
||||
context.setServer(server);
|
||||
context.setWar(location.toExternalForm());
|
||||
|
||||
final HandlerList handlers = new HandlerList();
|
||||
|
||||
if (fallback(redirectHttps, Defaults.REDIRECT_HTTPS, Boolean::parseBoolean)) {
|
||||
handlers.addHandler(new SecuredRedirectHandler());
|
||||
if (forceHttps) {
|
||||
context.setInitParameter("org.scalatra.ForceHttps", "true");
|
||||
}
|
||||
|
||||
handlers.addHandler(addStatisticsHandler(context));
|
||||
Handler handler = addStatisticsHandler(context);
|
||||
|
||||
server.setHandler(handlers);
|
||||
server.setHandler(handler);
|
||||
server.setStopAtShutdown(true);
|
||||
server.setStopTimeout(7_000);
|
||||
server.start();
|
||||
@@ -268,28 +170,11 @@ public class JettyLauncher {
|
||||
}
|
||||
}
|
||||
|
||||
private static <T, R> T fallback(R value, T defaultValue, Function<R, T> converter) {
|
||||
return value == null ? defaultValue : converter.apply(value);
|
||||
}
|
||||
|
||||
private static <T> T fallback(T value, T defaultValue) {
|
||||
return fallback(value, defaultValue, identity());
|
||||
}
|
||||
|
||||
private static void require(boolean condition, String message) {
|
||||
if (!condition) {
|
||||
throw new IllegalArgumentException(message);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> T requireNonNull(T value, String message) {
|
||||
require(value != null, message);
|
||||
return value;
|
||||
}
|
||||
|
||||
private static void mkdir(File dir) {
|
||||
if (!dir.mkdirs()) {
|
||||
throw new RuntimeException("Unable to create directory: " + dir);
|
||||
private static int getPort(String port){
|
||||
if(port == null) {
|
||||
return 8080;
|
||||
} else {
|
||||
return Integer.parseInt(port);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -20,15 +20,15 @@ public class PatchUtil {
|
||||
public static String apply(String source, String patch, FileHeader fh)
|
||||
throws IOException, PatchApplyException {
|
||||
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++)
|
||||
oldLines.add(rt.getString(i));
|
||||
List<String> newLines = new ArrayList<>(oldLines);
|
||||
List<String> newLines = new ArrayList<String>(oldLines);
|
||||
for (HunkHeader hh : fh.getHunks()) {
|
||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||
out.write(patch.getBytes("UTF-8"), hh.getStartOffset(), hh.getEndOffset() - hh.getStartOffset());
|
||||
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++)
|
||||
hunkLines.add(hrt.getString(i));
|
||||
int pos = 0;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
notifications:1.11.0
|
||||
gist:4.23.0
|
||||
notifications:1.8.0
|
||||
gist:4.18.0
|
||||
emoji:4.6.0
|
||||
pages:1.10.0
|
||||
pages:1.8.0
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
</appender>
|
||||
|
||||
<appender name="FILE" class="ch.qos.logback.core.FileAppender">
|
||||
<file>.tmp/gitbucket.log</file>
|
||||
<file>gitbucket.log</file>
|
||||
<encoder>
|
||||
<pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
|
||||
</encoder>
|
||||
@@ -23,4 +23,4 @@
|
||||
<logger name="scala.slick.jdbc.JdbcBackend.statement" level="DEBUG" />
|
||||
-->
|
||||
|
||||
</configuration>
|
||||
</configuration>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 3.0 KiB |
18
src/main/resources/update/gitbucket-core_4.0.sql
Normal file
18
src/main/resources/update/gitbucket-core_4.0.sql
Normal file
@@ -0,0 +1,18 @@
|
||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||
SELECT
|
||||
A.USER_NAME,
|
||||
A.REPOSITORY_NAME,
|
||||
A.ISSUE_ID,
|
||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT
|
||||
FROM ISSUE A
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) B
|
||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) C
|
||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID);
|
||||
@@ -237,7 +237,7 @@
|
||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_ID_FK1" baseTableName="ISSUE_ID" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- ISSUE_LABEL -->
|
||||
<!-- ISSUE_ID -->
|
||||
<!--================================================================================================-->
|
||||
<createTable tableName="ISSUE_LABEL">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
@@ -343,28 +343,4 @@
|
||||
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_PK" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH, CONTEXT"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_FK0" baseTableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" baseColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" referencedTableName="PROTECTED_BRANCH" referencedColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- ISSUE_OUTLINE_VIEW -->
|
||||
<!--================================================================================================-->
|
||||
<sql>
|
||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||
SELECT
|
||||
A.USER_NAME,
|
||||
A.REPOSITORY_NAME,
|
||||
A.ISSUE_ID,
|
||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT
|
||||
FROM ISSUE A
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) B
|
||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) C
|
||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
||||
</sql>
|
||||
|
||||
</changeSet>
|
||||
|
||||
26
src/main/resources/update/gitbucket-core_4.14.sql
Normal file
26
src/main/resources/update/gitbucket-core_4.14.sql
Normal file
@@ -0,0 +1,26 @@
|
||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||
|
||||
SELECT
|
||||
A.USER_NAME,
|
||||
A.REPOSITORY_NAME,
|
||||
A.ISSUE_ID,
|
||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT,
|
||||
COALESCE(D.ORDERING, 9999) AS PRIORITY
|
||||
|
||||
FROM ISSUE A
|
||||
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) B
|
||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) C
|
||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
||||
|
||||
LEFT OUTER JOIN PRIORITY D
|
||||
ON (A.PRIORITY_ID = D.PRIORITY_ID);
|
||||
@@ -35,28 +35,4 @@
|
||||
<column name="URL" type="varchar(200)" nullable="false"/>
|
||||
<column name="EVENT" type="varchar(30)" nullable="false"/>
|
||||
</createTable>
|
||||
|
||||
<sql>
|
||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||
SELECT
|
||||
A.USER_NAME,
|
||||
A.REPOSITORY_NAME,
|
||||
A.ISSUE_ID,
|
||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT,
|
||||
COALESCE(D.ORDERING, 9999) AS PRIORITY
|
||||
FROM ISSUE A
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) B
|
||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||
LEFT OUTER JOIN (
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||
) C
|
||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
||||
LEFT OUTER JOIN PRIORITY D
|
||||
ON (A.PRIORITY_ID = D.PRIORITY_ID);
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
@@ -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>
|
||||
@@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
||||
<modifyDataType columnName="URL" newDataType="varchar(400)" tableName="WEB_HOOK_EVENT"/>
|
||||
<modifyDataType columnName="URL" newDataType="varchar(400)" tableName="WEB_HOOK"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, URL" referencedTableName="WEB_HOOK" referencedColumnNames="USER_NAME, REPOSITORY_NAME, URL" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||
</changeSet>
|
||||
@@ -1,53 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<!--================================================================================================-->
|
||||
<!-- CUSTOM_FIELD -->
|
||||
<!--================================================================================================-->
|
||||
<createTable tableName="CUSTOM_FIELD">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="FIELD_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
||||
<column name="FIELD_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="FIELD_TYPE" type="varchar(100)" nullable="false"/>
|
||||
<column name="ENABLE_FOR_ISSUES" type="boolean" nullable="false"/>
|
||||
<column name="ENABLE_FOR_PULL_REQUESTS" type="boolean" nullable="false"/>
|
||||
</createTable>
|
||||
<addPrimaryKey constraintName="IDX_CUSTOM_FIELD_PK" tableName="CUSTOM_FIELD" columnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_CUSTOM_FIELD_FK0" baseTableName="CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- ISSUE_CUSTOM_FIELD -->
|
||||
<!--================================================================================================-->
|
||||
<createTable tableName="ISSUE_CUSTOM_FIELD">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="ISSUE_ID" type="int" nullable="false"/>
|
||||
<column name="FIELD_ID" type="int" nullable="false"/>
|
||||
<column name="VALUE" type="varchar(200)" nullable="true"/>
|
||||
</createTable>
|
||||
<addPrimaryKey constraintName="IDX_ISSUE_CUSTOM_FIELD_PK" tableName="ISSUE_CUSTOM_FIELD" columnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID, FIELD_ID"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_CUSTOM_FIELD_FK0" baseTableName="ISSUE_CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_CUSTOM_FIELD_FK1" baseTableName="ISSUE_CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID" referencedTableName="CUSTOM_FIELD" referencedColumnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID"/>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- ISSUE_ASSIGNEE -->
|
||||
<!--================================================================================================-->
|
||||
<createTable tableName="ISSUE_ASSIGNEE">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="ISSUE_ID" type="int" nullable="false"/>
|
||||
<column name="ASSIGNEE_USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
</createTable>
|
||||
<addPrimaryKey constraintName="IDX_ISSUE_ASSIGNEE_PK" tableName="ISSUE_ASSIGNEE" columnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNEE_USER_NAME"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_ASSIGNEE_FK0" baseTableName="ISSUE_ASSIGNEE" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
||||
<!--
|
||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_ASSIGNEE_FK1" baseTableName="ISSUE_ASSIGNEE" baseColumnNames="ASSIGNEE_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
||||
-->
|
||||
|
||||
<sql>
|
||||
INSERT INTO ISSUE_ASSIGNEE (USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNEE_USER_NAME)
|
||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNED_USER_NAME FROM ISSUE WHERE ASSIGNED_USER_NAME IS NOT NULL
|
||||
</sql>
|
||||
|
||||
<dropColumn tableName="ISSUE" columnName="ASSIGNED_USER_NAME"/>
|
||||
</changeSet>
|
||||
@@ -1,6 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<addColumn tableName="CUSTOM_FIELD">
|
||||
<column name="CONSTRAINTS" type="varchar(200)" nullable="true"/>
|
||||
</addColumn>
|
||||
</changeSet>
|
||||
@@ -1,20 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<dropForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_FK0" baseTableName="PROTECTED_BRANCH_REQUIRE_CONTEXT"/>
|
||||
<dropPrimaryKey constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_PK" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT"/>
|
||||
|
||||
<dropForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_FK0" baseTableName="PROTECTED_BRANCH"/>
|
||||
<dropPrimaryKey constraintName="IDX_PROTECTED_BRANCH_PK" tableName="PROTECTED_BRANCH"/>
|
||||
|
||||
<modifyDataType columnName="DEFAULT_BRANCH" newDataType="varchar(255)" tableName="REPOSITORY"/>
|
||||
<modifyDataType columnName="BRANCH" newDataType="varchar(255)" tableName="PULL_REQUEST"/>
|
||||
<modifyDataType columnName="REQUEST_BRANCH" newDataType="varchar(255)" tableName="PULL_REQUEST"/>
|
||||
<modifyDataType columnName="BRANCH" newDataType="varchar(255)" tableName="PROTECTED_BRANCH"/>
|
||||
<modifyDataType columnName="BRANCH" newDataType="varchar(255)" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT"/>
|
||||
|
||||
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_PK" tableName="PROTECTED_BRANCH" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_FK0" baseTableName="PROTECTED_BRANCH" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||
|
||||
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_PK" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH, CONTEXT"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_FK0" baseTableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" baseColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" referencedTableName="PROTECTED_BRANCH" referencedColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||
</changeSet>
|
||||
@@ -1,40 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<!--================================================================================================-->
|
||||
<!-- PROTECTED_BRANCH -->
|
||||
<!--================================================================================================-->
|
||||
<addColumn tableName="PROTECTED_BRANCH">
|
||||
<column name="REQUIRED_STATUS_CHECK" type="boolean" nullable="false" defaultValue="false"/>
|
||||
<column name="RESTRICTIONS" type="boolean" nullable="false" defaultValue="false"/>
|
||||
</addColumn>
|
||||
|
||||
<sql>
|
||||
UPDATE PROTECTED_BRANCH SET REQUIRED_STATUS_CHECK = TRUE
|
||||
WHERE EXISTS (SELECT * FROM PROTECTED_BRANCH_REQUIRE_CONTEXT
|
||||
WHERE PROTECTED_BRANCH.USER_NAME = PROTECTED_BRANCH_REQUIRE_CONTEXT.USER_NAME
|
||||
AND PROTECTED_BRANCH.REPOSITORY_NAME = PROTECTED_BRANCH_REQUIRE_CONTEXT.REPOSITORY_NAME
|
||||
AND PROTECTED_BRANCH.BRANCH = PROTECTED_BRANCH_REQUIRE_CONTEXT.BRANCH)
|
||||
</sql>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- PROTECTED_BRANCH_RESTRICTIONS_USER -->
|
||||
<!--================================================================================================-->
|
||||
<createTable tableName="PROTECTED_BRANCH_RESTRICTION">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="BRANCH" type="varchar(100)" nullable="false"/>
|
||||
<column name="ALLOWED_USER" type="varchar(255)" nullable="false"/>
|
||||
</createTable>
|
||||
|
||||
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_RESTRICTION_PK" tableName="PROTECTED_BRANCH_RESTRICTION" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH, ALLOWED_USER"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_RESTRICTION_FK0" baseTableName="PROTECTED_BRANCH_RESTRICTION" baseColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" referencedTableName="PROTECTED_BRANCH" referencedColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_RESTRICTION_FK1" baseTableName="PROTECTED_BRANCH_RESTRICTION" baseColumnNames="ALLOWED_USER" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
||||
|
||||
<!--================================================================================================-->
|
||||
<!-- PULL_REQUEST -->
|
||||
<!--================================================================================================-->
|
||||
<addColumn tableName="PULL_REQUEST">
|
||||
<column name="MERGED_COMMIT_IDS" type="text" nullable="true"/>
|
||||
</addColumn>
|
||||
|
||||
</changeSet>
|
||||
2
src/main/resources/update/gitbucket-core_4.7.sql
Normal file
2
src/main/resources/update/gitbucket-core_4.7.sql
Normal file
@@ -0,0 +1,2 @@
|
||||
-- DELETE COLLABORATORS IN GROUP REPOSITORIES
|
||||
DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE)
|
||||
@@ -30,9 +30,4 @@
|
||||
<dropColumn tableName="REPOSITORY" columnName="ENABLE_WIKI"/>
|
||||
<dropColumn tableName="REPOSITORY" columnName="ALLOW_WIKI_EDITING"/>
|
||||
<dropColumn tableName="REPOSITORY" columnName="ENABLE_ISSUES"/>
|
||||
|
||||
<!-- DELETE COLLABORATORS IN GROUP REPOSITORIES -->
|
||||
<sql>
|
||||
DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE)
|
||||
</sql>
|
||||
</changeSet>
|
||||
|
||||
@@ -2,6 +2,7 @@ import java.util.EnumSet
|
||||
import javax.servlet._
|
||||
|
||||
import gitbucket.core.controller.{ReleaseController, _}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.SystemSettingsService
|
||||
import gitbucket.core.servlet._
|
||||
import gitbucket.core.util.Directory
|
||||
|
||||
@@ -1,26 +1,16 @@
|
||||
package gitbucket.core
|
||||
|
||||
import java.io.FileOutputStream
|
||||
import java.nio.charset.StandardCharsets
|
||||
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}
|
||||
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 java.util.logging.Level
|
||||
import scala.util.Using
|
||||
import io.github.gitbucket.solidbase.migration.{SqlMigration, LiquibaseMigration}
|
||||
import io.github.gitbucket.solidbase.model.{Version, Module}
|
||||
|
||||
object GitBucketCoreModule
|
||||
extends Module(
|
||||
"gitbucket-core",
|
||||
new Version("4.0.0", new LiquibaseMigration("update/gitbucket-core_4.0.xml")),
|
||||
new Version(
|
||||
"4.0.0",
|
||||
new LiquibaseMigration("update/gitbucket-core_4.0.xml"),
|
||||
new SqlMigration("update/gitbucket-core_4.0.sql")
|
||||
),
|
||||
new Version("4.1.0"),
|
||||
new Version("4.2.0", new LiquibaseMigration("update/gitbucket-core_4.2.xml")),
|
||||
new Version("4.2.1"),
|
||||
@@ -28,7 +18,11 @@ object GitBucketCoreModule
|
||||
new Version("4.4.0"),
|
||||
new Version("4.5.0"),
|
||||
new Version("4.6.0", new LiquibaseMigration("update/gitbucket-core_4.6.xml")),
|
||||
new Version("4.7.0", new LiquibaseMigration("update/gitbucket-core_4.7.xml")),
|
||||
new Version(
|
||||
"4.7.0",
|
||||
new LiquibaseMigration("update/gitbucket-core_4.7.xml"),
|
||||
new SqlMigration("update/gitbucket-core_4.7.sql")
|
||||
),
|
||||
new Version("4.7.1"),
|
||||
new Version("4.8"),
|
||||
new Version("4.9.0", new LiquibaseMigration("update/gitbucket-core_4.9.xml")),
|
||||
@@ -37,7 +31,11 @@ object GitBucketCoreModule
|
||||
new Version("4.12.0"),
|
||||
new Version("4.12.1"),
|
||||
new Version("4.13.0"),
|
||||
new Version("4.14.0", new LiquibaseMigration("update/gitbucket-core_4.14.xml")),
|
||||
new Version(
|
||||
"4.14.0",
|
||||
new LiquibaseMigration("update/gitbucket-core_4.14.xml"),
|
||||
new SqlMigration("update/gitbucket-core_4.14.sql")
|
||||
),
|
||||
new Version("4.14.1"),
|
||||
new Version("4.15.0"),
|
||||
new Version("4.16.0"),
|
||||
@@ -67,61 +65,5 @@ object GitBucketCoreModule
|
||||
new Version("4.31.1"),
|
||||
new Version("4.31.2"),
|
||||
new Version("4.32.0", new LiquibaseMigration("update/gitbucket-core_4.32.xml")),
|
||||
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"),
|
||||
new Version("4.37.0", new LiquibaseMigration("update/gitbucket-core_4.37.xml")),
|
||||
new Version("4.37.1"),
|
||||
new Version("4.37.2"),
|
||||
new Version("4.38.0", new LiquibaseMigration("update/gitbucket-core_4.38.xml")),
|
||||
new Version("4.38.1"),
|
||||
new Version("4.38.2"),
|
||||
new Version("4.38.3"),
|
||||
new Version("4.38.4"),
|
||||
new Version("4.39.0", new LiquibaseMigration("update/gitbucket-core_4.39.xml")),
|
||||
new Version("4.40.0"),
|
||||
new Version("4.41.0"),
|
||||
new Version("4.42.0", new LiquibaseMigration("update/gitbucket-core_4.42.xml")),
|
||||
new Version("4.42.1"),
|
||||
new Version("4.43.0"),
|
||||
new Version("4.44.0", new LiquibaseMigration("update/gitbucket-core_4.44.xml"))
|
||||
) {
|
||||
java.util.logging.Logger.getLogger("liquibase").setLevel(Level.SEVERE)
|
||||
}
|
||||
new Version("4.33.0")
|
||||
)
|
||||
|
||||
@@ -1,6 +0,0 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
/**
|
||||
* https://developer.github.com/v3/issues/labels/#add-labels-to-an-issue
|
||||
*/
|
||||
case class AddLabelsToAnIssue(labels: Seq[String])
|
||||
@@ -6,7 +6,7 @@ import gitbucket.core.util.RepositoryName
|
||||
* https://developer.github.com/v3/repos/#get-branch
|
||||
* https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection
|
||||
*/
|
||||
case class ApiBranch(name: String, commit: ApiBranchCommit, protection: ApiBranchProtectionResponse)(
|
||||
case class ApiBranch(name: String, commit: ApiBranchCommit, protection: ApiBranchProtection)(
|
||||
repositoryName: RepositoryName
|
||||
) extends FieldSerializable {
|
||||
val _links =
|
||||
@@ -22,12 +22,3 @@ case class ApiBranchForList(
|
||||
name: String,
|
||||
commit: ApiBranchCommit
|
||||
)
|
||||
|
||||
/**
|
||||
* https://docs.github.com/en/rest/reference/repos#list-branches-for-head-commit
|
||||
*/
|
||||
case class ApiBranchForHeadCommit(
|
||||
name: String,
|
||||
commit: ApiBranchCommit,
|
||||
`protected`: Boolean
|
||||
)
|
||||
|
||||
54
src/main/scala/gitbucket/core/api/ApiBranchProtection.scala
Normal file
54
src/main/scala/gitbucket/core/api/ApiBranchProtection.scala
Normal file
@@ -0,0 +1,54 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
import gitbucket.core.service.ProtectedBranchService
|
||||
import org.json4s._
|
||||
|
||||
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
||||
case class ApiBranchProtection(enabled: Boolean, required_status_checks: Option[ApiBranchProtection.Status]) {
|
||||
def status: ApiBranchProtection.Status = required_status_checks.getOrElse(ApiBranchProtection.statusNone)
|
||||
}
|
||||
|
||||
object ApiBranchProtection {
|
||||
|
||||
/** form for enabling-and-disabling-branch-protection */
|
||||
case class EnablingAndDisabling(protection: ApiBranchProtection)
|
||||
|
||||
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtection =
|
||||
ApiBranchProtection(
|
||||
enabled = info.enabled,
|
||||
required_status_checks = Some(
|
||||
Status(EnforcementLevel(info.enabled && info.contexts.nonEmpty, info.includeAdministrators), info.contexts)
|
||||
)
|
||||
)
|
||||
val statusNone = Status(Off, Seq.empty)
|
||||
case class Status(enforcement_level: EnforcementLevel, contexts: Seq[String])
|
||||
sealed class EnforcementLevel(val name: String)
|
||||
case object Off extends EnforcementLevel("off")
|
||||
case object NonAdmins extends EnforcementLevel("non_admins")
|
||||
case object Everyone extends EnforcementLevel("everyone")
|
||||
object EnforcementLevel {
|
||||
def apply(enabled: Boolean, includeAdministrators: Boolean): EnforcementLevel =
|
||||
if (enabled) {
|
||||
if (includeAdministrators) {
|
||||
Everyone
|
||||
} else {
|
||||
NonAdmins
|
||||
}
|
||||
} else {
|
||||
Off
|
||||
}
|
||||
}
|
||||
|
||||
implicit val enforcementLevelSerializer = new CustomSerializer[EnforcementLevel](
|
||||
format =>
|
||||
(
|
||||
{
|
||||
case JString("off") => Off
|
||||
case JString("non_admins") => NonAdmins
|
||||
case JString("everyone") => Everyone
|
||||
}, {
|
||||
case x: EnforcementLevel => JString(x.name)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -1,21 +0,0 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
||||
case class ApiBranchProtectionRequest(
|
||||
enabled: Boolean,
|
||||
required_status_checks: Option[ApiBranchProtectionRequest.Status],
|
||||
restrictions: Option[ApiBranchProtectionRequest.Restrictions],
|
||||
enforce_admins: Option[Boolean]
|
||||
)
|
||||
|
||||
object ApiBranchProtectionRequest {
|
||||
|
||||
/** form for enabling-and-disabling-branch-protection */
|
||||
case class EnablingAndDisabling(protection: ApiBranchProtectionRequest)
|
||||
|
||||
case class Status(
|
||||
contexts: Seq[String]
|
||||
)
|
||||
|
||||
case class Restrictions(users: Seq[String])
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
import gitbucket.core.service.ProtectedBranchService
|
||||
import org.json4s._
|
||||
|
||||
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
||||
case class ApiBranchProtectionResponse(
|
||||
url: Option[ApiPath], // for output
|
||||
enabled: Boolean,
|
||||
required_status_checks: Option[ApiBranchProtectionResponse.Status],
|
||||
restrictions: Option[ApiBranchProtectionResponse.Restrictions],
|
||||
enforce_admins: Option[ApiBranchProtectionResponse.EnforceAdmins]
|
||||
) {
|
||||
def status: ApiBranchProtectionResponse.Status =
|
||||
required_status_checks.getOrElse(ApiBranchProtectionResponse.statusNone)
|
||||
}
|
||||
|
||||
object ApiBranchProtectionResponse {
|
||||
|
||||
case class EnforceAdmins(enabled: Boolean)
|
||||
|
||||
// /** form for enabling-and-disabling-branch-protection */
|
||||
// case class EnablingAndDisabling(protection: ApiBranchProtectionResponse)
|
||||
|
||||
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtectionResponse =
|
||||
ApiBranchProtectionResponse(
|
||||
url = Some(
|
||||
ApiPath(
|
||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection"
|
||||
)
|
||||
),
|
||||
enabled = info.enabled,
|
||||
required_status_checks = info.contexts.map { contexts =>
|
||||
Status(
|
||||
Some(
|
||||
ApiPath(
|
||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection/required_status_checks"
|
||||
)
|
||||
),
|
||||
EnforcementLevel(info.enabled && info.contexts.nonEmpty, info.enforceAdmins),
|
||||
contexts,
|
||||
Some(
|
||||
ApiPath(
|
||||
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection/required_status_checks/contexts"
|
||||
)
|
||||
)
|
||||
)
|
||||
},
|
||||
restrictions = info.restrictionsUsers.map { restrictionsUsers =>
|
||||
Restrictions(restrictionsUsers)
|
||||
},
|
||||
enforce_admins = if (info.enabled) Some(EnforceAdmins(info.enforceAdmins)) else None
|
||||
)
|
||||
|
||||
val statusNone: Status = Status(None, Off, Seq.empty, None)
|
||||
|
||||
case class Status(
|
||||
url: Option[ApiPath], // for output
|
||||
enforcement_level: EnforcementLevel,
|
||||
contexts: Seq[String],
|
||||
contexts_url: Option[ApiPath] // for output
|
||||
)
|
||||
|
||||
sealed class EnforcementLevel(val name: String)
|
||||
case object Off extends EnforcementLevel("off")
|
||||
case object NonAdmins extends EnforcementLevel("non_admins")
|
||||
case object Everyone extends EnforcementLevel("everyone")
|
||||
|
||||
object EnforcementLevel {
|
||||
def apply(enabled: Boolean, includeAdministrators: Boolean): EnforcementLevel =
|
||||
if (enabled) {
|
||||
if (includeAdministrators) {
|
||||
Everyone
|
||||
} else {
|
||||
NonAdmins
|
||||
}
|
||||
} else {
|
||||
Off
|
||||
}
|
||||
}
|
||||
|
||||
case class Restrictions(users: Seq[String])
|
||||
|
||||
implicit val enforcementLevelSerializer: CustomSerializer[EnforcementLevel] =
|
||||
new CustomSerializer[EnforcementLevel](format =>
|
||||
(
|
||||
{
|
||||
case JString("off") => Off
|
||||
case JString("non_admins") => NonAdmins
|
||||
case JString("everyone") => Everyone
|
||||
},
|
||||
{ case x: EnforcementLevel =>
|
||||
JString(x.name)
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
@@ -14,8 +14,7 @@ case class ApiComment(id: Int, user: ApiUser, body: String, created_at: Date, up
|
||||
isPullRequest: Boolean
|
||||
) {
|
||||
val html_url = ApiPath(
|
||||
s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" }
|
||||
else { "issues" }}/${issueId}#comment-${id}"
|
||||
s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${issueId}#comment-${id}"
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ case class ApiCommit(
|
||||
|
||||
object ApiCommit {
|
||||
def apply(git: Git, repositoryName: RepositoryName, commit: CommitInfo): ApiCommit = {
|
||||
val diffs = JGitUtil.getDiffs(git = git, from = None, to = commit.id, fetchContent = false, makePatch = false)
|
||||
val diffs = JGitUtil.getDiffs(git, None, commit.id, false, false)
|
||||
ApiCommit(
|
||||
id = commit.id,
|
||||
message = commit.fullMessage,
|
||||
|
||||
@@ -69,8 +69,7 @@ object ApiCommits {
|
||||
}
|
||||
|
||||
File(
|
||||
filename = if (diff.changeType == ChangeType.DELETE) { diff.oldPath }
|
||||
else { diff.newPath },
|
||||
filename = if (diff.changeType == ChangeType.DELETE) { diff.oldPath } else { diff.newPath },
|
||||
additions = additions,
|
||||
deletions = deletions,
|
||||
changes = additions + deletions,
|
||||
@@ -98,7 +97,7 @@ object ApiCommits {
|
||||
ApiCommits(
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||
sha = commitInfo.id,
|
||||
html_url = ApiPath(s"/${repositoryName.fullName}/commit/${commitInfo.id}"),
|
||||
html_url = ApiPath(s"${repositoryName.fullName}/commit/${commitInfo.id}"),
|
||||
comment_url = ApiPath(""), // TODO no API for commit comment
|
||||
commit = Commit(
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||
@@ -107,9 +106,7 @@ object ApiCommits {
|
||||
message = commitInfo.shortMessage,
|
||||
comment_count = commentCount,
|
||||
tree = Tree(
|
||||
url = ApiPath(
|
||||
s"/api/v3/repos/${repositoryName.fullName}/tree/${commitInfo.id}"
|
||||
), // TODO This endpoint has not been implemented yet.
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/tree/${commitInfo.id}"), // TODO This endpoint has not been implemented yet.
|
||||
sha = commitInfo.id
|
||||
)
|
||||
),
|
||||
@@ -117,9 +114,7 @@ object ApiCommits {
|
||||
committer = ApiUser(committer),
|
||||
parents = commitInfo.parents.map { parent =>
|
||||
Tree(
|
||||
url = ApiPath(
|
||||
s"/api/v3/repos/${repositoryName.fullName}/tree/${parent}"
|
||||
), // TODO This endpoint has not been implemented yet.
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/tree/${parent}"), // TODO This endpoint has not been implemented yet.
|
||||
sha = parent
|
||||
)
|
||||
},
|
||||
|
||||
@@ -22,15 +22,16 @@ object ApiContents {
|
||||
ApiContents("dir", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName)
|
||||
} else {
|
||||
content
|
||||
.map(arr =>
|
||||
ApiContents(
|
||||
"file",
|
||||
fileInfo.name,
|
||||
fileInfo.path,
|
||||
fileInfo.id.getName,
|
||||
Some(Base64.getEncoder.encodeToString(arr)),
|
||||
Some("base64")
|
||||
)(repositoryName)
|
||||
.map(
|
||||
arr =>
|
||||
ApiContents(
|
||||
"file",
|
||||
fileInfo.name,
|
||||
fileInfo.path,
|
||||
fileInfo.commitId,
|
||||
Some(Base64.getEncoder.encodeToString(arr)),
|
||||
Some("base64")
|
||||
)(repositoryName)
|
||||
)
|
||||
.getOrElse(ApiContents("file", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName))
|
||||
}
|
||||
|
||||
@@ -12,19 +12,17 @@ case class ApiIssue(
|
||||
number: Int,
|
||||
title: String,
|
||||
user: ApiUser,
|
||||
assignees: List[ApiUser],
|
||||
assignee: Option[ApiUser],
|
||||
labels: List[ApiLabel],
|
||||
state: String,
|
||||
created_at: Date,
|
||||
updated_at: Date,
|
||||
body: String,
|
||||
milestone: Option[ApiMilestone]
|
||||
body: String
|
||||
)(repositoryName: RepositoryName, isPullRequest: Boolean) {
|
||||
val id = 0 // dummy id
|
||||
val assignee = assignees.headOption
|
||||
val assignees = List(assignee).flatten
|
||||
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
||||
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" }
|
||||
else { "issues" }}/${number}")
|
||||
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}")
|
||||
val pull_request = if (isPullRequest) {
|
||||
Some(
|
||||
Map(
|
||||
@@ -44,19 +42,16 @@ object ApiIssue {
|
||||
issue: Issue,
|
||||
repositoryName: RepositoryName,
|
||||
user: ApiUser,
|
||||
assignees: List[ApiUser],
|
||||
labels: List[ApiLabel],
|
||||
milestone: Option[ApiMilestone]
|
||||
assignee: Option[ApiUser],
|
||||
labels: List[ApiLabel]
|
||||
): ApiIssue =
|
||||
ApiIssue(
|
||||
number = issue.issueId,
|
||||
title = issue.title,
|
||||
user = user,
|
||||
assignees = assignees,
|
||||
assignee = assignee,
|
||||
labels = labels,
|
||||
milestone = milestone,
|
||||
state = if (issue.closed) { "closed" }
|
||||
else { "open" },
|
||||
state = if (issue.closed) { "closed" } else { "open" },
|
||||
body = issue.content.getOrElse(""),
|
||||
created_at = issue.registeredDate,
|
||||
updated_at = issue.updatedDate
|
||||
|
||||
@@ -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
|
||||
|
||||
import gitbucket.core.plugin.PluginInfo
|
||||
import gitbucket.core.plugin.{PluginRegistry, PluginInfo}
|
||||
|
||||
case class ApiPlugin(
|
||||
id: String,
|
||||
|
||||
@@ -21,16 +21,15 @@ case class ApiPullRequest(
|
||||
body: String,
|
||||
user: ApiUser,
|
||||
labels: List[ApiLabel],
|
||||
assignees: List[ApiUser],
|
||||
assignee: Option[ApiUser],
|
||||
draft: Option[Boolean]
|
||||
) {
|
||||
val id = 0 // dummy id
|
||||
val assignee = assignees.headOption
|
||||
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
||||
// val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
|
||||
// val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
|
||||
//val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
|
||||
//val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
|
||||
val url = ApiPath(s"${base.repo.url.path}/pulls/${number}")
|
||||
// val issue_url = ApiPath(s"${base.repo.url.path}/issues/${number}")
|
||||
//val issue_url = ApiPath(s"${base.repo.url.path}/issues/${number}")
|
||||
val commits_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/commits")
|
||||
val review_comments_url = ApiPath(s"${base.repo.url.path}/pulls/${number}/comments")
|
||||
val review_comment_url = ApiPath(s"${base.repo.url.path}/pulls/comments/{number}")
|
||||
@@ -46,7 +45,7 @@ object ApiPullRequest {
|
||||
baseRepo: ApiRepository,
|
||||
user: ApiUser,
|
||||
labels: List[ApiLabel],
|
||||
assignees: List[ApiUser],
|
||||
assignee: Option[ApiUser],
|
||||
mergedComment: Option[(IssueComment, Account)]
|
||||
): ApiPullRequest =
|
||||
ApiPullRequest(
|
||||
@@ -64,13 +63,12 @@ object ApiPullRequest {
|
||||
body = issue.content.getOrElse(""),
|
||||
user = user,
|
||||
labels = labels,
|
||||
assignees = assignees,
|
||||
assignee = assignee,
|
||||
draft = Some(pullRequest.isDraft)
|
||||
)
|
||||
|
||||
case class Commit(sha: String, ref: String, repo: ApiRepository)(baseOwner: String) {
|
||||
val label = if (baseOwner == repo.owner.login) { ref }
|
||||
else { s"${repo.owner.login}:${ref}" }
|
||||
val label = if (baseOwner == repo.owner.login) { ref } else { s"${repo.owner.login}:${ref}" }
|
||||
val user = repo.owner
|
||||
}
|
||||
|
||||
|
||||
@@ -1,55 +1,5 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
import gitbucket.core.util.JGitUtil.TagInfo
|
||||
import gitbucket.core.util.RepositoryName
|
||||
import org.eclipse.jgit.lib.Ref
|
||||
case class ApiObject(sha: String)
|
||||
|
||||
case class ApiRefCommit(
|
||||
sha: String,
|
||||
`type`: String,
|
||||
url: ApiPath
|
||||
)
|
||||
|
||||
case class ApiRef(
|
||||
ref: String,
|
||||
node_id: String = "",
|
||||
url: ApiPath,
|
||||
`object`: ApiRefCommit,
|
||||
)
|
||||
|
||||
object ApiRef {
|
||||
|
||||
def fromRef(
|
||||
repositoryName: RepositoryName,
|
||||
ref: Ref
|
||||
): ApiRef =
|
||||
ApiRef(
|
||||
ref = ref.getName,
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/${ref.getName}"),
|
||||
`object` = ApiRefCommit(
|
||||
sha = ref.getObjectId.getName,
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${ref.getObjectId.getName}"),
|
||||
`type` = "commit"
|
||||
)
|
||||
)
|
||||
|
||||
def fromTag(
|
||||
repositoryName: RepositoryName,
|
||||
tagInfo: TagInfo
|
||||
): ApiRef =
|
||||
ApiRef(
|
||||
ref = s"refs/tags/${tagInfo.name}",
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/refs/tags/${tagInfo.name}"),
|
||||
// the GH api distinguishes between "releases" and plain git tags
|
||||
// for "releases", the api returns a reference to the release object (with type `tag`)
|
||||
// this would be something like s"/api/v3/repos/${repositoryName.fullName}/git/tags/<hash-of-tag>"
|
||||
// with a hash for the tag, which I do not fully understand
|
||||
// since this is not yet implemented in GB, we always return a link to the plain `commit` object,
|
||||
// which GH does for tags that are not annotated
|
||||
`object` = ApiRefCommit(
|
||||
sha = tagInfo.objectId,
|
||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${tagInfo.objectId}"),
|
||||
`type` = "commit"
|
||||
)
|
||||
)
|
||||
}
|
||||
case class ApiRef(ref: String, `object`: ApiObject)
|
||||
|
||||
@@ -12,16 +12,16 @@ case class ApiRepository(
|
||||
forks: Int,
|
||||
`private`: Boolean,
|
||||
default_branch: String,
|
||||
owner: ApiUser,
|
||||
has_issues: Boolean
|
||||
owner: ApiUser
|
||||
) {
|
||||
val id = 0 // dummy id
|
||||
val forks_count = forks
|
||||
val watchers_count = watchers
|
||||
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 html_url = ApiPath(s"/${full_name}")
|
||||
val ssh_url = Some(SshPath(s"/${full_name}.git"))
|
||||
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
||||
}
|
||||
|
||||
object ApiRepository {
|
||||
@@ -39,16 +39,11 @@ object ApiRepository {
|
||||
forks = forkedCount,
|
||||
`private` = repository.isPrivate,
|
||||
default_branch = repository.defaultBranch,
|
||||
owner = owner,
|
||||
has_issues = if (repository.options.issuesOption == "DISABLE") false else true
|
||||
owner = owner
|
||||
)
|
||||
|
||||
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
||||
ApiRepository(
|
||||
repositoryInfo.repository,
|
||||
owner,
|
||||
forkedCount = repositoryInfo.forkedCount
|
||||
)
|
||||
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
|
||||
|
||||
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
||||
this(repositoryInfo, ApiUser(owner))
|
||||
@@ -61,8 +56,7 @@ object ApiRepository {
|
||||
watchers = 0,
|
||||
forks = 0,
|
||||
`private` = false,
|
||||
default_branch = "main",
|
||||
owner = owner,
|
||||
has_issues = true
|
||||
default_branch = "master",
|
||||
owner = owner
|
||||
)
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
)
|
||||
}
|
||||
@@ -24,8 +24,7 @@ object ApiUser {
|
||||
def apply(user: Account): ApiUser = ApiUser(
|
||||
login = user.userName,
|
||||
email = user.mailAddress,
|
||||
`type` = if (user.isGroupAccount) { "Organization" }
|
||||
else { "User" },
|
||||
`type` = if (user.isGroupAccount) { "Organization" } else { "User" },
|
||||
site_admin = user.isAdmin,
|
||||
created_at = user.registeredDate
|
||||
)
|
||||
|
||||
@@ -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,
|
||||
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"
|
||||
}
|
||||
}
|
||||
@@ -15,12 +15,13 @@ object JsonFormat {
|
||||
|
||||
val parserISO = DateTimeFormatter.ofPattern("yyyy-MM-dd'T'HH:mm:ss'Z'")
|
||||
|
||||
val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](format =>
|
||||
(
|
||||
{ case JString(s) =>
|
||||
Try(Date.from(Instant.parse(s))).getOrElse(throw new MappingException("Can't convert " + s + " to Date"))
|
||||
},
|
||||
{ case x: Date => JString(OffsetDateTime.ofInstant(x.toInstant, ZoneId.of("UTC")).format(parserISO)) }
|
||||
val jsonFormats = Serialization.formats(NoTypeHints) + new CustomSerializer[Date](
|
||||
format =>
|
||||
(
|
||||
{
|
||||
case JString(s) =>
|
||||
Try(Date.from(Instant.parse(s))).getOrElse(throw new MappingException("Can't convert " + s + " to Date"))
|
||||
}, { case x: Date => JString(OffsetDateTime.ofInstant(x.toInstant, ZoneId.of("UTC")).format(parserISO)) }
|
||||
)
|
||||
) + FieldSerializer[ApiUser]() +
|
||||
FieldSerializer[ApiGroup]() +
|
||||
@@ -44,35 +45,32 @@ object JsonFormat {
|
||||
FieldSerializer[ApiCommits.File]() +
|
||||
FieldSerializer[ApiRelease]() +
|
||||
FieldSerializer[ApiReleaseAsset]() +
|
||||
ApiBranchProtectionResponse.enforcementLevelSerializer
|
||||
ApiBranchProtection.enforcementLevelSerializer
|
||||
|
||||
def apiPathSerializer(c: Context) =
|
||||
new CustomSerializer[ApiPath](_ =>
|
||||
(
|
||||
{
|
||||
new CustomSerializer[ApiPath](
|
||||
_ =>
|
||||
({
|
||||
case JString(s) if s.startsWith(c.baseUrl) => ApiPath(s.substring(c.baseUrl.length))
|
||||
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
||||
},
|
||||
{ case ApiPath(path) =>
|
||||
JString(c.baseUrl + path)
|
||||
}
|
||||
)
|
||||
}, {
|
||||
case ApiPath(path) => JString(c.baseUrl + path)
|
||||
})
|
||||
)
|
||||
|
||||
def sshPathSerializer(c: Context) =
|
||||
new CustomSerializer[SshPath](_ =>
|
||||
(
|
||||
{
|
||||
new CustomSerializer[SshPath](
|
||||
_ =>
|
||||
({
|
||||
case JString(s) if c.sshUrl.exists(sshUrl => s.startsWith(sshUrl)) =>
|
||||
SshPath(s.substring(c.sshUrl.get.length))
|
||||
case JString(s) => throw new MappingException("Can't convert " + s + " to ApiPath")
|
||||
},
|
||||
{ case SshPath(path) =>
|
||||
c.sshUrl.map { sshUrl =>
|
||||
JString(sshUrl + path)
|
||||
} getOrElse JNothing
|
||||
}
|
||||
)
|
||||
}, {
|
||||
case SshPath(path) =>
|
||||
c.sshUrl.map { sshUrl =>
|
||||
JString(sshUrl + path)
|
||||
} getOrElse JNothing
|
||||
})
|
||||
)
|
||||
|
||||
/**
|
||||
|
||||
@@ -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,14 +35,25 @@ class AccountController
|
||||
with WebHookService
|
||||
with PrioritiesService
|
||||
with RepositoryCreationService
|
||||
with RequestCache
|
||||
|
||||
trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
self: AccountService & RepositoryService & ActivityService & WikiService & LabelsService & SshKeyService &
|
||||
GpgKeyService & OneselfAuthenticator & UsersAuthenticator & GroupManagerAuthenticator & ReadableUsersAuthenticator &
|
||||
AccessTokenService & WebHookService & PrioritiesService & RepositoryCreationService =>
|
||||
self: AccountService
|
||||
with RepositoryService
|
||||
with ActivityService
|
||||
with WikiService
|
||||
with LabelsService
|
||||
with SshKeyService
|
||||
with GpgKeyService
|
||||
with OneselfAuthenticator
|
||||
with UsersAuthenticator
|
||||
with GroupManagerAuthenticator
|
||||
with ReadableUsersAuthenticator
|
||||
with AccessTokenService
|
||||
with WebHookService
|
||||
with PrioritiesService
|
||||
with RepositoryCreationService =>
|
||||
|
||||
private case class AccountNewForm(
|
||||
case class AccountNewForm(
|
||||
userName: String,
|
||||
password: String,
|
||||
fullName: String,
|
||||
@@ -53,7 +64,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
fileId: Option[String]
|
||||
)
|
||||
|
||||
private case class AccountEditForm(
|
||||
case class AccountEditForm(
|
||||
password: Option[String],
|
||||
fullName: String,
|
||||
mailAddress: String,
|
||||
@@ -64,17 +75,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
clearImage: Boolean
|
||||
)
|
||||
|
||||
private case class SshKeyForm(title: String, publicKey: String)
|
||||
case class SshKeyForm(title: String, publicKey: String)
|
||||
|
||||
private case class GpgKeyForm(title: String, publicKey: String)
|
||||
case class GpgKeyForm(title: String, publicKey: String)
|
||||
|
||||
private case class PersonalTokenForm(note: String)
|
||||
case class PersonalTokenForm(note: String)
|
||||
|
||||
private case class SyntaxHighlighterThemeForm(theme: String)
|
||||
|
||||
private val newForm = mapping(
|
||||
val newForm = mapping(
|
||||
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||
"extraMailAddresses" -> list(
|
||||
@@ -85,8 +94,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"fileId" -> trim(label("File ID", optional(text())))
|
||||
)(AccountNewForm.apply)
|
||||
|
||||
private val editForm = mapping(
|
||||
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||
val editForm = mapping(
|
||||
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||
"extraMailAddresses" -> list(
|
||||
@@ -98,41 +107,28 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"clearImage" -> trim(label("Clear image", boolean()))
|
||||
)(AccountEditForm.apply)
|
||||
|
||||
private val sshKeyForm = mapping(
|
||||
val sshKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim2(label("Key", text(required, validPublicKey)))
|
||||
)(SshKeyForm.apply)
|
||||
|
||||
private val gpgKeyForm = mapping(
|
||||
val gpgKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> label("Key", text(required, validGpgPublicKey))
|
||||
)(GpgKeyForm.apply)
|
||||
|
||||
private val personalTokenForm = mapping(
|
||||
val personalTokenForm = mapping(
|
||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||
)(PersonalTokenForm.apply)
|
||||
|
||||
private val syntaxHighlighterThemeForm = mapping(
|
||||
"highlighterTheme" -> trim(label("Theme", text(required)))
|
||||
)(SyntaxHighlighterThemeForm.apply)
|
||||
|
||||
private val resetPasswordEmailForm = mapping(
|
||||
"mailAddress" -> trim(label("Email", text(required)))
|
||||
)(ResetPasswordEmailForm.apply)
|
||||
|
||||
private val resetPasswordForm = mapping(
|
||||
"token" -> trim(label("Token", text(required))),
|
||||
"password" -> trim(label("Password", text(required, maxlength(40))))
|
||||
)(ResetPasswordForm.apply)
|
||||
|
||||
private case class NewGroupForm(
|
||||
case class NewGroupForm(
|
||||
groupName: String,
|
||||
description: Option[String],
|
||||
url: Option[String],
|
||||
fileId: Option[String],
|
||||
members: String
|
||||
)
|
||||
private case class EditGroupForm(
|
||||
case class EditGroupForm(
|
||||
groupName: String,
|
||||
description: Option[String],
|
||||
url: Option[String],
|
||||
@@ -140,15 +136,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
members: String,
|
||||
clearImage: Boolean
|
||||
)
|
||||
private case class ResetPasswordEmailForm(
|
||||
mailAddress: String
|
||||
)
|
||||
private case class ResetPasswordForm(
|
||||
token: String,
|
||||
password: String
|
||||
)
|
||||
|
||||
private val newGroupForm = mapping(
|
||||
val newGroupForm = mapping(
|
||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||
@@ -156,7 +145,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"members" -> trim(label("Members", text(required, members)))
|
||||
)(NewGroupForm.apply)
|
||||
|
||||
private val editGroupForm = mapping(
|
||||
val editGroupForm = mapping(
|
||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||
@@ -165,7 +154,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"clearImage" -> trim(label("Clear image", boolean()))
|
||||
)(EditGroupForm.apply)
|
||||
|
||||
private case class RepositoryCreationForm(
|
||||
case class RepositoryCreationForm(
|
||||
owner: String,
|
||||
name: String,
|
||||
description: Option[String],
|
||||
@@ -173,8 +162,9 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
initOption: String,
|
||||
sourceUrl: Option[String]
|
||||
)
|
||||
case class ForkRepositoryForm(owner: String, name: String)
|
||||
|
||||
private val newRepositoryForm = mapping(
|
||||
val newRepositoryForm = mapping(
|
||||
"owner" -> trim(label("Owner", text(required, maxlength(100), identifier, existsAccount))),
|
||||
"name" -> trim(label("Repository name", text(required, maxlength(100), repository, uniqueRepository))),
|
||||
"description" -> trim(label("Description", optional(text()))),
|
||||
@@ -183,27 +173,34 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"sourceUrl" -> trim(label("Source URL", optionalRequired(_.value("initOption") == "COPY", text())))
|
||||
)(RepositoryCreationForm.apply)
|
||||
|
||||
private case class AccountForm(accountName: String)
|
||||
val forkRepositoryForm = mapping(
|
||||
"owner" -> trim(label("Repository owner", text(required))),
|
||||
"name" -> trim(label("Repository name", text(required)))
|
||||
)(ForkRepositoryForm.apply)
|
||||
|
||||
private val accountForm = mapping(
|
||||
case class AccountForm(accountName: String)
|
||||
|
||||
val accountForm = mapping(
|
||||
"account" -> trim(label("Group/User name", text(required, validAccountName)))
|
||||
)(AccountForm.apply)
|
||||
|
||||
// for account web hook url addition.
|
||||
private case class AccountWebHookForm(
|
||||
case class AccountWebHookForm(
|
||||
url: String,
|
||||
events: Set[WebHook.Event],
|
||||
ctype: WebHookContentType,
|
||||
token: Option[String]
|
||||
)
|
||||
|
||||
private def accountWebHookForm(update: Boolean) =
|
||||
def accountWebHookForm(update: Boolean) =
|
||||
mapping(
|
||||
"url" -> trim(label("url", text(required, accountWebHook(update)))),
|
||||
"events" -> accountWebhookEvents,
|
||||
"ctype" -> label("ctype", text()),
|
||||
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
||||
)((url, events, ctype, token) => AccountWebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
||||
)(
|
||||
(url, events, ctype, token) => AccountWebHookForm(url, events, WebHookContentType.valueOf(ctype), token)
|
||||
)
|
||||
|
||||
/**
|
||||
* Provides duplication check for web hook url. duplicated from RepositorySettingsController.scala
|
||||
@@ -248,12 +245,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
gitbucket.core.account.html.activity(
|
||||
account,
|
||||
if (account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
||||
getActivitiesByUser(userName, publicOnly = true),
|
||||
getActivitiesByUser(userName, true),
|
||||
extraMailAddresses
|
||||
)
|
||||
|
||||
// Members
|
||||
case "members" if account.isGroupAccount =>
|
||||
case "members" if (account.isGroupAccount) => {
|
||||
val members = getGroupMembers(account.userName)
|
||||
gitbucket.core.account.html.members(
|
||||
account,
|
||||
@@ -261,9 +258,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
extraMailAddresses,
|
||||
isGroupManager(context.loginAccount, members)
|
||||
)
|
||||
}
|
||||
|
||||
// Repositories
|
||||
case _ =>
|
||||
case _ => {
|
||||
val members = getGroupMembers(account.userName)
|
||||
gitbucket.core.account.html.repositories(
|
||||
account,
|
||||
@@ -272,6 +270,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
extraMailAddresses,
|
||||
isGroupManager(context.loginAccount, members)
|
||||
)
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
@@ -279,7 +278,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:userName.atom") {
|
||||
val userName = params("userName")
|
||||
contentType = "application/atom+xml; type=feed"
|
||||
helper.xml.feed(getActivitiesByUser(userName, publicOnly = true))
|
||||
helper.xml.feed(getActivitiesByUser(userName, true))
|
||||
}
|
||||
|
||||
get("/:userName.keys") {
|
||||
@@ -324,21 +323,22 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
post("/:userName/_edit", editForm)(oneselfOnly { form =>
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { account =>
|
||||
updateAccount(
|
||||
account.copy(
|
||||
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
description = form.description,
|
||||
url = form.url
|
||||
getAccountByUserName(userName).map {
|
||||
account =>
|
||||
updateAccount(
|
||||
account.copy(
|
||||
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
description = form.description,
|
||||
url = form.url
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||
flash.update("info", "Account information has been updated.")
|
||||
redirect(s"/$userName/_edit")
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||
flash.update("info", "Account information has been updated.")
|
||||
redirect(s"/${userName}/_edit")
|
||||
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
@@ -346,11 +346,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:userName/_delete")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
|
||||
getAccountByUserName(userName, includeRemoved = true).map { account =>
|
||||
if (isLastAdministrator(account)) {
|
||||
flash.update("error", "Account can't be removed because this is last one administrator.")
|
||||
redirect(s"/$userName/_edit")
|
||||
} else {
|
||||
getAccountByUserName(userName, true).map {
|
||||
account =>
|
||||
if (isLastAdministrator(account)) {
|
||||
flash.update("error", "Account can't be removed because this is last one administrator.")
|
||||
redirect(s"/${userName}/_edit")
|
||||
} else {
|
||||
// // Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
@@ -358,10 +359,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
suspendAccount(account)
|
||||
session.invalidate()
|
||||
redirect("/")
|
||||
}
|
||||
suspendAccount(account)
|
||||
session.invalidate
|
||||
redirect("/")
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -375,20 +376,20 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
post("/:userName/_ssh", sshKeyForm)(oneselfOnly { form =>
|
||||
val userName = params("userName")
|
||||
addPublicKey(userName, form.title, form.publicKey)
|
||||
redirect(s"/$userName/_ssh")
|
||||
redirect(s"/${userName}/_ssh")
|
||||
})
|
||||
|
||||
get("/:userName/_ssh/delete/:id")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
val sshKeyId = params("id").toInt
|
||||
deletePublicKey(userName, sshKeyId)
|
||||
redirect(s"/$userName/_ssh")
|
||||
redirect(s"/${userName}/_ssh")
|
||||
})
|
||||
|
||||
get("/:userName/_gpg")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { x =>
|
||||
// html.ssh(x, getPublicKeys(x.userName))
|
||||
//html.ssh(x, getPublicKeys(x.userName))
|
||||
html.gpg(x, getGpgPublicKeys(x.userName))
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
@@ -396,14 +397,14 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
post("/:userName/_gpg", gpgKeyForm)(oneselfOnly { form =>
|
||||
val userName = params("userName")
|
||||
addGpgPublicKey(userName, form.title, form.publicKey)
|
||||
redirect(s"/$userName/_gpg")
|
||||
redirect(s"/${userName}/_gpg")
|
||||
})
|
||||
|
||||
get("/:userName/_gpg/delete/:id")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
val keyId = params("id").toInt
|
||||
deleteGpgPublicKey(userName, keyId)
|
||||
redirect(s"/$userName/_gpg")
|
||||
redirect(s"/${userName}/_gpg")
|
||||
})
|
||||
|
||||
get("/:userName/_application")(oneselfOnly {
|
||||
@@ -411,12 +412,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
getAccountByUserName(userName).map { x =>
|
||||
var tokens = getAccessTokens(x.userName)
|
||||
val generatedToken = flash.get("generatedToken") match {
|
||||
case Some((tokenId: Int, token: String)) =>
|
||||
case Some((tokenId: Int, token: String)) => {
|
||||
val gt = tokens.find(_.accessTokenId == tokenId)
|
||||
gt.map { t =>
|
||||
tokens = tokens.filterNot(_ == t)
|
||||
(t, token)
|
||||
}
|
||||
}
|
||||
case _ => None
|
||||
}
|
||||
html.application(x, tokens, generatedToken)
|
||||
@@ -425,41 +427,18 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).foreach { _ =>
|
||||
getAccountByUserName(userName).map { x =>
|
||||
val (tokenId, token) = generateAccessToken(userName, form.note)
|
||||
flash.update("generatedToken", (tokenId, token))
|
||||
}
|
||||
redirect(s"/$userName/_application")
|
||||
redirect(s"/${userName}/_application")
|
||||
})
|
||||
|
||||
get("/:userName/_personalToken/delete/:id")(oneselfOnly {
|
||||
val userName = params("userName")
|
||||
val tokenId = params("id").toInt
|
||||
deleteAccessToken(userName, tokenId)
|
||||
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")
|
||||
redirect(s"/${userName}/_application")
|
||||
})
|
||||
|
||||
get("/:userName/_hooks")(managersOnly {
|
||||
@@ -476,7 +455,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).map { account =>
|
||||
val webhook = AccountWebHook(userName, "", WebHookContentType.FORM, None)
|
||||
html.edithook(webhook, Set(WebHook.Push), account, create = true)
|
||||
html.edithook(webhook, Set(WebHook.Push), account, true)
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -487,7 +466,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
addAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||
flash.update("info", s"Webhook ${form.url} created")
|
||||
redirect(s"/$userName/_hooks")
|
||||
redirect(s"/${userName}/_hooks")
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -497,7 +476,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
deleteAccountWebHook(userName, params("url"))
|
||||
flash.update("info", s"Webhook ${params("url")} deleted")
|
||||
redirect(s"/$userName/_hooks")
|
||||
redirect(s"/${userName}/_hooks")
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -506,8 +485,9 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
get("/:userName/_hooks/edit")(managersOnly {
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).flatMap { account =>
|
||||
getAccountWebHook(userName, params("url")).map { case (webhook, events) =>
|
||||
html.edithook(webhook, events, account, create = false)
|
||||
getAccountWebHook(userName, params("url")).map {
|
||||
case (webhook, events) =>
|
||||
html.edithook(webhook, events, account, false)
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
@@ -519,7 +499,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val userName = params("userName")
|
||||
updateAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||
flash.update("info", s"webhook ${form.url} updated")
|
||||
redirect(s"/$userName/_hooks")
|
||||
redirect(s"/${userName}/_hooks")
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -527,8 +507,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
*/
|
||||
ajaxPost("/:userName/_hooks/test")(managersOnly {
|
||||
// TODO Is it possible to merge with [[RepositorySettingsController.ajaxPost]]?
|
||||
import scala.concurrent.duration.*
|
||||
import scala.concurrent.*
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent._
|
||||
import scala.util.control.NonFatal
|
||||
import org.apache.http.util.EntityUtils
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
@@ -541,8 +521,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
val url = params("url")
|
||||
val token = Some(params("token"))
|
||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||
val dummyWebHookInfo =
|
||||
RepositoryWebHook(userName = userName, repositoryName = "dummy", url = url, ctype = ctype, token = token)
|
||||
val dummyWebHookInfo = RepositoryWebHook(userName, "dummy", url, ctype, token)
|
||||
val dummyPayload = {
|
||||
val ownerAccount = getAccountByUserName(userName).get
|
||||
WebHookPushPayload.createDummyPayload(ownerAccount)
|
||||
@@ -552,10 +531,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||
|
||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||
case e: java.net.UnknownHostException => Map("error" -> s"Unknown host ${e.getMessage}")
|
||||
case _: java.lang.IllegalArgumentException => Map("error" -> "invalid url")
|
||||
case _: org.apache.http.client.ClientProtocolException => Map("error" -> "invalid url")
|
||||
case NonFatal(e) => Map("error" -> s"${e.getClass} ${e.getMessage}")
|
||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
||||
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
||||
}
|
||||
|
||||
contentType = formats("json")
|
||||
@@ -564,10 +543,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
"url" -> url,
|
||||
"request" -> Await.result(
|
||||
reqFuture
|
||||
.map(req =>
|
||||
Map(
|
||||
"headers" -> _headers(req.getAllHeaders),
|
||||
"payload" -> json
|
||||
.map(
|
||||
req =>
|
||||
Map(
|
||||
"headers" -> _headers(req.getAllHeaders),
|
||||
"payload" -> json
|
||||
)
|
||||
)
|
||||
.recover(toErrorMap),
|
||||
@@ -575,11 +555,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
),
|
||||
"response" -> Await.result(
|
||||
resFuture
|
||||
.map(res =>
|
||||
Map(
|
||||
"status" -> res.getStatusLine,
|
||||
"body" -> EntityUtils.toString(res.getEntity),
|
||||
"headers" -> _headers(res.getAllHeaders)
|
||||
.map(
|
||||
res =>
|
||||
Map(
|
||||
"status" -> res.getStatusLine(),
|
||||
"body" -> EntityUtils.toString(res.getEntity()),
|
||||
"headers" -> _headers(res.getAllHeaders())
|
||||
)
|
||||
)
|
||||
.recover(toErrorMap),
|
||||
@@ -590,7 +571,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
})
|
||||
|
||||
get("/register") {
|
||||
if (context.settings.basicBehavior.allowAccountRegistration) {
|
||||
if (context.settings.allowAccountRegistration) {
|
||||
if (context.loginAccount.isDefined) {
|
||||
redirect("/")
|
||||
} else {
|
||||
@@ -600,83 +581,24 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
}
|
||||
|
||||
post("/register", newForm) { form =>
|
||||
if (context.settings.basicBehavior.allowAccountRegistration) {
|
||||
if (context.settings.allowAccountRegistration) {
|
||||
createAccount(
|
||||
form.userName,
|
||||
pbkdf2_sha256(form.password),
|
||||
form.fullName,
|
||||
form.mailAddress,
|
||||
isAdmin = false,
|
||||
false,
|
||||
form.description,
|
||||
form.url
|
||||
)
|
||||
updateImage(form.userName, form.fileId, clearImage = false)
|
||||
updateImage(form.userName, form.fileId, false)
|
||||
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
||||
redirect("/signin")
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
get("/reset") {
|
||||
if (context.settings.basicBehavior.allowResetPassword) {
|
||||
html.reset()
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
post("/reset", resetPasswordEmailForm) { form =>
|
||||
if (context.settings.basicBehavior.allowResetPassword) {
|
||||
getAccountByMailAddress(form.mailAddress).foreach { account =>
|
||||
val token = generateResetPasswordToken(form.mailAddress)
|
||||
val mailer = new Mailer(context.settings)
|
||||
mailer.send(
|
||||
form.mailAddress,
|
||||
"Reset password",
|
||||
s"""Hello, ${account.fullName}!
|
||||
|
|
||||
|You requested to reset the password for your GitBucket account.
|
||||
|If you are not sure about the request, you can ignore this email.
|
||||
|Otherwise, click the following link to set the new password:
|
||||
|${context.baseUrl}/reset/form/$token
|
||||
|""".stripMargin
|
||||
)
|
||||
}
|
||||
redirect("/reset/sent")
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
get("/reset/sent") {
|
||||
if (context.settings.basicBehavior.allowResetPassword) {
|
||||
html.resetsent()
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
get("/reset/form/:token") {
|
||||
if (context.settings.basicBehavior.allowResetPassword) {
|
||||
val token = params("token")
|
||||
decodeResetPasswordToken(token)
|
||||
.map { _ =>
|
||||
html.resetform(token)
|
||||
}
|
||||
.getOrElse(NotFound())
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
post("/reset/form", resetPasswordForm) { form =>
|
||||
if (context.settings.basicBehavior.allowResetPassword) {
|
||||
decodeResetPasswordToken(form.token)
|
||||
.flatMap { mailAddress =>
|
||||
getAccountByMailAddress(mailAddress).map { account =>
|
||||
updateAccount(account.copy(password = pbkdf2_sha256(form.password)))
|
||||
html.resetcomplete()
|
||||
}
|
||||
}
|
||||
.getOrElse(NotFound())
|
||||
} else NotFound()
|
||||
}
|
||||
|
||||
get("/groups/new")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
html.creategroup(List(GroupMember("", loginAccount.userName, isManager = true)))
|
||||
}
|
||||
html.creategroup(List(GroupMember("", context.loginAccount.get.userName, true)))
|
||||
})
|
||||
|
||||
post("/groups/new", newGroupForm)(usersOnly { form =>
|
||||
@@ -692,25 +614,27 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
}
|
||||
.toList
|
||||
)
|
||||
updateImage(form.groupName, form.fileId, clearImage = false)
|
||||
updateImage(form.groupName, form.fileId, false)
|
||||
redirect(s"/${form.groupName}")
|
||||
})
|
||||
|
||||
get("/:groupName/_editgroup")(managersOnly {
|
||||
val groupName = params("groupName")
|
||||
getAccountByUserName(groupName, includeRemoved = true).map { account =>
|
||||
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
||||
} getOrElse NotFound()
|
||||
defining(params("groupName")) { groupName =>
|
||||
getAccountByUserName(groupName, true).map { account =>
|
||||
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
get("/:groupName/_deletegroup")(managersOnly {
|
||||
val groupName = params("groupName")
|
||||
// Remove from GROUP_MEMBER
|
||||
updateGroupMembers(groupName, Nil)
|
||||
// Disable group
|
||||
getAccountByUserName(groupName, includeRemoved = false).foreach { account =>
|
||||
updateGroup(groupName, account.description, account.url, removed = true)
|
||||
}
|
||||
defining(params("groupName")) {
|
||||
groupName =>
|
||||
// Remove from GROUP_MEMBER
|
||||
updateGroupMembers(groupName, Nil)
|
||||
// Disable group
|
||||
getAccountByUserName(groupName, false).foreach { account =>
|
||||
updateGroup(groupName, account.description, account.url, true)
|
||||
}
|
||||
// // Remove repositories
|
||||
// getRepositoryNamesOfUser(groupName).foreach { repositoryName =>
|
||||
// deleteRepository(groupName, repositoryName)
|
||||
@@ -718,25 +642,28 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
||||
// }
|
||||
}
|
||||
redirect("/")
|
||||
})
|
||||
|
||||
post("/:groupName/_editgroup", editGroupForm)(managersOnly { form =>
|
||||
val groupName = params("groupName")
|
||||
val members = form.members
|
||||
.split(",")
|
||||
.map {
|
||||
_.split(":") match {
|
||||
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
||||
defining(
|
||||
params("groupName"),
|
||||
form.members
|
||||
.split(",")
|
||||
.map {
|
||||
_.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, includeRemoved = true).map { _ =>
|
||||
updateGroup(groupName, form.description, form.url, removed = false)
|
||||
|
||||
// Update GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, members)
|
||||
// Update GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, members)
|
||||
// // Update COLLABORATOR for group repositories
|
||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||
// removeCollaborators(form.groupName, repositoryName)
|
||||
@@ -745,105 +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.")
|
||||
redirect(s"/$groupName/_editgroup")
|
||||
flash.update("info", "Account information has been updated.")
|
||||
redirect(s"/${groupName}/_editgroup")
|
||||
|
||||
} getOrElse NotFound()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
/**
|
||||
* Show the new repository form.
|
||||
*/
|
||||
get("/new")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
html.newrepo(getGroupsByUserName(loginAccount.userName), context.settings.basicBehavior.isCreateRepoOptionPublic)
|
||||
}
|
||||
html.newrepo(getGroupsByUserName(context.loginAccount.get.userName), context.settings.isCreateRepoOptionPublic)
|
||||
})
|
||||
|
||||
/**
|
||||
* Create new repository.
|
||||
*/
|
||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (context.settings.basicBehavior.repositoryOperation.create || loginAccount.isAdmin) {
|
||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||
if (getRepository(form.owner, form.name).isDefined) {
|
||||
// redirect to the repository if repository already exists
|
||||
redirect(s"/${form.owner}/${form.name}")
|
||||
} else if (!canCreateRepository(form.owner, loginAccount)) {
|
||||
// Permission error
|
||||
Forbidden()
|
||||
} else {
|
||||
// create repository asynchronously
|
||||
createRepository(
|
||||
loginAccount,
|
||||
form.owner,
|
||||
form.name,
|
||||
form.description,
|
||||
form.isPrivate,
|
||||
form.initOption,
|
||||
form.sourceUrl,
|
||||
context.settings.defaultBranch
|
||||
)
|
||||
// redirect to the repository
|
||||
redirect(s"/${form.owner}/${form.name}")
|
||||
}
|
||||
if (context.settings.repositoryOperation.create || context.loginAccount.get.isAdmin) {
|
||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||
if (getRepository(form.owner, form.name).isEmpty) {
|
||||
createRepository(
|
||||
context.loginAccount.get,
|
||||
form.owner,
|
||||
form.name,
|
||||
form.description,
|
||||
form.isPrivate,
|
||||
form.initOption,
|
||||
form.sourceUrl
|
||||
)
|
||||
}
|
||||
} else Forbidden()
|
||||
}
|
||||
}
|
||||
// redirect to the repository
|
||||
redirect(s"/${form.owner}/${form.name}")
|
||||
} else Forbidden()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (
|
||||
repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)
|
||||
) {
|
||||
val loginUserName = loginAccount.userName
|
||||
val groups = getGroupsByUserName(loginUserName)
|
||||
groups match {
|
||||
case _: List[String] =>
|
||||
val managerPermissions = groups.map { group =>
|
||||
val members = getGroupMembers(group)
|
||||
context.loginAccount.exists(x =>
|
||||
val loginAccount = context.loginAccount.get
|
||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||
val loginUserName = loginAccount.userName
|
||||
val groups = getGroupsByUserName(loginUserName)
|
||||
groups match {
|
||||
case _: List[String] =>
|
||||
val managerPermissions = groups.map { group =>
|
||||
val members = getGroupMembers(group)
|
||||
context.loginAccount.exists(
|
||||
x =>
|
||||
members.exists { member =>
|
||||
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) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (
|
||||
repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)
|
||||
) {
|
||||
val loginUserName = loginAccount.userName
|
||||
val accountName = form.accountName
|
||||
val loginAccount = context.loginAccount.get
|
||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||
val loginUserName = loginAccount.userName
|
||||
val accountName = form.accountName
|
||||
|
||||
if (getRepository(accountName, repository.name).isDefined) {
|
||||
// redirect to the repository if repository already exists
|
||||
redirect(s"/$accountName/${repository.name}")
|
||||
} else if (!canCreateRepository(accountName, loginAccount)) {
|
||||
// Permission error
|
||||
Forbidden()
|
||||
} else {
|
||||
// fork repository asynchronously
|
||||
forkRepository(accountName, repository, loginUserName)
|
||||
// redirect to the repository
|
||||
redirect(s"/$accountName/${repository.name}")
|
||||
}
|
||||
} else Forbidden()
|
||||
}
|
||||
if (getRepository(accountName, repository.name).isDefined ||
|
||||
(accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))) {
|
||||
// redirect to the repository if repository already exists
|
||||
redirect(s"/${accountName}/${repository.name}")
|
||||
} else {
|
||||
// fork repository asynchronously
|
||||
forkRepository(accountName, repository, loginUserName)
|
||||
// redirect to the repository
|
||||
redirect(s"/${accountName}/${repository.name}")
|
||||
}
|
||||
} else Forbidden()
|
||||
})
|
||||
|
||||
private def existsAccount: Constraint = new Constraint() {
|
||||
@@ -869,11 +778,9 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
private def members: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||
if (
|
||||
value.split(",").exists {
|
||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||
}
|
||||
) None
|
||||
if (value.split(",").exists {
|
||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||
}) None
|
||||
else Some("Must select one manager at least.")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.api.*
|
||||
import gitbucket.core.controller.api.*
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.api._
|
||||
import gitbucket.core.controller.api._
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
|
||||
class ApiController
|
||||
@@ -13,7 +13,6 @@ class ApiController
|
||||
with ApiIssueCommentControllerBase
|
||||
with ApiIssueControllerBase
|
||||
with ApiIssueLabelControllerBase
|
||||
with ApiIssueMilestoneControllerBase
|
||||
with ApiOrganizationControllerBase
|
||||
with ApiPullRequestControllerBase
|
||||
with ApiReleaseControllerBase
|
||||
@@ -23,7 +22,6 @@ class ApiController
|
||||
with ApiRepositoryContentsControllerBase
|
||||
with ApiRepositoryControllerBase
|
||||
with ApiRepositoryStatusControllerBase
|
||||
with ApiRepositoryWebhookControllerBase
|
||||
with ApiUserControllerBase
|
||||
with RepositoryService
|
||||
with AccountService
|
||||
@@ -54,7 +52,6 @@ class ApiController
|
||||
with ReferrerAuthenticator
|
||||
with ReadableUsersAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
with RequestCache
|
||||
|
||||
trait ApiControllerBase extends ControllerBase {
|
||||
|
||||
|
||||
@@ -1,21 +1,22 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import java.io.{File, FileInputStream, FileOutputStream}
|
||||
import java.io.{File, FileInputStream}
|
||||
|
||||
import gitbucket.core.api.{ApiError, JsonFormat}
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.{AccountService, RepositoryService, SystemSettingsService}
|
||||
import gitbucket.core.util.SyntaxSugars.*
|
||||
import gitbucket.core.util.Directory.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.*
|
||||
import org.json4s.*
|
||||
import org.scalatra.{MultiParams, *}
|
||||
import org.scalatra.i18n.*
|
||||
import org.scalatra.json.*
|
||||
import org.scalatra.forms.*
|
||||
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import org.json4s._
|
||||
import org.scalatra._
|
||||
import org.scalatra.i18n._
|
||||
import org.scalatra.json._
|
||||
import org.scalatra.forms._
|
||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||
import javax.servlet.{FilterChain, ServletRequest, ServletResponse}
|
||||
|
||||
import is.tagomor.woothee.Classifier
|
||||
|
||||
import scala.util.Try
|
||||
@@ -24,13 +25,9 @@ import net.coobird.thumbnailator.Thumbnails
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
import org.eclipse.jgit.treewalk.*
|
||||
import org.eclipse.jgit.treewalk._
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.slf4j.LoggerFactory
|
||||
import org.json4s.Formats
|
||||
import org.json4s.jackson.Serialization
|
||||
|
||||
import java.nio.charset.StandardCharsets
|
||||
|
||||
/**
|
||||
* Provides generic features for controller implementations.
|
||||
@@ -46,23 +43,13 @@ abstract class ControllerBase
|
||||
|
||||
private val logger = LoggerFactory.getLogger(getClass)
|
||||
|
||||
implicit val jsonFormats: Formats = gitbucket.core.api.JsonFormat.jsonFormats
|
||||
|
||||
private case class HttpException(status: Int) extends RuntimeException
|
||||
implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats
|
||||
|
||||
before("/api/v3/*") {
|
||||
contentType = formats("json")
|
||||
request.setAttribute(Keys.Request.APIv3, true)
|
||||
}
|
||||
|
||||
override def multiParams(implicit request: HttpServletRequest): MultiParams = {
|
||||
try {
|
||||
super.multiParams
|
||||
} catch {
|
||||
case _: Exception => throw HttpException(400)
|
||||
}
|
||||
}
|
||||
|
||||
override def requestPath(uri: String, idx: Int): String = {
|
||||
val path = super.requestPath(uri, idx)
|
||||
if (path != "/" && path.endsWith("/")) {
|
||||
@@ -96,24 +83,17 @@ abstract class ControllerBase
|
||||
*/
|
||||
implicit def context: Context = {
|
||||
contextCache.get match {
|
||||
case null =>
|
||||
case null => {
|
||||
val context = Context(loadSystemSettings(), LoginAccount, request)
|
||||
contextCache.set(context)
|
||||
context
|
||||
}
|
||||
case context => context
|
||||
}
|
||||
}
|
||||
|
||||
private def LoginAccount: Option[Account] = {
|
||||
request
|
||||
.getAs[Account](Keys.Session.LoginAccount)
|
||||
.orElse(session.getAs[Account](Keys.Session.LoginAccount))
|
||||
.orElse {
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
getLoginAccountFromLocalFile()
|
||||
} else None
|
||||
}
|
||||
}
|
||||
private def LoginAccount: Option[Account] =
|
||||
request.getAs[Account](Keys.Session.LoginAccount).orElse(session.getAs[Account](Keys.Session.LoginAccount))
|
||||
|
||||
def ajaxGet(path: String)(action: => Any): Route =
|
||||
super.get(path) {
|
||||
@@ -139,7 +119,7 @@ abstract class ControllerBase
|
||||
action(form)
|
||||
}
|
||||
|
||||
protected def NotFound(): ActionResult =
|
||||
protected def NotFound() =
|
||||
if (request.hasAttribute(Keys.Request.Ajax)) {
|
||||
org.scalatra.NotFound()
|
||||
} else if (request.hasAttribute(Keys.Request.APIv3)) {
|
||||
@@ -159,7 +139,7 @@ abstract class ControllerBase
|
||||
}
|
||||
}
|
||||
|
||||
protected def Unauthorized()(implicit context: Context): ActionResult =
|
||||
protected def Unauthorized()(implicit context: Context) =
|
||||
if (request.hasAttribute(Keys.Request.Ajax)) {
|
||||
org.scalatra.Unauthorized()
|
||||
} else if (request.hasAttribute(Keys.Request.APIv3)) {
|
||||
@@ -177,8 +157,11 @@ abstract class ControllerBase
|
||||
org.scalatra.Unauthorized(
|
||||
redirect(
|
||||
"/signin?redirect=" + StringUtil.urlEncode(
|
||||
request.getRequestURI
|
||||
.substring(request.getContextPath.length) + Option(request.getQueryString).map("?" + _).getOrElse("")
|
||||
defining(request.getQueryString) { queryString =>
|
||||
request.getRequestURI.substring(request.getContextPath.length) + (if (queryString != null)
|
||||
"?" + queryString
|
||||
else "")
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
@@ -187,9 +170,7 @@ abstract class ControllerBase
|
||||
}
|
||||
|
||||
error {
|
||||
case e: HttpException =>
|
||||
ActionResult(e.status, (), Map.empty)
|
||||
case e =>
|
||||
case e => {
|
||||
logger.error(s"Catch unhandled error in request: ${request}", e)
|
||||
if (request.hasAttribute(Keys.Request.Ajax)) {
|
||||
org.scalatra.InternalServerError()
|
||||
@@ -199,6 +180,7 @@ abstract class ControllerBase
|
||||
} else {
|
||||
org.scalatra.InternalServerError(gitbucket.core.html.error("Internal Server Error", Some(e)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override def url(
|
||||
@@ -210,7 +192,7 @@ abstract class ControllerBase
|
||||
withSessionId: Boolean = true
|
||||
)(implicit request: HttpServletRequest, response: HttpServletResponse): String =
|
||||
if (path.startsWith("http")) path
|
||||
else baseUrl + super.url(path, params, includeContextPath = false, includeServletPath = false, absolutize = false)
|
||||
else baseUrl + super.url(path, params, false, false, false)
|
||||
|
||||
/**
|
||||
* Extends scalatra-form's trim rule to eliminate CR and LF.
|
||||
@@ -254,9 +236,9 @@ abstract class ControllerBase
|
||||
protected def getPathObjectId(git: Git, path: String, revCommit: RevCommit): Option[ObjectId] = {
|
||||
@scala.annotation.tailrec
|
||||
def _getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] = walk.next match {
|
||||
case true if walk.getPathString == path => Some(walk.getObjectId(0))
|
||||
case true => _getPathObjectId(path, walk)
|
||||
case false => None
|
||||
case true if (walk.getPathString == path) => Some(walk.getObjectId(0))
|
||||
case true => _getPathObjectId(path, walk)
|
||||
case false => None
|
||||
}
|
||||
|
||||
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||
@@ -273,7 +255,7 @@ abstract class ControllerBase
|
||||
repository: RepositoryService.RepositoryInfo
|
||||
): Unit = {
|
||||
JGitUtil.getObjectLoaderFromId(git, objectId) { loader =>
|
||||
contentType = FileUtil.getSafeMimeType(path, repository.repository.options.safeMode)
|
||||
contentType = FileUtil.getSafeMimeType(path)
|
||||
|
||||
if (loader.isLarge) {
|
||||
response.setContentLength(loader.getSize.toInt)
|
||||
@@ -297,47 +279,6 @@ abstract class ControllerBase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected object DevFeatures {
|
||||
val KeepSession = "keep-session"
|
||||
}
|
||||
|
||||
private val loginAccountFile = new File(".tmp/login_account.json")
|
||||
|
||||
protected def isDevFeatureEnabled(feature: String): Boolean = {
|
||||
Option(System.getProperty("dev-features")).getOrElse("").split(",").map(_.trim).contains(feature)
|
||||
}
|
||||
|
||||
protected def getLoginAccountFromLocalFile(): Option[Account] = {
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
if (loginAccountFile.exists()) {
|
||||
Using.resource(new FileInputStream(loginAccountFile)) { in =>
|
||||
val json = IOUtils.toString(in, StandardCharsets.UTF_8)
|
||||
val account = parse(json).extract[Account]
|
||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||
Some(parse(json).extract[Account])
|
||||
}
|
||||
} else None
|
||||
|
||||
} else None
|
||||
}
|
||||
|
||||
protected def saveLoginAccountToLocalFile(account: Account): Unit = {
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
if (!loginAccountFile.getParentFile.exists()) {
|
||||
loginAccountFile.getParentFile.mkdirs()
|
||||
}
|
||||
Using.resource(new FileOutputStream(loginAccountFile)) { in =>
|
||||
in.write(Serialization.write(account).getBytes(StandardCharsets.UTF_8))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected def deleteLoginAccountFromLocalFile(): Unit = {
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
loginAccountFile.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -348,25 +289,18 @@ case class Context(
|
||||
loginAccount: Option[Account],
|
||||
request: HttpServletRequest
|
||||
) {
|
||||
val path: String = settings.baseUrl.getOrElse(request.getContextPath)
|
||||
val currentPath: String = request.getRequestURI.substring(request.getContextPath.length)
|
||||
val baseUrl: String = settings.baseUrl(request)
|
||||
val host: String = new java.net.URL(baseUrl).getHost
|
||||
val platform: String = request.getHeader("User-Agent") match {
|
||||
val path = settings.baseUrl.getOrElse(request.getContextPath)
|
||||
val currentPath = request.getRequestURI.substring(request.getContextPath.length)
|
||||
val baseUrl = settings.baseUrl(request)
|
||||
val host = new java.net.URL(baseUrl).getHost
|
||||
val platform = request.getHeader("User-Agent") match {
|
||||
case null => null
|
||||
case agent if agent.contains("Mac") => "mac"
|
||||
case agent if agent.contains("Linux") => "linux"
|
||||
case agent if agent.contains("Win") => "windows"
|
||||
case _ => null
|
||||
}
|
||||
val sidebarCollapse: Boolean = request.getSession.getAttribute("sidebar-collapse") != null
|
||||
|
||||
def withLoginAccount(f: Account => Any): Any = {
|
||||
loginAccount match {
|
||||
case Some(loginAccount) => f(loginAccount)
|
||||
case None => Unauthorized()
|
||||
}
|
||||
}
|
||||
val sidebarCollapse = request.getSession.getAttribute("sidebar-collapse") != null
|
||||
|
||||
/**
|
||||
* Get object from cache.
|
||||
@@ -374,14 +308,14 @@ case class Context(
|
||||
* If object has not been cached with the specified key then retrieves by given action.
|
||||
* Cached object are available during a request.
|
||||
*/
|
||||
def cache[A](key: String)(action: => A): A = {
|
||||
val cacheKey = Keys.Request.Cache(key)
|
||||
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
||||
val newObject = action
|
||||
request.setAttribute(cacheKey, newObject)
|
||||
newObject
|
||||
def cache[A](key: String)(action: => A): A =
|
||||
defining(Keys.Request.Cache(key)) { cacheKey =>
|
||||
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
||||
val newObject = action
|
||||
request.setAttribute(cacheKey, newObject)
|
||||
newObject
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -433,16 +367,15 @@ trait AccountManagementControllerBase extends ControllerBase {
|
||||
messages: Messages
|
||||
): Option[String] = {
|
||||
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||
if (
|
||||
extraMailAddresses.exists { case (k, v) =>
|
||||
v.contains(value)
|
||||
}
|
||||
) {
|
||||
if (extraMailAddresses.exists {
|
||||
case (k, v) =>
|
||||
v.contains(value)
|
||||
}) {
|
||||
Some("These mail addresses are duplicated.")
|
||||
} else {
|
||||
getAccountByMailAddress(value, includeRemoved = true)
|
||||
getAccountByMailAddress(value, true)
|
||||
.collect {
|
||||
case x if paramName.isEmpty || !params.optionValue(paramName).contains(x.userName) =>
|
||||
case x if paramName.isEmpty || Some(x.userName) != params.optionValue(paramName) =>
|
||||
"Mail address is already registered."
|
||||
}
|
||||
}
|
||||
@@ -457,23 +390,22 @@ trait AccountManagementControllerBase extends ControllerBase {
|
||||
messages: Messages
|
||||
): Option[String] = {
|
||||
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||
if (
|
||||
params.optionValue("mailAddress").contains(value) || extraMailAddresses.count { case (k, v) =>
|
||||
v.contains(value)
|
||||
} > 1
|
||||
) {
|
||||
if (Some(value) == params.optionValue("mailAddress") || extraMailAddresses.count {
|
||||
case (k, v) =>
|
||||
v.contains(value)
|
||||
} > 1) {
|
||||
Some("These mail addresses are duplicated.")
|
||||
} else {
|
||||
getAccountByMailAddress(value, includeRemoved = true)
|
||||
getAccountByMailAddress(value, true)
|
||||
.collect {
|
||||
case x if paramName.isEmpty || !params.optionValue(paramName).contains(x.userName) =>
|
||||
case x if paramName.isEmpty || Some(x.userName) != params.optionValue(paramName) =>
|
||||
"Mail address is already registered."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private val allReservedNames = Set(
|
||||
val allReservedNames = Set(
|
||||
"git",
|
||||
"admin",
|
||||
"upload",
|
||||
@@ -489,12 +421,13 @@ trait AccountManagementControllerBase extends ControllerBase {
|
||||
"new"
|
||||
)
|
||||
|
||||
protected def reservedNames: Constraint = new Constraint() {
|
||||
protected def reservedNames(): Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (allReservedNames.contains(value.toLowerCase)) {
|
||||
Some(s"$value is reserved")
|
||||
Some(s"${value} is reserved")
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.dashboard.html
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.util.UsersAuthenticator
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.service.IssuesService.*
|
||||
import gitbucket.core.service.ActivityService.*
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.service.IssuesService._
|
||||
|
||||
class DashboardController
|
||||
extends DashboardControllerBase
|
||||
@@ -23,75 +21,54 @@ class DashboardController
|
||||
with WebHookPullRequestService
|
||||
with WebHookPullRequestReviewCommentService
|
||||
with MilestonesService
|
||||
with CommitStatusService
|
||||
with UsersAuthenticator
|
||||
with RequestCache
|
||||
|
||||
trait DashboardControllerBase extends ControllerBase {
|
||||
self: IssuesService & PullRequestService & RepositoryService & AccountService & CommitStatusService &
|
||||
UsersAuthenticator =>
|
||||
self: IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator =>
|
||||
|
||||
get("/dashboard/repos")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
val repos = getVisibleRepositories(
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
)
|
||||
html.repos(getGroupNames(loginAccount.userName), repos, repos, isNewsFeedEnabled)
|
||||
}
|
||||
val repos = getVisibleRepositories(
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.limitVisibleRepositories
|
||||
)
|
||||
html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos)
|
||||
})
|
||||
|
||||
get("/dashboard/issues")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchIssues(loginAccount, "created_by")
|
||||
}
|
||||
searchIssues("created_by")
|
||||
})
|
||||
|
||||
get("/dashboard/issues/assigned")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchIssues(loginAccount, "assigned")
|
||||
}
|
||||
searchIssues("assigned")
|
||||
})
|
||||
|
||||
get("/dashboard/issues/created_by")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchIssues(loginAccount, "created_by")
|
||||
}
|
||||
searchIssues("created_by")
|
||||
})
|
||||
|
||||
get("/dashboard/issues/mentioned")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchIssues(loginAccount, "mentioned")
|
||||
}
|
||||
searchIssues("mentioned")
|
||||
})
|
||||
|
||||
get("/dashboard/pulls")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchPullRequests(loginAccount, "created_by")
|
||||
}
|
||||
searchPullRequests("created_by")
|
||||
})
|
||||
|
||||
get("/dashboard/pulls/created_by")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchPullRequests(loginAccount, "created_by")
|
||||
}
|
||||
searchPullRequests("created_by")
|
||||
})
|
||||
|
||||
get("/dashboard/pulls/assigned")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchPullRequests(loginAccount, "assigned")
|
||||
}
|
||||
searchPullRequests("assigned")
|
||||
})
|
||||
|
||||
get("/dashboard/pulls/mentioned")(usersOnly {
|
||||
context.withLoginAccount { loginAccount =>
|
||||
searchPullRequests(loginAccount, "mentioned")
|
||||
}
|
||||
searchPullRequests("mentioned")
|
||||
})
|
||||
|
||||
private def getOrCreateCondition(filter: String, userName: String) = {
|
||||
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
||||
val condition = IssueSearchCondition(request)
|
||||
|
||||
filter match {
|
||||
@@ -101,20 +78,19 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private def searchIssues(loginAccount: Account, filter: String) = {
|
||||
import IssuesService.*
|
||||
private def searchIssues(filter: String) = {
|
||||
import IssuesService._
|
||||
|
||||
val userName = loginAccount.userName
|
||||
val condition = getOrCreateCondition(filter, userName)
|
||||
val userRepos = getUserRepositories(userName, withoutPhysicalInfo = true).map(repo => repo.owner -> repo.name)
|
||||
val userName = context.loginAccount.get.userName
|
||||
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
||||
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
||||
val page = IssueSearchCondition.page(request)
|
||||
val issues = searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, userRepos*)
|
||||
|
||||
html.issues(
|
||||
issues.map(issue => (issue, None)),
|
||||
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, userRepos: _*),
|
||||
page,
|
||||
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, userRepos*),
|
||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, userRepos*),
|
||||
countIssue(condition.copy(state = "open"), false, userRepos: _*),
|
||||
countIssue(condition.copy(state = "closed"), false, userRepos: _*),
|
||||
filter match {
|
||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||
@@ -126,38 +102,25 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
),
|
||||
isNewsFeedEnabled
|
||||
limit = context.settings.limitVisibleRepositories
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
private def searchPullRequests(loginAccount: Account, filter: String) = {
|
||||
import IssuesService.*
|
||||
import PullRequestService.*
|
||||
private def searchPullRequests(filter: String) = {
|
||||
import IssuesService._
|
||||
import PullRequestService._
|
||||
|
||||
val userName = loginAccount.userName
|
||||
val condition = getOrCreateCondition(filter, userName)
|
||||
val userName = context.loginAccount.get.userName
|
||||
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
||||
val allRepos = getAllRepositories(userName)
|
||||
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(
|
||||
issues.zip(status),
|
||||
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, allRepos: _*),
|
||||
page,
|
||||
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, allRepos*),
|
||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, allRepos*),
|
||||
countIssue(condition.copy(state = "open"), true, allRepos: _*),
|
||||
countIssue(condition.copy(state = "closed"), true, allRepos: _*),
|
||||
filter match {
|
||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||
@@ -169,9 +132,8 @@ trait DashboardControllerBase extends ControllerBase {
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
),
|
||||
isNewsFeedEnabled
|
||||
limit = context.settings.limitVisibleRepositories
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -6,6 +6,7 @@ import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.{AccountService, ReleaseService, RepositoryService}
|
||||
import gitbucket.core.servlet.Database
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -17,7 +18,6 @@ import org.apache.commons.io.{FileUtils, IOUtils}
|
||||
|
||||
import scala.util.Using
|
||||
import gitbucket.core.service.SystemSettingsService
|
||||
import slick.jdbc.JdbcBackend.Session
|
||||
|
||||
/**
|
||||
* Provides Ajax based file upload functionality.
|
||||
@@ -37,10 +37,10 @@ class FileUploadController
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
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
|
||||
},
|
||||
FileUtil.isImage(_)
|
||||
FileUtil.isImage
|
||||
)
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class FileUploadController
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
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
|
||||
},
|
||||
_ => true
|
||||
@@ -65,7 +65,7 @@ class FileUploadController
|
||||
getAttachedDir(params("owner"), params("repository")),
|
||||
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
||||
),
|
||||
file.get()
|
||||
file.get
|
||||
)
|
||||
},
|
||||
_ => true
|
||||
@@ -75,92 +75,92 @@ class FileUploadController
|
||||
post("/wiki/:owner/:repository") {
|
||||
setMultipartConfig()
|
||||
// Don't accept not logged-in users
|
||||
session.get(Keys.Session.LoginAccount).collect { case loginAccount: Account =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
session.get(Keys.Session.LoginAccount).collect {
|
||||
case loginAccount: Account =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
|
||||
// Check whether logged-in user is collaborator
|
||||
onlyWikiEditable(owner, repository, loginAccount) {
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
val fileName = file.getName
|
||||
LockUtil.lock(s"$owner/$repository/wiki") {
|
||||
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
||||
val builder = DirCache.newInCore.builder()
|
||||
val inserter = git.getRepository.newObjectInserter()
|
||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||
// Check whether logged-in user is collaborator
|
||||
onlyWikiEditable(owner, repository, loginAccount) {
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
val fileName = file.getName
|
||||
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
||||
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) {
|
||||
git =>
|
||||
val builder = DirCache.newInCore.builder()
|
||||
val inserter = git.getRepository.newObjectInserter()
|
||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||
|
||||
if (headId != null) {
|
||||
JGitUtil.processTree(git, headId) { (path, tree) =>
|
||||
if (path != fileName) {
|
||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||
if (headId != null) {
|
||||
JGitUtil.processTree(git, headId) { (path, tree) =>
|
||||
if (path != fileName) {
|
||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val bytes = IOUtils.toByteArray(file.getInputStream)
|
||||
builder.add(
|
||||
JGitUtil.createDirCacheEntry(
|
||||
fileName,
|
||||
FileMode.REGULAR_FILE,
|
||||
inserter.insert(Constants.OBJ_BLOB, bytes)
|
||||
)
|
||||
)
|
||||
builder.finish()
|
||||
|
||||
val newHeadId = JGitUtil.createNewCommit(
|
||||
git,
|
||||
inserter,
|
||||
headId,
|
||||
builder.getDirCache.writeTree(inserter),
|
||||
Constants.HEAD,
|
||||
loginAccount.fullName,
|
||||
loginAccount.mailAddress,
|
||||
s"Uploaded ${fileName}"
|
||||
)
|
||||
|
||||
fileName
|
||||
}
|
||||
|
||||
val bytes = IOUtils.toByteArray(file.getInputStream)
|
||||
builder.add(
|
||||
JGitUtil.createDirCacheEntry(
|
||||
fileName,
|
||||
FileMode.REGULAR_FILE,
|
||||
inserter.insert(Constants.OBJ_BLOB, bytes)
|
||||
)
|
||||
)
|
||||
builder.finish()
|
||||
|
||||
JGitUtil.createNewCommit(
|
||||
git,
|
||||
inserter,
|
||||
headId,
|
||||
builder.getDirCache.writeTree(inserter),
|
||||
Constants.HEAD,
|
||||
loginAccount.fullName,
|
||||
loginAccount.mailAddress,
|
||||
s"Uploaded $fileName"
|
||||
)
|
||||
|
||||
fileName
|
||||
}
|
||||
}
|
||||
},
|
||||
_ => true
|
||||
)
|
||||
}
|
||||
},
|
||||
_ => true
|
||||
)
|
||||
}
|
||||
} getOrElse BadRequest()
|
||||
}
|
||||
|
||||
post("/release/:owner/:repository/*") {
|
||||
post("/release/:owner/:repository/:tag") {
|
||||
setMultipartConfigForLargeFile()
|
||||
session
|
||||
.get(Keys.Session.LoginAccount)
|
||||
.collect { case _: Account =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val tag = multiParams("splat").head
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
FileUtils.writeByteArrayToFile(
|
||||
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
||||
file.get()
|
||||
)
|
||||
},
|
||||
_ => true
|
||||
)
|
||||
.collect {
|
||||
case _: Account =>
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val tag = params("tag")
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
FileUtils.writeByteArrayToFile(
|
||||
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
||||
file.get
|
||||
)
|
||||
},
|
||||
_ => true
|
||||
)
|
||||
}
|
||||
.getOrElse(BadRequest())
|
||||
}
|
||||
|
||||
post("/import") {
|
||||
import JDBCUtil.*
|
||||
import JDBCUtil._
|
||||
setMultipartConfig()
|
||||
session.get(Keys.Session.LoginAccount).collect {
|
||||
case loginAccount: Account if loginAccount.isAdmin =>
|
||||
execute(
|
||||
{ (file, fileId) =>
|
||||
request2Session(request).conn.importAsSQL(file.getInputStream)
|
||||
},
|
||||
_ => true
|
||||
)
|
||||
execute({ (file, fileId) =>
|
||||
request2Session(request).conn.importAsSQL(file.getInputStream)
|
||||
}, _ => true)
|
||||
}
|
||||
redirect("/admin/data")
|
||||
}
|
||||
@@ -168,17 +168,17 @@ class FileUploadController
|
||||
private def setMultipartConfig(): Unit = {
|
||||
val settings = loadSystemSettings()
|
||||
val config = MultipartConfig(maxFileSize = Some(settings.upload.maxFileSize))
|
||||
config.apply(request.getServletContext)
|
||||
config.apply(request.getServletContext())
|
||||
}
|
||||
|
||||
private def setMultipartConfigForLargeFile(): Unit = {
|
||||
val settings = loadSystemSettings()
|
||||
val config = MultipartConfig(maxFileSize = Some(settings.upload.largeMaxFileSize))
|
||||
config.apply(request.getServletContext)
|
||||
config.apply(request.getServletContext())
|
||||
}
|
||||
|
||||
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 {
|
||||
case Some(x) =>
|
||||
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 {
|
||||
case Some(file) if mimeTypeChecker(file.name) =>
|
||||
val fileId = FileUtil.generateFileId
|
||||
f(file, fileId)
|
||||
contentType = "text/plain"
|
||||
Ok(fileId)
|
||||
case Some(file) if (mimeTypeChcker(file.name)) =>
|
||||
defining(FileUtil.generateFileId) { fileId =>
|
||||
f(file, fileId)
|
||||
contentType = "text/plain"
|
||||
Ok(fileId)
|
||||
}
|
||||
case _ => BadRequest()
|
||||
}
|
||||
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import com.nimbusds.jwt.JWT
|
||||
|
||||
import java.net.URI
|
||||
|
||||
import com.nimbusds.oauth2.sdk.id.State
|
||||
import com.nimbusds.openid.connect.sdk.Nonce
|
||||
import gitbucket.core.helper.xml
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.view.helpers.*
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.view.helpers._
|
||||
import org.scalatra.Ok
|
||||
import org.scalatra.forms.*
|
||||
|
||||
import gitbucket.core.service.ActivityService.*
|
||||
import org.scalatra.forms._
|
||||
|
||||
class IndexController
|
||||
extends IndexControllerBase
|
||||
@@ -31,15 +29,21 @@ class IndexController
|
||||
with AccessTokenService
|
||||
with AccountFederationService
|
||||
with OpenIDConnectService
|
||||
with RequestCache
|
||||
|
||||
trait IndexControllerBase extends ControllerBase {
|
||||
self: RepositoryService & ActivityService & AccountService & RepositorySearchService & UsersAuthenticator &
|
||||
ReferrerAuthenticator & AccessTokenService & AccountFederationService & OpenIDConnectService =>
|
||||
self: RepositoryService
|
||||
with ActivityService
|
||||
with AccountService
|
||||
with RepositorySearchService
|
||||
with UsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with AccessTokenService
|
||||
with AccountFederationService
|
||||
with OpenIDConnectService =>
|
||||
|
||||
private case class SignInForm(userName: String, password: String, hash: Option[String])
|
||||
case class SignInForm(userName: String, password: String, hash: Option[String])
|
||||
|
||||
private val signinForm = mapping(
|
||||
val signinForm = mapping(
|
||||
"userName" -> trim(label("Username", text(required))),
|
||||
"password" -> trim(label("Password", text(required))),
|
||||
"hash" -> trim(optional(text()))
|
||||
@@ -53,53 +57,38 @@ trait IndexControllerBase extends ControllerBase {
|
||||
//
|
||||
// case class SearchForm(query: String, owner: String, repository: String)
|
||||
|
||||
private case class OidcAuthContext(state: State, nonce: Nonce, redirectBackURI: String)
|
||||
private case class OidcSessionContext(token: JWT)
|
||||
case class OidcContext(state: State, nonce: Nonce, redirectBackURI: String)
|
||||
|
||||
get("/") {
|
||||
context.loginAccount
|
||||
.map { account =>
|
||||
// val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
||||
if (!isNewsFeedEnabled) {
|
||||
redirect("/dashboard/repos")
|
||||
} else {
|
||||
val repos = getVisibleRepositories(
|
||||
val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
||||
gitbucket.core.html.index(
|
||||
getRecentActivitiesByOwners(visibleOwnerSet),
|
||||
getVisibleRepositories(
|
||||
Some(account),
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = false
|
||||
limit = context.settings.limitVisibleRepositories
|
||||
),
|
||||
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
||||
account.userName
|
||||
)
|
||||
|
||||
gitbucket.core.html.index(
|
||||
activities = getRecentActivitiesByRepos(repos.map(x => (x.owner, x.name)).toSet),
|
||||
recentRepositories = if (context.settings.basicBehavior.limitVisibleRepositories) {
|
||||
repos.filter(x => x.owner == account.userName)
|
||||
} else repos,
|
||||
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
||||
account.userName
|
||||
),
|
||||
enableNewsFeed = isNewsFeedEnabled
|
||||
)
|
||||
}
|
||||
)
|
||||
}
|
||||
.getOrElse {
|
||||
gitbucket.core.html.index(
|
||||
activities = getRecentPublicActivities(),
|
||||
recentRepositories = getVisibleRepositories(None, withoutPhysicalInfo = true),
|
||||
showBannerToCreatePersonalAccessToken = false,
|
||||
enableNewsFeed = isNewsFeedEnabled
|
||||
getRecentActivities(),
|
||||
getVisibleRepositories(None, withoutPhysicalInfo = true),
|
||||
showBannerToCreatePersonalAccessToken = false
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
get("/signin") {
|
||||
if (context.loginAccount.nonEmpty) {
|
||||
redirect("/")
|
||||
}
|
||||
params.get("redirect").foreach { redirect =>
|
||||
if (redirect.startsWith("/")) {
|
||||
flash.update(Keys.Flash.Redirect, redirect)
|
||||
}
|
||||
val redirect = params.get("redirect")
|
||||
if (redirect.isDefined && redirect.get.startsWith("/")) {
|
||||
flash.update(Keys.Flash.Redirect, redirect.get)
|
||||
}
|
||||
gitbucket.core.html.signin(flash.get("userName"), flash.get("password"), flash.get("error"))
|
||||
}
|
||||
@@ -131,8 +120,8 @@ trait IndexControllerBase extends ControllerBase {
|
||||
case _ => "/"
|
||||
}
|
||||
session.setAttribute(
|
||||
Keys.Session.OidcAuthContext,
|
||||
OidcAuthContext(authenticationRequest.getState, authenticationRequest.getNonce, redirectBackURI)
|
||||
Keys.Session.OidcContext,
|
||||
OidcContext(authenticationRequest.getState, authenticationRequest.getNonce, redirectBackURI)
|
||||
)
|
||||
redirect(authenticationRequest.toURI.toString)
|
||||
} getOrElse {
|
||||
@@ -146,10 +135,9 @@ trait IndexControllerBase extends ControllerBase {
|
||||
get("/signin/oidc") {
|
||||
context.settings.oidc.map { oidc =>
|
||||
val redirectURI = new URI(s"$baseUrl/signin/oidc")
|
||||
session.get(Keys.Session.OidcAuthContext) match {
|
||||
case Some(context: OidcAuthContext) =>
|
||||
authenticate(params.toMap, redirectURI, context.state, context.nonce, oidc).map { case (jwt, account) =>
|
||||
session.setAttribute(Keys.Session.OidcSessionContext, OidcSessionContext(jwt))
|
||||
session.get(Keys.Session.OidcContext) match {
|
||||
case Some(context: OidcContext) =>
|
||||
authenticate(params.toMap, redirectURI, context.state, context.nonce, oidc).map { account =>
|
||||
signin(account, context.redirectBackURI)
|
||||
} orElse {
|
||||
flash.update("error", "Sorry, authentication failed. Please try again.")
|
||||
@@ -167,24 +155,13 @@ trait IndexControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
get("/signout") {
|
||||
context.settings.oidc.foreach { oidc =>
|
||||
session.get(Keys.Session.OidcSessionContext).foreach { case context: OidcSessionContext =>
|
||||
val redirectURI = new URI(baseUrl)
|
||||
val authenticationRequest = createOIDLogoutRequest(oidc.issuer, oidc.clientID, redirectURI, context.token)
|
||||
session.invalidate()
|
||||
redirect(authenticationRequest.toURI.toString)
|
||||
}
|
||||
}
|
||||
session.invalidate()
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
deleteLoginAccountFromLocalFile()
|
||||
}
|
||||
session.invalidate
|
||||
redirect("/")
|
||||
}
|
||||
|
||||
get("/activities.atom") {
|
||||
contentType = "application/atom+xml; type=feed"
|
||||
xml.feed(getRecentPublicActivities())
|
||||
xml.feed(getRecentActivities())
|
||||
}
|
||||
|
||||
post("/sidebar-collapse") {
|
||||
@@ -196,24 +173,11 @@ trait IndexControllerBase extends ControllerBase {
|
||||
Ok()
|
||||
}
|
||||
|
||||
get("/user.css") {
|
||||
context.settings.userDefinedCss match {
|
||||
case Some(css) =>
|
||||
contentType = "text/css"
|
||||
css
|
||||
case None =>
|
||||
NotFound()
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set account information into HttpSession and redirect.
|
||||
*/
|
||||
private def signin(account: Account, redirectUrl: String = "/") = {
|
||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||
if (isDevFeatureEnabled(DevFeatures.KeepSession)) {
|
||||
saveLoginAccountToLocalFile(account)
|
||||
}
|
||||
updateLastLoginDate(account.userName)
|
||||
|
||||
if (LDAPUtil.isDummyMailAddress(account)) {
|
||||
@@ -236,8 +200,8 @@ trait IndexControllerBase extends ControllerBase {
|
||||
val group = params("group").toBoolean
|
||||
org.json4s.jackson.Serialization.write(
|
||||
Map(
|
||||
"options" ->
|
||||
getAllUsers(includeRemoved = false)
|
||||
"options" -> (
|
||||
getAllUsers(false)
|
||||
.withFilter { t =>
|
||||
(user, group) match {
|
||||
case (true, true) => true
|
||||
@@ -248,84 +212,72 @@ trait IndexControllerBase extends ControllerBase {
|
||||
}
|
||||
.map { t =>
|
||||
Map(
|
||||
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(
|
||||
StringUtil.cutTail(t.userName, 25, "...")
|
||||
)}</b> ${StringUtil
|
||||
.escapeHtml(StringUtil.cutTail(t.fullName, 25, "..."))}",
|
||||
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(t.userName)}</b> ${StringUtil
|
||||
.escapeHtml(t.fullName)}",
|
||||
"value" -> t.userName
|
||||
)
|
||||
}
|
||||
)
|
||||
)
|
||||
)
|
||||
})
|
||||
|
||||
/**
|
||||
* JSON API for checking user or group existence.
|
||||
*
|
||||
* Returns a single string which is any of "group", "user" or "".
|
||||
* Additionally, check whether the user is writable to the repository
|
||||
* if "owner" and "repository" are given,
|
||||
*/
|
||||
post("/_user/existence")(usersOnly {
|
||||
getAccountByUserNameIgnoreCase(params("userName")).map { account =>
|
||||
if (!account.isGroupAccount && params.get("repository").isDefined && params.get("owner").isDefined) {
|
||||
getRepository(params("owner"), params("repository"))
|
||||
.collect {
|
||||
case repository if isWritable(repository.repository, Some(account)) => "user"
|
||||
}
|
||||
.getOrElse("")
|
||||
} else {
|
||||
if (account.isGroupAccount) "group" else "user"
|
||||
}
|
||||
if (account.isGroupAccount) "group" else "user"
|
||||
} getOrElse ""
|
||||
})
|
||||
|
||||
// TODO Move to RepositoryViewerController?
|
||||
// TODO Move to RepositoryViewrController?
|
||||
get("/:owner/:repository/search")(referrersOnly { repository =>
|
||||
val query = params.getOrElse("q", "").trim
|
||||
val target = params.getOrElse("type", "code")
|
||||
val page =
|
||||
try {
|
||||
val i = params.getOrElse("page", "1").toInt
|
||||
if (i <= 0) 1 else i
|
||||
} catch {
|
||||
case _: NumberFormatException => 1
|
||||
}
|
||||
defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")) {
|
||||
case (query, target) =>
|
||||
val page = try {
|
||||
val i = params.getOrElse("page", "1").toInt
|
||||
if (i <= 0) 1 else i
|
||||
} catch {
|
||||
case e: NumberFormatException => 1
|
||||
}
|
||||
|
||||
target.toLowerCase match {
|
||||
case "issues" =>
|
||||
gitbucket.core.search.html.issues(
|
||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, pullRequest = false) else Nil,
|
||||
pullRequest = false,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
target.toLowerCase match {
|
||||
case "issues" =>
|
||||
gitbucket.core.search.html.issues(
|
||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, false) else Nil,
|
||||
false,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
|
||||
case "pulls" =>
|
||||
gitbucket.core.search.html.issues(
|
||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, pullRequest = true) else Nil,
|
||||
pullRequest = true,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
case "pulls" =>
|
||||
gitbucket.core.search.html.issues(
|
||||
if (query.nonEmpty) searchIssues(repository.owner, repository.name, query, true) else Nil,
|
||||
true,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
|
||||
case "wiki" =>
|
||||
gitbucket.core.search.html.wiki(
|
||||
if (query.nonEmpty) searchWikiPages(repository.owner, repository.name, query) else Nil,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
case "wiki" =>
|
||||
gitbucket.core.search.html.wiki(
|
||||
if (query.nonEmpty) searchWikiPages(repository.owner, repository.name, query) else Nil,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
|
||||
case _ =>
|
||||
gitbucket.core.search.html.code(
|
||||
if (query.nonEmpty) searchFiles(repository.owner, repository.name, query) else Nil,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
case _ =>
|
||||
gitbucket.core.search.html.code(
|
||||
if (query.nonEmpty) searchFiles(repository.owner, repository.name, query) else Nil,
|
||||
query,
|
||||
page,
|
||||
repository
|
||||
)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
@@ -336,19 +288,19 @@ trait IndexControllerBase extends ControllerBase {
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||
limit = context.settings.limitVisibleRepositories
|
||||
)
|
||||
|
||||
val repositories = {
|
||||
if (context.settings.basicBehavior.limitVisibleRepositories) {
|
||||
getVisibleRepositories(
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = false
|
||||
)
|
||||
} else {
|
||||
visibleRepositories
|
||||
context.settings.limitVisibleRepositories match {
|
||||
case true =>
|
||||
getVisibleRepositories(
|
||||
context.loginAccount,
|
||||
None,
|
||||
withoutPhysicalInfo = true,
|
||||
limit = false
|
||||
)
|
||||
case false => visibleRepositories
|
||||
}
|
||||
}.filter { repository =>
|
||||
repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.issues.html
|
||||
import gitbucket.core.model.{Account, CustomFieldBehavior}
|
||||
import gitbucket.core.service.IssuesService.*
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.service.IssuesService._
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.view
|
||||
import gitbucket.core.view.Markdown
|
||||
import org.scalatra.forms.*
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.{BadRequest, Ok}
|
||||
|
||||
class IssuesController
|
||||
@@ -21,7 +21,6 @@ class IssuesController
|
||||
with ActivityService
|
||||
with HandleCommentService
|
||||
with IssueCreationService
|
||||
with CustomFieldsService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
@@ -31,242 +30,224 @@ class IssuesController
|
||||
with WebHookPullRequestReviewCommentService
|
||||
with CommitsService
|
||||
with PrioritiesService
|
||||
with RequestCache
|
||||
|
||||
trait IssuesControllerBase extends ControllerBase {
|
||||
self: IssuesService & RepositoryService & AccountService & LabelsService & MilestonesService & ActivityService &
|
||||
HandleCommentService & IssueCreationService & CustomFieldsService & ReadableUsersAuthenticator &
|
||||
ReferrerAuthenticator & WritableUsersAuthenticator & PullRequestService & WebHookIssueCommentService &
|
||||
PrioritiesService =>
|
||||
self: IssuesService
|
||||
with RepositoryService
|
||||
with AccountService
|
||||
with LabelsService
|
||||
with MilestonesService
|
||||
with ActivityService
|
||||
with HandleCommentService
|
||||
with IssueCreationService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
with PullRequestService
|
||||
with WebHookIssueCommentService
|
||||
with PrioritiesService =>
|
||||
|
||||
private case class IssueCreateForm(
|
||||
case class IssueCreateForm(
|
||||
title: String,
|
||||
content: Option[String],
|
||||
assigneeUserNames: Option[String],
|
||||
assignedUserName: Option[String],
|
||||
milestoneId: Option[Int],
|
||||
priorityId: Option[Int],
|
||||
labelNames: Option[String]
|
||||
)
|
||||
private case class CommentForm(issueId: Int, content: String)
|
||||
private case class IssueStateForm(issueId: Int, content: Option[String])
|
||||
case class CommentForm(issueId: Int, content: String)
|
||||
case class IssueStateForm(issueId: Int, content: Option[String])
|
||||
|
||||
private val issueCreateForm = mapping(
|
||||
val issueCreateForm = mapping(
|
||||
"title" -> trim(label("Title", text(required))),
|
||||
"content" -> trim(optional(text())),
|
||||
"assigneeUserNames" -> trim(optional(text())),
|
||||
"assignedUserName" -> trim(optional(text())),
|
||||
"milestoneId" -> trim(optional(number())),
|
||||
"priorityId" -> trim(optional(number())),
|
||||
"labelNames" -> trim(optional(text()))
|
||||
)(IssueCreateForm.apply)
|
||||
|
||||
private val issueTitleEditForm = mapping(
|
||||
val issueTitleEditForm = mapping(
|
||||
"title" -> trim(label("Title", text(required)))
|
||||
)(x => x)
|
||||
private val issueEditForm = mapping(
|
||||
val issueEditForm = mapping(
|
||||
"content" -> trim(optional(text()))
|
||||
)(x => x)
|
||||
|
||||
private val commentForm = mapping(
|
||||
val commentForm = mapping(
|
||||
"issueId" -> label("Issue Id", number()),
|
||||
"content" -> trim(label("Comment", text(required)))
|
||||
)(CommentForm.apply)
|
||||
|
||||
private val issueStateForm = mapping(
|
||||
val issueStateForm = mapping(
|
||||
"issueId" -> label("Issue Id", number()),
|
||||
"content" -> trim(optional(text()))
|
||||
)(IssueStateForm.apply)
|
||||
|
||||
get("/:owner/:repository/issues")(referrersOnly { repository =>
|
||||
val q = request.getParameter("q")
|
||||
Option(q) match {
|
||||
case Some(filter) if filter.contains("is:pr") =>
|
||||
redirect(s"/${repository.owner}/${repository.name}/pulls?q=${StringUtil.urlEncode(q)}")
|
||||
case Some(filter) =>
|
||||
val condition = IssueSearchCondition(filter)
|
||||
if (condition.isEmpty) {
|
||||
// Redirect to keyword search
|
||||
redirect(s"/${repository.owner}/${repository.name}/search?q=${StringUtil.urlEncode(q)}&type=issues")
|
||||
} else {
|
||||
searchIssues(repository, condition, IssueSearchCondition.page(request))
|
||||
}
|
||||
case None =>
|
||||
searchIssues(repository, IssueSearchCondition(request), IssueSearchCondition.page(request))
|
||||
if (Option(q).exists(_.contains("is:pr"))) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/pulls?q=${StringUtil.urlEncode(q)}")
|
||||
} else {
|
||||
searchIssues(repository)
|
||||
}
|
||||
})
|
||||
|
||||
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
||||
val issueId = params("id")
|
||||
getIssue(repository.owner, repository.name, issueId) map { issue =>
|
||||
if (issue.isPullRequest) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/pull/$issueId")
|
||||
} else {
|
||||
html.issue(
|
||||
issue,
|
||||
getComments(repository.owner, repository.name, issueId.toInt),
|
||||
getIssueLabels(repository.owner, repository.name, issueId.toInt),
|
||||
getIssueAssignees(repository.owner, repository.name, issueId.toInt),
|
||||
getAssignableUserNames(repository.owner, repository.name),
|
||||
getMilestonesWithIssueCount(repository.owner, repository.name),
|
||||
getPriorities(repository.owner, repository.name),
|
||||
getLabels(repository.owner, repository.name),
|
||||
getCustomFieldsWithValue(repository.owner, repository.name, issueId.toInt).filter(_._1.enableForIssues),
|
||||
isIssueEditable(repository),
|
||||
isIssueManageable(repository),
|
||||
isIssueCommentManageable(repository),
|
||||
repository
|
||||
)
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
defining(repository.owner, repository.name, params("id")) {
|
||||
case (owner, name, issueId) =>
|
||||
getIssue(owner, name, issueId) map {
|
||||
issue =>
|
||||
if (issue.isPullRequest) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||
} else {
|
||||
html.issue(
|
||||
issue,
|
||||
getComments(owner, name, issueId.toInt),
|
||||
getIssueLabels(owner, name, issueId.toInt),
|
||||
getAssignableUserNames(owner, name),
|
||||
getMilestonesWithIssueCount(owner, name),
|
||||
getPriorities(owner, name),
|
||||
getLabels(owner, name),
|
||||
isIssueEditable(repository),
|
||||
isIssueManageable(repository),
|
||||
repository
|
||||
)
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||
html.create(
|
||||
getAssignableUserNames(repository.owner, repository.name),
|
||||
getMilestones(repository.owner, repository.name),
|
||||
getPriorities(repository.owner, repository.name),
|
||||
getDefaultPriority(repository.owner, repository.name),
|
||||
getLabels(repository.owner, repository.name),
|
||||
getCustomFields(repository.owner, repository.name).filter(_.enableForIssues),
|
||||
isIssueManageable(repository),
|
||||
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
||||
repository
|
||||
)
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
html.create(
|
||||
getAssignableUserNames(owner, name),
|
||||
getMilestones(owner, name),
|
||||
getPriorities(owner, name),
|
||||
getDefaultPriority(owner, name),
|
||||
getLabels(owner, name),
|
||||
isIssueManageable(repository),
|
||||
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
||||
repository
|
||||
)
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||
val issue = createIssue(
|
||||
repository,
|
||||
form.title,
|
||||
form.content,
|
||||
form.assigneeUserNames.toSeq.flatMap(_.split(",")),
|
||||
form.milestoneId,
|
||||
form.priorityId,
|
||||
form.labelNames.toSeq.flatMap(_.split(",")),
|
||||
loginAccount
|
||||
)
|
||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||
val issue = createIssue(
|
||||
repository,
|
||||
form.title,
|
||||
form.content,
|
||||
form.assignedUserName,
|
||||
form.milestoneId,
|
||||
form.priorityId,
|
||||
form.labelNames.toSeq.flatMap(_.split(",")),
|
||||
context.loginAccount.get
|
||||
)
|
||||
|
||||
// Insert custom field values
|
||||
params.toMap.foreach { case (key, value) =>
|
||||
if (key.startsWith("custom-field-")) {
|
||||
getCustomField(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
key.replaceFirst("^custom-field-", "").toInt
|
||||
).foreach { field =>
|
||||
CustomFieldBehavior.validate(field, value, messages) match {
|
||||
case None =>
|
||||
insertOrUpdateCustomFieldValue(field, repository.owner, repository.name, issue.issueId, value)
|
||||
case Some(_) => halt(400)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
}
|
||||
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||
if (issue.title != title) {
|
||||
// update issue
|
||||
updateIssue(repository.owner, repository.name, issue.issueId, title, issue.content)
|
||||
// extract references and create refer comment
|
||||
createReferComment(repository.owner, repository.name, issue.copy(title = title), title, loginAccount)
|
||||
createComment(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
issue.issueId,
|
||||
issue.title + "\r\n" + title,
|
||||
"change_title"
|
||||
)
|
||||
}
|
||||
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
getIssue(owner, name, params("id")).map {
|
||||
issue =>
|
||||
if (isEditableContent(owner, name, issue.openedUserName)) {
|
||||
if (issue.title != title) {
|
||||
// update issue
|
||||
updateIssue(owner, name, issue.issueId, title, issue.content)
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue.copy(title = title), title, context.loginAccount.get)
|
||||
createComment(
|
||||
owner,
|
||||
name,
|
||||
context.loginAccount.get.userName,
|
||||
issue.issueId,
|
||||
issue.title + "\r\n" + title,
|
||||
"change_title"
|
||||
)
|
||||
}
|
||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
||||
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||
// update issue
|
||||
updateIssue(repository.owner, repository.name, issue.issueId, issue.title, content)
|
||||
// extract references and create refer comment
|
||||
createReferComment(repository.owner, repository.name, issue, content.getOrElse(""), loginAccount)
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
getIssue(owner, name, params("id")).map { issue =>
|
||||
if (isEditableContent(owner, name, issue.openedUserName)) {
|
||||
// update issue
|
||||
updateIssue(owner, name, issue.issueId, issue.title, content)
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, content.getOrElse(""), context.loginAccount.get)
|
||||
|
||||
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||
val actionOpt =
|
||||
params
|
||||
.get("action")
|
||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||
handleComment(issue, Some(form.content), repository, actionOpt) map { case (issue, id) =>
|
||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||
val actionOpt =
|
||||
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
||||
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
||||
case (issue, id) =>
|
||||
redirect(
|
||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-$id"
|
||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||
)
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||
val actionOpt =
|
||||
params
|
||||
.get("action")
|
||||
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||
handleComment(issue, form.content, repository, actionOpt) map { case (issue, id) =>
|
||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||
val actionOpt =
|
||||
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
||||
handleComment(issue, form.content, repository, actionOpt) map {
|
||||
case (issue, id) =>
|
||||
redirect(
|
||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-$id"
|
||||
s"/${repository.owner}/${repository.name}/${if (issue.isPullRequest) "pull" else "issues"}/${form.issueId}#comment-${id}"
|
||||
)
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||
if (isEditableContent(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||
updateComment(repository.owner, repository.name, comment.issueId, comment.commentId, form.content)
|
||||
redirect(s"/${repository.owner}/${repository.name}/issue_comments/_data/${comment.commentId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
getComment(owner, name, params("id")).map { comment =>
|
||||
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
||||
updateComment(comment.issueId, comment.commentId, form.content)
|
||||
redirect(s"/${owner}/${name}/issue_comments/_data/${comment.commentId}")
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||
if (isDeletableComment(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||
Ok(deleteComment(repository.owner, repository.name, comment.issueId, comment.commentId))
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, name) =>
|
||||
getComment(owner, name, params("id")).map { comment =>
|
||||
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
||||
Ok(deleteComment(comment.issueId, comment.commentId))
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getIssue(repository.owner, repository.name, params("id")) map { x =>
|
||||
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName, loginAccount)) {
|
||||
getIssue(repository.owner, repository.name, params("id")) map {
|
||||
x =>
|
||||
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName)) {
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
||||
} getOrElse {
|
||||
@@ -289,14 +270,13 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
)
|
||||
}
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
getComment(repository.owner, repository.name, params("id")) map { x =>
|
||||
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
||||
getComment(repository.owner, repository.name, params("id")) map {
|
||||
x =>
|
||||
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName)) {
|
||||
params.get("dataType") collect {
|
||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||
} getOrElse {
|
||||
@@ -318,8 +298,7 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
)
|
||||
}
|
||||
} else Unauthorized()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/new/label")(writableUsersOnly { repository =>
|
||||
@@ -329,103 +308,66 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
||||
val issueId = params("id").toInt
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, insertComment = true)
|
||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||
defining(params("id").toInt) { issueId =>
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||
}
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
||||
val issueId = params("id").toInt
|
||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, insertComment = true)
|
||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||
defining(params("id").toInt) { issueId =>
|
||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||
}
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/assignee/new")(writableUsersOnly { repository =>
|
||||
val issueId = params("id").toInt
|
||||
registerIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), insertComment = true)
|
||||
Ok()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/assignee/delete")(writableUsersOnly { repository =>
|
||||
val issueId = params("id").toInt
|
||||
deleteIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), insertComment = true)
|
||||
Ok()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
||||
updateMilestoneId(
|
||||
ajaxPost("/:owner/:repository/issues/:id/assign")(writableUsersOnly { repository =>
|
||||
updateAssignedUserName(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
params("id").toInt,
|
||||
milestoneId("milestoneId"),
|
||||
insertComment = true
|
||||
assignedUserName("assignedUserName"),
|
||||
true
|
||||
)
|
||||
Ok("updated")
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
||||
updateMilestoneId(repository.owner, repository.name, params("id").toInt, milestoneId("milestoneId"), true)
|
||||
milestoneId("milestoneId").map { milestoneId =>
|
||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||
.find(_._1.milestoneId == milestoneId)
|
||||
.map { case (_, openCount, closeCount) =>
|
||||
gitbucket.core.issues.milestones.html.progress(openCount + closeCount, closeCount)
|
||||
.map {
|
||||
case (_, openCount, closeCount) =>
|
||||
gitbucket.core.issues.milestones.html.progress(openCount + closeCount, closeCount)
|
||||
} getOrElse NotFound()
|
||||
} getOrElse Ok()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/priority")(writableUsersOnly { repository =>
|
||||
val priority = priorityId("priorityId")
|
||||
updatePriorityId(repository.owner, repository.name, params("id").toInt, priority, insertComment = true)
|
||||
updatePriorityId(repository.owner, repository.name, params("id").toInt, priority, true)
|
||||
Ok("updated")
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/customfield_validation/:fieldId")(writableUsersOnly { repository =>
|
||||
val fieldId = params("fieldId").toInt
|
||||
val value = params("value")
|
||||
getCustomField(repository.owner, repository.name, fieldId)
|
||||
.flatMap { field =>
|
||||
CustomFieldBehavior.validate(field, value, messages).map { error =>
|
||||
Ok(error)
|
||||
}
|
||||
}
|
||||
.getOrElse(Ok())
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/:id/customfield/:fieldId")(writableUsersOnly { repository =>
|
||||
val issueId = params("id").toInt
|
||||
val fieldId = params("fieldId").toInt
|
||||
val value = params("value")
|
||||
|
||||
for {
|
||||
_ <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||
field <- getCustomField(repository.owner, repository.name, fieldId)
|
||||
} {
|
||||
CustomFieldBehavior.validate(field, value, messages) match {
|
||||
case None => insertOrUpdateCustomFieldValue(field, repository.owner, repository.name, issueId, value)
|
||||
case Some(_) => halt(400)
|
||||
}
|
||||
}
|
||||
Ok(value)
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/batchedit/state")(writableUsersOnly { repository =>
|
||||
val action = params.get("value")
|
||||
action match {
|
||||
case Some("open") =>
|
||||
executeBatch(repository) { issueId =>
|
||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||
handleComment(issue, None, repository, Some("reopen"))
|
||||
}
|
||||
defining(params.get("value")) {
|
||||
action =>
|
||||
action match {
|
||||
case Some("open") =>
|
||||
executeBatch(repository) { issueId =>
|
||||
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()
|
||||
}
|
||||
})
|
||||
|
||||
@@ -433,48 +375,39 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
params("value").toIntOpt.map { labelId =>
|
||||
executeBatch(repository) { issueId =>
|
||||
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, labelId, insertComment = true)
|
||||
if (params("uri").nonEmpty) {
|
||||
redirect(params("uri"))
|
||||
}
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/batchedit/assign")(writableUsersOnly { repository =>
|
||||
val value = assignedUserName("value")
|
||||
executeBatch(repository) {
|
||||
// updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||
value match {
|
||||
case Some(assignedUserName) =>
|
||||
registerIssueAssignee(repository.owner, repository.name, _, assignedUserName, insertComment = true)
|
||||
case None =>
|
||||
deleteAllIssueAssignees(repository.owner, repository.name, _, insertComment = true)
|
||||
defining(assignedUserName("value")) { value =>
|
||||
executeBatch(repository) {
|
||||
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||
}
|
||||
}
|
||||
if (params("uri").nonEmpty) {
|
||||
redirect(params("uri"))
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
||||
val value = milestoneId("value")
|
||||
executeBatch(repository) {
|
||||
updateMilestoneId(repository.owner, repository.name, _, value, insertComment = true)
|
||||
defining(milestoneId("value")) { value =>
|
||||
executeBatch(repository) {
|
||||
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
||||
val value = priorityId("value")
|
||||
executeBatch(repository) {
|
||||
updatePriorityId(repository.owner, repository.name, _, value, insertComment = true)
|
||||
defining(priorityId("value")) { value =>
|
||||
executeBatch(repository) {
|
||||
updatePriorityId(repository.owner, repository.name, _, value, true)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
get("/:owner/:repository/_attached/:file")(referrersOnly { repository =>
|
||||
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
||||
case dir if dir.exists && dir.isDirectory =>
|
||||
case dir if (dir.exists && dir.isDirectory) =>
|
||||
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
||||
response.setHeader("Content-Disposition", f"""inline; filename=${file.getName}""")
|
||||
RawData(FileUtil.getSafeMimeType(file.getName), file)
|
||||
@@ -483,84 +416,50 @@ trait IssuesControllerBase extends ControllerBase {
|
||||
}) 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 milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
|
||||
private val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
||||
private val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
private val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||
|
||||
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit): Unit = {
|
||||
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit) = {
|
||||
params("checked").split(',') map (_.toInt) foreach execute
|
||||
params("from") match {
|
||||
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
||||
case _ =>
|
||||
}
|
||||
}
|
||||
|
||||
private def searchIssues(repository: RepositoryService.RepositoryInfo, condition: IssueSearchCondition, page: Int) = {
|
||||
// search issues
|
||||
val issues =
|
||||
searchIssue(
|
||||
condition,
|
||||
IssueSearchOption.Issues,
|
||||
(page - 1) * IssueLimit,
|
||||
IssueLimit,
|
||||
repository.owner -> repository.name
|
||||
)
|
||||
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
||||
defining(repository.owner, repository.name) {
|
||||
case (owner, repoName) =>
|
||||
val page = IssueSearchCondition.page(request)
|
||||
|
||||
html.list(
|
||||
"issues",
|
||||
issues.map(issue => (issue, None)),
|
||||
page,
|
||||
getAssignableUserNames(repository.owner, repository.name),
|
||||
getMilestones(repository.owner, repository.name),
|
||||
getPriorities(repository.owner, repository.name),
|
||||
getLabels(repository.owner, repository.name),
|
||||
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
||||
condition,
|
||||
repository,
|
||||
isIssueEditable(repository),
|
||||
isIssueManageable(repository)
|
||||
)
|
||||
// retrieve search condition
|
||||
val condition = IssueSearchCondition(request)
|
||||
|
||||
html.list(
|
||||
"issues",
|
||||
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, owner -> repoName),
|
||||
page,
|
||||
getAssignableUserNames(owner, repoName),
|
||||
getMilestones(owner, repoName),
|
||||
getPriorities(owner, repoName),
|
||||
getLabels(owner, repoName),
|
||||
countIssue(condition.copy(state = "open"), false, owner -> repoName),
|
||||
countIssue(condition.copy(state = "closed"), false, owner -> repoName),
|
||||
condition,
|
||||
repository,
|
||||
isIssueEditable(repository),
|
||||
isIssueManageable(repository)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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)(implicit
|
||||
context: Context
|
||||
private def isEditableContent(owner: String, repository: String, author: String)(
|
||||
implicit context: Context
|
||||
): Boolean = {
|
||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == loginAccount.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
|
||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@ import gitbucket.core.service.{
|
||||
PrioritiesService
|
||||
}
|
||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.SyntaxSugars.*
|
||||
import org.scalatra.forms.*
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.Messages
|
||||
import org.scalatra.Ok
|
||||
|
||||
@@ -28,11 +28,15 @@ class LabelsController
|
||||
with WritableUsersAuthenticator
|
||||
|
||||
trait LabelsControllerBase extends ControllerBase {
|
||||
self: LabelsService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||
self: LabelsService
|
||||
with IssuesService
|
||||
with RepositoryService
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator =>
|
||||
|
||||
private case class LabelForm(labelName: String, color: String)
|
||||
case class LabelForm(labelName: String, color: String)
|
||||
|
||||
private val labelForm = mapping(
|
||||
val labelForm = mapping(
|
||||
"labelName" -> trim(label("Label name", text(required, labelName, uniqueLabelName, maxlength(100)))),
|
||||
"labelColor" -> trim(label("Color", text(required, color)))
|
||||
)(LabelForm.apply)
|
||||
@@ -40,7 +44,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
get("/:owner/:repository/issues/labels")(referrersOnly { repository =>
|
||||
html.list(
|
||||
getLabels(repository.owner, repository.name),
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
@@ -55,7 +59,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
html.label(
|
||||
getLabel(repository.owner, repository.name, labelId).get,
|
||||
// TODO futility
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
@@ -72,7 +76,7 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
html.label(
|
||||
getLabel(repository.owner, repository.name, params("labelId").toInt).get,
|
||||
// TODO futility
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
@@ -89,9 +93,9 @@ trait LabelsControllerBase extends ControllerBase {
|
||||
private def labelName: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (value.contains(',')) {
|
||||
Some(s"$name contains invalid character.")
|
||||
Some(s"${name} contains invalid character.")
|
||||
} else if (value.startsWith("_") || value.startsWith("-")) {
|
||||
Some(s"$name starts with invalid character.")
|
||||
Some(s"${name} starts with invalid character.")
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
@@ -1,19 +1,11 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.issues.milestones.html
|
||||
import gitbucket.core.service.IssuesService.{IssueLimit, IssueSearchCondition}
|
||||
import gitbucket.core.service.{
|
||||
AccountService,
|
||||
CommitStatusService,
|
||||
IssueSearchOption,
|
||||
MilestonesService,
|
||||
RepositoryService
|
||||
}
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.service.{AccountService, MilestonesService, RepositoryService}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||
import gitbucket.core.util.SyntaxSugars.*
|
||||
import gitbucket.core.view.helpers.{getAssignableUserNames, getLabels, getPriorities, searchIssue}
|
||||
import org.scalatra.forms.*
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
class MilestonesController
|
||||
@@ -21,17 +13,15 @@ class MilestonesController
|
||||
with MilestonesService
|
||||
with RepositoryService
|
||||
with AccountService
|
||||
with CommitStatusService
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
|
||||
trait MilestonesControllerBase extends ControllerBase {
|
||||
self: MilestonesService & RepositoryService & CommitStatusService & ReferrerAuthenticator &
|
||||
WritableUsersAuthenticator =>
|
||||
self: MilestonesService with RepositoryService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||
|
||||
private 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])
|
||||
|
||||
private val milestoneForm = mapping(
|
||||
val milestoneForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100), uniqueMilestone))),
|
||||
"description" -> trim(label("Description", optional(text()))),
|
||||
"dueDate" -> trim(label("Due Date", optional(date())))
|
||||
@@ -46,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 {
|
||||
html.edit(None, _)
|
||||
})
|
||||
|
||||
@@ -29,15 +29,12 @@ trait PreProcessControllerBase extends ControllerBase {
|
||||
* If anonymous access is allowed, pass all requests.
|
||||
* But if it's not allowed, demands authentication except some paths.
|
||||
*/
|
||||
get(!context.settings.basicBehavior.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||
if (
|
||||
!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
||||
!context.currentPath.startsWith("/plugin-assets") && !context.currentPath.equals("/user.css") &&
|
||||
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
||||
context.currentPath.startsWith(path)
|
||||
}
|
||||
) {
|
||||
get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
||||
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
||||
context.currentPath.startsWith(path)
|
||||
}) {
|
||||
Unauthorized()
|
||||
} else {
|
||||
pass()
|
||||
|
||||
@@ -28,11 +28,15 @@ class PrioritiesController
|
||||
with WritableUsersAuthenticator
|
||||
|
||||
trait PrioritiesControllerBase extends ControllerBase {
|
||||
self: PrioritiesService & IssuesService & RepositoryService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||
self: PrioritiesService
|
||||
with IssuesService
|
||||
with RepositoryService
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator =>
|
||||
|
||||
private case class PriorityForm(priorityName: String, description: Option[String], color: String)
|
||||
case class PriorityForm(priorityName: String, description: Option[String], color: String)
|
||||
|
||||
private val priorityForm = mapping(
|
||||
val priorityForm = mapping(
|
||||
"priorityName" -> trim(label("Priority name", text(required, priorityName, uniquePriorityName, maxlength(100)))),
|
||||
"description" -> trim(label("Description", optional(text(maxlength(255))))),
|
||||
"priorityColor" -> trim(label("Color", text(required, color)))
|
||||
@@ -41,7 +45,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
||||
get("/:owner/:repository/issues/priorities")(referrersOnly { repository =>
|
||||
html.list(
|
||||
getPriorities(repository.owner, repository.name),
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
@@ -56,7 +60,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
||||
createPriority(repository.owner, repository.name, form.priorityName, form.description, form.color.substring(1))
|
||||
html.priority(
|
||||
getPriority(repository.owner, repository.name, priorityId).get,
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
@@ -80,13 +84,13 @@ trait PrioritiesControllerBase extends ControllerBase {
|
||||
)
|
||||
html.priority(
|
||||
getPriority(repository.owner, repository.name, params("priorityId").toInt).get,
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||
repository,
|
||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||
)
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/priorities/reorder")(writableUsersOnly { repository =>
|
||||
ajaxPost("/:owner/:repository/issues/priorities/reorder")(writableUsersOnly { (repository) =>
|
||||
reorderPriorities(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
@@ -100,7 +104,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
||||
Ok()
|
||||
})
|
||||
|
||||
ajaxPost("/:owner/:repository/issues/priorities/default")(writableUsersOnly { repository =>
|
||||
ajaxPost("/:owner/:repository/issues/priorities/default")(writableUsersOnly { (repository) =>
|
||||
setDefaultPriority(repository.owner, repository.name, priorityId("priorityId"))
|
||||
Ok()
|
||||
})
|
||||
@@ -118,9 +122,9 @@ trait PrioritiesControllerBase extends ControllerBase {
|
||||
private def priorityName: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (value.contains(',')) {
|
||||
Some(s"$name contains invalid character.")
|
||||
Some(s"${name} contains invalid character.")
|
||||
} else if (value.startsWith("_") || value.startsWith("-")) {
|
||||
Some(s"$name starts with invalid character.")
|
||||
Some(s"${name} starts with invalid character.")
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -2,19 +2,11 @@ package gitbucket.core.controller
|
||||
|
||||
import java.io.File
|
||||
|
||||
import gitbucket.core.model.activity.ReleaseInfo
|
||||
import gitbucket.core.service.{
|
||||
AccountService,
|
||||
ActivityService,
|
||||
PaginationHelper,
|
||||
ReleaseService,
|
||||
RepositoryService,
|
||||
RequestCache
|
||||
}
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.util.Directory.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import org.scalatra.forms.*
|
||||
import gitbucket.core.service.{AccountService, ActivityService, PaginationHelper, ReleaseService, RepositoryService}
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import org.scalatra.forms._
|
||||
import gitbucket.core.releases.html
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -30,18 +22,22 @@ class ReleaseController
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
with RequestCache
|
||||
|
||||
trait ReleaseControllerBase extends ControllerBase {
|
||||
self: RepositoryService & AccountService & ReleaseService & ReadableUsersAuthenticator & ReferrerAuthenticator &
|
||||
WritableUsersAuthenticator & ActivityService =>
|
||||
self: RepositoryService
|
||||
with AccountService
|
||||
with ReleaseService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator
|
||||
with ActivityService =>
|
||||
|
||||
private case class ReleaseForm(
|
||||
case class ReleaseForm(
|
||||
name: String,
|
||||
content: Option[String]
|
||||
)
|
||||
|
||||
private val releaseForm = mapping(
|
||||
val releaseForm = mapping(
|
||||
"name" -> trim(text(required)),
|
||||
"content" -> trim(optional(text()))
|
||||
)(ReleaseForm.apply)
|
||||
@@ -58,8 +54,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
)
|
||||
})
|
||||
|
||||
get("/:owner/:repository/releases/*")(referrersOnly { repository =>
|
||||
val tagName = multiParams("splat").head
|
||||
get("/:owner/:repository/releases/:tag")(referrersOnly { repository =>
|
||||
val tagName = params("tag")
|
||||
getRelease(repository.owner, repository.name, tagName)
|
||||
.map { release =>
|
||||
html.release(
|
||||
@@ -72,8 +68,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
.getOrElse(NotFound())
|
||||
})
|
||||
|
||||
get("/:owner/:repository/releases/*/assets/:fileId")(referrersOnly { repository =>
|
||||
val tagName = multiParams("splat").head
|
||||
get("/:owner/:repository/releases/:tag/assets/:fileId")(referrersOnly { repository =>
|
||||
val tagName = params("tag")
|
||||
val fileId = params("fileId")
|
||||
(for {
|
||||
_ <- repository.tags.find(_.name == tagName)
|
||||
@@ -88,8 +84,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
}).getOrElse(NotFound())
|
||||
})
|
||||
|
||||
get("/:owner/:repository/releases/*/create")(writableUsersOnly { repository =>
|
||||
val tagName = multiParams("splat").head
|
||||
get("/:owner/:repository/releases/:tag/create")(writableUsersOnly { repository =>
|
||||
val tagName = params("tag")
|
||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||
|
||||
repository.tags
|
||||
@@ -100,40 +96,40 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
.getOrElse(NotFound())
|
||||
})
|
||||
|
||||
post("/:owner/:repository/releases/*/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
val tagName = multiParams("splat").head
|
||||
post("/:owner/:repository/releases/:tag/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||
val tagName = params("tag")
|
||||
val loginAccount = context.loginAccount.get
|
||||
|
||||
// Insert into RELEASE
|
||||
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
||||
// Insert into RELEASE
|
||||
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
||||
|
||||
// Insert into RELEASE_ASSET
|
||||
val files = params.toMap.collect {
|
||||
case (name, value) if name.startsWith("file:") =>
|
||||
val Array(_, fileId) = name.split(":")
|
||||
(fileId, value)
|
||||
}
|
||||
files.foreach { case (fileId, fileName) =>
|
||||
// Insert into RELEASE_ASSET
|
||||
val files = params.toMap.collect {
|
||||
case (name, value) if name.startsWith("file:") =>
|
||||
val Array(_, fileId) = name.split(":")
|
||||
(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")
|
||||
}
|
||||
|
||||
recordReleaseActivity(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||
|
||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
||||
})
|
||||
|
||||
get("/:owner/:repository/changelog/*...*")(writableUsersOnly { repository =>
|
||||
val commitLog = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
val Seq(previousTag, currentTag) = multiParams("splat")
|
||||
val Seq(previousTag, currentTag) = multiParams("splat")
|
||||
val previousTagId = repository.tags.collectFirst { case x if x.name == previousTag => x.id }.getOrElse("")
|
||||
|
||||
val commits = JGitUtil.getCommitLog(git, previousTag, currentTag).reverse
|
||||
val commitLog = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
val commits = JGitUtil.getCommitLog(git, previousTagId, currentTag).reverse
|
||||
commits
|
||||
.map { commit =>
|
||||
s"- ${commit.shortMessage} ${commit.id}"
|
||||
@@ -144,8 +140,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
commitLog
|
||||
})
|
||||
|
||||
get("/:owner/:repository/releases/*/edit")(writableUsersOnly { repository =>
|
||||
val tagName = multiParams("splat").head
|
||||
get("/:owner/:repository/releases/:tag/edit")(writableUsersOnly { repository =>
|
||||
val tagName = params("tag")
|
||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||
|
||||
(for {
|
||||
@@ -162,9 +158,10 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
}).getOrElse(NotFound())
|
||||
})
|
||||
|
||||
post("/:owner/:repository/releases/*/edit", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
val tagName = multiParams("splat").head
|
||||
post("/:owner/:repository/releases/:tag/edit", releaseForm)(writableUsersOnly {
|
||||
(form, repository) =>
|
||||
val tagName = params("tag")
|
||||
val loginAccount = context.loginAccount.get
|
||||
|
||||
getRelease(repository.owner, repository.name, tagName)
|
||||
.map { release =>
|
||||
@@ -180,13 +177,14 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
val Array(_, fileId) = name.split(":")
|
||||
(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)
|
||||
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 =>
|
||||
@@ -199,14 +197,13 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
|
||||
redirect(s"/${release.userName}/${release.repositoryName}/releases/$tagName")
|
||||
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
||||
}
|
||||
.getOrElse(NotFound())
|
||||
}
|
||||
})
|
||||
|
||||
post("/:owner/:repository/releases/*/delete")(writableUsersOnly { repository =>
|
||||
val tagName = multiParams("splat").head
|
||||
post("/:owner/:repository/releases/:tag/delete")(writableUsersOnly { repository =>
|
||||
val tagName = params("tag")
|
||||
getRelease(repository.owner, repository.name, tagName).foreach { release =>
|
||||
FileUtils.deleteDirectory(
|
||||
new File(getReleaseFilesDir(repository.owner, repository.name), FileUtil.checkFilename(release.tag))
|
||||
@@ -217,7 +214,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
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 tagsToDisplay = repository.tags.reverse.slice(offset, offset + limit)
|
||||
@@ -226,12 +224,9 @@ trait ReleaseControllerBase extends ControllerBase {
|
||||
val assets = getReleaseAssetsMap(repository.owner, repository.name, releases)
|
||||
|
||||
val tagsWithReleases = tagsToDisplay.map { tag =>
|
||||
(
|
||||
tag,
|
||||
releases.find(_.tag == tag.name).map { release =>
|
||||
(release, assets(release))
|
||||
}
|
||||
)
|
||||
(tag, releases.find(_.tag == tag.name).map { release =>
|
||||
(release, assets(release))
|
||||
})
|
||||
}
|
||||
tagsWithReleases
|
||||
}
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import java.time.{LocalDateTime, ZoneOffset}
|
||||
import java.time.{LocalDateTime, ZoneId, ZoneOffset}
|
||||
import java.util.Date
|
||||
|
||||
import gitbucket.core.settings.html
|
||||
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.service.WebHookService.*
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.util.JGitUtil.*
|
||||
import gitbucket.core.util.SyntaxSugars.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.Directory.*
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.service.WebHookService._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.JGitUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.model.WebHookContentType
|
||||
import gitbucket.core.model.activity.RenameRepositoryInfo
|
||||
import org.scalatra.forms.*
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.Messages
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
|
||||
import scala.util.Using
|
||||
import org.scalatra.{Forbidden, Ok}
|
||||
import org.scalatra.Forbidden
|
||||
|
||||
class RepositorySettingsController
|
||||
extends RepositorySettingsControllerBase
|
||||
@@ -30,18 +30,21 @@ class RepositorySettingsController
|
||||
with ProtectedBranchService
|
||||
with CommitStatusService
|
||||
with DeployKeyService
|
||||
with CustomFieldsService
|
||||
with ActivityService
|
||||
with OwnerAuthenticator
|
||||
with UsersAuthenticator
|
||||
with RequestCache
|
||||
|
||||
trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
self: RepositoryService & AccountService & WebHookService & ProtectedBranchService & CommitStatusService &
|
||||
DeployKeyService & CustomFieldsService & ActivityService & OwnerAuthenticator & UsersAuthenticator =>
|
||||
self: RepositoryService
|
||||
with AccountService
|
||||
with WebHookService
|
||||
with ProtectedBranchService
|
||||
with CommitStatusService
|
||||
with DeployKeyService
|
||||
with OwnerAuthenticator
|
||||
with UsersAuthenticator =>
|
||||
|
||||
// for repository options
|
||||
private case class OptionsForm(
|
||||
case class OptionsForm(
|
||||
description: Option[String],
|
||||
isPrivate: Boolean,
|
||||
issuesOption: String,
|
||||
@@ -50,11 +53,10 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
externalWikiUrl: Option[String],
|
||||
allowFork: Boolean,
|
||||
mergeOptions: Seq[String],
|
||||
defaultMergeOption: String,
|
||||
safeMode: Boolean
|
||||
defaultMergeOption: String
|
||||
)
|
||||
|
||||
private val optionsForm = mapping(
|
||||
val optionsForm = mapping(
|
||||
"description" -> trim(label("Description", optional(text()))),
|
||||
"isPrivate" -> trim(label("Repository Type", boolean())),
|
||||
"issuesOption" -> trim(label("Issues Option", text(required, featureOption))),
|
||||
@@ -63,8 +65,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
"externalWikiUrl" -> trim(label("External Wiki URL", optional(text(maxlength(200))))),
|
||||
"allowFork" -> trim(label("Allow Forking", boolean())),
|
||||
"mergeOptions" -> mergeOptions,
|
||||
"defaultMergeOption" -> trim(label("Default merge strategy", text(required))),
|
||||
"safeMode" -> trim(label("XSS protection", boolean()))
|
||||
"defaultMergeOption" -> trim(label("Default merge strategy", text(required)))
|
||||
)(OptionsForm.apply).verifying { form =>
|
||||
if (!form.mergeOptions.contains(form.defaultMergeOption)) {
|
||||
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
||||
@@ -72,70 +73,50 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
}
|
||||
|
||||
// for default branch
|
||||
private case class DefaultBranchForm(defaultBranch: String)
|
||||
case class DefaultBranchForm(defaultBranch: String)
|
||||
|
||||
private val defaultBranchForm = mapping(
|
||||
val defaultBranchForm = mapping(
|
||||
"defaultBranch" -> trim(label("Default Branch", text(required, maxlength(100))))
|
||||
)(DefaultBranchForm.apply)
|
||||
|
||||
// for deploy key
|
||||
private case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
||||
case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
||||
|
||||
private val deployKeyForm = mapping(
|
||||
val deployKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim2(label("Key", text(required))), // TODO duplication check in the repository?
|
||||
"allowWrite" -> trim(label("Key", boolean()))
|
||||
)(DeployKeyForm.apply)
|
||||
|
||||
// for web hook url addition
|
||||
private case class WebHookForm(
|
||||
url: String,
|
||||
events: Set[WebHook.Event],
|
||||
ctype: WebHookContentType,
|
||||
token: Option[String]
|
||||
)
|
||||
case class WebHookForm(url: String, events: Set[WebHook.Event], ctype: WebHookContentType, token: Option[String])
|
||||
|
||||
private def webHookForm(update: Boolean) =
|
||||
def webHookForm(update: Boolean) =
|
||||
mapping(
|
||||
"url" -> trim(label("url", text(required, webHook(update)))),
|
||||
"events" -> webhookEvents,
|
||||
"ctype" -> label("ctype", text()),
|
||||
"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
|
||||
private case class RenameRepositoryForm(repositoryName: String)
|
||||
case class RenameRepositoryForm(repositoryName: String)
|
||||
|
||||
private val renameForm = mapping(
|
||||
val renameForm = mapping(
|
||||
"repositoryName" -> trim(
|
||||
label("New repository name", text(required, maxlength(100), repository, renameRepositoryName))
|
||||
)
|
||||
)(RenameRepositoryForm.apply)
|
||||
|
||||
// for transfer ownership
|
||||
private case class TransferOwnerShipForm(newOwner: String)
|
||||
case class TransferOwnerShipForm(newOwner: String)
|
||||
|
||||
private val transferForm = mapping(
|
||||
val transferForm = mapping(
|
||||
"newOwner" -> trim(label("New owner", text(required, transferUser)))
|
||||
)(TransferOwnerShipForm.apply)
|
||||
|
||||
// for custom field
|
||||
private case class CustomFieldForm(
|
||||
fieldName: String,
|
||||
fieldType: String,
|
||||
constraints: Option[String],
|
||||
enableForIssues: Boolean,
|
||||
enableForPullRequests: Boolean
|
||||
)
|
||||
|
||||
private val customFieldForm = mapping(
|
||||
"fieldName" -> trim(label("Field name", text(required, maxlength(100)))),
|
||||
"fieldType" -> trim(label("Field type", text(required))),
|
||||
"constraints" -> trim(label("Constraints", optional(text()))),
|
||||
"enableForIssues" -> trim(label("Enable for issues", boolean(required))),
|
||||
"enableForPullRequests" -> trim(label("Enable for pull requests", boolean(required))),
|
||||
)(CustomFieldForm.apply)
|
||||
|
||||
/**
|
||||
* Redirect to the Options page.
|
||||
*/
|
||||
@@ -167,8 +148,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
form.externalWikiUrl,
|
||||
form.allowFork,
|
||||
form.mergeOptions,
|
||||
form.defaultMergeOption,
|
||||
form.safeMode
|
||||
form.defaultMergeOption
|
||||
)
|
||||
flash.update("info", "Repository settings has been updated.")
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||
@@ -183,7 +163,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
/** Update default branch */
|
||||
post("/:owner/:repository/settings/update_default_branch", defaultBranchForm)(ownerOnly { (form, repository) =>
|
||||
if (!repository.branchList.contains(form.defaultBranch)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||
} else {
|
||||
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
|
||||
// Change repository HEAD
|
||||
@@ -196,15 +176,14 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/** Branch protection for branch */
|
||||
get("/:owner/:repository/settings/branches/*")(ownerOnly { repository =>
|
||||
import gitbucket.core.api.*
|
||||
val branch = params("splat")
|
||||
|
||||
get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository =>
|
||||
import gitbucket.core.api._
|
||||
val branch = params("branch")
|
||||
if (!repository.branchList.contains(branch)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||
} else {
|
||||
val protection = ApiBranchProtectionResponse(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||
val lastWeeks = getRecentStatusContexts(
|
||||
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||
val lastWeeks = getRecentStatuesContexts(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
Date.from(LocalDateTime.now.minusWeeks(1).toInstant(ZoneOffset.UTC))
|
||||
@@ -246,14 +225,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
* Display the web hook edit page.
|
||||
*/
|
||||
get("/:owner/:repository/settings/hooks/new")(ownerOnly { repository =>
|
||||
val webhook = RepositoryWebHook(
|
||||
userName = repository.owner,
|
||||
repositoryName = repository.name,
|
||||
url = "",
|
||||
ctype = WebHookContentType.FORM,
|
||||
token = None
|
||||
)
|
||||
html.edithook(webhook, Set(WebHook.Push), repository, create = true)
|
||||
val webhook = RepositoryWebHook(repository.owner, repository.name, "", WebHookContentType.FORM, None)
|
||||
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -278,95 +251,91 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
* Send the test request to registered web hook URLs.
|
||||
*/
|
||||
ajaxPost("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
||||
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] =
|
||||
h.map { h =>
|
||||
Array(h.getName, h.getValue)
|
||||
}
|
||||
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] = h.map { h =>
|
||||
Array(h.getName, h.getValue)
|
||||
}
|
||||
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
import scala.concurrent.duration.*
|
||||
import scala.concurrent.*
|
||||
import scala.jdk.CollectionConverters.*
|
||||
import scala.util.control.NonFatal
|
||||
import org.apache.http.util.EntityUtils
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||
git =>
|
||||
import scala.concurrent.duration._
|
||||
import scala.concurrent._
|
||||
import scala.jdk.CollectionConverters._
|
||||
import scala.util.control.NonFatal
|
||||
import org.apache.http.util.EntityUtils
|
||||
import scala.concurrent.ExecutionContext.Implicits.global
|
||||
|
||||
val url = params("url")
|
||||
val token = Some(params("token"))
|
||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||
val dummyWebHookInfo = RepositoryWebHook(
|
||||
userName = repository.owner,
|
||||
repositoryName = repository.name,
|
||||
url = url,
|
||||
ctype = ctype,
|
||||
token = token
|
||||
)
|
||||
val dummyPayload = {
|
||||
val ownerAccount = getAccountByUserName(repository.owner).get
|
||||
val commits =
|
||||
if (JGitUtil.isEmpty(git)) List.empty
|
||||
else
|
||||
git.log
|
||||
.add(git.getRepository.resolve(repository.repository.defaultBranch))
|
||||
.setMaxCount(4)
|
||||
.call
|
||||
.iterator
|
||||
.asScala
|
||||
.map(new CommitInfo(_))
|
||||
.toList
|
||||
val pushedCommit = commits.drop(1)
|
||||
val url = params("url")
|
||||
val token = Some(params("token"))
|
||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||
val dummyWebHookInfo = RepositoryWebHook(repository.owner, repository.name, url, ctype, token)
|
||||
val dummyPayload = {
|
||||
val ownerAccount = getAccountByUserName(repository.owner).get
|
||||
val commits =
|
||||
if (JGitUtil.isEmpty(git)) List.empty
|
||||
else
|
||||
git.log
|
||||
.add(git.getRepository.resolve(repository.repository.defaultBranch))
|
||||
.setMaxCount(4)
|
||||
.call
|
||||
.iterator
|
||||
.asScala
|
||||
.map(new CommitInfo(_))
|
||||
.toList
|
||||
val pushedCommit = commits.drop(1)
|
||||
|
||||
WebHookPushPayload(
|
||||
git = git,
|
||||
sender = ownerAccount,
|
||||
refName = "refs/heads/" + repository.repository.defaultBranch,
|
||||
repositoryInfo = repository,
|
||||
commits = pushedCommit,
|
||||
repositoryOwner = ownerAccount,
|
||||
oldId = commits.lastOption.map(_.id).map(ObjectId.fromString).getOrElse(ObjectId.zeroId()),
|
||||
newId = commits.headOption.map(_.id).map(ObjectId.fromString).getOrElse(ObjectId.zeroId())
|
||||
)
|
||||
}
|
||||
WebHookPushPayload(
|
||||
git = git,
|
||||
sender = ownerAccount,
|
||||
refName = "refs/heads/" + repository.repository.defaultBranch,
|
||||
repositoryInfo = repository,
|
||||
commits = pushedCommit,
|
||||
repositoryOwner = ownerAccount,
|
||||
oldId = commits.lastOption.map(_.id).map(ObjectId.fromString).getOrElse(ObjectId.zeroId()),
|
||||
newId = commits.headOption.map(_.id).map(ObjectId.fromString).getOrElse(ObjectId.zeroId())
|
||||
)
|
||||
}
|
||||
|
||||
val (webHook, json, reqFuture, resFuture) =
|
||||
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||
val (webHook, json, reqFuture, resFuture) =
|
||||
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||
|
||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||
case e: java.net.UnknownHostException => Map("error" -> s"Unknown host ${e.getMessage}")
|
||||
case _: java.lang.IllegalArgumentException => Map("error" -> "invalid url")
|
||||
case _: org.apache.http.client.ClientProtocolException => Map("error" -> "invalid url")
|
||||
case NonFatal(e) => Map("error" -> s"${e.getClass} ${e.getMessage}")
|
||||
}
|
||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
||||
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
||||
}
|
||||
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
Map(
|
||||
"url" -> url,
|
||||
"request" -> Await.result(
|
||||
reqFuture
|
||||
.map(req =>
|
||||
Map(
|
||||
"headers" -> _headers(req.getAllHeaders),
|
||||
"payload" -> json
|
||||
contentType = formats("json")
|
||||
org.json4s.jackson.Serialization.write(
|
||||
Map(
|
||||
"url" -> url,
|
||||
"request" -> Await.result(
|
||||
reqFuture
|
||||
.map(
|
||||
req =>
|
||||
Map(
|
||||
"headers" -> _headers(req.getAllHeaders),
|
||||
"payload" -> json
|
||||
)
|
||||
)
|
||||
)
|
||||
.recover(toErrorMap),
|
||||
20 seconds
|
||||
),
|
||||
"response" -> Await.result(
|
||||
resFuture
|
||||
.map(res =>
|
||||
Map(
|
||||
"status" -> res.getStatusLine.getStatusCode,
|
||||
"body" -> EntityUtils.toString(res.getEntity),
|
||||
"headers" -> _headers(res.getAllHeaders)
|
||||
.recover(toErrorMap),
|
||||
20 seconds
|
||||
),
|
||||
"response" -> Await.result(
|
||||
resFuture
|
||||
.map(
|
||||
res =>
|
||||
Map(
|
||||
"status" -> res.getStatusLine(),
|
||||
"body" -> EntityUtils.toString(res.getEntity()),
|
||||
"headers" -> _headers(res.getAllHeaders())
|
||||
)
|
||||
)
|
||||
)
|
||||
.recover(toErrorMap),
|
||||
20 seconds
|
||||
.recover(toErrorMap),
|
||||
20 seconds
|
||||
)
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -374,8 +343,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
* Display the web hook edit page.
|
||||
*/
|
||||
get("/:owner/:repository/settings/hooks/edit")(ownerOnly { repository =>
|
||||
getWebHook(repository.owner, repository.name, params("url")).map { case (webhook, events) =>
|
||||
html.edithook(webhook, events, repository, create = false)
|
||||
getWebHook(repository.owner, repository.name, params("url")).map {
|
||||
case (webhook, events) =>
|
||||
html.edithook(webhook, events, repository, false)
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -399,60 +369,36 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
* Rename repository.
|
||||
*/
|
||||
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (context.settings.basicBehavior.repositoryOperation.rename || loginAccount.isAdmin) {
|
||||
if (repository.name != form.repositoryName) {
|
||||
// Update database and move git repository
|
||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
||||
// Record activity log
|
||||
val renameInfo = RenameRepositoryInfo(
|
||||
repository.owner,
|
||||
form.repositoryName,
|
||||
loginAccount.userName,
|
||||
repository.name
|
||||
)
|
||||
recordActivity(renameInfo)
|
||||
}
|
||||
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||
} else Forbidden()
|
||||
}
|
||||
if (context.settings.repositoryOperation.rename || context.loginAccount.get.isAdmin) {
|
||||
if (repository.name != form.repositoryName) {
|
||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
||||
}
|
||||
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||
} else Forbidden()
|
||||
})
|
||||
|
||||
/**
|
||||
* Transfer repository ownership.
|
||||
*/
|
||||
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (context.settings.basicBehavior.repositoryOperation.transfer || loginAccount.isAdmin) {
|
||||
// Change repository owner
|
||||
if (repository.owner != form.newOwner) {
|
||||
// Update database and move git repository
|
||||
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
||||
// Record activity log
|
||||
val renameInfo = RenameRepositoryInfo(
|
||||
form.newOwner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
repository.owner
|
||||
)
|
||||
recordActivity(renameInfo)
|
||||
}
|
||||
redirect(s"/${form.newOwner}/${repository.name}")
|
||||
} else Forbidden()
|
||||
}
|
||||
if (context.settings.repositoryOperation.transfer || context.loginAccount.get.isAdmin) {
|
||||
// Change repository owner
|
||||
if (repository.owner != form.newOwner) {
|
||||
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
||||
}
|
||||
redirect(s"/${form.newOwner}/${repository.name}")
|
||||
} else Forbidden()
|
||||
})
|
||||
|
||||
/**
|
||||
* Delete the repository.
|
||||
*/
|
||||
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (context.settings.basicBehavior.repositoryOperation.delete || loginAccount.isAdmin) {
|
||||
// Delete the repository and related files
|
||||
deleteRepository(repository.repository)
|
||||
redirect(s"/${repository.owner}")
|
||||
} else Forbidden()
|
||||
}
|
||||
if (context.settings.repositoryOperation.delete || context.loginAccount.get.isAdmin) {
|
||||
// Delete the repository and related files
|
||||
deleteRepository(repository.repository)
|
||||
redirect(s"/${repository.owner}")
|
||||
} else Forbidden()
|
||||
})
|
||||
|
||||
/**
|
||||
@@ -486,91 +432,35 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
||||
})
|
||||
|
||||
/** Custom fields for issues and pull requests */
|
||||
get("/:owner/:repository/settings/issues")(ownerOnly { repository =>
|
||||
val customFields = getCustomFields(repository.owner, repository.name)
|
||||
html.issues(customFields, repository)
|
||||
})
|
||||
|
||||
/** New custom field form */
|
||||
get("/:owner/:repository/settings/issues/fields/new")(ownerOnly { repository =>
|
||||
html.issuesfieldform(None, repository)
|
||||
})
|
||||
|
||||
/** Add custom field */
|
||||
ajaxPost("/:owner/:repository/settings/issues/fields/new", customFieldForm)(ownerOnly { (form, repository) =>
|
||||
val fieldId = createCustomField(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
form.fieldName,
|
||||
form.fieldType,
|
||||
if (form.fieldType == "enum") form.constraints else None,
|
||||
form.enableForIssues,
|
||||
form.enableForPullRequests
|
||||
)
|
||||
html.issuesfield(getCustomField(repository.owner, repository.name, fieldId).get)
|
||||
})
|
||||
|
||||
/** Edit custom field form */
|
||||
ajaxGet("/:owner/:repository/settings/issues/fields/:fieldId/edit")(ownerOnly { repository =>
|
||||
getCustomField(repository.owner, repository.name, params("fieldId").toInt).map { customField =>
|
||||
html.issuesfieldform(Some(customField), repository)
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
/** Update custom field */
|
||||
ajaxPost("/:owner/:repository/settings/issues/fields/:fieldId/edit", customFieldForm)(ownerOnly {
|
||||
(form, repository) =>
|
||||
updateCustomField(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
params("fieldId").toInt,
|
||||
form.fieldName,
|
||||
form.fieldType,
|
||||
if (form.fieldType == "enum") form.constraints else None,
|
||||
form.enableForIssues,
|
||||
form.enableForPullRequests
|
||||
)
|
||||
html.issuesfield(getCustomField(repository.owner, repository.name, params("fieldId").toInt).get)
|
||||
})
|
||||
|
||||
/** Delete custom field */
|
||||
ajaxPost("/:owner/:repository/settings/issues/fields/:fieldId/delete")(ownerOnly { repository =>
|
||||
deleteCustomField(repository.owner, repository.name, params("fieldId").toInt)
|
||||
Ok()
|
||||
})
|
||||
|
||||
/**
|
||||
* Provides duplication check for web hook url.
|
||||
*/
|
||||
private def webHook(needExists: Boolean): Constraint =
|
||||
new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
||||
Some(if (needExists) {
|
||||
"URL had not been registered yet."
|
||||
} else {
|
||||
"URL had been registered already."
|
||||
})
|
||||
private def webHook(needExists: Boolean): Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
||||
Some(if (needExists) {
|
||||
"URL had not been registered yet."
|
||||
} 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
|
||||
"URL had been registered already."
|
||||
})
|
||||
} else {
|
||||
None
|
||||
}
|
||||
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
|
||||
}
|
||||
}
|
||||
|
||||
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))
|
||||
} else {
|
||||
Nil
|
||||
}
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Provides Constraint to validate the collaborator name.
|
||||
@@ -590,77 +480,70 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
/**
|
||||
* Duplicate check for the rename repository name.
|
||||
*/
|
||||
private def renameRepositoryName: Constraint =
|
||||
new Constraint() {
|
||||
override def validate(
|
||||
name: String,
|
||||
value: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Option[String] = {
|
||||
for {
|
||||
repoName <- params.optionValue("repository") if repoName != value
|
||||
userName <- params.optionValue("owner")
|
||||
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
||||
} yield {
|
||||
"Repository already exists."
|
||||
}
|
||||
private def renameRepositoryName: Constraint = new Constraint() {
|
||||
override def validate(
|
||||
name: String,
|
||||
value: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Option[String] = {
|
||||
for {
|
||||
repoName <- params.optionValue("repository") if repoName != value
|
||||
userName <- params.optionValue("owner")
|
||||
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
||||
} yield {
|
||||
"Repository already exists."
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
private def featureOption: Constraint =
|
||||
new Constraint() {
|
||||
override def validate(
|
||||
name: String,
|
||||
value: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Option[String] =
|
||||
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
||||
}
|
||||
private def featureOption: Constraint = new Constraint() {
|
||||
override def validate(
|
||||
name: String,
|
||||
value: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Option[String] =
|
||||
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
||||
}
|
||||
|
||||
/**
|
||||
* Provides Constraint to validate the repository transfer user.
|
||||
*/
|
||||
private def transferUser: Constraint =
|
||||
new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
getAccountByUserName(value) match {
|
||||
case None => Some("User does not exist.")
|
||||
case Some(x) =>
|
||||
if (x.userName == params("owner")) {
|
||||
Some("This is current repository owner.")
|
||||
} else {
|
||||
params.get("repository").flatMap { repositoryName =>
|
||||
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
||||
"User already has same repository."
|
||||
}
|
||||
private def transferUser: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
getAccountByUserName(value) match {
|
||||
case None => Some("User does not exist.")
|
||||
case Some(x) =>
|
||||
if (x.userName == params("owner")) {
|
||||
Some("This is current repository owner.")
|
||||
} else {
|
||||
params.get("repository").flatMap { repositoryName =>
|
||||
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
||||
"User already has same repository."
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private def mergeOptions =
|
||||
new ValueType[Seq[String]] {
|
||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
||||
params.getOrElse("mergeOptions", Nil)
|
||||
}
|
||||
override def validate(
|
||||
name: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Seq[(String, String)] = {
|
||||
val mergeOptions = params.getOrElse("mergeOptions", Nil)
|
||||
if (mergeOptions.isEmpty) {
|
||||
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
|
||||
}
|
||||
private def mergeOptions = new ValueType[Seq[String]] {
|
||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
||||
params.getOrElse("mergeOptions", Nil)
|
||||
}
|
||||
override def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] = {
|
||||
val mergeOptions = params.getOrElse("mergeOptions", Nil)
|
||||
if (mergeOptions.isEmpty) {
|
||||
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
@@ -1,19 +1,21 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import java.io.FileInputStream
|
||||
|
||||
import gitbucket.core.admin.html
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service.SystemSettingsService.*
|
||||
import gitbucket.core.service.SystemSettingsService._
|
||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||
import gitbucket.core.ssh.SshServer
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.StringUtil.*
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.apache.commons.mail.EmailException
|
||||
import org.json4s.jackson.Serialization
|
||||
import org.scalatra.*
|
||||
import org.scalatra.forms.*
|
||||
import org.scalatra._
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
import scala.collection.mutable.ListBuffer
|
||||
@@ -29,41 +31,29 @@ case class Table(name: String, columns: Seq[Column])
|
||||
case class Column(name: String, primaryKey: Boolean)
|
||||
|
||||
trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
self: AccountService & RepositoryService & AdminAuthenticator =>
|
||||
self: AccountService with RepositoryService with AdminAuthenticator =>
|
||||
|
||||
private val form = mapping(
|
||||
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
||||
"information" -> trim(label("Information", optional(text()))),
|
||||
"basicBehavior" -> mapping(
|
||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||
"allowResetPassword" -> trim(label("Reset password", boolean())),
|
||||
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
||||
"isCreateRepoOptionPublic" -> trim(label("Default visibility of new repository", boolean())),
|
||||
"repositoryOperation" -> mapping(
|
||||
"create" -> trim(label("Allow all users to create repository", boolean())),
|
||||
"delete" -> trim(label("Allow all users to delete repository", boolean())),
|
||||
"rename" -> trim(label("Allow all users to rename repository", boolean())),
|
||||
"transfer" -> trim(label("Allow all users to transfer repository", boolean())),
|
||||
"fork" -> trim(label("Allow all users to fork repository", boolean()))
|
||||
)(RepositoryOperation.apply),
|
||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||
"notification" -> trim(label("Notification", boolean())),
|
||||
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
||||
)(BasicBehavior.apply),
|
||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
||||
"isCreateRepoOptionPublic" -> trim(label("Default visibility of new repository", boolean())),
|
||||
"repositoryOperation" -> mapping(
|
||||
"create" -> trim(label("Allow all users to create repository", boolean())),
|
||||
"delete" -> trim(label("Allow all users to delete repository", boolean())),
|
||||
"rename" -> trim(label("Allow all users to rename repository", boolean())),
|
||||
"transfer" -> trim(label("Allow all users to transfer repository", boolean())),
|
||||
"fork" -> trim(label("Allow all users to fork repository", boolean()))
|
||||
)(RepositoryOperation.apply),
|
||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||
"notification" -> trim(label("Notification", boolean())),
|
||||
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
||||
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
||||
"ssh" -> mapping(
|
||||
"enabled" -> trim(label("SSH access", boolean())),
|
||||
"bindAddress" -> mapping(
|
||||
"host" -> trim(label("Bind SSH host", optional(text()))),
|
||||
"port" -> trim(label("Bind SSH port", optional(number()))),
|
||||
)((hostOption, portOption) =>
|
||||
hostOption.map(h => SshAddress(h, portOption.getOrElse(DefaultSshPort), GenericSshUser))
|
||||
),
|
||||
"publicAddress" -> mapping(
|
||||
"host" -> trim(label("Public SSH host", optional(text()))),
|
||||
"port" -> trim(label("Public SSH port", optional(number()))),
|
||||
)((hostOption, portOption) =>
|
||||
hostOption.map(h => SshAddress(h, portOption.getOrElse(PublicSshPort), GenericSshUser))
|
||||
),
|
||||
"host" -> trim(label("SSH host", optional(text()))),
|
||||
"port" -> trim(label("SSH port", optional(number())))
|
||||
)(Ssh.apply),
|
||||
"useSMTP" -> trim(label("SMTP", boolean())),
|
||||
"smtp" -> optionalIfNotChecked(
|
||||
@@ -119,20 +109,14 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
"timeout" -> trim(label("Timeout", long(required))),
|
||||
"largeMaxFileSize" -> trim(label("Max file size for large file", long(required))),
|
||||
"largeTimeout" -> trim(label("Timeout for large file", long(required)))
|
||||
)(Upload.apply),
|
||||
"repositoryViewer" -> mapping(
|
||||
"maxFiles" -> trim(label("Max files", number(required))),
|
||||
"maxDiffFiles" -> trim(label("Max diff files", number(required))),
|
||||
"maxDiffLines" -> trim(label("Max diff lines", number(required)))
|
||||
)(RepositoryViewerSettings.apply),
|
||||
"defaultBranch" -> trim(label("Default branch", text(required)))
|
||||
)(Upload.apply)
|
||||
)(SystemSettings.apply).verifying { settings =>
|
||||
Vector(
|
||||
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
||||
Some("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
||||
} else None,
|
||||
if (settings.ssh.enabled && settings.ssh.bindAddress.isEmpty) {
|
||||
Some("ssh.bindAddress.host" -> "SSH bind host is required if SSH access is enabled.")
|
||||
if (settings.ssh.enabled && settings.ssh.sshHost.isEmpty) {
|
||||
Some("sshHost" -> "SSH host is required if SSH access is enabled.")
|
||||
} else None
|
||||
).flatten
|
||||
}
|
||||
@@ -151,11 +135,11 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
"testAddress" -> trim(label("", text(required)))
|
||||
)(SendMailForm.apply)
|
||||
|
||||
private case class SendMailForm(smtp: Smtp, testAddress: String)
|
||||
case class SendMailForm(smtp: Smtp, testAddress: String)
|
||||
|
||||
// case class DataExportForm(tableNames: List[String])
|
||||
case class DataExportForm(tableNames: List[String])
|
||||
|
||||
private case class NewUserForm(
|
||||
case class NewUserForm(
|
||||
userName: String,
|
||||
password: String,
|
||||
fullName: String,
|
||||
@@ -167,7 +151,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
fileId: Option[String]
|
||||
)
|
||||
|
||||
private case class EditUserForm(
|
||||
case class EditUserForm(
|
||||
userName: String,
|
||||
password: Option[String],
|
||||
fullName: String,
|
||||
@@ -181,7 +165,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
isRemoved: Boolean
|
||||
)
|
||||
|
||||
private case class NewGroupForm(
|
||||
case class NewGroupForm(
|
||||
groupName: String,
|
||||
description: Option[String],
|
||||
url: Option[String],
|
||||
@@ -189,7 +173,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
members: String
|
||||
)
|
||||
|
||||
private case class EditGroupForm(
|
||||
case class EditGroupForm(
|
||||
groupName: String,
|
||||
description: Option[String],
|
||||
url: Option[String],
|
||||
@@ -199,9 +183,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
isRemoved: Boolean
|
||||
)
|
||||
|
||||
private val newUserForm = mapping(
|
||||
val newUserForm = mapping(
|
||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||
"extraMailAddresses" -> list(
|
||||
@@ -213,9 +197,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
"fileId" -> trim(label("File ID", optional(text())))
|
||||
)(NewUserForm.apply)
|
||||
|
||||
private val editUserForm = mapping(
|
||||
val editUserForm = mapping(
|
||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
||||
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||
"extraMailAddresses" -> list(
|
||||
@@ -229,7 +213,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
"removed" -> trim(label("Disable", boolean(disableByNotYourself("userName"))))
|
||||
)(EditUserForm.apply)
|
||||
|
||||
private val newGroupForm = mapping(
|
||||
val newGroupForm = mapping(
|
||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||
@@ -237,7 +221,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
"members" -> trim(label("Members", text(required, members)))
|
||||
)(NewGroupForm.apply)
|
||||
|
||||
private val editGroupForm = mapping(
|
||||
val editGroupForm = mapping(
|
||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL", optional(text(maxlength(200))))),
|
||||
@@ -251,27 +235,28 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
val conn = request2Session(request).conn
|
||||
val meta = conn.getMetaData
|
||||
val tables = ListBuffer[Table]()
|
||||
Using.resource(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) { rs =>
|
||||
while (rs.next()) {
|
||||
val tableName = rs.getString("TABLE_NAME")
|
||||
Using.resource(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) {
|
||||
rs =>
|
||||
while (rs.next()) {
|
||||
val tableName = rs.getString("TABLE_NAME")
|
||||
|
||||
val pkColumns = ListBuffer[String]()
|
||||
Using.resource(meta.getPrimaryKeys(null, null, tableName)) { rs =>
|
||||
while (rs.next()) {
|
||||
pkColumns += rs.getString("COLUMN_NAME").toUpperCase
|
||||
val pkColumns = ListBuffer[String]()
|
||||
Using.resource(meta.getPrimaryKeys(null, null, tableName)) { rs =>
|
||||
while (rs.next()) {
|
||||
pkColumns += rs.getString("COLUMN_NAME").toUpperCase
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val columns = ListBuffer[Column]()
|
||||
Using.resource(meta.getColumns(null, "%", tableName, "%")) { rs =>
|
||||
while (rs.next()) {
|
||||
val columnName = rs.getString("COLUMN_NAME").toUpperCase
|
||||
columns += Column(columnName, pkColumns.contains(columnName))
|
||||
val columns = ListBuffer[Column]()
|
||||
Using.resource(meta.getColumns(null, "%", tableName, "%")) { rs =>
|
||||
while (rs.next()) {
|
||||
val columnName = rs.getString("COLUMN_NAME").toUpperCase
|
||||
columns += Column(columnName, pkColumns.contains(columnName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
tables += Table(tableName.toUpperCase, columns.toSeq)
|
||||
}
|
||||
tables += Table(tableName.toUpperCase, columns.toSeq)
|
||||
}
|
||||
}
|
||||
html.dbviewer(tables.toSeq)
|
||||
})
|
||||
@@ -284,26 +269,28 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
if (trimmedQuery.nonEmpty) {
|
||||
try {
|
||||
val conn = request2Session(request).conn
|
||||
Using.resource(conn.prepareStatement(query)) { stmt =>
|
||||
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
||||
Using.resource(stmt.executeQuery()) { rs =>
|
||||
val meta = rs.getMetaData
|
||||
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
||||
meta.getColumnName(i)
|
||||
Using.resource(conn.prepareStatement(query)) {
|
||||
stmt =>
|
||||
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
||||
Using.resource(stmt.executeQuery()) {
|
||||
rs =>
|
||||
val meta = rs.getMetaData
|
||||
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
||||
meta.getColumnName(i)
|
||||
}
|
||||
val result = ListBuffer[Map[String, String]]()
|
||||
while (rs.next()) {
|
||||
val row = columns.map { columnName =>
|
||||
columnName -> Option(rs.getObject(columnName)).map(_.toString).getOrElse("<NULL>")
|
||||
}.toMap
|
||||
result += row
|
||||
}
|
||||
Ok(Serialization.write(Map("type" -> "query", "columns" -> columns, "rows" -> result)))
|
||||
}
|
||||
val result = ListBuffer[Map[String, String]]()
|
||||
while (rs.next()) {
|
||||
val row = columns.map { columnName =>
|
||||
columnName -> Option(rs.getObject(columnName)).map(_.toString).getOrElse("<NULL>")
|
||||
}.toMap
|
||||
result += row
|
||||
}
|
||||
Ok(Serialization.write(Map("type" -> "query", "columns" -> columns, "rows" -> result)))
|
||||
} else {
|
||||
val rows = stmt.executeUpdate()
|
||||
Ok(Serialization.write(Map("type" -> "update", "rows" -> rows)))
|
||||
}
|
||||
} else {
|
||||
val rows = stmt.executeUpdate()
|
||||
Ok(Serialization.write(Map("type" -> "update", "rows" -> rows)))
|
||||
}
|
||||
}
|
||||
} catch {
|
||||
case e: Exception =>
|
||||
@@ -320,15 +307,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
post("/admin/system", form)(adminOnly { form =>
|
||||
saveSystemSettings(form)
|
||||
|
||||
if (
|
||||
form.ssh.bindAddress != context.settings.sshBindAddress || form.ssh.publicAddress != context.settings.sshPublicAddress
|
||||
) {
|
||||
if (form.sshAddress != context.settings.sshAddress) {
|
||||
SshServer.stop()
|
||||
for {
|
||||
bindAddress <- form.ssh.bindAddress
|
||||
publicAddress <- form.ssh.publicAddress.orElse(form.ssh.bindAddress)
|
||||
sshAddress <- form.sshAddress
|
||||
baseUrl <- form.baseUrl
|
||||
} SshServer.start(bindAddress, publicAddress, baseUrl)
|
||||
} SshServer.start(sshAddress, baseUrl)
|
||||
}
|
||||
|
||||
flash.update("info", "System settings has been updated.")
|
||||
@@ -337,12 +321,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
post("/admin/system/sendmail", sendMailForm)(adminOnly { form =>
|
||||
try {
|
||||
new Mailer(
|
||||
context.settings.copy(
|
||||
smtp = Some(form.smtp),
|
||||
basicBehavior = context.settings.basicBehavior.copy(notification = true)
|
||||
)
|
||||
).send(
|
||||
new Mailer(context.settings.copy(smtp = Some(form.smtp), notification = true)).send(
|
||||
to = form.testAddress,
|
||||
subject = "Test message from GitBucket",
|
||||
textMsg = "This is a test message from GitBucket.",
|
||||
@@ -363,7 +342,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
})
|
||||
|
||||
post("/admin/plugins/_reload")(adminOnly {
|
||||
PluginRegistry.reload(request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
||||
PluginRegistry.reload(request.getServletContext(), loadSystemSettings(), request2Session(request).conn)
|
||||
flash.update("info", "All plugins were reloaded.")
|
||||
redirect("/admin/plugins")
|
||||
})
|
||||
@@ -381,11 +360,11 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
})
|
||||
|
||||
get("/admin/users")(adminOnly {
|
||||
val includeRemoved = params.get("includeRemoved").exists(_.toBoolean)
|
||||
val includeGroups = params.get("includeGroups").exists(_.toBoolean)
|
||||
val includeRemoved = params.get("includeRemoved").map(_.toBoolean).getOrElse(false)
|
||||
val includeGroups = params.get("includeGroups").map(_.toBoolean).getOrElse(false)
|
||||
val users = getAllUsers(includeRemoved, includeGroups)
|
||||
val members = users.collect {
|
||||
case account if account.isGroupAccount =>
|
||||
case account if (account.isGroupAccount) =>
|
||||
account.userName -> getGroupMembers(account.userName).map(_.userName)
|
||||
}.toMap
|
||||
|
||||
@@ -406,7 +385,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
form.description,
|
||||
form.url
|
||||
)
|
||||
updateImage(form.userName, form.fileId, clearImage = false)
|
||||
updateImage(form.userName, form.fileId, false)
|
||||
updateAccountExtraMailAddresses(form.userName, form.extraMailAddresses.filter(_ != ""))
|
||||
redirect("/admin/users")
|
||||
})
|
||||
@@ -414,48 +393,49 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
get("/admin/users/:userName/_edituser")(adminOnly {
|
||||
val userName = params("userName")
|
||||
val extraMails = getAccountExtraMailAddresses(userName)
|
||||
html.user(getAccountByUserName(userName, includeRemoved = true), extraMails, flash.get("error"))
|
||||
html.user(getAccountByUserName(userName, true), extraMails, flash.get("error"))
|
||||
})
|
||||
|
||||
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName, includeRemoved = true).map { account =>
|
||||
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
||||
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
||||
redirect(s"/admin/users/${userName}/_edituser")
|
||||
} else {
|
||||
if (form.isRemoved) {
|
||||
// Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
// FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
// Remove from GROUP_MEMBER and COLLABORATOR
|
||||
removeUserRelatedData(userName)
|
||||
}
|
||||
getAccountByUserName(userName, true).map {
|
||||
account =>
|
||||
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
||||
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
||||
redirect(s"/admin/users/${userName}/_edituser")
|
||||
} else {
|
||||
if (form.isRemoved) {
|
||||
// Remove repositories
|
||||
// getRepositoryNamesOfUser(userName).foreach { repositoryName =>
|
||||
// deleteRepository(userName, repositoryName)
|
||||
// FileUtils.deleteDirectory(getRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(userName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(userName, repositoryName))
|
||||
// }
|
||||
// Remove from GROUP_MEMBER and COLLABORATOR
|
||||
removeUserRelatedData(userName)
|
||||
}
|
||||
|
||||
updateAccount(
|
||||
account.copy(
|
||||
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
description = form.description,
|
||||
url = form.url,
|
||||
isRemoved = form.isRemoved
|
||||
updateAccount(
|
||||
account.copy(
|
||||
password = form.password.map(pbkdf2_sha256).getOrElse(account.password),
|
||||
fullName = form.fullName,
|
||||
mailAddress = form.mailAddress,
|
||||
isAdmin = form.isAdmin,
|
||||
description = form.description,
|
||||
url = form.url,
|
||||
isRemoved = form.isRemoved
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||
updateImage(userName, form.fileId, form.clearImage)
|
||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||
|
||||
// call hooks
|
||||
if (form.isRemoved) PluginRegistry().getAccountHooks.foreach(_.deleted(userName))
|
||||
// call hooks
|
||||
if (form.isRemoved) PluginRegistry().getAccountHooks.foreach(_.deleted(userName))
|
||||
|
||||
redirect("/admin/users")
|
||||
}
|
||||
redirect("/admin/users")
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -476,32 +456,36 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
}
|
||||
.toList
|
||||
)
|
||||
updateImage(form.groupName, form.fileId, clearImage = false)
|
||||
updateImage(form.groupName, form.fileId, false)
|
||||
redirect("/admin/users")
|
||||
})
|
||||
|
||||
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
||||
val groupName = params("groupName")
|
||||
html.usergroup(getAccountByUserName(groupName, includeRemoved = true), getGroupMembers(groupName))
|
||||
defining(params("groupName")) { groupName =>
|
||||
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
||||
}
|
||||
})
|
||||
|
||||
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
||||
val groupName = params("groupName")
|
||||
val members = form.members
|
||||
.split(",")
|
||||
.map {
|
||||
_.split(":") match {
|
||||
case Array(userName, isManager) => (userName, isManager.toBoolean)
|
||||
defining(
|
||||
params("groupName"),
|
||||
form.members
|
||||
.split(",")
|
||||
.map {
|
||||
_.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, includeRemoved = true).map { account =>
|
||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||
|
||||
if (form.isRemoved) {
|
||||
// Remove from GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, Nil)
|
||||
if (form.isRemoved) {
|
||||
// Remove from GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, Nil)
|
||||
// // Remove repositories
|
||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||
// deleteRepository(groupName, repositoryName)
|
||||
@@ -509,9 +493,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
||||
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
||||
// }
|
||||
} else {
|
||||
// Update GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, members)
|
||||
} else {
|
||||
// Update GROUP_MEMBER
|
||||
updateGroupMembers(form.groupName, members)
|
||||
// // Update COLLABORATOR for group repositories
|
||||
// getRepositoryNamesOfUser(form.groupName).foreach { repositoryName =>
|
||||
// removeCollaborators(form.groupName, repositoryName)
|
||||
@@ -519,22 +503,23 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
// addCollaborator(form.groupName, repositoryName, userName)
|
||||
// }
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||
redirect("/admin/users")
|
||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||
redirect("/admin/users")
|
||||
|
||||
} getOrElse NotFound()
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
get("/admin/data")(adminOnly {
|
||||
import gitbucket.core.util.JDBCUtil.*
|
||||
import gitbucket.core.util.JDBCUtil._
|
||||
val session = request2Session(request)
|
||||
html.data(session.conn.allTableNames())
|
||||
})
|
||||
|
||||
post("/admin/export")(adminOnly {
|
||||
import gitbucket.core.util.JDBCUtil.*
|
||||
import gitbucket.core.util.JDBCUtil._
|
||||
val file = request2Session(request).conn.exportAsSQL(request.getParameterValues("tableNames").toSeq)
|
||||
|
||||
contentType = "application/octet-stream"
|
||||
@@ -549,7 +534,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
})
|
||||
|
||||
private def multiLineText(constraints: Constraint*): SingleValueType[Seq[String]] =
|
||||
new SingleValueType[Seq[String]](constraints*) {
|
||||
new SingleValueType[Seq[String]](constraints: _*) {
|
||||
def convert(value: String, messages: Messages): Seq[String] = {
|
||||
if (value == null) {
|
||||
Nil
|
||||
@@ -562,11 +547,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
private def members: Constraint =
|
||||
new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||
if (
|
||||
value.split(",").exists {
|
||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||
}
|
||||
) None
|
||||
if (value.split(",").exists {
|
||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||
}) None
|
||||
else Some("Must select one manager at least.")
|
||||
}
|
||||
}
|
||||
@@ -574,11 +557,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
protected def disableByNotYourself(paramName: String): Constraint =
|
||||
new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||
for {
|
||||
userName <- params.get(paramName)
|
||||
loginAccount <- context.loginAccount
|
||||
if userName == loginAccount.userName && params.get("removed").contains("true")
|
||||
} yield "You can't disable your account yourself"
|
||||
params.get(paramName).flatMap { userName =>
|
||||
if (userName == context.loginAccount.get.userName && params.get("removed") == Some("true"))
|
||||
Some("You can't disable your account yourself")
|
||||
else
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import org.json4s.{JField, JObject, JString}
|
||||
import org.scalatra.*
|
||||
import org.scalatra.json.*
|
||||
import org.scalatra.forms.*
|
||||
import org.scalatra._
|
||||
import org.scalatra.json._
|
||||
import org.scalatra.forms._
|
||||
import org.scalatra.i18n.I18nSupport
|
||||
import org.scalatra.servlet.ServletBase
|
||||
|
||||
/**
|
||||
* Extends scalatra-forms to support the client-side validation and Ajax requests as well.
|
||||
*/
|
||||
trait ValidationSupport extends FormSupport { self: ServletBase & JacksonJsonSupport & I18nSupport =>
|
||||
trait ValidationSupport extends FormSupport { self: ServletBase with JacksonJsonSupport with I18nSupport =>
|
||||
|
||||
def get[T](path: String, form: ValueType[T])(action: T => Any): Route = {
|
||||
registerValidate(path, form)
|
||||
@@ -84,8 +84,9 @@ trait ValidationSupport extends FormSupport { self: ServletBase & JacksonJsonSup
|
||||
* Converts errors to JSON.
|
||||
*/
|
||||
private def toJson(errors: Seq[(String, String)]): JObject =
|
||||
JObject(errors.map { case (key, value) =>
|
||||
JField(key, JString(value))
|
||||
JObject(errors.map {
|
||||
case (key, value) =>
|
||||
JField(key, JString(value))
|
||||
}.toList)
|
||||
|
||||
}
|
||||
|
||||
@@ -1,20 +1,18 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.model.WebHook
|
||||
import gitbucket.core.model.activity.{CreateWikiPageInfo, DeleteWikiInfo, EditWikiPageInfo}
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||
import gitbucket.core.wiki.html
|
||||
import gitbucket.core.service.*
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.util.StringUtil.*
|
||||
import gitbucket.core.util.SyntaxSugars.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.Directory.*
|
||||
import org.scalatra.forms.*
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import org.scalatra.forms._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
import scala.util.Using
|
||||
|
||||
class WikiController
|
||||
@@ -26,13 +24,17 @@ class WikiController
|
||||
with WebHookService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator
|
||||
with RequestCache
|
||||
|
||||
trait WikiControllerBase extends ControllerBase {
|
||||
self: WikiService & RepositoryService & AccountService & ActivityService & WebHookService &
|
||||
ReadableUsersAuthenticator & ReferrerAuthenticator =>
|
||||
self: WikiService
|
||||
with RepositoryService
|
||||
with AccountService
|
||||
with ActivityService
|
||||
with WebHookService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator =>
|
||||
|
||||
private case class WikiPageEditForm(
|
||||
case class WikiPageEditForm(
|
||||
pageName: String,
|
||||
content: String,
|
||||
message: Option[String],
|
||||
@@ -40,16 +42,16 @@ trait WikiControllerBase extends ControllerBase {
|
||||
id: String
|
||||
)
|
||||
|
||||
private val newForm = mapping(
|
||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName, unique))),
|
||||
val newForm = mapping(
|
||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pagename, unique))),
|
||||
"content" -> trim(label("Content", text(required, conflictForNew))),
|
||||
"message" -> trim(label("Message", optional(text()))),
|
||||
"currentPageName" -> trim(label("Current page name", text())),
|
||||
"id" -> trim(label("Latest commit id", text()))
|
||||
)(WikiPageEditForm.apply)
|
||||
|
||||
private val editForm = mapping(
|
||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pageName))),
|
||||
val editForm = mapping(
|
||||
"pageName" -> trim(label("Page name", text(required, maxlength(40), pagename))),
|
||||
"content" -> trim(label("Content", text(required, conflictForEdit))),
|
||||
"message" -> trim(label("Message", optional(text()))),
|
||||
"currentPageName" -> trim(label("Current page name", text(required))),
|
||||
@@ -57,56 +59,46 @@ trait WikiControllerBase extends ControllerBase {
|
||||
)(WikiPageEditForm.apply)
|
||||
|
||||
get("/:owner/:repository/wiki")(referrersOnly { repository =>
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
|
||||
getWikiPage(repository.owner, repository.name, "Home", branch).map { page =>
|
||||
getWikiPage(repository.owner, repository.name, "Home").map { page =>
|
||||
html.page(
|
||||
"Home",
|
||||
page,
|
||||
getWikiPageList(repository.owner, repository.name, branch),
|
||||
getWikiPageList(repository.owner, repository.name),
|
||||
repository,
|
||||
isEditable(repository),
|
||||
getWikiPage(repository.owner, repository.name, "_Sidebar", branch),
|
||||
getWikiPage(repository.owner, repository.name, "_Footer", branch)
|
||||
getWikiPage(repository.owner, repository.name, "_Sidebar"),
|
||||
getWikiPage(repository.owner, repository.name, "_Footer")
|
||||
)
|
||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/Home/_edit")
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/:page")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
|
||||
getWikiPage(repository.owner, repository.name, pageName, branch).map { page =>
|
||||
getWikiPage(repository.owner, repository.name, pageName).map { page =>
|
||||
html.page(
|
||||
pageName,
|
||||
page,
|
||||
getWikiPageList(repository.owner, repository.name, branch),
|
||||
getWikiPageList(repository.owner, repository.name),
|
||||
repository,
|
||||
isEditable(repository),
|
||||
getWikiPage(repository.owner, repository.name, "_Sidebar", branch),
|
||||
getWikiPage(repository.owner, repository.name, "_Footer", branch)
|
||||
getWikiPage(repository.owner, repository.name, "_Sidebar"),
|
||||
getWikiPage(repository.owner, repository.name, "_Footer")
|
||||
)
|
||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_edit")
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_history")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
|
||||
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
JGitUtil.getCommitLog(git, branch, path = pageName + ".md") match {
|
||||
JGitUtil.getCommitLog(git, "master", path = pageName + ".md") match {
|
||||
case Right((logs, hasNext)) => html.history(Some(pageName), logs, repository, isEditable(repository))
|
||||
case Left(_) => NotFound()
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
private def getWikiBranch(owner: String, repository: String): String = {
|
||||
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) { git =>
|
||||
git.getRepository.getBranch
|
||||
}
|
||||
}
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_compare/:commitId")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
@@ -116,17 +108,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
Some(pageName),
|
||||
from,
|
||||
to,
|
||||
JGitUtil
|
||||
.getDiffs(
|
||||
git = git,
|
||||
from = Some(from),
|
||||
to = to,
|
||||
fetchContent = true,
|
||||
makePatch = false,
|
||||
maxFiles = context.settings.repositoryViewer.maxDiffFiles,
|
||||
maxLines = context.settings.repositoryViewer.maxDiffLines
|
||||
)
|
||||
.filter(_.newPath == pageName + ".md"),
|
||||
JGitUtil.getDiffs(git, Some(from), to, true, false).filter(_.newPath == pageName + ".md"),
|
||||
repository,
|
||||
isEditable(repository),
|
||||
flash.get("info")
|
||||
@@ -142,15 +124,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
None,
|
||||
from,
|
||||
to,
|
||||
JGitUtil.getDiffs(
|
||||
git = git,
|
||||
from = Some(from),
|
||||
to = to,
|
||||
fetchContent = true,
|
||||
makePatch = false,
|
||||
maxFiles = context.settings.repositoryViewer.maxDiffFiles,
|
||||
maxLines = context.settings.repositoryViewer.maxDiffLines
|
||||
),
|
||||
JGitUtil.getDiffs(git, Some(from), to, true, false),
|
||||
repository,
|
||||
isEditable(repository),
|
||||
flash.get("info")
|
||||
@@ -159,79 +133,77 @@ trait WikiControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isEditable(repository)) {
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
if (isEditable(repository)) {
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
|
||||
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, Some(pageName), branch)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
||||
} else {
|
||||
flash.update("info", "This patch was not able to be reversed.")
|
||||
redirect(
|
||||
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/$from...$to"
|
||||
)
|
||||
}
|
||||
} else Unauthorized()
|
||||
}
|
||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, Some(pageName))) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
||||
} else {
|
||||
flash.update("info", "This patch was not able to be reversed.")
|
||||
redirect(
|
||||
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
||||
)
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isEditable(repository)) {
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
if (isEditable(repository)) {
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
|
||||
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, None, branch)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
} else {
|
||||
flash.update("info", "This patch was not able to be reversed.")
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/$from...$to")
|
||||
}
|
||||
} else Unauthorized()
|
||||
}
|
||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, None)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
} else {
|
||||
flash.update("info", "This patch was not able to be reversed.")
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_edit")(readableUsersOnly { repository =>
|
||||
if (isEditable(repository)) {
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
|
||||
html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName, branch), repository)
|
||||
html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName), repository)
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isEditable(repository)) {
|
||||
saveWikiPage(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
form.currentPageName,
|
||||
form.pageName,
|
||||
appendNewLine(convertLineSeparator(form.content, "LF"), "LF"),
|
||||
loginAccount,
|
||||
form.message.getOrElse(""),
|
||||
Some(form.id)
|
||||
).foreach { commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
val wikiEditInfo =
|
||||
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
||||
recordActivity(wikiEditInfo)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
}
|
||||
if (isEditable(repository)) {
|
||||
defining(context.loginAccount.get) {
|
||||
loginAccount =>
|
||||
saveWikiPage(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
form.currentPageName,
|
||||
form.pageName,
|
||||
appendNewLine(convertLineSeparator(form.content, "LF"), "LF"),
|
||||
loginAccount,
|
||||
form.message.getOrElse(""),
|
||||
Some(form.id)
|
||||
).foreach {
|
||||
commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
recordEditWikiPageActivity(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
loginAccount.userName,
|
||||
form.pageName,
|
||||
commitId
|
||||
)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (notReservedPageName(form.pageName)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||
} else {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
}
|
||||
} else Unauthorized()
|
||||
}
|
||||
if (notReservedPageName(form.pageName)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||
} else {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
}
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
||||
@@ -241,67 +213,60 @@ trait WikiControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isEditable(repository)) {
|
||||
saveWikiPage(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
form.currentPageName,
|
||||
form.pageName,
|
||||
form.content,
|
||||
loginAccount,
|
||||
form.message.getOrElse(""),
|
||||
None
|
||||
).foreach { commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
val createWikiPageInfo =
|
||||
CreateWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||
recordActivity(createWikiPageInfo)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
}
|
||||
if (isEditable(repository)) {
|
||||
defining(context.loginAccount.get) {
|
||||
loginAccount =>
|
||||
saveWikiPage(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
form.currentPageName,
|
||||
form.pageName,
|
||||
form.content,
|
||||
loginAccount,
|
||||
form.message.getOrElse(""),
|
||||
None
|
||||
).foreach {
|
||||
commitId =>
|
||||
updateLastActivityDate(repository.owner, repository.name)
|
||||
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (notReservedPageName(form.pageName)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||
} else {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
}
|
||||
} else Unauthorized()
|
||||
}
|
||||
if (notReservedPageName(form.pageName)) {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(form.pageName)}")
|
||||
} else {
|
||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||
}
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
||||
context.withLoginAccount { loginAccount =>
|
||||
if (isEditable(repository)) {
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
if (isEditable(repository)) {
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
|
||||
defining(context.loginAccount.get) { loginAccount =>
|
||||
deleteWikiPage(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
pageName,
|
||||
loginAccount.fullName,
|
||||
loginAccount.mailAddress,
|
||||
s"Destroyed $pageName"
|
||||
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")
|
||||
} else Unauthorized()
|
||||
}
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
||||
val branch = getWikiBranch(repository.owner, repository.name)
|
||||
html.pages(getWikiPageList(repository.owner, repository.name, branch), repository, isEditable(repository))
|
||||
html.pages(getWikiPageList(repository.owner, repository.name), repository, isEditable(repository))
|
||||
})
|
||||
|
||||
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
||||
@@ -330,29 +295,24 @@ trait WikiControllerBase extends ControllerBase {
|
||||
value: String,
|
||||
params: Map[String, Seq[String]],
|
||||
messages: Messages
|
||||
): Option[String] = {
|
||||
val owner = params.value("owner")
|
||||
val repository = params.value("repository")
|
||||
val branch = getWikiBranch(owner, repository)
|
||||
|
||||
getWikiPageList(owner, repository, branch)
|
||||
): Option[String] =
|
||||
getWikiPageList(params.value("owner"), params.value("repository"))
|
||||
.find(_ == value)
|
||||
.map(_ => "Page already exists.")
|
||||
}
|
||||
}
|
||||
|
||||
private def pageName: Constraint = new Constraint() {
|
||||
private def pagename: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||
if (value.exists("\\/:*?\"<>|".contains(_))) {
|
||||
Some(s"$name contains invalid character.")
|
||||
Some(s"${name} contains invalid character.")
|
||||
} else if (notReservedPageName(value) && (value.startsWith("_") || value.startsWith("-"))) {
|
||||
Some(s"$name starts with invalid character.")
|
||||
Some(s"${name} starts with invalid character.")
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
|
||||
private def notReservedPageName(value: String): Boolean = !(Array[String]("_Sidebar", "_Footer") contains value)
|
||||
private def notReservedPageName(value: String) = !(Array[String]("_Sidebar", "_Footer") contains value)
|
||||
|
||||
private def conflictForNew: Constraint = new Constraint() {
|
||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||
@@ -370,13 +330,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private def targetWikiPage: Option[WikiService.WikiPageInfo] = {
|
||||
val owner = params("owner")
|
||||
val repository = params("repository")
|
||||
val pageName = params("pageName")
|
||||
val branch = getWikiBranch(owner, repository)
|
||||
getWikiPage(owner, repository, pageName, branch)
|
||||
}
|
||||
private def targetWikiPage = getWikiPage(params("owner"), params("repository"), params("pageName"))
|
||||
|
||||
private def isEditable(repository: RepositoryInfo)(implicit context: Context): Boolean = {
|
||||
repository.repository.options.wikiOption match {
|
||||
|
||||
@@ -1,160 +1,75 @@
|
||||
package gitbucket.core.controller.api
|
||||
import gitbucket.core.api.{ApiError, ApiRef, CreateARef, JsonFormat, UpdateARef}
|
||||
import gitbucket.core.api.{ApiObject, ApiRef, JsonFormat}
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util.Directory.getRepositoryDir
|
||||
import gitbucket.core.util.ReferrerAuthenticator
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.{ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
||||
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 scala.jdk.CollectionConverters._
|
||||
import scala.util.Using
|
||||
|
||||
trait ApiGitReferenceControllerBase extends ControllerBase {
|
||||
self: ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||
self: ReferrerAuthenticator =>
|
||||
|
||||
private val logger = LoggerFactory.getLogger(classOf[ApiGitReferenceControllerBase])
|
||||
|
||||
get("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { repository =>
|
||||
val result = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
val refs = git
|
||||
.getRepository()
|
||||
.getRefDatabase()
|
||||
.getRefsByPrefix("refs")
|
||||
.asScala
|
||||
|
||||
refs.map(ApiRef.fromRef(RepositoryName(s"${repository.owner}/${repository.name}"), _))
|
||||
}
|
||||
JsonFormat(result)
|
||||
})
|
||||
|
||||
/*
|
||||
* 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 =>
|
||||
val revstr = multiParams("splat").head
|
||||
getRef(revstr, repository)
|
||||
getRef()
|
||||
})
|
||||
|
||||
// Some versions of GHE support this path
|
||||
get("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { repository =>
|
||||
logger.warn("git/refs/ endpoint may not be compatible with GitHub API v3. Consider using git/ref/ endpoint instead")
|
||||
val revstr = multiParams("splat").head
|
||||
getRef(revstr, repository)
|
||||
getRef()
|
||||
})
|
||||
|
||||
private def getRef() = {
|
||||
val revstr = multiParams("splat").head
|
||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||
val ref = git.getRepository().findRef(revstr)
|
||||
|
||||
if (ref != null) {
|
||||
val sha = ref.getObjectId().name()
|
||||
JsonFormat(ApiRef(revstr, ApiObject(sha)))
|
||||
|
||||
} else {
|
||||
val refs = git
|
||||
.getRepository()
|
||||
.getRefDatabase()
|
||||
.getRefsByPrefix("refs/")
|
||||
.asScala
|
||||
|
||||
JsonFormat(refs.map { ref =>
|
||||
val sha = ref.getObjectId().name()
|
||||
ApiRef(revstr, ApiObject(sha))
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* 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
|
||||
* 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")(writableUsersOnly { repository =>
|
||||
extractFromJsonBody[CreateARef].map { data =>
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { 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
|
||||
.fromRef(RepositoryName(repository.owner, repository.name), git.getRepository.findRef(data.ref))
|
||||
)
|
||||
case _ => UnprocessableEntity(result.name())
|
||||
}
|
||||
} else {
|
||||
UnprocessableEntity("Ref already exists.")
|
||||
}
|
||||
}
|
||||
} getOrElse BadRequest()
|
||||
})
|
||||
|
||||
/*
|
||||
* 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/*")(writableUsersOnly { repository =>
|
||||
val refName = multiParams("splat").mkString("/")
|
||||
extractFromJsonBody[UpdateARef].map { data =>
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { 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.fromRef(RepositoryName(repository), git.getRepository.findRef(refName)))
|
||||
case _ => UnprocessableEntity(result.name())
|
||||
}
|
||||
}
|
||||
}
|
||||
} getOrElse BadRequest()
|
||||
})
|
||||
|
||||
/*
|
||||
* v. Delete a reference
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#delete-a-reference
|
||||
*/
|
||||
delete("/api/v3/repos/:owner/:repository/git/refs/*")(writableUsersOnly { _ =>
|
||||
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())
|
||||
}
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
private def notFound(): ApiError = {
|
||||
response.setStatus(404)
|
||||
ApiError("Not Found")
|
||||
}
|
||||
|
||||
protected def getRef(revstr: String, repository: RepositoryInfo): AnyRef = {
|
||||
logger.debug(s"getRef: path '${revstr}'")
|
||||
|
||||
val name = RepositoryName(repository)
|
||||
val result = JsonFormat(revstr match {
|
||||
case "tags" => repository.tags.map(ApiRef.fromTag(name, _))
|
||||
case x if x.startsWith("tags/") =>
|
||||
val tagName = x.substring("tags/".length)
|
||||
repository.tags.find(_.name == tagName) match {
|
||||
case Some(tagInfo) => ApiRef.fromTag(name, tagInfo)
|
||||
case None => notFound()
|
||||
}
|
||||
case other =>
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
git.getRepository().findRef(other) match {
|
||||
case null => notFound()
|
||||
case ref => ApiRef.fromRef(name, ref)
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
logger.debug(s"json result: $result")
|
||||
result
|
||||
}
|
||||
* v. Delete a reference
|
||||
* https://developer.github.com/v3/git/refs/#delete-a-reference
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -4,111 +4,44 @@ import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
||||
import org.scalatra.ActionResult
|
||||
|
||||
trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||
self: AccountService & IssuesService & RepositoryService & HandleCommentService & MilestonesService &
|
||||
ReadableUsersAuthenticator & ReferrerAuthenticator =>
|
||||
self: AccountService
|
||||
with IssuesService
|
||||
with RepositoryService
|
||||
with HandleCommentService
|
||||
with MilestonesService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator =>
|
||||
/*
|
||||
* i. List issue comments for a repository
|
||||
* https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
|
||||
* i. List comments on an issue
|
||||
* https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
|
||||
*/
|
||||
get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository =>
|
||||
(for {
|
||||
issueId <- params("id").toIntOpt
|
||||
comments = getCommentsForApi(repository.owner, repository.name, issueId)
|
||||
} yield {
|
||||
JsonFormat(comments.map { case (issueComment, user, issue) =>
|
||||
ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user), issue.isPullRequest)
|
||||
JsonFormat(comments.map {
|
||||
case (issueComment, user, issue) =>
|
||||
ApiComment(issueComment, RepositoryName(repository), issueId, ApiUser(user), issue.isPullRequest)
|
||||
})
|
||||
}) getOrElse NotFound()
|
||||
})
|
||||
|
||||
/*
|
||||
* ii. Get an issue comment
|
||||
* https://docs.github.com/en/rest/reference/issues#get-an-issue-comment
|
||||
*/
|
||||
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/:repository/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
|
||||
* ii. List comments in a repository
|
||||
* https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
|
||||
*/
|
||||
|
||||
/*
|
||||
* vi. Create an issue comment
|
||||
* https://docs.github.com/en/rest/reference/issues#create-an-issue-comment
|
||||
* iii. Get a single 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 =>
|
||||
(for {
|
||||
@@ -131,6 +64,16 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||
}) 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 =
|
||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||
}
|
||||
|
||||
@@ -5,12 +5,16 @@ import gitbucket.core.model.{Account, Issue}
|
||||
import gitbucket.core.service.{AccountService, IssueCreationService, IssuesService, MilestonesService}
|
||||
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
||||
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._
|
||||
|
||||
trait ApiIssueControllerBase extends ControllerBase {
|
||||
self: AccountService & IssuesService & IssueCreationService & MilestonesService & ReadableUsersAuthenticator &
|
||||
ReferrerAuthenticator =>
|
||||
self: AccountService
|
||||
with IssuesService
|
||||
with IssueCreationService
|
||||
with MilestonesService
|
||||
with ReadableUsersAuthenticator
|
||||
with ReferrerAuthenticator =>
|
||||
/*
|
||||
* i. List issues
|
||||
* https://developer.github.com/v3/issues/#list-issues
|
||||
@@ -25,9 +29,9 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
val page = IssueSearchCondition.page(request)
|
||||
// TODO: more api spec condition
|
||||
val condition = IssueSearchCondition(request)
|
||||
// val baseOwner = getAccountByUserName(repository.owner).get
|
||||
val baseOwner = getAccountByUserName(repository.owner).get
|
||||
|
||||
val issues: List[(Issue, Account, List[Account])] =
|
||||
val issues: List[(Issue, Account, Option[Account])] =
|
||||
searchIssueByApi(
|
||||
condition = condition,
|
||||
offset = (page - 1) * PullRequestLimit,
|
||||
@@ -35,16 +39,16 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
repos = repository.owner -> repository.name
|
||||
)
|
||||
|
||||
JsonFormat(issues.map { case (issue, issueUser, assigneeUsers) =>
|
||||
ApiIssue(
|
||||
issue = issue,
|
||||
repositoryName = RepositoryName(repository),
|
||||
user = ApiUser(issueUser),
|
||||
assignees = assigneeUsers.map(ApiUser(_)),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository))),
|
||||
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||
)
|
||||
JsonFormat(issues.map {
|
||||
case (issue, issueUser, assignedUser) =>
|
||||
ApiIssue(
|
||||
issue = issue,
|
||||
repositoryName = RepositoryName(repository),
|
||||
user = ApiUser(issueUser),
|
||||
assignee = assignedUser.map(ApiUser(_)),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository)))
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -56,8 +60,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
(for {
|
||||
issueId <- params("id").toIntOpt
|
||||
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||
assigneeUsers = getIssueAssignees(repository.owner, repository.name, issueId)
|
||||
users = getAccountsByUserNames(Set(issue.openedUserName) ++ assigneeUsers.map(_.assigneeUserName), Set())
|
||||
users = getAccountsByUserNames(Set(issue.openedUserName) ++ issue.assignedUserName, Set())
|
||||
openedUser <- users.get(issue.openedUserName)
|
||||
} yield {
|
||||
JsonFormat(
|
||||
@@ -65,9 +68,8 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
issue,
|
||||
RepositoryName(repository),
|
||||
ApiUser(openedUser),
|
||||
assigneeUsers.flatMap(x => users.get(x.assigneeUserName)).map(ApiUser(_)),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
|
||||
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||
issue.assignedUserName.flatMap(users.get(_)).map(ApiUser(_)),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
||||
)
|
||||
)
|
||||
}) getOrElse NotFound()
|
||||
@@ -88,7 +90,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
repository,
|
||||
data.title,
|
||||
data.body,
|
||||
data.assignees,
|
||||
data.assignees.headOption,
|
||||
milestone.map(_.milestoneId),
|
||||
None,
|
||||
data.labels,
|
||||
@@ -99,12 +101,9 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
issue,
|
||||
RepositoryName(repository),
|
||||
ApiUser(loginAccount),
|
||||
getIssueAssignees(repository.owner, repository.name, issue.issueId)
|
||||
.flatMap(x => getAccountByUserName(x.assigneeUserName, false))
|
||||
.map(ApiUser.apply),
|
||||
issue.assignedUserName.flatMap(getAccountByUserName(_)).map(ApiUser(_)),
|
||||
getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository))),
|
||||
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||
.map(ApiLabel(_, RepositoryName(repository)))
|
||||
)
|
||||
)
|
||||
}) getOrElse NotFound()
|
||||
@@ -121,7 +120,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
||||
*/
|
||||
|
||||
/*
|
||||
* vii. Unlock an issue
|
||||
* https://developer.github.com/v3/issues/#unlock-an-issue
|
||||
*/
|
||||
* vii. Unlock an issue
|
||||
* https://developer.github.com/v3/issues/#unlock-an-issue
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package gitbucket.core.controller.api
|
||||
import gitbucket.core.api.{AddLabelsToAnIssue, ApiError, ApiLabel, CreateALabel, JsonFormat}
|
||||
import gitbucket.core.api.{ApiError, ApiLabel, CreateALabel, JsonFormat}
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.Implicits._
|
||||
@@ -7,7 +7,11 @@ import gitbucket.core.util._
|
||||
import org.scalatra.{Created, NoContent, UnprocessableEntity}
|
||||
|
||||
trait ApiIssueLabelControllerBase extends ControllerBase {
|
||||
self: AccountService & IssuesService & LabelsService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||
self: AccountService
|
||||
with IssuesService
|
||||
with LabelsService
|
||||
with ReferrerAuthenticator
|
||||
with WritableUsersAuthenticator =>
|
||||
|
||||
/*
|
||||
* i. List all labels for this repository
|
||||
@@ -65,24 +69,25 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
||||
data <- extractFromJsonBody[CreateALabel] if data.isValid
|
||||
} yield {
|
||||
LockUtil.lock(RepositoryName(repository).fullName) {
|
||||
getLabel(repository.owner, repository.name, params("labelName")).map { label =>
|
||||
if (getLabel(repository.owner, repository.name, data.name).isEmpty) {
|
||||
updateLabel(repository.owner, repository.name, label.labelId, data.name, data.color)
|
||||
JsonFormat(
|
||||
ApiLabel(
|
||||
getLabel(repository.owner, repository.name, label.labelId).get,
|
||||
RepositoryName(repository)
|
||||
getLabel(repository.owner, repository.name, params("labelName")).map {
|
||||
label =>
|
||||
if (getLabel(repository.owner, repository.name, data.name).isEmpty) {
|
||||
updateLabel(repository.owner, repository.name, label.labelId, data.name, data.color)
|
||||
JsonFormat(
|
||||
ApiLabel(
|
||||
getLabel(repository.owner, repository.name, label.labelId).get,
|
||||
RepositoryName(repository)
|
||||
)
|
||||
)
|
||||
)
|
||||
} else {
|
||||
// TODO ApiError should support errors field to enhance compatibility of GitHub API
|
||||
UnprocessableEntity(
|
||||
ApiError(
|
||||
"Validation Failed",
|
||||
Some("https://developer.github.com/v3/issues/labels/#create-a-label")
|
||||
} else {
|
||||
// TODO ApiError should support errors field to enhance compatibility of GitHub API
|
||||
UnprocessableEntity(
|
||||
ApiError(
|
||||
"Validation Failed",
|
||||
Some("https://developer.github.com/v3/issues/labels/#create-a-label")
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
}) getOrElse NotFound()
|
||||
@@ -116,10 +121,10 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
||||
*/
|
||||
post("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||
JsonFormat(for {
|
||||
data <- extractFromJsonBody[AddLabelsToAnIssue]
|
||||
data <- extractFromJsonBody[Seq[String]];
|
||||
issueId <- params("id").toIntOpt
|
||||
} yield {
|
||||
data.labels.map { labelName =>
|
||||
data.map { labelName =>
|
||||
val label = getLabel(repository.owner, repository.name, labelName).getOrElse(
|
||||
getLabel(
|
||||
repository.owner,
|
||||
@@ -155,11 +160,11 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
||||
*/
|
||||
put("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||
JsonFormat(for {
|
||||
data <- extractFromJsonBody[AddLabelsToAnIssue]
|
||||
data <- extractFromJsonBody[Seq[String]];
|
||||
issueId <- params("id").toIntOpt
|
||||
} yield {
|
||||
deleteAllIssueLabels(repository.owner, repository.name, issueId, true)
|
||||
data.labels.map { labelName =>
|
||||
data.map { labelName =>
|
||||
val label = getLabel(repository.owner, repository.name, labelName).getOrElse(
|
||||
getLabel(
|
||||
repository.owner,
|
||||
@@ -184,7 +189,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/*
|
||||
* xi Get labels for every issue in a milestone
|
||||
* https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
|
||||
*/
|
||||
* xi Get labels for every issue in a milestone
|
||||
* https://developer.github.com/v3/issues/labels/#get-labels-for-every-issue-in-a-milestone
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,106 +0,0 @@
|
||||
package gitbucket.core.controller.api
|
||||
import gitbucket.core.api._
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.service.MilestonesService
|
||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import org.scalatra.NoContent
|
||||
|
||||
trait ApiIssueMilestoneControllerBase extends ControllerBase {
|
||||
self: MilestonesService & WritableUsersAuthenticator & 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()
|
||||
})
|
||||
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
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.service.{AccountService, RepositoryService}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.{AdminAuthenticator, UsersAuthenticator}
|
||||
|
||||
trait ApiOrganizationControllerBase extends ControllerBase {
|
||||
self: RepositoryService & AccountService & AdminAuthenticator & UsersAuthenticator =>
|
||||
self: RepositoryService with AccountService with AdminAuthenticator with UsersAuthenticator =>
|
||||
|
||||
/*
|
||||
* i. List your organizations
|
||||
@@ -71,6 +71,6 @@ trait ApiOrganizationControllerBase extends ControllerBase {
|
||||
*/
|
||||
|
||||
/*
|
||||
* should implement delete an organization API?
|
||||
*/
|
||||
* should implement delete an organization API?
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -10,14 +10,20 @@ import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||
import gitbucket.core.util._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.scalatra.{Conflict, MethodNotAllowed, NoContent, Ok}
|
||||
import org.scalatra.NoContent
|
||||
import scala.util.Using
|
||||
|
||||
import scala.jdk.CollectionConverters._
|
||||
|
||||
trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
self: AccountService & IssuesService & PullRequestService & RepositoryService & MergeService & ReferrerAuthenticator &
|
||||
ReadableUsersAuthenticator & WritableUsersAuthenticator =>
|
||||
self: AccountService
|
||||
with IssuesService
|
||||
with PullRequestService
|
||||
with RepositoryService
|
||||
with MergeService
|
||||
with ReferrerAuthenticator
|
||||
with ReadableUsersAuthenticator
|
||||
with WritableUsersAuthenticator =>
|
||||
|
||||
/*
|
||||
* i. Link Relations
|
||||
@@ -34,7 +40,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
val condition = IssueSearchCondition(request)
|
||||
val baseOwner = getAccountByUserName(repository.owner).get
|
||||
|
||||
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, List[Account])] =
|
||||
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, Option[Account])] =
|
||||
searchPullRequestByApi(
|
||||
condition = condition,
|
||||
offset = (page - 1) * PullRequestLimit,
|
||||
@@ -42,18 +48,19 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
repos = repository.owner -> repository.name
|
||||
)
|
||||
|
||||
JsonFormat(issues.map { case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignees) =>
|
||||
ApiPullRequest(
|
||||
issue = issue,
|
||||
pullRequest = pullRequest,
|
||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository))),
|
||||
assignees = assignees.map(ApiUser.apply),
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
)
|
||||
JsonFormat(issues.map {
|
||||
case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignee) =>
|
||||
ApiPullRequest(
|
||||
issue = issue,
|
||||
pullRequest = pullRequest,
|
||||
headRepo = ApiRepository(headRepo, ApiUser(headOwner)),
|
||||
baseRepo = ApiRepository(repository, ApiUser(baseOwner)),
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository))),
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
)
|
||||
})
|
||||
})
|
||||
|
||||
@@ -82,37 +89,39 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
case Left(createPullReq) =>
|
||||
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReq.head, repository.owner)
|
||||
getRepository(reqOwner, repository.name)
|
||||
.flatMap { forkedRepository =>
|
||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReq.base, reqBranch) match {
|
||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||
val issueId = insertIssue(
|
||||
owner = repository.owner,
|
||||
repository = repository.name,
|
||||
loginUser = context.loginAccount.get.userName,
|
||||
title = createPullReq.title,
|
||||
content = createPullReq.body,
|
||||
milestoneId = None,
|
||||
priorityId = None,
|
||||
isPullRequest = true
|
||||
)
|
||||
.flatMap {
|
||||
forkedRepository =>
|
||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReq.base, reqBranch) match {
|
||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||
val issueId = insertIssue(
|
||||
owner = repository.owner,
|
||||
repository = repository.name,
|
||||
loginUser = context.loginAccount.get.userName,
|
||||
title = createPullReq.title,
|
||||
content = createPullReq.body,
|
||||
assignedUserName = None,
|
||||
milestoneId = None,
|
||||
priorityId = None,
|
||||
isPullRequest = true
|
||||
)
|
||||
|
||||
createPullRequest(
|
||||
originRepository = repository,
|
||||
issueId = issueId,
|
||||
originBranch = createPullReq.base,
|
||||
requestUserName = reqOwner,
|
||||
requestRepositoryName = repository.name,
|
||||
requestBranch = reqBranch,
|
||||
commitIdFrom = commitIdFrom.getName,
|
||||
commitIdTo = commitIdTo.getName,
|
||||
isDraft = createPullReq.draft.getOrElse(false),
|
||||
loginAccount = context.loginAccount.get,
|
||||
settings = context.settings
|
||||
)
|
||||
getApiPullRequest(repository, issueId).map(JsonFormat(_))
|
||||
case _ =>
|
||||
None
|
||||
}
|
||||
createPullRequest(
|
||||
originRepository = repository,
|
||||
issueId = issueId,
|
||||
originBranch = createPullReq.base,
|
||||
requestUserName = reqOwner,
|
||||
requestRepositoryName = repository.name,
|
||||
requestBranch = reqBranch,
|
||||
commitIdFrom = commitIdFrom.getName,
|
||||
commitIdTo = commitIdTo.getName,
|
||||
isDraft = createPullReq.draft.getOrElse(false),
|
||||
loginAccount = context.loginAccount.get,
|
||||
settings = context.settings
|
||||
)
|
||||
getApiPullRequest(repository, issueId).map(JsonFormat(_))
|
||||
case _ =>
|
||||
None
|
||||
}
|
||||
}
|
||||
.getOrElse {
|
||||
NotFound()
|
||||
@@ -120,27 +129,28 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
case Right(createPullReqAlt) =>
|
||||
val (reqOwner, reqBranch) = parseCompareIdentifier(createPullReqAlt.head, repository.owner)
|
||||
getRepository(reqOwner, repository.name)
|
||||
.flatMap { forkedRepository =>
|
||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReqAlt.base, reqBranch) match {
|
||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||
changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue)
|
||||
createPullRequest(
|
||||
originRepository = repository,
|
||||
issueId = createPullReqAlt.issue,
|
||||
originBranch = createPullReqAlt.base,
|
||||
requestUserName = reqOwner,
|
||||
requestRepositoryName = repository.name,
|
||||
requestBranch = reqBranch,
|
||||
commitIdFrom = commitIdFrom.getName,
|
||||
commitIdTo = commitIdTo.getName,
|
||||
isDraft = false,
|
||||
loginAccount = context.loginAccount.get,
|
||||
settings = context.settings
|
||||
)
|
||||
getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_))
|
||||
case _ =>
|
||||
None
|
||||
}
|
||||
.flatMap {
|
||||
forkedRepository =>
|
||||
getPullRequestCommitFromTo(repository, forkedRepository, createPullReqAlt.base, reqBranch) match {
|
||||
case (Some(commitIdFrom), Some(commitIdTo)) =>
|
||||
changeIssueToPullRequest(repository.owner, repository.name, createPullReqAlt.issue)
|
||||
createPullRequest(
|
||||
originRepository = repository,
|
||||
issueId = createPullReqAlt.issue,
|
||||
originBranch = createPullReqAlt.base,
|
||||
requestUserName = reqOwner,
|
||||
requestRepositoryName = repository.name,
|
||||
requestBranch = reqBranch,
|
||||
commitIdFrom = commitIdFrom.getName,
|
||||
commitIdTo = commitIdTo.getName,
|
||||
isDraft = false,
|
||||
loginAccount = context.loginAccount.get,
|
||||
settings = context.settings
|
||||
)
|
||||
getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_))
|
||||
case _ =>
|
||||
None
|
||||
}
|
||||
}
|
||||
.getOrElse {
|
||||
NotFound()
|
||||
@@ -151,28 +161,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -181,24 +171,26 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
get("/api/v3/repos/:owner/:repository/pulls/:id/commits")(referrersOnly { repository =>
|
||||
val owner = repository.owner
|
||||
val name = repository.name
|
||||
params("id").toIntOpt.flatMap { issueId =>
|
||||
getPullRequest(owner, name, issueId) map { case (issue, pullreq) =>
|
||||
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
||||
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
||||
val repoFullName = RepositoryName(repository)
|
||||
val commits = git.log
|
||||
.addRange(oldId, newId)
|
||||
.call
|
||||
.iterator
|
||||
.asScala
|
||||
.map { c =>
|
||||
ApiCommitListItem(new CommitInfo(c), repoFullName)
|
||||
params("id").toIntOpt.flatMap {
|
||||
issueId =>
|
||||
getPullRequest(owner, name, issueId) map {
|
||||
case (issue, pullreq) =>
|
||||
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
||||
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
||||
val repoFullName = RepositoryName(repository)
|
||||
val commits = git.log
|
||||
.addRange(oldId, newId)
|
||||
.call
|
||||
.iterator
|
||||
.asScala
|
||||
.map { c =>
|
||||
ApiCommitListItem(new CommitInfo(c), repoFullName)
|
||||
}
|
||||
.toList
|
||||
JsonFormat(commits)
|
||||
}
|
||||
.toList
|
||||
JsonFormat(commits)
|
||||
}
|
||||
}
|
||||
} getOrElse NotFound()
|
||||
})
|
||||
/*
|
||||
@@ -218,79 +210,15 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
||||
NoContent
|
||||
} else {
|
||||
NotFound()
|
||||
NotFound
|
||||
}
|
||||
}).getOrElse(NotFound())
|
||||
}).getOrElse(NotFound)
|
||||
})
|
||||
|
||||
/*
|
||||
* 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
|
||||
@@ -307,8 +235,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
baseOwner <- users.get(repository.owner)
|
||||
headOwner <- users.get(pullRequest.requestUserName)
|
||||
issueUser <- users.get(issue.openedUserName)
|
||||
assignees = getIssueAssignees(repository.owner, repository.name, issueId).flatMap { assignedUser =>
|
||||
getAccountByUserName(assignedUser.assigneeUserName, false)
|
||||
assignee = issue.assignedUserName.flatMap { userName =>
|
||||
getAccountByUserName(userName, false)
|
||||
}
|
||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
|
||||
} yield {
|
||||
@@ -320,7 +248,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
||||
user = ApiUser(issueUser),
|
||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||
.map(ApiLabel(_, RepositoryName(repository))),
|
||||
assignees = assignees.map(ApiUser.apply),
|
||||
assignee = assignee.map(ApiUser.apply),
|
||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
package gitbucket.core.controller.api
|
||||
import java.io.File
|
||||
import java.io.{ByteArrayInputStream, File}
|
||||
|
||||
import gitbucket.core.api._
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
@@ -7,11 +7,12 @@ import gitbucket.core.service.{AccountService, ReleaseService}
|
||||
import gitbucket.core.util.Directory.getReleaseFilesDir
|
||||
import gitbucket.core.util.{FileUtil, ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.SyntaxSugars.defining
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.scalatra.NoContent
|
||||
import org.scalatra.{Created, NoContent}
|
||||
|
||||
trait ApiReleaseControllerBase extends ControllerBase {
|
||||
self: AccountService & ReleaseService & ReferrerAuthenticator & WritableUsersAuthenticator =>
|
||||
self: AccountService with ReleaseService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||
|
||||
/**
|
||||
* i. List releases for a repository
|
||||
@@ -86,7 +87,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
||||
/**
|
||||
* vi. 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 =>
|
||||
(for {
|
||||
@@ -103,7 +104,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
||||
/**
|
||||
* vii. 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 =>
|
||||
val tag = params("tag")
|
||||
@@ -123,32 +124,34 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
||||
val name = params("name")
|
||||
val tag = params("tag")
|
||||
getRelease(repository.owner, repository.name, tag)
|
||||
.map { release =>
|
||||
val fileId = FileUtil.generateFileId
|
||||
val buf = new Array[Byte](request.inputStream.available())
|
||||
request.inputStream.read(buf)
|
||||
FileUtils.writeByteArrayToFile(
|
||||
new File(
|
||||
getReleaseFilesDir(repository.owner, repository.name),
|
||||
FileUtil.checkFilename(tag + "/" + fileId)
|
||||
),
|
||||
buf
|
||||
)
|
||||
createReleaseAsset(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
tag,
|
||||
fileId,
|
||||
name,
|
||||
request.contentLength.getOrElse(0),
|
||||
context.loginAccount.get
|
||||
)
|
||||
getReleaseAsset(repository.owner, repository.name, tag, fileId)
|
||||
.map { asset =>
|
||||
JsonFormat(ApiReleaseAsset(asset, RepositoryName(repository)))
|
||||
}
|
||||
.getOrElse {
|
||||
ApiError("Unknown error")
|
||||
.map {
|
||||
release =>
|
||||
defining(FileUtil.generateFileId) { fileId =>
|
||||
val buf = new Array[Byte](request.inputStream.available())
|
||||
request.inputStream.read(buf)
|
||||
FileUtils.writeByteArrayToFile(
|
||||
new File(
|
||||
getReleaseFilesDir(repository.owner, repository.name),
|
||||
FileUtil.checkFilename(tag + "/" + fileId)
|
||||
),
|
||||
buf
|
||||
)
|
||||
createReleaseAsset(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
tag,
|
||||
fileId,
|
||||
name,
|
||||
request.contentLength.getOrElse(0),
|
||||
context.loginAccount.get
|
||||
)
|
||||
getReleaseAsset(repository.owner, repository.name, tag, fileId)
|
||||
.map { asset =>
|
||||
JsonFormat(ApiReleaseAsset(asset, RepositoryName(repository)))
|
||||
}
|
||||
.getOrElse {
|
||||
ApiError("Unknown error")
|
||||
}
|
||||
}
|
||||
}
|
||||
.getOrElse(NotFound())
|
||||
@@ -175,7 +178,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
||||
*/
|
||||
|
||||
/*
|
||||
* xii. Delete a release asset
|
||||
* https://developer.github.com/v3/repos/releases/#edit-a-release-asset
|
||||
*/
|
||||
* xii. Delete a release asset
|
||||
* https://developer.github.com/v3/repos/releases/#edit-a-release-asset
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -1,29 +1,38 @@
|
||||
package gitbucket.core.controller.api
|
||||
import gitbucket.core.api.*
|
||||
import gitbucket.core.api._
|
||||
import gitbucket.core.controller.ControllerBase
|
||||
import gitbucket.core.service.{AccountService, ProtectedBranchService, RepositoryService}
|
||||
import gitbucket.core.util.*
|
||||
import gitbucket.core.util.Directory.*
|
||||
import gitbucket.core.util.Implicits.*
|
||||
import gitbucket.core.util.JGitUtil.{getBranchesNoMergeInfo, processTree}
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.JGitUtil.getBranches
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.scalatra.NoContent
|
||||
|
||||
import scala.util.Using
|
||||
|
||||
trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
||||
self: RepositoryService & AccountService & OwnerAuthenticator & UsersAuthenticator & GroupManagerAuthenticator &
|
||||
ProtectedBranchService & ReferrerAuthenticator & ReadableUsersAuthenticator & WritableUsersAuthenticator =>
|
||||
self: RepositoryService
|
||||
with AccountService
|
||||
with OwnerAuthenticator
|
||||
with UsersAuthenticator
|
||||
with GroupManagerAuthenticator
|
||||
with ProtectedBranchService
|
||||
with ReferrerAuthenticator
|
||||
with ReadableUsersAuthenticator
|
||||
with WritableUsersAuthenticator =>
|
||||
|
||||
/**
|
||||
* 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 =>
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
JsonFormat(
|
||||
JGitUtil
|
||||
.getBranchesNoMergeInfo(git)
|
||||
.getBranches(
|
||||
git = git,
|
||||
defaultBranch = repository.repository.defaultBranch,
|
||||
origin = repository.repository.originUserName.isEmpty
|
||||
)
|
||||
.map { br =>
|
||||
ApiBranchForList(br.name, ApiBranchCommit(br.commitId))
|
||||
}
|
||||
@@ -32,227 +41,171 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/**
|
||||
* ii. Get a branch
|
||||
* https://docs.github.com/en/rest/reference/repos#get-a-branch
|
||||
* ii. Get branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-branch
|
||||
*/
|
||||
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
(for {
|
||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||
br <- getBranchesNoMergeInfo(git).find(_.name == branch)
|
||||
} yield {
|
||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||
JsonFormat(
|
||||
ApiBranch(branch, ApiBranchCommit(br.commitId), ApiBranchProtectionResponse(protection))(
|
||||
RepositoryName(repository)
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||
git =>
|
||||
(for {
|
||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||
br <- getBranches(
|
||||
git,
|
||||
repository.repository.defaultBranch,
|
||||
repository.repository.originUserName.isEmpty
|
||||
).find(_.name == branch)
|
||||
} yield {
|
||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||
JsonFormat(
|
||||
ApiBranch(branch, ApiBranchCommit(br.commitId), ApiBranchProtection(protection))(RepositoryName(repository))
|
||||
)
|
||||
)
|
||||
}) getOrElse NotFound()
|
||||
}) getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
/*
|
||||
* 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(
|
||||
ApiBranchProtectionResponse(protection)
|
||||
)
|
||||
} else { NotFound() }
|
||||
})
|
||||
|
||||
/*
|
||||
* 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
|
||||
* https://docs.github.com/en/rest/reference/repos#delete-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
|
||||
* v. Remove branch protection
|
||||
* https://developer.github.com/v3/repos/branches/#remove-branch-protection
|
||||
*/
|
||||
|
||||
/*
|
||||
* vii. Set admin branch protection
|
||||
* https://docs.github.com/en/rest/reference/repos#set-admin-branch-protection
|
||||
* vi. Get required status checks of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* viii. Delete admin branch protection
|
||||
* https://docs.github.com/en/rest/reference/repos#delete-admin-branch-protection
|
||||
* vii. Update required status checks of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* ix. Get pull request review protection
|
||||
* https://docs.github.com/en/rest/reference/repos#get-pull-request-review-protection
|
||||
* viii. Remove required status checks of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* x. Update pull request review protection
|
||||
* https://docs.github.com/en/rest/reference/repos#update-pull-request-review-protection
|
||||
* ix. List required status checks contexts of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xi. Delete pull request review protection
|
||||
* https://docs.github.com/en/rest/reference/repos#delete-pull-request-review-protection
|
||||
* x. Replace required status checks contexts of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xii. Get commit signature protection
|
||||
* https://docs.github.com/en/rest/reference/repos#get-commit-signature-protection
|
||||
* xi. Add required status checks contexts of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xiii. Create commit signature protection
|
||||
* https://docs.github.com/en/rest/reference/repos#create-commit-signature-protection
|
||||
* xii. Remove required status checks contexts of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xiv. Delete commit signature protection
|
||||
* https://docs.github.com/en/rest/reference/repos#delete-commit-signature-protection
|
||||
* xiii. Get pull request review enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xv. Get status checks protection
|
||||
* https://docs.github.com/en/rest/reference/repos#get-status-checks-protection
|
||||
*/
|
||||
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(
|
||||
ApiBranchProtectionResponse(protection).required_status_checks
|
||||
)
|
||||
} else { NotFound() }
|
||||
})
|
||||
|
||||
/*
|
||||
* xvi. Update status check protection
|
||||
* https://docs.github.com/en/rest/reference/repos#update-status-check-protection
|
||||
* xiv. Update pull request review enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xvii. Remove status check protection
|
||||
* https://docs.github.com/en/rest/reference/repos#remove-status-check-protection
|
||||
* xv. Remove pull request review enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xviii. Get all status check contexts
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-all-status-check-contexts
|
||||
*/
|
||||
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
|
||||
* xvi. Get required signatures of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-required-signatures-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xx. Set status check contexts
|
||||
* https://docs.github.com/en/rest/reference/repos#set-status-check-contexts
|
||||
* xvii. Add required signatures of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#add-required-signatures-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxi. Remove status check contexts
|
||||
* https://docs.github.com/en/rest/reference/repos#remove-status-check-contexts
|
||||
* xviii. Remove required signatures of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-required-signatures-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxii. Get access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#get-access-restrictions
|
||||
* xix. Get admin enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxiii. Delete access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#delete-access-restrictions
|
||||
* xx. Add admin enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxiv. Get apps with access to the protected branch
|
||||
* https://docs.github.com/en/rest/reference/repos#get-apps-with-access-to-the-protected-branch
|
||||
* xxi. Remove admin enforcement of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxv. Add app access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#add-app-access-restrictions
|
||||
* xxii. Get restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxvi. Set app access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#set-app-access-restrictions
|
||||
* xxiii. Remove restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxvii. Remove app access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#remove-app-access-restrictions
|
||||
* xxiv. List team restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxviii. Get teams with access to the protected branch
|
||||
* https://docs.github.com/en/rest/reference/repos#get-teams-with-access-to-the-protected-branch
|
||||
* xxv. Replace team restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxix. Add team access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#add-team-access-restrictions
|
||||
* xxvi. Add team restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxx. Set team access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#set-team-access-restrictions
|
||||
* xxvii. Remove team restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxxi. Remove team access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#remove-team-access-restrictions
|
||||
* xxviii. List user restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxxii. Get users with access to the protected branch
|
||||
* https://docs.github.com/en/rest/reference/repos#get-users-with-access-to-the-protected-branch
|
||||
* xxix. Replace user restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxxiii. Add user access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#add-user-access-restrictions
|
||||
* xxx. Add user restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxxiv. Set user access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#set-user-access-restrictions
|
||||
*/
|
||||
|
||||
/*
|
||||
* xxxv. Remove user access restrictions
|
||||
* https://docs.github.com/en/rest/reference/repos#remove-user-access-restrictions
|
||||
* xxxi. Remove user restrictions of protected branch
|
||||
* https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch
|
||||
*/
|
||||
|
||||
/**
|
||||
@@ -260,30 +213,31 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
||||
* https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection
|
||||
*/
|
||||
patch("/api/v3/repos/:owner/:repository/branches/*")(ownerOnly { repository =>
|
||||
import gitbucket.core.api.*
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||
(for {
|
||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||
protection <- extractFromJsonBody[ApiBranchProtectionRequest.EnablingAndDisabling].map(_.protection)
|
||||
br <- getBranchesNoMergeInfo(git).find(_.name == branch)
|
||||
} yield {
|
||||
if (protection.enabled) {
|
||||
enableBranchProtection(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
branch,
|
||||
protection.enforce_admins.getOrElse(false),
|
||||
protection.required_status_checks.isDefined,
|
||||
protection.required_status_checks.map(_.contexts).getOrElse(Nil),
|
||||
protection.restrictions.isDefined,
|
||||
protection.restrictions.map(_.users).getOrElse(Nil)
|
||||
)
|
||||
} else {
|
||||
disableBranchProtection(repository.owner, repository.name, branch)
|
||||
}
|
||||
val response = ApiBranchProtectionResponse(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||
JsonFormat(ApiBranch(branch, ApiBranchCommit(br.commitId), response)(RepositoryName(repository)))
|
||||
}) getOrElse NotFound()
|
||||
import gitbucket.core.api._
|
||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||
git =>
|
||||
(for {
|
||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
|
||||
br <- getBranches(
|
||||
git,
|
||||
repository.repository.defaultBranch,
|
||||
repository.repository.originUserName.isEmpty
|
||||
).find(_.name == branch)
|
||||
} yield {
|
||||
if (protection.enabled) {
|
||||
enableBranchProtection(
|
||||
repository.owner,
|
||||
repository.name,
|
||||
branch,
|
||||
protection.status.enforcement_level == ApiBranchProtection.Everyone,
|
||||
protection.status.contexts
|
||||
)
|
||||
} else {
|
||||
disableBranchProtection(repository.owner, repository.name, branch)
|
||||
}
|
||||
JsonFormat(ApiBranch(branch, ApiBranchCommit(br.commitId), protection)(RepositoryName(repository)))
|
||||
}) getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
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.service.{AccountService, RepositoryService}
|
||||
import gitbucket.core.util.Implicits._
|
||||
@@ -7,11 +7,11 @@ import gitbucket.core.util.{OwnerAuthenticator, ReferrerAuthenticator}
|
||||
import org.scalatra.NoContent
|
||||
|
||||
trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
||||
self: RepositoryService & AccountService & ReferrerAuthenticator & OwnerAuthenticator =>
|
||||
self: RepositoryService with AccountService with ReferrerAuthenticator with OwnerAuthenticator =>
|
||||
|
||||
/*
|
||||
* i. List repository collaborators
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#list-repository-collaborators
|
||||
* i. List collaborators
|
||||
* https://developer.github.com/v3/repos/collaborators/#list-collaborators
|
||||
*/
|
||||
get("/api/v3/repos/:owner/:repository/collaborators")(referrersOnly { repository =>
|
||||
// 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))
|
||||
)
|
||||
})
|
||||
|
||||
/*
|
||||
* 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
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-repository-permissions-for-a-user
|
||||
* iii. Review a user's permission level
|
||||
* 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
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#add-a-repository-collaborator
|
||||
* iv. Add user as a collaborator
|
||||
* https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
|
||||
* requested #1586
|
||||
*/
|
||||
put("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||
@@ -65,8 +44,8 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
||||
})
|
||||
|
||||
/*
|
||||
* v. Remove a repository collaborator
|
||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-a-repository-collaborator
|
||||
* v. Remove user as a collaborator
|
||||
* https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator
|
||||
* requested #1586
|
||||
*/
|
||||
delete("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user