mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-08 23:27:43 +02:00
Compare commits
258 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
41d13db5d4 | ||
|
|
c63e20ce7d | ||
|
|
736fdafea4 | ||
|
|
1dfe76e21c | ||
|
|
e7ddfc7ebb | ||
|
|
66be84289d | ||
|
|
2a3c8e0712 | ||
|
|
d3a29b3ecb | ||
|
|
7a50a15748 | ||
|
|
9a1b55b992 | ||
|
|
828b798c0e | ||
|
|
8d8845536d | ||
|
|
f20497e769 | ||
|
|
6053d9826e | ||
|
|
85263474a7 | ||
|
|
c02a722799 | ||
|
|
ce4faceccc | ||
|
|
04c8f8b864 | ||
|
|
1b32e13113 | ||
|
|
401728d47f | ||
|
|
31ace89f43 | ||
|
|
995cb86e90 | ||
|
|
e27623ca29 | ||
|
|
ea4da561c5 | ||
|
|
2e8f3efafd | ||
|
|
f25cf5781c | ||
|
|
d97f7c6025 | ||
|
|
e91d903650 | ||
|
|
4f93f06de5 | ||
|
|
08ed3c4171 | ||
|
|
5193d82980 | ||
|
|
eab82bf1be | ||
|
|
311d758910 | ||
|
|
097a2d32b8 | ||
|
|
a34766ccfd | ||
|
|
147eef9ee5 | ||
|
|
49118662b2 | ||
|
|
5989f2e2cb | ||
|
|
127f034bba | ||
|
|
e1e00c4b94 | ||
|
|
eb64cdd9cd | ||
|
|
1bfa8dffb8 | ||
|
|
33361b8015 | ||
|
|
b5ee074075 | ||
|
|
cbddc34bfa | ||
|
|
61504ae9e3 | ||
|
|
3049f6010c | ||
|
|
d4e01d631f | ||
|
|
a46aa2c61c | ||
|
|
ad147e8dd5 | ||
|
|
3555519392 | ||
|
|
f6a5def638 | ||
|
|
0590cb7048 | ||
|
|
b35d0792aa | ||
|
|
0d20bc0173 | ||
|
|
851141c2f4 | ||
|
|
31a104a697 | ||
|
|
bfc44cff98 | ||
|
|
0da781c33d | ||
|
|
8dbcbb5485 | ||
|
|
7544f64c65 | ||
|
|
73d05aefad | ||
|
|
4d70b056ad | ||
|
|
b81ce41d51 | ||
|
|
a143683d7f | ||
|
|
5ba38057dc | ||
|
|
07eb2bc41e | ||
|
|
5e4d041295 | ||
|
|
4d7fc061a4 | ||
|
|
8db98d7b16 | ||
|
|
a6063c8aa9 | ||
|
|
2cc1336e82 | ||
|
|
308bda2050 | ||
|
|
36989c38d4 | ||
|
|
29357ae170 | ||
|
|
36643bcdd0 | ||
|
|
72e40a0b12 | ||
|
|
2194ff7625 | ||
|
|
b247864bfe | ||
|
|
b1c3ae4974 | ||
|
|
81c0e2037f | ||
|
|
6224ec2a7b | ||
|
|
9ff4507fe2 | ||
|
|
67667dbff1 | ||
|
|
1a4961c3e1 | ||
|
|
561220237f | ||
|
|
f45b85aa71 | ||
|
|
83b3a7983e | ||
|
|
63d4c5054e | ||
|
|
c8f6017be9 | ||
|
|
f9fcb54861 | ||
|
|
3534b7172d | ||
|
|
42a7f974e9 | ||
|
|
b8e02d995a | ||
|
|
e0d038aa92 | ||
|
|
3d01df2bdc | ||
|
|
6f08f1fd23 | ||
|
|
3dd366b394 | ||
|
|
8cf4528959 | ||
|
|
5d77bc5d98 | ||
|
|
572c9ef558 | ||
|
|
7c736c526e | ||
|
|
696d354f3c | ||
|
|
501cbf54ab | ||
|
|
c15d69d566 | ||
|
|
83eb933230 | ||
|
|
43bec9b0df | ||
|
|
279305c202 | ||
|
|
ecbb86c006 | ||
|
|
921fb17ef0 | ||
|
|
0362de7d35 | ||
|
|
cf0d8ea2d0 | ||
|
|
0e9026447d | ||
|
|
cf4d9cb03c | ||
|
|
2a1edeaca3 | ||
|
|
eebabf9b08 | ||
|
|
d882fcad12 | ||
|
|
f976290282 | ||
|
|
f3f9d5dae2 | ||
|
|
71dffd1089 | ||
|
|
f411e98c9a | ||
|
|
1baa489bc7 | ||
|
|
f996b0fc4a | ||
|
|
eb6ba1c800 | ||
|
|
8fac1baa3c | ||
|
|
2d327543b9 | ||
|
|
8a080efe9d | ||
|
|
aaaf61e29e | ||
|
|
1294323df5 | ||
|
|
9ef4e75746 | ||
|
|
ded4ab702d | ||
|
|
f893d045c7 | ||
|
|
ef2e3adcfb | ||
|
|
a1908c5398 | ||
|
|
ec4f0d6531 | ||
|
|
9ef366237c | ||
|
|
9197ad2600 | ||
|
|
2cb7ecd851 | ||
|
|
7d1ad4ce66 | ||
|
|
c274acc8f4 | ||
|
|
7a0d48dd7a | ||
|
|
9c6f9048e1 | ||
|
|
4ff4acfd7e | ||
|
|
d8e9f07721 | ||
|
|
662c5638dd | ||
|
|
02b830d034 | ||
|
|
3734529e5c | ||
|
|
715ec24389 | ||
|
|
5615b23548 | ||
|
|
ca2eeb48cf | ||
|
|
b063c0a80c | ||
|
|
ee8b5692bd | ||
|
|
7a749dca67 | ||
|
|
0378f26ee6 | ||
|
|
4d281273c1 | ||
|
|
e23e11e1a8 | ||
|
|
772835dd22 | ||
|
|
bbf2e57548 | ||
|
|
aecda130b6 | ||
|
|
1d48030e7c | ||
|
|
929ba2fa19 | ||
|
|
6fefa947ca | ||
|
|
072cd2e846 | ||
|
|
5d20cd0365 | ||
|
|
03ec055f66 | ||
|
|
4b6a5e5d49 | ||
|
|
6d21e38159 | ||
|
|
a47c8249bf | ||
|
|
59d7a672b3 | ||
|
|
564e95d36e | ||
|
|
9aee99be74 | ||
|
|
aecd8b503d | ||
|
|
fa65eeea35 | ||
|
|
fe43584c3d | ||
|
|
c255b13dfc | ||
|
|
917b204e5b | ||
|
|
6225fd79fc | ||
|
|
cbec567ef4 | ||
|
|
84b62242d3 | ||
|
|
f17f74c30b | ||
|
|
63b04d5a27 | ||
|
|
f02073a24c | ||
|
|
cb87d126de | ||
|
|
941f8002e5 | ||
|
|
90f4f5cd89 | ||
|
|
a6e7761141 | ||
|
|
eb053a66d7 | ||
|
|
5257c83563 | ||
|
|
04bc92001f | ||
|
|
d939082e1f | ||
|
|
a943a5985d | ||
|
|
9e19821256 | ||
|
|
455183a13e | ||
|
|
c241c08904 | ||
|
|
08389cb1a0 | ||
|
|
94f9d42fc4 | ||
|
|
f35ecce3c7 | ||
|
|
2837bb40b0 | ||
|
|
54331f976d | ||
|
|
b975e74de3 | ||
|
|
c45ab34f43 | ||
|
|
4ee442f697 | ||
|
|
3c25d322f2 | ||
|
|
265c6b3e0f | ||
|
|
fad4503aec | ||
|
|
d8f70bfde3 | ||
|
|
d7dfb44efc | ||
|
|
409330a9fb | ||
|
|
0fd7e07831 | ||
|
|
91bd26d2a9 | ||
|
|
e5c4cf3298 | ||
|
|
c874d3fd84 | ||
|
|
c06f95256e | ||
|
|
2f1e05833e | ||
|
|
719cad00d6 | ||
|
|
b372c71fbf | ||
|
|
6b252a7018 | ||
|
|
6575258b6c | ||
|
|
d33280f9af | ||
|
|
863bb80ad1 | ||
|
|
e4266f31a6 | ||
|
|
0405fccb69 | ||
|
|
9a41adcec8 | ||
|
|
1d54920165 | ||
|
|
7ace37cd07 | ||
|
|
eb6398654d | ||
|
|
10a4c3e2a4 | ||
|
|
d494014011 | ||
|
|
91bf562b91 | ||
|
|
ec3961555f | ||
|
|
33b46869b6 | ||
|
|
88db21ef07 | ||
|
|
d53948f4a9 | ||
|
|
f97992a776 | ||
|
|
f9d99703cb | ||
|
|
b015cdde74 | ||
|
|
92b35bd458 | ||
|
|
3c8026f135 | ||
|
|
6a3f51a784 | ||
|
|
160c4a8a72 | ||
|
|
c4ff760bda | ||
|
|
aaed8f595a | ||
|
|
3c0a2e8385 | ||
|
|
0eef0f9aa5 | ||
|
|
169e2f16fb | ||
|
|
3800391a0e | ||
|
|
1f564808d5 | ||
|
|
433639dd04 | ||
|
|
f1e4116672 | ||
|
|
6cf00c5c66 | ||
|
|
71248cd9b7 | ||
|
|
841e6d110c | ||
|
|
f7defffeab | ||
|
|
13e6f5f6cf | ||
|
|
130cbf0b24 | ||
|
|
642d85b6bf | ||
|
|
8fe7f85e1a | ||
|
|
d1fb794783 |
@@ -5,6 +5,10 @@ trim_trailing_whitespace = true
|
|||||||
insert_final_newline = true
|
insert_final_newline = true
|
||||||
indent_style = space
|
indent_style = space
|
||||||
indent_size = 2
|
indent_size = 2
|
||||||
|
end_of_line = lf
|
||||||
|
|
||||||
|
[*.md]
|
||||||
|
trim_trailing_whitespace = false
|
||||||
|
|
||||||
[*.java]
|
[*.java]
|
||||||
trim_trailing_whitespace = true
|
trim_trailing_whitespace = true
|
||||||
|
|||||||
6
.github/ISSUE_TEMPLATE.md
vendored
6
.github/ISSUE_TEMPLATE.md
vendored
@@ -1,8 +1,8 @@
|
|||||||
### Before submitting an issue to GitBucket I have first:
|
### Before submitting an issue to GitBucket I have first:
|
||||||
|
|
||||||
- [] read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
- [ ] read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
||||||
- [] searched for similar already existing issue
|
- [ ] searched for similar already existing issue
|
||||||
- [] read the documentation and [wiki](https://github.com/gitbucket/gitbucket/wiki)
|
- [ ] 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)*
|
*(if you have performed all the above, remove the paragraph and continue describing the issue with template below)*
|
||||||
|
|
||||||
|
|||||||
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
12
.github/PULL_REQUEST_TEMPLATE.md
vendored
@@ -1,8 +1,8 @@
|
|||||||
### Before submitting a pull-request to GitBucket I have first:
|
### Before submitting a pull-request to GitBucket I have first:
|
||||||
|
|
||||||
- [] read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
- [ ] read the [contribution guidelines](https://github.com/gitbucket/gitbucket/blob/master/.github/CONTRIBUTING.md)
|
||||||
- [] rebased my branch over master
|
- [ ] rebased my branch over master
|
||||||
- [] verified that project is compiling
|
- [ ] verified that project is compiling
|
||||||
- [] verified that tests are passing
|
- [ ] verified that tests are passing
|
||||||
- [] squashed my commits as appropriate *(keep several commits if it is relevant to understand the PR)*
|
- [ ] squashed my commits as appropriate *(keep several commits if it is relevant to understand the PR)*
|
||||||
- [] [marked as closed using commit message](https://help.github.com/articles/closing-issues-via-commit-messages/) all issue ID that this PR should correct
|
- [ ] [marked as closed using commit message](https://help.github.com/articles/closing-issues-via-commit-messages/) all issue ID that this PR should correct
|
||||||
|
|||||||
6
.github/dependabot.yml
vendored
Normal file
6
.github/dependabot.yml
vendored
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
version: 2
|
||||||
|
updates:
|
||||||
|
- package-ecosystem: "github-actions"
|
||||||
|
directory: "/"
|
||||||
|
schedule:
|
||||||
|
interval: "weekly"
|
||||||
35
.github/workflows/build.yml
vendored
Normal file
35
.github/workflows/build.yml
vendored
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
name: build
|
||||||
|
|
||||||
|
on: [push, pull_request]
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
java: [8, 11]
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- name: Cache
|
||||||
|
uses: actions/cache@v2
|
||||||
|
env:
|
||||||
|
cache-name: cache-sbt-libs
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.ivy2/cache
|
||||||
|
~/.sbt
|
||||||
|
~/.cache/coursier/v1
|
||||||
|
key: build-${{ env.cache-name }}-${{ hashFiles('build.sbt') }}
|
||||||
|
- name: Set up JDK
|
||||||
|
uses: actions/setup-java@v1
|
||||||
|
with:
|
||||||
|
java-version: ${{ matrix.java }}
|
||||||
|
- name: Run tests
|
||||||
|
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
||||||
|
- name: Build executable
|
||||||
|
run: sbt executable
|
||||||
|
- name: Upload artifacts
|
||||||
|
uses: actions/upload-artifact@v2
|
||||||
|
with:
|
||||||
|
name: gitbucket-java${{ matrix.java }}-${{ github.sha }}
|
||||||
|
path: ./target/executable/gitbucket.*
|
||||||
10
.gitignore
vendored
10
.gitignore
vendored
@@ -10,6 +10,7 @@ lib_managed/
|
|||||||
src_managed/
|
src_managed/
|
||||||
project/boot/
|
project/boot/
|
||||||
project/plugins/project/
|
project/plugins/project/
|
||||||
|
.bsp/
|
||||||
|
|
||||||
# Scala-IDE specific
|
# Scala-IDE specific
|
||||||
.scala_dependencies
|
.scala_dependencies
|
||||||
@@ -24,3 +25,12 @@ project/plugins/project/
|
|||||||
.idea/
|
.idea/
|
||||||
.idea_modules/
|
.idea_modules/
|
||||||
*.iml
|
*.iml
|
||||||
|
|
||||||
|
# Metals specific
|
||||||
|
.metals
|
||||||
|
.bloop
|
||||||
|
**/metals.sbt
|
||||||
|
|
||||||
|
# Visual Studio Code specific
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
version = "1.5.1"
|
||||||
project.git = true
|
project.git = true
|
||||||
|
|
||||||
maxColumn = 120
|
maxColumn = 120
|
||||||
|
|||||||
19
.travis.yml
19
.travis.yml
@@ -1,19 +0,0 @@
|
|||||||
language: scala
|
|
||||||
sudo: true
|
|
||||||
jdk:
|
|
||||||
- oraclejdk8
|
|
||||||
- oraclejdk11
|
|
||||||
- openjdk8
|
|
||||||
- openjdk11
|
|
||||||
script:
|
|
||||||
- sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
|
||||||
before_script:
|
|
||||||
- sudo /etc/init.d/mysql stop
|
|
||||||
- sudo /etc/init.d/postgresql stop
|
|
||||||
- sudo chmod +x /usr/local/bin/sbt
|
|
||||||
cache:
|
|
||||||
directories:
|
|
||||||
- $HOME/.ivy2/cache
|
|
||||||
- $HOME/.sbt/boot
|
|
||||||
- $HOME/.sbt/launchers
|
|
||||||
- $HOME/.coursier
|
|
||||||
54
CHANGELOG.md
54
CHANGELOG.md
@@ -1,20 +1,64 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to the project will be documented in this file.
|
All changes to the project will be documented in this file.
|
||||||
|
|
||||||
### 4.31.2 - 7 Apr 2019
|
### 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
|
||||||
|
- Bump to Scala 2.13.0 and Scalatra 2.7.0
|
||||||
|
- Draft pull request
|
||||||
|
- Drop network installation of plugins
|
||||||
|
- Compare view works for commit id
|
||||||
|
- Apply default priority to pull requests
|
||||||
|
- Focus title after clicking issue / pull request edit button
|
||||||
|
|
||||||
|
## 4.31.2 - 7 Apr 2019
|
||||||
- Bug and security fix
|
- Bug and security fix
|
||||||
|
|
||||||
### 4.31.1 - 17 Mar 2019
|
## 4.31.1 - 17 Mar 2019
|
||||||
- Bug fix
|
- Bug fix
|
||||||
|
|
||||||
### 4.31.0 - 17 Mar 2019
|
## 4.31.0 - 17 Mar 2019
|
||||||
- Docker support in CI plugin
|
- Docker support in CI plugin
|
||||||
- Verify GPG key signed commit
|
- Verify GPG key signed commit
|
||||||
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
||||||
- OGP (Open Graph protocol) support
|
- OGP (Open Graph protocol) support
|
||||||
- Username completion with avatars
|
- Username completion with avatars
|
||||||
|
|
||||||
### 4.30.1 - 22 Dec 2018
|
## 4.30.1 - 22 Dec 2018
|
||||||
- Bug fix for several WebHooks and Web API
|
- Bug fix for several WebHooks and Web API
|
||||||
|
|
||||||
## 4.30.0 - 15 Dec 2018
|
## 4.30.0 - 15 Dec 2018
|
||||||
@@ -101,7 +145,7 @@ All changes to the project will be documented in this file.
|
|||||||
- Submodule links to web page
|
- Submodule links to web page
|
||||||
- Clarify close/reopen button
|
- Clarify close/reopen button
|
||||||
|
|
||||||
# 4.20.0 - 23 Dec 2017
|
## 4.20.0 - 23 Dec 2017
|
||||||
- Squash and rebase merge strategy for pull requests
|
- Squash and rebase merge strategy for pull requests
|
||||||
- Quick pull request creation
|
- Quick pull request creation
|
||||||
- Download patch from the diff view
|
- Download patch from the diff view
|
||||||
|
|||||||
43
README.md
43
README.md
@@ -1,4 +1,4 @@
|
|||||||
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://travis-ci.org/gitbucket/gitbucket) [](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/gitbucket_2.12) [](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:
|
GitBucket is a Git web platform powered by Scala offering:
|
||||||
@@ -22,7 +22,7 @@ The current version of GitBucket provides many features such as:
|
|||||||
- Account and group management with LDAP integration
|
- Account and group management with LDAP integration
|
||||||
- a Plug-in system
|
- a Plug-in system
|
||||||
|
|
||||||
If you want to try the development version of GitBucket, see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/how_to_run.md).
|
If you want to try the development version of GitBucket, see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/readme.md).
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
--------
|
--------
|
||||||
@@ -31,19 +31,6 @@ GitBucket requires **Java8**. You have to install it, if it is not already insta
|
|||||||
1. Download the latest **gitbucket.war** from [the releases page](https://github.com/gitbucket/gitbucket/releases) and run it by `java -jar gitbucket.war`.
|
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**.
|
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
|
||||||
|
|
||||||
You can specify following options:
|
|
||||||
|
|
||||||
- `--port=[NUMBER]`
|
|
||||||
- `--prefix=[CONTEXTPATH]`
|
|
||||||
- `--host=[HOSTNAME]`
|
|
||||||
- `--gitbucket.home=[DATA_DIR]`
|
|
||||||
- `--temp_dir=[TEMP_DIR]`
|
|
||||||
- `--max_file_size=[MAX_FILE_SIZE]`
|
|
||||||
|
|
||||||
`TEMP_DIR` is used as the [temporary directory for the jetty application context](https://www.eclipse.org/jetty/documentation/9.3.x/ref-temporary-directories.html). This is the directory into which the `gitbucket.war` file is unpacked, the source files are compiled, etc. If given this parameter **must** match the path of an existing directory or the application will quit reporting an error; if not given the path used will be a `tmp` directory inside the gitbucket home.
|
|
||||||
|
|
||||||
`MAX_FILE_SIZE` is the max file size for upload files.
|
|
||||||
|
|
||||||
You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc)
|
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).
|
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).
|
||||||
@@ -68,19 +55,23 @@ Support
|
|||||||
- If you can't find same question and report, send it to [gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
- If you can't find same question and report, send it to [gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
||||||
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
||||||
|
|
||||||
What's New in 4.31.x
|
What's New in 4.35.x
|
||||||
-------------
|
-------------
|
||||||
### 4.31.2 - 7 Apr 2019
|
### 4.35.1 - 29 Dec 2020
|
||||||
- Bug and security fix
|
|
||||||
|
|
||||||
### 4.31.1 - 17 Mar 2019
|
- Fix database migration issue which happens if webhook is configured
|
||||||
- Bug fix
|
- Call push webhook when pull request is merged
|
||||||
|
- Show commit status at commits tab of pull request
|
||||||
|
|
||||||
### 4.31.0 - 17 Mar 2019
|
### 4.35.0 - 25 Dec 2020
|
||||||
- Docker support in CI plugin
|
|
||||||
- Verify GPG key signed commit
|
- Editor and source viewer color theme
|
||||||
- OAuth2 Token (sent as a parameter) authentication support and new APIs in Web API
|
- Auto completion for issues and pull requests
|
||||||
- OGP (Open Graph protocol) support
|
- Upload image from clipboard
|
||||||
- Username completion with avatars
|
- Close multiple issues by commit comment
|
||||||
|
- Create pull request from online editor
|
||||||
|
- Milestone overview
|
||||||
|
- Commit status at various places
|
||||||
|
- WebAPI coverage improvements
|
||||||
|
|
||||||
See the [change log](CHANGELOG.md) for all of the updates.
|
See the [change log](CHANGELOG.md) for all of the updates.
|
||||||
|
|||||||
84
build.sbt
84
build.sbt
@@ -3,10 +3,10 @@ import com.typesafe.sbt.pgp.PgpKeys._
|
|||||||
|
|
||||||
val Organization = "io.github.gitbucket"
|
val Organization = "io.github.gitbucket"
|
||||||
val Name = "gitbucket"
|
val Name = "gitbucket"
|
||||||
val GitBucketVersion = "4.31.2"
|
val GitBucketVersion = "4.35.1"
|
||||||
val ScalatraVersion = "2.6.3"
|
val ScalatraVersion = "2.7.1"
|
||||||
val JettyVersion = "9.4.14.v20181114"
|
val JettyVersion = "9.4.32.v20200930"
|
||||||
val JgitVersion = "5.2.0.201812061821-r"
|
val JgitVersion = "5.9.0.202009080501-r"
|
||||||
|
|
||||||
lazy val root = (project in file("."))
|
lazy val root = (project in file("."))
|
||||||
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
||||||
@@ -17,7 +17,7 @@ sourcesInBase := false
|
|||||||
organization := Organization
|
organization := Organization
|
||||||
name := Name
|
name := Name
|
||||||
version := GitBucketVersion
|
version := GitBucketVersion
|
||||||
scalaVersion := "2.12.8"
|
scalaVersion := "2.13.3"
|
||||||
|
|
||||||
scalafmtOnCompile := true
|
scalafmtOnCompile := true
|
||||||
|
|
||||||
@@ -27,9 +27,7 @@ coverageExcludedPackages := ".*\\.html\\..*"
|
|||||||
resolvers ++= Seq(
|
resolvers ++= Seq(
|
||||||
Classpaths.typesafeReleases,
|
Classpaths.typesafeReleases,
|
||||||
Resolver.jcenterRepo,
|
Resolver.jcenterRepo,
|
||||||
"amateras" at "http://amateras.sourceforge.jp/mvn/",
|
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/",
|
|
||||||
"amateras-snapshot" at "http://amateras.sourceforge.jp/mvn-snapshot/"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
@@ -38,46 +36,46 @@ libraryDependencies ++= Seq(
|
|||||||
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
||||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
||||||
"org.scalatra" %% "scalatra-forms" % ScalatraVersion,
|
"org.scalatra" %% "scalatra-forms" % ScalatraVersion,
|
||||||
"org.json4s" %% "json4s-jackson" % "3.5.2",
|
"org.json4s" %% "json4s-jackson" % "3.6.10",
|
||||||
"commons-io" % "commons-io" % "2.6",
|
"commons-io" % "commons-io" % "2.8.0",
|
||||||
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
||||||
"io.github.gitbucket" % "markedj" % "1.0.16",
|
"io.github.gitbucket" % "markedj" % "1.0.16",
|
||||||
"org.apache.commons" % "commons-compress" % "1.18",
|
"org.apache.commons" % "commons-compress" % "1.20",
|
||||||
"org.apache.commons" % "commons-email" % "1.5",
|
"org.apache.commons" % "commons-email" % "1.5",
|
||||||
"org.apache.httpcomponents" % "httpclient" % "4.5.6",
|
"commons-net" % "commons-net" % "3.7",
|
||||||
|
"org.apache.httpcomponents" % "httpclient" % "4.5.12",
|
||||||
"org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
"org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
||||||
"org.apache.tika" % "tika-core" % "1.19.1",
|
"org.apache.tika" % "tika-core" % "1.24.1",
|
||||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.11",
|
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12",
|
||||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
"com.h2database" % "h2" % "1.4.197",
|
"com.h2database" % "h2" % "1.4.199",
|
||||||
"org.mariadb.jdbc" % "mariadb-java-client" % "2.3.0",
|
"org.mariadb.jdbc" % "mariadb-java-client" % "2.7.0",
|
||||||
"org.postgresql" % "postgresql" % "42.2.5",
|
"org.postgresql" % "postgresql" % "42.2.6",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
||||||
"com.zaxxer" % "HikariCP" % "3.2.0",
|
"com.zaxxer" % "HikariCP" % "3.4.5",
|
||||||
"com.typesafe" % "config" % "1.3.3",
|
"com.typesafe" % "config" % "1.4.0",
|
||||||
"com.typesafe.akka" %% "akka-actor" % "2.5.18",
|
|
||||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
||||||
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
||||||
"org.cache2k" % "cache2k-all" % "1.2.0.Final",
|
"org.cache2k" % "cache2k-all" % "1.2.4.Final",
|
||||||
"com.enragedginger" %% "akka-quartz-scheduler" % "1.7.0-akka-2.5.x" exclude ("c3p0", "c3p0") exclude ("com.zaxxer", "HikariCP-java6"),
|
"net.coobird" % "thumbnailator" % "0.4.12",
|
||||||
"net.coobird" % "thumbnailator" % "0.4.8",
|
|
||||||
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
||||||
"com.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
|
"com.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
|
||||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
||||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||||
"junit" % "junit" % "4.12" % "test",
|
"junit" % "junit" % "4.13" % "test",
|
||||||
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
||||||
"org.mockito" % "mockito-core" % "2.23.4" % "test",
|
"org.mockito" % "mockito-core" % "3.3.3" % "test",
|
||||||
"com.dimafeng" %% "testcontainers-scala" % "0.22.0" % "test",
|
"com.dimafeng" %% "testcontainers-scala" % "0.37.0" % "test",
|
||||||
"org.testcontainers" % "mysql" % "1.10.3" % "test",
|
"org.testcontainers" % "mysql" % "1.14.3" % "test",
|
||||||
"org.testcontainers" % "postgresql" % "1.10.3" % "test",
|
"org.testcontainers" % "postgresql" % "1.14.3" % "test",
|
||||||
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
||||||
"is.tagomor.woothee" % "woothee-java" % "1.8.0",
|
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
||||||
"org.ec4j.core" % "ec4j-core" % "0.0.3"
|
"org.ec4j.core" % "ec4j-core" % "0.0.3",
|
||||||
|
"org.kohsuke" % "github-api" % "1.116" % "test"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Compiler settings
|
// Compiler settings
|
||||||
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method", "-Xfuture")
|
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method", "-feature")
|
||||||
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
||||||
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||||
|
|
||||||
@@ -123,6 +121,12 @@ libraryDependencies ++= Seq(
|
|||||||
"org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
|
"org.eclipse.jetty" % "jetty-util" % JettyVersion % "executable"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Run package task before test to generate target/webapp for integration test
|
||||||
|
test in Test := {
|
||||||
|
_root_.sbt.Keys.`package`.value
|
||||||
|
(test in Test).value
|
||||||
|
}
|
||||||
|
|
||||||
val executableKey = TaskKey[File]("executable")
|
val executableKey = TaskKey[File]("executable")
|
||||||
executableKey := {
|
executableKey := {
|
||||||
import java.util.jar.Attributes.{Name => AttrName}
|
import java.util.jar.Attributes.{Name => AttrName}
|
||||||
@@ -165,8 +169,8 @@ executableKey := {
|
|||||||
plugins.foreach { plugin =>
|
plugins.foreach { plugin =>
|
||||||
plugin.trim.split(":") match {
|
plugin.trim.split(":") match {
|
||||||
case Array(pluginId, pluginVersion) =>
|
case Array(pluginId, pluginVersion) =>
|
||||||
val url = "https://plugins.gitbucket-community.org/releases/" +
|
val url = "https://github.com/" +
|
||||||
s"gitbucket-${pluginId}-plugin/gitbucket-${pluginId}-plugin-gitbucket_${version.value}-${pluginVersion}.jar"
|
s"gitbucket/gitbucket-${pluginId}-plugin/releases/download/${pluginVersion}/gitbucket-${pluginId}-plugin-${pluginVersion}.jar"
|
||||||
log info s"Download: ${url}"
|
log info s"Download: ${url}"
|
||||||
IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
IO transfer (new java.net.URL(url).openStream, pluginsDir / url.substring(url.lastIndexOf("/") + 1))
|
||||||
case _ => ()
|
case _ => ()
|
||||||
@@ -258,3 +262,17 @@ licenseOverrides := {
|
|||||||
case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
|
case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
|
||||||
LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
|
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(
|
||||||
|
Set(
|
||||||
|
"gitbucket.core.GitBucketCoreModuleSpec"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ To build war file, run the following command:
|
|||||||
$ sbt package
|
$ sbt package
|
||||||
```
|
```
|
||||||
|
|
||||||
`gitbucket_2.12-x.x.x.war` is generated into `target/scala-2.12`.
|
`gitbucket_2.13-x.x.x.war` is generated into `target/scala-2.13`.
|
||||||
|
|
||||||
To build an executable war file, run
|
To build an executable war file, run
|
||||||
|
|
||||||
@@ -58,4 +58,4 @@ If you don't have docker, you can skip docker tests which require docker as foll
|
|||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ sbt "testOnly * -- -l ExternalDBTest"
|
$ sbt "testOnly * -- -l ExternalDBTest"
|
||||||
```
|
```
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
sbt.version=1.2.6
|
sbt.version=1.4.6
|
||||||
|
|||||||
@@ -1,12 +1,10 @@
|
|||||||
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
||||||
|
|
||||||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.0")
|
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.3.15")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.0")
|
||||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9")
|
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
||||||
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.3")
|
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
||||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
|
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
||||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
||||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.5.1")
|
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
|
||||||
|
|
||||||
addSbtCoursier
|
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0")
|
|
||||||
@@ -4,6 +4,10 @@ import org.eclipse.jetty.server.Handler;
|
|||||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
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.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
@@ -16,13 +20,22 @@ public class JettyLauncher {
|
|||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
|
||||||
String host = null;
|
String host = null;
|
||||||
int port = 8080;
|
String port = null;
|
||||||
InetSocketAddress address = null;
|
InetSocketAddress address = null;
|
||||||
String contextPath = "/";
|
String contextPath = "/";
|
||||||
String tmpDirPath="";
|
String tmpDirPath="";
|
||||||
boolean forceHttps = false;
|
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) {
|
for(String arg: args) {
|
||||||
|
if(arg.equals("--save_sessions")) {
|
||||||
|
saveSessions = true;
|
||||||
|
}
|
||||||
if(arg.startsWith("--") && arg.contains("=")) {
|
if(arg.startsWith("--") && arg.contains("=")) {
|
||||||
String[] dim = arg.split("=");
|
String[] dim = arg.split("=");
|
||||||
if(dim.length >= 2) {
|
if(dim.length >= 2) {
|
||||||
@@ -31,16 +44,10 @@ public class JettyLauncher {
|
|||||||
host = dim[1];
|
host = dim[1];
|
||||||
break;
|
break;
|
||||||
case "--port":
|
case "--port":
|
||||||
port = Integer.parseInt(dim[1]);
|
port = dim[1];
|
||||||
break;
|
break;
|
||||||
case "--prefix":
|
case "--prefix":
|
||||||
contextPath = dim[1];
|
contextPath = dim[1];
|
||||||
if (!contextPath.startsWith("/")) {
|
|
||||||
contextPath = "/" + contextPath;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case "--max_file_size":
|
|
||||||
System.setProperty("gitbucket.maxFileSize", dim[1]);
|
|
||||||
break;
|
break;
|
||||||
case "--gitbucket.home":
|
case "--gitbucket.home":
|
||||||
System.setProperty("gitbucket.home", dim[1]);
|
System.setProperty("gitbucket.home", dim[1]);
|
||||||
@@ -51,18 +58,19 @@ public class JettyLauncher {
|
|||||||
case "--plugin_dir":
|
case "--plugin_dir":
|
||||||
System.setProperty("gitbucket.pluginDir", dim[1]);
|
System.setProperty("gitbucket.pluginDir", dim[1]);
|
||||||
break;
|
break;
|
||||||
case "--validate_password":
|
|
||||||
System.setProperty("gitbucket.validate.password", dim[1]);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (contextPath != null && !contextPath.startsWith("/")) {
|
||||||
|
contextPath = "/" + contextPath;
|
||||||
|
}
|
||||||
|
|
||||||
if(host != null) {
|
if(host != null) {
|
||||||
address = new InetSocketAddress(host, port);
|
address = new InetSocketAddress(host, getPort(port));
|
||||||
} else {
|
} else {
|
||||||
address = new InetSocketAddress(port);
|
address = new InetSocketAddress(getPort(port));
|
||||||
}
|
}
|
||||||
|
|
||||||
Server server = new Server(address);
|
Server server = new Server(address);
|
||||||
@@ -87,8 +95,21 @@ public class JettyLauncher {
|
|||||||
|
|
||||||
WebAppContext context = new WebAppContext();
|
WebAppContext context = new WebAppContext();
|
||||||
|
|
||||||
|
if(saveSessions) {
|
||||||
|
File sessDir = new File(getGitBucketHome(), "sessions");
|
||||||
|
if(!sessDir.exists()){
|
||||||
|
sessDir.mkdirs();
|
||||||
|
}
|
||||||
|
SessionHandler sessions = context.getSessionHandler();
|
||||||
|
SessionCache cache = new DefaultSessionCache(sessions);
|
||||||
|
FileSessionDataStore fsds = new FileSessionDataStore();
|
||||||
|
fsds.setStoreDir(sessDir);
|
||||||
|
cache.setSessionDataStore(fsds);
|
||||||
|
sessions.setSessionCache(cache);
|
||||||
|
}
|
||||||
|
|
||||||
File tmpDir;
|
File tmpDir;
|
||||||
if(tmpDirPath.equals("")){
|
if(tmpDirPath == null || tmpDirPath.equals("")){
|
||||||
tmpDir = new File(getGitBucketHome(), "tmp");
|
tmpDir = new File(getGitBucketHome(), "tmp");
|
||||||
if(!tmpDir.exists()){
|
if(!tmpDir.exists()){
|
||||||
tmpDir.mkdirs();
|
tmpDir.mkdirs();
|
||||||
@@ -111,7 +132,7 @@ public class JettyLauncher {
|
|||||||
ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
|
ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
|
||||||
URL location = domain.getCodeSource().getLocation();
|
URL location = domain.getCodeSource().getLocation();
|
||||||
|
|
||||||
context.setContextPath(contextPath);
|
context.setContextPath(contextPath == null ? "" : contextPath);
|
||||||
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
|
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
|
||||||
context.setServer(server);
|
context.setServer(server);
|
||||||
context.setWar(location.toExternalForm());
|
context.setWar(location.toExternalForm());
|
||||||
@@ -140,6 +161,23 @@ public class JettyLauncher {
|
|||||||
return new File(System.getProperty("user.home"), ".gitbucket");
|
return new File(System.getProperty("user.home"), ".gitbucket");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getEnvironmentVariable(String key){
|
||||||
|
String value = System.getenv(key.toUpperCase().replace('.', '_'));
|
||||||
|
if (value != null && value.length() == 0){
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int getPort(String port){
|
||||||
|
if(port == null) {
|
||||||
|
return 8080;
|
||||||
|
} else {
|
||||||
|
return Integer.parseInt(port);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static Handler addStatisticsHandler(Handler handler) {
|
private static Handler addStatisticsHandler(Handler handler) {
|
||||||
// The graceful shutdown is implemented via the statistics handler.
|
// The graceful shutdown is implemented via the statistics handler.
|
||||||
// See the following: https://bugs.eclipse.org/bugs/show_bug.cgi?id=420142
|
// See the following: https://bugs.eclipse.org/bugs/show_bug.cgi?id=420142
|
||||||
|
|||||||
@@ -1 +1,4 @@
|
|||||||
notifications:1.7.0
|
notifications:1.9.0
|
||||||
|
gist:4.20.0
|
||||||
|
emoji:4.6.0
|
||||||
|
pages:1.9.0
|
||||||
|
|||||||
@@ -60,13 +60,12 @@
|
|||||||
<!-- ACCESS_TOKEN -->
|
<!-- ACCESS_TOKEN -->
|
||||||
<!--================================================================================================-->
|
<!--================================================================================================-->
|
||||||
<createTable tableName="ACCESS_TOKEN">
|
<createTable tableName="ACCESS_TOKEN">
|
||||||
<column name="ACCESS_TOKEN_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
<column name="ACCESS_TOKEN_ID" type="int" nullable="false" autoIncrement="true" unique="true" primaryKeyName="IDX_ACCESS_TOKEN_PK" primaryKey="true" />
|
||||||
<column name="TOKEN_HASH" type="varchar(40)" nullable="false"/>
|
<column name="TOKEN_HASH" type="varchar(40)" nullable="false"/>
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="NOTE" type="text" nullable="false"/>
|
<column name="NOTE" type="text" nullable="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addPrimaryKey constraintName="IDX_ACCESS_TOKEN_PK" tableName="ACCESS_TOKEN" columnNames="ACCESS_TOKEN_ID"/>
|
|
||||||
<addUniqueConstraint constraintName="IDX_ACCESS_TOKEN_TOKEN_HASH" tableName="ACCESS_TOKEN" columnNames="TOKEN_HASH"/>
|
<addUniqueConstraint constraintName="IDX_ACCESS_TOKEN_TOKEN_HASH" tableName="ACCESS_TOKEN" columnNames="TOKEN_HASH"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_ACCESS_TOKEN_FK0" baseTableName="ACCESS_TOKEN" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
<addForeignKeyConstraint constraintName="IDX_ACCESS_TOKEN_FK0" baseTableName="ACCESS_TOKEN" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
|
||||||
@@ -74,7 +73,7 @@
|
|||||||
<!-- ACTIVITY -->
|
<!-- ACTIVITY -->
|
||||||
<!--================================================================================================-->
|
<!--================================================================================================-->
|
||||||
<createTable tableName="ACTIVITY">
|
<createTable tableName="ACTIVITY">
|
||||||
<column name="ACTIVITY_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
<column name="ACTIVITY_ID" type="int" nullable="false" autoIncrement="true" unique="true" primaryKeyName="IDX_ACTIVITY_PK" primaryKey="true"/>
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="ACTIVITY_USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="ACTIVITY_USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
@@ -84,7 +83,6 @@
|
|||||||
<column name="ACTIVITY_DATE" type="datetime" nullable="false"/>
|
<column name="ACTIVITY_DATE" type="datetime" nullable="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addPrimaryKey constraintName="IDX_ACTIVITY_PK" tableName="ACTIVITY" columnNames="ACTIVITY_ID"/>
|
|
||||||
<addForeignKeyConstraint constraintName="IDX_ACTIVITY_FK1" baseTableName="ACTIVITY" baseColumnNames="ACTIVITY_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
<addForeignKeyConstraint constraintName="IDX_ACTIVITY_FK1" baseTableName="ACTIVITY" baseColumnNames="ACTIVITY_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_ACTIVITY_FK0" baseTableName="ACTIVITY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
<addForeignKeyConstraint constraintName="IDX_ACTIVITY_FK0" baseTableName="ACTIVITY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
|
||||||
@@ -108,7 +106,7 @@
|
|||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="COMMIT_ID" type="varchar(100)" nullable="false"/>
|
<column name="COMMIT_ID" type="varchar(100)" nullable="false"/>
|
||||||
<column name="COMMENT_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
<column name="COMMENT_ID" type="int" nullable="false" autoIncrement="true" unique="true" primaryKeyName="IDX_COMMIT_COMMENT_PK" primaryKey="true" />
|
||||||
<column name="COMMENTED_USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="COMMENTED_USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="CONTENT" type="text" nullable="false"/>
|
<column name="CONTENT" type="text" nullable="false"/>
|
||||||
<column name="FILE_NAME" type="varchar(260)" nullable="true"/>
|
<column name="FILE_NAME" type="varchar(260)" nullable="true"/>
|
||||||
@@ -119,14 +117,13 @@
|
|||||||
<column name="ISSUE_ID" type="int" nullable="true"/>
|
<column name="ISSUE_ID" type="int" nullable="true"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addPrimaryKey constraintName="IDX_COMMIT_COMMENT_PK" tableName="COMMIT_COMMENT" columnNames="COMMENT_ID"/>
|
|
||||||
<addForeignKeyConstraint constraintName="IDX_COMMIT_COMMENT_FK0" baseTableName="COMMIT_COMMENT" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
<addForeignKeyConstraint constraintName="IDX_COMMIT_COMMENT_FK0" baseTableName="COMMIT_COMMENT" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
|
||||||
<!--================================================================================================-->
|
<!--================================================================================================-->
|
||||||
<!-- COMMIT_STATUS -->
|
<!-- COMMIT_STATUS -->
|
||||||
<!--================================================================================================-->
|
<!--================================================================================================-->
|
||||||
<createTable tableName="COMMIT_STATUS">
|
<createTable tableName="COMMIT_STATUS">
|
||||||
<column name="COMMIT_STATUS_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
<column name="COMMIT_STATUS_ID" type="int" nullable="false" autoIncrement="true" unique="true" primaryKeyName="IDX_COMMIT_STATUS_PK" primaryKey="true" />
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="COMMIT_ID" type="varchar(40)" nullable="false"/>
|
<column name="COMMIT_ID" type="varchar(40)" nullable="false"/>
|
||||||
@@ -139,7 +136,6 @@
|
|||||||
<column name="UPDATED_DATE" type="datetime" nullable="false"/>
|
<column name="UPDATED_DATE" type="datetime" nullable="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addPrimaryKey constraintName="IDX_COMMIT_STATUS_PK" tableName="COMMIT_STATUS" columnNames="COMMIT_STATUS_ID"/>
|
|
||||||
<addUniqueConstraint constraintName="IDX_COMMIT_STATUS_1" tableName="COMMIT_STATUS" columnNames="USER_NAME, REPOSITORY_NAME, COMMIT_ID, CONTEXT"/>
|
<addUniqueConstraint constraintName="IDX_COMMIT_STATUS_1" tableName="COMMIT_STATUS" columnNames="USER_NAME, REPOSITORY_NAME, COMMIT_ID, CONTEXT"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK3" baseTableName="COMMIT_STATUS" baseColumnNames="CREATOR" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
<addForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK3" baseTableName="COMMIT_STATUS" baseColumnNames="CREATOR" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK2" baseTableName="COMMIT_STATUS" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
<addForeignKeyConstraint constraintName="IDX_COMMIT_STATUS_FK2" baseTableName="COMMIT_STATUS" baseColumnNames="USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
@@ -218,7 +214,7 @@
|
|||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="REPOSITORY_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="ISSUE_ID" type="int" nullable="false"/>
|
||||||
<column name="COMMENT_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
<column name="COMMENT_ID" type="int" nullable="false" autoIncrement="true" unique="true" primaryKeyName="IDX_ISSUE_COMMENT_PK" primaryKey="true" />
|
||||||
<column name="ACTION" type="varchar(20)" nullable="false"/>
|
<column name="ACTION" type="varchar(20)" nullable="false"/>
|
||||||
<column name="COMMENTED_USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="COMMENTED_USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="CONTENT" type="text" nullable="false"/>
|
<column name="CONTENT" type="text" nullable="false"/>
|
||||||
@@ -226,7 +222,6 @@
|
|||||||
<column name="UPDATED_DATE" type="datetime" nullable="false"/>
|
<column name="UPDATED_DATE" type="datetime" nullable="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
<addPrimaryKey constraintName="IDX_ISSUE_COMMENT_PK" tableName="ISSUE_COMMENT" columnNames="COMMENT_ID"/>
|
|
||||||
<addForeignKeyConstraint constraintName="IDX_ISSUE_COMMENT_FK0" baseTableName="ISSUE_COMMENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_COMMENT_FK0" baseTableName="ISSUE_COMMENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
||||||
|
|
||||||
<!--================================================================================================-->
|
<!--================================================================================================-->
|
||||||
|
|||||||
6
src/main/resources/update/gitbucket-core_4.32.xml
Normal file
6
src/main/resources/update/gitbucket-core_4.32.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<addColumn tableName="PULL_REQUEST">
|
||||||
|
<column name="IS_DRAFT" type="boolean" nullable="false" defaultValueBoolean="false" />
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
4
src/main/resources/update/gitbucket-core_4.34.xml
Normal file
4
src/main/resources/update/gitbucket-core_4.34.xml
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<dropTable tableName="ACTIVITY" />
|
||||||
|
</changeSet>
|
||||||
39
src/main/resources/update/gitbucket-core_4.35.xml
Normal file
39
src/main/resources/update/gitbucket-core_4.35.xml
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
<?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>
|
||||||
@@ -16,7 +16,7 @@ class ScalatraBootstrap extends LifeCycle with SystemSettingsService {
|
|||||||
context.getSessionCookieConfig.setSecure(true)
|
context.getSessionCookieConfig.setSecure(true)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Register TransactionFilter and BasicAuthenticationFilter at first
|
// Register TransactionFilter at first
|
||||||
context.addFilter("transactionFilter", new TransactionFilter)
|
context.addFilter("transactionFilter", new TransactionFilter)
|
||||||
context
|
context
|
||||||
.getFilterRegistration("transactionFilter")
|
.getFilterRegistration("transactionFilter")
|
||||||
|
|||||||
@@ -1,7 +1,22 @@
|
|||||||
package gitbucket.core
|
package gitbucket.core
|
||||||
|
|
||||||
import io.github.gitbucket.solidbase.migration.{SqlMigration, LiquibaseMigration}
|
import java.io.FileOutputStream
|
||||||
import io.github.gitbucket.solidbase.model.{Version, Module}
|
import java.nio.charset.StandardCharsets
|
||||||
|
import java.sql.Connection
|
||||||
|
import java.util
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.util.Directory.ActivityLog
|
||||||
|
import gitbucket.core.util.JDBCUtil
|
||||||
|
import io.github.gitbucket.solidbase.Solidbase
|
||||||
|
import io.github.gitbucket.solidbase.migration.{LiquibaseMigration, Migration, SqlMigration}
|
||||||
|
import io.github.gitbucket.solidbase.model.{Module, Version}
|
||||||
|
import org.json4s.NoTypeHints
|
||||||
|
import org.json4s.jackson.Serialization
|
||||||
|
import org.json4s.jackson.Serialization.write
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
object GitBucketCoreModule
|
object GitBucketCoreModule
|
||||||
extends Module(
|
extends Module(
|
||||||
@@ -63,5 +78,42 @@ object GitBucketCoreModule
|
|||||||
new Version("4.30.1"),
|
new Version("4.30.1"),
|
||||||
new Version("4.31.0", new LiquibaseMigration("update/gitbucket-core_4.31.xml")),
|
new Version("4.31.0", new LiquibaseMigration("update/gitbucket-core_4.31.xml")),
|
||||||
new Version("4.31.1"),
|
new Version("4.31.1"),
|
||||||
new Version("4.31.2")
|
new Version("4.31.2"),
|
||||||
|
new Version("4.32.0", new LiquibaseMigration("update/gitbucket-core_4.32.xml")),
|
||||||
|
new Version("4.33.0"),
|
||||||
|
new Version(
|
||||||
|
"4.34.0",
|
||||||
|
new Migration() {
|
||||||
|
override def migrate(moduleId: String, version: String, context: util.Map[String, AnyRef]): Unit = {
|
||||||
|
implicit val 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"),
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -22,3 +22,12 @@ case class ApiBranchForList(
|
|||||||
name: String,
|
name: String,
|
||||||
commit: ApiBranchCommit
|
commit: ApiBranchCommit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#list-branches-for-head-commit
|
||||||
|
*/
|
||||||
|
case class ApiBranchForHeadCommit(
|
||||||
|
name: String,
|
||||||
|
commit: ApiBranchCommit,
|
||||||
|
`protected`: Boolean
|
||||||
|
)
|
||||||
|
|||||||
@@ -4,7 +4,11 @@ import gitbucket.core.service.ProtectedBranchService
|
|||||||
import org.json4s._
|
import org.json4s._
|
||||||
|
|
||||||
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
/** https://developer.github.com/v3/repos/#enabling-and-disabling-branch-protection */
|
||||||
case class ApiBranchProtection(enabled: Boolean, required_status_checks: Option[ApiBranchProtection.Status]) {
|
case class ApiBranchProtection(
|
||||||
|
url: Option[ApiPath], // for output
|
||||||
|
enabled: Boolean,
|
||||||
|
required_status_checks: Option[ApiBranchProtection.Status]
|
||||||
|
) {
|
||||||
def status: ApiBranchProtection.Status = required_status_checks.getOrElse(ApiBranchProtection.statusNone)
|
def status: ApiBranchProtection.Status = required_status_checks.getOrElse(ApiBranchProtection.statusNone)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -15,13 +19,36 @@ object ApiBranchProtection {
|
|||||||
|
|
||||||
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtection =
|
def apply(info: ProtectedBranchService.ProtectedBranchInfo): ApiBranchProtection =
|
||||||
ApiBranchProtection(
|
ApiBranchProtection(
|
||||||
|
url = Some(
|
||||||
|
ApiPath(
|
||||||
|
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection"
|
||||||
|
)
|
||||||
|
),
|
||||||
enabled = info.enabled,
|
enabled = info.enabled,
|
||||||
required_status_checks = Some(
|
required_status_checks = Some(
|
||||||
Status(EnforcementLevel(info.enabled && info.contexts.nonEmpty, info.includeAdministrators), info.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.includeAdministrators),
|
||||||
|
info.contexts,
|
||||||
|
Some(
|
||||||
|
ApiPath(
|
||||||
|
s"/api/v3/repos/${info.owner}/${info.repository}/branches/${info.branch}/protection/required_status_checks/contexts"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
val statusNone = Status(Off, Seq.empty)
|
val statusNone = Status(None, Off, Seq.empty, None)
|
||||||
case class Status(enforcement_level: EnforcementLevel, contexts: Seq[String])
|
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)
|
sealed class EnforcementLevel(val name: String)
|
||||||
case object Off extends EnforcementLevel("off")
|
case object Off extends EnforcementLevel("off")
|
||||||
case object NonAdmins extends EnforcementLevel("non_admins")
|
case object NonAdmins extends EnforcementLevel("non_admins")
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ case class ApiIssue(
|
|||||||
number: Int,
|
number: Int,
|
||||||
title: String,
|
title: String,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
|
assignee: Option[ApiUser],
|
||||||
labels: List[ApiLabel],
|
labels: List[ApiLabel],
|
||||||
state: String,
|
state: String,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
@@ -19,6 +20,7 @@ case class ApiIssue(
|
|||||||
body: String
|
body: String
|
||||||
)(repositoryName: RepositoryName, isPullRequest: Boolean) {
|
)(repositoryName: RepositoryName, isPullRequest: Boolean) {
|
||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
|
val assignees = List(assignee).flatten
|
||||||
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
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) {
|
val pull_request = if (isPullRequest) {
|
||||||
@@ -36,11 +38,18 @@ case class ApiIssue(
|
|||||||
}
|
}
|
||||||
|
|
||||||
object ApiIssue {
|
object ApiIssue {
|
||||||
def apply(issue: Issue, repositoryName: RepositoryName, user: ApiUser, labels: List[ApiLabel]): ApiIssue =
|
def apply(
|
||||||
|
issue: Issue,
|
||||||
|
repositoryName: RepositoryName,
|
||||||
|
user: ApiUser,
|
||||||
|
assignee: Option[ApiUser],
|
||||||
|
labels: List[ApiLabel]
|
||||||
|
): ApiIssue =
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
number = issue.issueId,
|
number = issue.issueId,
|
||||||
title = issue.title,
|
title = issue.title,
|
||||||
user = user,
|
user = user,
|
||||||
|
assignee = assignee,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
state = if (issue.closed) { "closed" } else { "open" },
|
state = if (issue.closed) { "closed" } else { "open" },
|
||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
|
|||||||
49
src/main/scala/gitbucket/core/api/ApiMilestone.scala
Normal file
49
src/main/scala/gitbucket/core/api/ApiMilestone.scala
Normal file
@@ -0,0 +1,49 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -21,7 +21,8 @@ case class ApiPullRequest(
|
|||||||
body: String,
|
body: String,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
labels: List[ApiLabel],
|
labels: List[ApiLabel],
|
||||||
assignee: Option[ApiUser]
|
assignee: Option[ApiUser],
|
||||||
|
draft: Option[Boolean]
|
||||||
) {
|
) {
|
||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
||||||
@@ -62,7 +63,8 @@ object ApiPullRequest {
|
|||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
user = user,
|
user = user,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
assignee = assignee
|
assignee = assignee,
|
||||||
|
draft = Some(pullRequest.isDraft)
|
||||||
)
|
)
|
||||||
|
|
||||||
case class Commit(sha: String, ref: String, repo: ApiRepository)(baseOwner: String) {
|
case class Commit(sha: String, ref: String, repo: ApiRepository)(baseOwner: String) {
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ case class ApiReleaseAsset(name: String, size: Long)(tag: String, fileName: Stri
|
|||||||
val label = name
|
val label = name
|
||||||
val file_id = fileName
|
val file_id = fileName
|
||||||
val browser_download_url = ApiPath(
|
val browser_download_url = ApiPath(
|
||||||
s"/api/v3/repos/${repositoryName.fullName}/releases/${tag}/assets/${fileName}"
|
s"/${repositoryName.fullName}/releases/${tag}/assets/${fileName}"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,13 +12,13 @@ case class ApiRepository(
|
|||||||
forks: Int,
|
forks: Int,
|
||||||
`private`: Boolean,
|
`private`: Boolean,
|
||||||
default_branch: String,
|
default_branch: String,
|
||||||
owner: ApiUser
|
owner: ApiUser,
|
||||||
|
has_issues: Boolean
|
||||||
) {
|
) {
|
||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
val forks_count = forks
|
val forks_count = forks
|
||||||
val watchers_count = watchers
|
val watchers_count = watchers
|
||||||
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
||||||
val http_url = ApiPath(s"/git/${full_name}.git")
|
|
||||||
val clone_url = ApiPath(s"/git/${full_name}.git")
|
val clone_url = ApiPath(s"/git/${full_name}.git")
|
||||||
val html_url = ApiPath(s"/${full_name}")
|
val html_url = ApiPath(s"/${full_name}")
|
||||||
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
||||||
@@ -39,11 +39,16 @@ object ApiRepository {
|
|||||||
forks = forkedCount,
|
forks = forkedCount,
|
||||||
`private` = repository.isPrivate,
|
`private` = repository.isPrivate,
|
||||||
default_branch = repository.defaultBranch,
|
default_branch = repository.defaultBranch,
|
||||||
owner = owner
|
owner = owner,
|
||||||
|
has_issues = if (repository.options.issuesOption == "DISABLE") false else true
|
||||||
)
|
)
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
def apply(repositoryInfo: RepositoryInfo, owner: ApiUser): ApiRepository =
|
||||||
ApiRepository(repositoryInfo.repository, owner, forkedCount = repositoryInfo.forkedCount)
|
ApiRepository(
|
||||||
|
repositoryInfo.repository,
|
||||||
|
owner,
|
||||||
|
forkedCount = repositoryInfo.forkedCount
|
||||||
|
)
|
||||||
|
|
||||||
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
def apply(repositoryInfo: RepositoryInfo, owner: Account): ApiRepository =
|
||||||
this(repositoryInfo, ApiUser(owner))
|
this(repositoryInfo, ApiUser(owner))
|
||||||
@@ -57,6 +62,7 @@ object ApiRepository {
|
|||||||
forks = 0,
|
forks = 0,
|
||||||
`private` = false,
|
`private` = false,
|
||||||
default_branch = "master",
|
default_branch = "master",
|
||||||
owner = owner
|
owner = owner,
|
||||||
|
has_issues = true
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
case class ApiRepositoryCollaborator(
|
||||||
|
permission: String,
|
||||||
|
user: ApiUser
|
||||||
|
)
|
||||||
29
src/main/scala/gitbucket/core/api/ApiTag.scala
Normal file
29
src/main/scala/gitbucket/core/api/ApiTag.scala
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
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")
|
||||||
|
)
|
||||||
|
}
|
||||||
46
src/main/scala/gitbucket/core/api/ApiWebhook.scala
Normal file
46
src/main/scala/gitbucket/core/api/ApiWebhook.scala
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
package gitbucket.core.api
|
||||||
|
|
||||||
|
import gitbucket.core.model.Profile.{RepositoryWebHookEvents, RepositoryWebHooks}
|
||||||
|
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
||||||
|
import gitbucket.core.util.RepositoryName
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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}")
|
||||||
|
)
|
||||||
|
}
|
||||||
14
src/main/scala/gitbucket/core/api/CreateAMilestone.scala
Normal file
14
src/main/scala/gitbucket/core/api/CreateAMilestone.scala
Normal file
@@ -0,0 +1,14 @@
|
|||||||
|
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\\-\\+_.]+")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -5,7 +5,8 @@ case class CreateAPullRequest(
|
|||||||
head: String,
|
head: String,
|
||||||
base: String,
|
base: String,
|
||||||
body: Option[String],
|
body: Option[String],
|
||||||
maintainer_can_modify: Option[Boolean]
|
maintainer_can_modify: Option[Boolean],
|
||||||
|
draft: Option[Boolean]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class CreateAPullRequestAlt(
|
case class CreateAPullRequestAlt(
|
||||||
@@ -14,3 +15,11 @@ case class CreateAPullRequestAlt(
|
|||||||
base: String,
|
base: String,
|
||||||
maintainer_can_modify: Option[Boolean]
|
maintainer_can_modify: Option[Boolean]
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case class UpdateAPullRequest(
|
||||||
|
title: Option[String],
|
||||||
|
body: Option[String],
|
||||||
|
state: Option[String],
|
||||||
|
base: Option[String],
|
||||||
|
maintainer_can_modify: Option[Boolean],
|
||||||
|
)
|
||||||
|
|||||||
7
src/main/scala/gitbucket/core/api/CreateARef.scala
Normal file
7
src/main/scala/gitbucket/core/api/CreateARef.scala
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
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)
|
||||||
@@ -0,0 +1,35 @@
|
|||||||
|
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"
|
||||||
|
}
|
||||||
|
}
|
||||||
23
src/main/scala/gitbucket/core/api/MergeAPullRequest.scala
Normal file
23
src/main/scala/gitbucket/core/api/MergeAPullRequest.scala
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
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
|
||||||
|
)
|
||||||
7
src/main/scala/gitbucket/core/api/UpdateARef.scala
Normal file
7
src/main/scala/gitbucket/core/api/UpdateARef.scala
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
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)
|
||||||
@@ -5,7 +5,6 @@ import java.io.File
|
|||||||
import gitbucket.core.account.html
|
import gitbucket.core.account.html
|
||||||
import gitbucket.core.helper
|
import gitbucket.core.helper
|
||||||
import gitbucket.core.model._
|
import gitbucket.core.model._
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.service.WebHookService._
|
import gitbucket.core.service.WebHookService._
|
||||||
import gitbucket.core.ssh.SshUtil
|
import gitbucket.core.ssh.SshUtil
|
||||||
@@ -17,6 +16,7 @@ import gitbucket.core.util._
|
|||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.scalatra.BadRequest
|
import org.scalatra.BadRequest
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
|
import org.scalatra.Forbidden
|
||||||
|
|
||||||
class AccountController
|
class AccountController
|
||||||
extends AccountControllerBase
|
extends AccountControllerBase
|
||||||
@@ -35,6 +35,7 @@ class AccountController
|
|||||||
with WebHookService
|
with WebHookService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
with RepositoryCreationService
|
with RepositoryCreationService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait AccountControllerBase extends AccountManagementControllerBase {
|
trait AccountControllerBase extends AccountManagementControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
@@ -81,9 +82,11 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
case class PersonalTokenForm(note: String)
|
case class PersonalTokenForm(note: String)
|
||||||
|
|
||||||
|
case class SyntaxHighlighterThemeForm(theme: String)
|
||||||
|
|
||||||
val newForm = mapping(
|
val newForm = mapping(
|
||||||
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(20), password))),
|
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -95,7 +98,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
)(AccountNewForm.apply)
|
)(AccountNewForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
val editForm = mapping(
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(20), password)))),
|
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -121,6 +124,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||||
)(PersonalTokenForm.apply)
|
)(PersonalTokenForm.apply)
|
||||||
|
|
||||||
|
val syntaxHighlighterThemeForm = mapping(
|
||||||
|
"highlighterTheme" -> trim(label("Theme", text(required)))
|
||||||
|
)(SyntaxHighlighterThemeForm.apply)
|
||||||
|
|
||||||
case class NewGroupForm(
|
case class NewGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
@@ -256,12 +263,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
account,
|
account,
|
||||||
members,
|
members,
|
||||||
extraMailAddresses,
|
extraMailAddresses,
|
||||||
context.loginAccount.exists(
|
isGroupManager(context.loginAccount, members)
|
||||||
x =>
|
|
||||||
members.exists { member =>
|
|
||||||
member.userName == x.userName && member.isManager
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -273,12 +275,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
if (account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
if (account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
||||||
getVisibleRepositories(context.loginAccount, Some(userName)),
|
getVisibleRepositories(context.loginAccount, Some(userName)),
|
||||||
extraMailAddresses,
|
extraMailAddresses,
|
||||||
context.loginAccount.exists(
|
isGroupManager(context.loginAccount, members)
|
||||||
x =>
|
|
||||||
members.exists { member =>
|
|
||||||
member.userName == x.userName && member.isManager
|
|
||||||
}
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -347,7 +344,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
updateImage(userName, form.fileId, form.clearImage)
|
updateImage(userName, form.fileId, form.clearImage)
|
||||||
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
updateAccountExtraMailAddresses(userName, form.extraMailAddresses.filter(_ != ""))
|
||||||
flash += "info" -> "Account information has been updated."
|
flash.update("info", "Account information has been updated.")
|
||||||
redirect(s"/${userName}/_edit")
|
redirect(s"/${userName}/_edit")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -359,7 +356,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
getAccountByUserName(userName, true).map {
|
getAccountByUserName(userName, true).map {
|
||||||
account =>
|
account =>
|
||||||
if (isLastAdministrator(account)) {
|
if (isLastAdministrator(account)) {
|
||||||
flash += "error" -> "Account can't be removed because this is last one administrator."
|
flash.update("error", "Account can't be removed because this is last one administrator.")
|
||||||
redirect(s"/${userName}/_edit")
|
redirect(s"/${userName}/_edit")
|
||||||
} else {
|
} else {
|
||||||
// // Remove repositories
|
// // Remove repositories
|
||||||
@@ -439,7 +436,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { x =>
|
getAccountByUserName(userName).map { x =>
|
||||||
val (tokenId, token) = generateAccessToken(userName, form.note)
|
val (tokenId, token) = generateAccessToken(userName, form.note)
|
||||||
flash += "generatedToken" -> (tokenId, token)
|
flash.update("generatedToken", (tokenId, token))
|
||||||
}
|
}
|
||||||
redirect(s"/${userName}/_application")
|
redirect(s"/${userName}/_application")
|
||||||
})
|
})
|
||||||
@@ -451,6 +448,29 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect(s"/${userName}/_application")
|
redirect(s"/${userName}/_application")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Display the user preference settings page
|
||||||
|
*/
|
||||||
|
get("/:userName/_preferences")(oneselfOnly {
|
||||||
|
val userName = params("userName")
|
||||||
|
val currentTheme = getAccountPreference(userName) match {
|
||||||
|
case Some(accountHighlighter) => accountHighlighter.highlighterTheme
|
||||||
|
case _ => "github-v2"
|
||||||
|
}
|
||||||
|
getAccountByUserName(userName).map { x =>
|
||||||
|
html.preferences(x, currentTheme)
|
||||||
|
} getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update the syntax highlighter setting of user
|
||||||
|
*/
|
||||||
|
post("/:userName/_preferences/highlighter", syntaxHighlighterThemeForm)(oneselfOnly { form =>
|
||||||
|
val userName = params("userName")
|
||||||
|
addOrUpdateAccountPreference(userName, form.theme)
|
||||||
|
redirect(s"/${userName}/_preferences")
|
||||||
|
})
|
||||||
|
|
||||||
get("/:userName/_hooks")(managersOnly {
|
get("/:userName/_hooks")(managersOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { account =>
|
getAccountByUserName(userName).map { account =>
|
||||||
@@ -475,7 +495,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/:userName/_hooks/new", accountWebHookForm(false))(managersOnly { form =>
|
post("/:userName/_hooks/new", accountWebHookForm(false))(managersOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
addAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
addAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||||
flash += "info" -> s"Webhook ${form.url} created"
|
flash.update("info", s"Webhook ${form.url} created")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/${userName}/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -485,7 +505,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_hooks/delete")(managersOnly {
|
get("/:userName/_hooks/delete")(managersOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
deleteAccountWebHook(userName, params("url"))
|
deleteAccountWebHook(userName, params("url"))
|
||||||
flash += "info" -> s"Webhook ${params("url")} deleted"
|
flash.update("info", s"Webhook ${params("url")} deleted")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/${userName}/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -508,7 +528,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/:userName/_hooks/edit", accountWebHookForm(true))(managersOnly { form =>
|
post("/:userName/_hooks/edit", accountWebHookForm(true))(managersOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
updateAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
updateAccountWebHook(userName, form.url, form.events, form.ctype, form.token)
|
||||||
flash += "info" -> s"webhook ${form.url} updated"
|
flash.update("info", s"webhook ${form.url} updated")
|
||||||
redirect(s"/${userName}/_hooks")
|
redirect(s"/${userName}/_hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -531,19 +551,21 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
val url = params("url")
|
val url = params("url")
|
||||||
val token = Some(params("token"))
|
val token = Some(params("token"))
|
||||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||||
val dummyWebHookInfo = RepositoryWebHook(userName, "dummy", url, ctype, token)
|
val dummyWebHookInfo =
|
||||||
|
RepositoryWebHook(userName = userName, repositoryName = "dummy", url = url, ctype = ctype, token = token)
|
||||||
val dummyPayload = {
|
val dummyPayload = {
|
||||||
val ownerAccount = getAccountByUserName(userName).get
|
val ownerAccount = getAccountByUserName(userName).get
|
||||||
WebHookPushPayload.createDummyPayload(ownerAccount)
|
WebHookPushPayload.createDummyPayload(ownerAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
val (webHook, json, reqFuture, resFuture) = callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload).head
|
val (webHook, json, reqFuture, resFuture) =
|
||||||
|
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||||
|
|
||||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
||||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
||||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
||||||
case NonFatal(e) => Map("error" -> (e.getClass + " " + e.getMessage))
|
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -683,7 +705,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
updateImage(form.groupName, form.fileId, form.clearImage)
|
updateImage(form.groupName, form.fileId, form.clearImage)
|
||||||
|
|
||||||
flash += "info" -> "Account information has been updated."
|
flash.update("info", "Account information has been updated.")
|
||||||
redirect(s"/${groupName}/_editgroup")
|
redirect(s"/${groupName}/_editgroup")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -701,27 +723,28 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
* Create new repository.
|
* Create new repository.
|
||||||
*/
|
*/
|
||||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
if (context.settings.repositoryOperation.create || context.loginAccount.get.isAdmin) {
|
||||||
if (getRepository(form.owner, form.name).isEmpty) {
|
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||||
createRepository(
|
if (getRepository(form.owner, form.name).isEmpty) {
|
||||||
context.loginAccount.get,
|
createRepository(
|
||||||
form.owner,
|
context.loginAccount.get,
|
||||||
form.name,
|
form.owner,
|
||||||
form.description,
|
form.name,
|
||||||
form.isPrivate,
|
form.description,
|
||||||
form.initOption,
|
form.isPrivate,
|
||||||
form.sourceUrl
|
form.initOption,
|
||||||
)
|
form.sourceUrl
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
// redirect to the repository
|
||||||
|
redirect(s"/${form.owner}/${form.name}")
|
||||||
// redirect to the repository
|
} else Forbidden()
|
||||||
redirect(s"/${form.owner}/${form.name}")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||||
if (repository.repository.options.allowFork) {
|
val loginAccount = context.loginAccount.get
|
||||||
val loginAccount = context.loginAccount.get
|
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val groups = getGroupsByUserName(loginUserName)
|
val groups = getGroupsByUserName(loginUserName)
|
||||||
groups match {
|
groups match {
|
||||||
@@ -745,8 +768,8 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||||
if (repository.repository.options.allowFork) {
|
val loginAccount = context.loginAccount.get
|
||||||
val loginAccount = context.loginAccount.get
|
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val accountName = form.accountName
|
val accountName = form.accountName
|
||||||
|
|
||||||
@@ -760,7 +783,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// redirect to the repository
|
// redirect to the repository
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
}
|
}
|
||||||
} else BadRequest()
|
} else Forbidden()
|
||||||
})
|
})
|
||||||
|
|
||||||
private def existsAccount: Constraint = new Constraint() {
|
private def existsAccount: Constraint = new Constraint() {
|
||||||
@@ -823,4 +846,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def isGroupManager(account: Option[Account], members: Seq[GroupMember]): Boolean = {
|
||||||
|
account.exists { account =>
|
||||||
|
account.isAdmin || members.exists { member =>
|
||||||
|
member.userName == account.userName && member.isManager
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ class ApiController
|
|||||||
with ApiIssueCommentControllerBase
|
with ApiIssueCommentControllerBase
|
||||||
with ApiIssueControllerBase
|
with ApiIssueControllerBase
|
||||||
with ApiIssueLabelControllerBase
|
with ApiIssueLabelControllerBase
|
||||||
|
with ApiIssueMilestoneControllerBase
|
||||||
with ApiOrganizationControllerBase
|
with ApiOrganizationControllerBase
|
||||||
with ApiPullRequestControllerBase
|
with ApiPullRequestControllerBase
|
||||||
with ApiReleaseControllerBase
|
with ApiReleaseControllerBase
|
||||||
@@ -22,6 +23,7 @@ class ApiController
|
|||||||
with ApiRepositoryContentsControllerBase
|
with ApiRepositoryContentsControllerBase
|
||||||
with ApiRepositoryControllerBase
|
with ApiRepositoryControllerBase
|
||||||
with ApiRepositoryStatusControllerBase
|
with ApiRepositoryStatusControllerBase
|
||||||
|
with ApiRepositoryWebhookControllerBase
|
||||||
with ApiUserControllerBase
|
with ApiUserControllerBase
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
with AccountService
|
with AccountService
|
||||||
@@ -52,6 +54,7 @@ class ApiController
|
|||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait ApiControllerBase extends ControllerBase {
|
trait ApiControllerBase extends ControllerBase {
|
||||||
|
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ import javax.servlet.{FilterChain, ServletRequest, ServletResponse}
|
|||||||
import is.tagomor.woothee.Classifier
|
import is.tagomor.woothee.Classifier
|
||||||
|
|
||||||
import scala.util.Try
|
import scala.util.Try
|
||||||
|
import scala.util.Using
|
||||||
import net.coobird.thumbnailator.Thumbnails
|
import net.coobird.thumbnailator.Thumbnails
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
@@ -240,7 +241,7 @@ abstract class ControllerBase
|
|||||||
case false => None
|
case false => None
|
||||||
}
|
}
|
||||||
|
|
||||||
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||||
treeWalk.addTree(revCommit.getTree)
|
treeWalk.addTree(revCommit.getTree)
|
||||||
treeWalk.setRecursive(true)
|
treeWalk.setRecursive(true)
|
||||||
_getPathObjectId(path, treeWalk)
|
_getPathObjectId(path, treeWalk)
|
||||||
@@ -268,7 +269,7 @@ abstract class ControllerBase
|
|||||||
response.setContentLength(attrs("size").toInt)
|
response.setContentLength(attrs("size").toInt)
|
||||||
val oid = attrs("oid").split(":")(1)
|
val oid = attrs("oid").split(":")(1)
|
||||||
|
|
||||||
using(new FileInputStream(FileUtil.getLfsFilePath(repository.owner, repository.name, oid))) { in =>
|
Using.resource(new FileInputStream(FileUtil.getLfsFilePath(repository.owner, repository.name, oid))) { in =>
|
||||||
IOUtils.copy(in, response.getOutputStream)
|
IOUtils.copy(in, response.getOutputStream)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -324,6 +325,8 @@ case class Context(
|
|||||||
trait AccountManagementControllerBase extends ControllerBase {
|
trait AccountManagementControllerBase extends ControllerBase {
|
||||||
self: AccountService =>
|
self: AccountService =>
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(getClass)
|
||||||
|
|
||||||
protected def updateImage(userName: String, fileId: Option[String], clearImage: Boolean): Unit =
|
protected def updateImage(userName: String, fileId: Option[String], clearImage: Boolean): Unit =
|
||||||
if (clearImage) {
|
if (clearImage) {
|
||||||
getAccountByUserName(userName).flatMap(_.image).foreach { image =>
|
getAccountByUserName(userName).flatMap(_.image).foreach { image =>
|
||||||
@@ -331,17 +334,21 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
updateAvatarImage(userName, None)
|
updateAvatarImage(userName, None)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
fileId.foreach { fileId =>
|
try {
|
||||||
val filename = "avatar." + FileUtil.getExtension(session.getAndRemove(Keys.Session.Upload(fileId)).get)
|
fileId.foreach { fileId =>
|
||||||
val uploadDir = getUserUploadDir(userName)
|
val filename = "avatar." + FileUtil.getExtension(session.getAndRemove(Keys.Session.Upload(fileId)).get)
|
||||||
if (!uploadDir.exists) {
|
val uploadDir = getUserUploadDir(userName)
|
||||||
uploadDir.mkdirs()
|
if (!uploadDir.exists) {
|
||||||
|
uploadDir.mkdirs()
|
||||||
|
}
|
||||||
|
Thumbnails
|
||||||
|
.of(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)))
|
||||||
|
.size(324, 324)
|
||||||
|
.toFile(new File(uploadDir, FileUtil.checkFilename(filename)))
|
||||||
|
updateAvatarImage(userName, Some(filename))
|
||||||
}
|
}
|
||||||
Thumbnails
|
} catch {
|
||||||
.of(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)))
|
case e: Exception => logger.info("Error while updateImage" + e.getMessage)
|
||||||
.size(324, 324)
|
|
||||||
.toFile(new File(uploadDir, FileUtil.checkFilename(filename)))
|
|
||||||
updateAvatarImage(userName, Some(filename))
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -359,7 +366,7 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
params: Map[String, Seq[String]],
|
params: Map[String, Seq[String]],
|
||||||
messages: Messages
|
messages: Messages
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
val extraMailAddresses = params.filterKeys(k => k.startsWith("extraMailAddresses"))
|
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||||
if (extraMailAddresses.exists {
|
if (extraMailAddresses.exists {
|
||||||
case (k, v) =>
|
case (k, v) =>
|
||||||
v.contains(value)
|
v.contains(value)
|
||||||
@@ -382,7 +389,7 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
params: Map[String, Seq[String]],
|
params: Map[String, Seq[String]],
|
||||||
messages: Messages
|
messages: Messages
|
||||||
): Option[String] = {
|
): Option[String] = {
|
||||||
val extraMailAddresses = params.filterKeys(k => k.startsWith("extraMailAddresses"))
|
val extraMailAddresses = params.view.filterKeys(k => k.startsWith("extraMailAddresses"))
|
||||||
if (Some(value) == params.optionValue("mailAddress") || extraMailAddresses.count {
|
if (Some(value) == params.optionValue("mailAddress") || extraMailAddresses.count {
|
||||||
case (k, v) =>
|
case (k, v) =>
|
||||||
v.contains(value)
|
v.contains(value)
|
||||||
@@ -414,7 +421,7 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
"new"
|
"new"
|
||||||
)
|
)
|
||||||
|
|
||||||
protected def reservedNames(): Constraint = new Constraint() {
|
protected def reservedNames: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (allReservedNames.contains(value.toLowerCase)) {
|
if (allReservedNames.contains(value.toLowerCase)) {
|
||||||
Some(s"${value} is reserved")
|
Some(s"${value} is reserved")
|
||||||
|
|||||||
@@ -21,13 +21,25 @@ class DashboardController
|
|||||||
with WebHookPullRequestService
|
with WebHookPullRequestService
|
||||||
with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestReviewCommentService
|
||||||
with MilestonesService
|
with MilestonesService
|
||||||
|
with CommitStatusService
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait DashboardControllerBase extends ControllerBase {
|
trait DashboardControllerBase extends ControllerBase {
|
||||||
self: IssuesService with PullRequestService with RepositoryService with AccountService with UsersAuthenticator =>
|
self: IssuesService
|
||||||
|
with PullRequestService
|
||||||
|
with RepositoryService
|
||||||
|
with AccountService
|
||||||
|
with CommitStatusService
|
||||||
|
with UsersAuthenticator =>
|
||||||
|
|
||||||
get("/dashboard/repos")(usersOnly {
|
get("/dashboard/repos")(usersOnly {
|
||||||
val repos = getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true)
|
val repos = getVisibleRepositories(
|
||||||
|
context.loginAccount,
|
||||||
|
None,
|
||||||
|
withoutPhysicalInfo = true,
|
||||||
|
limit = context.settings.limitVisibleRepositories
|
||||||
|
)
|
||||||
html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos)
|
html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -80,12 +92,13 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
||||||
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
|
val issues = searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, userRepos: _*)
|
||||||
|
|
||||||
html.issues(
|
html.issues(
|
||||||
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, userRepos: _*),
|
issues.map(issue => (issue, None)),
|
||||||
page,
|
page,
|
||||||
countIssue(condition.copy(state = "open"), false, userRepos: _*),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, userRepos: _*),
|
||||||
countIssue(condition.copy(state = "closed"), false, userRepos: _*),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, userRepos: _*),
|
||||||
filter match {
|
filter match {
|
||||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
@@ -93,7 +106,12 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
},
|
},
|
||||||
filter,
|
filter,
|
||||||
getGroupNames(userName),
|
getGroupNames(userName),
|
||||||
getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true)
|
getVisibleRepositories(
|
||||||
|
context.loginAccount,
|
||||||
|
None,
|
||||||
|
withoutPhysicalInfo = true,
|
||||||
|
limit = context.settings.limitVisibleRepositories
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,12 +123,24 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
||||||
val allRepos = getAllRepositories(userName)
|
val allRepos = getAllRepositories(userName)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
|
val issues = searchIssue(
|
||||||
|
condition,
|
||||||
|
IssueSearchOption.PullRequests,
|
||||||
|
(page - 1) * PullRequestLimit,
|
||||||
|
PullRequestLimit,
|
||||||
|
allRepos: _*
|
||||||
|
)
|
||||||
|
val status = issues.map { issue =>
|
||||||
|
issue.commitId.flatMap { commitId =>
|
||||||
|
getCommitStatusWithSummary(issue.issue.userName, issue.issue.repositoryName, commitId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
html.pulls(
|
html.pulls(
|
||||||
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, allRepos: _*),
|
issues.zip(status),
|
||||||
page,
|
page,
|
||||||
countIssue(condition.copy(state = "open"), true, allRepos: _*),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, allRepos: _*),
|
||||||
countIssue(condition.copy(state = "closed"), true, allRepos: _*),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, allRepos: _*),
|
||||||
filter match {
|
filter match {
|
||||||
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
case "assigned" => condition.copy(assigned = Some(Some(userName)))
|
||||||
case "mentioned" => condition.copy(mentioned = Some(userName))
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
@@ -118,7 +148,12 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
},
|
},
|
||||||
filter,
|
filter,
|
||||||
getGroupNames(userName),
|
getGroupNames(userName),
|
||||||
getVisibleRepositories(context.loginAccount, withoutPhysicalInfo = true)
|
getVisibleRepositories(
|
||||||
|
context.loginAccount,
|
||||||
|
None,
|
||||||
|
withoutPhysicalInfo = true,
|
||||||
|
limit = context.settings.limitVisibleRepositories
|
||||||
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,6 +16,9 @@ import org.scalatra._
|
|||||||
import org.scalatra.servlet.{FileItem, FileUploadSupport, MultipartConfig}
|
import org.scalatra.servlet.{FileItem, FileUploadSupport, MultipartConfig}
|
||||||
import org.apache.commons.io.{FileUtils, IOUtils}
|
import org.apache.commons.io.{FileUtils, IOUtils}
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
import gitbucket.core.service.SystemSettingsService
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Ajax based file upload functionality.
|
* Provides Ajax based file upload functionality.
|
||||||
*
|
*
|
||||||
@@ -26,15 +29,15 @@ class FileUploadController
|
|||||||
with FileUploadSupport
|
with FileUploadSupport
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
with AccountService
|
with AccountService
|
||||||
with ReleaseService {
|
with ReleaseService
|
||||||
|
with SystemSettingsService {
|
||||||
configureMultipartHandling(MultipartConfig(maxFileSize = Some(FileUtil.MaxFileSize)))
|
|
||||||
|
|
||||||
post("/image") {
|
post("/image") {
|
||||||
|
setMultipartConfig()
|
||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
FileUtil.isImage
|
FileUtil.isImage
|
||||||
@@ -42,10 +45,11 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/tmp") {
|
post("/tmp") {
|
||||||
|
setMultipartConfig()
|
||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -53,6 +57,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/file/:owner/:repository") {
|
post("/file/:owner/:repository") {
|
||||||
|
setMultipartConfig()
|
||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
@@ -60,7 +65,7 @@ class FileUploadController
|
|||||||
getAttachedDir(params("owner"), params("repository")),
|
getAttachedDir(params("owner"), params("repository")),
|
||||||
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
||||||
),
|
),
|
||||||
file.get
|
file.get()
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -68,6 +73,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/wiki/:owner/:repository") {
|
post("/wiki/:owner/:repository") {
|
||||||
|
setMultipartConfig()
|
||||||
// Don't accept not logged-in users
|
// Don't accept not logged-in users
|
||||||
session.get(Keys.Session.LoginAccount).collect {
|
session.get(Keys.Session.LoginAccount).collect {
|
||||||
case loginAccount: Account =>
|
case loginAccount: Account =>
|
||||||
@@ -80,7 +86,7 @@ class FileUploadController
|
|||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
val fileName = file.getName
|
val fileName = file.getName
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
LockUtil.lock(s"${owner}/${repository}/wiki") {
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))) {
|
Using.resource(Git.open(Directory.getWikiRepositoryDir(owner, repository))) {
|
||||||
git =>
|
git =>
|
||||||
val builder = DirCache.newInCore.builder()
|
val builder = DirCache.newInCore.builder()
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
@@ -126,6 +132,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/release/:owner/:repository/:tag") {
|
post("/release/:owner/:repository/:tag") {
|
||||||
|
setMultipartConfigForLargeFile()
|
||||||
session
|
session
|
||||||
.get(Keys.Session.LoginAccount)
|
.get(Keys.Session.LoginAccount)
|
||||||
.collect {
|
.collect {
|
||||||
@@ -137,7 +144,7 @@ class FileUploadController
|
|||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
||||||
file.get
|
file.get()
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -148,6 +155,7 @@ class FileUploadController
|
|||||||
|
|
||||||
post("/import") {
|
post("/import") {
|
||||||
import JDBCUtil._
|
import JDBCUtil._
|
||||||
|
setMultipartConfig()
|
||||||
session.get(Keys.Session.LoginAccount).collect {
|
session.get(Keys.Session.LoginAccount).collect {
|
||||||
case loginAccount: Account if loginAccount.isAdmin =>
|
case loginAccount: Account if loginAccount.isAdmin =>
|
||||||
execute({ (file, fileId) =>
|
execute({ (file, fileId) =>
|
||||||
@@ -157,6 +165,18 @@ class FileUploadController
|
|||||||
redirect("/admin/data")
|
redirect("/admin/data")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def setMultipartConfig(): Unit = {
|
||||||
|
val settings = loadSystemSettings()
|
||||||
|
val config = MultipartConfig(maxFileSize = Some(settings.upload.maxFileSize))
|
||||||
|
config.apply(request.getServletContext())
|
||||||
|
}
|
||||||
|
|
||||||
|
private def setMultipartConfigForLargeFile(): Unit = {
|
||||||
|
val settings = loadSystemSettings()
|
||||||
|
val config = MultipartConfig(maxFileSize = Some(settings.upload.largeMaxFileSize))
|
||||||
|
config.apply(request.getServletContext())
|
||||||
|
}
|
||||||
|
|
||||||
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
||||||
implicit val session = Database.getSession(request)
|
implicit val session = Database.getSession(request)
|
||||||
getRepository(owner, repository) match {
|
getRepository(owner, repository) match {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ class IndexController
|
|||||||
with AccessTokenService
|
with AccessTokenService
|
||||||
with AccountFederationService
|
with AccountFederationService
|
||||||
with OpenIDConnectService
|
with OpenIDConnectService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait IndexControllerBase extends ControllerBase {
|
trait IndexControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -65,7 +66,12 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
val visibleOwnerSet: Set[String] = Set(account.userName) ++ getGroupsByUserName(account.userName)
|
||||||
gitbucket.core.html.index(
|
gitbucket.core.html.index(
|
||||||
getRecentActivitiesByOwners(visibleOwnerSet),
|
getRecentActivitiesByOwners(visibleOwnerSet),
|
||||||
getVisibleRepositories(Some(account), withoutPhysicalInfo = true),
|
getVisibleRepositories(
|
||||||
|
Some(account),
|
||||||
|
None,
|
||||||
|
withoutPhysicalInfo = true,
|
||||||
|
limit = context.settings.limitVisibleRepositories
|
||||||
|
),
|
||||||
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
||||||
account.userName
|
account.userName
|
||||||
)
|
)
|
||||||
@@ -73,7 +79,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
.getOrElse {
|
.getOrElse {
|
||||||
gitbucket.core.html.index(
|
gitbucket.core.html.index(
|
||||||
getRecentActivities(),
|
getRecentPublicActivities(),
|
||||||
getVisibleRepositories(None, withoutPhysicalInfo = true),
|
getVisibleRepositories(None, withoutPhysicalInfo = true),
|
||||||
showBannerToCreatePersonalAccessToken = false
|
showBannerToCreatePersonalAccessToken = false
|
||||||
)
|
)
|
||||||
@@ -83,7 +89,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
get("/signin") {
|
get("/signin") {
|
||||||
val redirect = params.get("redirect")
|
val redirect = params.get("redirect")
|
||||||
if (redirect.isDefined && redirect.get.startsWith("/")) {
|
if (redirect.isDefined && redirect.get.startsWith("/")) {
|
||||||
flash += Keys.Flash.Redirect -> redirect.get
|
flash.update(Keys.Flash.Redirect, redirect.get)
|
||||||
}
|
}
|
||||||
gitbucket.core.html.signin(flash.get("userName"), flash.get("password"), flash.get("error"))
|
gitbucket.core.html.signin(flash.get("userName"), flash.get("password"), flash.get("error"))
|
||||||
}
|
}
|
||||||
@@ -96,9 +102,9 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
case _ => signin(account)
|
case _ => signin(account)
|
||||||
}
|
}
|
||||||
case None =>
|
case None =>
|
||||||
flash += "userName" -> form.userName
|
flash.update("userName", form.userName)
|
||||||
flash += "password" -> form.password
|
flash.update("password", form.password)
|
||||||
flash += "error" -> "Sorry, your Username and/or Password is incorrect. Please try again."
|
flash.update("error", "Sorry, your Username and/or Password is incorrect. Please try again.")
|
||||||
redirect("/signin")
|
redirect("/signin")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,15 +138,15 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
val redirectURI = new URI(s"$baseUrl/signin/oidc")
|
val redirectURI = new URI(s"$baseUrl/signin/oidc")
|
||||||
session.get(Keys.Session.OidcContext) match {
|
session.get(Keys.Session.OidcContext) match {
|
||||||
case Some(context: OidcContext) =>
|
case Some(context: OidcContext) =>
|
||||||
authenticate(params, redirectURI, context.state, context.nonce, oidc) map { account =>
|
authenticate(params.toMap, redirectURI, context.state, context.nonce, oidc).map { account =>
|
||||||
signin(account, context.redirectBackURI)
|
signin(account, context.redirectBackURI)
|
||||||
} orElse {
|
} orElse {
|
||||||
flash += "error" -> "Sorry, authentication failed. Please try again."
|
flash.update("error", "Sorry, authentication failed. Please try again.")
|
||||||
session.invalidate()
|
session.invalidate()
|
||||||
redirect("/signin")
|
redirect("/signin")
|
||||||
}
|
}
|
||||||
case _ =>
|
case _ =>
|
||||||
flash += "error" -> "Sorry, something wrong. Please try again."
|
flash.update("error", "Sorry, something wrong. Please try again.")
|
||||||
session.invalidate()
|
session.invalidate()
|
||||||
redirect("/signin")
|
redirect("/signin")
|
||||||
}
|
}
|
||||||
@@ -156,7 +162,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/activities.atom") {
|
get("/activities.atom") {
|
||||||
contentType = "application/atom+xml; type=feed"
|
contentType = "application/atom+xml; type=feed"
|
||||||
xml.feed(getRecentActivities())
|
xml.feed(getRecentPublicActivities())
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/sidebar-collapse") {
|
post("/sidebar-collapse") {
|
||||||
@@ -207,8 +213,10 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
.map { t =>
|
.map { t =>
|
||||||
Map(
|
Map(
|
||||||
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(t.userName)}</b> ${StringUtil
|
"label" -> s"${avatar(t.userName, 16)}<b>@${StringUtil.escapeHtml(
|
||||||
.escapeHtml(t.fullName)}",
|
StringUtil.cutTail(t.userName, 25, "...")
|
||||||
|
)}</b> ${StringUtil
|
||||||
|
.escapeHtml(StringUtil.cutTail(t.fullName, 25, "..."))}",
|
||||||
"value" -> t.userName
|
"value" -> t.userName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -227,7 +235,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
} getOrElse ""
|
} getOrElse ""
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO Move to RepositoryViwerController?
|
// TODO Move to RepositoryViewrController?
|
||||||
get("/:owner/:repository/search")(referrersOnly { repository =>
|
get("/:owner/:repository/search")(referrersOnly { repository =>
|
||||||
defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")) {
|
defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")) {
|
||||||
case (query, target) =>
|
case (query, target) =>
|
||||||
@@ -279,11 +287,28 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
get("/search") {
|
get("/search") {
|
||||||
val query = params.getOrElse("query", "").trim.toLowerCase
|
val query = params.getOrElse("query", "").trim.toLowerCase
|
||||||
val visibleRepositories =
|
val visibleRepositories =
|
||||||
getVisibleRepositories(context.loginAccount, repositoryUserName = None, withoutPhysicalInfo = true)
|
getVisibleRepositories(
|
||||||
val repositories = visibleRepositories.filter { repository =>
|
context.loginAccount,
|
||||||
|
None,
|
||||||
|
withoutPhysicalInfo = true,
|
||||||
|
limit = context.settings.limitVisibleRepositories
|
||||||
|
)
|
||||||
|
|
||||||
|
val repositories = {
|
||||||
|
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
|
repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0
|
||||||
}
|
}
|
||||||
|
|
||||||
gitbucket.core.search.html.repositories(query, repositories, visibleRepositories)
|
gitbucket.core.search.html.repositories(query, repositories, visibleRepositories)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,7 @@ class IssuesController
|
|||||||
with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestReviewCommentService
|
||||||
with CommitsService
|
with CommitsService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait IssuesControllerBase extends ControllerBase {
|
trait IssuesControllerBase extends ControllerBase {
|
||||||
self: IssuesService
|
self: IssuesService
|
||||||
@@ -111,6 +112,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
getLabels(owner, name),
|
getLabels(owner, name),
|
||||||
isIssueEditable(repository),
|
isIssueEditable(repository),
|
||||||
isIssueManageable(repository),
|
isIssueManageable(repository),
|
||||||
|
isIssueCommentManageable(repository),
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -145,7 +147,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
form.assignedUserName,
|
form.assignedUserName,
|
||||||
form.milestoneId,
|
form.milestoneId,
|
||||||
form.priorityId,
|
form.priorityId,
|
||||||
form.labelNames.toArray.flatMap(_.split(",")),
|
form.labelNames.toSeq.flatMap(_.split(",")),
|
||||||
context.loginAccount.get
|
context.loginAccount.get
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -237,8 +239,8 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
defining(repository.owner, repository.name) {
|
defining(repository.owner, repository.name) {
|
||||||
case (owner, name) =>
|
case (owner, name) =>
|
||||||
getComment(owner, name, params("id")).map { comment =>
|
getComment(owner, name, params("id")).map { comment =>
|
||||||
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
if (isDeletableComment(owner, name, comment.commentedUserName)) {
|
||||||
Ok(deleteComment(comment.issueId, comment.commentId))
|
Ok(deleteComment(repository.owner, repository.name, comment.issueId, comment.commentId))
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
@@ -368,6 +370,9 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
case _ => BadRequest()
|
case _ => BadRequest()
|
||||||
}
|
}
|
||||||
|
if (params("uri").nonEmpty) {
|
||||||
|
redirect(params("uri"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -376,6 +381,9 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
executeBatch(repository) { issueId =>
|
executeBatch(repository) { issueId =>
|
||||||
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
getIssueLabel(repository.owner, repository.name, issueId, labelId) getOrElse {
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, labelId, true)
|
||||||
|
if (params("uri").nonEmpty) {
|
||||||
|
redirect(params("uri"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -386,6 +394,9 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||||
}
|
}
|
||||||
|
if (params("uri").nonEmpty) {
|
||||||
|
redirect(params("uri"))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -416,6 +427,29 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON API for issue and PR completion.
|
||||||
|
*/
|
||||||
|
ajaxGet("/:owner/:repository/_issue/proposals")(writableUsersOnly { repository =>
|
||||||
|
contentType = formats("json")
|
||||||
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map(
|
||||||
|
"options" -> (
|
||||||
|
getOpenIssues(repository.owner, repository.name)
|
||||||
|
.map { t =>
|
||||||
|
Map(
|
||||||
|
"label" -> s"""${if (t.isPullRequest) "<i class='octicon octicon-git-pull-request'></i>"
|
||||||
|
else "<i class='octicon octicon-issue-opened'></i>"}<b> #${StringUtil
|
||||||
|
.escapeHtml(t.issueId.toString)} ${StringUtil
|
||||||
|
.escapeHtml(StringUtil.cutTail(t.title, 50, "..."))}</b>""",
|
||||||
|
"value" -> t.issueId.toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
val assignedUserName = (key: String) => params.get(key) filter (_.trim != "")
|
||||||
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
val milestoneId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
val priorityId: String => Option[Int] = (key: String) => params.get(key).flatMap(_.toIntOpt)
|
||||||
@@ -425,6 +459,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
params("from") match {
|
params("from") match {
|
||||||
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||||
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
||||||
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -432,20 +467,22 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
defining(repository.owner, repository.name) {
|
defining(repository.owner, repository.name) {
|
||||||
case (owner, repoName) =>
|
case (owner, repoName) =>
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
|
|
||||||
// retrieve search condition
|
// retrieve search condition
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
|
// search issues
|
||||||
|
val issues =
|
||||||
|
searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, owner -> repoName)
|
||||||
|
|
||||||
html.list(
|
html.list(
|
||||||
"issues",
|
"issues",
|
||||||
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, owner -> repoName),
|
issues.map(issue => (issue, None)),
|
||||||
page,
|
page,
|
||||||
getAssignableUserNames(owner, repoName),
|
getAssignableUserNames(owner, repoName),
|
||||||
getMilestones(owner, repoName),
|
getMilestones(owner, repoName),
|
||||||
getPriorities(owner, repoName),
|
getPriorities(owner, repoName),
|
||||||
getLabels(owner, repoName),
|
getLabels(owner, repoName),
|
||||||
countIssue(condition.copy(state = "open"), false, owner -> repoName),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, owner -> repoName),
|
||||||
countIssue(condition.copy(state = "closed"), false, owner -> repoName),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, owner -> repoName),
|
||||||
condition,
|
condition,
|
||||||
repository,
|
repository,
|
||||||
isIssueEditable(repository),
|
isIssueEditable(repository),
|
||||||
@@ -462,4 +499,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tests whether an issue comment is deletable by a logged-in user.
|
||||||
|
*/
|
||||||
|
private def isDeletableComment(owner: String, repository: String, author: String)(
|
||||||
|
implicit context: Context
|
||||||
|
): Boolean = {
|
||||||
|
hasOwnerRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,26 +1,41 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.issues.milestones.html
|
import gitbucket.core.issues.milestones.html
|
||||||
import gitbucket.core.service.{RepositoryService, MilestonesService, AccountService}
|
import gitbucket.core.service.IssuesService.{IssueLimit, IssueSearchCondition}
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
import gitbucket.core.service.{
|
||||||
|
AccountService,
|
||||||
|
CommitStatusService,
|
||||||
|
IssueSearchOption,
|
||||||
|
MilestonesService,
|
||||||
|
RepositoryService
|
||||||
|
}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
|
import gitbucket.core.view.helpers.{getAssignableUserNames, getLabels, getPriorities, searchIssue}
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
class MilestonesController
|
class MilestonesController
|
||||||
extends MilestonesControllerBase
|
extends MilestonesControllerBase
|
||||||
with MilestonesService
|
with MilestonesService
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
with AccountService
|
with AccountService
|
||||||
|
with CommitStatusService
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
|
|
||||||
trait MilestonesControllerBase extends ControllerBase {
|
trait MilestonesControllerBase extends ControllerBase {
|
||||||
self: MilestonesService with RepositoryService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
self: MilestonesService
|
||||||
|
with RepositoryService
|
||||||
|
with CommitStatusService
|
||||||
|
with ReferrerAuthenticator
|
||||||
|
with WritableUsersAuthenticator =>
|
||||||
|
|
||||||
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
case class MilestoneForm(title: String, description: Option[String], dueDate: Option[java.util.Date])
|
||||||
|
|
||||||
val milestoneForm = mapping(
|
val milestoneForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required, maxlength(100), uniqueMilestone))),
|
||||||
"description" -> trim(label("Description", optional(text()))),
|
"description" -> trim(label("Description", optional(text()))),
|
||||||
"dueDate" -> trim(label("Due Date", optional(date())))
|
"dueDate" -> trim(label("Due Date", optional(date())))
|
||||||
)(MilestoneForm.apply)
|
)(MilestoneForm.apply)
|
||||||
@@ -34,6 +49,41 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
get("/:owner/:repository/milestone/:id")(referrersOnly { repository =>
|
||||||
|
val milestone = getMilestone(repository.owner, repository.name, params("id").toInt)
|
||||||
|
val page = IssueSearchCondition.page(request)
|
||||||
|
val condition = IssueSearchCondition(
|
||||||
|
request,
|
||||||
|
milestone.get.title
|
||||||
|
)
|
||||||
|
val issues = searchIssue(
|
||||||
|
condition,
|
||||||
|
IssueSearchOption.Both,
|
||||||
|
(page - 1) * IssueLimit,
|
||||||
|
IssueLimit,
|
||||||
|
repository.owner -> repository.name
|
||||||
|
)
|
||||||
|
val status = issues.map { issue =>
|
||||||
|
issue.commitId.flatMap { commitId =>
|
||||||
|
getCommitStatusWithSummary(issue.issue.userName, issue.issue.repositoryName, commitId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
html.milestone(
|
||||||
|
condition.state,
|
||||||
|
issues.zip(status),
|
||||||
|
page,
|
||||||
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
|
getPriorities(repository.owner, repository.name),
|
||||||
|
getLabels(repository.owner, repository.name),
|
||||||
|
condition,
|
||||||
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
|
.filter(p => p._1.milestoneId == milestone.get.milestoneId),
|
||||||
|
repository,
|
||||||
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/milestones/new")(writableUsersOnly {
|
get("/:owner/:repository/issues/milestones/new")(writableUsersOnly {
|
||||||
html.edit(None, _)
|
html.edit(None, _)
|
||||||
})
|
})
|
||||||
@@ -86,4 +136,29 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private def uniqueMilestone: Constraint = new Constraint() {
|
||||||
|
override def validate(
|
||||||
|
name: String,
|
||||||
|
value: String,
|
||||||
|
params: Map[String, Seq[String]],
|
||||||
|
messages: Messages
|
||||||
|
): Option[String] = {
|
||||||
|
for {
|
||||||
|
owner <- params.optionValue("owner")
|
||||||
|
repository <- params.optionValue("repository")
|
||||||
|
_ <- params.optionValue("milestoneId") match {
|
||||||
|
// existing milestone
|
||||||
|
case Some(id) =>
|
||||||
|
getMilestones(owner, repository)
|
||||||
|
.find(m => m.title.equalsIgnoreCase(value) && m.milestoneId.toString != id)
|
||||||
|
// new milestone
|
||||||
|
case None =>
|
||||||
|
getMilestones(owner, repository)
|
||||||
|
.find(m => m.title.equalsIgnoreCase(value))
|
||||||
|
}
|
||||||
|
} yield {
|
||||||
|
"Milestone already exists."
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.model.{CommitComment, CommitComments, IssueComment, WebHook}
|
import gitbucket.core.model.activity.DeleteBranchInfo
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
|
||||||
import gitbucket.core.pulls.html
|
import gitbucket.core.pulls.html
|
||||||
import gitbucket.core.service.CommitStatusService
|
import gitbucket.core.service.CommitStatusService
|
||||||
import gitbucket.core.service.MergeService
|
import gitbucket.core.service.MergeService
|
||||||
@@ -15,11 +14,9 @@ import gitbucket.core.util.Implicits._
|
|||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.{ObjectId, PersonIdent}
|
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
|
||||||
import org.scalatra.BadRequest
|
import org.scalatra.BadRequest
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.util.Using
|
||||||
|
|
||||||
class PullRequestsController
|
class PullRequestsController
|
||||||
extends PullRequestsControllerBase
|
extends PullRequestsControllerBase
|
||||||
@@ -40,6 +37,7 @@ class PullRequestsController
|
|||||||
with MergeService
|
with MergeService
|
||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with PrioritiesService
|
with PrioritiesService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait PullRequestsControllerBase extends ControllerBase {
|
trait PullRequestsControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -69,6 +67,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
"requestBranch" -> trim(text(required, maxlength(100))),
|
"requestBranch" -> trim(text(required, maxlength(100))),
|
||||||
"commitIdFrom" -> trim(text(required, maxlength(40))),
|
"commitIdFrom" -> trim(text(required, maxlength(40))),
|
||||||
"commitIdTo" -> trim(text(required, maxlength(40))),
|
"commitIdTo" -> trim(text(required, maxlength(40))),
|
||||||
|
"isDraft" -> trim(boolean(required)),
|
||||||
"assignedUserName" -> trim(optional(text())),
|
"assignedUserName" -> trim(optional(text())),
|
||||||
"milestoneId" -> trim(optional(number())),
|
"milestoneId" -> trim(optional(number())),
|
||||||
"priorityId" -> trim(optional(number())),
|
"priorityId" -> trim(optional(number())),
|
||||||
@@ -77,7 +76,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
val mergeForm = mapping(
|
val mergeForm = mapping(
|
||||||
"message" -> trim(label("Message", text(required))),
|
"message" -> trim(label("Message", text(required))),
|
||||||
"strategy" -> trim(label("Strategy", text(required)))
|
"strategy" -> trim(label("Strategy", text(required))),
|
||||||
|
"isDraft" -> trim(boolean(required))
|
||||||
)(MergeForm.apply)
|
)(MergeForm.apply)
|
||||||
|
|
||||||
case class PullRequestForm(
|
case class PullRequestForm(
|
||||||
@@ -90,13 +90,14 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
requestBranch: String,
|
requestBranch: String,
|
||||||
commitIdFrom: String,
|
commitIdFrom: String,
|
||||||
commitIdTo: String,
|
commitIdTo: String,
|
||||||
|
isDraft: Boolean,
|
||||||
assignedUserName: Option[String],
|
assignedUserName: Option[String],
|
||||||
milestoneId: Option[Int],
|
milestoneId: Option[Int],
|
||||||
priorityId: Option[Int],
|
priorityId: Option[Int],
|
||||||
labelNames: Option[String]
|
labelNames: Option[String]
|
||||||
)
|
)
|
||||||
|
|
||||||
case class MergeForm(message: String, strategy: String)
|
case class MergeForm(message: String, strategy: String, isDraft: Boolean)
|
||||||
|
|
||||||
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
||||||
val q = request.getParameter("q")
|
val q = request.getParameter("q")
|
||||||
@@ -133,7 +134,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
||||||
repository,
|
repository,
|
||||||
getRepository(pullreq.requestUserName, pullreq.requestRepositoryName),
|
getRepository(pullreq.requestUserName, pullreq.requestRepositoryName),
|
||||||
flash.toMap.map(f => f._1 -> f._2.toString)
|
flash.iterator.map(f => f._1 -> f._2.toString).toMap
|
||||||
)
|
)
|
||||||
|
|
||||||
// html.pullreq(
|
// html.pullreq(
|
||||||
@@ -168,10 +169,16 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
||||||
|
|
||||||
|
val commitsWithStatus = commits.map { day =>
|
||||||
|
day.map { commit =>
|
||||||
|
(commit, getCommitStatusWithSummary(repository.owner, repository.name, commit.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
html.commits(
|
html.commits(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
commits,
|
commitsWithStatus,
|
||||||
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
||||||
diffs.size,
|
diffs.size,
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
@@ -218,7 +225,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.branch)
|
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.branch)
|
||||||
val mergeStatus = PullRequestService.MergeStatus(
|
val mergeStatus = PullRequestService.MergeStatus(
|
||||||
conflictMessage = conflictMessage,
|
conflictMessage = conflictMessage,
|
||||||
commitStatues = getCommitStatues(owner, name, pullreq.commitIdTo),
|
commitStatuses = getCommitStatuses(owner, name, pullreq.commitIdTo),
|
||||||
branchProtection = branchProtection,
|
branchProtection = branchProtection,
|
||||||
branchIsOutOfDate = JGitUtil.getShaByRef(owner, name, pullreq.branch) != Some(pullreq.commitIdFrom),
|
branchIsOutOfDate = JGitUtil.getShaByRef(owner, name, pullreq.branch) != Some(pullreq.commitIdFrom),
|
||||||
needStatusCheck = context.loginAccount
|
needStatusCheck = context.loginAccount
|
||||||
@@ -266,13 +273,14 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val repository = getRepository(owner, name).get
|
val repository = getRepository(owner, name).get
|
||||||
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.requestBranch)
|
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.requestBranch)
|
||||||
if (branchProtection.enabled) {
|
if (branchProtection.enabled) {
|
||||||
flash += "error" -> s"branch ${pullreq.requestBranch} is protected."
|
flash.update("error", s"branch ${pullreq.requestBranch} is protected.")
|
||||||
} else {
|
} else {
|
||||||
if (repository.repository.defaultBranch != pullreq.requestBranch) {
|
if (repository.repository.defaultBranch != pullreq.requestBranch) {
|
||||||
val userName = context.loginAccount.get.userName
|
val userName = context.loginAccount.get.userName
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.branchDelete().setForce(true).setBranchNames(pullreq.requestBranch).call()
|
git.branchDelete().setForce(true).setBranchNames(pullreq.requestBranch).call()
|
||||||
recordDeleteBranchActivity(repository.owner, repository.name, userName, pullreq.requestBranch)
|
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, pullreq.requestBranch)
|
||||||
|
recordActivity(deleteBranchInfo)
|
||||||
}
|
}
|
||||||
createComment(
|
createComment(
|
||||||
baseRepository.owner,
|
baseRepository.owner,
|
||||||
@@ -283,9 +291,10 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
"delete_branch"
|
"delete_branch"
|
||||||
)
|
)
|
||||||
} else {
|
} else {
|
||||||
flash += "error" -> s"""Can't delete the default branch "${pullreq.requestBranch}"."""
|
flash.update("error", s"""Can't delete the default branch "${pullreq.requestBranch}".""")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${baseRepository.owner}/${baseRepository.name}/pull/${issueId}")
|
redirect(s"/${baseRepository.owner}/${baseRepository.name}/pull/${issueId}")
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -303,7 +312,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} yield {
|
} yield {
|
||||||
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.requestBranch)
|
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.requestBranch)
|
||||||
if (branchProtection.needStatusCheck(loginAccount.userName)) {
|
if (branchProtection.needStatusCheck(loginAccount.userName)) {
|
||||||
flash += "error" -> s"branch ${pullreq.requestBranch} is protected need status check."
|
flash.update("error", s"branch ${pullreq.requestBranch} is protected need status check.")
|
||||||
} else {
|
} else {
|
||||||
LockUtil.lock(s"${owner}/${name}") {
|
LockUtil.lock(s"${owner}/${name}") {
|
||||||
val alias =
|
val alias =
|
||||||
@@ -312,9 +321,11 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
s"${pullreq.userName}:${pullreq.branch}"
|
s"${pullreq.userName}:${pullreq.branch}"
|
||||||
}
|
}
|
||||||
val existIds = using(Git.open(Directory.getRepositoryDir(owner, name))) { git =>
|
val existIds = Using
|
||||||
JGitUtil.getAllCommitIds(git)
|
.resource(Git.open(Directory.getRepositoryDir(owner, name))) { git =>
|
||||||
}.toSet
|
JGitUtil.getAllCommitIds(git)
|
||||||
|
}
|
||||||
|
.toSet
|
||||||
pullRemote(
|
pullRemote(
|
||||||
repository,
|
repository,
|
||||||
pullreq.requestBranch,
|
pullreq.requestBranch,
|
||||||
@@ -322,14 +333,15 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
pullreq.branch,
|
pullreq.branch,
|
||||||
loginAccount,
|
loginAccount,
|
||||||
s"Merge branch '${alias}' into ${pullreq.requestBranch}",
|
s"Merge branch '${alias}' into ${pullreq.requestBranch}",
|
||||||
Some(pullreq)
|
Some(pullreq),
|
||||||
|
context.settings
|
||||||
) match {
|
) match {
|
||||||
case None => // conflict
|
case None => // conflict
|
||||||
flash += "error" -> s"Can't automatic merging branch '${alias}' into ${pullreq.requestBranch}."
|
flash.update("error", s"Can't automatic merging branch '${alias}' into ${pullreq.requestBranch}.")
|
||||||
case Some(oldId) =>
|
case Some(oldId) =>
|
||||||
// update pull request
|
// update pull request
|
||||||
updatePullRequests(owner, name, pullreq.requestBranch, loginAccount, "synchronize")
|
updatePullRequests(owner, name, pullreq.requestBranch, loginAccount, "synchronize", context.settings)
|
||||||
flash += "info" -> s"Merge branch '${alias}' into ${pullreq.requestBranch}"
|
flash.update("info", s"Merge branch '${alias}' into ${pullreq.requestBranch}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -338,14 +350,34 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
post("/:owner/:repository/pull/:id/update_draft")(readableUsersOnly { baseRepository =>
|
||||||
|
(for {
|
||||||
|
issueId <- params("id").toIntOpt
|
||||||
|
(_, pullreq) <- getPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
||||||
|
owner = pullreq.requestUserName
|
||||||
|
name = pullreq.requestRepositoryName
|
||||||
|
if hasDeveloperRole(owner, name, context.loginAccount)
|
||||||
|
} yield {
|
||||||
|
updateDraftToPullRequest(baseRepository.owner, baseRepository.name, issueId)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
||||||
params("id").toIntOpt.flatMap { issueId =>
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
val owner = repository.owner
|
val owner = repository.owner
|
||||||
val name = repository.name
|
val name = repository.name
|
||||||
|
|
||||||
mergePullRequest(repository, issueId, context.loginAccount.get, form.message, form.strategy) match {
|
mergePullRequest(
|
||||||
|
repository,
|
||||||
|
issueId,
|
||||||
|
context.loginAccount.get,
|
||||||
|
form.message,
|
||||||
|
form.strategy,
|
||||||
|
form.isDraft,
|
||||||
|
context.settings
|
||||||
|
) match {
|
||||||
case Right(objectId) => redirect(s"/${owner}/${name}/pull/${issueId}")
|
case Right(objectId) => redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||||
case Left(message) => Some(BadRequest())
|
case Left(message) => Some(BadRequest(message))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -356,7 +388,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
case (Some(originUserName), Some(originRepositoryName)) => {
|
case (Some(originUserName), Some(originRepositoryName)) => {
|
||||||
getRepository(originUserName, originRepositoryName).map {
|
getRepository(originUserName, originRepositoryName).map {
|
||||||
originRepository =>
|
originRepository =>
|
||||||
using(
|
Using.resources(
|
||||||
Git.open(getRepositoryDir(originUserName, originRepositoryName)),
|
Git.open(getRepositoryDir(originUserName, originRepositoryName)),
|
||||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||||
) { (oldGit, newGit) =>
|
) { (oldGit, newGit) =>
|
||||||
@@ -372,7 +404,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
case _ => {
|
case _ => {
|
||||||
using(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
||||||
JGitUtil.getDefaultBranch(git, forkedRepository).map {
|
JGitUtil.getDefaultBranch(git, forkedRepository).map {
|
||||||
case (_, defaultBranch) =>
|
case (_, defaultBranch) =>
|
||||||
redirect(
|
redirect(
|
||||||
@@ -464,6 +496,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
getAssignableUserNames(originRepository.owner, originRepository.name),
|
getAssignableUserNames(originRepository.owner, originRepository.name),
|
||||||
getMilestones(originRepository.owner, originRepository.name),
|
getMilestones(originRepository.owner, originRepository.name),
|
||||||
getPriorities(originRepository.owner, originRepository.name),
|
getPriorities(originRepository.owner, originRepository.name),
|
||||||
|
getDefaultPriority(originRepository.owner, originRepository.name),
|
||||||
getLabels(originRepository.owner, originRepository.name)
|
getLabels(originRepository.owner, originRepository.name)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
@@ -493,7 +526,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
||||||
using(
|
Using.resources(
|
||||||
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
Git.open(getRepositoryDir(originRepository.owner, originRepository.name)),
|
||||||
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))
|
||||||
) {
|
) {
|
||||||
@@ -542,7 +575,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
requestBranch = form.requestBranch,
|
requestBranch = form.requestBranch,
|
||||||
commitIdFrom = form.commitIdFrom,
|
commitIdFrom = form.commitIdFrom,
|
||||||
commitIdTo = form.commitIdTo,
|
commitIdTo = form.commitIdTo,
|
||||||
loginAccount = context.loginAccount.get
|
isDraft = form.isDraft,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
)
|
)
|
||||||
|
|
||||||
// insert labels
|
// insert labels
|
||||||
@@ -567,7 +602,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
context.loginAccount.map(x => Seq(x.mailAddress) ++ getAccountExtraMailAddresses(x.userName)).getOrElse(Nil)
|
context.loginAccount.map(x => Seq(x.mailAddress) ++ getAccountExtraMailAddresses(x.userName)).getOrElse(Nil)
|
||||||
|
|
||||||
val branches =
|
val branches =
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getBranches(
|
.getBranches(
|
||||||
@@ -608,20 +643,33 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
defining(repository.owner, repository.name) {
|
defining(repository.owner, repository.name) {
|
||||||
case (owner, repoName) =>
|
case (owner, repoName) =>
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
|
|
||||||
// retrieve search condition
|
// retrieve search condition
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
|
// search issues
|
||||||
|
val issues = searchIssue(
|
||||||
|
condition,
|
||||||
|
IssueSearchOption.PullRequests,
|
||||||
|
(page - 1) * PullRequestLimit,
|
||||||
|
PullRequestLimit,
|
||||||
|
owner -> repoName
|
||||||
|
)
|
||||||
|
// commit status
|
||||||
|
val status = issues.map { issue =>
|
||||||
|
issue.commitId.flatMap { commitId =>
|
||||||
|
getCommitStatusWithSummary(owner, repoName, commitId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
gitbucket.core.issues.html.list(
|
gitbucket.core.issues.html.list(
|
||||||
"pulls",
|
"pulls",
|
||||||
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, owner -> repoName),
|
issues.zip(status),
|
||||||
page,
|
page,
|
||||||
getAssignableUserNames(owner, repoName),
|
getAssignableUserNames(owner, repoName),
|
||||||
getMilestones(owner, repoName),
|
getMilestones(owner, repoName),
|
||||||
getPriorities(owner, repoName),
|
getPriorities(owner, repoName),
|
||||||
getLabels(owner, repoName),
|
getLabels(owner, repoName),
|
||||||
countIssue(condition.copy(state = "open"), true, owner -> repoName),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, owner -> repoName),
|
||||||
countIssue(condition.copy(state = "closed"), true, owner -> repoName),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, owner -> repoName),
|
||||||
condition,
|
condition,
|
||||||
repository,
|
repository,
|
||||||
isEditable(repository),
|
isEditable(repository),
|
||||||
|
|||||||
@@ -2,16 +2,25 @@ package gitbucket.core.controller
|
|||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
import gitbucket.core.service.{AccountService, ActivityService, ReleaseService, RepositoryService}
|
import gitbucket.core.model.activity.ReleaseInfo
|
||||||
|
import gitbucket.core.service.{
|
||||||
|
AccountService,
|
||||||
|
ActivityService,
|
||||||
|
PaginationHelper,
|
||||||
|
ReleaseService,
|
||||||
|
RepositoryService,
|
||||||
|
RequestCache
|
||||||
|
}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import gitbucket.core.releases.html
|
import gitbucket.core.releases.html
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
class ReleaseController
|
class ReleaseController
|
||||||
extends ReleaseControllerBase
|
extends ReleaseControllerBase
|
||||||
with RepositoryService
|
with RepositoryService
|
||||||
@@ -21,6 +30,7 @@ class ReleaseController
|
|||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait ReleaseControllerBase extends ControllerBase {
|
trait ReleaseControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -42,17 +52,14 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
)(ReleaseForm.apply)
|
)(ReleaseForm.apply)
|
||||||
|
|
||||||
get("/:owner/:repository/releases")(referrersOnly { repository =>
|
get("/:owner/:repository/releases")(referrersOnly { repository =>
|
||||||
val releases = getReleases(repository.owner, repository.name)
|
val page = PaginationHelper.page(params.get("page"))
|
||||||
val assets = getReleaseAssetsMap(repository.owner, repository.name)
|
|
||||||
|
|
||||||
html.list(
|
html.list(
|
||||||
repository,
|
repository,
|
||||||
repository.tags.reverse.map { tag =>
|
fetchReleases(repository, page),
|
||||||
(tag, releases.find(_.tag == tag.name).map { release =>
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
||||||
(release, assets(release))
|
page,
|
||||||
})
|
repository.tags.size
|
||||||
},
|
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -106,7 +113,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
||||||
|
|
||||||
// Insert into RELEASE_ASSET
|
// Insert into RELEASE_ASSET
|
||||||
val files = params.collect {
|
val files = params.toMap.collect {
|
||||||
case (name, value) if name.startsWith("file:") =>
|
case (name, value) if name.startsWith("file:") =>
|
||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
@@ -121,7 +128,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
createReleaseAsset(repository.owner, repository.name, tagName, fileId, fileName, size, loginAccount)
|
||||||
}
|
}
|
||||||
|
|
||||||
recordReleaseActivity(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
val releaseInfo = ReleaseInfo(repository.owner, repository.name, loginAccount.userName, form.name, tagName)
|
||||||
|
recordActivity(releaseInfo)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
||||||
})
|
})
|
||||||
@@ -130,7 +138,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
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 previousTagId = repository.tags.collectFirst { case x if x.name == previousTag => x.id }.getOrElse("")
|
||||||
|
|
||||||
val commitLog = using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
val commitLog = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val commits = JGitUtil.getCommitLog(git, previousTagId, currentTag).reverse
|
val commits = JGitUtil.getCommitLog(git, previousTagId, currentTag).reverse
|
||||||
commits
|
commits
|
||||||
.map { commit =>
|
.map { commit =>
|
||||||
@@ -174,7 +182,7 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
val assets = getReleaseAssets(repository.owner, repository.name, tagName)
|
val assets = getReleaseAssets(repository.owner, repository.name, tagName)
|
||||||
deleteReleaseAssets(repository.owner, repository.name, tagName)
|
deleteReleaseAssets(repository.owner, repository.name, tagName)
|
||||||
|
|
||||||
val files = params.collect {
|
val files = params.toMap.collect {
|
||||||
case (name, value) if name.startsWith("file:") =>
|
case (name, value) if name.startsWith("file:") =>
|
||||||
val Array(_, fileId) = name.split(":")
|
val Array(_, fileId) = name.split(":")
|
||||||
(fileId, value)
|
(fileId, value)
|
||||||
@@ -215,4 +223,21 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
redirect(s"/${repository.owner}/${repository.name}/releases")
|
redirect(s"/${repository.owner}/${repository.name}/releases")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
||||||
|
|
||||||
|
import gitbucket.core.service.ReleaseService._
|
||||||
|
|
||||||
|
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
||||||
|
val tagsToDisplay = repository.tags.reverse.slice(offset, offset + limit)
|
||||||
|
|
||||||
|
val releases = getReleases(repository.owner, repository.name, tagsToDisplay)
|
||||||
|
val assets = getReleaseAssetsMap(repository.owner, repository.name, releases)
|
||||||
|
|
||||||
|
val tagsWithReleases = tagsToDisplay.map { tag =>
|
||||||
|
(tag, releases.find(_.tag == tag.name).map { release =>
|
||||||
|
(release, assets(release))
|
||||||
|
})
|
||||||
|
}
|
||||||
|
tagsWithReleases
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,12 +12,16 @@ import gitbucket.core.util.JGitUtil._
|
|||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
|
import gitbucket.core.model.WebHookContentType
|
||||||
|
import gitbucket.core.model.activity.RenameRepositoryInfo
|
||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.Constants
|
import org.eclipse.jgit.lib.Constants
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
import gitbucket.core.model.WebHookContentType
|
|
||||||
|
import scala.util.Using
|
||||||
|
import org.scalatra.Forbidden
|
||||||
|
|
||||||
class RepositorySettingsController
|
class RepositorySettingsController
|
||||||
extends RepositorySettingsControllerBase
|
extends RepositorySettingsControllerBase
|
||||||
@@ -27,8 +31,10 @@ class RepositorySettingsController
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
|
with ActivityService
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait RepositorySettingsControllerBase extends ControllerBase {
|
trait RepositorySettingsControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -37,12 +43,12 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
|
with ActivityService
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator =>
|
with UsersAuthenticator =>
|
||||||
|
|
||||||
// for repository options
|
// for repository options
|
||||||
case class OptionsForm(
|
case class OptionsForm(
|
||||||
repositoryName: String,
|
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
isPrivate: Boolean,
|
isPrivate: Boolean,
|
||||||
issuesOption: String,
|
issuesOption: String,
|
||||||
@@ -55,9 +61,6 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val optionsForm = mapping(
|
val optionsForm = mapping(
|
||||||
"repositoryName" -> trim(
|
|
||||||
label("Repository Name", text(required, maxlength(100), repository, renameRepositoryName))
|
|
||||||
),
|
|
||||||
"description" -> trim(label("Description", optional(text()))),
|
"description" -> trim(label("Description", optional(text()))),
|
||||||
"isPrivate" -> trim(label("Repository Type", boolean())),
|
"isPrivate" -> trim(label("Repository Type", boolean())),
|
||||||
"issuesOption" -> trim(label("Issues Option", text(required, featureOption))),
|
"issuesOption" -> trim(label("Issues Option", text(required, featureOption))),
|
||||||
@@ -98,9 +101,16 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"events" -> webhookEvents,
|
"events" -> webhookEvents,
|
||||||
"ctype" -> label("ctype", text()),
|
"ctype" -> label("ctype", text()),
|
||||||
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
"token" -> optional(trim(label("token", text(maxlength(100)))))
|
||||||
)(
|
)((url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token))
|
||||||
(url, events, ctype, token) => WebHookForm(url, events, WebHookContentType.valueOf(ctype), token)
|
|
||||||
|
// for rename repository
|
||||||
|
case class RenameRepositoryForm(repositoryName: String)
|
||||||
|
|
||||||
|
val renameForm = mapping(
|
||||||
|
"repositoryName" -> trim(
|
||||||
|
label("New repository name", text(required, maxlength(100), repository, renameRepositoryName))
|
||||||
)
|
)
|
||||||
|
)(RenameRepositoryForm.apply)
|
||||||
|
|
||||||
// for transfer ownership
|
// for transfer ownership
|
||||||
case class TransferOwnerShipForm(newOwner: String)
|
case class TransferOwnerShipForm(newOwner: String)
|
||||||
@@ -142,13 +152,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
form.mergeOptions,
|
form.mergeOptions,
|
||||||
form.defaultMergeOption
|
form.defaultMergeOption
|
||||||
)
|
)
|
||||||
// Change repository name
|
flash.update("info", "Repository settings has been updated.")
|
||||||
if (repository.name != form.repositoryName) {
|
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||||
// Update database
|
|
||||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
|
||||||
}
|
|
||||||
flash += "info" -> "Repository settings has been updated."
|
|
||||||
redirect(s"/${repository.owner}/${form.repositoryName}/settings/options")
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/** branch settings */
|
/** branch settings */
|
||||||
@@ -164,23 +169,24 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
|
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
|
||||||
// Change repository HEAD
|
// Change repository HEAD
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.getRepository.updateRef(Constants.HEAD, true).link(Constants.R_HEADS + form.defaultBranch)
|
git.getRepository.updateRef(Constants.HEAD, true).link(Constants.R_HEADS + form.defaultBranch)
|
||||||
}
|
}
|
||||||
flash += "info" -> "Repository default branch has been updated."
|
flash.update("info", "Repository default branch has been updated.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/** Branch protection for branch */
|
/** Branch protection for branch */
|
||||||
get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/branches/*")(ownerOnly { repository =>
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
val branch = params("branch")
|
val branch = params("splat")
|
||||||
|
|
||||||
if (!repository.branchList.contains(branch)) {
|
if (!repository.branchList.contains(branch)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||||
} else {
|
} else {
|
||||||
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||||
val lastWeeks = getRecentStatuesContexts(
|
val lastWeeks = getRecentStatusContexts(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
Date.from(LocalDateTime.now.minusWeeks(1).toInstant(ZoneOffset.UTC))
|
Date.from(LocalDateTime.now.minusWeeks(1).toInstant(ZoneOffset.UTC))
|
||||||
@@ -222,7 +228,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the web hook edit page.
|
* Display the web hook edit page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/new")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks/new")(ownerOnly { repository =>
|
||||||
val webhook = RepositoryWebHook(repository.owner, repository.name, "", WebHookContentType.FORM, None)
|
val webhook = RepositoryWebHook(
|
||||||
|
userName = repository.owner,
|
||||||
|
repositoryName = repository.name,
|
||||||
|
url = "",
|
||||||
|
ctype = WebHookContentType.FORM,
|
||||||
|
token = None
|
||||||
|
)
|
||||||
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
html.edithook(webhook, Set(WebHook.Push), repository, true)
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -231,7 +243,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/hooks/new", webHookForm(false))(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/hooks/new", webHookForm(false))(ownerOnly { (form, repository) =>
|
||||||
addWebHook(repository.owner, repository.name, form.url, form.events, form.ctype, form.token)
|
addWebHook(repository.owner, repository.name, form.url, form.events, form.ctype, form.token)
|
||||||
flash += "info" -> s"Webhook ${form.url} created"
|
flash.update("info", s"Webhook ${form.url} created")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -240,7 +252,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/delete")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks/delete")(ownerOnly { repository =>
|
||||||
deleteWebHook(repository.owner, repository.name, params("url"))
|
deleteWebHook(repository.owner, repository.name, params("url"))
|
||||||
flash += "info" -> s"Webhook ${params("url")} deleted"
|
flash.update("info", s"Webhook ${params("url")} deleted")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -248,15 +260,16 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Send the test request to registered web hook URLs.
|
* Send the test request to registered web hook URLs.
|
||||||
*/
|
*/
|
||||||
ajaxPost("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
ajaxPost("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
||||||
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] = h.map { h =>
|
def _headers(h: Array[org.apache.http.Header]): Array[Array[String]] =
|
||||||
Array(h.getName, h.getValue)
|
h.map { h =>
|
||||||
}
|
Array(h.getName, h.getValue)
|
||||||
|
}
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
import scala.collection.JavaConverters._
|
|
||||||
import scala.concurrent.duration._
|
import scala.concurrent.duration._
|
||||||
import scala.concurrent._
|
import scala.concurrent._
|
||||||
|
import scala.jdk.CollectionConverters._
|
||||||
import scala.util.control.NonFatal
|
import scala.util.control.NonFatal
|
||||||
import org.apache.http.util.EntityUtils
|
import org.apache.http.util.EntityUtils
|
||||||
import scala.concurrent.ExecutionContext.Implicits.global
|
import scala.concurrent.ExecutionContext.Implicits.global
|
||||||
@@ -264,7 +277,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
val url = params("url")
|
val url = params("url")
|
||||||
val token = Some(params("token"))
|
val token = Some(params("token"))
|
||||||
val ctype = WebHookContentType.valueOf(params("ctype"))
|
val ctype = WebHookContentType.valueOf(params("ctype"))
|
||||||
val dummyWebHookInfo = RepositoryWebHook(repository.owner, repository.name, url, ctype, token)
|
val dummyWebHookInfo = RepositoryWebHook(
|
||||||
|
userName = repository.owner,
|
||||||
|
repositoryName = repository.name,
|
||||||
|
url = url,
|
||||||
|
ctype = ctype,
|
||||||
|
token = token
|
||||||
|
)
|
||||||
val dummyPayload = {
|
val dummyPayload = {
|
||||||
val ownerAccount = getAccountByUserName(repository.owner).get
|
val ownerAccount = getAccountByUserName(repository.owner).get
|
||||||
val commits =
|
val commits =
|
||||||
@@ -292,13 +311,14 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
val (webHook, json, reqFuture, resFuture) = callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload).head
|
val (webHook, json, reqFuture, resFuture) =
|
||||||
|
callWebHook(WebHook.Push, List(dummyWebHookInfo), dummyPayload, context.settings).head
|
||||||
|
|
||||||
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
val toErrorMap: PartialFunction[Throwable, Map[String, String]] = {
|
||||||
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
case e: java.net.UnknownHostException => Map("error" -> ("Unknown host " + e.getMessage))
|
||||||
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
case e: java.lang.IllegalArgumentException => Map("error" -> ("invalid url"))
|
||||||
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
case e: org.apache.http.client.ClientProtocolException => Map("error" -> ("invalid url"))
|
||||||
case NonFatal(e) => Map("error" -> (e.getClass + " " + e.getMessage))
|
case NonFatal(e) => Map("error" -> (s"${e.getClass} ${e.getMessage}"))
|
||||||
}
|
}
|
||||||
|
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -350,7 +370,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/hooks/edit", webHookForm(true))(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/hooks/edit", webHookForm(true))(ownerOnly { (form, repository) =>
|
||||||
updateWebHook(repository.owner, repository.name, form.url, form.events, form.ctype, form.token)
|
updateWebHook(repository.owner, repository.name, form.url, form.events, form.ctype, form.token)
|
||||||
flash += "info" -> s"webhook ${form.url} updated"
|
flash.update("info", s"webhook ${form.url} updated")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -361,24 +381,58 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
html.danger(_, flash.get("info"))
|
html.danger(_, flash.get("info"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Rename repository.
|
||||||
|
*/
|
||||||
|
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
||||||
|
if (context.settings.repositoryOperation.rename || context.loginAccount.get.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,
|
||||||
|
context.loginAccount.get.userName,
|
||||||
|
repository.name
|
||||||
|
)
|
||||||
|
recordActivity(renameInfo)
|
||||||
|
}
|
||||||
|
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||||
|
} else Forbidden()
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfer repository ownership.
|
* Transfer repository ownership.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
||||||
// Change repository owner
|
if (context.settings.repositoryOperation.transfer || context.loginAccount.get.isAdmin) {
|
||||||
if (repository.owner != form.newOwner) {
|
// Change repository owner
|
||||||
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
if (repository.owner != form.newOwner) {
|
||||||
}
|
// Update database and move git repository
|
||||||
redirect(s"/${form.newOwner}/${repository.name}")
|
renameRepository(repository.owner, repository.name, form.newOwner, repository.name)
|
||||||
|
// Record activity log
|
||||||
|
val renameInfo = RenameRepositoryInfo(
|
||||||
|
form.newOwner,
|
||||||
|
repository.name,
|
||||||
|
context.loginAccount.get.userName,
|
||||||
|
repository.owner
|
||||||
|
)
|
||||||
|
recordActivity(renameInfo)
|
||||||
|
}
|
||||||
|
redirect(s"/${form.newOwner}/${repository.name}")
|
||||||
|
} else Forbidden()
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the repository.
|
* Delete the repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
||||||
// Delete the repository and related files
|
if (context.settings.repositoryOperation.delete || context.loginAccount.get.isAdmin) {
|
||||||
deleteRepository(repository.repository)
|
// Delete the repository and related files
|
||||||
redirect(s"/${repository.owner}")
|
deleteRepository(repository.repository)
|
||||||
|
redirect(s"/${repository.owner}")
|
||||||
|
} else Forbidden()
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -386,11 +440,11 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/gc")(ownerOnly { repository =>
|
post("/:owner/:repository/settings/gc")(ownerOnly { repository =>
|
||||||
LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.gc().call()
|
git.gc().call()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
flash += "info" -> "Garbage collection has been executed."
|
flash.update("info", "Garbage collection has been executed.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/danger")
|
redirect(s"/${repository.owner}/${repository.name}/settings/danger")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -415,32 +469,34 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Provides duplication check for web hook url.
|
* Provides duplication check for web hook url.
|
||||||
*/
|
*/
|
||||||
private def webHook(needExists: Boolean): Constraint = new Constraint() {
|
private def webHook(needExists: Boolean): Constraint =
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
new Constraint() {
|
||||||
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
Some(if (needExists) {
|
if (getWebHook(params("owner"), params("repository"), value).isDefined != needExists) {
|
||||||
"URL had not been registered yet."
|
Some(if (needExists) {
|
||||||
|
"URL had not been registered yet."
|
||||||
|
} else {
|
||||||
|
"URL had been registered already."
|
||||||
|
})
|
||||||
} else {
|
} else {
|
||||||
"URL had been registered already."
|
None
|
||||||
})
|
}
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def webhookEvents = new ValueType[Set[WebHook.Event]] {
|
|
||||||
def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Set[WebHook.Event] = {
|
|
||||||
WebHook.Event.values.flatMap { t =>
|
|
||||||
params.get(name + "." + t.name).map(_ => t)
|
|
||||||
}.toSet
|
|
||||||
}
|
}
|
||||||
def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] =
|
|
||||||
if (convert(name, params, messages).isEmpty) {
|
private def webhookEvents =
|
||||||
Seq(name -> messages("error.required").format(name))
|
new ValueType[Set[WebHook.Event]] {
|
||||||
} else {
|
def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Set[WebHook.Event] = {
|
||||||
Nil
|
WebHook.Event.values.flatMap { t =>
|
||||||
|
params.get(name + "." + t.name).map(_ => t)
|
||||||
|
}.toSet
|
||||||
}
|
}
|
||||||
}
|
def validate(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[(String, String)] =
|
||||||
|
if (convert(name, params, messages).isEmpty) {
|
||||||
|
Seq(name -> messages("error.required").format(name))
|
||||||
|
} else {
|
||||||
|
Nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// /**
|
// /**
|
||||||
// * Provides Constraint to validate the collaborator name.
|
// * Provides Constraint to validate the collaborator name.
|
||||||
@@ -460,70 +516,77 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Duplicate check for the rename repository name.
|
* Duplicate check for the rename repository name.
|
||||||
*/
|
*/
|
||||||
private def renameRepositoryName: Constraint = new Constraint() {
|
private def renameRepositoryName: Constraint =
|
||||||
override def validate(
|
new Constraint() {
|
||||||
name: String,
|
override def validate(
|
||||||
value: String,
|
name: String,
|
||||||
params: Map[String, Seq[String]],
|
value: String,
|
||||||
messages: Messages
|
params: Map[String, Seq[String]],
|
||||||
): Option[String] = {
|
messages: Messages
|
||||||
for {
|
): Option[String] = {
|
||||||
repoName <- params.optionValue("repository") if repoName != value
|
for {
|
||||||
userName <- params.optionValue("owner")
|
repoName <- params.optionValue("repository") if repoName != value
|
||||||
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
userName <- params.optionValue("owner")
|
||||||
} yield {
|
_ <- getRepositoryNamesOfUser(userName).find(_ == value)
|
||||||
"Repository already exists."
|
} yield {
|
||||||
|
"Repository already exists."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
|
||||||
*/
|
*/
|
||||||
private def featureOption: Constraint = new Constraint() {
|
private def featureOption: Constraint =
|
||||||
override def validate(
|
new Constraint() {
|
||||||
name: String,
|
override def validate(
|
||||||
value: String,
|
name: String,
|
||||||
params: Map[String, Seq[String]],
|
value: String,
|
||||||
messages: Messages
|
params: Map[String, Seq[String]],
|
||||||
): Option[String] =
|
messages: Messages
|
||||||
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
): Option[String] =
|
||||||
}
|
if (Seq("DISABLE", "PRIVATE", "PUBLIC", "ALL").contains(value)) None else Some("Option is invalid.")
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Constraint to validate the repository transfer user.
|
* Provides Constraint to validate the repository transfer user.
|
||||||
*/
|
*/
|
||||||
private def transferUser: Constraint = new Constraint() {
|
private def transferUser: Constraint =
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
new Constraint() {
|
||||||
getAccountByUserName(value) match {
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
case None => Some("User does not exist.")
|
getAccountByUserName(value) match {
|
||||||
case Some(x) =>
|
case None => Some("User does not exist.")
|
||||||
if (x.userName == params("owner")) {
|
case Some(x) =>
|
||||||
Some("This is current repository owner.")
|
if (x.userName == params("owner")) {
|
||||||
} else {
|
Some("This is current repository owner.")
|
||||||
params.get("repository").flatMap { repositoryName =>
|
} else {
|
||||||
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
params.get("repository").flatMap { repositoryName =>
|
||||||
"User already has same repository."
|
getRepositoryNamesOfUser(x.userName).find(_ == repositoryName).map { _ =>
|
||||||
|
"User already has same repository."
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private def mergeOptions = new ValueType[Seq[String]] {
|
private def mergeOptions =
|
||||||
override def convert(name: String, params: Map[String, Seq[String]], messages: Messages): Seq[String] = {
|
new ValueType[Seq[String]] {
|
||||||
params.getOrElse("mergeOptions", Nil)
|
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)
|
override def validate(
|
||||||
if (mergeOptions.isEmpty) {
|
name: String,
|
||||||
Seq("mergeOptions" -> "At least one option must be enabled.")
|
params: Map[String, Seq[String]],
|
||||||
} else if (!mergeOptions.forall(x => Seq("merge-commit", "squash", "rebase").contains(x))) {
|
messages: Messages
|
||||||
Seq("mergeOptions" -> "mergeOptions are invalid.")
|
): Seq[(String, String)] = {
|
||||||
} else {
|
val mergeOptions = params.getOrElse("mergeOptions", Nil)
|
||||||
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,11 +1,12 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import java.io.File
|
import java.io.{File, FileInputStream, FileOutputStream}
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
|
||||||
import gitbucket.core.repo.html
|
import gitbucket.core.repo.html
|
||||||
import gitbucket.core.helper
|
import gitbucket.core.helper
|
||||||
|
import gitbucket.core.model.activity.DeleteBranchInfo
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
@@ -13,7 +14,8 @@ import gitbucket.core.util.StringUtil._
|
|||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.model.{Account, CommitState, CommitStatus}
|
import gitbucket.core.model.Account
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
import gitbucket.core.view.helpers
|
import gitbucket.core.view.helpers
|
||||||
@@ -59,6 +61,7 @@ class RepositoryViewerController
|
|||||||
with WebHookPullRequestService
|
with WebHookPullRequestService
|
||||||
with WebHookPullRequestReviewCommentService
|
with WebHookPullRequestReviewCommentService
|
||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository viewer.
|
* The repository viewer.
|
||||||
@@ -87,7 +90,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
branch: String,
|
branch: String,
|
||||||
path: String,
|
path: String,
|
||||||
uploadFiles: String,
|
uploadFiles: String,
|
||||||
message: Option[String]
|
message: Option[String],
|
||||||
|
commit: String,
|
||||||
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class EditorForm(
|
case class EditorForm(
|
||||||
@@ -99,7 +104,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
lineSeparator: String,
|
lineSeparator: String,
|
||||||
newFileName: String,
|
newFileName: String,
|
||||||
oldFileName: Option[String],
|
oldFileName: Option[String],
|
||||||
commit: String
|
commit: String,
|
||||||
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class DeleteForm(
|
case class DeleteForm(
|
||||||
@@ -107,7 +113,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
path: String,
|
path: String,
|
||||||
message: Option[String],
|
message: Option[String],
|
||||||
fileName: String,
|
fileName: String,
|
||||||
commit: String
|
commit: String,
|
||||||
|
newBranch: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
case class CommentForm(
|
case class CommentForm(
|
||||||
@@ -130,6 +137,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"uploadFiles" -> trim(label("Upload files", text(required))),
|
"uploadFiles" -> trim(label("Upload files", text(required))),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
|
"commit" -> trim(label("Commit", text(required, conflict))),
|
||||||
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(UploadForm.apply)
|
)(UploadForm.apply)
|
||||||
|
|
||||||
val editorForm = mapping(
|
val editorForm = mapping(
|
||||||
@@ -141,7 +150,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"lineSeparator" -> trim(label("Line Separator", text(required))),
|
"lineSeparator" -> trim(label("Line Separator", text(required))),
|
||||||
"newFileName" -> trim(label("Filename", text(required))),
|
"newFileName" -> trim(label("Filename", text(required))),
|
||||||
"oldFileName" -> trim(label("Old filename", optional(text()))),
|
"oldFileName" -> trim(label("Old filename", optional(text()))),
|
||||||
"commit" -> trim(label("Commit", text(required, conflict)))
|
"commit" -> trim(label("Commit", text(required, conflict))),
|
||||||
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(EditorForm.apply)
|
)(EditorForm.apply)
|
||||||
|
|
||||||
val deleteForm = mapping(
|
val deleteForm = mapping(
|
||||||
@@ -149,7 +159,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
"fileName" -> trim(label("Filename", text(required))),
|
"fileName" -> trim(label("Filename", text(required))),
|
||||||
"commit" -> trim(label("Commit", text(required, conflict)))
|
"commit" -> trim(label("Commit", text(required, conflict))),
|
||||||
|
"newBranch" -> trim(label("New Branch", boolean()))
|
||||||
)(DeleteForm.apply)
|
)(DeleteForm.apply)
|
||||||
|
|
||||||
val commentForm = mapping(
|
val commentForm = mapping(
|
||||||
@@ -251,23 +262,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val (branchName, path) = repository.splitPath(multiParams("splat").head)
|
val (branchName, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val page = params.get("page").flatMap(_.toIntOpt).getOrElse(1)
|
val page = params.get("page").flatMap(_.toIntOpt).getOrElse(1)
|
||||||
|
|
||||||
def getStatuses(sha: String): List[CommitStatus] = {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
getCommitStatues(repository.owner, repository.name, sha)
|
|
||||||
}
|
|
||||||
|
|
||||||
def getSummary(statuses: List[CommitStatus]): (CommitState, String) = {
|
|
||||||
val stateMap = statuses.groupBy(_.state)
|
|
||||||
val state = CommitState.combine(stateMap.keySet)
|
|
||||||
val summary = stateMap.map { case (keyState, states) => states.size + " " + keyState.name }.mkString(", ")
|
|
||||||
state -> summary
|
|
||||||
}
|
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
|
||||||
git =>
|
git =>
|
||||||
def getTags(sha: String): List[String] = {
|
|
||||||
JGitUtil.getTagsOnCommit(git, sha)
|
|
||||||
}
|
|
||||||
|
|
||||||
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
||||||
case Right((logs, hasNext)) =>
|
case Right((logs, hasNext)) =>
|
||||||
html.commits(
|
html.commits(
|
||||||
@@ -276,34 +272,33 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repository,
|
repository,
|
||||||
logs
|
logs
|
||||||
.map {
|
.map {
|
||||||
c =>
|
commit =>
|
||||||
CommitInfo(
|
(
|
||||||
id = c.id,
|
CommitInfo(
|
||||||
shortMessage = c.shortMessage,
|
id = commit.id,
|
||||||
fullMessage = c.fullMessage,
|
shortMessage = commit.shortMessage,
|
||||||
parents = c.parents,
|
fullMessage = commit.fullMessage,
|
||||||
authorTime = c.authorTime,
|
parents = commit.parents,
|
||||||
authorName = c.authorName,
|
authorTime = commit.authorTime,
|
||||||
authorEmailAddress = c.authorEmailAddress,
|
authorName = commit.authorName,
|
||||||
commitTime = c.commitTime,
|
authorEmailAddress = commit.authorEmailAddress,
|
||||||
committerName = c.committerName,
|
commitTime = commit.commitTime,
|
||||||
committerEmailAddress = c.committerEmailAddress,
|
committerName = commit.committerName,
|
||||||
commitSign = c.commitSign,
|
committerEmailAddress = commit.committerEmailAddress,
|
||||||
verified = c.commitSign
|
commitSign = commit.commitSign,
|
||||||
.flatMap { s =>
|
verified = commit.commitSign.flatMap(GpgUtil.verifySign)
|
||||||
GpgUtil.verifySign(s)
|
),
|
||||||
}
|
JGitUtil.getTagsOnCommit(git, commit.id),
|
||||||
|
getCommitStatusWithSummary(repository.owner, repository.name, commit.id)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
.splitWith { (commit1, commit2) =>
|
.splitWith {
|
||||||
view.helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
case ((commit1, _, _), (commit2, _, _)) =>
|
||||||
|
view.helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
||||||
},
|
},
|
||||||
page,
|
page,
|
||||||
hasNext,
|
hasNext,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
getStatuses,
|
|
||||||
getSummary,
|
|
||||||
getTags
|
|
||||||
)
|
)
|
||||||
case Left(_) => NotFound()
|
case Left(_) => NotFound()
|
||||||
}
|
}
|
||||||
@@ -315,7 +310,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(context.loginAccount.get.userName)
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
html.editor(
|
html.editor(
|
||||||
@@ -334,7 +329,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(context.loginAccount.get.userName)
|
||||||
html.upload(branch, repository, if (path.length == 0) Nil else path.split("/").toList, protectedBranch)
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
html.upload(
|
||||||
|
branch,
|
||||||
|
repository,
|
||||||
|
if (path.length == 0) Nil else path.split("/").toList,
|
||||||
|
protectedBranch,
|
||||||
|
revCommit.name
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/upload", uploadForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/upload", uploadForm)(writableUsersOnly { (form, repository) =>
|
||||||
@@ -347,35 +351,47 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
file.copy(name = if (form.path.length == 0) file.name else s"${form.path}/${file.name}")
|
file.copy(name = if (form.path.length == 0) file.name else s"${form.path}/${file.name}")
|
||||||
}
|
}
|
||||||
|
|
||||||
commitFiles(
|
if (form.newBranch) {
|
||||||
repository = repository,
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
||||||
branch = form.branch,
|
val objectId = _commit(newBranchName)
|
||||||
path = form.path,
|
val issueId =
|
||||||
files = files,
|
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
||||||
message = form.message.getOrElse("Add files via upload"),
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
loginAccount = context.loginAccount.get
|
} else {
|
||||||
) {
|
_commit(form.branch)
|
||||||
case (git, headTip, builder, inserter) =>
|
if (form.path.length == 0) {
|
||||||
JGitUtil.processTree(git, headTip) { (path, tree) =>
|
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}")
|
||||||
if (!newFiles.exists(_.name.contains(path))) {
|
} else {
|
||||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}/${form.path}")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
newFiles.foreach { file =>
|
|
||||||
val bytes =
|
|
||||||
FileUtils.readFileToByteArray(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(file.id)))
|
|
||||||
builder.add(
|
|
||||||
JGitUtil.createDirCacheEntry(file.name, FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, bytes))
|
|
||||||
)
|
|
||||||
builder.finish()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (form.path.length == 0) {
|
def _commit(branchName: String): ObjectId = {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}")
|
commitFiles(
|
||||||
} else {
|
repository = repository,
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}/${form.path}")
|
branch = branchName,
|
||||||
|
path = form.path,
|
||||||
|
files = files.toIndexedSeq,
|
||||||
|
message = form.message.getOrElse("Add files via upload"),
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
|
) {
|
||||||
|
case (git, headTip, builder, inserter) =>
|
||||||
|
JGitUtil.processTree(git, headTip) { (path, tree) =>
|
||||||
|
if (!newFiles.exists(_.name.contains(path))) {
|
||||||
|
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
newFiles.foreach { file =>
|
||||||
|
val bytes =
|
||||||
|
FileUtils.readFileToByteArray(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(file.id)))
|
||||||
|
builder.add(
|
||||||
|
JGitUtil.createDirCacheEntry(file.name, FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, bytes))
|
||||||
|
)
|
||||||
|
builder.finish()
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -384,7 +400,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(context.loginAccount.get.userName)
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
@@ -411,7 +427,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
@@ -430,73 +446,160 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/create", editorForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/create", editorForm)(writableUsersOnly { (form, repository) =>
|
||||||
commitFile(
|
if (form.newBranch) {
|
||||||
repository = repository,
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
||||||
branch = form.branch,
|
val objectId = _commit(newBranchName)
|
||||||
path = form.path,
|
val issueId =
|
||||||
newFileName = Some(form.newFileName),
|
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
||||||
oldFileName = None,
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
|
} else {
|
||||||
charset = form.charset,
|
_commit(form.branch)
|
||||||
message = form.message.getOrElse(s"Create ${form.newFileName}"),
|
redirect(
|
||||||
commit = form.commit,
|
s"/${repository.owner}/${repository.name}/blob/${form.branch}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
||||||
loginAccount = context.loginAccount.get
|
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
redirect(
|
def _commit(branchName: String): ObjectId = {
|
||||||
s"/${repository.owner}/${repository.name}/blob/${form.branch}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
commitFile(
|
||||||
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
repository = repository,
|
||||||
)
|
branch = branchName,
|
||||||
|
path = form.path,
|
||||||
|
newFileName = Some(form.newFileName),
|
||||||
|
oldFileName = None,
|
||||||
|
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
|
||||||
|
charset = form.charset,
|
||||||
|
message = form.message.getOrElse(s"Create ${form.newFileName}"),
|
||||||
|
commit = form.commit,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/update", editorForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/update", editorForm)(writableUsersOnly { (form, repository) =>
|
||||||
commitFile(
|
if (form.newBranch) {
|
||||||
repository = repository,
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
||||||
branch = form.branch,
|
val objectId = _commit(newBranchName)
|
||||||
path = form.path,
|
val issueId =
|
||||||
newFileName = Some(form.newFileName),
|
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
||||||
oldFileName = form.oldFileName,
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
|
} else {
|
||||||
charset = form.charset,
|
_commit(form.branch)
|
||||||
message = if (form.oldFileName.contains(form.newFileName)) {
|
redirect(
|
||||||
form.message.getOrElse(s"Update ${form.newFileName}")
|
s"/${repository.owner}/${repository.name}/blob/${urlEncode(form.branch)}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
||||||
} else {
|
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
||||||
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
|
)
|
||||||
},
|
}
|
||||||
commit = form.commit,
|
|
||||||
loginAccount = context.loginAccount.get
|
|
||||||
)
|
|
||||||
|
|
||||||
redirect(
|
def _commit(branchName: String): ObjectId = {
|
||||||
s"/${repository.owner}/${repository.name}/blob/${urlEncode(form.branch)}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
commitFile(
|
||||||
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
repository = repository,
|
||||||
)
|
branch = branchName,
|
||||||
|
path = form.path,
|
||||||
|
newFileName = Some(form.newFileName),
|
||||||
|
oldFileName = form.oldFileName,
|
||||||
|
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
|
||||||
|
charset = form.charset,
|
||||||
|
message = if (form.oldFileName.contains(form.newFileName)) {
|
||||||
|
form.message.getOrElse(s"Update ${form.newFileName}")
|
||||||
|
} else {
|
||||||
|
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
|
||||||
|
},
|
||||||
|
commit = form.commit,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/remove", deleteForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/remove", deleteForm)(writableUsersOnly { (form, repository) =>
|
||||||
commitFile(
|
if (form.newBranch) {
|
||||||
repository = repository,
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
||||||
branch = form.branch,
|
val objectId = _commit(newBranchName)
|
||||||
path = form.path,
|
val issueId =
|
||||||
newFileName = None,
|
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
||||||
oldFileName = Some(form.fileName),
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
content = "",
|
} else {
|
||||||
charset = "",
|
_commit(form.branch)
|
||||||
message = form.message.getOrElse(s"Delete ${form.fileName}"),
|
redirect(
|
||||||
commit = form.commit,
|
s"/${repository.owner}/${repository.name}/tree/${form.branch}${if (form.path.length == 0) ""
|
||||||
loginAccount = context.loginAccount.get
|
else "/" + form.path}"
|
||||||
)
|
)
|
||||||
|
}
|
||||||
|
|
||||||
println(form.path)
|
def _commit(branchName: String): ObjectId = {
|
||||||
|
commitFile(
|
||||||
redirect(
|
repository = repository,
|
||||||
s"/${repository.owner}/${repository.name}/tree/${form.branch}${if (form.path.length == 0) "" else "/" + form.path}"
|
branch = branchName,
|
||||||
)
|
path = form.path,
|
||||||
|
newFileName = None,
|
||||||
|
oldFileName = Some(form.fileName),
|
||||||
|
content = "",
|
||||||
|
charset = "",
|
||||||
|
message = form.message.getOrElse(s"Delete ${form.fileName}"),
|
||||||
|
commit = form.commit,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private def getNewBranchName(repository: RepositoryInfo): String = {
|
||||||
|
var i = 1
|
||||||
|
val branchNamePrefix = cutTail(context.loginAccount.get.userName.replaceAll("[^a-zA-Z0-9-_]", "-"), 25)
|
||||||
|
while (repository.branchList.exists(p => p.contains(s"$branchNamePrefix-patch-$i"))) {
|
||||||
|
i += 1
|
||||||
|
}
|
||||||
|
s"$branchNamePrefix-patch-$i"
|
||||||
|
}
|
||||||
|
|
||||||
|
private def createNewBranchForPullRequest(repository: RepositoryInfo, baseBranchName: String): String = {
|
||||||
|
val newBranchName = getNewBranchName(repository)
|
||||||
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
|
JGitUtil.createBranch(git, baseBranchName, newBranchName)
|
||||||
|
}
|
||||||
|
newBranchName
|
||||||
|
}
|
||||||
|
|
||||||
|
private def createIssueAndPullRequest(
|
||||||
|
repository: RepositoryInfo,
|
||||||
|
baseBranch: String,
|
||||||
|
requestBranch: String,
|
||||||
|
commitIdFrom: String,
|
||||||
|
commitIdTo: String,
|
||||||
|
commitMessage: Option[String]
|
||||||
|
): Int = {
|
||||||
|
val issueId = insertIssue(
|
||||||
|
owner = repository.owner,
|
||||||
|
repository = repository.name,
|
||||||
|
loginUser = context.loginAccount.get.userName,
|
||||||
|
title = requestBranch,
|
||||||
|
content = commitMessage,
|
||||||
|
assignedUserName = None,
|
||||||
|
milestoneId = None,
|
||||||
|
priorityId = None,
|
||||||
|
isPullRequest = true
|
||||||
|
)
|
||||||
|
createPullRequest(
|
||||||
|
originRepository = repository,
|
||||||
|
issueId = issueId,
|
||||||
|
originBranch = baseBranch,
|
||||||
|
requestUserName = repository.owner,
|
||||||
|
requestRepositoryName = repository.name,
|
||||||
|
requestBranch = requestBranch,
|
||||||
|
commitIdFrom = commitIdFrom,
|
||||||
|
commitIdTo = commitIdTo,
|
||||||
|
isDraft = false,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
|
)
|
||||||
|
issueId
|
||||||
|
}
|
||||||
|
|
||||||
get("/:owner/:repository/raw/*")(referrersOnly { repository =>
|
get("/:owner/:repository/raw/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
@@ -511,7 +614,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val blobRoute = get("/:owner/:repository/blob/*")(referrersOnly { repository =>
|
val blobRoute = get("/:owner/:repository/blob/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val raw = params.get("raw").getOrElse("false").toBoolean
|
val raw = params.get("raw").getOrElse("false").toBoolean
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
val highlighterTheme = getSyntaxHighlighterTheme()
|
||||||
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
getPathObjectId(git, path, revCommit).map {
|
getPathObjectId(git, path, revCommit).map {
|
||||||
@@ -530,13 +634,25 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
hasWritePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
hasWritePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
||||||
isBlame = request.paths(2) == "blame",
|
isBlame = request.paths(2) == "blame",
|
||||||
isLfsFile = isLfsFile(git, objectId),
|
isLfsFile = isLfsFile(git, objectId),
|
||||||
tabSize = info.tabSize
|
tabSize = info.tabSize,
|
||||||
|
highlighterTheme = highlighterTheme
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private def getSyntaxHighlighterTheme()(implicit context: Context): String = {
|
||||||
|
context.loginAccount match {
|
||||||
|
case Some(account) =>
|
||||||
|
getAccountPreference(account.userName) match {
|
||||||
|
case Some(x) => x.highlighterTheme
|
||||||
|
case _ => "github-v2"
|
||||||
|
}
|
||||||
|
case _ => "github-v2"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private def isLfsFile(git: Git, objectId: ObjectId): Boolean = {
|
private def isLfsFile(git: Git, objectId: ObjectId): Boolean = {
|
||||||
JGitUtil.getObjectLoaderFromId(git, objectId)(JGitUtil.isLfsPointer).getOrElse(false)
|
JGitUtil.getObjectLoaderFromId(git, objectId)(JGitUtil.isLfsPointer).getOrElse(false)
|
||||||
}
|
}
|
||||||
@@ -551,7 +667,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
ajaxGet("/:owner/:repository/get-blame/*")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/get-blame/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
val last = git.log.add(git.getRepository.resolve(id)).addPath(path).setMaxCount(1).call.iterator.next.name
|
val last = git.log.add(git.getRepository.resolve(id)).addPath(path).setMaxCount(1).call.iterator.next.name
|
||||||
Serialization.write(
|
Serialization.write(
|
||||||
@@ -586,7 +702,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val id = params("id")
|
val id = params("id")
|
||||||
|
|
||||||
try {
|
try {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))) {
|
defining(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))) {
|
||||||
revCommit =>
|
revCommit =>
|
||||||
@@ -598,6 +714,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
new JGitUtil.CommitInfo(revCommit),
|
new JGitUtil.CommitInfo(revCommit),
|
||||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||||
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||||
|
getCommitStatusWithSummary(repository.owner, repository.name, revCommit.getName),
|
||||||
getCommitComments(repository.owner, repository.name, id, true),
|
getCommitComments(repository.owner, repository.name, id, true),
|
||||||
repository,
|
repository,
|
||||||
diffs,
|
diffs,
|
||||||
@@ -615,7 +732,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/patch/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/patch/:id")(referrersOnly { repository =>
|
||||||
try {
|
try {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val diff = JGitUtil.getPatch(git, None, params("id"))
|
val diff = JGitUtil.getPatch(git, None, params("id"))
|
||||||
contentType = formats("txt")
|
contentType = formats("txt")
|
||||||
diff
|
diff
|
||||||
@@ -628,7 +745,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/patch/*...*")(referrersOnly { repository =>
|
get("/:owner/:repository/patch/*...*")(referrersOnly { repository =>
|
||||||
try {
|
try {
|
||||||
val Seq(fromId, toId) = multiParams("splat")
|
val Seq(fromId, toId) = multiParams("splat")
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val diff = JGitUtil.getPatch(git, Some(fromId), toId)
|
val diff = JGitUtil.getPatch(git, Some(fromId), toId)
|
||||||
contentType = formats("txt")
|
contentType = formats("txt")
|
||||||
diff
|
diff
|
||||||
@@ -748,7 +865,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
||||||
val protectedBranches = getProtectedBranchList(repository.owner, repository.name).toSet
|
val protectedBranches = getProtectedBranchList(repository.owner, repository.name).toSet
|
||||||
val branches = using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
val branches = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getBranches(
|
.getBranches(
|
||||||
@@ -756,19 +873,20 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
defaultBranch = repository.repository.defaultBranch,
|
defaultBranch = repository.repository.defaultBranch,
|
||||||
origin = repository.repository.originUserName.isEmpty
|
origin = repository.repository.originUserName.isEmpty
|
||||||
)
|
)
|
||||||
.sortBy(br => (br.mergeInfo.isEmpty, br.commitTime))
|
.sortBy(branch => (branch.mergeInfo.isEmpty, branch.commitTime))
|
||||||
.map(
|
.map(
|
||||||
br =>
|
branch =>
|
||||||
(
|
(
|
||||||
br,
|
branch,
|
||||||
getPullRequestByRequestCommit(
|
getPullRequestByRequestCommit(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
repository.repository.defaultBranch,
|
repository.repository.defaultBranch,
|
||||||
br.name,
|
branch.name,
|
||||||
br.commitId
|
branch.commitId
|
||||||
),
|
),
|
||||||
protectedBranches.contains(br.name)
|
protectedBranches.contains(branch.name),
|
||||||
|
getCommitStatusWithSummary(repository.owner, repository.name, branch.commitId)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
.reverse
|
.reverse
|
||||||
@@ -788,14 +906,14 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* Creates a tag.
|
* Creates a tag.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/tag", tagForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/tag", tagForm)(writableUsersOnly { (form, repository) =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JGitUtil.createTag(git, form.tagName, form.message, form.commitId)
|
JGitUtil.createTag(git, form.tagName, form.message, form.commitId)
|
||||||
} match {
|
} match {
|
||||||
case Right(message) =>
|
case Right(message) =>
|
||||||
flash += "info" -> message
|
flash.update("info", message)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
||||||
case Left(message) =>
|
case Left(message) =>
|
||||||
flash += "error" -> message
|
flash.update("error", message)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
redirect(s"/${repository.owner}/${repository.name}/commit/${form.commitId}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -806,16 +924,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
||||||
val newBranchName = params.getOrElse("new", halt(400))
|
val newBranchName = params.getOrElse("new", halt(400))
|
||||||
val fromBranchName = params.getOrElse("from", halt(400))
|
val fromBranchName = params.getOrElse("from", halt(400))
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JGitUtil.createBranch(git, fromBranchName, newBranchName)
|
JGitUtil.createBranch(git, fromBranchName, newBranchName)
|
||||||
} match {
|
} match {
|
||||||
case Right(message) =>
|
case Right(message) =>
|
||||||
flash += "info" -> message
|
flash.update("info", message)
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/tree/${StringUtil.urlEncode(newBranchName).replace("%2F", "/")}"
|
s"/${repository.owner}/${repository.name}/tree/${StringUtil.urlEncode(newBranchName).replace("%2F", "/")}"
|
||||||
)
|
)
|
||||||
case Left(message) =>
|
case Left(message) =>
|
||||||
flash += "error" -> message
|
flash.update("error", message)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -827,9 +945,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val branchName = multiParams("splat").head
|
val branchName = multiParams("splat").head
|
||||||
val userName = context.loginAccount.get.userName
|
val userName = context.loginAccount.get.userName
|
||||||
if (repository.repository.defaultBranch != branchName) {
|
if (repository.repository.defaultBranch != branchName) {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.branchDelete().setForce(true).setBranchNames(branchName).call()
|
git.branchDelete().setForce(true).setBranchNames(branchName).call()
|
||||||
recordDeleteBranchActivity(repository.owner, repository.name, userName, branchName)
|
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, branchName)
|
||||||
|
recordActivity(deleteBranchInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
redirect(s"/${repository.owner}/${repository.name}/branches")
|
redirect(s"/${repository.owner}/${repository.name}/branches")
|
||||||
@@ -879,7 +998,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* Displays the file find of branch.
|
* Displays the file find of branch.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/find/*")(referrersOnly { repository =>
|
get("/:owner/:repository/find/*")(referrersOnly { repository =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val ref = multiParams("splat").head
|
val ref = multiParams("splat").head
|
||||||
JGitUtil.getTreeId(git, ref).map { treeId =>
|
JGitUtil.getTreeId(git, ref).map { treeId =>
|
||||||
html.find(ref, treeId, repository)
|
html.find(ref, treeId, repository)
|
||||||
@@ -891,7 +1010,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* Get all file list of branch.
|
* Get all file list of branch.
|
||||||
*/
|
*/
|
||||||
ajaxGet("/:owner/:repository/tree-list/:tree")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/tree-list/:tree")(referrersOnly { repository =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val treeId = params("tree")
|
val treeId = params("tree")
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
Map("paths" -> JGitUtil.getAllFileListByTreeId(git, treeId))
|
Map("paths" -> JGitUtil.getAllFileListByTreeId(git, treeId))
|
||||||
@@ -902,10 +1021,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
lazy val isValid: Boolean = fileIds.nonEmpty
|
lazy val isValid: Boolean = fileIds.nonEmpty
|
||||||
}
|
}
|
||||||
|
|
||||||
private val readmeFiles = PluginRegistry().renderableExtensions.map { extension =>
|
|
||||||
s"readme.${extension}"
|
|
||||||
} ++ Seq("readme.txt", "readme")
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides HTML of the file list.
|
* Provides HTML of the file list.
|
||||||
*
|
*
|
||||||
@@ -915,7 +1030,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* @return HTML of the file list
|
* @return HTML of the file list
|
||||||
*/
|
*/
|
||||||
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
|
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
if (JGitUtil.isEmpty(git)) {
|
if (JGitUtil.isEmpty(git)) {
|
||||||
html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount))
|
html.guide(repository, hasDeveloperRole(repository.owner, repository.name, context.loginAccount))
|
||||||
} else {
|
} else {
|
||||||
@@ -925,13 +1040,21 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
||||||
val lastModifiedCommit =
|
val lastModifiedCommit =
|
||||||
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
|
val commitCount = JGitUtil.getCommitCount(git, lastModifiedCommit.getName)
|
||||||
// get files
|
// get files
|
||||||
val files = JGitUtil.getFileList(git, revision, path, context.settings.baseUrl)
|
val files = JGitUtil.getFileList(
|
||||||
|
git,
|
||||||
|
revision,
|
||||||
|
path,
|
||||||
|
context.settings.baseUrl,
|
||||||
|
commitCount,
|
||||||
|
context.settings.repositoryViewer.maxFiles
|
||||||
|
)
|
||||||
val parentPath = if (path == ".") Nil else path.split("/").toList
|
val parentPath = if (path == ".") Nil else path.split("/").toList
|
||||||
// process README.md or README.markdown
|
// process README
|
||||||
val readme = files
|
val readme = files // files should be sorted alphabetically.
|
||||||
.find { file =>
|
.find { file =>
|
||||||
!file.isDirectory && readmeFiles.contains(file.name.toLowerCase)
|
!file.isDirectory && RepositoryService.readmeFiles.contains(file.name.toLowerCase)
|
||||||
}
|
}
|
||||||
.map { file =>
|
.map { file =>
|
||||||
val path = (file.name :: parentPath.reverse).reverse
|
val path = (file.name :: parentPath.reverse).reverse
|
||||||
@@ -947,7 +1070,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repository,
|
repository,
|
||||||
if (path == ".") Nil else path.split("/").toList, // current path
|
if (path == ".") Nil else path.split("/").toList, // current path
|
||||||
new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit
|
new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit
|
||||||
JGitUtil.getCommitCount(git, lastModifiedCommit.getName),
|
getCommitStatusWithSummary(repository.owner, repository.name, lastModifiedCommit.getName),
|
||||||
|
commitCount,
|
||||||
files,
|
files,
|
||||||
readme,
|
readme,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
||||||
@@ -974,16 +1098,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
def archive(revision: String, archiveFormat: String, archive: ArchiveOutputStream)(
|
def archive(revision: String, archiveFormat: String, archive: ArchiveOutputStream)(
|
||||||
entryCreator: (String, Long, java.util.Date, Int) => ArchiveEntry
|
entryCreator: (String, Long, java.util.Date, Int) => ArchiveEntry
|
||||||
): Unit = {
|
): Unit = {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val oid = git.getRepository.resolve(revision)
|
val oid = git.getRepository.resolve(revision)
|
||||||
val commit = JGitUtil.getRevCommitFromId(git, oid)
|
val commit = JGitUtil.getRevCommitFromId(git, oid)
|
||||||
val date = commit.getCommitterIdent.getWhen
|
val date = commit.getCommitterIdent.getWhen
|
||||||
val sha1 = oid.getName()
|
val sha1 = oid.getName()
|
||||||
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
val repositorySuffix = (if (sha1.startsWith(revision)) sha1 else revision).replace('/', '-')
|
||||||
val pathSuffix = if (path.isEmpty) "" else '-' + path.replace('/', '-')
|
val pathSuffix = if (path.isEmpty) "" else s"-${path.replace('/', '-')}"
|
||||||
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
val baseName = repository.name + "-" + repositorySuffix + pathSuffix
|
||||||
|
|
||||||
using(new TreeWalk(git.getRepository)) { treeWalk =>
|
Using.resource(new TreeWalk(git.getRepository)) { treeWalk =>
|
||||||
treeWalk.addTree(commit.getTree)
|
treeWalk.addTree(commit.getTree)
|
||||||
treeWalk.setRecursive(true)
|
treeWalk.setRecursive(true)
|
||||||
if (!path.isEmpty) {
|
if (!path.isEmpty) {
|
||||||
@@ -994,24 +1118,31 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val entryPath =
|
val entryPath =
|
||||||
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
||||||
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
||||||
val size = JGitUtil.getContentSize(git.getRepository.open(treeWalk.getObjectId(0)))
|
|
||||||
val mode = treeWalk.getFileMode.getBits
|
val mode = treeWalk.getFileMode.getBits
|
||||||
val entry: ArchiveEntry = entryCreator(entryPath, size, date, mode)
|
|
||||||
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
|
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
|
||||||
|
val tempFile = File.createTempFile("gitbucket", ".archive")
|
||||||
|
val size = Using.resource(new FileOutputStream(tempFile)) { out =>
|
||||||
|
IOUtils.copy(
|
||||||
|
EolStreamTypeUtil.wrapInputStream(
|
||||||
|
in,
|
||||||
|
EolStreamTypeUtil
|
||||||
|
.detectStreamType(
|
||||||
|
OperationType.CHECKOUT_OP,
|
||||||
|
git.getRepository.getConfig.get(WorkingTreeOptions.KEY),
|
||||||
|
treeWalk.getAttributes
|
||||||
|
)
|
||||||
|
),
|
||||||
|
out
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
val entry: ArchiveEntry = entryCreator(entryPath, size, date, mode)
|
||||||
archive.putArchiveEntry(entry)
|
archive.putArchiveEntry(entry)
|
||||||
IOUtils.copy(
|
Using.resource(new FileInputStream(tempFile)) { in =>
|
||||||
EolStreamTypeUtil.wrapInputStream(
|
IOUtils.copy(in, archive)
|
||||||
in,
|
}
|
||||||
EolStreamTypeUtil
|
|
||||||
.detectStreamType(
|
|
||||||
OperationType.CHECKOUT_OP,
|
|
||||||
git.getRepository.getConfig.get(WorkingTreeOptions.KEY),
|
|
||||||
treeWalk.getAttributes
|
|
||||||
)
|
|
||||||
),
|
|
||||||
archive
|
|
||||||
)
|
|
||||||
archive.closeArchiveEntry()
|
archive.closeArchiveEntry()
|
||||||
|
tempFile.delete()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1032,9 +1163,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
response.setBufferSize(1024 * 1024)
|
response.setBufferSize(1024 * 1024)
|
||||||
using(new ZipArchiveOutputStream(response.getOutputStream)) { zip =>
|
Using.resource(new ZipArchiveOutputStream(response.getOutputStream)) { zip =>
|
||||||
archive(revision, ".zip", zip) { (path, size, date, mode) =>
|
archive(revision, ".zip", zip) { (path, size, date, mode) =>
|
||||||
val entry = new ZipArchiveEntry(path)
|
val entry = new ZipArchiveEntry(path)
|
||||||
|
entry.setSize(size)
|
||||||
entry.setUnixMode(mode)
|
entry.setUnixMode(mode)
|
||||||
entry.setTime(date.getTime)
|
entry.setTime(date.getTime)
|
||||||
entry
|
entry
|
||||||
@@ -1048,17 +1180,18 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
contentType = "application/octet-stream"
|
contentType = "application/octet-stream"
|
||||||
response.setBufferSize(1024 * 1024)
|
response.setBufferSize(1024 * 1024)
|
||||||
using(compressor match {
|
Using.resource(compressor match {
|
||||||
case "gz" => new GzipCompressorOutputStream(response.getOutputStream)
|
case "gz" => new GzipCompressorOutputStream(response.getOutputStream)
|
||||||
case "bz2" => new BZip2CompressorOutputStream(response.getOutputStream)
|
case "bz2" => new BZip2CompressorOutputStream(response.getOutputStream)
|
||||||
case "xz" => new XZCompressorOutputStream(response.getOutputStream)
|
case "xz" => new XZCompressorOutputStream(response.getOutputStream)
|
||||||
}) { compressorOutputStream =>
|
}) { compressorOutputStream =>
|
||||||
using(new TarArchiveOutputStream(compressorOutputStream)) { tar =>
|
Using.resource(new TarArchiveOutputStream(compressorOutputStream)) { tar =>
|
||||||
tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR)
|
tar.setBigNumberMode(TarArchiveOutputStream.BIGNUMBER_STAR)
|
||||||
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU)
|
tar.setLongFileMode(TarArchiveOutputStream.LONGFILE_GNU)
|
||||||
tar.setAddPaxHeadersForNonAsciiNames(true)
|
tar.setAddPaxHeadersForNonAsciiNames(true)
|
||||||
archive(revision, ".tar.gz", tar) { (path, size, date, mode) =>
|
archive(revision, ".tar.gz", tar) { (path, size, date, mode) =>
|
||||||
val entry = new TarArchiveEntry(path)
|
val entry = new TarArchiveEntry(path)
|
||||||
|
entry.setSize(size)
|
||||||
entry.setModTime(date)
|
entry.setModTime(date)
|
||||||
entry.setMode(mode)
|
entry.setMode(mode)
|
||||||
entry
|
entry
|
||||||
@@ -1081,7 +1214,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val branch = params("branch")
|
val branch = params("branch")
|
||||||
|
|
||||||
LockUtil.lock(s"${owner}/${repository}") {
|
LockUtil.lock(s"${owner}/${repository}") {
|
||||||
using(Git.open(getRepositoryDir(owner, repository))) { git =>
|
Using.resource(Git.open(getRepositoryDir(owner, repository))) { git =>
|
||||||
val headName = s"refs/heads/${branch}"
|
val headName = s"refs/heads/${branch}"
|
||||||
val headTip = git.getRepository.resolve(headName)
|
val headTip = git.getRepository.resolve(headName)
|
||||||
if (headTip.getName != value) {
|
if (headTip.getName != value) {
|
||||||
|
|||||||
@@ -2,14 +2,11 @@ package gitbucket.core.controller
|
|||||||
|
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
|
||||||
import com.github.zafarkhaja.semver.{Version => Semver}
|
|
||||||
import gitbucket.core.GitBucketCoreModule
|
|
||||||
import gitbucket.core.admin.html
|
import gitbucket.core.admin.html
|
||||||
import gitbucket.core.plugin.{PluginInfoBase, PluginRegistry, PluginRepository}
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
import gitbucket.core.service.SystemSettingsService._
|
import gitbucket.core.service.SystemSettingsService._
|
||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.ssh.SshServer
|
import gitbucket.core.ssh.SshServer
|
||||||
import gitbucket.core.util.Directory._
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
import gitbucket.core.util.SyntaxSugars._
|
||||||
@@ -21,8 +18,8 @@ import org.scalatra._
|
|||||||
import org.scalatra.forms._
|
import org.scalatra.forms._
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
|
||||||
import scala.collection.mutable.ListBuffer
|
import scala.collection.mutable.ListBuffer
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
class SystemSettingsController
|
class SystemSettingsController
|
||||||
extends SystemSettingsControllerBase
|
extends SystemSettingsControllerBase
|
||||||
@@ -41,14 +38,21 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"information" -> trim(label("Information", optional(text()))),
|
"information" -> trim(label("Information", optional(text()))),
|
||||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||||
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
||||||
"isCreateRepoOptionPublic" -> trim(label("Default option to create a new repository", 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())),
|
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||||
"notification" -> trim(label("Notification", boolean())),
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
"activityLogLimit" -> trim(label("Limit of activity logs", optional(number()))),
|
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
||||||
"ssh" -> mapping(
|
"ssh" -> mapping(
|
||||||
"enabled" -> trim(label("SSH access", boolean())),
|
"enabled" -> trim(label("SSH access", boolean())),
|
||||||
"host" -> trim(label("SSH host", optional(text()))),
|
"host" -> trim(label("SSH host", optional(text()))),
|
||||||
"port" -> trim(label("SSH port", optional(number()))),
|
"port" -> trim(label("SSH port", optional(number())))
|
||||||
)(Ssh.apply),
|
)(Ssh.apply),
|
||||||
"useSMTP" -> trim(label("SMTP", boolean())),
|
"useSMTP" -> trim(label("SMTP", boolean())),
|
||||||
"smtp" -> optionalIfNotChecked(
|
"smtp" -> optionalIfNotChecked(
|
||||||
@@ -93,17 +97,21 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
)(OIDC.apply)
|
)(OIDC.apply)
|
||||||
),
|
),
|
||||||
"skinName" -> trim(label("AdminLTE skin name", text(required))),
|
"skinName" -> trim(label("AdminLTE skin name", text(required))),
|
||||||
|
"userDefinedCss" -> trim(label("User-defined CSS", optional(text()))),
|
||||||
"showMailAddress" -> trim(label("Show mail address", boolean())),
|
"showMailAddress" -> trim(label("Show mail address", boolean())),
|
||||||
"pluginNetworkInstall" -> trim(label("Network plugin installation", boolean())),
|
"webhook" -> mapping(
|
||||||
"proxy" -> optionalIfNotChecked(
|
"blockPrivateAddress" -> trim(label("Block private address", boolean())),
|
||||||
"useProxy",
|
"whitelist" -> trim(label("Whitelist", multiLineText()))
|
||||||
mapping(
|
)(WebHook.apply),
|
||||||
"host" -> trim(label("Proxy host", text(required))),
|
"upload" -> mapping(
|
||||||
"port" -> trim(label("Proxy port", number())),
|
"maxFileSize" -> trim(label("Max file size", long(required))),
|
||||||
"user" -> trim(label("Keystore", optional(text()))),
|
"timeout" -> trim(label("Timeout", long(required))),
|
||||||
"password" -> trim(label("Keystore", optional(text())))
|
"largeMaxFileSize" -> trim(label("Max file size for large file", long(required))),
|
||||||
)(Proxy.apply)
|
"largeTimeout" -> trim(label("Timeout for large file", long(required)))
|
||||||
)
|
)(Upload.apply),
|
||||||
|
"repositoryViewer" -> mapping(
|
||||||
|
"maxFiles" -> trim(label("Max files", number(required)))
|
||||||
|
)(RepositoryViewerSettings.apply)
|
||||||
)(SystemSettings.apply).verifying { settings =>
|
)(SystemSettings.apply).verifying { settings =>
|
||||||
Vector(
|
Vector(
|
||||||
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
||||||
@@ -179,7 +187,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val newUserForm = mapping(
|
val newUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(20), password))),
|
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -193,7 +201,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val editUserForm = mapping(
|
val editUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(20), password)))),
|
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -229,30 +237,30 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
val conn = request2Session(request).conn
|
val conn = request2Session(request).conn
|
||||||
val meta = conn.getMetaData
|
val meta = conn.getMetaData
|
||||||
val tables = ListBuffer[Table]()
|
val tables = ListBuffer[Table]()
|
||||||
using(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) {
|
Using.resource(meta.getTables(null, "%", "%", Array("TABLE", "VIEW"))) {
|
||||||
rs =>
|
rs =>
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
val tableName = rs.getString("TABLE_NAME")
|
val tableName = rs.getString("TABLE_NAME")
|
||||||
|
|
||||||
val pkColumns = ListBuffer[String]()
|
val pkColumns = ListBuffer[String]()
|
||||||
using(meta.getPrimaryKeys(null, null, tableName)) { rs =>
|
Using.resource(meta.getPrimaryKeys(null, null, tableName)) { rs =>
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
pkColumns += rs.getString("COLUMN_NAME").toUpperCase
|
pkColumns += rs.getString("COLUMN_NAME").toUpperCase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val columns = ListBuffer[Column]()
|
val columns = ListBuffer[Column]()
|
||||||
using(meta.getColumns(null, "%", tableName, "%")) { rs =>
|
Using.resource(meta.getColumns(null, "%", tableName, "%")) { rs =>
|
||||||
while (rs.next()) {
|
while (rs.next()) {
|
||||||
val columnName = rs.getString("COLUMN_NAME").toUpperCase
|
val columnName = rs.getString("COLUMN_NAME").toUpperCase
|
||||||
columns += Column(columnName, pkColumns.contains(columnName))
|
columns += Column(columnName, pkColumns.contains(columnName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
tables += Table(tableName.toUpperCase, columns)
|
tables += Table(tableName.toUpperCase, columns.toSeq)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
html.dbviewer(tables)
|
html.dbviewer(tables.toSeq)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/dbviewer/_query")(adminOnly {
|
post("/admin/dbviewer/_query")(adminOnly {
|
||||||
@@ -263,10 +271,10 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
if (trimmedQuery.nonEmpty) {
|
if (trimmedQuery.nonEmpty) {
|
||||||
try {
|
try {
|
||||||
val conn = request2Session(request).conn
|
val conn = request2Session(request).conn
|
||||||
using(conn.prepareStatement(query)) {
|
Using.resource(conn.prepareStatement(query)) {
|
||||||
stmt =>
|
stmt =>
|
||||||
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
if (trimmedQuery.toUpperCase.startsWith("SELECT")) {
|
||||||
using(stmt.executeQuery()) {
|
Using.resource(stmt.executeQuery()) {
|
||||||
rs =>
|
rs =>
|
||||||
val meta = rs.getMetaData
|
val meta = rs.getMetaData
|
||||||
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
val columns = for (i <- 1 to meta.getColumnCount) yield {
|
||||||
@@ -309,7 +317,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
} SshServer.start(sshAddress, baseUrl)
|
} SshServer.start(sshAddress, baseUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
flash += "info" -> "System settings has been updated."
|
flash.update("info", "System settings has been updated.")
|
||||||
redirect("/admin/system")
|
redirect("/admin/system")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -332,63 +340,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/plugins")(adminOnly {
|
get("/admin/plugins")(adminOnly {
|
||||||
// Installed plugins
|
html.plugins(PluginRegistry().getPlugins(), flash.get("info"))
|
||||||
val enabledPlugins = PluginRegistry().getPlugins()
|
|
||||||
val gitbucketVersion = GitBucketCoreModule.getVersions.asScala.last.getVersion
|
|
||||||
val gitbucketSemver = Semver.valueOf(gitbucketVersion)
|
|
||||||
|
|
||||||
// Plugins in the remote repository
|
|
||||||
val repositoryPlugins = if (context.settings.pluginNetworkInstall) {
|
|
||||||
PluginRepository
|
|
||||||
.getPlugins()
|
|
||||||
.map {
|
|
||||||
meta =>
|
|
||||||
(meta, meta.versions.reverse.find {
|
|
||||||
version =>
|
|
||||||
val semver = Semver.valueOf(version.version)
|
|
||||||
gitbucketVersion == version.gitbucketVersion && !enabledPlugins.exists { plugin =>
|
|
||||||
if (plugin.pluginId == meta.id) {
|
|
||||||
Semver.valueOf(plugin.pluginVersion) match {
|
|
||||||
case x if x.greaterThan(semver) => true
|
|
||||||
case x if x.equals(semver) =>
|
|
||||||
plugin.gitbucketVersion match {
|
|
||||||
case None => true
|
|
||||||
case Some(x) => Semver.valueOf(x).greaterThanOrEqualTo(gitbucketSemver)
|
|
||||||
}
|
|
||||||
case _ => false
|
|
||||||
}
|
|
||||||
} else false
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
.collect {
|
|
||||||
case (meta, Some(version)) =>
|
|
||||||
new PluginInfoBase(
|
|
||||||
pluginId = meta.id,
|
|
||||||
pluginName = meta.name,
|
|
||||||
pluginVersion = version.version,
|
|
||||||
gitbucketVersion = Some(version.gitbucketVersion),
|
|
||||||
description = meta.description
|
|
||||||
)
|
|
||||||
}
|
|
||||||
} else Nil
|
|
||||||
|
|
||||||
// Merge
|
|
||||||
val plugins = (enabledPlugins.map((_, true)) ++ repositoryPlugins.map((_, false)))
|
|
||||||
.groupBy(_._1.pluginId)
|
|
||||||
.map {
|
|
||||||
case (pluginId, plugins) =>
|
|
||||||
val (plugin, enabled) = plugins.head
|
|
||||||
(plugin, enabled, if (plugins.length > 1) plugins.last._1.pluginVersion else "")
|
|
||||||
}
|
|
||||||
.toList
|
|
||||||
|
|
||||||
html.plugins(plugins, flash.get("info"))
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/plugins/_reload")(adminOnly {
|
post("/admin/plugins/_reload")(adminOnly {
|
||||||
PluginRegistry.reload(request.getServletContext(), loadSystemSettings(), request2Session(request).conn)
|
PluginRegistry.reload(request.getServletContext(), loadSystemSettings(), request2Session(request).conn)
|
||||||
flash += "info" -> "All plugins were reloaded."
|
flash.update("info", "All plugins were reloaded.")
|
||||||
redirect("/admin/plugins")
|
redirect("/admin/plugins")
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -398,37 +355,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
if (PluginRegistry().getPlugins().exists(_.pluginId == pluginId)) {
|
if (PluginRegistry().getPlugins().exists(_.pluginId == pluginId)) {
|
||||||
PluginRegistry
|
PluginRegistry
|
||||||
.uninstall(pluginId, request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
.uninstall(pluginId, request.getServletContext, loadSystemSettings(), request2Session(request).conn)
|
||||||
flash += "info" -> s"${pluginId} was uninstalled."
|
flash.update("info", s"${pluginId} was uninstalled.")
|
||||||
}
|
|
||||||
|
|
||||||
redirect("/admin/plugins")
|
|
||||||
})
|
|
||||||
|
|
||||||
post("/admin/plugins/:pluginId/:version/_install")(adminOnly {
|
|
||||||
if (context.settings.pluginNetworkInstall) {
|
|
||||||
val pluginId = params("pluginId")
|
|
||||||
val version = params("version")
|
|
||||||
val gitbucketVersion = GitBucketCoreModule.getVersions.asScala.last.getVersion
|
|
||||||
|
|
||||||
PluginRepository
|
|
||||||
.getPlugins()
|
|
||||||
.collectFirst {
|
|
||||||
case meta if meta.id == pluginId =>
|
|
||||||
(meta, meta.versions.find(x => x.gitbucketVersion == gitbucketVersion && x.version == version))
|
|
||||||
}
|
|
||||||
.foreach {
|
|
||||||
case (meta, version) =>
|
|
||||||
version.foreach { version =>
|
|
||||||
PluginRegistry.install(
|
|
||||||
pluginId,
|
|
||||||
new java.net.URL(version.url),
|
|
||||||
request.getServletContext,
|
|
||||||
loadSystemSettings(),
|
|
||||||
request2Session(request).conn
|
|
||||||
)
|
|
||||||
flash += "info" -> s"${pluginId}:${version.version} was installed."
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect("/admin/plugins")
|
redirect("/admin/plugins")
|
||||||
@@ -476,7 +403,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
getAccountByUserName(userName, true).map {
|
getAccountByUserName(userName, true).map {
|
||||||
account =>
|
account =>
|
||||||
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
if (account.isAdmin && (form.isRemoved || !form.isAdmin) && isLastAdministrator(account)) {
|
||||||
flash += "error" -> "Account can't be turned off because this is last one administrator."
|
flash.update("error", "Account can't be turned off because this is last one administrator.")
|
||||||
redirect(s"/admin/users/${userName}/_edituser")
|
redirect(s"/admin/users/${userName}/_edituser")
|
||||||
} else {
|
} else {
|
||||||
if (form.isRemoved) {
|
if (form.isRemoved) {
|
||||||
@@ -601,31 +528,44 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName)
|
response.setHeader("Content-Disposition", "attachment; filename=" + file.getName)
|
||||||
response.setContentLength(file.length.toInt)
|
response.setContentLength(file.length.toInt)
|
||||||
|
|
||||||
using(new FileInputStream(file)) { in =>
|
Using.resource(new FileInputStream(file)) { in =>
|
||||||
IOUtils.copy(in, response.outputStream)
|
IOUtils.copy(in, response.outputStream)
|
||||||
}
|
}
|
||||||
|
|
||||||
()
|
()
|
||||||
})
|
})
|
||||||
|
|
||||||
private def members: Constraint = new Constraint() {
|
private def multiLineText(constraints: Constraint*): SingleValueType[Seq[String]] =
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
new SingleValueType[Seq[String]](constraints: _*) {
|
||||||
if (value.split(",").exists {
|
def convert(value: String, messages: Messages): Seq[String] = {
|
||||||
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
if (value == null) {
|
||||||
}) None
|
Nil
|
||||||
else Some("Must select one manager at least.")
|
} else {
|
||||||
}
|
value.split("\n").toIndexedSeq.map(_.trim)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
protected def disableByNotYourself(paramName: String): Constraint = new Constraint() {
|
}
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
|
||||||
params.get(paramName).flatMap { userName =>
|
private def members: Constraint =
|
||||||
if (userName == context.loginAccount.get.userName && params.get("removed") == Some("true"))
|
new Constraint() {
|
||||||
Some("You can't disable your account yourself")
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
else
|
if (value.split(",").exists {
|
||||||
None
|
_.split(":") match { case Array(userName, isManager) => isManager.toBoolean }
|
||||||
|
}) None
|
||||||
|
else Some("Must select one manager at least.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected def disableByNotYourself(paramName: String): Constraint =
|
||||||
|
new Constraint() {
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
|
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,6 +1,7 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.model.WebHook
|
import gitbucket.core.model.WebHook
|
||||||
|
import gitbucket.core.model.activity.{CreateWikiPageInfo, DeleteWikiInfo, EditWikiPageInfo}
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
import gitbucket.core.service.WebHookService.WebHookGollumPayload
|
||||||
import gitbucket.core.wiki.html
|
import gitbucket.core.wiki.html
|
||||||
@@ -14,6 +15,8 @@ import org.scalatra.forms._
|
|||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
class WikiController
|
class WikiController
|
||||||
extends WikiControllerBase
|
extends WikiControllerBase
|
||||||
with WikiService
|
with WikiService
|
||||||
@@ -23,6 +26,7 @@ class WikiController
|
|||||||
with WebHookService
|
with WebHookService
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
|
with RequestCache
|
||||||
|
|
||||||
trait WikiControllerBase extends ControllerBase {
|
trait WikiControllerBase extends ControllerBase {
|
||||||
self: WikiService
|
self: WikiService
|
||||||
@@ -90,7 +94,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/wiki/:page/_history")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_history")(referrersOnly { repository =>
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JGitUtil.getCommitLog(git, "master", 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 Right((logs, hasNext)) => html.history(Some(pageName), logs, repository, isEditable(repository))
|
||||||
case Left(_) => NotFound()
|
case Left(_) => NotFound()
|
||||||
@@ -102,7 +106,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
html.compare(
|
html.compare(
|
||||||
Some(pageName),
|
Some(pageName),
|
||||||
from,
|
from,
|
||||||
@@ -118,7 +122,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/wiki/_compare/:commitId")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_compare/:commitId")(referrersOnly { repository =>
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
html.compare(
|
html.compare(
|
||||||
None,
|
None,
|
||||||
from,
|
from,
|
||||||
@@ -139,7 +143,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, Some(pageName))) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, Some(pageName))) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
||||||
} else {
|
} else {
|
||||||
flash += "info" -> "This patch was not able to be reversed."
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_compare/${from}...${to}"
|
||||||
)
|
)
|
||||||
@@ -154,7 +158,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, None)) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, None)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
} else {
|
} else {
|
||||||
flash += "info" -> "This patch was not able to be reversed."
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
@@ -183,14 +187,10 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
).foreach {
|
).foreach {
|
||||||
commitId =>
|
commitId =>
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
recordEditWikiPageActivity(
|
val wikiEditInfo =
|
||||||
repository.owner,
|
EditWikiPageInfo(repository.owner, repository.name, loginAccount.userName, form.pageName, commitId)
|
||||||
repository.name,
|
recordActivity(wikiEditInfo)
|
||||||
loginAccount.userName,
|
callWebHookOf(repository.owner, repository.name, WebHook.Gollum, context.settings) {
|
||||||
form.pageName,
|
|
||||||
commitId
|
|
||||||
)
|
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum) {
|
|
||||||
getAccountByUserName(repository.owner).map { repositoryUser =>
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
WebHookGollumPayload("edited", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
}
|
}
|
||||||
@@ -227,8 +227,10 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
).foreach {
|
).foreach {
|
||||||
commitId =>
|
commitId =>
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
recordCreateWikiPageActivity(repository.owner, repository.name, loginAccount.userName, form.pageName)
|
val createWikiPageInfo =
|
||||||
callWebHookOf(repository.owner, repository.name, WebHook.Gollum) {
|
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 =>
|
getAccountByUserName(repository.owner).map { repositoryUser =>
|
||||||
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
WebHookGollumPayload("created", form.pageName, commitId, repository, repositoryUser, loginAccount)
|
||||||
}
|
}
|
||||||
@@ -249,14 +251,13 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
|
|
||||||
defining(context.loginAccount.get) { loginAccount =>
|
defining(context.loginAccount.get) { loginAccount =>
|
||||||
deleteWikiPage(
|
val deleteWikiInfo = DeleteWikiInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
pageName,
|
loginAccount.userName,
|
||||||
loginAccount.fullName,
|
pageName
|
||||||
loginAccount.mailAddress,
|
|
||||||
s"Destroyed ${pageName}"
|
|
||||||
)
|
)
|
||||||
|
recordActivity(deleteWikiInfo)
|
||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
@@ -269,7 +270,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JGitUtil.getCommitLog(git, "master") match {
|
JGitUtil.getCommitLog(git, "master") match {
|
||||||
case Right((logs, hasNext)) => html.history(None, logs, repository, isEditable(repository))
|
case Right((logs, hasNext)) => html.history(None, logs, repository, isEditable(repository))
|
||||||
case Left(_) => NotFound()
|
case Left(_) => NotFound()
|
||||||
@@ -279,7 +280,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/wiki/_blob/*")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_blob/*")(referrersOnly { repository =>
|
||||||
val path = multiParams("splat").head
|
val path = multiParams("splat").head
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getWikiRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve("master"))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve("master"))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
|
|||||||
@@ -1,23 +1,40 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiObject, ApiRef, JsonFormat}
|
import gitbucket.core.api.{ApiObject, ApiRef, CreateARef, JsonFormat, UpdateARef}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.ReferrerAuthenticator
|
import gitbucket.core.util.ReferrerAuthenticator
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import scala.collection.JavaConverters._
|
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 {
|
trait ApiGitReferenceControllerBase extends ControllerBase {
|
||||||
self: ReferrerAuthenticator =>
|
self: ReferrerAuthenticator =>
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[ApiGitReferenceControllerBase])
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* i. Get a reference
|
* i. Get a reference
|
||||||
* https://developer.github.com/v3/git/refs/#get-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/git/ref/*")(referrersOnly { repository =>
|
||||||
|
getRef()
|
||||||
|
})
|
||||||
|
|
||||||
|
// Some versions of GHE support this path
|
||||||
get("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { repository =>
|
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")
|
||||||
|
getRef()
|
||||||
|
})
|
||||||
|
|
||||||
|
private def getRef() = {
|
||||||
val revstr = multiParams("splat").head
|
val revstr = multiParams("splat").head
|
||||||
using(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
val ref = git.getRepository().findRef(revstr)
|
val ref = git.getRepository().findRef(revstr)
|
||||||
|
|
||||||
if (ref != null) {
|
if (ref != null) {
|
||||||
@@ -37,24 +54,83 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Get all references
|
* ii. Get all references
|
||||||
* https://developer.github.com/v3/git/refs/#get-all-references
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#list-matching-references
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Create a reference
|
* iii. Create a reference
|
||||||
* https://developer.github.com/v3/git/refs/#create-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
||||||
*/
|
*/
|
||||||
|
post("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { _ =>
|
||||||
|
extractFromJsonBody[CreateARef].map {
|
||||||
|
data =>
|
||||||
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
|
val ref = git.getRepository.findRef(data.ref)
|
||||||
|
if (ref == null) {
|
||||||
|
val update = git.getRepository.updateRef(data.ref)
|
||||||
|
update.setNewObjectId(ObjectId.fromString(data.sha))
|
||||||
|
val result = update.update()
|
||||||
|
result match {
|
||||||
|
case Result.NEW => JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
||||||
|
case _ => UnprocessableEntity(result.name())
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
UnprocessableEntity("Ref already exists.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} getOrElse BadRequest()
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iv. Update a reference
|
* iv. Update a reference
|
||||||
* https://developer.github.com/v3/git/refs/#update-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
|
||||||
*/
|
*/
|
||||||
|
patch("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { _ =>
|
||||||
|
val refName = multiParams("splat").mkString("/")
|
||||||
|
extractFromJsonBody[UpdateARef].map {
|
||||||
|
data =>
|
||||||
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
|
val ref = git.getRepository.findRef(refName)
|
||||||
|
if (ref == null) {
|
||||||
|
UnprocessableEntity("Ref does not exist.")
|
||||||
|
} else {
|
||||||
|
val update = git.getRepository.updateRef(ref.getName)
|
||||||
|
update.setNewObjectId(ObjectId.fromString(data.sha))
|
||||||
|
update.setForceUpdate(data.force)
|
||||||
|
val result = update.update()
|
||||||
|
result match {
|
||||||
|
case Result.FORCED | Result.FAST_FORWARD | Result.NO_CHANGE =>
|
||||||
|
JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
||||||
|
case _ => UnprocessableEntity(result.name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} getOrElse BadRequest()
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Delete a reference
|
* v. Delete a reference
|
||||||
* https://developer.github.com/v3/git/refs/#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/*")(referrersOnly { _ =>
|
||||||
|
val refName = multiParams("splat").mkString("/")
|
||||||
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
|
val ref = git.getRepository.findRef(refName)
|
||||||
|
if (ref == null) {
|
||||||
|
UnprocessableEntity("Ref does not exist.")
|
||||||
|
} else {
|
||||||
|
val update = git.getRepository.updateRef(ref.getName)
|
||||||
|
update.setForceUpdate(true)
|
||||||
|
val result = update.delete()
|
||||||
|
result match {
|
||||||
|
case Result.FORCED => NoContent()
|
||||||
|
case _ => UnprocessableEntity(result.name())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import gitbucket.core.controller.{Context, ControllerBase}
|
|||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
||||||
|
import org.scalatra.{ActionResult, NoContent}
|
||||||
|
|
||||||
trait ApiIssueCommentControllerBase extends ControllerBase {
|
trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
@@ -14,8 +15,8 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator =>
|
with ReferrerAuthenticator =>
|
||||||
/*
|
/*
|
||||||
* i. List comments on an issue
|
* i. List issue comments for a repository
|
||||||
* https://developer.github.com/v3/issues/comments/#list-comments-on-an-issue
|
* https://docs.github.com/en/rest/reference/issues#list-issue-comments-for-a-repository
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/issues/:id/comments")(referrersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -30,18 +31,90 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. List comments in a repository
|
* ii. Get an issue comment
|
||||||
* https://developer.github.com/v3/issues/comments/#list-comments-in-a-repository
|
* 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/:repo/issues/comments/:id")(readableUsersOnly { repository =>
|
||||||
|
val maybeDeleteResponse: Option[Either[ActionResult, Option[Int]]] =
|
||||||
|
for {
|
||||||
|
commentId <- params("id").toIntOpt
|
||||||
|
comment <- getComment(repository.owner, repository.name, commentId.toString)
|
||||||
|
issue <- getIssue(repository.owner, repository.name, comment.issueId.toString)
|
||||||
|
} yield {
|
||||||
|
if (isEditable(repository.owner, repository.name, comment.commentedUserName)) {
|
||||||
|
val maybeDeletedComment = deleteCommentByApi(repository, comment, issue)
|
||||||
|
Right(maybeDeletedComment.map(_.commentId))
|
||||||
|
} else {
|
||||||
|
Left(Unauthorized())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
maybeDeleteResponse
|
||||||
|
.map {
|
||||||
|
case Right(maybeDeletedCommentId) => maybeDeletedCommentId.getOrElse(NotFound())
|
||||||
|
case Left(err) => err
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound())
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. List issue comments
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#list-issue-comments
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Get a single comment
|
* vi. Create an issue comment
|
||||||
* https://developer.github.com/v3/issues/comments/#get-a-single-comment
|
* https://docs.github.com/en/rest/reference/issues#create-an-issue-comment
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* iv. Create a comment
|
|
||||||
* https://developer.github.com/v3/issues/comments/#create-a-comment
|
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/issues/:id/comments")(readableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/issues/:id/comments")(readableUsersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -64,16 +137,6 @@ trait ApiIssueCommentControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
|
||||||
* v. Edit a comment
|
|
||||||
* https://developer.github.com/v3/issues/comments/#edit-a-comment
|
|
||||||
*/
|
|
||||||
|
|
||||||
/*
|
|
||||||
* vi. Delete a comment
|
|
||||||
* https://developer.github.com/v3/issues/comments/#delete-a-comment
|
|
||||||
*/
|
|
||||||
|
|
||||||
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
val baseOwner = getAccountByUserName(repository.owner).get
|
val baseOwner = getAccountByUserName(repository.owner).get
|
||||||
|
|
||||||
val issues: List[(Issue, Account)] =
|
val issues: List[(Issue, Account, Option[Account])] =
|
||||||
searchIssueByApi(
|
searchIssueByApi(
|
||||||
condition = condition,
|
condition = condition,
|
||||||
offset = (page - 1) * PullRequestLimit,
|
offset = (page - 1) * PullRequestLimit,
|
||||||
@@ -40,11 +40,12 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
JsonFormat(issues.map {
|
JsonFormat(issues.map {
|
||||||
case (issue, issueUser) =>
|
case (issue, issueUser, assignedUser) =>
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
repositoryName = RepositoryName(repository),
|
repositoryName = RepositoryName(repository),
|
||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
|
assignee = assignedUser.map(ApiUser(_)),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository)))
|
.map(ApiLabel(_, RepositoryName(repository)))
|
||||||
)
|
)
|
||||||
@@ -59,13 +60,15 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
(for {
|
(for {
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||||
openedUser <- getAccountByUserName(issue.openedUserName)
|
users = getAccountsByUserNames(Set(issue.openedUserName) ++ issue.assignedUserName, Set())
|
||||||
|
openedUser <- users.get(issue.openedUserName)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(
|
JsonFormat(
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
issue,
|
issue,
|
||||||
RepositoryName(repository),
|
RepositoryName(repository),
|
||||||
ApiUser(openedUser),
|
ApiUser(openedUser),
|
||||||
|
issue.assignedUserName.flatMap(users.get(_)).map(ApiUser(_)),
|
||||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -98,6 +101,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
issue,
|
issue,
|
||||||
RepositoryName(repository),
|
RepositoryName(repository),
|
||||||
ApiUser(loginAccount),
|
ApiUser(loginAccount),
|
||||||
|
issue.assignedUserName.flatMap(getAccountByUserName(_)).map(ApiUser(_)),
|
||||||
getIssueLabels(repository.owner, repository.name, issue.issueId)
|
getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository)))
|
.map(ApiLabel(_, RepositoryName(repository)))
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -0,0 +1,118 @@
|
|||||||
|
package gitbucket.core.controller.api
|
||||||
|
import gitbucket.core.api._
|
||||||
|
import gitbucket.core.controller.ControllerBase
|
||||||
|
import gitbucket.core.service.MilestonesService
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import org.scalatra.NoContent
|
||||||
|
|
||||||
|
trait ApiIssueMilestoneControllerBase extends ControllerBase {
|
||||||
|
self: MilestonesService with WritableUsersAuthenticator with ReferrerAuthenticator =>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* i. List milestones
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#list-milestones
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/milestones")(referrersOnly { repository =>
|
||||||
|
val state = params.getOrElse("state", "all")
|
||||||
|
// TODO "sort", "direction" params should be implemented.
|
||||||
|
val apiMilestones = (for (milestoneWithIssue <- getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
|
.sortBy(p => p._1.milestoneId))
|
||||||
|
yield {
|
||||||
|
ApiMilestone(
|
||||||
|
repository.repository,
|
||||||
|
milestoneWithIssue._1,
|
||||||
|
milestoneWithIssue._2,
|
||||||
|
milestoneWithIssue._3
|
||||||
|
)
|
||||||
|
}).reverse
|
||||||
|
state match {
|
||||||
|
case "all" => JsonFormat(apiMilestones)
|
||||||
|
case "open" | "closed" =>
|
||||||
|
JsonFormat(
|
||||||
|
apiMilestones.filter(p => p.state == state)
|
||||||
|
)
|
||||||
|
case _ => NotFound()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ii. Create a milestone
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#create-a-milestone
|
||||||
|
*/
|
||||||
|
post("/api/v3/repos/:owner/:repository/milestones")(writableUsersOnly { repository =>
|
||||||
|
(for {
|
||||||
|
data <- extractFromJsonBody[CreateAMilestone] if data.isValid
|
||||||
|
milestoneId = createMilestone(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
data.title,
|
||||||
|
data.description,
|
||||||
|
data.due_on
|
||||||
|
)
|
||||||
|
apiMilestone <- getApiMilestone(repository, milestoneId)
|
||||||
|
} yield {
|
||||||
|
JsonFormat(apiMilestone)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iii. Get a milestone
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#get-a-milestone
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/milestones/:number")(referrersOnly { repository =>
|
||||||
|
val milestoneId = params("number").toInt // use milestoneId as number
|
||||||
|
(for (apiMilestone <- getApiMilestone(repository, milestoneId)) yield {
|
||||||
|
JsonFormat(apiMilestone)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iv.Update a milestone
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#update-a-milestone
|
||||||
|
*/
|
||||||
|
patch("/api/v3/repos/:owner/:repository/milestones/:number")(writableUsersOnly { repository =>
|
||||||
|
val milestoneId = params("number").toInt
|
||||||
|
(for {
|
||||||
|
data <- extractFromJsonBody[CreateAMilestone] if data.isValid
|
||||||
|
milestone <- getMilestone(repository.owner, repository.name, milestoneId)
|
||||||
|
_ = (data.state, milestone.closedDate) match {
|
||||||
|
case ("open", Some(_)) =>
|
||||||
|
openMilestone(milestone)
|
||||||
|
case ("closed", None) =>
|
||||||
|
closeMilestone(milestone)
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
milestone <- getMilestone(repository.owner, repository.name, milestoneId)
|
||||||
|
_ = updateMilestone(milestone.copy(title = data.title, description = data.description, dueDate = data.due_on))
|
||||||
|
apiMilestone <- getApiMilestone(repository, milestoneId)
|
||||||
|
} yield {
|
||||||
|
JsonFormat(apiMilestone)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. Delete a milestone
|
||||||
|
* https://docs.github.com/en/rest/reference/issues#delete-a-milestone
|
||||||
|
*/
|
||||||
|
delete("/api/v3/repos/:owner/:repository/milestones/:number")(writableUsersOnly { repository =>
|
||||||
|
val milestoneId = params("number").toInt // use milestoneId as number
|
||||||
|
deleteMilestone(repository.owner, repository.name, milestoneId)
|
||||||
|
NoContent()
|
||||||
|
})
|
||||||
|
|
||||||
|
private def getApiMilestone(repository: RepositoryInfo, milestoneId: Int): Option[ApiMilestone] = {
|
||||||
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
|
.find(p => p._1.milestoneId == milestoneId)
|
||||||
|
.map(
|
||||||
|
milestoneWithIssue =>
|
||||||
|
ApiMilestone(
|
||||||
|
repository.repository,
|
||||||
|
milestoneWithIssue._1,
|
||||||
|
milestoneWithIssue._2,
|
||||||
|
milestoneWithIssue._3
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -8,12 +8,12 @@ import gitbucket.core.service.PullRequestService.PullRequestLimit
|
|||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.scalatra.NoContent
|
import org.scalatra.{Conflict, MethodNotAllowed, NoContent, Ok}
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
|
|
||||||
trait ApiPullRequestControllerBase extends ControllerBase {
|
trait ApiPullRequestControllerBase extends ControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
@@ -114,7 +114,9 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
requestBranch = reqBranch,
|
requestBranch = reqBranch,
|
||||||
commitIdFrom = commitIdFrom.getName,
|
commitIdFrom = commitIdFrom.getName,
|
||||||
commitIdTo = commitIdTo.getName,
|
commitIdTo = commitIdTo.getName,
|
||||||
loginAccount = context.loginAccount.get
|
isDraft = createPullReq.draft.getOrElse(false),
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
)
|
)
|
||||||
getApiPullRequest(repository, issueId).map(JsonFormat(_))
|
getApiPullRequest(repository, issueId).map(JsonFormat(_))
|
||||||
case _ =>
|
case _ =>
|
||||||
@@ -141,7 +143,9 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
requestBranch = reqBranch,
|
requestBranch = reqBranch,
|
||||||
commitIdFrom = commitIdFrom.getName,
|
commitIdFrom = commitIdFrom.getName,
|
||||||
commitIdTo = commitIdTo.getName,
|
commitIdTo = commitIdTo.getName,
|
||||||
loginAccount = context.loginAccount.get
|
isDraft = false,
|
||||||
|
loginAccount = context.loginAccount.get,
|
||||||
|
settings = context.settings
|
||||||
)
|
)
|
||||||
getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_))
|
getApiPullRequest(repository, createPullReqAlt.issue).map(JsonFormat(_))
|
||||||
case _ =>
|
case _ =>
|
||||||
@@ -157,8 +161,28 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Update a pull request
|
* v. Update a pull request
|
||||||
* https://developer.github.com/v3/pulls/#update-a-pull-request
|
* https://docs.github.com/en/rest/reference/pulls#update-a-pull-request
|
||||||
*/
|
*/
|
||||||
|
patch("/api/v3/repos/:owner/:repository/pulls/:id")(referrersOnly { repository =>
|
||||||
|
(for {
|
||||||
|
issueId <- params("id").toIntOpt
|
||||||
|
account <- context.loginAccount
|
||||||
|
settings = context.settings
|
||||||
|
data <- extractFromJsonBody[UpdateAPullRequest]
|
||||||
|
} yield {
|
||||||
|
updatePullRequestsByApi(
|
||||||
|
repository,
|
||||||
|
issueId,
|
||||||
|
account,
|
||||||
|
settings,
|
||||||
|
data.title,
|
||||||
|
data.body,
|
||||||
|
data.state,
|
||||||
|
data.base
|
||||||
|
)
|
||||||
|
JsonFormat(getApiPullRequest(repository, issueId))
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. List commits on a pull request
|
* vi. List commits on a pull request
|
||||||
@@ -171,7 +195,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
issueId =>
|
issueId =>
|
||||||
getPullRequest(owner, name, issueId) map {
|
getPullRequest(owner, name, issueId) map {
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
using(Git.open(getRepositoryDir(owner, name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(owner, name))) { git =>
|
||||||
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
val oldId = git.getRepository.resolve(pullreq.commitIdFrom)
|
||||||
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
val newId = git.getRepository.resolve(pullreq.commitIdTo)
|
||||||
val repoFullName = RepositoryName(repository)
|
val repoFullName = RepositoryName(repository)
|
||||||
@@ -206,15 +230,79 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
||||||
NoContent
|
NoContent
|
||||||
} else {
|
} else {
|
||||||
NotFound
|
NotFound()
|
||||||
}
|
}
|
||||||
}).getOrElse(NotFound)
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. Merge a pull request (Merge Button)
|
* ix. Merge a pull request (Merge Button)
|
||||||
* https://developer.github.com/v3/pulls/#merge-a-pull-request-merge-button
|
* https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request
|
||||||
*/
|
*/
|
||||||
|
put("/api/v3/repos/:owner/:repository/pulls/:id/merge")(referrersOnly { repository =>
|
||||||
|
(for {
|
||||||
|
//TODO: crash when body is empty
|
||||||
|
//TODO: Implement sha parameter
|
||||||
|
data <- extractFromJsonBody[MergeAPullRequest]
|
||||||
|
issueId <- params("id").toIntOpt
|
||||||
|
(issue, pullReq) <- getPullRequest(repository.owner, repository.name, issueId)
|
||||||
|
} yield {
|
||||||
|
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
||||||
|
Conflict(
|
||||||
|
JsonFormat(
|
||||||
|
FailToMergePrResponse(
|
||||||
|
message = "Head branch was modified. Review and try the merge again.",
|
||||||
|
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
if (issue.closed) {
|
||||||
|
MethodNotAllowed(
|
||||||
|
JsonFormat(
|
||||||
|
FailToMergePrResponse(
|
||||||
|
message = "Pull Request is not mergeable, Closed",
|
||||||
|
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val strategy =
|
||||||
|
if (data.merge_method.getOrElse("merge-commit") == "merge") "merge-commit"
|
||||||
|
else data.merge_method.getOrElse("merge-commit")
|
||||||
|
mergePullRequest(
|
||||||
|
repository,
|
||||||
|
issueId,
|
||||||
|
context.loginAccount.get,
|
||||||
|
data.commit_message.getOrElse(""), //TODO: Implement commit_title
|
||||||
|
strategy,
|
||||||
|
pullReq.isDraft,
|
||||||
|
context.settings
|
||||||
|
) match {
|
||||||
|
case Right(objectId) =>
|
||||||
|
Ok(
|
||||||
|
JsonFormat(
|
||||||
|
SuccessToMergePrResponse(
|
||||||
|
sha = objectId.toString,
|
||||||
|
merged = true,
|
||||||
|
message = "Pull Request successfully merged"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
case Left(message) =>
|
||||||
|
MethodNotAllowed(
|
||||||
|
JsonFormat(
|
||||||
|
FailToMergePrResponse(
|
||||||
|
message = "Pull Request is not mergeable",
|
||||||
|
documentation_url = "https://docs.github.com/en/rest/reference/pulls#merge-a-pull-request",
|
||||||
|
)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. Labels, assignees, and milestones
|
* x. Labels, assignees, and milestones
|
||||||
|
|||||||
@@ -3,11 +3,13 @@ import gitbucket.core.api._
|
|||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.{AccountService, ProtectedBranchService, RepositoryService}
|
import gitbucket.core.service.{AccountService, ProtectedBranchService, RepositoryService}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.JGitUtil.getBranches
|
import gitbucket.core.util.JGitUtil.getBranches
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.scalatra.NoContent
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -22,10 +24,10 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* i. List branches
|
* i. List branches
|
||||||
* https://developer.github.com/v3/repos/branches/#list-branches
|
* https://docs.github.com/en/rest/reference/repos#list-branches
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/branches")(referrersOnly { repository =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JsonFormat(
|
JsonFormat(
|
||||||
JGitUtil
|
JGitUtil
|
||||||
.getBranches(
|
.getBranches(
|
||||||
@@ -41,11 +43,11 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get branch
|
* ii. Get a branch
|
||||||
* https://developer.github.com/v3/repos/branches/#get-branch
|
* https://docs.github.com/en/rest/reference/repos#get-a-branch
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/branches/*")(referrersOnly { repository =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
(for {
|
(for {
|
||||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||||
@@ -65,147 +67,206 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* iii. Get branch protection
|
* iii. Get branch protection
|
||||||
* https://developer.github.com/v3/repos/branches/#get-branch-protection
|
* https://docs.github.com/en/rest/reference/repos#get-branch-protection
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/branches/:branch/protection")(referrersOnly { repository =>
|
||||||
|
val branch = params("branch")
|
||||||
|
if (repository.branchList.contains(branch)) {
|
||||||
|
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
|
JsonFormat(
|
||||||
|
ApiBranchProtection(protection)
|
||||||
|
)
|
||||||
|
} else { NotFound() }
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* iv. Update branch protection
|
* iv. Update branch protection
|
||||||
* https://developer.github.com/v3/repos/branches/#update-branch-protection
|
* https://docs.github.com/en/rest/reference/repos#update-branch-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Remove branch protection
|
* v. Delete branch protection
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Get required status checks of protected branch
|
* vii. Set admin branch protection
|
||||||
* https://developer.github.com/v3/repos/branches/#get-required-status-checks-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#set-admin-branch-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vii. Update required status checks of protected branch
|
* viii. Delete admin branch protection
|
||||||
* https://developer.github.com/v3/repos/branches/#update-required-status-checks-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#delete-admin-branch-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* viii. Remove required status checks of protected branch
|
* ix. Get pull request review protection
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-pull-request-review-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. List required status checks contexts of protected branch
|
* x. Update pull request review protection
|
||||||
* https://developer.github.com/v3/repos/branches/#list-required-status-checks-contexts-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#update-pull-request-review-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. Replace required status checks contexts of protected branch
|
* xi. Delete pull request review protection
|
||||||
* https://developer.github.com/v3/repos/branches/#replace-required-status-checks-contexts-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#delete-pull-request-review-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xi. Add required status checks contexts of protected branch
|
* xii. Get commit signature protection
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-commit-signature-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xii. Remove required status checks contexts of protected branch
|
* xiii. Create commit signature protection
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-required-status-checks-contexts-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#create-commit-signature-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiii. Get pull request review enforcement of protected branch
|
* xiv. Delete commit signature protection
|
||||||
* https://developer.github.com/v3/repos/branches/#get-pull-request-review-enforcement-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#delete-commit-signature-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiv. Update pull request review enforcement of protected branch
|
* xv. Get status checks protection
|
||||||
* https://developer.github.com/v3/repos/branches/#update-pull-request-review-enforcement-of-protected-branch
|
* 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(
|
||||||
|
ApiBranchProtection(protection).required_status_checks
|
||||||
|
)
|
||||||
|
} else { NotFound() }
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* xvi. Update status check protection
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#update-status-check-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xv. Remove pull request review enforcement of protected branch
|
* xvii. Remove status check protection
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-pull-request-review-enforcement-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#remove-status-check-protection
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xvi. Get required signatures of protected branch
|
* xviii. Get all status check contexts
|
||||||
* https://developer.github.com/v3/repos/branches/#get-required-signatures-of-protected-branch
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xvii. Add required signatures of protected branch
|
* xx. Set status check contexts
|
||||||
* https://developer.github.com/v3/repos/branches/#add-required-signatures-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#set-status-check-contexts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xviii. Remove required signatures of protected branch
|
* xxi. Remove status check contexts
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-required-signatures-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#remove-status-check-contexts
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xix. Get admin enforcement of protected branch
|
* xxii. Get access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#get-admin-enforcement-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xx. Add admin enforcement of protected branch
|
* xxiii. Delete access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#add-admin-enforcement-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#delete-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxi. Remove admin enforcement of protected branch
|
* xxiv. Get apps with access to the protected branch
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-admin-enforcement-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-apps-with-access-to-the-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxii. Get restrictions of protected branch
|
* xxv. Add app access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#get-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#add-app-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxiii. Remove restrictions of protected branch
|
* xxvi. Set app access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#set-app-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxiv. List team restrictions of protected branch
|
* xxvii. Remove app access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#list-team-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#remove-app-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxv. Replace team restrictions of protected branch
|
* xxviii. Get teams with access to the protected branch
|
||||||
* https://developer.github.com/v3/repos/branches/#replace-team-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-teams-with-access-to-the-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxvi. Add team restrictions of protected branch
|
* xxix. Add team access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#add-team-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#add-team-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxvii. Remove team restrictions of protected branch
|
* xxx. Set team access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-team-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#set-team-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxviii. List user restrictions of protected branch
|
* xxxi. Remove team access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#list-user-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#remove-team-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxix. Replace user restrictions of protected branch
|
* xxxii. Get users with access to the protected branch
|
||||||
* https://developer.github.com/v3/repos/branches/#replace-user-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#get-users-with-access-to-the-protected-branch
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxx. Add user restrictions of protected branch
|
* xxxiii. Add user access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#add-user-restrictions-of-protected-branch
|
* https://docs.github.com/en/rest/reference/repos#add-user-access-restrictions
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xxxi. Remove user restrictions of protected branch
|
* xxxiv. Set user access restrictions
|
||||||
* https://developer.github.com/v3/repos/branches/#remove-user-restrictions-of-protected-branch
|
* 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
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -214,7 +275,7 @@ trait ApiRepositoryBranchControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/branches/*")(ownerOnly { repository =>
|
patch("/api/v3/repos/:owner/:repository/branches/*")(ownerOnly { repository =>
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
(for {
|
(for {
|
||||||
branch <- params.get("splat") if repository.branchList.contains(branch)
|
branch <- params.get("splat") if repository.branchList.contains(branch)
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{AddACollaborator, ApiUser, JsonFormat}
|
import gitbucket.core.api.{AddACollaborator, ApiRepositoryCollaborator, ApiUser, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -10,8 +10,8 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
self: RepositoryService with AccountService with ReferrerAuthenticator with OwnerAuthenticator =>
|
self: RepositoryService with AccountService with ReferrerAuthenticator with OwnerAuthenticator =>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* i. List collaborators
|
* i. List repository collaborators
|
||||||
* https://developer.github.com/v3/repos/collaborators/#list-collaborators
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#list-repository-collaborators
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/collaborators")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/collaborators")(referrersOnly { repository =>
|
||||||
// TODO Should ApiUser take permission? getCollaboratorUserNames does not return owner group members.
|
// TODO Should ApiUser take permission? getCollaboratorUserNames does not return owner group members.
|
||||||
@@ -19,19 +19,40 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
getCollaboratorUserNames(params("owner"), params("repository")).map(u => ApiUser(getAccountByUserName(u).get))
|
getCollaboratorUserNames(params("owner"), params("repository")).map(u => ApiUser(getAccountByUserName(u).get))
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Check if a user is a collaborator
|
* ii. Check if a user is a collaborator
|
||||||
* https://developer.github.com/v3/repos/collaborators/#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
|
||||||
*/
|
*/
|
||||||
|
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. Review a user's permission level
|
* iii. Get repository permissions for a user
|
||||||
* https://developer.github.com/v3/repos/collaborators/#review-a-users-permission-level
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#get-repository-permissions-for-a-user
|
||||||
*/
|
*/
|
||||||
|
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 user as a collaborator
|
* iv. Add a repository collaborator
|
||||||
* https://developer.github.com/v3/repos/collaborators/#add-user-as-a-collaborator
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#add-a-repository-collaborator
|
||||||
* requested #1586
|
* requested #1586
|
||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||||
@@ -44,8 +65,8 @@ trait ApiRepositoryCollaboratorControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Remove user as a collaborator
|
* v. Remove a repository collaborator
|
||||||
* https://developer.github.com/v3/repos/collaborators/#remove-user-as-a-collaborator
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/repos#remove-a-repository-collaborator
|
||||||
* requested #1586
|
* requested #1586
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
delete("/api/v3/repos/:owner/:repository/collaborators/:userName")(ownerOnly { repository =>
|
||||||
|
|||||||
@@ -1,22 +1,51 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiCommits, JsonFormat}
|
import gitbucket.core.api.{ApiBranchCommit, ApiBranchForHeadCommit, ApiCommits, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service.{AccountService, CommitsService}
|
import gitbucket.core.service.{AccountService, CommitsService, ProtectedBranchService}
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil.{CommitInfo, getBranches, getBranchesOfCommit}
|
||||||
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
|
|
||||||
|
import scala.jdk.CollectionConverters._
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
||||||
self: AccountService with CommitsService with ReferrerAuthenticator =>
|
self: AccountService with CommitsService with ProtectedBranchService with ReferrerAuthenticator =>
|
||||||
/*
|
/*
|
||||||
* i. List commits on a repository
|
* i. List commits on a repository
|
||||||
* https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
* https://developer.github.com/v3/repos/commits/#list-commits-on-a-repository
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/commits")(referrersOnly { repository =>
|
||||||
|
val owner = repository.owner
|
||||||
|
val name = repository.name
|
||||||
|
// TODO: The following parameters need to be implemented. [:path, :author, :since, :until]
|
||||||
|
val sha = params.getOrElse("sha", "refs/heads/master")
|
||||||
|
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
||||||
|
git =>
|
||||||
|
val repo = git.getRepository
|
||||||
|
Using.resource(new RevWalk(repo)) {
|
||||||
|
revWalk =>
|
||||||
|
val objectId = repo.resolve(sha)
|
||||||
|
revWalk.markStart(revWalk.parseCommit(objectId))
|
||||||
|
JsonFormat(revWalk.asScala.take(30).map {
|
||||||
|
commit =>
|
||||||
|
val commitInfo = new CommitInfo(commit)
|
||||||
|
ApiCommits(
|
||||||
|
repositoryName = RepositoryName(repository),
|
||||||
|
commitInfo = commitInfo,
|
||||||
|
diffs = JGitUtil.getDiffs(git, commitInfo.parents.headOption, commitInfo.id, false, true),
|
||||||
|
author = getAccount(commitInfo.authorName, commitInfo.authorEmailAddress),
|
||||||
|
committer = getAccount(commitInfo.committerName, commitInfo.committerEmailAddress),
|
||||||
|
commentCount = getCommitComment(repository.owner, repository.name, commitInfo.id.toString).size
|
||||||
|
)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Get a single commit
|
* ii. Get a single commit
|
||||||
@@ -27,11 +56,11 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
val name = repository.name
|
val name = repository.name
|
||||||
val sha = params("sha")
|
val sha = params("sha")
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(owner, name))) {
|
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
||||||
git =>
|
git =>
|
||||||
val repo = git.getRepository
|
val repo = git.getRepository
|
||||||
val objectId = repo.resolve(sha)
|
val objectId = repo.resolve(sha)
|
||||||
val commitInfo = using(new RevWalk(repo)) { revWalk =>
|
val commitInfo = Using.resource(new RevWalk(repo)) { revWalk =>
|
||||||
new CommitInfo(revWalk.parseCommit(objectId))
|
new CommitInfo(revWalk.parseCommit(objectId))
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,7 +108,25 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Commit signature verification
|
* v. Commit signature verification
|
||||||
* https://developer.github.com/v3/repos/commits/#commit-signature-verification
|
* https://developer.github.com/v3/repos/commits/#commit-signature-verification
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vi. List branches for HEAD commit
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#list-branches-for-head-commit
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/commits/:sha/branches-where-head")(referrersOnly { repository =>
|
||||||
|
val sha = params("sha")
|
||||||
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
|
val apiBranchForCommits = for {
|
||||||
|
branch <- getBranchesOfCommit(git, sha)
|
||||||
|
br <- getBranches(git, branch, repository.repository.originUserName.isEmpty).find(_.name == branch)
|
||||||
|
} yield {
|
||||||
|
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
|
ApiBranchForHeadCommit(branch, ApiBranchCommit(br.commitId), protection.enabled)
|
||||||
|
}
|
||||||
|
JsonFormat(apiBranchForCommits)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,22 +1,38 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiContents, ApiError, CreateAFile, JsonFormat}
|
import gitbucket.core.api.{ApiContents, ApiError, CreateAFile, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.JGitUtil.{FileInfo, getContentFromId, getFileList}
|
import gitbucket.core.util.JGitUtil.{FileInfo, getContentFromId, getFileList}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
||||||
self: ReferrerAuthenticator with WritableUsersAuthenticator with RepositoryCommitFileService =>
|
self: ReferrerAuthenticator with WritableUsersAuthenticator with RepositoryCommitFileService =>
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* i. Get the README
|
* i. Get a repository README
|
||||||
* https://developer.github.com/v3/repos/contents/#get-the-readme
|
* https://docs.github.com/en/rest/reference/repos#get-a-repository-readme
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/readme")(referrersOnly { repository =>
|
||||||
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
||||||
|
git =>
|
||||||
|
val refStr = params.getOrElse("ref", repository.repository.defaultBranch)
|
||||||
|
val files = getFileList(git, refStr, ".", maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
|
files // files should be sorted alphabetically.
|
||||||
|
.find { file =>
|
||||||
|
!file.isDirectory && RepositoryService.readmeFiles.contains(file.name.toLowerCase)
|
||||||
|
} match {
|
||||||
|
case Some(x) => getContents(repository = repository, path = x.name, refStr = refStr, ignoreCase = true)
|
||||||
|
case _ => NotFound()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get contents
|
* ii. Get contents
|
||||||
@@ -34,21 +50,32 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getContents(repository: RepositoryService.RepositoryInfo, path: String, refStr: String) = {
|
private def getContents(
|
||||||
def getFileInfo(git: Git, revision: String, pathStr: String): Option[FileInfo] = {
|
repository: RepositoryService.RepositoryInfo,
|
||||||
|
path: String,
|
||||||
|
refStr: String,
|
||||||
|
ignoreCase: Boolean = false
|
||||||
|
) = {
|
||||||
|
def getFileInfo(git: Git, revision: String, pathStr: String, ignoreCase: Boolean): Option[FileInfo] = {
|
||||||
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
||||||
case -1 =>
|
case -1 =>
|
||||||
(".", pathStr)
|
(".", pathStr)
|
||||||
case n =>
|
case n =>
|
||||||
(pathStr.take(n), pathStr.drop(n + 1))
|
(pathStr.take(n), pathStr.drop(n + 1))
|
||||||
}
|
}
|
||||||
getFileList(git, revision, dirName).find(f => f.name.equals(fileName))
|
if (ignoreCase) {
|
||||||
|
getFileList(git, revision, dirName, maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
|
.find(_.name.toLowerCase.equals(fileName.toLowerCase))
|
||||||
|
} else {
|
||||||
|
getFileList(git, revision, dirName, maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
|
.find(_.name.equals(fileName))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
val fileList = getFileList(git, refStr, path)
|
val fileList = getFileList(git, refStr, path, maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
if (fileList.isEmpty) { // file or NotFound
|
if (fileList.isEmpty) { // file or NotFound
|
||||||
getFileInfo(git, refStr, path)
|
getFileInfo(git, refStr, path, ignoreCase)
|
||||||
.flatMap { f =>
|
.flatMap { f =>
|
||||||
val largeFile = params.get("large_file").exists(s => s.equals("true"))
|
val largeFile = params.get("large_file").exists(s => s.equals("true"))
|
||||||
val content = getContentFromId(git, f.id, largeFile)
|
val content = getContentFromId(git, f.id, largeFile)
|
||||||
@@ -113,7 +140,7 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
data <- extractFromJsonBody[CreateAFile]
|
data <- extractFromJsonBody[CreateAFile]
|
||||||
} yield {
|
} yield {
|
||||||
val branch = data.branch.getOrElse(repository.repository.defaultBranch)
|
val branch = data.branch.getOrElse(repository.repository.defaultBranch)
|
||||||
val commit = using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
val commit = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
revCommit.name
|
revCommit.name
|
||||||
}
|
}
|
||||||
@@ -127,17 +154,14 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
branch,
|
branch,
|
||||||
path,
|
path,
|
||||||
Some(paths.last),
|
Some(paths.last),
|
||||||
if (data.sha.isDefined) {
|
data.sha.map(_ => paths.last),
|
||||||
Some(paths.last)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
StringUtil.base64Decode(data.content),
|
StringUtil.base64Decode(data.content),
|
||||||
data.message,
|
data.message,
|
||||||
commit,
|
commit,
|
||||||
context.loginAccount.get,
|
context.loginAccount.get,
|
||||||
data.committer.map(_.name).getOrElse(context.loginAccount.get.fullName),
|
data.committer.map(_.name).getOrElse(context.loginAccount.get.fullName),
|
||||||
data.committer.map(_.email).getOrElse(context.loginAccount.get.mailAddress)
|
data.committer.map(_.email).getOrElse(context.loginAccount.get.mailAddress),
|
||||||
|
context.settings
|
||||||
)
|
)
|
||||||
ApiContents("file", paths.last, path, objectId.name, None, None)(RepositoryName(repository))
|
ApiContents("file", paths.last, path, objectId.name, None, None)(RepositoryName(repository))
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,12 +6,12 @@ import gitbucket.core.servlet.Database
|
|||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.SyntaxSugars.using
|
|
||||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
import scala.concurrent.duration.Duration
|
import scala.concurrent.duration.Duration
|
||||||
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiRepositoryControllerBase extends ControllerBase {
|
trait ApiRepositoryControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
@@ -54,11 +54,15 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/**
|
||||||
* iv. List all public repositories
|
* iv. List all public repositories
|
||||||
* https://developer.github.com/v3/repos/#list-all-public-repositories
|
* https://developer.github.com/v3/repos/#list-public-repositories
|
||||||
* Not implemented
|
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repositories") {
|
||||||
|
JsonFormat(getPublicRepositories().map { r =>
|
||||||
|
ApiRepository(r, getAccountByUserName(r.owner).get)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Create
|
* v. Create
|
||||||
@@ -174,9 +178,14 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiii. List tags
|
* xiii. List repository tags
|
||||||
* https://developer.github.com/v3/repos/#list-tags
|
* https://docs.github.com/en/rest/reference/repos#list-repository-tags
|
||||||
*/
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/tags")(referrersOnly { repository =>
|
||||||
|
JsonFormat(
|
||||||
|
repository.tags.map(tagInfo => ApiTag(tagInfo.name, RepositoryName(repository), tagInfo.id))
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiv. Delete a repository
|
* xiv. Delete a repository
|
||||||
@@ -193,7 +202,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/raw/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/raw/*")(referrersOnly { repository =>
|
||||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ trait ApiRepositoryStatusControllerBase extends ControllerBase {
|
|||||||
ref <- params.get("ref")
|
ref <- params.get("ref")
|
||||||
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(getCommitStatuesWithCreator(repository.owner, repository.name, sha).map {
|
JsonFormat(getCommitStatusesWithCreator(repository.owner, repository.name, sha).map {
|
||||||
case (status, creator) =>
|
case (status, creator) =>
|
||||||
ApiCommitStatus(status, ApiUser(creator))
|
ApiCommitStatus(status, ApiUser(creator))
|
||||||
})
|
})
|
||||||
@@ -73,7 +73,7 @@ trait ApiRepositoryStatusControllerBase extends ControllerBase {
|
|||||||
owner <- getAccountByUserName(repository.owner)
|
owner <- getAccountByUserName(repository.owner)
|
||||||
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
sha <- JGitUtil.getShaByRef(repository.owner, repository.name, ref)
|
||||||
} yield {
|
} yield {
|
||||||
val statuses = getCommitStatuesWithCreator(repository.owner, repository.name, sha)
|
val statuses = getCommitStatusesWithCreator(repository.owner, repository.name, sha)
|
||||||
JsonFormat(ApiCombinedCommitStatus(sha, statuses, ApiRepository(repository, owner)))
|
JsonFormat(ApiCombinedCommitStatus(sha, statuses, ApiRepository(repository, owner)))
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -0,0 +1,120 @@
|
|||||||
|
package gitbucket.core.controller.api
|
||||||
|
import gitbucket.core.api._
|
||||||
|
import gitbucket.core.controller.ControllerBase
|
||||||
|
import gitbucket.core.model.{WebHook, WebHookContentType}
|
||||||
|
import gitbucket.core.service.{RepositoryService, WebHookService}
|
||||||
|
import gitbucket.core.util._
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import org.scalatra.NoContent
|
||||||
|
|
||||||
|
trait ApiRepositoryWebhookControllerBase extends ControllerBase {
|
||||||
|
self: RepositoryService with WebHookService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||||
|
|
||||||
|
/*
|
||||||
|
* i. List repository webhooks
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#list-repository-webhooks
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/hooks")(referrersOnly { repository =>
|
||||||
|
val apiWebhooks = for {
|
||||||
|
(hook, events) <- getWebHooks(repository.owner, repository.name)
|
||||||
|
} yield {
|
||||||
|
ApiWebhook("Repository", hook, events)
|
||||||
|
}
|
||||||
|
JsonFormat(apiWebhooks)
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* ii. Create a repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#create-a-repository-webhook
|
||||||
|
*/
|
||||||
|
post("/api/v3/repos/:owner/:repository/hooks")(writableUsersOnly { repository =>
|
||||||
|
(for {
|
||||||
|
data <- extractFromJsonBody[CreateARepositoryWebhook] if data.isValid
|
||||||
|
ctype = if (data.config.content_type == "form") WebHookContentType.FORM else WebHookContentType.JSON
|
||||||
|
events = data.events.map(p => WebHook.Event.valueOf(p)).toSet
|
||||||
|
} yield {
|
||||||
|
addWebHook(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
data.config.url,
|
||||||
|
events,
|
||||||
|
ctype,
|
||||||
|
data.config.secret
|
||||||
|
)
|
||||||
|
getWebHook(repository.owner, repository.name, data.config.url) match {
|
||||||
|
case Some(createdHook) => JsonFormat(ApiWebhook("Repository", createdHook._1, createdHook._2))
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iii. Get a repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#get-a-repository-webhook
|
||||||
|
*/
|
||||||
|
get("/api/v3/repos/:owner/:repository/hooks/:id")(referrersOnly { repository =>
|
||||||
|
val hookId = params("id").toInt
|
||||||
|
getWebHookById(hookId) match {
|
||||||
|
case Some(hook) => JsonFormat(ApiWebhook("Repository", hook._1, hook._2))
|
||||||
|
case _ => NotFound()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* iv. Update a repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#update-a-repository-webhook
|
||||||
|
*/
|
||||||
|
patch("/api/v3/repos/:owner/:repository/hooks/:id")(writableUsersOnly { repository =>
|
||||||
|
val hookId = params("id").toInt
|
||||||
|
(for {
|
||||||
|
data <- extractFromJsonBody[UpdateARepositoryWebhook] if data.isValid
|
||||||
|
ctype = data.config.content_type match {
|
||||||
|
case "json" => WebHookContentType.JSON
|
||||||
|
case _ => WebHookContentType.FORM
|
||||||
|
}
|
||||||
|
} yield {
|
||||||
|
val events = (data.events ++ data.add_events)
|
||||||
|
.filterNot(p => data.remove_events.contains(p))
|
||||||
|
.map(p => WebHook.Event.valueOf(p))
|
||||||
|
.toSet
|
||||||
|
updateWebHookByApi(
|
||||||
|
hookId,
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
data.config.url,
|
||||||
|
events,
|
||||||
|
ctype,
|
||||||
|
data.config.secret
|
||||||
|
)
|
||||||
|
getWebHookById(hookId) match {
|
||||||
|
case Some(updatedHook) => JsonFormat(ApiWebhook("Repository", updatedHook._1, updatedHook._2))
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* v. Delete a repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#delete-a-repository-webhook
|
||||||
|
*/
|
||||||
|
delete("/api/v3/repos/:owner/:repository/hooks/:id")(writableUsersOnly { repository =>
|
||||||
|
val hookId = params("id").toInt
|
||||||
|
getWebHookById(hookId) match {
|
||||||
|
case Some(_) =>
|
||||||
|
deleteWebHookById(params("id").toInt)
|
||||||
|
NoContent()
|
||||||
|
case _ => NotFound()
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vi. Ping a repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#ping-a-repository-webhook
|
||||||
|
*/
|
||||||
|
|
||||||
|
/*
|
||||||
|
* vi. Test the push repository webhook
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#test-the-push-repository-webhook
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
||||||
@@ -4,6 +4,7 @@ import gitbucket.core.controller.ControllerBase
|
|||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.util.{AdminAuthenticator, UsersAuthenticator}
|
import gitbucket.core.util.{AdminAuthenticator, UsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.StringUtil._
|
||||||
import org.scalatra.NoContent
|
import org.scalatra.NoContent
|
||||||
|
|
||||||
trait ApiUserControllerBase extends ControllerBase {
|
trait ApiUserControllerBase extends ControllerBase {
|
||||||
@@ -70,7 +71,7 @@ trait ApiUserControllerBase extends ControllerBase {
|
|||||||
} yield {
|
} yield {
|
||||||
val user = createAccount(
|
val user = createAccount(
|
||||||
data.login,
|
data.login,
|
||||||
data.password,
|
pbkdf2_sha256(data.password),
|
||||||
data.fullName.getOrElse(data.login),
|
data.fullName.getOrElse(data.login),
|
||||||
data.email,
|
data.email,
|
||||||
data.isAdmin.getOrElse(false),
|
data.isAdmin.getOrElse(false),
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait AccessTokenComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
val tokenHash = column[String]("TOKEN_HASH")
|
val tokenHash = column[String]("TOKEN_HASH")
|
||||||
val note = column[String]("NOTE")
|
val note = column[String]("NOTE")
|
||||||
def * = (accessTokenId, userName, tokenHash, note) <> (AccessToken.tupled, AccessToken.unapply)
|
def * = (accessTokenId, userName, tokenHash, note).<>(AccessToken.tupled, AccessToken.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case class AccessToken(
|
case class AccessToken(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ trait AccountComponent { self: Profile =>
|
|||||||
groupAccount,
|
groupAccount,
|
||||||
removed,
|
removed,
|
||||||
description.?
|
description.?
|
||||||
) <> (Account.tupled, Account.unapply)
|
).<>(Account.tupled, Account.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountExtraMailAddressComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
||||||
def * =
|
def * =
|
||||||
(userName, extraMailAddress) <> (AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
(userName, extraMailAddress).<>(AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountFederationComponent { self: Profile =>
|
|||||||
val issuer = column[String]("ISSUER")
|
val issuer = column[String]("ISSUER")
|
||||||
val subject = column[String]("SUBJECT")
|
val subject = column[String]("SUBJECT")
|
||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
def * = (issuer, subject, userName) <> (AccountFederation.tupled, AccountFederation.unapply)
|
def * = (issuer, subject, userName).<>(AccountFederation.tupled, AccountFederation.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
||||||
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
||||||
|
|||||||
21
src/main/scala/gitbucket/core/model/AccountPreference.scala
Normal file
21
src/main/scala/gitbucket/core/model/AccountPreference.scala
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait AccountPreferenceComponent { self: Profile =>
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
|
lazy val AccountPreferences = TableQuery[AccountPreferences]
|
||||||
|
|
||||||
|
class AccountPreferences(tag: Tag) extends Table[AccountPreference](tag, "ACCOUNT_PREFERENCE") {
|
||||||
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
|
val highlighterTheme = column[String]("HIGHLIGHTER_THEME")
|
||||||
|
def * =
|
||||||
|
(userName, highlighterTheme).<>(AccountPreference.tupled, AccountPreference.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(userName: String): Rep[Boolean] = this.userName === userName.bind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class AccountPreference(
|
||||||
|
userName: String,
|
||||||
|
highlighterTheme: String = "prettify"
|
||||||
|
)
|
||||||
@@ -12,7 +12,7 @@ trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val token = column[Option[String]]("TOKEN")
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE")
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
def * = (userName, url, ctype, token) <> ((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
def * = (userName, url, ctype, token).<>((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ trait AccountWebHookEventComponent extends TemplateComponent {
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
|
|
||||||
def * = (userName, url, event) <> ((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
def * = (userName, url, event).<>((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
||||||
|
|
||||||
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
/**
|
||||||
|
* ActivityComponent has been deprecated, but keep it for binary compatibility.
|
||||||
|
*/
|
||||||
|
@deprecated("ActivityComponent has been deprecated, but keep it for binary compatibility.", "4.34.0")
|
||||||
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
@@ -7,14 +11,7 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val Activities = TableQuery[Activities]
|
lazy val Activities = TableQuery[Activities]
|
||||||
|
|
||||||
class Activities(tag: Tag) extends Table[Activity](tag, "ACTIVITY") with BasicTemplate {
|
class Activities(tag: Tag) extends Table[Activity](tag, "ACTIVITY") with BasicTemplate {
|
||||||
val activityId = column[Int]("ACTIVITY_ID", O AutoInc)
|
def * = ???
|
||||||
val activityUserName = column[String]("ACTIVITY_USER_NAME")
|
|
||||||
val activityType = column[String]("ACTIVITY_TYPE")
|
|
||||||
val message = column[String]("MESSAGE")
|
|
||||||
val additionalInfo = column[String]("ADDITIONAL_INFO")
|
|
||||||
val activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
|
||||||
def * =
|
|
||||||
(userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -26,5 +23,5 @@ case class Activity(
|
|||||||
message: String,
|
message: String,
|
||||||
additionalInfo: Option[String],
|
additionalInfo: Option[String],
|
||||||
activityDate: java.util.Date,
|
activityDate: java.util.Date,
|
||||||
activityId: Int = 0
|
activityId: String
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
|||||||
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
||||||
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
||||||
val role = column[String]("ROLE")
|
val role = column[String]("ROLE")
|
||||||
def * = (userName, repositoryName, collaboratorName, role) <> (Collaborator.tupled, Collaborator.unapply)
|
def * = (userName, repositoryName, collaboratorName, role).<>(Collaborator.tupled, Collaborator.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
||||||
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate) <> (IssueComment.tupled, IssueComment.unapply)
|
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate)
|
||||||
|
.<>(IssueComment.tupled, IssueComment.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
@@ -74,7 +75,7 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
originalCommitId,
|
originalCommitId,
|
||||||
originalOldLine,
|
originalOldLine,
|
||||||
originalNewLine
|
originalNewLine
|
||||||
) <> (CommitComment.tupled, CommitComment.unapply)
|
).<>(CommitComment.tupled, CommitComment.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
|||||||
creator,
|
creator,
|
||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate
|
updatedDate
|
||||||
) <> ((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
).<>((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
||||||
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ trait DeployKeyComponent extends TemplateComponent { self: Profile =>
|
|||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite) <> (DeployKey.tupled, DeployKey.unapply)
|
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite).<>(DeployKey.tupled, DeployKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ trait GpgKeyComponent { self: Profile =>
|
|||||||
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, keyId, gpgKeyId, title, publicKey) <> (GpgKey.tupled, GpgKey.unapply)
|
def * = (userName, keyId, gpgKeyId, title, publicKey).<>(GpgKey.tupled, GpgKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, keyId: Int) =
|
def byPrimaryKey(userName: String, keyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait GroupMemberComponent { self: Profile =>
|
|||||||
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val isManager = column[Boolean]("MANAGER")
|
val isManager = column[Boolean]("MANAGER")
|
||||||
def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply)
|
def * = (groupName, userName, isManager).<>(GroupMember.tupled, GroupMember.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
|||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate,
|
updatedDate,
|
||||||
pullRequest
|
pullRequest
|
||||||
) <> (Issue.tupled, Issue.unapply)
|
).<>(Issue.tupled, Issue.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val IssueLabels = TableQuery[IssueLabels]
|
lazy val IssueLabels = TableQuery[IssueLabels]
|
||||||
|
|
||||||
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
||||||
def * = (userName, repositoryName, issueId, labelId) <> (IssueLabel.tupled, IssueLabel.unapply)
|
def * = (userName, repositoryName, issueId, labelId).<>(IssueLabel.tupled, IssueLabel.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
||||||
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
||||||
override val labelName = column[String]("LABEL_NAME")
|
override val labelName = column[String]("LABEL_NAME")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply)
|
def * = (userName, repositoryName, labelId, labelName, color).<>(Label.tupled, Label.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
|||||||
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
||||||
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate) <> (Milestone.tupled, Milestone.unapply)
|
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate)
|
||||||
|
.<>(Milestone.tupled, Milestone.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ trait PriorityComponent extends TemplateComponent { self: Profile =>
|
|||||||
val isDefault = column[Boolean]("IS_DEFAULT")
|
val isDefault = column[Boolean]("IS_DEFAULT")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color) <> (Priority.tupled, Priority.unapply)
|
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color)
|
||||||
|
.<>(Priority.tupled, Priority.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
||||||
|
|||||||
@@ -70,5 +70,6 @@ trait CoreProfile
|
|||||||
with ReleaseTagComponent
|
with ReleaseTagComponent
|
||||||
with ReleaseAssetComponent
|
with ReleaseAssetComponent
|
||||||
with AccountExtraMailAddressComponent
|
with AccountExtraMailAddressComponent
|
||||||
|
with AccountPreferenceComponent
|
||||||
|
|
||||||
object Profile extends CoreProfile
|
object Profile extends CoreProfile
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
||||||
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
||||||
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
||||||
def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply)
|
def * = (userName, repositoryName, branch, statusCheckAdmin).<>(ProtectedBranch.tupled, ProtectedBranch.unapply)
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
||||||
byBranch(userName, repositoryName, branch)
|
byBranch(userName, repositoryName, branch)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
||||||
@@ -20,7 +20,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
with BranchTemplate {
|
with BranchTemplate {
|
||||||
val context = column[String]("CONTEXT")
|
val context = column[String]("CONTEXT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, branch, context) <> (ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
(userName, repositoryName, branch, context).<>(ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -12,6 +12,7 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
|||||||
val requestBranch = column[String]("REQUEST_BRANCH")
|
val requestBranch = column[String]("REQUEST_BRANCH")
|
||||||
val commitIdFrom = column[String]("COMMIT_ID_FROM")
|
val commitIdFrom = column[String]("COMMIT_ID_FROM")
|
||||||
val commitIdTo = column[String]("COMMIT_ID_TO")
|
val commitIdTo = column[String]("COMMIT_ID_TO")
|
||||||
|
val isDraft = column[Boolean]("IS_DRAFT")
|
||||||
def * =
|
def * =
|
||||||
(
|
(
|
||||||
userName,
|
userName,
|
||||||
@@ -22,8 +23,9 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
|||||||
requestRepositoryName,
|
requestRepositoryName,
|
||||||
requestBranch,
|
requestBranch,
|
||||||
commitIdFrom,
|
commitIdFrom,
|
||||||
commitIdTo
|
commitIdTo,
|
||||||
) <> (PullRequest.tupled, PullRequest.unapply)
|
isDraft
|
||||||
|
).<>(PullRequest.tupled, PullRequest.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
||||||
byIssue(userName, repositoryName, issueId)
|
byIssue(userName, repositoryName, issueId)
|
||||||
@@ -41,5 +43,6 @@ case class PullRequest(
|
|||||||
requestRepositoryName: String,
|
requestRepositoryName: String,
|
||||||
requestBranch: String,
|
requestBranch: String,
|
||||||
commitIdFrom: String,
|
commitIdFrom: String,
|
||||||
commitIdTo: String
|
commitIdTo: String,
|
||||||
|
isDraft: Boolean
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -21,7 +21,8 @@ trait ReleaseAssetComponent extends TemplateComponent {
|
|||||||
val updatedDate = column[Date]("UPDATED_DATE")
|
val updatedDate = column[Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate) <> (ReleaseAsset.tupled, ReleaseAsset.unapply)
|
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate)
|
||||||
|
.<>(ReleaseAsset.tupled, ReleaseAsset.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
||||||
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
|
|||||||
@@ -17,7 +17,8 @@ trait ReleaseTagComponent extends TemplateComponent {
|
|||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate) <> (ReleaseTag.tupled, ReleaseTag.unapply)
|
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate)
|
||||||
|
.<>(ReleaseTag.tupled, ReleaseTag.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
byRepository(owner, repository) && (this.tag === tag.bind)
|
byRepository(owner, repository) && (this.tag === tag.bind)
|
||||||
|
|||||||
@@ -42,46 +42,48 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
parentRepositoryName.?
|
parentRepositoryName.?
|
||||||
),
|
),
|
||||||
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions, defaultMergeOption)
|
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions, defaultMergeOption)
|
||||||
).shaped <> ({
|
).shaped.<>(
|
||||||
case (repository, options) =>
|
{
|
||||||
Repository(
|
case (repository, options) =>
|
||||||
repository._1,
|
Repository(
|
||||||
repository._2,
|
repository._1,
|
||||||
repository._3,
|
repository._2,
|
||||||
repository._4,
|
repository._3,
|
||||||
repository._5,
|
repository._4,
|
||||||
repository._6,
|
repository._5,
|
||||||
repository._7,
|
repository._6,
|
||||||
repository._8,
|
repository._7,
|
||||||
repository._9,
|
repository._8,
|
||||||
repository._10,
|
repository._9,
|
||||||
repository._11,
|
repository._10,
|
||||||
repository._12,
|
repository._11,
|
||||||
RepositoryOptions.tupled.apply(options)
|
repository._12,
|
||||||
)
|
RepositoryOptions.tupled.apply(options)
|
||||||
}, { (r: Repository) =>
|
)
|
||||||
Some(
|
}, { (r: Repository) =>
|
||||||
(
|
Some(
|
||||||
(
|
(
|
||||||
r.userName,
|
(
|
||||||
r.repositoryName,
|
r.userName,
|
||||||
r.isPrivate,
|
r.repositoryName,
|
||||||
r.description,
|
r.isPrivate,
|
||||||
r.defaultBranch,
|
r.description,
|
||||||
r.registeredDate,
|
r.defaultBranch,
|
||||||
r.updatedDate,
|
r.registeredDate,
|
||||||
r.lastActivityDate,
|
r.updatedDate,
|
||||||
r.originUserName,
|
r.lastActivityDate,
|
||||||
r.originRepositoryName,
|
r.originUserName,
|
||||||
r.parentUserName,
|
r.originRepositoryName,
|
||||||
r.parentRepositoryName
|
r.parentUserName,
|
||||||
),
|
r.parentRepositoryName
|
||||||
(
|
),
|
||||||
RepositoryOptions.unapply(r.options).get
|
(
|
||||||
|
RepositoryOptions.unapply(r.options).get
|
||||||
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
}
|
||||||
})
|
)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,20 +9,26 @@ trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
||||||
|
|
||||||
class RepositoryWebHooks(tag: Tag) extends Table[RepositoryWebHook](tag, "WEB_HOOK") with BasicTemplate {
|
class RepositoryWebHooks(tag: Tag) extends Table[RepositoryWebHook](tag, "WEB_HOOK") with BasicTemplate {
|
||||||
|
val hookId = column[Int]("HOOK_ID", O AutoInc)
|
||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val token = column[Option[String]]("TOKEN")
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE")
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, url, ctype, token) <> ((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
(userName, repositoryName, hookId, url, ctype, token)
|
||||||
|
.<>((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, url: String) =
|
def byRepositoryUrl(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|
||||||
|
def byId(id: Int) =
|
||||||
|
(this.hookId === id.bind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
case class RepositoryWebHook(
|
case class RepositoryWebHook(
|
||||||
userName: String,
|
userName: String,
|
||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
|
hookId: Int = 0,
|
||||||
url: String,
|
url: String,
|
||||||
ctype: WebHookContentType,
|
ctype: WebHookContentType,
|
||||||
token: Option[String]
|
token: Option[String]
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ trait RepositoryWebHookEventComponent extends TemplateComponent { self: Profile
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, url, event) <> ((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
(userName, repositoryName, url, event).<>((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
||||||
|
|
||||||
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait SshKeyComponent { self: Profile =>
|
|||||||
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, sshKeyId, title, publicKey) <> (SshKey.tupled, SshKey.unapply)
|
def * = (userName, sshKeyId, title, publicKey).<>(SshKey.tupled, SshKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
||||||
|
|||||||
@@ -0,0 +1,12 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
|
||||||
|
trait BaseActivityInfo {
|
||||||
|
|
||||||
|
def toActivity: Activity
|
||||||
|
|
||||||
|
protected def trimInfoString(str: String, maxLen: Int): String =
|
||||||
|
if (str.length > maxLen) s"${str.substring(0, maxLen)}..."
|
||||||
|
else str
|
||||||
|
}
|
||||||
@@ -0,0 +1,74 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.model.Profile.currentDate
|
||||||
|
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||||
|
|
||||||
|
final case class PushInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
branchName: String,
|
||||||
|
commits: List[CommitInfo]
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"push",
|
||||||
|
s"[user:$activityUserName] pushed to [branch:$userName/$repositoryName#$branchName] at [repo:$userName/$repositoryName]",
|
||||||
|
Some(buildCommitSummary(commits)),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
|
||||||
|
private[this] def buildCommitSummary(commits: List[CommitInfo]): String =
|
||||||
|
commits
|
||||||
|
.take(5)
|
||||||
|
.map(commit => s"${commit.id}:${commit.shortMessage}")
|
||||||
|
.mkString("\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class CreateBranchInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
branchName: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"create_branch",
|
||||||
|
s"[user:$activityUserName] created branch [branch:$userName/$repositoryName#$branchName] at [repo:$userName/$repositoryName]",
|
||||||
|
None,
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class DeleteBranchInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
branchName: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"delete_branch",
|
||||||
|
s"[user:$activityUserName] deleted branch $branchName at [repo:$userName/$repositoryName]",
|
||||||
|
None,
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.model.Profile.currentDate
|
||||||
|
|
||||||
|
final case class IssueCommentInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
comment: String,
|
||||||
|
issueId: Int
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"comment_issue",
|
||||||
|
s"[user:${activityUserName}] commented on issue [issue:${userName}/${repositoryName}#${issueId}]",
|
||||||
|
Some(trimInfoString(comment, 200)),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class PullRequestCommentInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
comment: String,
|
||||||
|
issueId: Int
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"comment_issue",
|
||||||
|
s"[user:$activityUserName] commented on pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(trimInfoString(comment, 200)),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class CommitCommentInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
comment: String,
|
||||||
|
commitId: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"comment_commit",
|
||||||
|
s"[user:$activityUserName] commented on commit [commit:$userName/$repositoryName@$commitId]",
|
||||||
|
Some(trimInfoString(comment, 200)),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.model.Profile.currentDate
|
||||||
|
|
||||||
|
final case class ForkInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
forkedUserName: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"fork",
|
||||||
|
s"[user:$activityUserName] forked [repo:$userName/$repositoryName] to [repo:$forkedUserName/$repositoryName]",
|
||||||
|
None,
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,132 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.model.Profile.currentDate
|
||||||
|
|
||||||
|
final case class CreateIssueInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"open_issue",
|
||||||
|
s"[user:$activityUserName] opened issue [issue:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class CloseIssueInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"close_issue",
|
||||||
|
s"[user:$activityUserName] closed issue [issue:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class ReopenIssueInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"reopen_issue",
|
||||||
|
s"[user:$activityUserName] reopened issue [issue:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class OpenPullRequestInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"open_pullreq",
|
||||||
|
s"[user:${activityUserName}] opened pull request [pullreq:${userName}/${repositoryName}#${issueId}]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class ClosePullRequestInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"close_issue",
|
||||||
|
s"[user:$activityUserName] closed pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
final case class ReopenPullRequestInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
title: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"reopen_issue",
|
||||||
|
s"[user:$activityUserName] reopened pull request [issue:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(title),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package gitbucket.core.model.activity
|
||||||
|
|
||||||
|
import java.util.UUID
|
||||||
|
|
||||||
|
import gitbucket.core.model.Activity
|
||||||
|
import gitbucket.core.model.Profile.currentDate
|
||||||
|
|
||||||
|
final case class MergeInfo(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
issueId: Int,
|
||||||
|
message: String
|
||||||
|
) extends BaseActivityInfo {
|
||||||
|
|
||||||
|
override def toActivity: Activity =
|
||||||
|
Activity(
|
||||||
|
userName,
|
||||||
|
repositoryName,
|
||||||
|
activityUserName,
|
||||||
|
"merge_pullreq",
|
||||||
|
s"[user:$activityUserName] merged pull request [pullreq:$userName/$repositoryName#$issueId]",
|
||||||
|
Some(message),
|
||||||
|
currentDate,
|
||||||
|
UUID.randomUUID().toString
|
||||||
|
)
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user