mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-09 01:27:04 +02:00
Compare commits
399 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b37967162 | ||
|
|
a03b9584ee | ||
|
|
34649dfeda | ||
|
|
bc84cfc2c8 | ||
|
|
bcba1f068b | ||
|
|
e6f30ef86b | ||
|
|
9e67999ef0 | ||
|
|
be75cef752 | ||
|
|
19ead71b48 | ||
|
|
7ebe1d6c62 | ||
|
|
2331b58b87 | ||
|
|
d495b04d85 | ||
|
|
751a8703ef | ||
|
|
9019d93449 | ||
|
|
32006e02c0 | ||
|
|
5ba0f6d51e | ||
|
|
c004d501f6 | ||
|
|
6067fa0fca | ||
|
|
e2c6658e59 | ||
|
|
0a6e50cbbe | ||
|
|
3732963d4b | ||
|
|
20217058fe | ||
|
|
e67365a19f | ||
|
|
c2f1817c6a | ||
|
|
4a948d9b01 | ||
|
|
377bc2703b | ||
|
|
196890b26f | ||
|
|
491fc2c164 | ||
|
|
1bed38f175 | ||
|
|
b124c31f65 | ||
|
|
8c588cbd66 | ||
|
|
334753b1ad | ||
|
|
f6e7401d1b | ||
|
|
ab564cc2d4 | ||
|
|
b10839a5c2 | ||
|
|
bb3323fb0e | ||
|
|
0b15ecbacd | ||
|
|
9f6afaed07 | ||
|
|
925420734e | ||
|
|
fb6bb12c52 | ||
|
|
22d12d0488 | ||
|
|
6888d959e1 | ||
|
|
65e66f52f6 | ||
|
|
225abfa126 | ||
|
|
876757f2d4 | ||
|
|
7e77398645 | ||
|
|
73c76a5a88 | ||
|
|
e5fca0d6cc | ||
|
|
eed7e5177f | ||
|
|
dd54ab31cb | ||
|
|
0085cb24ad | ||
|
|
6a758902ef | ||
|
|
0d81a9a9b6 | ||
|
|
6e4f6da633 | ||
|
|
15118ca5c1 | ||
|
|
8161560757 | ||
|
|
9ba564c864 | ||
|
|
06b5b92673 | ||
|
|
a417c373f1 | ||
|
|
5f5cc8d454 | ||
|
|
b9b6589bd7 | ||
|
|
b79f6a5fa0 | ||
|
|
0acbaeae86 | ||
|
|
bd046da3d0 | ||
|
|
a889ed7c46 | ||
|
|
e24684cb2b | ||
|
|
5f939c18b4 | ||
|
|
140f1eb31b | ||
|
|
d412dd5009 | ||
|
|
8643bfeb37 | ||
|
|
31b6adf0e5 | ||
|
|
f1ac2b3507 | ||
|
|
172af307a6 | ||
|
|
135e1ef73d | ||
|
|
da55bf6af3 | ||
|
|
883a9c8b17 | ||
|
|
7da89940e3 | ||
|
|
3233b0ae3c | ||
|
|
4c2ed09915 | ||
|
|
256b6c480f | ||
|
|
dc311837f9 | ||
|
|
92aec48c99 | ||
|
|
a6ada8c457 | ||
|
|
dcc601502e | ||
|
|
dd58d8c804 | ||
|
|
2ade54b7e3 | ||
|
|
136c5854f3 | ||
|
|
c597238d9c | ||
|
|
2552a58e08 | ||
|
|
74ad5872a3 | ||
|
|
485d502bd3 | ||
|
|
47bc8d030e | ||
|
|
48fe7133f7 | ||
|
|
5d962dc5e4 | ||
|
|
31e8e5a951 | ||
|
|
858373c628 | ||
|
|
7f142d2c0d | ||
|
|
08b86232a8 | ||
|
|
6bf4f42fdb | ||
|
|
f3c7de36d8 | ||
|
|
19f556de57 | ||
|
|
e4467df411 | ||
|
|
8d305a1fb1 | ||
|
|
b47153e645 | ||
|
|
c71766c84b | ||
|
|
23e4d679ae | ||
|
|
182acb2e02 | ||
|
|
b255b15006 | ||
|
|
b458f88161 | ||
|
|
398d8f2f1c | ||
|
|
85c1a56cbf | ||
|
|
da216c6960 | ||
|
|
bc91b153bf | ||
|
|
bc50b47d3a | ||
|
|
aed15a7f25 | ||
|
|
a1f09117b0 | ||
|
|
0a4a4a51ca | ||
|
|
f7fd53bf09 | ||
|
|
cbfb863a54 | ||
|
|
9d56d72611 | ||
|
|
527c91ff9d | ||
|
|
c58c2d6700 | ||
|
|
5518eca952 | ||
|
|
6e2b67ec0b | ||
|
|
837b1e44a7 | ||
|
|
e04c230c6e | ||
|
|
a01b5a4a59 | ||
|
|
427b6ce846 | ||
|
|
b7b5af2b72 | ||
|
|
39fec57f72 | ||
|
|
238dedb6df | ||
|
|
af091117b7 | ||
|
|
ddea4e12f0 | ||
|
|
9767903252 | ||
|
|
bc75f9f8a2 | ||
|
|
63627fc1d0 | ||
|
|
c23985c1a7 | ||
|
|
af58e99dcf | ||
|
|
676670e9e3 | ||
|
|
823c52e941 | ||
|
|
7f42007648 | ||
|
|
7214ef21d2 | ||
|
|
18a4492975 | ||
|
|
99f73b1016 | ||
|
|
0c1ce6a088 | ||
|
|
ae6291ab83 | ||
|
|
617fcf7c99 | ||
|
|
9df4a74837 | ||
|
|
966d4251be | ||
|
|
84b2e9cdcd | ||
|
|
e29d63c91a | ||
|
|
805d2b8e79 | ||
|
|
9983fd1292 | ||
|
|
1de202e927 | ||
|
|
4eb9f4a485 | ||
|
|
a8801e4e41 | ||
|
|
ee1c84dbf2 | ||
|
|
e40e1fa6cd | ||
|
|
055f648ea2 | ||
|
|
37a399c3a2 | ||
|
|
bc0b11b60a | ||
|
|
65a1ca7146 | ||
|
|
2293030d4e | ||
|
|
2848f07b83 | ||
|
|
55224ddcd8 | ||
|
|
054ae75b6b | ||
|
|
c83fab611e | ||
|
|
29baf1223c | ||
|
|
2a60f607ff | ||
|
|
78f4d26aa0 | ||
|
|
f59e86f5ca | ||
|
|
1c2af36c92 | ||
|
|
badbe73f4e | ||
|
|
a9d58698cd | ||
|
|
bb3f086aa6 | ||
|
|
2db674bb03 | ||
|
|
4bc4a16a80 | ||
|
|
d88a105628 | ||
|
|
15d0c5b506 | ||
|
|
dbde79d2f2 | ||
|
|
e6e3786b47 | ||
|
|
4c1b8004fc | ||
|
|
ff4052f097 | ||
|
|
13c206d068 | ||
|
|
5b875d7c73 | ||
|
|
e33dd9008b | ||
|
|
8764910553 | ||
|
|
4c89c40944 | ||
|
|
0f0986afcf | ||
|
|
5d5f1f8bdd | ||
|
|
03e386b3ce | ||
|
|
435eac7ae6 | ||
|
|
bd5df3977d | ||
|
|
ba218053f9 | ||
|
|
1fe448a83b | ||
|
|
26a45d0117 | ||
|
|
320585a530 | ||
|
|
ca0f888a99 | ||
|
|
3b08dc2e41 | ||
|
|
cc128a49c1 | ||
|
|
e0148695f2 | ||
|
|
afe0b1dd71 | ||
|
|
353852d6da | ||
|
|
28585d1a3d | ||
|
|
9d69a48c65 | ||
|
|
2f95c76634 | ||
|
|
eac9f0e6ff | ||
|
|
043fc21e05 | ||
|
|
5854a75615 | ||
|
|
7b02946496 | ||
|
|
70f0ffd4f4 | ||
|
|
91b82c2652 | ||
|
|
b1017140aa | ||
|
|
fc806b8813 | ||
|
|
836913482b | ||
|
|
b3df3f44c6 | ||
|
|
4ffbf89e74 | ||
|
|
9851c7d93d | ||
|
|
a10188260c | ||
|
|
2201f2b202 | ||
|
|
c92e71bb7a | ||
|
|
d271fac350 | ||
|
|
ce4522fc30 | ||
|
|
a178c48de6 | ||
|
|
9d1323a044 | ||
|
|
43babfed94 | ||
|
|
6fa7ea30fb | ||
|
|
d78315695b | ||
|
|
16021865cb | ||
|
|
b516be242d | ||
|
|
0124f7cc3c | ||
|
|
f3eec35287 | ||
|
|
fb396a33b0 | ||
|
|
3370499421 | ||
|
|
d847e27cf9 | ||
|
|
9684b158ce | ||
|
|
8456808a8e | ||
|
|
9747899a19 | ||
|
|
099304605e | ||
|
|
30994d0465 | ||
|
|
71fdbe7b71 | ||
|
|
86432c5ffe | ||
|
|
4dfa1fb0f8 | ||
|
|
db59a7652f | ||
|
|
417470a81c | ||
|
|
cc639da17e | ||
|
|
f619f4a9bc | ||
|
|
5dffc2a64e | ||
|
|
bb63a8d14c | ||
|
|
c1263cc16d | ||
|
|
49f2e7d70f | ||
|
|
f93b535f70 | ||
|
|
e16d3c823b | ||
|
|
7a6fdbcf50 | ||
|
|
46041a3762 | ||
|
|
20b0553f7f | ||
|
|
5870cacf44 | ||
|
|
cb512cd98d | ||
|
|
90487eb7b7 | ||
|
|
706fa77de3 | ||
|
|
26b14ded58 | ||
|
|
3b1367dd8e | ||
|
|
e1f310317d | ||
|
|
937814ec5d | ||
|
|
b55fc649a6 | ||
|
|
f4e4506517 | ||
|
|
287a0b6669 | ||
|
|
5bddd352af | ||
|
|
9c6ea8fb9d | ||
|
|
32e8bf46a7 | ||
|
|
d61fe1bf84 | ||
|
|
47dbea947d | ||
|
|
97c6b0495e | ||
|
|
a602ece8e9 | ||
|
|
cf6dca84d8 | ||
|
|
79432ff8ad | ||
|
|
b8613431de | ||
|
|
698eafa562 | ||
|
|
d33886db89 | ||
|
|
cde09d3a59 | ||
|
|
5674f0e980 | ||
|
|
b9ade60eb2 | ||
|
|
96303723fa | ||
|
|
0f5dbc5788 | ||
|
|
8df0c3a439 | ||
|
|
ca6a86816a | ||
|
|
3ea939798f | ||
|
|
d947410e3c | ||
|
|
db59bc08ac | ||
|
|
95a8649f79 | ||
|
|
ffd10122ed | ||
|
|
c4c39f36e9 | ||
|
|
96900c3cbf | ||
|
|
69fa370d12 | ||
|
|
7496437d11 | ||
|
|
33b7d09af7 | ||
|
|
53d0974760 | ||
|
|
a87399f223 | ||
|
|
975dfb17e1 | ||
|
|
8b8bd0289b | ||
|
|
3bb69c623b | ||
|
|
dd427bdbef | ||
|
|
b40657a14a | ||
|
|
21ca5b2eec | ||
|
|
b78d584d8a | ||
|
|
e6b666a66a | ||
|
|
bab93ea4f5 | ||
|
|
7fe98253ae | ||
|
|
13385cbced | ||
|
|
3f20cec7b2 | ||
|
|
a0e4b020ca | ||
|
|
ea5d898b27 | ||
|
|
4e652b5ccd | ||
|
|
dd809896c8 | ||
|
|
93536d3365 | ||
|
|
098b18fe6d | ||
|
|
66efdac757 | ||
|
|
45545d3815 | ||
|
|
b65d41731b | ||
|
|
be19e97518 | ||
|
|
2ebf2b99bd | ||
|
|
be79ac2eb2 | ||
|
|
05afec3236 | ||
|
|
57879eb72e | ||
|
|
2bc915f51b | ||
|
|
1ca55805b5 | ||
|
|
93cc1be166 | ||
|
|
f88ce3f671 | ||
|
|
20aabfc273 | ||
|
|
601f8c4249 | ||
|
|
d0ccfc52b8 | ||
|
|
c22aef8ee2 | ||
|
|
3807e61a48 | ||
|
|
55722f87af | ||
|
|
212f3725ed | ||
|
|
193a312b22 | ||
|
|
6a2d2ebfd1 | ||
|
|
82beed1f44 | ||
|
|
0ede7e9921 | ||
|
|
6d200aa340 | ||
|
|
a0fbb90048 | ||
|
|
08e29e7077 | ||
|
|
d2317d0a97 | ||
|
|
972628eb65 | ||
|
|
51a56356cb | ||
|
|
3bef71f5f2 | ||
|
|
2bb1f6168a | ||
|
|
b13820fc0e | ||
|
|
723de9e81e | ||
|
|
3e161353ed | ||
|
|
2a8706630a | ||
|
|
121b6ee641 | ||
|
|
34e299bf52 | ||
|
|
0822b7b5f3 | ||
|
|
618110327a | ||
|
|
f58f476060 | ||
|
|
f5a544603a | ||
|
|
89515cd087 | ||
|
|
37731c4163 | ||
|
|
1d4720d784 | ||
|
|
a10b053489 | ||
|
|
6122c8a1e1 | ||
|
|
fa9254c240 | ||
|
|
10616bca7d | ||
|
|
307f7e15e9 | ||
|
|
86cf97d76b | ||
|
|
01f6590c04 | ||
|
|
8f0c22bae9 | ||
|
|
652a68c5b1 | ||
|
|
1f56e1360d | ||
|
|
38475ffefe | ||
|
|
7a44a4d726 | ||
|
|
9dbc0c3fd6 | ||
|
|
56bb43ea6b | ||
|
|
b287c1f60d | ||
|
|
258d53b7a6 | ||
|
|
2e11d6dd78 | ||
|
|
a2a2e22485 | ||
|
|
c182cde14b | ||
|
|
3683a5fb7d | ||
|
|
1223bf2fd8 | ||
|
|
e2c99a46be | ||
|
|
6175eb7c08 | ||
|
|
ebb9d9329a | ||
|
|
8c35310cd6 | ||
|
|
843722f82e | ||
|
|
ce79eaada8 | ||
|
|
00af52815d | ||
|
|
9175cf5c71 | ||
|
|
a74bbd3eeb | ||
|
|
4e2a3fdbd0 | ||
|
|
8d200c72d3 | ||
|
|
18cd967a9c | ||
|
|
328d6c1d17 | ||
|
|
a335c31385 | ||
|
|
97349a9bb2 | ||
|
|
ce3b6ed7c2 | ||
|
|
5e0619b500 | ||
|
|
639e7e0b3f |
3
.travis.yml
Normal file
3
.travis.yml
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
language: scala
|
||||||
|
scala:
|
||||||
|
- 2.11.2
|
||||||
63
README.md
63
README.md
@@ -1,7 +1,7 @@
|
|||||||
GitBucket [](https://gitter.im/takezoe/gitbucket) [](https://buildhive.cloudbees.com/job/takezoe/job/gitbucket/)
|
GitBucket [](https://gitter.im/takezoe/gitbucket) [](https://travis-ci.org/takezoe/gitbucket)
|
||||||
=========
|
=========
|
||||||
|
|
||||||
GitBucket is the easily installable Github clone written with Scala.
|
GitBucket is the easily installable GitHub clone powered by Scala.
|
||||||
|
|
||||||
|
|
||||||
Features
|
Features
|
||||||
@@ -23,7 +23,6 @@ The current version of GitBucket provides a basic features below:
|
|||||||
|
|
||||||
Following features are not implemented, but we will make them in the future release!
|
Following features are not implemented, but we will make them in the future release!
|
||||||
|
|
||||||
- Comment for the changeset
|
|
||||||
- Network graph
|
- Network graph
|
||||||
- Statistics
|
- Statistics
|
||||||
- Watch / Star
|
- Watch / Star
|
||||||
@@ -80,6 +79,64 @@ Run the following commands in `Terminal` to
|
|||||||
|
|
||||||
Release Notes
|
Release Notes
|
||||||
--------
|
--------
|
||||||
|
### 3.0 - 3 Mar 2015
|
||||||
|
- New plug-in system is available
|
||||||
|
- Connection pooling by c3p0
|
||||||
|
- New branch UI
|
||||||
|
- Compare between specified commit ids
|
||||||
|
|
||||||
|
### 2.8 - 1 Feb 2015
|
||||||
|
- New logo and icons
|
||||||
|
- New system setting options to control visibility
|
||||||
|
- Comment on side-by-side diff
|
||||||
|
- Information message on sign-in page
|
||||||
|
- Fork repository by group account
|
||||||
|
|
||||||
|
### 2.7 - 29 Dec 2014
|
||||||
|
- Comment for commit and diff
|
||||||
|
- Fix security issue in markdown rendering
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
|
### 2.6 - 24 Nov 2014
|
||||||
|
- Search box at issues and pull requests
|
||||||
|
- Information from administrator
|
||||||
|
- Pull request UI has been updated
|
||||||
|
- Move to TravisCI from Buildhive
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
|
### 2.5 - 4 Nov 2014
|
||||||
|
- New Dashboard
|
||||||
|
- Change datetime format
|
||||||
|
- Create branch from Web UI
|
||||||
|
- Task list in Markdown
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
|
### 2.4.1 - 6 Oct 2014
|
||||||
|
- Bug fix
|
||||||
|
|
||||||
|
### 2.4 - 6 Oct 2014
|
||||||
|
- New UI is applied to Issues and Pull requests
|
||||||
|
- Side-by-side diff is available
|
||||||
|
- Fix relative path problem in Markdown links and images
|
||||||
|
- Plugin System is disabled in default
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
|
### 2.3 - 1 Sep 2014
|
||||||
|
- Scala based plugin system
|
||||||
|
- Embedded Jetty war extraction directory moved to `GITBUCKET_HOME/tmp`
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
|
### 2.2.1 - 5 Aug 2014
|
||||||
|
- Bug fix
|
||||||
|
|
||||||
|
### 2.2 - 4 Aug 2014
|
||||||
|
- Plug-in system is available
|
||||||
|
- Move to Scala 2.11, Scalatra 2.3 and Slick 2.1
|
||||||
|
- tar.gz export for repository contents
|
||||||
|
- LDAP authentication improvement (mail address became optional)
|
||||||
|
- Show news feed of a private repository to members
|
||||||
|
- Some bug fix and improvements
|
||||||
|
|
||||||
### 2.1 - 6 Jul 2014
|
### 2.1 - 6 Jul 2014
|
||||||
- Upgrade to Slick 2.0 from 1.9
|
- Upgrade to Slick 2.0 from 1.9
|
||||||
- Base part of the plug-in system is merged
|
- Base part of the plug-in system is merged
|
||||||
|
|||||||
@@ -4,8 +4,8 @@
|
|||||||
<property name="target.dir" value="target"/>
|
<property name="target.dir" value="target"/>
|
||||||
<property name="embed.classes.dir" value="${target.dir}/embed-classes"/>
|
<property name="embed.classes.dir" value="${target.dir}/embed-classes"/>
|
||||||
<property name="jetty.dir" value="embed-jetty"/>
|
<property name="jetty.dir" value="embed-jetty"/>
|
||||||
<property name="scala.version" value="2.10"/>
|
<property name="scala.version" value="2.11"/>
|
||||||
<property name="gitbucket.version" value="0.0.1"/>
|
<property name="gitbucket.version" value="3.0.0"/>
|
||||||
<property name="jetty.version" value="8.1.8.v20121106"/>
|
<property name="jetty.version" value="8.1.8.v20121106"/>
|
||||||
<property name="servlet.version" value="3.0.0.v201112011016"/>
|
<property name="servlet.version" value="3.0.0.v201112011016"/>
|
||||||
|
|
||||||
|
|||||||
13
contrib/README.md
Normal file
13
contrib/README.md
Normal file
@@ -0,0 +1,13 @@
|
|||||||
|
# Contrib Notes #
|
||||||
|
|
||||||
|
The configuration script adapts according to the OS.
|
||||||
|
The `linux` directory contains scripts for Ubuntu and RedHat.
|
||||||
|
The Mac scripts have been folded in as well.
|
||||||
|
Common scripts are in this directory.
|
||||||
|
|
||||||
|
This version of scripts has so far only been tested on Ubuntu and Mac. Someone else will have to test on RedHat.
|
||||||
|
|
||||||
|
To run:
|
||||||
|
|
||||||
|
1. Edit `gitbucket.conf` to suit.
|
||||||
|
2. Type: `install`
|
||||||
62
contrib/gitbucket.conf
Normal file
62
contrib/gitbucket.conf
Normal file
@@ -0,0 +1,62 @@
|
|||||||
|
# Configuration section is below. Ignore this part
|
||||||
|
|
||||||
|
function isUbuntu {
|
||||||
|
if [ -f /etc/lsb-release ]; then
|
||||||
|
grep -i ubuntu /etc/lsb-release | head -n 1 | cut -d \ -f 1 | cut -d = -f 2
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function isRedHat {
|
||||||
|
if [ -d "/etc/rc.d/init.d" ]; then echo yes; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function isMac {
|
||||||
|
if [[ "$(uname -a | cut -d \ -f 1 )" == "Darwin" ]]; then echo yes; fi
|
||||||
|
}
|
||||||
|
|
||||||
|
#
|
||||||
|
# Configuration section start
|
||||||
|
#
|
||||||
|
|
||||||
|
# Bind host
|
||||||
|
GITBUCKET_HOST=0.0.0.0
|
||||||
|
|
||||||
|
# Other Java option
|
||||||
|
GITBUCKET_JVM_OPTS=-Dmail.smtp.starttls.enable=true
|
||||||
|
|
||||||
|
# Data directory, holds repositories
|
||||||
|
GITBUCKET_HOME=/var/lib/gitbucket
|
||||||
|
|
||||||
|
GITBUCKET_LOG_DIR=/var/log/gitbucket
|
||||||
|
|
||||||
|
# Server port
|
||||||
|
GITBUCKET_PORT=8080
|
||||||
|
|
||||||
|
# URL prefix for the GitBucket page (http://<host>:<port>/<prefix>/)
|
||||||
|
GITBUCKET_PREFIX=
|
||||||
|
|
||||||
|
# Directory where GitBucket is installed
|
||||||
|
# Configuration is stored here:
|
||||||
|
GITBUCKET_DIR=/usr/share/gitbucket
|
||||||
|
GITBUCKET_WAR_DIR=$GITBUCKET_DIR/lib
|
||||||
|
|
||||||
|
# Path to the WAR file
|
||||||
|
GITBUCKET_WAR_FILE=$GITBUCKET_WAR_DIR/gitbucket.war
|
||||||
|
|
||||||
|
# GitBucket version to fetch when installing
|
||||||
|
GITBUCKET_VERSION=2.1
|
||||||
|
|
||||||
|
#
|
||||||
|
# End of configuration section. Ignore this part
|
||||||
|
#
|
||||||
|
if [ `isUbuntu` ]; then
|
||||||
|
GITBUCKET_SERVICE=/etc/init.d/gitbucket
|
||||||
|
elif [ `isRedHat` ]; then
|
||||||
|
GITBUCKET_SERVICE=/etc/rc.d/init.d
|
||||||
|
elif [ `isMac` ]; then
|
||||||
|
GITBUCKET_SERVICE=/Library/StartupItems/GitBucket/GitBucket
|
||||||
|
else
|
||||||
|
echo "Don't know how to install onto this OS"
|
||||||
|
exit -2
|
||||||
|
fi
|
||||||
|
|
||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
#
|
#
|
||||||
# /etc/rc.d/init.d/gitbucket
|
# RedHat: /etc/rc.d/init.d/gitbucket
|
||||||
|
# Ubuntu: /etc/init.d/gitbucket
|
||||||
|
# Mac OS/X: /Library/StartupItems/GitBucket
|
||||||
#
|
#
|
||||||
# Starts the GitBucket server
|
# Starts the GitBucket server
|
||||||
#
|
#
|
||||||
@@ -8,28 +10,44 @@
|
|||||||
# description: Run GitBucket server
|
# description: Run GitBucket server
|
||||||
# processname: java
|
# processname: java
|
||||||
|
|
||||||
# Source function library
|
set -e
|
||||||
. /etc/rc.d/init.d/functions
|
|
||||||
|
[ -f /etc/rc.d/init.d/functions ] && source /etc/rc.d/init.d/functions # RedHat
|
||||||
|
[ -f /etc/rc.common ] && source /etc/rc.common # Mac OS/X
|
||||||
|
|
||||||
# Default values
|
# Default values
|
||||||
GITBUCKET_HOME=/var/lib/gitbucket
|
GITBUCKET_HOME=/var/lib/gitbucket
|
||||||
GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war
|
GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war
|
||||||
|
|
||||||
# Pull in cq settings
|
# Pull in cq settings
|
||||||
[ -f /etc/sysconfig/gitbucket ] && . /etc/sysconfig/gitbucket
|
[ -f /etc/sysconfig/gitbucket ] && source /etc/sysconfig/gitbucket # RedHat
|
||||||
|
[ -f gitbucket.conf ] && source gitbucket.conf # For all systems
|
||||||
|
|
||||||
# Location of the log and PID file
|
# Location of the log and PID file
|
||||||
LOG_FILE=/var/log/gitbucket/run.log
|
LOG_FILE=$GITBUCKET_LOG_DIR/run.log
|
||||||
PID_FILE=/var/run/gitbucket.pid
|
PID_FILE=/var/run/gitbucket.pid
|
||||||
|
|
||||||
# Default return value
|
RED='\033[1m\E[37;41m'
|
||||||
RETVAL=0
|
GREEN='\033[1m\E[37;42m'
|
||||||
|
OFF='\E[0m'
|
||||||
|
|
||||||
|
if [ -z "$(which success)" ]; then
|
||||||
|
function success {
|
||||||
|
printf "%b\n" "$GREEN $* $OFF"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
if [ -z "$(which failure)" ]; then
|
||||||
|
function failure {
|
||||||
|
printf "%b\n" "$RED $* $OFF"
|
||||||
|
}
|
||||||
|
fi
|
||||||
|
|
||||||
|
RETVAL=0
|
||||||
|
|
||||||
start() {
|
start() {
|
||||||
echo -n $"Starting GitBucket server: "
|
echo -n $"Starting GitBucket server: "
|
||||||
|
|
||||||
# Compile statup parameters
|
START_OPTS=
|
||||||
if [ $GITBUCKET_PORT ]; then
|
if [ $GITBUCKET_PORT ]; then
|
||||||
START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}"
|
START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}"
|
||||||
fi
|
fi
|
||||||
@@ -40,17 +58,15 @@ start() {
|
|||||||
START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}"
|
START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run the Java process
|
|
||||||
GITBUCKET_HOME="${GITBUCKET_HOME}" java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 &
|
GITBUCKET_HOME="${GITBUCKET_HOME}" java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 &
|
||||||
RETVAL=$?
|
RETVAL=$?
|
||||||
|
|
||||||
# Store PID of the Java process into a file
|
|
||||||
echo $! > $PID_FILE
|
echo $! > $PID_FILE
|
||||||
|
|
||||||
if [ $RETVAL -eq 0 ] ; then
|
if [ $RETVAL -eq 0 ] ; then
|
||||||
success "GitBucket startup"
|
success "Success"
|
||||||
else
|
else
|
||||||
failure "GitBucket startup"
|
failure "Exit code $RETVAL"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
@@ -82,25 +98,41 @@ restart() {
|
|||||||
start
|
start
|
||||||
}
|
}
|
||||||
|
|
||||||
|
## MacOS proxies for System V service hooks:
|
||||||
case "$1" in
|
StartService() {
|
||||||
start)
|
|
||||||
start
|
start
|
||||||
;;
|
}
|
||||||
stop)
|
|
||||||
|
StopService() {
|
||||||
stop
|
stop
|
||||||
;;
|
}
|
||||||
restart)
|
|
||||||
|
RestartService() {
|
||||||
restart
|
restart
|
||||||
;;
|
}
|
||||||
status)
|
|
||||||
status -p $PID_FILE java
|
|
||||||
RETVAL=$?
|
|
||||||
;;
|
|
||||||
*)
|
|
||||||
echo $"Usage: $0 [start|stop|restart|status]"
|
|
||||||
RETVAL=2
|
|
||||||
esac
|
|
||||||
|
|
||||||
|
|
||||||
exit $RETVAL
|
if [ `isMac` ]; then
|
||||||
|
RunService "$1"
|
||||||
|
else
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
restart
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
status -p $PID_FILE java
|
||||||
|
RETVAL=$?
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo $"Usage: $0 [start|stop|restart|status]"
|
||||||
|
RETVAL=2
|
||||||
|
esac
|
||||||
|
exit $RETVAL
|
||||||
|
fi
|
||||||
|
|
||||||
69
contrib/install
Executable file
69
contrib/install
Executable file
@@ -0,0 +1,69 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# Only tested on Ubuntu 14.04
|
||||||
|
|
||||||
|
# Uses information stored in GitBucket git repo on GitHub as defaults.
|
||||||
|
# Edit gitbucket.conf before running this
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
GITBUCKET_VERSION=2.1
|
||||||
|
|
||||||
|
if [ ! -f gitbucket.conf ]; then
|
||||||
|
echo "gitbucket.conf not found, aborting"
|
||||||
|
exit -3
|
||||||
|
fi
|
||||||
|
source gitbucket.conf
|
||||||
|
|
||||||
|
function createDir {
|
||||||
|
if [ ! -d "$1" ]; then
|
||||||
|
echo "Making $1 directory."
|
||||||
|
sudo mkdir -p "$1"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if [ "$(which iptables)" ]; then
|
||||||
|
echo "Opening port $GITBUCKET_PORT in firewall."
|
||||||
|
sudo iptables -A INPUT -p tcp --dport $GITBUCKET_PORT -j ACCEPT
|
||||||
|
echo "Please use iptables-persistent:"
|
||||||
|
echo " sudo apt-get install iptables-persistent"
|
||||||
|
echo "After installed, you can save/reload iptables rules anytime:"
|
||||||
|
echo " sudo /etc/init.d/iptables-persistent save"
|
||||||
|
echo " sudo /etc/init.d/iptables-persistent reload"
|
||||||
|
fi
|
||||||
|
|
||||||
|
createDir "$GITBUCKET_HOME"
|
||||||
|
createDir "$GITBUCKET_WAR_DIR"
|
||||||
|
createDir "$GITBUCKET_DIR"
|
||||||
|
createDir "$GITBUCKET_LOG_DIR"
|
||||||
|
|
||||||
|
echo "Fetching GitBucket v$GITBUCKET_VERSION and saving as $GITBUCKET_WAR_FILE"
|
||||||
|
sudo wget -qO "$GITBUCKET_WAR_FILE" https://github.com/takezoe/gitbucket/releases/download/$GITBUCKET_VERSION/gitbucket.war
|
||||||
|
|
||||||
|
sudo rm -f "$GITBUCKET_LOG_DIR/run.log"
|
||||||
|
|
||||||
|
echo "Copying gitbucket.conf to $GITBUCKET_DIR"
|
||||||
|
sudo cp gitbucket.conf $GITBUCKET_DIR
|
||||||
|
if [ `isUbuntu` ] || [ `isRedHat` ]; then
|
||||||
|
sudo cp gitbucket.init "$GITBUCKET_SERVICE"
|
||||||
|
# Install gitbucket as a service that starts when system boots
|
||||||
|
sudo chown root:root $GITBUCKET_SERVICE
|
||||||
|
sudo chmod 755 $GITBUCKET_SERVICE
|
||||||
|
sudo update-rc.d "$(basename $GITBUCKET_SERVICE)" defaults 98 02
|
||||||
|
echo "Starting GitBucket service"
|
||||||
|
sudo $GITBUCKET_SERVICE start
|
||||||
|
elif [ `isMac` ]; then
|
||||||
|
sudo macosx/makePlist
|
||||||
|
echo "Starting GitBucket service"
|
||||||
|
sudo cp gitbucket.conf "$GITBUCKET_SERVICE"
|
||||||
|
sudo cp gitbucket.init "$GITBUCKET_SERVICE"
|
||||||
|
sudo chmod a+x "$GITBUCKET_SERVICE"
|
||||||
|
sudo "$GITBUCKET_SERVICE" start
|
||||||
|
else
|
||||||
|
echo "Don't know how to install this OS"
|
||||||
|
exit -2
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ $? != 0 ]; then
|
||||||
|
less "$GITBUCKET_LOG_DIR/run.log"
|
||||||
|
fi
|
||||||
15
contrib/linux/redhat/README.md
Normal file
15
contrib/linux/redhat/README.md
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
# Contrib Notes #
|
||||||
|
|
||||||
|
RPM spec file and init script for Red Hat Enterprise Linux 6.x.
|
||||||
|
|
||||||
|
To create RPM:
|
||||||
|
1. Edit `../../gitbucket.conf` to suit.
|
||||||
|
2. Edit `gitbucket.init` to suit.
|
||||||
|
3. Edit `gitbucket.spec` to suit.
|
||||||
|
4. Place `gitbucket.spec` to rpm/SPECS/.
|
||||||
|
5. Place `gitbucket.init` and `gitbucket.war` to rpm/SOURCES/.
|
||||||
|
6. Execute `rpmbuild -ba rpm/SPECS/gitbucket.spec`
|
||||||
|
|
||||||
|
This rpm runs gitbucket not as root user but as gitbucket user.
|
||||||
|
This rpm creates user and group named `gitbucket` at installation.
|
||||||
|
This rpm make chkconfig of gitbucket to be on.
|
||||||
108
contrib/linux/redhat/gitbucket.init
Normal file
108
contrib/linux/redhat/gitbucket.init
Normal file
@@ -0,0 +1,108 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
#
|
||||||
|
# RedHat: /etc/rc.d/init.d/gitbucket
|
||||||
|
#
|
||||||
|
# Starts the GitBucket server
|
||||||
|
#
|
||||||
|
# chkconfig: 345 60 40
|
||||||
|
# description: Run GitBucket server
|
||||||
|
# processname: java
|
||||||
|
|
||||||
|
[ -f /etc/rc.d/init.d/functions ] && source /etc/rc.d/init.d/functions # RedHat
|
||||||
|
|
||||||
|
# Default values
|
||||||
|
GITBUCKET_HOME=/var/lib/gitbucket
|
||||||
|
GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war
|
||||||
|
|
||||||
|
# Pull in cq settings
|
||||||
|
[ -f /etc/sysconfig/gitbucket ] && source /etc/sysconfig/gitbucket # RedHat
|
||||||
|
[ -f gitbucket.conf ] && source gitbucket.conf # For all systems
|
||||||
|
|
||||||
|
# Location of the log and PID file
|
||||||
|
LOG_FILE=$GITBUCKET_LOG_DIR/run.log
|
||||||
|
|
||||||
|
RED='\033[1m\E[37;41m'
|
||||||
|
GREEN='\033[1m\E[37;42m'
|
||||||
|
OFF='\E[0m'
|
||||||
|
|
||||||
|
RETVAL=0
|
||||||
|
|
||||||
|
start() {
|
||||||
|
echo -n $"Starting GitBucket server: "
|
||||||
|
|
||||||
|
START_OPTS=
|
||||||
|
if [ $GITBUCKET_PORT ]; then
|
||||||
|
START_OPTS="${START_OPTS} --port=${GITBUCKET_PORT}"
|
||||||
|
fi
|
||||||
|
if [ $GITBUCKET_PREFIX ]; then
|
||||||
|
START_OPTS="${START_OPTS} --prefix=${GITBUCKET_PREFIX}"
|
||||||
|
fi
|
||||||
|
if [ $GITBUCKET_HOST ]; then
|
||||||
|
START_OPTS="${START_OPTS} --host=${GITBUCKET_HOST}"
|
||||||
|
fi
|
||||||
|
|
||||||
|
GITBUCKET_HOME="${GITBUCKET_HOME}" daemon --user=gitbucket java $GITBUCKET_JVM_OPTS -jar $GITBUCKET_WAR_FILE $START_OPTS >>$LOG_FILE 2>&1 &
|
||||||
|
sleep 3
|
||||||
|
pgrep -f $GITBUCKET_WAR_FILE >> $LOG_FILE 2>&1
|
||||||
|
RETVAL=$?
|
||||||
|
|
||||||
|
if [ $RETVAL -eq 0 ] ; then
|
||||||
|
success "Success"
|
||||||
|
else
|
||||||
|
failure "Exit code $RETVAL"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
return $RETVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
stop() {
|
||||||
|
echo -n $"Stopping GitBucket server: "
|
||||||
|
|
||||||
|
# Run the Java process
|
||||||
|
pkill -f $GITBUCKET_WAR_FILE >>$LOG_FILE 2>&1
|
||||||
|
RETVAL=$?
|
||||||
|
|
||||||
|
if [ $RETVAL -eq 0 ] ; then
|
||||||
|
success "GitBucket stopping"
|
||||||
|
else
|
||||||
|
failure "GitBucket stopping"
|
||||||
|
fi
|
||||||
|
|
||||||
|
echo
|
||||||
|
return $RETVAL
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
restart() {
|
||||||
|
stop
|
||||||
|
start
|
||||||
|
}
|
||||||
|
|
||||||
|
case "$1" in
|
||||||
|
start)
|
||||||
|
start
|
||||||
|
;;
|
||||||
|
stop)
|
||||||
|
stop
|
||||||
|
;;
|
||||||
|
restart)
|
||||||
|
restart
|
||||||
|
;;
|
||||||
|
status)
|
||||||
|
pgrep -f $GITBUCKET_WAR_FILE >> $LOG_FILE 2>&1
|
||||||
|
RETVAL=$?
|
||||||
|
if [ $RETVAL -eq 0 ]; then
|
||||||
|
echo $"GitBucket is running...."
|
||||||
|
else
|
||||||
|
echo $"GitBucket is stopped"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
*)
|
||||||
|
echo $"Usage: $0 [start|stop|restart|status]"
|
||||||
|
RETVAL=2
|
||||||
|
esac
|
||||||
|
|
||||||
|
exit $RETVAL
|
||||||
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
Name: gitbucket
|
Name: gitbucket
|
||||||
Summary: GitHub clone written with Scala.
|
Summary: GitHub clone written with Scala.
|
||||||
Version: 1.7
|
Version: 2.6
|
||||||
Release: 1%{?dist}
|
Release: 1%{?dist}
|
||||||
License: Apache
|
License: Apache
|
||||||
URL: https://github.com/takezoe/gitbucket
|
URL: https://github.com/takezoe/gitbucket
|
||||||
@@ -26,6 +26,25 @@ GitBucket is the easily installable GitHub clone written with Scala.
|
|||||||
%{__install} -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
|
%{__install} -m 0644 %{SOURCE2} %{buildroot}%{_sysconfdir}/sysconfig/%{name}
|
||||||
touch %{buildroot}%{_localstatedir}/log/%{name}/run.log
|
touch %{buildroot}%{_localstatedir}/log/%{name}/run.log
|
||||||
|
|
||||||
|
%pre
|
||||||
|
/usr/sbin/groupadd -r gitbucket &> /dev/null || :
|
||||||
|
/usr/sbin/useradd -g gitbucket -s /bin/false -r -c "GitBucket GitHub clone" -d %{_sharedstatedir}/%{name} gitbucket &> /dev/null || :
|
||||||
|
|
||||||
|
%post
|
||||||
|
/sbin/chkconfig --add gitbucket
|
||||||
|
|
||||||
|
%preun
|
||||||
|
if [ "$1" = 0 ]; then
|
||||||
|
/sbin/service gitbucket stop > /dev/null 2>&1
|
||||||
|
/sbin/chkconfig --del gitbucket
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
|
||||||
|
%postun
|
||||||
|
if [ "$1" -ge 1 ]; then
|
||||||
|
/sbin/service gitbucket restart > /dev/null 2>&1
|
||||||
|
fi
|
||||||
|
exit 0
|
||||||
|
|
||||||
%clean
|
%clean
|
||||||
[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}"
|
[ "%{buildroot}" != / ] && %{__rm} -rf "%{buildroot}"
|
||||||
@@ -34,12 +53,28 @@ touch %{buildroot}%{_localstatedir}/log/%{name}/run.log
|
|||||||
%files
|
%files
|
||||||
%defattr(-,root,root,-)
|
%defattr(-,root,root,-)
|
||||||
%{_datarootdir}/%{name}/lib/%{name}.war
|
%{_datarootdir}/%{name}/lib/%{name}.war
|
||||||
%{_sysconfdir}/init.d/%{name}
|
%config %{_sysconfdir}/init.d/%{name}
|
||||||
%config %{_sysconfdir}/sysconfig/%{name}
|
%config(noreplace) %{_sysconfdir}/sysconfig/%{name}
|
||||||
%{_localstatedir}/log/%{name}/run.log
|
%attr(0755,gitbucket,gitbucket) %{_sharedstatedir}/%{name}
|
||||||
|
%attr(0750,gitbucket,gitbucket) %{_localstatedir}/log/%{name}
|
||||||
|
|
||||||
|
|
||||||
%changelog
|
%changelog
|
||||||
|
* Mon Nov 24 2014 Toru Takahashi <torutk at gmail.com>
|
||||||
|
- Version bump to v2.6
|
||||||
|
|
||||||
|
* Sun Nov 09 2014 Toru Takahashi <torutk at gmail.com>
|
||||||
|
- Version bump to v2.5
|
||||||
|
|
||||||
|
* Sun Oct 26 2014 Toru Takahashi <torutk at gmail.com>
|
||||||
|
- Version bump to v2.4.1
|
||||||
|
|
||||||
|
* Mon Jul 21 2014 Toru Takahashi <torutk at gmail.com>
|
||||||
|
- execute as gitbucket user
|
||||||
|
|
||||||
|
* Sun Jul 20 2014 Toru Takahashi <torutk at gmail.com>
|
||||||
|
- Version bump to v2.1.
|
||||||
|
|
||||||
* Mon Oct 28 2013 Jiri Tyr <jiri_DOT_tyr at gmail.com>
|
* Mon Oct 28 2013 Jiri Tyr <jiri_DOT_tyr at gmail.com>
|
||||||
- Version bump to v1.7.
|
- Version bump to v1.7.
|
||||||
|
|
||||||
14
contrib/macosx/gitbucket.plist → contrib/macosx/makePlist
Normal file → Executable file
14
contrib/macosx/gitbucket.plist → contrib/macosx/makePlist
Normal file → Executable file
@@ -1,3 +1,10 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
# From http://docstore.mik.ua/orelly/unix3/mac/ch02_02.htm
|
||||||
|
source gitbucket.conf
|
||||||
|
GITBUCKET_SERVICE_DIR=`dirname "$GITBUCKET_SERVICE"`
|
||||||
|
mkdir -p "$GITBUCKET_SERVICE_DIR"
|
||||||
|
cat << EOF > "$GITBUCKET_SERVICE_DIR/gitbucket.plist"
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
|
||||||
<plist version="1.0">
|
<plist version="1.0">
|
||||||
@@ -7,14 +14,15 @@
|
|||||||
<key>ProgramArguments</key>
|
<key>ProgramArguments</key>
|
||||||
<array>
|
<array>
|
||||||
<string>/usr/bin/java</string>
|
<string>/usr/bin/java</string>
|
||||||
<string>-Dmail.smtp.starttls.enable=true</string>
|
<string>$GITBUCKET_JVM_OPTS</string>
|
||||||
<string>-jar</string>
|
<string>-jar</string>
|
||||||
<string>gitbucket.war</string>
|
<string>gitbucket.war</string>
|
||||||
<string>--host=127.0.0.1</string>
|
<string>--host=$GITBUCKET_HOST</string>
|
||||||
<string>--port=8080</string>
|
<string>--port=$GITBUCKET_PORT</string>
|
||||||
<string>--https=true</string>
|
<string>--https=true</string>
|
||||||
</array>
|
</array>
|
||||||
<key>RunAtLoad</key>
|
<key>RunAtLoad</key>
|
||||||
<true/>
|
<true/>
|
||||||
</dict>
|
</dict>
|
||||||
</plist>
|
</plist>
|
||||||
|
EOF
|
||||||
@@ -1,17 +0,0 @@
|
|||||||
# Bind host
|
|
||||||
#GITBUCKET_HOST=0.0.0.0
|
|
||||||
|
|
||||||
# Server port
|
|
||||||
#GITBUCKET_PORT=8080
|
|
||||||
|
|
||||||
# Data directory (GITBUCKET_HOME/gitbucket)
|
|
||||||
#GITBUCKET_HOME=/var/lib/gitbucket
|
|
||||||
|
|
||||||
# Path to the WAR file
|
|
||||||
#GITBUCKET_WAR_FILE=/usr/share/gitbucket/lib/gitbucket.war
|
|
||||||
|
|
||||||
# URL prefix for the GitBucket page (http://<host>:<port>/<prefix>/)
|
|
||||||
#GITBUCKET_PREFIX=
|
|
||||||
|
|
||||||
# Other Java option
|
|
||||||
#GITBUCKET_JVM_OPTS=
|
|
||||||
9
etc/deploy-assemby-jar.sh
Executable file
9
etc/deploy-assemby-jar.sh
Executable file
@@ -0,0 +1,9 @@
|
|||||||
|
#!/bin/sh
|
||||||
|
mvn deploy:deploy-file \
|
||||||
|
-DgroupId=gitbucket\
|
||||||
|
-DartifactId=gitbucket-assembly\
|
||||||
|
-Dversion=3.0.0\
|
||||||
|
-Dpackaging=jar\
|
||||||
|
-Dfile=../target/scala-2.11/gitbucket-assembly-3.0.0.jar\
|
||||||
|
-DrepositoryId=sourceforge.jp\
|
||||||
|
-Durl=scp://shell.sourceforge.jp/home/groups/a/am/amateras/htdocs/mvn/
|
||||||
2451
etc/icons.svg
2451
etc/icons.svg
File diff suppressed because it is too large
Load Diff
|
Before Width: | Height: | Size: 87 KiB After Width: | Height: | Size: 78 KiB |
17
etc/pom.xml
Normal file
17
etc/pom.xml
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<?xml version="1.0"?>
|
||||||
|
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<groupId>jp.sf.amateras</groupId>
|
||||||
|
<artifactId>gitbucket-assembly</artifactId>
|
||||||
|
<version>0.0.1</version>
|
||||||
|
<build>
|
||||||
|
<extensions>
|
||||||
|
<extension>
|
||||||
|
<groupId>org.apache.maven.wagon</groupId>
|
||||||
|
<artifactId>wagon-ssh</artifactId>
|
||||||
|
<version>1.0-beta-6</version>
|
||||||
|
</extension>
|
||||||
|
</extensions>
|
||||||
|
</build>
|
||||||
|
</project>
|
||||||
@@ -1 +1 @@
|
|||||||
sbt.version=0.13.1
|
sbt.version=0.13.5
|
||||||
|
|||||||
@@ -1,57 +1,75 @@
|
|||||||
import sbt._
|
import sbt._
|
||||||
import Keys._
|
import Keys._
|
||||||
import org.scalatra.sbt._
|
import org.scalatra.sbt._
|
||||||
import twirl.sbt.TwirlPlugin._
|
|
||||||
import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys
|
import com.typesafe.sbteclipse.plugin.EclipsePlugin.EclipseKeys
|
||||||
|
import play.twirl.sbt.SbtTwirl
|
||||||
|
import play.twirl.sbt.Import.TwirlKeys._
|
||||||
|
import sbtassembly._
|
||||||
|
import sbtassembly.AssemblyKeys._
|
||||||
|
|
||||||
object MyBuild extends Build {
|
object MyBuild extends Build {
|
||||||
val Organization = "jp.sf.amateras"
|
val Organization = "gitbucket"
|
||||||
val Name = "gitbucket"
|
val Name = "gitbucket"
|
||||||
val Version = "0.0.1"
|
val Version = "3.0.0"
|
||||||
val ScalaVersion = "2.10.3"
|
val ScalaVersion = "2.11.2"
|
||||||
val ScalatraVersion = "2.2.1"
|
val ScalatraVersion = "2.3.0"
|
||||||
|
|
||||||
lazy val project = Project (
|
lazy val project = Project (
|
||||||
"gitbucket",
|
"gitbucket",
|
||||||
file("."),
|
file(".")
|
||||||
settings = Defaults.defaultSettings ++ ScalatraPlugin.scalatraWithJRebel ++ Seq(
|
|
||||||
sourcesInBase := false,
|
|
||||||
organization := Organization,
|
|
||||||
name := Name,
|
|
||||||
version := Version,
|
|
||||||
scalaVersion := ScalaVersion,
|
|
||||||
resolvers ++= Seq(
|
|
||||||
Classpaths.typesafeReleases,
|
|
||||||
"amateras-repo" at "http://amateras.sourceforge.jp/mvn/"
|
|
||||||
),
|
|
||||||
scalacOptions := Seq("-deprecation", "-language:postfixOps"),
|
|
||||||
libraryDependencies ++= Seq(
|
|
||||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "3.0.0.201306101825-r",
|
|
||||||
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
|
||||||
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
|
|
||||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
|
||||||
"org.json4s" %% "json4s-jackson" % "3.2.5",
|
|
||||||
"jp.sf.amateras" %% "scalatra-forms" % "0.0.14",
|
|
||||||
"commons-io" % "commons-io" % "2.4",
|
|
||||||
"org.pegdown" % "pegdown" % "1.4.1",
|
|
||||||
"org.apache.commons" % "commons-compress" % "1.5",
|
|
||||||
"org.apache.commons" % "commons-email" % "1.3.1",
|
|
||||||
"org.apache.httpcomponents" % "httpclient" % "4.3",
|
|
||||||
"org.apache.sshd" % "apache-sshd" % "0.11.0",
|
|
||||||
"com.typesafe.slick" %% "slick" % "2.0.2",
|
|
||||||
"org.mozilla" % "rhino" % "1.7R4",
|
|
||||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
|
||||||
"org.quartz-scheduler" % "quartz" % "2.2.1",
|
|
||||||
"com.h2database" % "h2" % "1.3.173",
|
|
||||||
"ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime",
|
|
||||||
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;provided",
|
|
||||||
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts Artifact("javax.servlet", "jar", "jar"),
|
|
||||||
"junit" % "junit" % "4.11" % "test"
|
|
||||||
),
|
|
||||||
EclipseKeys.withSource := true,
|
|
||||||
javacOptions in compile ++= Seq("-target", "6", "-source", "6"),
|
|
||||||
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "junitxml", "console"),
|
|
||||||
packageOptions += Package.MainClass("JettyLauncher")
|
|
||||||
) ++ seq(Twirl.settings: _*)
|
|
||||||
)
|
)
|
||||||
|
.settings(ScalatraPlugin.scalatraWithJRebel: _*)
|
||||||
|
.settings(
|
||||||
|
test in assembly := {},
|
||||||
|
assemblyMergeStrategy in assembly := {
|
||||||
|
case PathList("META-INF", xs @ _*) =>
|
||||||
|
(xs map {_.toLowerCase}) match {
|
||||||
|
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
||||||
|
case _ => MergeStrategy.discard
|
||||||
|
}
|
||||||
|
case x => MergeStrategy.first
|
||||||
|
}
|
||||||
|
)
|
||||||
|
.settings(
|
||||||
|
sourcesInBase := false,
|
||||||
|
organization := Organization,
|
||||||
|
name := Name,
|
||||||
|
version := Version,
|
||||||
|
scalaVersion := ScalaVersion,
|
||||||
|
resolvers ++= Seq(
|
||||||
|
Classpaths.typesafeReleases,
|
||||||
|
"amateras-repo" at "http://amateras.sourceforge.jp/mvn/"
|
||||||
|
),
|
||||||
|
scalacOptions := Seq("-deprecation", "-language:postfixOps"),
|
||||||
|
libraryDependencies ++= Seq(
|
||||||
|
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "3.4.1.201406201815-r",
|
||||||
|
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % "3.4.1.201406201815-r",
|
||||||
|
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
||||||
|
"org.scalatra" %% "scalatra-specs2" % ScalatraVersion % "test",
|
||||||
|
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
||||||
|
"org.json4s" %% "json4s-jackson" % "3.2.10",
|
||||||
|
"jp.sf.amateras" %% "scalatra-forms" % "0.1.0",
|
||||||
|
"commons-io" % "commons-io" % "2.4",
|
||||||
|
"org.pegdown" % "pegdown" % "1.4.1",
|
||||||
|
"org.apache.commons" % "commons-compress" % "1.5",
|
||||||
|
"org.apache.commons" % "commons-email" % "1.3.1",
|
||||||
|
"org.apache.httpcomponents" % "httpclient" % "4.3",
|
||||||
|
"org.apache.sshd" % "apache-sshd" % "0.11.0",
|
||||||
|
"com.typesafe.slick" %% "slick" % "2.1.0",
|
||||||
|
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
|
"com.h2database" % "h2" % "1.4.180",
|
||||||
|
// "ch.qos.logback" % "logback-classic" % "1.0.13" % "runtime",
|
||||||
|
"org.eclipse.jetty" % "jetty-webapp" % "8.1.8.v20121106" % "container;provided",
|
||||||
|
"org.eclipse.jetty.orbit" % "javax.servlet" % "3.0.0.v201112011016" % "container;provided;test" artifacts Artifact("javax.servlet", "jar", "jar"),
|
||||||
|
"junit" % "junit" % "4.11" % "test",
|
||||||
|
"com.mchange" % "c3p0" % "0.9.5",
|
||||||
|
"com.typesafe" % "config" % "1.2.1",
|
||||||
|
"com.typesafe.play" %% "twirl-compiler" % "1.0.2"
|
||||||
|
),
|
||||||
|
play.twirl.sbt.Import.TwirlKeys.templateImports += "gitbucket.core._",
|
||||||
|
EclipseKeys.withSource := true,
|
||||||
|
javacOptions in compile ++= Seq("-target", "7", "-source", "7"),
|
||||||
|
testOptions in Test += Tests.Argument(TestFrameworks.Specs2, "junitxml", "console"),
|
||||||
|
packageOptions += Package.MainClass("JettyLauncher")
|
||||||
|
).enablePlugins(SbtTwirl)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ addSbtPlugin("com.github.mpeltonen" % "sbt-idea" % "1.6.0")
|
|||||||
|
|
||||||
addSbtPlugin("org.scalatra.sbt" % "scalatra-sbt" % "0.3.5")
|
addSbtPlugin("org.scalatra.sbt" % "scalatra-sbt" % "0.3.5")
|
||||||
|
|
||||||
resolvers += "spray repo" at "http://repo.spray.io"
|
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.0.2")
|
||||||
|
|
||||||
addSbtPlugin("io.spray" % "sbt-twirl" % "0.7.0")
|
|
||||||
|
|
||||||
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.4")
|
addSbtPlugin("com.timushev.sbt" % "sbt-updates" % "0.1.4")
|
||||||
|
|
||||||
|
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.12.0")
|
||||||
Binary file not shown.
2
sbt.bat
2
sbt.bat
@@ -1,2 +1,2 @@
|
|||||||
set SCRIPT_DIR=%~dp0
|
set SCRIPT_DIR=%~dp0
|
||||||
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar "%SCRIPT_DIR%\sbt-launch-0.13.1.jar" %*
|
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar "%SCRIPT_DIR%\sbt-launch-0.13.5.jar" %*
|
||||||
|
|||||||
3
sbt.sh
3
sbt.sh
@@ -1 +1,2 @@
|
|||||||
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar `dirname $0`/sbt-launch-0.13.1.jar "$@"
|
#!/bin/sh
|
||||||
|
java -Dsbt.log.noformat=true -XX:+CMSClassUnloadingEnabled -XX:MaxPermSize=256m -Xmx512M -Xss2M -Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005 -jar `dirname $0`/sbt-launch-0.13.5.jar "$@"
|
||||||
|
|||||||
@@ -1,10 +1,8 @@
|
|||||||
import org.eclipse.jetty.io.EndPoint;
|
|
||||||
import org.eclipse.jetty.server.Request;
|
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.File;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
|
||||||
@@ -44,6 +42,14 @@ public class JettyLauncher {
|
|||||||
server.addConnector(connector);
|
server.addConnector(connector);
|
||||||
|
|
||||||
WebAppContext context = new WebAppContext();
|
WebAppContext context = new WebAppContext();
|
||||||
|
|
||||||
|
File tmpDir = new File(getGitBucketHome(), "tmp");
|
||||||
|
if(tmpDir.exists()){
|
||||||
|
deleteDirectory(tmpDir);
|
||||||
|
}
|
||||||
|
tmpDir.mkdirs();
|
||||||
|
context.setTempDirectory(tmpDir);
|
||||||
|
|
||||||
ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
|
ProtectionDomain domain = JettyLauncher.class.getProtectionDomain();
|
||||||
URL location = domain.getCodeSource().getLocation();
|
URL location = domain.getCodeSource().getLocation();
|
||||||
|
|
||||||
@@ -59,4 +65,27 @@ public class JettyLauncher {
|
|||||||
server.start();
|
server.start();
|
||||||
server.join();
|
server.join();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static File getGitBucketHome(){
|
||||||
|
String home = System.getProperty("gitbucket.home");
|
||||||
|
if(home != null && home.length() > 0){
|
||||||
|
return new File(home);
|
||||||
|
}
|
||||||
|
home = System.getenv("GITBUCKET_HOME");
|
||||||
|
if(home != null && home.length() > 0){
|
||||||
|
return new File(home);
|
||||||
|
}
|
||||||
|
return new File(System.getProperty("user.home"), ".gitbucket");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void deleteDirectory(File dir){
|
||||||
|
for(File file: dir.listFiles()){
|
||||||
|
if(file.isFile()){
|
||||||
|
file.delete();
|
||||||
|
} else if(file.isDirectory()){
|
||||||
|
deleteDirectory(file);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
dir.delete();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package util;
|
package gitbucket.core.util;
|
||||||
|
|
||||||
import org.eclipse.jgit.api.errors.PatchApplyException;
|
import org.eclipse.jgit.api.errors.PatchApplyException;
|
||||||
import org.eclipse.jgit.diff.RawText;
|
import org.eclipse.jgit.diff.RawText;
|
||||||
6
src/main/resources/database.conf
Normal file
6
src/main/resources/database.conf
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
db {
|
||||||
|
driver = "org.h2.Driver"
|
||||||
|
url = "jdbc:h2:${DatabaseHome};MVCC=true"
|
||||||
|
user = "sa"
|
||||||
|
password = "sa"
|
||||||
|
}
|
||||||
6
src/main/resources/update/2_3.sql
Normal file
6
src/main/resources/update/2_3.sql
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
CREATE TABLE PLUGIN (
|
||||||
|
PLUGIN_ID VARCHAR(100) NOT NULL,
|
||||||
|
VERSION VARCHAR(100) NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE PLUGIN ADD CONSTRAINT IDX_PLUGIN_PK PRIMARY KEY (PLUGIN_ID);
|
||||||
18
src/main/resources/update/2_7.sql
Normal file
18
src/main/resources/update/2_7.sql
Normal file
@@ -0,0 +1,18 @@
|
|||||||
|
CREATE TABLE COMMIT_COMMENT (
|
||||||
|
USER_NAME VARCHAR(100) NOT NULL,
|
||||||
|
REPOSITORY_NAME VARCHAR(100) NOT NULL,
|
||||||
|
COMMIT_ID VARCHAR(100) NOT NULL,
|
||||||
|
COMMENT_ID INT AUTO_INCREMENT,
|
||||||
|
COMMENTED_USER_NAME VARCHAR(100) NOT NULL,
|
||||||
|
CONTENT TEXT NOT NULL,
|
||||||
|
FILE_NAME NVARCHAR(100),
|
||||||
|
OLD_LINE_NUMBER INT,
|
||||||
|
NEW_LINE_NUMBER INT,
|
||||||
|
REGISTERED_DATE TIMESTAMP NOT NULL,
|
||||||
|
UPDATED_DATE TIMESTAMP NOT NULL,
|
||||||
|
PULL_REQUEST BOOLEAN NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
ALTER TABLE COMMIT_COMMENT ADD CONSTRAINT IDX_COMMIT_COMMENT_PK PRIMARY KEY (COMMENT_ID);
|
||||||
|
ALTER TABLE COMMIT_COMMENT ADD CONSTRAINT IDX_COMMIT_COMMENT_FK0 FOREIGN KEY (USER_NAME, REPOSITORY_NAME) REFERENCES REPOSITORY (USER_NAME, REPOSITORY_NAME);
|
||||||
|
ALTER TABLE COMMIT_COMMENT ADD CONSTRAINT IDX_COMMIT_COMMENT_1 UNIQUE (USER_NAME, REPOSITORY_NAME, COMMIT_ID, COMMENT_ID);
|
||||||
1
src/main/resources/update/2_8.sql
Normal file
1
src/main/resources/update/2_8.sql
Normal file
@@ -0,0 +1 @@
|
|||||||
|
ALTER TABLE COMMIT_COMMENT ALTER COLUMN FILE_NAME NVARCHAR(260);
|
||||||
@@ -1,5 +1,9 @@
|
|||||||
import _root_.servlet.{PluginActionInvokeFilter, BasicAuthenticationFilter, TransactionFilter}
|
|
||||||
import app._
|
import gitbucket.core.controller._
|
||||||
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
|
import gitbucket.core.servlet.{TransactionFilter, BasicAuthenticationFilter}
|
||||||
|
import gitbucket.core.util.Directory
|
||||||
|
|
||||||
//import jp.sf.amateras.scalatra.forms.ValidationJavaScriptProvider
|
//import jp.sf.amateras.scalatra.forms.ValidationJavaScriptProvider
|
||||||
import org.scalatra._
|
import org.scalatra._
|
||||||
import javax.servlet._
|
import javax.servlet._
|
||||||
@@ -10,12 +14,16 @@ class ScalatraBootstrap extends LifeCycle {
|
|||||||
// Register TransactionFilter and BasicAuthenticationFilter at first
|
// Register TransactionFilter and BasicAuthenticationFilter at first
|
||||||
context.addFilter("transactionFilter", new TransactionFilter)
|
context.addFilter("transactionFilter", new TransactionFilter)
|
||||||
context.getFilterRegistration("transactionFilter").addMappingForUrlPatterns(EnumSet.allOf(classOf[DispatcherType]), true, "/*")
|
context.getFilterRegistration("transactionFilter").addMappingForUrlPatterns(EnumSet.allOf(classOf[DispatcherType]), true, "/*")
|
||||||
context.addFilter("pluginActionInvokeFilter", new PluginActionInvokeFilter)
|
|
||||||
context.getFilterRegistration("pluginActionInvokeFilter").addMappingForUrlPatterns(EnumSet.allOf(classOf[DispatcherType]), true, "/*")
|
|
||||||
context.addFilter("basicAuthenticationFilter", new BasicAuthenticationFilter)
|
context.addFilter("basicAuthenticationFilter", new BasicAuthenticationFilter)
|
||||||
context.getFilterRegistration("basicAuthenticationFilter").addMappingForUrlPatterns(EnumSet.allOf(classOf[DispatcherType]), true, "/git/*")
|
context.getFilterRegistration("basicAuthenticationFilter").addMappingForUrlPatterns(EnumSet.allOf(classOf[DispatcherType]), true, "/git/*")
|
||||||
|
|
||||||
// Register controllers
|
// Register controllers
|
||||||
|
context.mount(new AnonymousAccessController, "/*")
|
||||||
|
|
||||||
|
PluginRegistry().getControllers.foreach { case (controller, path) =>
|
||||||
|
context.mount(controller, path)
|
||||||
|
}
|
||||||
|
|
||||||
context.mount(new IndexController, "/")
|
context.mount(new IndexController, "/")
|
||||||
context.mount(new SearchController, "/")
|
context.mount(new SearchController, "/")
|
||||||
context.mount(new FileUploadController, "/upload")
|
context.mount(new FileUploadController, "/upload")
|
||||||
@@ -32,7 +40,7 @@ class ScalatraBootstrap extends LifeCycle {
|
|||||||
context.mount(new RepositorySettingsController, "/*")
|
context.mount(new RepositorySettingsController, "/*")
|
||||||
|
|
||||||
// Create GITBUCKET_HOME directory if it does not exist
|
// Create GITBUCKET_HOME directory if it does not exist
|
||||||
val dir = new java.io.File(_root_.util.Directory.GitBucketHome)
|
val dir = new java.io.File(Directory.GitBucketHome)
|
||||||
if(!dir.exists){
|
if(!dir.exists){
|
||||||
dir.mkdirs()
|
dir.mkdirs()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,109 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import service._
|
|
||||||
import util.{UsersAuthenticator, Keys}
|
|
||||||
import util.Implicits._
|
|
||||||
|
|
||||||
class DashboardController extends DashboardControllerBase
|
|
||||||
with IssuesService with PullRequestService with RepositoryService with AccountService
|
|
||||||
with UsersAuthenticator
|
|
||||||
|
|
||||||
trait DashboardControllerBase extends ControllerBase {
|
|
||||||
self: IssuesService with PullRequestService with RepositoryService with UsersAuthenticator =>
|
|
||||||
|
|
||||||
get("/dashboard/issues/repos")(usersOnly {
|
|
||||||
searchIssues("all")
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/issues/assigned")(usersOnly {
|
|
||||||
searchIssues("assigned")
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/issues/created_by")(usersOnly {
|
|
||||||
searchIssues("created_by")
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/pulls")(usersOnly {
|
|
||||||
searchPullRequests("created_by", None)
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/pulls/owned")(usersOnly {
|
|
||||||
searchPullRequests("created_by", None)
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/pulls/public")(usersOnly {
|
|
||||||
searchPullRequests("not_created_by", None)
|
|
||||||
})
|
|
||||||
|
|
||||||
get("/dashboard/pulls/for/:owner/:repository")(usersOnly {
|
|
||||||
searchPullRequests("all", Some(params("owner") + "/" + params("repository")))
|
|
||||||
})
|
|
||||||
|
|
||||||
private def searchIssues(filter: String) = {
|
|
||||||
import IssuesService._
|
|
||||||
|
|
||||||
// condition
|
|
||||||
val condition = session.putAndGet(Keys.Session.DashboardIssues,
|
|
||||||
if(request.hasQueryString) IssueSearchCondition(request)
|
|
||||||
else session.getAs[IssueSearchCondition](Keys.Session.DashboardIssues).getOrElse(IssueSearchCondition())
|
|
||||||
)
|
|
||||||
|
|
||||||
val userName = context.loginAccount.get.userName
|
|
||||||
val repositories = getUserRepositories(userName, context.baseUrl).map(repo => repo.owner -> repo.name)
|
|
||||||
val filterUser = Map(filter -> userName)
|
|
||||||
val page = IssueSearchCondition.page(request)
|
|
||||||
//
|
|
||||||
dashboard.html.issues(
|
|
||||||
issues.html.listparts(
|
|
||||||
searchIssue(condition, filterUser, false, (page - 1) * IssueLimit, IssueLimit, repositories: _*),
|
|
||||||
page,
|
|
||||||
countIssue(condition.copy(state = "open"), filterUser, false, repositories: _*),
|
|
||||||
countIssue(condition.copy(state = "closed"), filterUser, false, repositories: _*),
|
|
||||||
condition),
|
|
||||||
countIssue(condition, Map.empty, false, repositories: _*),
|
|
||||||
countIssue(condition, Map("assigned" -> userName), false, repositories: _*),
|
|
||||||
countIssue(condition, Map("created_by" -> userName), false, repositories: _*),
|
|
||||||
countIssueGroupByRepository(condition, filterUser, false, repositories: _*),
|
|
||||||
condition,
|
|
||||||
filter)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private def searchPullRequests(filter: String, repository: Option[String]) = {
|
|
||||||
import IssuesService._
|
|
||||||
import PullRequestService._
|
|
||||||
|
|
||||||
// condition
|
|
||||||
val condition = session.putAndGet(Keys.Session.DashboardPulls, {
|
|
||||||
if(request.hasQueryString) IssueSearchCondition(request)
|
|
||||||
else session.getAs[IssueSearchCondition](Keys.Session.DashboardPulls).getOrElse(IssueSearchCondition())
|
|
||||||
}.copy(repo = repository))
|
|
||||||
|
|
||||||
val userName = context.loginAccount.get.userName
|
|
||||||
val repositories = getUserRepositories(userName, context.baseUrl).map(repo => repo.owner -> repo.name)
|
|
||||||
val filterUser = Map(filter -> userName)
|
|
||||||
val page = IssueSearchCondition.page(request)
|
|
||||||
|
|
||||||
val counts = countIssueGroupByRepository(
|
|
||||||
IssueSearchCondition().copy(state = condition.state), Map.empty, true, repositories: _*)
|
|
||||||
|
|
||||||
dashboard.html.pulls(
|
|
||||||
pulls.html.listparts(
|
|
||||||
searchIssue(condition, filterUser, true, (page - 1) * PullRequestLimit, PullRequestLimit, repositories: _*),
|
|
||||||
page,
|
|
||||||
countIssue(condition.copy(state = "open"), filterUser, true, repositories: _*),
|
|
||||||
countIssue(condition.copy(state = "closed"), filterUser, true, repositories: _*),
|
|
||||||
condition,
|
|
||||||
None,
|
|
||||||
false),
|
|
||||||
getPullRequestCountGroupByUser(condition.state == "closed", None, None),
|
|
||||||
getRepositoryNamesOfUser(userName).map { RepoName =>
|
|
||||||
(userName, RepoName, counts.collectFirst { case (_, RepoName, count) => count }.getOrElse(0))
|
|
||||||
}.sortBy(_._3).reverse,
|
|
||||||
condition,
|
|
||||||
filter)
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,66 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import jp.sf.amateras.scalatra.forms._
|
|
||||||
import service._
|
|
||||||
import util.CollaboratorsAuthenticator
|
|
||||||
import util.Implicits._
|
|
||||||
import org.scalatra.i18n.Messages
|
|
||||||
|
|
||||||
class LabelsController extends LabelsControllerBase
|
|
||||||
with LabelsService with RepositoryService with AccountService with CollaboratorsAuthenticator
|
|
||||||
|
|
||||||
trait LabelsControllerBase extends ControllerBase {
|
|
||||||
self: LabelsService with RepositoryService with CollaboratorsAuthenticator =>
|
|
||||||
|
|
||||||
case class LabelForm(labelName: String, color: String)
|
|
||||||
|
|
||||||
val newForm = mapping(
|
|
||||||
"newLabelName" -> trim(label("Label name", text(required, labelName, maxlength(100)))),
|
|
||||||
"newColor" -> trim(label("Color", text(required, color)))
|
|
||||||
)(LabelForm.apply)
|
|
||||||
|
|
||||||
val editForm = mapping(
|
|
||||||
"editLabelName" -> trim(label("Label name", text(required, labelName, maxlength(100)))),
|
|
||||||
"editColor" -> trim(label("Color", text(required, color)))
|
|
||||||
)(LabelForm.apply)
|
|
||||||
|
|
||||||
post("/:owner/:repository/issues/label/new", newForm)(collaboratorsOnly { (form, repository) =>
|
|
||||||
createLabel(repository.owner, repository.name, form.labelName, form.color.substring(1))
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/issues")
|
|
||||||
})
|
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/label/edit")(collaboratorsOnly { repository =>
|
|
||||||
issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
|
|
||||||
})
|
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/label/:labelId/edit")(collaboratorsOnly { repository =>
|
|
||||||
getLabel(repository.owner, repository.name, params("labelId").toInt).map { label =>
|
|
||||||
issues.labels.html.edit(Some(label), repository)
|
|
||||||
} getOrElse NotFound()
|
|
||||||
})
|
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/label/:labelId/edit", editForm)(collaboratorsOnly { (form, repository) =>
|
|
||||||
updateLabel(repository.owner, repository.name, params("labelId").toInt, form.labelName, form.color.substring(1))
|
|
||||||
issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
|
|
||||||
})
|
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/label/:labelId/delete")(collaboratorsOnly { repository =>
|
|
||||||
deleteLabel(repository.owner, repository.name, params("labelId").toInt)
|
|
||||||
issues.labels.html.editlist(getLabels(repository.owner, repository.name), repository)
|
|
||||||
})
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constraint for the identifier such as user name, repository name or page name.
|
|
||||||
*/
|
|
||||||
private def labelName: Constraint = new Constraint(){
|
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
|
||||||
if(value.contains(',')){
|
|
||||||
Some(s"${name} contains invalid character.")
|
|
||||||
} else if(value.startsWith("_") || value.startsWith("-")){
|
|
||||||
Some(s"${name} starts with invalid character.")
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,184 +0,0 @@
|
|||||||
package app
|
|
||||||
|
|
||||||
import service.{AccountService, SystemSettingsService}
|
|
||||||
import SystemSettingsService._
|
|
||||||
import util.AdminAuthenticator
|
|
||||||
import util.Directory._
|
|
||||||
import util.ControlUtil._
|
|
||||||
import jp.sf.amateras.scalatra.forms._
|
|
||||||
import ssh.SshServer
|
|
||||||
import org.apache.commons.io.FileUtils
|
|
||||||
import java.io.FileInputStream
|
|
||||||
import plugin.{Plugin, PluginSystem}
|
|
||||||
|
|
||||||
class SystemSettingsController extends SystemSettingsControllerBase
|
|
||||||
with AccountService with AdminAuthenticator
|
|
||||||
|
|
||||||
trait SystemSettingsControllerBase extends ControllerBase {
|
|
||||||
self: AccountService with AdminAuthenticator =>
|
|
||||||
|
|
||||||
private val form = mapping(
|
|
||||||
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
|
||||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
|
||||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
|
||||||
"notification" -> trim(label("Notification", boolean())),
|
|
||||||
"ssh" -> trim(label("SSH access", boolean())),
|
|
||||||
"sshPort" -> trim(label("SSH port", optional(number()))),
|
|
||||||
"smtp" -> optionalIfNotChecked("notification", mapping(
|
|
||||||
"host" -> trim(label("SMTP Host", text(required))),
|
|
||||||
"port" -> trim(label("SMTP Port", optional(number()))),
|
|
||||||
"user" -> trim(label("SMTP User", optional(text()))),
|
|
||||||
"password" -> trim(label("SMTP Password", optional(text()))),
|
|
||||||
"ssl" -> trim(label("Enable SSL", optional(boolean()))),
|
|
||||||
"fromAddress" -> trim(label("FROM Address", optional(text()))),
|
|
||||||
"fromName" -> trim(label("FROM Name", optional(text())))
|
|
||||||
)(Smtp.apply)),
|
|
||||||
"ldapAuthentication" -> trim(label("LDAP", boolean())),
|
|
||||||
"ldap" -> optionalIfNotChecked("ldapAuthentication", mapping(
|
|
||||||
"host" -> trim(label("LDAP host", text(required))),
|
|
||||||
"port" -> trim(label("LDAP port", optional(number()))),
|
|
||||||
"bindDN" -> trim(label("Bind DN", optional(text()))),
|
|
||||||
"bindPassword" -> trim(label("Bind Password", optional(text()))),
|
|
||||||
"baseDN" -> trim(label("Base DN", text(required))),
|
|
||||||
"userNameAttribute" -> trim(label("User name attribute", text(required))),
|
|
||||||
"fullNameAttribute" -> trim(label("Full name attribute", optional(text()))),
|
|
||||||
"mailAttribute" -> trim(label("Mail address attribute", text(required))),
|
|
||||||
"tls" -> trim(label("Enable TLS", optional(boolean()))),
|
|
||||||
"keystore" -> trim(label("Keystore", optional(text())))
|
|
||||||
)(Ldap.apply))
|
|
||||||
)(SystemSettings.apply).verifying { settings =>
|
|
||||||
if(settings.ssh && settings.baseUrl.isEmpty){
|
|
||||||
Seq("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
|
||||||
} else Nil
|
|
||||||
}
|
|
||||||
|
|
||||||
private val pluginForm = mapping(
|
|
||||||
"pluginId" -> list(trim(label("", text())))
|
|
||||||
)(PluginForm.apply)
|
|
||||||
|
|
||||||
case class PluginForm(pluginIds: List[String])
|
|
||||||
|
|
||||||
get("/admin/system")(adminOnly {
|
|
||||||
admin.html.system(flash.get("info"))
|
|
||||||
})
|
|
||||||
|
|
||||||
post("/admin/system", form)(adminOnly { form =>
|
|
||||||
saveSystemSettings(form)
|
|
||||||
|
|
||||||
if(form.ssh && SshServer.isActive && context.settings.sshPort != form.sshPort){
|
|
||||||
SshServer.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
if(form.ssh && !SshServer.isActive && form.baseUrl.isDefined){
|
|
||||||
SshServer.start(request.getServletContext,
|
|
||||||
form.sshPort.getOrElse(SystemSettingsService.DefaultSshPort),
|
|
||||||
form.baseUrl.get)
|
|
||||||
} else if(!form.ssh && SshServer.isActive){
|
|
||||||
SshServer.stop()
|
|
||||||
}
|
|
||||||
|
|
||||||
flash += "info" -> "System settings has been updated."
|
|
||||||
redirect("/admin/system")
|
|
||||||
})
|
|
||||||
|
|
||||||
// TODO Enable commented code to enable plug-in system
|
|
||||||
// get("/admin/plugins")(adminOnly {
|
|
||||||
// val installedPlugins = plugin.PluginSystem.plugins
|
|
||||||
// val updatablePlugins = getAvailablePlugins(installedPlugins).filter(_.status == "updatable")
|
|
||||||
// admin.plugins.html.installed(installedPlugins, updatablePlugins)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// post("/admin/plugins/_update", pluginForm)(adminOnly { form =>
|
|
||||||
// deletePlugins(form.pluginIds)
|
|
||||||
// installPlugins(form.pluginIds)
|
|
||||||
// redirect("/admin/plugins")
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// post("/admin/plugins/_delete", pluginForm)(adminOnly { form =>
|
|
||||||
// deletePlugins(form.pluginIds)
|
|
||||||
// redirect("/admin/plugins")
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// get("/admin/plugins/available")(adminOnly {
|
|
||||||
// val installedPlugins = plugin.PluginSystem.plugins
|
|
||||||
// val availablePlugins = getAvailablePlugins(installedPlugins).filter(_.status == "available")
|
|
||||||
// admin.plugins.html.available(availablePlugins)
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// post("/admin/plugins/_install", pluginForm)(adminOnly { form =>
|
|
||||||
// installPlugins(form.pluginIds)
|
|
||||||
// redirect("/admin/plugins")
|
|
||||||
// })
|
|
||||||
|
|
||||||
// get("/admin/plugins/console")(adminOnly {
|
|
||||||
// admin.plugins.html.console()
|
|
||||||
// })
|
|
||||||
//
|
|
||||||
// post("/admin/plugins/console")(adminOnly {
|
|
||||||
// val script = request.getParameter("script")
|
|
||||||
// val result = plugin.JavaScriptPlugin.evaluateJavaScript(script)
|
|
||||||
// Ok(result)
|
|
||||||
// })
|
|
||||||
|
|
||||||
// TODO Move these methods to PluginSystem or Service?
|
|
||||||
private def deletePlugins(pluginIds: List[String]): Unit = {
|
|
||||||
pluginIds.foreach { pluginId =>
|
|
||||||
plugin.PluginSystem.uninstall(pluginId)
|
|
||||||
val dir = new java.io.File(PluginHome, pluginId)
|
|
||||||
if(dir.exists && dir.isDirectory){
|
|
||||||
FileUtils.deleteQuietly(dir)
|
|
||||||
PluginSystem.uninstall(pluginId)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def installPlugins(pluginIds: List[String]): Unit = {
|
|
||||||
val dir = getPluginCacheDir()
|
|
||||||
val installedPlugins = plugin.PluginSystem.plugins
|
|
||||||
getAvailablePlugins(installedPlugins).filter(x => pluginIds.contains(x.id)).foreach { plugin =>
|
|
||||||
val pluginDir = new java.io.File(PluginHome, plugin.id)
|
|
||||||
if(!pluginDir.exists){
|
|
||||||
FileUtils.copyDirectory(new java.io.File(dir, plugin.repository + "/" + plugin.id), pluginDir)
|
|
||||||
}
|
|
||||||
PluginSystem.installPlugin(plugin.id)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private def getAvailablePlugins(installedPlugins: List[Plugin]): List[SystemSettingsControllerBase.AvailablePlugin] = {
|
|
||||||
val repositoryRoot = getPluginCacheDir()
|
|
||||||
|
|
||||||
if(repositoryRoot.exists && repositoryRoot.isDirectory){
|
|
||||||
PluginSystem.repositories.flatMap { repo =>
|
|
||||||
val repoDir = new java.io.File(repositoryRoot, repo.id)
|
|
||||||
if(repoDir.exists && repoDir.isDirectory){
|
|
||||||
repoDir.listFiles.filter(d => d.isDirectory && !d.getName.startsWith(".")).map { plugin =>
|
|
||||||
val propertyFile = new java.io.File(plugin, "plugin.properties")
|
|
||||||
val properties = new java.util.Properties()
|
|
||||||
if(propertyFile.exists && propertyFile.isFile){
|
|
||||||
using(new FileInputStream(propertyFile)){ in =>
|
|
||||||
properties.load(in)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SystemSettingsControllerBase.AvailablePlugin(
|
|
||||||
repository = repo.id,
|
|
||||||
id = properties.getProperty("id"),
|
|
||||||
version = properties.getProperty("version"),
|
|
||||||
author = properties.getProperty("author"),
|
|
||||||
url = properties.getProperty("url"),
|
|
||||||
description = properties.getProperty("description"),
|
|
||||||
status = installedPlugins.find(_.id == properties.getProperty("id")) match {
|
|
||||||
case Some(x) if(PluginSystem.isUpdatable(x.version, properties.getProperty("version")))=> "updatable"
|
|
||||||
case Some(x) => "installed"
|
|
||||||
case None => "available"
|
|
||||||
})
|
|
||||||
}
|
|
||||||
} else Nil
|
|
||||||
}
|
|
||||||
} else Nil
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
object SystemSettingsControllerBase {
|
|
||||||
case class AvailablePlugin(repository: String, id: String, version: String,
|
|
||||||
author: String, url: String, description: String, status: String)
|
|
||||||
}
|
|
||||||
@@ -1,19 +1,22 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import service._
|
import gitbucket.core.account.html
|
||||||
import util._
|
import gitbucket.core.helper
|
||||||
import util.StringUtil._
|
import gitbucket.core.model.GroupMember
|
||||||
import util.Directory._
|
import gitbucket.core.util._
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.Implicits._
|
||||||
import util.Implicits._
|
import gitbucket.core.util.Directory._
|
||||||
import ssh.SshUtil
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.StringUtil._
|
||||||
|
import gitbucket.core.ssh.SshUtil
|
||||||
|
import gitbucket.core.service._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
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.{FileMode, Constants}
|
import org.eclipse.jgit.lib.{FileMode, Constants}
|
||||||
import org.eclipse.jgit.dircache.DirCache
|
import org.eclipse.jgit.dircache.DirCache
|
||||||
import model.GroupMember
|
|
||||||
|
|
||||||
class AccountController extends AccountControllerBase
|
class AccountController extends AccountControllerBase
|
||||||
with AccountService with RepositoryService with ActivityService with WikiService with LabelsService with SshKeyService
|
with AccountService with RepositoryService with ActivityService with WikiService with LabelsService with SshKeyService
|
||||||
@@ -88,6 +91,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"name" -> trim(label("Repository name", text(required)))
|
"name" -> trim(label("Repository name", text(required)))
|
||||||
)(ForkRepositoryForm.apply)
|
)(ForkRepositoryForm.apply)
|
||||||
|
|
||||||
|
case class AccountForm(accountName: String)
|
||||||
|
|
||||||
|
val accountForm = mapping(
|
||||||
|
"account" -> trim(label("Group/User name", text(required, validAccountName)))
|
||||||
|
)(AccountForm.apply)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays user information.
|
* Displays user information.
|
||||||
*/
|
*/
|
||||||
@@ -97,21 +106,21 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
params.getOrElse("tab", "repositories") match {
|
params.getOrElse("tab", "repositories") match {
|
||||||
// Public Activity
|
// Public Activity
|
||||||
case "activity" =>
|
case "activity" =>
|
||||||
_root_.account.html.activity(account,
|
gitbucket.core.account.html.activity(account,
|
||||||
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
||||||
getActivitiesByUser(userName, true))
|
getActivitiesByUser(userName, true))
|
||||||
|
|
||||||
// Members
|
// Members
|
||||||
case "members" if(account.isGroupAccount) => {
|
case "members" if(account.isGroupAccount) => {
|
||||||
val members = getGroupMembers(account.userName)
|
val members = getGroupMembers(account.userName)
|
||||||
_root_.account.html.members(account, members.map(_.userName),
|
gitbucket.core.account.html.members(account, members.map(_.userName),
|
||||||
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager }))
|
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager }))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Repositories
|
// Repositories
|
||||||
case _ => {
|
case _ => {
|
||||||
val members = getGroupMembers(account.userName)
|
val members = getGroupMembers(account.userName)
|
||||||
_root_.account.html.repositories(account,
|
gitbucket.core.account.html.repositories(account,
|
||||||
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
if(account.isGroupAccount) Nil else getGroupsByUserName(userName),
|
||||||
getVisibleRepositories(context.loginAccount, context.baseUrl, Some(userName)),
|
getVisibleRepositories(context.loginAccount, context.baseUrl, Some(userName)),
|
||||||
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager }))
|
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager }))
|
||||||
@@ -129,8 +138,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_avatar"){
|
get("/:userName/_avatar"){
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
||||||
contentType = FileUtil.getMimeType(image)
|
RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image))
|
||||||
new java.io.File(getUserUploadDir(userName), image)
|
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
contentType = "image/png"
|
contentType = "image/png"
|
||||||
Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png")
|
Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png")
|
||||||
@@ -140,7 +148,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_edit")(oneselfOnly {
|
get("/:userName/_edit")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { x =>
|
getAccountByUserName(userName).map { x =>
|
||||||
account.html.edit(x, flash.get("info"))
|
html.edit(x, flash.get("info"))
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -184,7 +192,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:userName/_ssh")(oneselfOnly {
|
get("/:userName/_ssh")(oneselfOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { x =>
|
getAccountByUserName(userName).map { x =>
|
||||||
account.html.ssh(x, getPublicKeys(x.userName))
|
html.ssh(x, getPublicKeys(x.userName))
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -206,7 +214,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
if(context.loginAccount.isDefined){
|
if(context.loginAccount.isDefined){
|
||||||
redirect("/")
|
redirect("/")
|
||||||
} else {
|
} else {
|
||||||
account.html.register()
|
html.register()
|
||||||
}
|
}
|
||||||
} else NotFound
|
} else NotFound
|
||||||
}
|
}
|
||||||
@@ -220,7 +228,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get("/groups/new")(usersOnly {
|
get("/groups/new")(usersOnly {
|
||||||
account.html.group(None, List(GroupMember("", context.loginAccount.get.userName, true)))
|
html.group(None, List(GroupMember("", context.loginAccount.get.userName, true)))
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/groups/new", newGroupForm)(usersOnly { form =>
|
post("/groups/new", newGroupForm)(usersOnly { form =>
|
||||||
@@ -236,7 +244,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
get("/:groupName/_editgroup")(managersOnly {
|
get("/:groupName/_editgroup")(managersOnly {
|
||||||
defining(params("groupName")){ groupName =>
|
defining(params("groupName")){ groupName =>
|
||||||
account.html.group(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
html.group(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -285,7 +293,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
* Show the new repository form.
|
* Show the new repository form.
|
||||||
*/
|
*/
|
||||||
get("/new")(usersOnly {
|
get("/new")(usersOnly {
|
||||||
account.html.newrepo(getGroupsByUserName(context.loginAccount.get.userName))
|
html.newrepo(getGroupsByUserName(context.loginAccount.get.userName), context.settings.isCreateRepoOptionPublic)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -335,7 +343,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
builder.finish()
|
builder.finish()
|
||||||
|
|
||||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
||||||
loginAccount.fullName, loginAccount.mailAddress, "Initial commit")
|
Constants.HEAD, loginAccount.fullName, loginAccount.mailAddress, "Initial commit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -354,11 +362,31 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||||
val loginAccount = context.loginAccount.get
|
val loginAccount = context.loginAccount.get
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
|
val groups = getGroupsByUserName(loginUserName)
|
||||||
|
groups match {
|
||||||
|
case _: List[String] =>
|
||||||
|
val managerPermissions = groups.map { group =>
|
||||||
|
val members = getGroupMembers(group)
|
||||||
|
context.loginAccount.exists(x => members.exists { member => member.userName == x.userName && member.isManager })
|
||||||
|
}
|
||||||
|
helper.html.forkrepository(
|
||||||
|
repository,
|
||||||
|
(groups zip managerPermissions).toMap
|
||||||
|
)
|
||||||
|
case _ => redirect(s"/${loginUserName}")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
LockUtil.lock(s"${loginUserName}/${repository.name}"){
|
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||||
if(repository.owner == loginUserName || getRepository(loginAccount.userName, repository.name, baseUrl).isDefined){
|
val loginAccount = context.loginAccount.get
|
||||||
|
val loginUserName = loginAccount.userName
|
||||||
|
val accountName = form.accountName
|
||||||
|
|
||||||
|
LockUtil.lock(s"${accountName}/${repository.name}"){
|
||||||
|
if(getRepository(accountName, repository.name, baseUrl).isDefined ||
|
||||||
|
(accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))){
|
||||||
// redirect to the repository if repository already exists
|
// redirect to the repository if repository already exists
|
||||||
redirect(s"/${loginUserName}/${repository.name}")
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
} else {
|
} else {
|
||||||
// Insert to the database at first
|
// Insert to the database at first
|
||||||
val originUserName = repository.repository.originUserName.getOrElse(repository.owner)
|
val originUserName = repository.repository.originUserName.getOrElse(repository.owner)
|
||||||
@@ -366,7 +394,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
createRepository(
|
createRepository(
|
||||||
repositoryName = repository.name,
|
repositoryName = repository.name,
|
||||||
userName = loginUserName,
|
userName = accountName,
|
||||||
description = repository.repository.description,
|
description = repository.repository.description,
|
||||||
isPrivate = repository.repository.isPrivate,
|
isPrivate = repository.repository.isPrivate,
|
||||||
originRepositoryName = Some(originRepositoryName),
|
originRepositoryName = Some(originRepositoryName),
|
||||||
@@ -376,22 +404,22 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Insert default labels
|
// Insert default labels
|
||||||
insertDefaultLabels(loginUserName, repository.name)
|
insertDefaultLabels(accountName, repository.name)
|
||||||
|
|
||||||
// clone repository actually
|
// clone repository actually
|
||||||
JGitUtil.cloneRepository(
|
JGitUtil.cloneRepository(
|
||||||
getRepositoryDir(repository.owner, repository.name),
|
getRepositoryDir(repository.owner, repository.name),
|
||||||
getRepositoryDir(loginUserName, repository.name))
|
getRepositoryDir(accountName, repository.name))
|
||||||
|
|
||||||
// Create Wiki repository
|
// Create Wiki repository
|
||||||
JGitUtil.cloneRepository(
|
JGitUtil.cloneRepository(
|
||||||
getWikiRepositoryDir(repository.owner, repository.name),
|
getWikiRepositoryDir(repository.owner, repository.name),
|
||||||
getWikiRepositoryDir(loginUserName, repository.name))
|
getWikiRepositoryDir(accountName, repository.name))
|
||||||
|
|
||||||
// Record activity
|
// Record activity
|
||||||
recordForkActivity(repository.owner, repository.name, loginUserName)
|
recordForkActivity(repository.owner, repository.name, loginUserName, accountName)
|
||||||
// redirect to the repository
|
// redirect to the repository
|
||||||
redirect(s"/${loginUserName}/${repository.name}")
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -431,4 +459,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
case None => Some("Key is invalid.")
|
case None => Some("Key is invalid.")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def validAccountName: Constraint = new Constraint(){
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
|
getAccountByUserName(value) match {
|
||||||
|
case Some(_) => None
|
||||||
|
case None => Some("Invalid Group/User Account.")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
class AnonymousAccessController extends AnonymousAccessControllerBase
|
||||||
|
|
||||||
|
trait AnonymousAccessControllerBase extends ControllerBase {
|
||||||
|
get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||||
|
if(!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||||
|
!context.currentPath.startsWith("/register")) {
|
||||||
|
Unauthorized()
|
||||||
|
} else {
|
||||||
|
pass()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,16 +1,16 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import _root_.util.Directory._
|
import gitbucket.core.service.{AccountService, SystemSettingsService}
|
||||||
import _root_.util.Implicits._
|
import gitbucket.core.util._
|
||||||
import _root_.util.ControlUtil._
|
import gitbucket.core.util.Implicits._
|
||||||
import _root_.util.{StringUtil, FileUtil, Validations, Keys}
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
|
import gitbucket.core.model.Account
|
||||||
import org.scalatra._
|
import org.scalatra._
|
||||||
import org.scalatra.json._
|
import org.scalatra.json._
|
||||||
import org.json4s._
|
import org.json4s._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import model._
|
|
||||||
import service.{SystemSettingsService, AccountService}
|
|
||||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||||
import javax.servlet.{FilterChain, ServletResponse, ServletRequest}
|
import javax.servlet.{FilterChain, ServletResponse, ServletRequest}
|
||||||
import org.scalatra.i18n._
|
import org.scalatra.i18n._
|
||||||
@@ -24,8 +24,9 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
|
|
||||||
implicit val jsonFormats = DefaultFormats
|
implicit val jsonFormats = DefaultFormats
|
||||||
|
|
||||||
// Don't set content type via Accept header.
|
// TODO Scala 2.11
|
||||||
override def format(implicit request: HttpServletRequest) = ""
|
// // Don't set content type via Accept header.
|
||||||
|
// override def format(implicit request: HttpServletRequest) = ""
|
||||||
|
|
||||||
override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain): Unit = try {
|
override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain): Unit = try {
|
||||||
val httpRequest = request.asInstanceOf[HttpServletRequest]
|
val httpRequest = request.asInstanceOf[HttpServletRequest]
|
||||||
@@ -103,10 +104,10 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
if(request.hasAttribute(Keys.Request.Ajax)){
|
if(request.hasAttribute(Keys.Request.Ajax)){
|
||||||
org.scalatra.NotFound()
|
org.scalatra.NotFound()
|
||||||
} else {
|
} else {
|
||||||
org.scalatra.NotFound(html.error("Not Found"))
|
org.scalatra.NotFound(gitbucket.core.html.error("Not Found"))
|
||||||
}
|
}
|
||||||
|
|
||||||
protected def Unauthorized()(implicit context: app.Context) =
|
protected def Unauthorized()(implicit context: Context) =
|
||||||
if(request.hasAttribute(Keys.Request.Ajax)){
|
if(request.hasAttribute(Keys.Request.Ajax)){
|
||||||
org.scalatra.Unauthorized()
|
org.scalatra.Unauthorized()
|
||||||
} else {
|
} else {
|
||||||
@@ -125,12 +126,26 @@ abstract class ControllerBase extends ScalatraFilter
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override def fullUrl(path: String, params: Iterable[(String, Any)] = Iterable.empty,
|
// TODO Scala 2.11
|
||||||
includeContextPath: Boolean = true, includeServletPath: Boolean = true)
|
override def url(path: String, params: Iterable[(String, Any)] = Iterable.empty,
|
||||||
(implicit request: HttpServletRequest, response: HttpServletResponse) =
|
includeContextPath: Boolean = true, includeServletPath: Boolean = true,
|
||||||
|
absolutize: Boolean = true, withSessionId: Boolean = true)
|
||||||
|
(implicit request: HttpServletRequest, response: HttpServletResponse): String =
|
||||||
if (path.startsWith("http")) path
|
if (path.startsWith("http")) path
|
||||||
else baseUrl + url(path, params, false, false, false)
|
else baseUrl + super.url(path, params, false, false, false)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Use this method to response the raw data against XSS.
|
||||||
|
*/
|
||||||
|
protected def RawData[T](contentType: String, rawData: T): T = {
|
||||||
|
if(contentType.split(";").head.trim.toLowerCase.startsWith("text/html")){
|
||||||
|
this.contentType = "text/plain"
|
||||||
|
} else {
|
||||||
|
this.contentType = contentType
|
||||||
|
}
|
||||||
|
response.addHeader("X-Content-Type-Options", "nosniff")
|
||||||
|
rawData
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -0,0 +1,138 @@
|
|||||||
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.dashboard.html
|
||||||
|
import gitbucket.core.service.{RepositoryService, PullRequestService, AccountService, IssuesService}
|
||||||
|
import gitbucket.core.util.{StringUtil, Keys, UsersAuthenticator}
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.service.IssuesService._
|
||||||
|
|
||||||
|
class DashboardController extends DashboardControllerBase
|
||||||
|
with IssuesService with PullRequestService with RepositoryService with AccountService
|
||||||
|
with UsersAuthenticator
|
||||||
|
|
||||||
|
trait DashboardControllerBase extends ControllerBase {
|
||||||
|
self: IssuesService with PullRequestService with RepositoryService with AccountService
|
||||||
|
with UsersAuthenticator =>
|
||||||
|
|
||||||
|
get("/dashboard/issues")(usersOnly {
|
||||||
|
val q = request.getParameter("q")
|
||||||
|
val account = context.loginAccount.get
|
||||||
|
Option(q).map { q =>
|
||||||
|
val condition = IssueSearchCondition(q, Map[String, Int]())
|
||||||
|
q match {
|
||||||
|
case q if(q.contains("is:pr")) => redirect(s"/dashboard/pulls?q=${StringUtil.urlEncode(q)}")
|
||||||
|
case q if(q.contains(s"author:${account.userName}")) => redirect(s"/dashboard/issues/created_by${condition.toURL}")
|
||||||
|
case q if(q.contains(s"assignee:${account.userName}")) => redirect(s"/dashboard/issues/assigned${condition.toURL}")
|
||||||
|
case q if(q.contains(s"mentions:${account.userName}")) => redirect(s"/dashboard/issues/mentioned${condition.toURL}")
|
||||||
|
case _ => searchIssues("created_by")
|
||||||
|
}
|
||||||
|
} getOrElse {
|
||||||
|
searchIssues("created_by")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/issues/assigned")(usersOnly {
|
||||||
|
searchIssues("assigned")
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/issues/created_by")(usersOnly {
|
||||||
|
searchIssues("created_by")
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/issues/mentioned")(usersOnly {
|
||||||
|
searchIssues("mentioned")
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/pulls")(usersOnly {
|
||||||
|
val q = request.getParameter("q")
|
||||||
|
val account = context.loginAccount.get
|
||||||
|
Option(q).map { q =>
|
||||||
|
val condition = IssueSearchCondition(q, Map[String, Int]())
|
||||||
|
q match {
|
||||||
|
case q if(q.contains("is:issue")) => redirect(s"/dashboard/issues?q=${StringUtil.urlEncode(q)}")
|
||||||
|
case q if(q.contains(s"author:${account.userName}")) => redirect(s"/dashboard/pulls/created_by${condition.toURL}")
|
||||||
|
case q if(q.contains(s"assignee:${account.userName}")) => redirect(s"/dashboard/pulls/assigned${condition.toURL}")
|
||||||
|
case q if(q.contains(s"mentions:${account.userName}")) => redirect(s"/dashboard/pulls/mentioned${condition.toURL}")
|
||||||
|
case _ => searchPullRequests("created_by")
|
||||||
|
}
|
||||||
|
} getOrElse {
|
||||||
|
searchPullRequests("created_by")
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/pulls/created_by")(usersOnly {
|
||||||
|
searchPullRequests("created_by")
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/pulls/assigned")(usersOnly {
|
||||||
|
searchPullRequests("assigned")
|
||||||
|
})
|
||||||
|
|
||||||
|
get("/dashboard/pulls/mentioned")(usersOnly {
|
||||||
|
searchPullRequests("mentioned")
|
||||||
|
})
|
||||||
|
|
||||||
|
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
||||||
|
val condition = session.putAndGet(key, if(request.hasQueryString){
|
||||||
|
val q = request.getParameter("q")
|
||||||
|
if(q == null){
|
||||||
|
IssueSearchCondition(request)
|
||||||
|
} else {
|
||||||
|
IssueSearchCondition(q, Map[String, Int]())
|
||||||
|
}
|
||||||
|
} else session.getAs[IssueSearchCondition](key).getOrElse(IssueSearchCondition()))
|
||||||
|
|
||||||
|
filter match {
|
||||||
|
case "assigned" => condition.copy(assigned = Some(userName), author = None , mentioned = None)
|
||||||
|
case "mentioned" => condition.copy(assigned = None , author = None , mentioned = Some(userName))
|
||||||
|
case _ => condition.copy(assigned = None , author = Some(userName), mentioned = None)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private def searchIssues(filter: String) = {
|
||||||
|
import IssuesService._
|
||||||
|
|
||||||
|
val userName = context.loginAccount.get.userName
|
||||||
|
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
||||||
|
val userRepos = getUserRepositories(userName, context.baseUrl, true).map(repo => repo.owner -> repo.name)
|
||||||
|
val page = IssueSearchCondition.page(request)
|
||||||
|
|
||||||
|
html.issues(
|
||||||
|
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, userRepos: _*),
|
||||||
|
page,
|
||||||
|
countIssue(condition.copy(state = "open" ), false, userRepos: _*),
|
||||||
|
countIssue(condition.copy(state = "closed"), false, userRepos: _*),
|
||||||
|
filter match {
|
||||||
|
case "assigned" => condition.copy(assigned = Some(userName))
|
||||||
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
|
case _ => condition.copy(author = Some(userName))
|
||||||
|
},
|
||||||
|
filter,
|
||||||
|
getGroupNames(userName))
|
||||||
|
}
|
||||||
|
|
||||||
|
private def searchPullRequests(filter: String) = {
|
||||||
|
import IssuesService._
|
||||||
|
import PullRequestService._
|
||||||
|
|
||||||
|
val userName = context.loginAccount.get.userName
|
||||||
|
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
||||||
|
val allRepos = getAllRepositories(userName)
|
||||||
|
val page = IssueSearchCondition.page(request)
|
||||||
|
|
||||||
|
html.pulls(
|
||||||
|
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, allRepos: _*),
|
||||||
|
page,
|
||||||
|
countIssue(condition.copy(state = "open" ), true, allRepos: _*),
|
||||||
|
countIssue(condition.copy(state = "closed"), true, allRepos: _*),
|
||||||
|
filter match {
|
||||||
|
case "assigned" => condition.copy(assigned = Some(userName))
|
||||||
|
case "mentioned" => condition.copy(mentioned = Some(userName))
|
||||||
|
case _ => condition.copy(author = Some(userName))
|
||||||
|
},
|
||||||
|
filter,
|
||||||
|
getGroupNames(userName))
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import util.{Keys, FileUtil}
|
import gitbucket.core.util.{Keys, FileUtil}
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import org.scalatra._
|
import org.scalatra._
|
||||||
import org.scalatra.servlet.{MultipartConfig, FileUploadSupport, FileItem}
|
import org.scalatra.servlet.{MultipartConfig, FileUploadSupport, FileItem}
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
@@ -1,8 +1,11 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import util._
|
import gitbucket.core.html
|
||||||
import util.Implicits._
|
import gitbucket.core.helper.xml
|
||||||
import service._
|
import gitbucket.core.model.Account
|
||||||
|
import gitbucket.core.service.{RepositoryService, ActivityService, AccountService}
|
||||||
|
import gitbucket.core.util.{LDAPUtil, Keys, UsersAuthenticator}
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class IndexController extends IndexControllerBase
|
class IndexController extends IndexControllerBase
|
||||||
@@ -20,11 +23,23 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/"){
|
get("/"){
|
||||||
val loginAccount = context.loginAccount
|
val loginAccount = context.loginAccount
|
||||||
|
if(loginAccount.isEmpty) {
|
||||||
|
html.index(getRecentActivities(),
|
||||||
|
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
||||||
|
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
val loginUserName = loginAccount.get.userName
|
||||||
|
val loginUserGroups = getGroupsByUserName(loginUserName)
|
||||||
|
var visibleOwnerSet : Set[String] = Set(loginUserName)
|
||||||
|
|
||||||
|
visibleOwnerSet ++= loginUserGroups
|
||||||
|
|
||||||
html.index(getRecentActivities(),
|
html.index(getRecentActivitiesByOwners(visibleOwnerSet),
|
||||||
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
getVisibleRepositories(loginAccount, context.baseUrl, withoutPhysicalInfo = true),
|
||||||
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
loginAccount.map{ account => getUserRepositories(account.userName, context.baseUrl, withoutPhysicalInfo = true) }.getOrElse(Nil)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
get("/signin"){
|
get("/signin"){
|
||||||
@@ -49,16 +64,20 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/activities.atom"){
|
get("/activities.atom"){
|
||||||
contentType = "application/atom+xml; type=feed"
|
contentType = "application/atom+xml; type=feed"
|
||||||
helper.xml.feed(getRecentActivities())
|
xml.feed(getRecentActivities())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set account information into HttpSession and redirect.
|
* Set account information into HttpSession and redirect.
|
||||||
*/
|
*/
|
||||||
private def signin(account: model.Account) = {
|
private def signin(account: Account) = {
|
||||||
session.setAttribute(Keys.Session.LoginAccount, account)
|
session.setAttribute(Keys.Session.LoginAccount, account)
|
||||||
updateLastLoginDate(account.userName)
|
updateLastLoginDate(account.userName)
|
||||||
|
|
||||||
|
if(LDAPUtil.isDummyMailAddress(account)) {
|
||||||
|
redirect("/" + account.userName + "/_edit")
|
||||||
|
}
|
||||||
|
|
||||||
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
|
flash.get(Keys.Flash.Redirect).asInstanceOf[Option[String]].map { redirectUrl =>
|
||||||
if(redirectUrl.stripSuffix("/") == request.getContextPath){
|
if(redirectUrl.stripSuffix("/") == request.getContextPath){
|
||||||
redirect("/")
|
redirect("/")
|
||||||
@@ -72,8 +91,6 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* JSON API for collaborator completion.
|
* JSON API for collaborator completion.
|
||||||
*
|
|
||||||
* TODO Move to other controller?
|
|
||||||
*/
|
*/
|
||||||
get("/_user/proposals")(usersOnly {
|
get("/_user/proposals")(usersOnly {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -82,5 +99,11 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* JSON APU for checking user existence.
|
||||||
|
*/
|
||||||
|
post("/_user/existence")(usersOnly {
|
||||||
|
getAccountByUserName(params("userName")).isDefined
|
||||||
|
})
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,17 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.issues.html
|
||||||
|
import gitbucket.core.model.Issue
|
||||||
|
import gitbucket.core.service._
|
||||||
|
import gitbucket.core.util._
|
||||||
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.view
|
||||||
|
import gitbucket.core.view.Markdown
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
import service._
|
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
import util._
|
|
||||||
import util.Implicits._
|
|
||||||
import util.ControlUtil._
|
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
import model.Issue
|
|
||||||
|
|
||||||
class IssuesController extends IssuesControllerBase
|
class IssuesController extends IssuesControllerBase
|
||||||
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
|
with IssuesService with RepositoryService with AccountService with LabelsService with MilestonesService with ActivityService
|
||||||
@@ -20,7 +23,6 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
case class IssueCreateForm(title: String, content: Option[String],
|
case class IssueCreateForm(title: String, content: Option[String],
|
||||||
assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String])
|
assignedUserName: Option[String], milestoneId: Option[Int], labelNames: Option[String])
|
||||||
case class IssueEditForm(title: String, content: Option[String])
|
|
||||||
case class CommentForm(issueId: Int, content: String)
|
case class CommentForm(issueId: Int, content: String)
|
||||||
case class IssueStateForm(issueId: Int, content: Option[String])
|
case class IssueStateForm(issueId: Int, content: Option[String])
|
||||||
|
|
||||||
@@ -32,10 +34,12 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
"labelNames" -> trim(optional(text()))
|
"labelNames" -> trim(optional(text()))
|
||||||
)(IssueCreateForm.apply)
|
)(IssueCreateForm.apply)
|
||||||
|
|
||||||
|
val issueTitleEditForm = mapping(
|
||||||
|
"title" -> trim(label("Title", text(required)))
|
||||||
|
)(x => x)
|
||||||
val issueEditForm = mapping(
|
val issueEditForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required))),
|
"content" -> trim(optional(text()))
|
||||||
"content" -> trim(optional(text()))
|
)(x => x)
|
||||||
)(IssueEditForm.apply)
|
|
||||||
|
|
||||||
val commentForm = mapping(
|
val commentForm = mapping(
|
||||||
"issueId" -> label("Issue Id", number()),
|
"issueId" -> label("Issue Id", number()),
|
||||||
@@ -47,22 +51,19 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
"content" -> trim(optional(text()))
|
"content" -> trim(optional(text()))
|
||||||
)(IssueStateForm.apply)
|
)(IssueStateForm.apply)
|
||||||
|
|
||||||
get("/:owner/:repository/issues")(referrersOnly {
|
get("/:owner/:repository/issues")(referrersOnly { repository =>
|
||||||
searchIssues("all", _)
|
val q = request.getParameter("q")
|
||||||
})
|
if(Option(q).exists(_.contains("is:pr"))){
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/pulls?q=" + StringUtil.urlEncode(q))
|
||||||
get("/:owner/:repository/issues/assigned/:userName")(referrersOnly {
|
} else {
|
||||||
searchIssues("assigned", _)
|
searchIssues(repository)
|
||||||
})
|
}
|
||||||
|
|
||||||
get("/:owner/:repository/issues/created_by/:userName")(referrersOnly {
|
|
||||||
searchIssues("created_by", _)
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
||||||
defining(repository.owner, repository.name, params("id")){ case (owner, name, issueId) =>
|
defining(repository.owner, repository.name, params("id")){ case (owner, name, issueId) =>
|
||||||
getIssue(owner, name, issueId) map {
|
getIssue(owner, name, issueId) map {
|
||||||
issues.html.issue(
|
html.issue(
|
||||||
_,
|
_,
|
||||||
getComments(owner, name, issueId.toInt),
|
getComments(owner, name, issueId.toInt),
|
||||||
getIssueLabels(owner, name, issueId.toInt),
|
getIssueLabels(owner, name, issueId.toInt),
|
||||||
@@ -77,7 +78,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
||||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
issues.html.create(
|
html.create(
|
||||||
(getCollaborators(owner, name) ::: (if(getAccountByUserName(owner).get.isGroupAccount) Nil else List(owner))).sorted,
|
(getCollaborators(owner, name) ::: (if(getAccountByUserName(owner).get.isGroupAccount) Nil else List(owner))).sorted,
|
||||||
getMilestones(owner, name),
|
getMilestones(owner, name),
|
||||||
getLabels(owner, name),
|
getLabels(owner, name),
|
||||||
@@ -125,14 +126,29 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
||||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
getIssue(owner, name, params("id")).map { issue =>
|
getIssue(owner, name, params("id")).map { issue =>
|
||||||
if(isEditable(owner, name, issue.openedUserName)){
|
if(isEditable(owner, name, issue.openedUserName)){
|
||||||
// update issue
|
// update issue
|
||||||
updateIssue(owner, name, issue.issueId, form.title, form.content)
|
updateIssue(owner, name, issue.issueId, title, issue.content)
|
||||||
// extract references and create refer comment
|
// extract references and create refer comment
|
||||||
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""))
|
createReferComment(owner, name, issue.copy(title = title), title)
|
||||||
|
|
||||||
|
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||||
|
} else Unauthorized
|
||||||
|
} getOrElse NotFound
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||||
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
|
getIssue(owner, name, params("id")).map { issue =>
|
||||||
|
if(isEditable(owner, name, issue.openedUserName)){
|
||||||
|
// update issue
|
||||||
|
updateIssue(owner, name, issue.issueId, issue.title, content)
|
||||||
|
// extract references and create refer comment
|
||||||
|
createReferComment(owner, name, issue, content.getOrElse(""))
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized
|
} else Unauthorized
|
||||||
@@ -179,14 +195,14 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
getIssue(repository.owner, repository.name, params("id")) map { x =>
|
getIssue(repository.owner, repository.name, params("id")) map { x =>
|
||||||
if(isEditable(x.userName, x.repositoryName, x.openedUserName)){
|
if(isEditable(x.userName, x.repositoryName, x.openedUserName)){
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => issues.html.editissue(
|
case t if t == "html" => html.editissue(
|
||||||
x.title, x.content, x.issueId, x.userName, x.repositoryName)
|
x.content, x.issueId, x.userName, x.repositoryName)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
org.json4s.jackson.Serialization.write(
|
org.json4s.jackson.Serialization.write(
|
||||||
Map("title" -> x.title,
|
Map("title" -> x.title,
|
||||||
"content" -> view.Markdown.toHtml(x.content getOrElse "No description given.",
|
"content" -> Markdown.toHtml(x.content getOrElse "No description given.",
|
||||||
repository, false, true)
|
repository, false, true, true, isEditable(x.userName, x.repositoryName, x.openedUserName))
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else Unauthorized
|
} else Unauthorized
|
||||||
@@ -197,13 +213,13 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
getComment(repository.owner, repository.name, params("id")) map { x =>
|
getComment(repository.owner, repository.name, params("id")) map { x =>
|
||||||
if(isEditable(x.userName, x.repositoryName, x.commentedUserName)){
|
if(isEditable(x.userName, x.repositoryName, x.commentedUserName)){
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => issues.html.editcomment(
|
case t if t == "html" => html.editcomment(
|
||||||
x.content, x.commentId, x.userName, x.repositoryName)
|
x.content, x.commentId, x.userName, x.repositoryName)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
org.json4s.jackson.Serialization.write(
|
org.json4s.jackson.Serialization.write(
|
||||||
Map("content" -> view.Markdown.toHtml(x.content,
|
Map("content" -> view.Markdown.toHtml(x.content,
|
||||||
repository, false, true)
|
repository, false, true, true, isEditable(x.userName, x.repositoryName, x.commentedUserName))
|
||||||
))
|
))
|
||||||
}
|
}
|
||||||
} else Unauthorized
|
} else Unauthorized
|
||||||
@@ -213,14 +229,14 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
ajaxPost("/:owner/:repository/issues/:id/label/new")(collaboratorsOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/new")(collaboratorsOnly { repository =>
|
||||||
defining(params("id").toInt){ issueId =>
|
defining(params("id").toInt){ issueId =>
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt)
|
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt)
|
||||||
issues.html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/delete")(collaboratorsOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/delete")(collaboratorsOnly { repository =>
|
||||||
defining(params("id").toInt){ issueId =>
|
defining(params("id").toInt){ issueId =>
|
||||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt)
|
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt)
|
||||||
issues.html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -234,15 +250,17 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
milestoneId("milestoneId").map { milestoneId =>
|
milestoneId("milestoneId").map { milestoneId =>
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
getMilestonesWithIssueCount(repository.owner, repository.name)
|
||||||
.find(_._1.milestoneId == milestoneId).map { case (_, openCount, closeCount) =>
|
.find(_._1.milestoneId == milestoneId).map { case (_, openCount, closeCount) =>
|
||||||
issues.milestones.html.progress(openCount + closeCount, closeCount, false)
|
gitbucket.core.issues.milestones.html.progress(openCount + closeCount, closeCount)
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
} getOrElse Ok()
|
} getOrElse Ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/state")(collaboratorsOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/state")(collaboratorsOnly { repository =>
|
||||||
defining(params.get("value")){ action =>
|
defining(params.get("value")){ action =>
|
||||||
executeBatch(repository) {
|
action match {
|
||||||
handleComment(_, None, repository)( _ => action)
|
case Some("open") => executeBatch(repository) { handleComment(_, None, repository)( _ => Some("reopen")) }
|
||||||
|
case Some("close") => executeBatch(repository) { handleComment(_, None, repository)( _ => Some("close")) }
|
||||||
|
case _ => // TODO BadRequest
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -277,8 +295,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
(Directory.getAttachedDir(repository.owner, repository.name) match {
|
||||||
case dir if(dir.exists && dir.isDirectory) =>
|
case dir if(dir.exists && dir.isDirectory) =>
|
||||||
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
dir.listFiles.find(_.getName.startsWith(params("file") + ".")).map { file =>
|
||||||
contentType = FileUtil.getMimeType(file.getName)
|
RawData(FileUtil.getMimeType(file.getName), file)
|
||||||
file
|
|
||||||
}
|
}
|
||||||
case _ => None
|
case _ => None
|
||||||
}) getOrElse NotFound
|
}) getOrElse NotFound
|
||||||
@@ -287,12 +304,15 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
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)
|
||||||
|
|
||||||
private def isEditable(owner: String, repository: String, author: String)(implicit context: app.Context): Boolean =
|
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
||||||
hasWritePermission(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasWritePermission(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
|
|
||||||
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit) = {
|
private def executeBatch(repository: RepositoryService.RepositoryInfo)(execute: Int => Unit) = {
|
||||||
params("checked").split(',') map(_.toInt) foreach execute
|
params("checked").split(',') map(_.toInt) foreach execute
|
||||||
redirect(s"/${repository.owner}/${repository.name}/issues")
|
params("from") match {
|
||||||
|
case "issues" => redirect(s"/${repository.owner}/${repository.name}/issues")
|
||||||
|
case "pulls" => redirect(s"/${repository.owner}/${repository.name}/pulls")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String) = {
|
private def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String) = {
|
||||||
@@ -308,35 +328,34 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
* @see [[https://github.com/takezoe/gitbucket/wiki/CommentAction]]
|
* @see [[https://github.com/takezoe/gitbucket/wiki/CommentAction]]
|
||||||
*/
|
*/
|
||||||
private def handleComment(issueId: Int, content: Option[String], repository: RepositoryService.RepositoryInfo)
|
private def handleComment(issueId: Int, content: Option[String], repository: RepositoryService.RepositoryInfo)
|
||||||
(getAction: model.Issue => Option[String] =
|
(getAction: Issue => Option[String] =
|
||||||
p1 => params.get("action").filter(_ => isEditable(p1.userName, p1.repositoryName, p1.openedUserName))) = {
|
p1 => params.get("action").filter(_ => isEditable(p1.userName, p1.repositoryName, p1.openedUserName))) = {
|
||||||
|
|
||||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
val userName = context.loginAccount.get.userName
|
val userName = context.loginAccount.get.userName
|
||||||
|
|
||||||
getIssue(owner, name, issueId.toString) map { issue =>
|
getIssue(owner, name, issueId.toString) flatMap { issue =>
|
||||||
val (action, recordActivity) =
|
val (action, recordActivity) =
|
||||||
getAction(issue)
|
getAction(issue)
|
||||||
.collect {
|
.collect {
|
||||||
case "close" => true -> (Some("close") ->
|
case "close" if(!issue.closed) => true ->
|
||||||
Some(if(issue.isPullRequest) recordClosePullRequestActivity _ else recordCloseIssueActivity _))
|
(Some("close") -> Some(if(issue.isPullRequest) recordClosePullRequestActivity _ else recordCloseIssueActivity _))
|
||||||
case "reopen" => false -> (Some("reopen") ->
|
case "reopen" if(issue.closed) => false ->
|
||||||
Some(recordReopenIssueActivity _))
|
(Some("reopen") -> Some(recordReopenIssueActivity _))
|
||||||
}
|
}
|
||||||
.map { case (closed, t) =>
|
.map { case (closed, t) =>
|
||||||
updateClosed(owner, name, issueId, closed)
|
updateClosed(owner, name, issueId, closed)
|
||||||
t
|
t
|
||||||
}
|
}
|
||||||
.getOrElse(None -> None)
|
.getOrElse(None -> None)
|
||||||
|
|
||||||
val commentId = content
|
val commentId = (content, action) match {
|
||||||
.map ( _ -> action.map( _ + "_comment" ).getOrElse("comment") )
|
case (None, None) => None
|
||||||
.getOrElse ( action.get.capitalize -> action.get )
|
case (None, Some(action)) => Some(createComment(owner, name, userName, issueId, action.capitalize, action))
|
||||||
match {
|
case (Some(content), _) => Some(createComment(owner, name, userName, issueId, content, action.map(_+ "_comment").getOrElse("comment")))
|
||||||
case (content, action) => createComment(owner, name, userName, issueId, content, action)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// record activity
|
// record comment activity if comment is entered
|
||||||
content foreach {
|
content foreach {
|
||||||
(if(issue.isPullRequest) recordCommentPullRequestActivity _ else recordCommentIssueActivity _)
|
(if(issue.isPullRequest) recordCommentPullRequestActivity _ else recordCommentIssueActivity _)
|
||||||
(owner, name, userName, issueId, _)
|
(owner, name, userName, issueId, _)
|
||||||
@@ -354,7 +373,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
content foreach {
|
content foreach {
|
||||||
f.toNotify(repository, issueId, _){
|
f.toNotify(repository, issueId, _){
|
||||||
Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${
|
Notifier.msgComment(s"${context.baseUrl}/${owner}/${name}/${
|
||||||
if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId}")
|
if(issue.isPullRequest) "pull" else "issues"}/${issueId}#comment-${commentId.get}")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
action foreach {
|
action foreach {
|
||||||
@@ -364,37 +383,38 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
issue -> commentId
|
commentId.map( issue -> _ )
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(filter: String, repository: RepositoryService.RepositoryInfo) = {
|
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
||||||
defining(repository.owner, repository.name){ case (owner, repoName) =>
|
defining(repository.owner, repository.name){ case (owner, repoName) =>
|
||||||
val filterUser = Map(filter -> params.getOrElse("userName", ""))
|
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val sessionKey = Keys.Session.Issues(owner, repoName)
|
val sessionKey = Keys.Session.Issues(owner, repoName)
|
||||||
|
|
||||||
// retrieve search condition
|
// retrieve search condition
|
||||||
val condition = session.putAndGet(sessionKey,
|
val condition = session.putAndGet(sessionKey,
|
||||||
if(request.hasQueryString) IssueSearchCondition(request)
|
if(request.hasQueryString){
|
||||||
else session.getAs[IssueSearchCondition](sessionKey).getOrElse(IssueSearchCondition())
|
val q = request.getParameter("q")
|
||||||
|
if(q == null || q.trim.isEmpty){
|
||||||
|
IssueSearchCondition(request)
|
||||||
|
} else {
|
||||||
|
IssueSearchCondition(q, getMilestones(owner, repoName).map(x => (x.title, x.milestoneId)).toMap)
|
||||||
|
}
|
||||||
|
} else session.getAs[IssueSearchCondition](sessionKey).getOrElse(IssueSearchCondition())
|
||||||
)
|
)
|
||||||
|
|
||||||
issues.html.list(
|
html.list(
|
||||||
searchIssue(condition, filterUser, false, (page - 1) * IssueLimit, IssueLimit, owner -> repoName),
|
"issues",
|
||||||
|
searchIssue(condition, false, (page - 1) * IssueLimit, IssueLimit, owner -> repoName),
|
||||||
page,
|
page,
|
||||||
(getCollaborators(owner, repoName) :+ owner).sorted,
|
(getCollaborators(owner, repoName) :+ owner).sorted,
|
||||||
getMilestones(owner, repoName),
|
getMilestones(owner, repoName),
|
||||||
getLabels(owner, repoName),
|
getLabels(owner, repoName),
|
||||||
countIssue(condition.copy(state = "open"), filterUser, false, owner -> repoName),
|
countIssue(condition.copy(state = "open" ), false, owner -> repoName),
|
||||||
countIssue(condition.copy(state = "closed"), filterUser, false, owner -> repoName),
|
countIssue(condition.copy(state = "closed"), false, owner -> repoName),
|
||||||
countIssue(condition, Map.empty, false, owner -> repoName),
|
|
||||||
context.loginAccount.map(x => countIssue(condition, Map("assigned" -> x.userName), false, owner -> repoName)),
|
|
||||||
context.loginAccount.map(x => countIssue(condition, Map("created_by" -> x.userName), false, owner -> repoName)),
|
|
||||||
countIssueGroupByLabels(owner, repoName, condition, filterUser),
|
|
||||||
condition,
|
condition,
|
||||||
filter,
|
|
||||||
repository,
|
repository,
|
||||||
hasWritePermission(owner, repoName, context.loginAccount))
|
hasWritePermission(owner, repoName, context.loginAccount))
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.issues.labels.html
|
||||||
|
import gitbucket.core.service.{RepositoryService, AccountService, IssuesService, LabelsService}
|
||||||
|
import gitbucket.core.util.{ReferrerAuthenticator, CollaboratorsAuthenticator}
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
import org.scalatra.i18n.Messages
|
||||||
|
import org.scalatra.Ok
|
||||||
|
|
||||||
|
class LabelsController extends LabelsControllerBase
|
||||||
|
with LabelsService with IssuesService with RepositoryService with AccountService
|
||||||
|
with ReferrerAuthenticator with CollaboratorsAuthenticator
|
||||||
|
|
||||||
|
trait LabelsControllerBase extends ControllerBase {
|
||||||
|
self: LabelsService with IssuesService with RepositoryService
|
||||||
|
with ReferrerAuthenticator with CollaboratorsAuthenticator =>
|
||||||
|
|
||||||
|
case class LabelForm(labelName: String, color: String)
|
||||||
|
|
||||||
|
val labelForm = mapping(
|
||||||
|
"labelName" -> trim(label("Label name", text(required, labelName, maxlength(100)))),
|
||||||
|
"labelColor" -> trim(label("Color", text(required, color)))
|
||||||
|
)(LabelForm.apply)
|
||||||
|
|
||||||
|
get("/:owner/:repository/issues/labels")(referrersOnly { repository =>
|
||||||
|
html.list(
|
||||||
|
getLabels(repository.owner, repository.name),
|
||||||
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||||
|
repository,
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/issues/labels/new")(collaboratorsOnly { repository =>
|
||||||
|
html.edit(None, repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/labels/new", labelForm)(collaboratorsOnly { (form, repository) =>
|
||||||
|
val labelId = createLabel(repository.owner, repository.name, form.labelName, form.color.substring(1))
|
||||||
|
html.label(
|
||||||
|
getLabel(repository.owner, repository.name, labelId).get,
|
||||||
|
// TODO futility
|
||||||
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||||
|
repository,
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/issues/labels/:labelId/edit")(collaboratorsOnly { repository =>
|
||||||
|
getLabel(repository.owner, repository.name, params("labelId").toInt).map { label =>
|
||||||
|
html.edit(Some(label), repository)
|
||||||
|
} getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/labels/:labelId/edit", labelForm)(collaboratorsOnly { (form, repository) =>
|
||||||
|
updateLabel(repository.owner, repository.name, params("labelId").toInt, form.labelName, form.color.substring(1))
|
||||||
|
html.label(
|
||||||
|
getLabel(repository.owner, repository.name, params("labelId").toInt).get,
|
||||||
|
// TODO futility
|
||||||
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
||||||
|
repository,
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/labels/:labelId/delete")(collaboratorsOnly { repository =>
|
||||||
|
deleteLabel(repository.owner, repository.name, params("labelId").toInt)
|
||||||
|
Ok()
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constraint for the identifier such as user name, repository name or page name.
|
||||||
|
*/
|
||||||
|
private def labelName: Constraint = new Constraint(){
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
|
if(value.contains(',')){
|
||||||
|
Some(s"${name} contains invalid character.")
|
||||||
|
} else if(value.startsWith("_") || value.startsWith("-")){
|
||||||
|
Some(s"${name} starts with invalid character.")
|
||||||
|
} else {
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,11 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.issues.milestones.html
|
||||||
|
import gitbucket.core.service.{RepositoryService, MilestonesService, AccountService}
|
||||||
|
import gitbucket.core.util.{ReferrerAuthenticator, CollaboratorsAuthenticator}
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
import service._
|
|
||||||
import util.{CollaboratorsAuthenticator, ReferrerAuthenticator}
|
|
||||||
import util.Implicits._
|
|
||||||
|
|
||||||
class MilestonesController extends MilestonesControllerBase
|
class MilestonesController extends MilestonesControllerBase
|
||||||
with MilestonesService with RepositoryService with AccountService
|
with MilestonesService with RepositoryService with AccountService
|
||||||
with ReferrerAuthenticator with CollaboratorsAuthenticator
|
with ReferrerAuthenticator with CollaboratorsAuthenticator
|
||||||
@@ -23,7 +23,7 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
)(MilestoneForm.apply)
|
)(MilestoneForm.apply)
|
||||||
|
|
||||||
get("/:owner/:repository/issues/milestones")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/milestones")(referrersOnly { repository =>
|
||||||
issues.milestones.html.list(
|
html.list(
|
||||||
params.getOrElse("state", "open"),
|
params.getOrElse("state", "open"),
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name),
|
getMilestonesWithIssueCount(repository.owner, repository.name),
|
||||||
repository,
|
repository,
|
||||||
@@ -31,7 +31,7 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/milestones/new")(collaboratorsOnly {
|
get("/:owner/:repository/issues/milestones/new")(collaboratorsOnly {
|
||||||
issues.milestones.html.edit(None, _)
|
html.edit(None, _)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/milestones/new", milestoneForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/issues/milestones/new", milestoneForm)(collaboratorsOnly { (form, repository) =>
|
||||||
@@ -41,7 +41,7 @@ trait MilestonesControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/issues/milestones/:milestoneId/edit")(collaboratorsOnly { repository =>
|
get("/:owner/:repository/issues/milestones/:milestoneId/edit")(collaboratorsOnly { repository =>
|
||||||
params("milestoneId").toIntOpt.map{ milestoneId =>
|
params("milestoneId").toIntOpt.map{ milestoneId =>
|
||||||
issues.milestones.html.edit(getMilestone(repository.owner, repository.name, milestoneId), repository)
|
html.edit(getMilestone(repository.owner, repository.name, milestoneId), repository)
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1,31 +1,34 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import util.{LockUtil, CollaboratorsAuthenticator, JGitUtil, ReferrerAuthenticator, Notifier, Keys}
|
import gitbucket.core.pulls.html
|
||||||
import util.Directory._
|
import gitbucket.core.util._
|
||||||
import util.Implicits._
|
import gitbucket.core.util.JGitUtil._
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import service._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
|
import gitbucket.core.view
|
||||||
|
import gitbucket.core.view.helpers
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.eclipse.jgit.transport.RefSpec
|
import org.eclipse.jgit.transport.RefSpec
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import org.eclipse.jgit.lib.{ObjectId, CommitBuilder, PersonIdent}
|
import org.eclipse.jgit.lib.{ObjectId, CommitBuilder, PersonIdent}
|
||||||
import service.IssuesService._
|
import gitbucket.core.service._
|
||||||
import service.PullRequestService._
|
import gitbucket.core.service.IssuesService._
|
||||||
import util.JGitUtil.DiffInfo
|
import gitbucket.core.service.PullRequestService._
|
||||||
import util.JGitUtil.CommitInfo
|
import gitbucket.core.service.WebHookService.WebHookPayload
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import org.eclipse.jgit.merge.MergeStrategy
|
import org.eclipse.jgit.merge.MergeStrategy
|
||||||
import org.eclipse.jgit.errors.NoMergeBaseException
|
import org.eclipse.jgit.errors.NoMergeBaseException
|
||||||
import service.WebHookService.WebHookPayload
|
|
||||||
|
|
||||||
class PullRequestsController extends PullRequestsControllerBase
|
class PullRequestsController extends PullRequestsControllerBase
|
||||||
with RepositoryService with AccountService with IssuesService with PullRequestService with MilestonesService with LabelsService
|
with RepositoryService with AccountService with IssuesService with PullRequestService with MilestonesService with LabelsService
|
||||||
with ActivityService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator
|
with CommitsService with ActivityService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator
|
||||||
|
|
||||||
trait PullRequestsControllerBase extends ControllerBase {
|
trait PullRequestsControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with AccountService with IssuesService with MilestonesService with LabelsService
|
self: RepositoryService with AccountService with IssuesService with MilestonesService with LabelsService
|
||||||
with ActivityService with PullRequestService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator =>
|
with CommitsService with ActivityService with PullRequestService with WebHookService with ReferrerAuthenticator with CollaboratorsAuthenticator =>
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[PullRequestsControllerBase])
|
private val logger = LoggerFactory.getLogger(classOf[PullRequestsControllerBase])
|
||||||
|
|
||||||
@@ -59,11 +62,12 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
case class MergeForm(message: String)
|
case class MergeForm(message: String)
|
||||||
|
|
||||||
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
get("/:owner/:repository/pulls")(referrersOnly { repository =>
|
||||||
searchPullRequests(None, repository)
|
val q = request.getParameter("q")
|
||||||
})
|
if(Option(q).exists(_.contains("is:issue"))){
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/issues?q=" + StringUtil.urlEncode(q))
|
||||||
get("/:owner/:repository/pulls/:userName")(referrersOnly { repository =>
|
} else {
|
||||||
searchPullRequests(Some(params("userName")), repository)
|
searchPullRequests(None, repository)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
||||||
@@ -75,9 +79,10 @@ 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)
|
||||||
|
|
||||||
pulls.html.pullreq(
|
html.pullreq(
|
||||||
issue, pullreq,
|
issue, pullreq,
|
||||||
getComments(owner, name, issueId),
|
(commits.flatten.map(commit => getCommitComments(owner, name, commit.id, true)).flatten.toList ::: getComments(owner, name, issueId))
|
||||||
|
.sortWith((a, b) => a.registeredDate before b.registeredDate),
|
||||||
getIssueLabels(owner, name, issueId),
|
getIssueLabels(owner, name, issueId),
|
||||||
(getCollaborators(owner, name) ::: (if(getAccountByUserName(owner).get.isGroupAccount) Nil else List(owner))).sorted,
|
(getCollaborators(owner, name) ::: (if(getAccountByUserName(owner).get.isGroupAccount) Nil else List(owner))).sorted,
|
||||||
getMilestonesWithIssueCount(owner, name),
|
getMilestonesWithIssueCount(owner, name),
|
||||||
@@ -96,7 +101,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val owner = repository.owner
|
val owner = repository.owner
|
||||||
val name = repository.name
|
val name = repository.name
|
||||||
getPullRequest(owner, name, issueId) map { case(issue, pullreq) =>
|
getPullRequest(owner, name, issueId) map { case(issue, pullreq) =>
|
||||||
pulls.html.mergeguide(
|
html.mergeguide(
|
||||||
checkConflictInPullRequest(owner, name, pullreq.branch, pullreq.requestUserName, name, pullreq.requestBranch, issueId),
|
checkConflictInPullRequest(owner, name, pullreq.branch, pullreq.requestUserName, name, pullreq.requestBranch, issueId),
|
||||||
pullreq,
|
pullreq,
|
||||||
s"${context.baseUrl}/git/${pullreq.requestUserName}/${pullreq.requestRepositoryName}.git")
|
s"${context.baseUrl}/git/${pullreq.requestUserName}/${pullreq.requestRepositoryName}.git")
|
||||||
@@ -156,7 +161,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val personIdent = new PersonIdent(loginAccount.fullName, loginAccount.mailAddress)
|
val personIdent = new PersonIdent(loginAccount.fullName, loginAccount.mailAddress)
|
||||||
mergeCommit.setAuthor(personIdent)
|
mergeCommit.setAuthor(personIdent)
|
||||||
mergeCommit.setCommitter(personIdent)
|
mergeCommit.setCommitter(personIdent)
|
||||||
mergeCommit.setMessage(s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestRepositoryName}\n\n" +
|
mergeCommit.setMessage(s"Merge pull request #${issueId} from ${pullreq.requestUserName}/${pullreq.requestBranch}\n\n" +
|
||||||
form.message)
|
form.message)
|
||||||
|
|
||||||
// insertObject and got mergeCommit Object Id
|
// insertObject and got mergeCommit Object Id
|
||||||
@@ -239,8 +244,8 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/compare/*...*")(referrersOnly { forkedRepository =>
|
get("/:owner/:repository/compare/*...*")(referrersOnly { forkedRepository =>
|
||||||
val Seq(origin, forked) = multiParams("splat")
|
val Seq(origin, forked) = multiParams("splat")
|
||||||
val (originOwner, tmpOriginBranch) = parseCompareIdentifie(origin, forkedRepository.owner)
|
val (originOwner, originId) = parseCompareIdentifie(origin, forkedRepository.owner)
|
||||||
val (forkedOwner, tmpForkedBranch) = parseCompareIdentifie(forked, forkedRepository.owner)
|
val (forkedOwner, forkedId) = parseCompareIdentifie(forked, forkedRepository.owner)
|
||||||
|
|
||||||
(for(
|
(for(
|
||||||
originRepositoryName <- if(originOwner == forkedOwner){
|
originRepositoryName <- if(originOwner == forkedOwner){
|
||||||
@@ -256,29 +261,33 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
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))
|
||||||
){ case (oldGit, newGit) =>
|
){ case (oldGit, newGit) =>
|
||||||
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
val (oldId, newId) =
|
||||||
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
if(originRepository.branchList.contains(originId) && forkedRepository.branchList.contains(forkedId)){
|
||||||
|
// Branch name
|
||||||
|
val rootId = JGitUtil.getForkedCommitId(oldGit, newGit,
|
||||||
|
originRepository.owner, originRepository.name, originId,
|
||||||
|
forkedRepository.owner, forkedRepository.name, forkedId)
|
||||||
|
|
||||||
val forkedId = JGitUtil.getForkedCommitId(oldGit, newGit,
|
(oldGit.getRepository.resolve(rootId), newGit.getRepository.resolve(forkedId))
|
||||||
originRepository.owner, originRepository.name, originBranch,
|
} else {
|
||||||
forkedRepository.owner, forkedRepository.name, forkedBranch)
|
// Commit id
|
||||||
|
(oldGit.getRepository.resolve(originId), newGit.getRepository.resolve(forkedId))
|
||||||
val oldId = oldGit.getRepository.resolve(forkedId)
|
}
|
||||||
val newId = newGit.getRepository.resolve(forkedBranch)
|
|
||||||
|
|
||||||
val (commits, diffs) = getRequestCompareInfo(
|
val (commits, diffs) = getRequestCompareInfo(
|
||||||
originRepository.owner, originRepository.name, oldId.getName,
|
originRepository.owner, originRepository.name, oldId.getName,
|
||||||
forkedRepository.owner, forkedRepository.name, newId.getName)
|
forkedRepository.owner, forkedRepository.name, newId.getName)
|
||||||
|
|
||||||
pulls.html.compare(
|
html.compare(
|
||||||
commits,
|
commits,
|
||||||
diffs,
|
diffs,
|
||||||
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
||||||
case (Some(userName), Some(repositoryName)) => (userName, repositoryName) :: getForkedRepositories(userName, repositoryName)
|
case (Some(userName), Some(repositoryName)) => (userName, repositoryName) :: getForkedRepositories(userName, repositoryName)
|
||||||
case _ => (forkedRepository.owner, forkedRepository.name) :: getForkedRepositories(forkedRepository.owner, forkedRepository.name)
|
case _ => (forkedRepository.owner, forkedRepository.name) :: getForkedRepositories(forkedRepository.owner, forkedRepository.name)
|
||||||
},
|
},
|
||||||
originBranch,
|
commits.flatten.map(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false)).flatten.toList,
|
||||||
forkedBranch,
|
originId,
|
||||||
|
forkedId,
|
||||||
oldId.getName,
|
oldId.getName,
|
||||||
newId.getName,
|
newId.getName,
|
||||||
forkedRepository,
|
forkedRepository,
|
||||||
@@ -311,7 +320,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
val originBranch = JGitUtil.getDefaultBranch(oldGit, originRepository, tmpOriginBranch).get._2
|
||||||
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
val forkedBranch = JGitUtil.getDefaultBranch(newGit, forkedRepository, tmpForkedBranch).get._2
|
||||||
|
|
||||||
pulls.html.mergecheck(
|
html.mergecheck(
|
||||||
checkConflict(originRepository.owner, originRepository.name, originBranch,
|
checkConflict(originRepository.owner, originRepository.name, originBranch,
|
||||||
forkedRepository.owner, forkedRepository.name, forkedBranch))
|
forkedRepository.owner, forkedRepository.name, forkedBranch))
|
||||||
}
|
}
|
||||||
@@ -443,7 +452,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
val commits = newGit.log.addRange(oldId, newId).call.iterator.asScala.map { revCommit =>
|
val commits = newGit.log.addRange(oldId, newId).call.iterator.asScala.map { revCommit =>
|
||||||
new CommitInfo(revCommit)
|
new CommitInfo(revCommit)
|
||||||
}.toList.splitWith { (commit1, commit2) =>
|
}.toList.splitWith { (commit1, commit2) =>
|
||||||
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
|
helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
||||||
}
|
}
|
||||||
|
|
||||||
val diffs = JGitUtil.getDiffs(newGit, oldId.getName, newId.getName, true)
|
val diffs = JGitUtil.getDiffs(newGit, oldId.getName, newId.getName, true)
|
||||||
@@ -453,7 +462,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) =
|
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) =
|
||||||
defining(repository.owner, repository.name){ case (owner, repoName) =>
|
defining(repository.owner, repository.name){ case (owner, repoName) =>
|
||||||
val filterUser = userName.map { x => Map("created_by" -> x) } getOrElse Map("all" -> "")
|
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
val sessionKey = Keys.Session.Pulls(owner, repoName)
|
val sessionKey = Keys.Session.Pulls(owner, repoName)
|
||||||
|
|
||||||
@@ -463,14 +471,15 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
else session.getAs[IssueSearchCondition](sessionKey).getOrElse(IssueSearchCondition())
|
else session.getAs[IssueSearchCondition](sessionKey).getOrElse(IssueSearchCondition())
|
||||||
)
|
)
|
||||||
|
|
||||||
pulls.html.list(
|
gitbucket.core.issues.html.list(
|
||||||
searchIssue(condition, filterUser, true, (page - 1) * PullRequestLimit, PullRequestLimit, owner -> repoName),
|
"pulls",
|
||||||
getPullRequestCountGroupByUser(condition.state == "closed", Some(owner), Some(repoName)),
|
searchIssue(condition, true, (page - 1) * PullRequestLimit, PullRequestLimit, owner -> repoName),
|
||||||
userName,
|
|
||||||
page,
|
page,
|
||||||
countIssue(condition.copy(state = "open" ), filterUser, true, owner -> repoName),
|
(getCollaborators(owner, repoName) :+ owner).sorted,
|
||||||
countIssue(condition.copy(state = "closed"), filterUser, true, owner -> repoName),
|
getMilestones(owner, repoName),
|
||||||
countIssue(condition, Map.empty, true, owner -> repoName),
|
getLabels(owner, repoName),
|
||||||
|
countIssue(condition.copy(state = "open" ), true, owner -> repoName),
|
||||||
|
countIssue(condition.copy(state = "closed"), true, owner -> repoName),
|
||||||
condition,
|
condition,
|
||||||
repository,
|
repository,
|
||||||
hasWritePermission(owner, repoName, context.loginAccount))
|
hasWritePermission(owner, repoName, context.loginAccount))
|
||||||
@@ -1,18 +1,19 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import service._
|
import gitbucket.core.settings.html
|
||||||
import util.Directory._
|
import gitbucket.core.model.WebHook
|
||||||
import util.ControlUtil._
|
import gitbucket.core.service.{RepositoryService, AccountService, WebHookService}
|
||||||
import util.Implicits._
|
import gitbucket.core.service.WebHookService.WebHookPayload
|
||||||
import util.{LockUtil, UsersAuthenticator, OwnerAuthenticator}
|
import gitbucket.core.util._
|
||||||
import util.JGitUtil.CommitInfo
|
import gitbucket.core.util.JGitUtil._
|
||||||
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import service.WebHookService.WebHookPayload
|
|
||||||
import util.JGitUtil.CommitInfo
|
|
||||||
import util.ControlUtil._
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.eclipse.jgit.lib.Constants
|
||||||
|
|
||||||
class RepositorySettingsController extends RepositorySettingsControllerBase
|
class RepositorySettingsController extends RepositorySettingsControllerBase
|
||||||
with RepositoryService with AccountService with WebHookService
|
with RepositoryService with AccountService with WebHookService
|
||||||
@@ -64,18 +65,19 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the Options page.
|
* Display the Options page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/options")(ownerOnly {
|
get("/:owner/:repository/settings/options")(ownerOnly {
|
||||||
settings.html.options(_, flash.get("info"))
|
html.options(_, flash.get("info"))
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save the repository options.
|
* Save the repository options.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/options", optionsForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/options", optionsForm)(ownerOnly { (form, repository) =>
|
||||||
|
val defaultBranch = if(repository.branchList.isEmpty) "master" else form.defaultBranch
|
||||||
saveRepositoryOptions(
|
saveRepositoryOptions(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
form.description,
|
form.description,
|
||||||
if(repository.branchList.isEmpty) "master" else form.defaultBranch,
|
defaultBranch,
|
||||||
repository.repository.parentUserName.map { _ =>
|
repository.repository.parentUserName.map { _ =>
|
||||||
repository.repository.isPrivate
|
repository.repository.isPrivate
|
||||||
} getOrElse form.isPrivate
|
} getOrElse form.isPrivate
|
||||||
@@ -93,6 +95,10 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
FileUtils.moveDirectory(dir, getWikiRepositoryDir(repository.owner, form.repositoryName))
|
FileUtils.moveDirectory(dir, getWikiRepositoryDir(repository.owner, form.repositoryName))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Change repository HEAD
|
||||||
|
using(Git.open(getRepositoryDir(repository.owner, form.repositoryName))) { git =>
|
||||||
|
git.getRepository.updateRef(Constants.HEAD, true).link(Constants.R_HEADS + defaultBranch)
|
||||||
|
}
|
||||||
flash += "info" -> "Repository settings has been updated."
|
flash += "info" -> "Repository settings has been updated."
|
||||||
redirect(s"/${repository.owner}/${form.repositoryName}/settings/options")
|
redirect(s"/${repository.owner}/${form.repositoryName}/settings/options")
|
||||||
})
|
})
|
||||||
@@ -101,7 +107,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the Collaborators page.
|
* Display the Collaborators page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/collaborators")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/collaborators")(ownerOnly { repository =>
|
||||||
settings.html.collaborators(
|
html.collaborators(
|
||||||
getCollaborators(repository.owner, repository.name),
|
getCollaborators(repository.owner, repository.name),
|
||||||
getAccountByUserName(repository.owner).get.isGroupAccount,
|
getAccountByUserName(repository.owner).get.isGroupAccount,
|
||||||
repository)
|
repository)
|
||||||
@@ -131,7 +137,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the web hook page.
|
* Display the web hook page.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks")(ownerOnly { repository =>
|
get("/:owner/:repository/settings/hooks")(ownerOnly { repository =>
|
||||||
settings.html.hooks(getWebHookURLs(repository.owner, repository.name), repository, flash.get("info"))
|
html.hooks(getWebHookURLs(repository.owner, repository.name), flash.get("url"), repository, flash.get("info"))
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,7 +159,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* Send the test request to registered web hook URLs.
|
* Send the test request to registered web hook URLs.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/hooks/test")(ownerOnly { repository =>
|
post("/:owner/:repository/settings/hooks/test", webHookForm)(ownerOnly { (form, repository) =>
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
val commits = git.log
|
val commits = git.log
|
||||||
@@ -161,15 +167,13 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
.setMaxCount(3)
|
.setMaxCount(3)
|
||||||
.call.iterator.asScala.map(new CommitInfo(_))
|
.call.iterator.asScala.map(new CommitInfo(_))
|
||||||
|
|
||||||
getWebHookURLs(repository.owner, repository.name) match {
|
getAccountByUserName(repository.owner).foreach { ownerAccount =>
|
||||||
case webHookURLs if(webHookURLs.nonEmpty) =>
|
callWebHook(repository.owner, repository.name,
|
||||||
for(ownerAccount <- getAccountByUserName(repository.owner)){
|
List(WebHook(repository.owner, repository.name, form.url)),
|
||||||
callWebHook(repository.owner, repository.name, webHookURLs,
|
WebHookPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount)
|
||||||
WebHookPayload(git, ownerAccount, "refs/heads/" + repository.repository.defaultBranch, repository, commits.toList, ownerAccount))
|
)
|
||||||
}
|
|
||||||
case _ =>
|
|
||||||
}
|
}
|
||||||
|
flash += "url" -> form.url
|
||||||
flash += "info" -> "Test payload deployed!"
|
flash += "info" -> "Test payload deployed!"
|
||||||
}
|
}
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
redirect(s"/${repository.owner}/${repository.name}/settings/hooks")
|
||||||
@@ -179,7 +183,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Display the danger zone.
|
* Display the danger zone.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/settings/danger")(ownerOnly {
|
get("/:owner/:repository/settings/danger")(ownerOnly {
|
||||||
settings.html.danger(_)
|
html.danger(_)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1,30 +1,42 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import _root_.util.JGitUtil.CommitInfo
|
import gitbucket.core.repo.html
|
||||||
import util.Directory._
|
import gitbucket.core.helper
|
||||||
import util.Implicits._
|
import gitbucket.core.service._
|
||||||
import _root_.util.ControlUtil._
|
import gitbucket.core.util._
|
||||||
import _root_.util._
|
import gitbucket.core.util.JGitUtil._
|
||||||
import service._
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
|
import gitbucket.core.model.Account
|
||||||
|
import gitbucket.core.service.WebHookService.WebHookPayload
|
||||||
|
import gitbucket.core.view
|
||||||
|
import gitbucket.core.view.helpers
|
||||||
import org.scalatra._
|
import org.scalatra._
|
||||||
import java.io.File
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.{ArchiveCommand, Git}
|
||||||
|
import org.eclipse.jgit.archive.{TgzFormat, ZipFormat}
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.lib._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.eclipse.jgit.treewalk._
|
import org.eclipse.jgit.treewalk._
|
||||||
import java.util.zip.{ZipEntry, ZipOutputStream}
|
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.eclipse.jgit.dircache.DirCache
|
import org.eclipse.jgit.dircache.DirCache
|
||||||
import org.eclipse.jgit.revwalk.{RevCommit, RevWalk}
|
import org.eclipse.jgit.revwalk.RevCommit
|
||||||
|
|
||||||
class RepositoryViewerController extends RepositoryViewerControllerBase
|
class RepositoryViewerController extends RepositoryViewerControllerBase
|
||||||
with RepositoryService with AccountService with ActivityService with ReferrerAuthenticator with CollaboratorsAuthenticator
|
with RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
||||||
|
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The repository viewer.
|
* The repository viewer.
|
||||||
*/
|
*/
|
||||||
trait RepositoryViewerControllerBase extends ControllerBase {
|
trait RepositoryViewerControllerBase extends ControllerBase {
|
||||||
self: RepositoryService with AccountService with ActivityService with ReferrerAuthenticator with CollaboratorsAuthenticator =>
|
self: RepositoryService with AccountService with ActivityService with IssuesService with WebHookService with CommitsService
|
||||||
|
with ReadableUsersAuthenticator with ReferrerAuthenticator with CollaboratorsAuthenticator with PullRequestService =>
|
||||||
|
|
||||||
|
ArchiveCommand.registerFormat("zip", new ZipFormat)
|
||||||
|
ArchiveCommand.registerFormat("tar.gz", new TgzFormat)
|
||||||
|
|
||||||
case class EditorForm(
|
case class EditorForm(
|
||||||
branch: String,
|
branch: String,
|
||||||
@@ -32,6 +44,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
content: String,
|
content: String,
|
||||||
message: Option[String],
|
message: Option[String],
|
||||||
charset: String,
|
charset: String,
|
||||||
|
lineSeparator: String,
|
||||||
newFileName: String,
|
newFileName: String,
|
||||||
oldFileName: Option[String]
|
oldFileName: Option[String]
|
||||||
)
|
)
|
||||||
@@ -43,14 +56,23 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
fileName: String
|
fileName: String
|
||||||
)
|
)
|
||||||
|
|
||||||
|
case class CommentForm(
|
||||||
|
fileName: Option[String],
|
||||||
|
oldLineNumber: Option[Int],
|
||||||
|
newLineNumber: Option[Int],
|
||||||
|
content: String,
|
||||||
|
issueId: Option[Int]
|
||||||
|
)
|
||||||
|
|
||||||
val editorForm = mapping(
|
val editorForm = mapping(
|
||||||
"branch" -> trim(label("Branch", text(required))),
|
"branch" -> trim(label("Branch", text(required))),
|
||||||
"path" -> trim(label("Path", text())),
|
"path" -> trim(label("Path", text())),
|
||||||
"content" -> trim(label("Content", text(required))),
|
"content" -> trim(label("Content", text(required))),
|
||||||
"message" -> trim(label("Message", optional(text()))),
|
"message" -> trim(label("Message", optional(text()))),
|
||||||
"charset" -> trim(label("Charset", text(required))),
|
"charset" -> trim(label("Charset", text(required))),
|
||||||
"newFileName" -> trim(label("Filename", text(required))),
|
"lineSeparator" -> trim(label("Line Separator", text(required))),
|
||||||
"oldFileName" -> trim(label("Old filename", optional(text())))
|
"newFileName" -> trim(label("Filename", text(required))),
|
||||||
|
"oldFileName" -> trim(label("Old filename", optional(text())))
|
||||||
)(EditorForm.apply)
|
)(EditorForm.apply)
|
||||||
|
|
||||||
val deleteForm = mapping(
|
val deleteForm = mapping(
|
||||||
@@ -60,14 +82,24 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
"fileName" -> trim(label("Filename", text(required)))
|
"fileName" -> trim(label("Filename", text(required)))
|
||||||
)(DeleteForm.apply)
|
)(DeleteForm.apply)
|
||||||
|
|
||||||
|
val commentForm = mapping(
|
||||||
|
"fileName" -> trim(label("Filename", optional(text()))),
|
||||||
|
"oldLineNumber" -> trim(label("Old line number", optional(number()))),
|
||||||
|
"newLineNumber" -> trim(label("New line number", optional(number()))),
|
||||||
|
"content" -> trim(label("Content", text(required))),
|
||||||
|
"issueId" -> trim(label("Issue Id", optional(number())))
|
||||||
|
)(CommentForm.apply)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns converted HTML from Markdown for preview.
|
* Returns converted HTML from Markdown for preview.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/_preview")(referrersOnly { repository =>
|
post("/:owner/:repository/_preview")(referrersOnly { repository =>
|
||||||
contentType = "text/html"
|
contentType = "text/html"
|
||||||
view.helpers.markdown(params("content"), repository,
|
helpers.markdown(params("content"), repository,
|
||||||
params("enableWikiLink").toBoolean,
|
params("enableWikiLink").toBoolean,
|
||||||
params("enableRefsLink").toBoolean)
|
params("enableRefsLink").toBoolean,
|
||||||
|
params("enableTaskList").toBoolean,
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -99,10 +131,10 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
JGitUtil.getCommitLog(git, branchName, page, 30, path) match {
|
||||||
case Right((logs, hasNext)) =>
|
case Right((logs, hasNext)) =>
|
||||||
repo.html.commits(if(path.isEmpty) Nil else path.split("/").toList, branchName, repository,
|
html.commits(if(path.isEmpty) Nil else path.split("/").toList, branchName, repository,
|
||||||
logs.splitWith{ (commit1, commit2) =>
|
logs.splitWith{ (commit1, commit2) =>
|
||||||
view.helpers.date(commit1.time) == view.helpers.date(commit2.time)
|
view.helpers.date(commit1.commitTime) == view.helpers.date(commit2.commitTime)
|
||||||
}, page, hasNext)
|
}, page, hasNext, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
case Left(_) => NotFound
|
case Left(_) => NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,7 +142,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
||||||
val (branch, path) = splitPath(repository, multiParams("splat").head)
|
val (branch, path) = splitPath(repository, multiParams("splat").head)
|
||||||
repo.html.editor(branch, repository, if(path.length == 0) Nil else path.split("/").toList,
|
html.editor(branch, repository, if(path.length == 0) Nil else path.split("/").toList,
|
||||||
None, JGitUtil.ContentInfo("text", None, Some("UTF-8")))
|
None, JGitUtil.ContentInfo("text", None, Some("UTF-8")))
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -122,7 +154,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
val paths = path.split("/")
|
val paths = path.split("/")
|
||||||
repo.html.editor(branch, repository, paths.take(paths.size - 1).toList, Some(paths.last),
|
html.editor(branch, repository, paths.take(paths.size - 1).toList, Some(paths.last),
|
||||||
JGitUtil.getContentInfo(git, path, objectId))
|
JGitUtil.getContentInfo(git, path, objectId))
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
@@ -135,14 +167,15 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
val paths = path.split("/")
|
val paths = path.split("/")
|
||||||
repo.html.delete(branch, repository, paths.take(paths.size - 1).toList, paths.last,
|
html.delete(branch, repository, paths.take(paths.size - 1).toList, paths.last,
|
||||||
JGitUtil.getContentInfo(git, path, objectId))
|
JGitUtil.getContentInfo(git, path, objectId))
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/create", editorForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/create", editorForm)(collaboratorsOnly { (form, repository) =>
|
||||||
commitFile(repository, form.branch, form.path, Some(form.newFileName), None, form.content, form.charset,
|
commitFile(repository, form.branch, form.path, Some(form.newFileName), None,
|
||||||
|
StringUtil.convertLineSeparator(form.content, form.lineSeparator), form.charset,
|
||||||
form.message.getOrElse(s"Create ${form.newFileName}"))
|
form.message.getOrElse(s"Create ${form.newFileName}"))
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/blob/${form.branch}/${
|
redirect(s"/${repository.owner}/${repository.name}/blob/${form.branch}/${
|
||||||
@@ -151,7 +184,8 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/update", editorForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/update", editorForm)(collaboratorsOnly { (form, repository) =>
|
||||||
commitFile(repository, form.branch, form.path, Some(form.newFileName), form.oldFileName, form.content, form.charset,
|
commitFile(repository, form.branch, form.path, Some(form.newFileName), form.oldFileName,
|
||||||
|
StringUtil.convertLineSeparator(form.content, form.lineSeparator), form.charset,
|
||||||
if(form.oldFileName.exists(_ == form.newFileName)){
|
if(form.oldFileName.exists(_ == form.newFileName)){
|
||||||
form.message.getOrElse(s"Update ${form.newFileName}")
|
form.message.getOrElse(s"Update ${form.newFileName}")
|
||||||
} else {
|
} else {
|
||||||
@@ -179,16 +213,16 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(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))
|
||||||
|
val lastModifiedCommit = JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||||
if(raw){
|
if(raw){
|
||||||
// Download
|
// Download
|
||||||
defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
defining(JGitUtil.getContentFromId(git, objectId, false).get){ bytes =>
|
||||||
contentType = FileUtil.getContentType(path, bytes)
|
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||||
bytes
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
repo.html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
html.blob(id, repository, path.split("/").toList, JGitUtil.getContentInfo(git, path, objectId),
|
||||||
new JGitUtil.CommitInfo(revCommit), hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
new JGitUtil.CommitInfo(lastModifiedCommit), hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
@@ -203,26 +237,117 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))){ revCommit =>
|
defining(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))){ revCommit =>
|
||||||
JGitUtil.getDiffs(git, id) match { case (diffs, oldCommitId) =>
|
JGitUtil.getDiffs(git, id) match { case (diffs, oldCommitId) =>
|
||||||
repo.html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
html.commit(id, new JGitUtil.CommitInfo(revCommit),
|
||||||
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
JGitUtil.getBranchesOfCommit(git, revCommit.getName),
|
||||||
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
JGitUtil.getTagsOfCommit(git, revCommit.getName),
|
||||||
repository, diffs, oldCommitId)
|
getCommitComments(repository.owner, repository.name, id, false),
|
||||||
|
repository, diffs, oldCommitId, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
val id = params("id")
|
||||||
|
createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName, form.content,
|
||||||
|
form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId.isDefined)
|
||||||
|
form.issueId match {
|
||||||
|
case Some(issueId) => recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content)
|
||||||
|
case None => recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content)
|
||||||
|
}
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/commit/${id}")
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/commit/:id/comment/_form")(readableUsersOnly { repository =>
|
||||||
|
val id = params("id")
|
||||||
|
val fileName = params.get("fileName")
|
||||||
|
val oldLineNumber = params.get("oldLineNumber") map (_.toInt)
|
||||||
|
val newLineNumber = params.get("newLineNumber") map (_.toInt)
|
||||||
|
val issueId = params.get("issueId") map (_.toInt)
|
||||||
|
html.commentform(
|
||||||
|
commitId = id,
|
||||||
|
fileName, oldLineNumber, newLineNumber, issueId,
|
||||||
|
hasWritePermission = hasWritePermission(repository.owner, repository.name, context.loginAccount),
|
||||||
|
repository = repository
|
||||||
|
)
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
val id = params("id")
|
||||||
|
val commentId = createCommitComment(repository.owner, repository.name, id, context.loginAccount.get.userName,
|
||||||
|
form.content, form.fileName, form.oldLineNumber, form.newLineNumber, form.issueId.isDefined)
|
||||||
|
form.issueId match {
|
||||||
|
case Some(issueId) => recordCommentPullRequestActivity(repository.owner, repository.name, context.loginAccount.get.userName, issueId, form.content)
|
||||||
|
case None => recordCommentCommitActivity(repository.owner, repository.name, context.loginAccount.get.userName, id, form.content)
|
||||||
|
}
|
||||||
|
helper.html.commitcomment(getCommitComment(repository.owner, repository.name, commentId.toString).get,
|
||||||
|
hasWritePermission(repository.owner, repository.name, context.loginAccount), repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
|
getCommitComment(repository.owner, repository.name, params("id")) map { x =>
|
||||||
|
if(isEditable(x.userName, x.repositoryName, x.commentedUserName)){
|
||||||
|
params.get("dataType") collect {
|
||||||
|
case t if t == "html" => html.editcomment(
|
||||||
|
x.content, x.commentId, x.userName, x.repositoryName)
|
||||||
|
} getOrElse {
|
||||||
|
contentType = formats("json")
|
||||||
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map("content" -> view.Markdown.toHtml(x.content,
|
||||||
|
repository, false, true, true, isEditable(x.userName, x.repositoryName, x.commentedUserName))
|
||||||
|
))
|
||||||
|
}
|
||||||
|
} else Unauthorized
|
||||||
|
} getOrElse NotFound
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/commit_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
|
getCommitComment(owner, name, params("id")).map { comment =>
|
||||||
|
if(isEditable(owner, name, comment.commentedUserName)){
|
||||||
|
updateCommitComment(comment.commentId, form.content)
|
||||||
|
redirect(s"/${owner}/${name}/commit_comments/_data/${comment.commentId}")
|
||||||
|
} else Unauthorized
|
||||||
|
} getOrElse NotFound
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/commit_comments/delete/:id")(readableUsersOnly { repository =>
|
||||||
|
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||||
|
getCommitComment(owner, name, params("id")).map { comment =>
|
||||||
|
if(isEditable(owner, name, comment.commentedUserName)){
|
||||||
|
Ok(deleteCommitComment(comment.commentId))
|
||||||
|
} else Unauthorized
|
||||||
|
} getOrElse NotFound
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Displays branches.
|
* Displays branches.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
get("/:owner/:repository/branches")(referrersOnly { repository =>
|
||||||
|
val branches = JGitUtil.getBranches(repository.owner, repository.name, repository.repository.defaultBranch)
|
||||||
|
.sortBy(br => (br.mergeInfo.isEmpty, br.commitTime))
|
||||||
|
.map(br => br -> getPullRequestByRequestCommit(repository.owner, repository.name, repository.repository.defaultBranch, br.name, br.commitId))
|
||||||
|
.reverse
|
||||||
|
html.branches(branches, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates a branch.
|
||||||
|
*/
|
||||||
|
post("/:owner/:repository/branches")(collaboratorsOnly { repository =>
|
||||||
|
val newBranchName = params.getOrElse("new", halt(400))
|
||||||
|
val fromBranchName = params.getOrElse("from", halt(400))
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
// retrieve latest update date of each branch
|
JGitUtil.createBranch(git, fromBranchName, newBranchName)
|
||||||
val branchInfo = repository.branchList.map { branchName =>
|
} match {
|
||||||
val revCommit = git.log.add(git.getRepository.resolve(branchName)).setMaxCount(1).call.iterator.next
|
case Right(message) =>
|
||||||
(branchName, revCommit.getCommitterIdent.getWhen)
|
flash += "info" -> message
|
||||||
}
|
redirect(s"/${repository.owner}/${repository.name}/tree/${StringUtil.urlEncode(newBranchName).replace("%2F", "/")}")
|
||||||
repo.html.branches(branchInfo, hasWritePermission(repository.owner, repository.name, context.loginAccount), repository)
|
case Left(message) =>
|
||||||
|
flash += "error" -> message
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -245,62 +370,24 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
* Displays tags.
|
* Displays tags.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/tags")(referrersOnly {
|
get("/:owner/:repository/tags")(referrersOnly {
|
||||||
repo.html.tags(_)
|
html.tags(_)
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Download repository contents as an archive.
|
* Download repository contents as an archive.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/archive/*")(referrersOnly { repository =>
|
get("/:owner/:repository/archive/*")(referrersOnly { repository =>
|
||||||
val name = multiParams("splat").head
|
multiParams("splat").head match {
|
||||||
|
case name if name.endsWith(".zip") =>
|
||||||
if(name.endsWith(".zip")){
|
archiveRepository(name, ".zip", repository)
|
||||||
val revision = name.stripSuffix(".zip")
|
case name if name.endsWith(".tar.gz") =>
|
||||||
val workDir = getDownloadWorkDir(repository.owner, repository.name, session.getId)
|
archiveRepository(name, ".tar.gz", repository)
|
||||||
if(workDir.exists){
|
case _ => BadRequest
|
||||||
FileUtils.deleteDirectory(workDir)
|
|
||||||
}
|
|
||||||
workDir.mkdirs
|
|
||||||
|
|
||||||
val zipFile = new File(workDir, repository.name + "-" +
|
|
||||||
(if(revision.length == 40) revision.substring(0, 10) else revision).replace('/', '_') + ".zip")
|
|
||||||
|
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
|
||||||
using(new TreeWalk(git.getRepository)){ walk =>
|
|
||||||
val reader = walk.getObjectReader
|
|
||||||
val objectId = new MutableObjectId
|
|
||||||
|
|
||||||
using(new ZipOutputStream(new java.io.FileOutputStream(zipFile))){ out =>
|
|
||||||
walk.addTree(revCommit.getTree)
|
|
||||||
walk.setRecursive(true)
|
|
||||||
|
|
||||||
while(walk.next){
|
|
||||||
val name = walk.getPathString
|
|
||||||
val mode = walk.getFileMode(0)
|
|
||||||
if(mode == FileMode.REGULAR_FILE || mode == FileMode.EXECUTABLE_FILE){
|
|
||||||
walk.getObjectId(objectId, 0)
|
|
||||||
val entry = new ZipEntry(name)
|
|
||||||
val loader = reader.open(objectId)
|
|
||||||
entry.setSize(loader.getSize)
|
|
||||||
out.putNextEntry(entry)
|
|
||||||
loader.copyTo(out)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
contentType = "application/octet-stream"
|
|
||||||
response.setHeader("Content-Disposition", s"attachment; filename=${zipFile.getName}")
|
|
||||||
zipFile
|
|
||||||
} else {
|
|
||||||
BadRequest
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/network/members")(referrersOnly { repository =>
|
get("/:owner/:repository/network/members")(referrersOnly { repository =>
|
||||||
repo.html.forked(
|
html.forked(
|
||||||
getRepository(
|
getRepository(
|
||||||
repository.repository.originUserName.getOrElse(repository.owner),
|
repository.repository.originUserName.getOrElse(repository.owner),
|
||||||
repository.repository.originRepositoryName.getOrElse(repository.name),
|
repository.repository.originRepositoryName.getOrElse(repository.name),
|
||||||
@@ -311,7 +398,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repository)
|
repository)
|
||||||
})
|
})
|
||||||
|
|
||||||
private def splitPath(repository: service.RepositoryService.RepositoryInfo, path: String): (String, String) = {
|
private def splitPath(repository: RepositoryService.RepositoryInfo, path: String): (String, String) = {
|
||||||
val id = repository.branchList.collectFirst {
|
val id = repository.branchList.collectFirst {
|
||||||
case branch if(path == branch || path.startsWith(branch + "/")) => branch
|
case branch if(path == branch || path.startsWith(branch + "/")) => branch
|
||||||
} orElse repository.tags.collectFirst {
|
} orElse repository.tags.collectFirst {
|
||||||
@@ -334,13 +421,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
|
private def fileList(repository: RepositoryService.RepositoryInfo, revstr: String = "", path: String = ".") = {
|
||||||
if(repository.commitCount == 0){
|
if(repository.commitCount == 0){
|
||||||
repo.html.guide(repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
html.guide(repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
} else {
|
} else {
|
||||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
//val revisions = Seq(if(revstr.isEmpty) repository.repository.defaultBranch else revstr, repository.branchList.head)
|
|
||||||
// get specified commit
|
// get specified commit
|
||||||
JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) =>
|
JGitUtil.getDefaultBranch(git, repository, revstr).map { case (objectId, revision) =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
||||||
|
val lastModifiedCommit = if(path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
// get files
|
// get files
|
||||||
val files = JGitUtil.getFileList(git, revision, path)
|
val files = JGitUtil.getFileList(git, revision, path)
|
||||||
val parentPath = if (path == ".") Nil else path.split("/").toList
|
val parentPath = if (path == ".") Nil else path.split("/").toList
|
||||||
@@ -353,17 +440,22 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get)
|
Git.open(getRepositoryDir(repository.owner, repository.name)), file.id, true).get)
|
||||||
}
|
}
|
||||||
|
|
||||||
repo.html.files(revision, repository,
|
html.files(revision, repository,
|
||||||
if(path == ".") Nil else path.split("/").toList, // current path
|
if(path == ".") Nil else path.split("/").toList, // current path
|
||||||
new JGitUtil.CommitInfo(revCommit), // latest commit
|
context.loginAccount match {
|
||||||
files, readme, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
case None => List()
|
||||||
|
case account: Option[Account] => getGroupsByUserName(account.get.userName)
|
||||||
|
}, // groups of current user
|
||||||
|
new JGitUtil.CommitInfo(lastModifiedCommit), // last modified commit
|
||||||
|
files, readme, hasWritePermission(repository.owner, repository.name, context.loginAccount),
|
||||||
|
flash.get("info"), flash.get("error"))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def commitFile(repository: service.RepositoryService.RepositoryInfo,
|
private def commitFile(repository: RepositoryService.RepositoryInfo,
|
||||||
branch: String, path: String, newFileName: Option[String], oldFileName: Option[String],
|
branch: String, path: String, newFileName: Option[String], oldFileName: Option[String],
|
||||||
content: String, charset: String, message: String) = {
|
content: String, charset: String, message: String) = {
|
||||||
|
|
||||||
@@ -376,7 +468,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val builder = DirCache.newInCore.builder()
|
val builder = DirCache.newInCore.builder()
|
||||||
val inserter = git.getRepository.newObjectInserter()
|
val inserter = git.getRepository.newObjectInserter()
|
||||||
val headName = s"refs/heads/${branch}"
|
val headName = s"refs/heads/${branch}"
|
||||||
val headTip = git.getRepository.resolve(s"refs/heads/${branch}")
|
val headTip = git.getRepository.resolve(headName)
|
||||||
|
|
||||||
JGitUtil.processTree(git, headTip){ (path, tree) =>
|
JGitUtil.processTree(git, headTip){ (path, tree) =>
|
||||||
if(!newPath.exists(_ == path) && !oldPath.exists(_ == path)){
|
if(!newPath.exists(_ == path) && !oldPath.exists(_ == path)){
|
||||||
@@ -391,7 +483,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
builder.finish()
|
builder.finish()
|
||||||
|
|
||||||
val commitId = JGitUtil.createNewCommit(git, inserter, headTip, builder.getDirCache.writeTree(inserter),
|
val commitId = JGitUtil.createNewCommit(git, inserter, headTip, builder.getDirCache.writeTree(inserter),
|
||||||
loginAccount.fullName, loginAccount.mailAddress, message)
|
headName, loginAccount.fullName, loginAccount.mailAddress, message)
|
||||||
|
|
||||||
inserter.flush()
|
inserter.flush()
|
||||||
inserter.release()
|
inserter.release()
|
||||||
@@ -404,12 +496,26 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
//refUpdate.setRefLogMessage("merged", true)
|
//refUpdate.setRefLogMessage("merged", true)
|
||||||
refUpdate.update()
|
refUpdate.update()
|
||||||
|
|
||||||
|
// update pull request
|
||||||
|
updatePullRequests(repository.owner, repository.name, branch)
|
||||||
|
|
||||||
// record activity
|
// record activity
|
||||||
recordPushActivity(repository.owner, repository.name, loginAccount.userName, branch,
|
recordPushActivity(repository.owner, repository.name, loginAccount.userName, branch,
|
||||||
List(new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))))
|
List(new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))))
|
||||||
|
|
||||||
// TODO invoke hook
|
// close issue by commit message
|
||||||
|
closeIssuesFromMessage(message, loginAccount.userName, repository.owner, repository.name)
|
||||||
|
|
||||||
|
// call web hook
|
||||||
|
val commit = new JGitUtil.CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))
|
||||||
|
getWebHookURLs(repository.owner, repository.name) match {
|
||||||
|
case webHookURLs if(webHookURLs.nonEmpty) =>
|
||||||
|
for(ownerAccount <- getAccountByUserName(repository.owner)){
|
||||||
|
callWebHook(repository.owner, repository.name, webHookURLs,
|
||||||
|
WebHookPayload(git, loginAccount, headName, repository, List(commit), ownerAccount))
|
||||||
|
}
|
||||||
|
case _ =>
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -429,4 +535,34 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def archiveRepository(name: String, suffix: String, repository: RepositoryService.RepositoryInfo): Unit = {
|
||||||
|
val revision = name.stripSuffix(suffix)
|
||||||
|
val workDir = getDownloadWorkDir(repository.owner, repository.name, session.getId)
|
||||||
|
if(workDir.exists) {
|
||||||
|
FileUtils.deleteDirectory(workDir)
|
||||||
|
}
|
||||||
|
workDir.mkdirs
|
||||||
|
|
||||||
|
val filename = repository.name + "-" +
|
||||||
|
(if(revision.length == 40) revision.substring(0, 10) else revision).replace('/', '_') + suffix
|
||||||
|
|
||||||
|
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||||
|
|
||||||
|
contentType = "application/octet-stream"
|
||||||
|
response.setHeader("Content-Disposition", s"attachment; filename=${filename}")
|
||||||
|
response.setBufferSize(1024 * 1024);
|
||||||
|
|
||||||
|
git.archive
|
||||||
|
.setFormat(suffix.tail)
|
||||||
|
.setTree(revCommit.getTree)
|
||||||
|
.setOutputStream(response.getOutputStream)
|
||||||
|
.call()
|
||||||
|
|
||||||
|
Unit
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
||||||
|
hasWritePermission(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||||
}
|
}
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import util._
|
import gitbucket.core.search.html
|
||||||
|
import gitbucket.core.service._
|
||||||
|
import gitbucket.core.util.{StringUtil, ControlUtil, ReferrerAuthenticator, Implicits}
|
||||||
import ControlUtil._
|
import ControlUtil._
|
||||||
import Implicits._
|
import Implicits._
|
||||||
import service._
|
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
class SearchController extends SearchControllerBase
|
class SearchController extends SearchControllerBase
|
||||||
@@ -34,12 +35,12 @@ trait SearchControllerBase extends ControllerBase { self: RepositoryService
|
|||||||
}
|
}
|
||||||
|
|
||||||
target.toLowerCase match {
|
target.toLowerCase match {
|
||||||
case "issue" => search.html.issues(
|
case "issue" => html.issues(
|
||||||
searchIssues(repository.owner, repository.name, query),
|
searchIssues(repository.owner, repository.name, query),
|
||||||
countFiles(repository.owner, repository.name, query),
|
countFiles(repository.owner, repository.name, query),
|
||||||
query, page, repository)
|
query, page, repository)
|
||||||
|
|
||||||
case _ => search.html.code(
|
case _ => html.code(
|
||||||
searchFiles(repository.owner, repository.name, query),
|
searchFiles(repository.owner, repository.name, query),
|
||||||
countIssues(repository.owner, repository.name, query),
|
countIssues(repository.owner, repository.name, query),
|
||||||
query, page, repository)
|
query, page, repository)
|
||||||
@@ -0,0 +1,85 @@
|
|||||||
|
package gitbucket.core.controller
|
||||||
|
|
||||||
|
import gitbucket.core.admin.html
|
||||||
|
import gitbucket.core.service.{AccountService, SystemSettingsService}
|
||||||
|
import gitbucket.core.util.AdminAuthenticator
|
||||||
|
import gitbucket.core.ssh.SshServer
|
||||||
|
import SystemSettingsService._
|
||||||
|
import jp.sf.amateras.scalatra.forms._
|
||||||
|
|
||||||
|
class SystemSettingsController extends SystemSettingsControllerBase
|
||||||
|
with AccountService with AdminAuthenticator
|
||||||
|
|
||||||
|
trait SystemSettingsControllerBase extends ControllerBase {
|
||||||
|
self: AccountService with AdminAuthenticator =>
|
||||||
|
|
||||||
|
private val form = mapping(
|
||||||
|
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
||||||
|
"information" -> trim(label("Information", optional(text()))),
|
||||||
|
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||||
|
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
||||||
|
"isCreateRepoOptionPublic" -> trim(label("Default option to create a new repository", boolean())),
|
||||||
|
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||||
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
|
"ssh" -> trim(label("SSH access", boolean())),
|
||||||
|
"sshPort" -> trim(label("SSH port", optional(number()))),
|
||||||
|
"smtp" -> optionalIfNotChecked("notification", mapping(
|
||||||
|
"host" -> trim(label("SMTP Host", text(required))),
|
||||||
|
"port" -> trim(label("SMTP Port", optional(number()))),
|
||||||
|
"user" -> trim(label("SMTP User", optional(text()))),
|
||||||
|
"password" -> trim(label("SMTP Password", optional(text()))),
|
||||||
|
"ssl" -> trim(label("Enable SSL", optional(boolean()))),
|
||||||
|
"fromAddress" -> trim(label("FROM Address", optional(text()))),
|
||||||
|
"fromName" -> trim(label("FROM Name", optional(text())))
|
||||||
|
)(Smtp.apply)),
|
||||||
|
"ldapAuthentication" -> trim(label("LDAP", boolean())),
|
||||||
|
"ldap" -> optionalIfNotChecked("ldapAuthentication", mapping(
|
||||||
|
"host" -> trim(label("LDAP host", text(required))),
|
||||||
|
"port" -> trim(label("LDAP port", optional(number()))),
|
||||||
|
"bindDN" -> trim(label("Bind DN", optional(text()))),
|
||||||
|
"bindPassword" -> trim(label("Bind Password", optional(text()))),
|
||||||
|
"baseDN" -> trim(label("Base DN", text(required))),
|
||||||
|
"userNameAttribute" -> trim(label("User name attribute", text(required))),
|
||||||
|
"additionalFilterCondition"-> trim(label("Additional filter condition", optional(text()))),
|
||||||
|
"fullNameAttribute" -> trim(label("Full name attribute", optional(text()))),
|
||||||
|
"mailAttribute" -> trim(label("Mail address attribute", optional(text()))),
|
||||||
|
"tls" -> trim(label("Enable TLS", optional(boolean()))),
|
||||||
|
"ssl" -> trim(label("Enable SSL", optional(boolean()))),
|
||||||
|
"keystore" -> trim(label("Keystore", optional(text())))
|
||||||
|
)(Ldap.apply))
|
||||||
|
)(SystemSettings.apply).verifying { settings =>
|
||||||
|
if(settings.ssh && settings.baseUrl.isEmpty){
|
||||||
|
Seq("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
||||||
|
} else Nil
|
||||||
|
}
|
||||||
|
|
||||||
|
private val pluginForm = mapping(
|
||||||
|
"pluginId" -> list(trim(label("", text())))
|
||||||
|
)(PluginForm.apply)
|
||||||
|
|
||||||
|
case class PluginForm(pluginIds: List[String])
|
||||||
|
|
||||||
|
get("/admin/system")(adminOnly {
|
||||||
|
html.system(flash.get("info"))
|
||||||
|
})
|
||||||
|
|
||||||
|
post("/admin/system", form)(adminOnly { form =>
|
||||||
|
saveSystemSettings(form)
|
||||||
|
|
||||||
|
if(form.ssh && SshServer.isActive && context.settings.sshPort != form.sshPort){
|
||||||
|
SshServer.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
if(form.ssh && !SshServer.isActive && form.baseUrl.isDefined){
|
||||||
|
SshServer.start(
|
||||||
|
form.sshPort.getOrElse(SystemSettingsService.DefaultSshPort),
|
||||||
|
form.baseUrl.get)
|
||||||
|
} else if(!form.ssh && SshServer.isActive){
|
||||||
|
SshServer.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
flash += "info" -> "System settings has been updated."
|
||||||
|
redirect("/admin/system")
|
||||||
|
})
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,11 +1,12 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import service._
|
import gitbucket.core.service.{RepositoryService, AccountService}
|
||||||
import util.AdminAuthenticator
|
import gitbucket.core.admin.users.html
|
||||||
import util.StringUtil._
|
import gitbucket.core.util._
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import util.Directory._
|
import gitbucket.core.util.StringUtil._
|
||||||
import util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.scalatra.forms._
|
||||||
import org.scalatra.i18n.Messages
|
import org.scalatra.i18n.Messages
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
@@ -49,7 +50,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||||
"clearImage" -> trim(label("Clear image" ,boolean())),
|
"clearImage" -> trim(label("Clear image" ,boolean())),
|
||||||
"removed" -> trim(label("Disable" ,boolean()))
|
"removed" -> trim(label("Disable" ,boolean(disableByNotYourself("userName"))))
|
||||||
)(EditUserForm.apply)
|
)(EditUserForm.apply)
|
||||||
|
|
||||||
val newGroupForm = mapping(
|
val newGroupForm = mapping(
|
||||||
@@ -75,11 +76,11 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
account.userName -> getGroupMembers(account.userName).map(_.userName)
|
account.userName -> getGroupMembers(account.userName).map(_.userName)
|
||||||
}.toMap
|
}.toMap
|
||||||
|
|
||||||
admin.users.html.list(users, members, includeRemoved)
|
html.list(users, members, includeRemoved)
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/_newuser")(adminOnly {
|
get("/admin/users/_newuser")(adminOnly {
|
||||||
admin.users.html.user(None)
|
html.user(None)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/_newuser", newUserForm)(adminOnly { form =>
|
post("/admin/users/_newuser", newUserForm)(adminOnly { form =>
|
||||||
@@ -90,7 +91,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
get("/admin/users/:userName/_edituser")(adminOnly {
|
get("/admin/users/:userName/_edituser")(adminOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
admin.users.html.user(getAccountByUserName(userName, true))
|
html.user(getAccountByUserName(userName, true))
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
post("/admin/users/:name/_edituser", editUserForm)(adminOnly { form =>
|
||||||
@@ -124,7 +125,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/_newgroup")(adminOnly {
|
get("/admin/users/_newgroup")(adminOnly {
|
||||||
admin.users.html.group(None, Nil)
|
html.group(None, Nil)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/_newgroup", newGroupForm)(adminOnly { form =>
|
post("/admin/users/_newgroup", newGroupForm)(adminOnly { form =>
|
||||||
@@ -140,7 +141,7 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
||||||
defining(params("groupName")){ groupName =>
|
defining(params("groupName")){ groupName =>
|
||||||
admin.users.html.group(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
html.group(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -182,11 +183,6 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
// TODO Move to other generic controller?
|
|
||||||
post("/admin/users/_usercheck"){
|
|
||||||
getAccountByUserName(params("userName")).isDefined
|
|
||||||
}
|
|
||||||
|
|
||||||
private def members: Constraint = new Constraint(){
|
private def members: 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(value.split(",").exists {
|
if(value.split(",").exists {
|
||||||
@@ -195,4 +191,14 @@ trait UserManagementControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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)
|
||||||
|
Some("You can't disable your account yourself")
|
||||||
|
else
|
||||||
|
None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
package app
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import service._
|
import gitbucket.core.wiki.html
|
||||||
import util._
|
import gitbucket.core.service.{RepositoryService, WikiService, ActivityService, AccountService}
|
||||||
import util.Directory._
|
import gitbucket.core.util._
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
import jp.sf.amateras.scalatra.forms._
|
import jp.sf.amateras.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 java.util.ResourceBundle
|
|
||||||
|
|
||||||
class WikiController extends WikiControllerBase
|
class WikiController extends WikiControllerBase
|
||||||
with WikiService with RepositoryService with AccountService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator
|
with WikiService with RepositoryService with AccountService with ActivityService with CollaboratorsAuthenticator with ReferrerAuthenticator
|
||||||
@@ -36,7 +36,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/wiki")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki")(referrersOnly { repository =>
|
||||||
getWikiPage(repository.owner, repository.name, "Home").map { page =>
|
getWikiPage(repository.owner, repository.name, "Home").map { page =>
|
||||||
wiki.html.page("Home", page, getWikiPageList(repository.owner, repository.name),
|
html.page("Home", page, getWikiPageList(repository.owner, repository.name),
|
||||||
repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/Home/_edit")
|
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/Home/_edit")
|
||||||
})
|
})
|
||||||
@@ -45,7 +45,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
|
|
||||||
getWikiPage(repository.owner, repository.name, pageName).map { page =>
|
getWikiPage(repository.owner, repository.name, pageName).map { page =>
|
||||||
wiki.html.page(pageName, page, getWikiPageList(repository.owner, repository.name),
|
html.page(pageName, page, getWikiPageList(repository.owner, repository.name),
|
||||||
repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
repository, hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_edit")
|
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_edit")
|
||||||
})
|
})
|
||||||
@@ -55,7 +55,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
using(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)) => wiki.html.history(Some(pageName), logs, repository)
|
case Right((logs, hasNext)) => html.history(Some(pageName), logs, repository)
|
||||||
case Left(_) => NotFound
|
case Left(_) => NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -66,7 +66,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
wiki.html.compare(Some(pageName), from, to, JGitUtil.getDiffs(git, from, to, true).filter(_.newPath == pageName + ".md"), repository,
|
html.compare(Some(pageName), from, to, JGitUtil.getDiffs(git, from, to, true).filter(_.newPath == pageName + ".md"), repository,
|
||||||
hasWritePermission(repository.owner, repository.name, context.loginAccount), flash.get("info"))
|
hasWritePermission(repository.owner, repository.name, context.loginAccount), flash.get("info"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -75,7 +75,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
wiki.html.compare(None, from, to, JGitUtil.getDiffs(git, from, to, true), repository,
|
html.compare(None, from, to, JGitUtil.getDiffs(git, from, to, true), repository,
|
||||||
hasWritePermission(repository.owner, repository.name, context.loginAccount), flash.get("info"))
|
hasWritePermission(repository.owner, repository.name, context.loginAccount), flash.get("info"))
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
@@ -105,7 +105,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_edit")(collaboratorsOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_edit")(collaboratorsOnly { repository =>
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
wiki.html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName), repository)
|
html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName), repository)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_edit", editForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_edit", editForm)(collaboratorsOnly { (form, repository) =>
|
||||||
@@ -120,7 +120,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_new")(collaboratorsOnly {
|
get("/:owner/:repository/wiki/_new")(collaboratorsOnly {
|
||||||
wiki.html.edit("", None, _)
|
html.edit("", None, _)
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_new", newForm)(collaboratorsOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(collaboratorsOnly { (form, repository) =>
|
||||||
@@ -147,14 +147,14 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
||||||
wiki.html.pages(getWikiPageList(repository.owner, repository.name), repository,
|
html.pages(getWikiPageList(repository.owner, repository.name), repository,
|
||||||
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
hasWritePermission(repository.owner, repository.name, context.loginAccount))
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
||||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
||||||
JGitUtil.getCommitLog(git, "master") match {
|
JGitUtil.getCommitLog(git, "master") match {
|
||||||
case Right((logs, hasNext)) => wiki.html.history(None, logs, repository)
|
case Right((logs, hasNext)) => html.history(None, logs, repository)
|
||||||
case Left(_) => NotFound
|
case Left(_) => NotFound
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -164,8 +164,7 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
val path = multiParams("splat").head
|
val path = multiParams("splat").head
|
||||||
|
|
||||||
getFileContent(repository.owner, repository.name, path).map { bytes =>
|
getFileContent(repository.owner, repository.name, path).map { bytes =>
|
||||||
contentType = FileUtil.getContentType(path, bytes)
|
RawData(FileUtil.getContentType(path, bytes), bytes)
|
||||||
bytes
|
|
||||||
} getOrElse NotFound
|
} getOrElse NotFound
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait AccountComponent { self: Profile =>
|
trait AccountComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -21,20 +21,19 @@ trait AccountComponent { self: Profile =>
|
|||||||
val removed = column[Boolean]("REMOVED")
|
val removed = column[Boolean]("REMOVED")
|
||||||
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply)
|
def * = (userName, fullName, mailAddress, password, isAdmin, url.?, registeredDate, updatedDate, lastLoginDate.?, image.?, groupAccount, removed) <> (Account.tupled, Account.unapply)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Account(
|
|
||||||
|
|
||||||
userName: String,
|
|
||||||
fullName: String,
|
|
||||||
mailAddress: String,
|
|
||||||
password: String,
|
|
||||||
isAdmin: Boolean,
|
|
||||||
url: Option[String],
|
|
||||||
registeredDate: java.util.Date,
|
|
||||||
updatedDate: java.util.Date,
|
|
||||||
lastLoginDate: Option[java.util.Date],
|
|
||||||
image: Option[String],
|
|
||||||
isGroupAccount: Boolean,
|
|
||||||
isRemoved: Boolean
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Account(
|
||||||
|
userName: String,
|
||||||
|
fullName: String,
|
||||||
|
mailAddress: String,
|
||||||
|
password: String,
|
||||||
|
isAdmin: Boolean,
|
||||||
|
url: Option[String],
|
||||||
|
registeredDate: java.util.Date,
|
||||||
|
updatedDate: java.util.Date,
|
||||||
|
lastLoginDate: Option[java.util.Date],
|
||||||
|
image: Option[String],
|
||||||
|
isGroupAccount: Boolean,
|
||||||
|
isRemoved: Boolean
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
trait ActivityComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -15,15 +15,15 @@ trait ActivityComponent extends TemplateComponent { self: Profile =>
|
|||||||
val activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
val activityDate = column[java.util.Date]("ACTIVITY_DATE")
|
||||||
def * = (userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
|
def * = (userName, repositoryName, activityUserName, activityType, message, additionalInfo.?, activityDate, activityId) <> (Activity.tupled, Activity.unapply)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Activity(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
activityUserName: String,
|
|
||||||
activityType: String,
|
|
||||||
message: String,
|
|
||||||
additionalInfo: Option[String],
|
|
||||||
activityDate: java.util.Date,
|
|
||||||
activityId: Int = 0
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Activity(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
activityUserName: String,
|
||||||
|
activityType: String,
|
||||||
|
message: String,
|
||||||
|
additionalInfo: Option[String],
|
||||||
|
activityDate: java.util.Date,
|
||||||
|
activityId: Int = 0
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
protected[model] trait TemplateComponent { self: Profile =>
|
protected[model] trait TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -8,40 +8,47 @@ protected[model] trait TemplateComponent { self: Profile =>
|
|||||||
val repositoryName = column[String]("REPOSITORY_NAME")
|
val repositoryName = column[String]("REPOSITORY_NAME")
|
||||||
|
|
||||||
def byRepository(owner: String, repository: String) =
|
def byRepository(owner: String, repository: String) =
|
||||||
(userName is owner.bind) && (repositoryName is repository.bind)
|
(userName === owner.bind) && (repositoryName === repository.bind)
|
||||||
|
|
||||||
def byRepository(userName: Column[String], repositoryName: Column[String]) =
|
def byRepository(userName: Column[String], repositoryName: Column[String]) =
|
||||||
(this.userName is userName) && (this.repositoryName is repositoryName)
|
(this.userName === userName) && (this.repositoryName === repositoryName)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait IssueTemplate extends BasicTemplate { self: Table[_] =>
|
trait IssueTemplate extends BasicTemplate { self: Table[_] =>
|
||||||
val issueId = column[Int]("ISSUE_ID")
|
val issueId = column[Int]("ISSUE_ID")
|
||||||
|
|
||||||
def byIssue(owner: String, repository: String, issueId: Int) =
|
def byIssue(owner: String, repository: String, issueId: Int) =
|
||||||
byRepository(owner, repository) && (this.issueId is issueId.bind)
|
byRepository(owner, repository) && (this.issueId === issueId.bind)
|
||||||
|
|
||||||
def byIssue(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) =
|
def byIssue(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) =
|
||||||
byRepository(userName, repositoryName) && (this.issueId is issueId)
|
byRepository(userName, repositoryName) && (this.issueId === issueId)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait LabelTemplate extends BasicTemplate { self: Table[_] =>
|
trait LabelTemplate extends BasicTemplate { self: Table[_] =>
|
||||||
val labelId = column[Int]("LABEL_ID")
|
val labelId = column[Int]("LABEL_ID")
|
||||||
|
|
||||||
def byLabel(owner: String, repository: String, labelId: Int) =
|
def byLabel(owner: String, repository: String, labelId: Int) =
|
||||||
byRepository(owner, repository) && (this.labelId is labelId.bind)
|
byRepository(owner, repository) && (this.labelId === labelId.bind)
|
||||||
|
|
||||||
def byLabel(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) =
|
def byLabel(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) =
|
||||||
byRepository(userName, repositoryName) && (this.labelId is labelId)
|
byRepository(userName, repositoryName) && (this.labelId === labelId)
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MilestoneTemplate extends BasicTemplate { self: Table[_] =>
|
trait MilestoneTemplate extends BasicTemplate { self: Table[_] =>
|
||||||
val milestoneId = column[Int]("MILESTONE_ID")
|
val milestoneId = column[Int]("MILESTONE_ID")
|
||||||
|
|
||||||
def byMilestone(owner: String, repository: String, milestoneId: Int) =
|
def byMilestone(owner: String, repository: String, milestoneId: Int) =
|
||||||
byRepository(owner, repository) && (this.milestoneId is milestoneId.bind)
|
byRepository(owner, repository) && (this.milestoneId === milestoneId.bind)
|
||||||
|
|
||||||
def byMilestone(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) =
|
def byMilestone(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) =
|
||||||
byRepository(userName, repositoryName) && (this.milestoneId is milestoneId)
|
byRepository(userName, repositoryName) && (this.milestoneId === milestoneId)
|
||||||
|
}
|
||||||
|
|
||||||
|
trait CommitTemplate extends BasicTemplate { self: Table[_] =>
|
||||||
|
val commitId = column[String]("COMMIT_ID")
|
||||||
|
|
||||||
|
def byCommit(owner: String, repository: String, commitId: String) =
|
||||||
|
byRepository(owner, repository) && (this.commitId === commitId)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -10,12 +10,12 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
|||||||
def * = (userName, repositoryName, collaboratorName) <> (Collaborator.tupled, Collaborator.unapply)
|
def * = (userName, repositoryName, collaboratorName) <> (Collaborator.tupled, Collaborator.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
||||||
byRepository(owner, repository) && (collaboratorName is collaborator.bind)
|
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Collaborator(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
collaboratorName: String
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Collaborator(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
collaboratorName: String
|
||||||
|
)
|
||||||
78
src/main/scala/gitbucket/core/model/Comment.scala
Normal file
78
src/main/scala/gitbucket/core/model/Comment.scala
Normal file
@@ -0,0 +1,78 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait Comment {
|
||||||
|
val commentedUserName: String
|
||||||
|
val registeredDate: java.util.Date
|
||||||
|
}
|
||||||
|
|
||||||
|
trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.simple._
|
||||||
|
import self._
|
||||||
|
|
||||||
|
lazy val IssueComments = new TableQuery(tag => new IssueComments(tag)){
|
||||||
|
def autoInc = this returning this.map(_.commentId)
|
||||||
|
}
|
||||||
|
|
||||||
|
class IssueComments(tag: Tag) extends Table[IssueComment](tag, "ISSUE_COMMENT") with IssueTemplate {
|
||||||
|
val commentId = column[Int]("COMMENT_ID", O AutoInc)
|
||||||
|
val action = column[String]("ACTION")
|
||||||
|
val commentedUserName = column[String]("COMMENTED_USER_NAME")
|
||||||
|
val content = column[String]("CONTENT")
|
||||||
|
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||||
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
|
def * = (userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate) <> (IssueComment.tupled, IssueComment.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class IssueComment (
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
commentId: Int = 0,
|
||||||
|
action: String,
|
||||||
|
commentedUserName: String,
|
||||||
|
content: String,
|
||||||
|
registeredDate: java.util.Date,
|
||||||
|
updatedDate: java.util.Date
|
||||||
|
) extends Comment
|
||||||
|
|
||||||
|
trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.simple._
|
||||||
|
import self._
|
||||||
|
|
||||||
|
lazy val CommitComments = new TableQuery(tag => new CommitComments(tag)){
|
||||||
|
def autoInc = this returning this.map(_.commentId)
|
||||||
|
}
|
||||||
|
|
||||||
|
class CommitComments(tag: Tag) extends Table[CommitComment](tag, "COMMIT_COMMENT") with CommitTemplate {
|
||||||
|
val commentId = column[Int]("COMMENT_ID", O AutoInc)
|
||||||
|
val commentedUserName = column[String]("COMMENTED_USER_NAME")
|
||||||
|
val content = column[String]("CONTENT")
|
||||||
|
val fileName = column[Option[String]]("FILE_NAME")
|
||||||
|
val oldLine = column[Option[Int]]("OLD_LINE_NUMBER")
|
||||||
|
val newLine = column[Option[Int]]("NEW_LINE_NUMBER")
|
||||||
|
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||||
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
|
val pullRequest = column[Boolean]("PULL_REQUEST")
|
||||||
|
def * = (userName, repositoryName, commitId, commentId, commentedUserName, content, fileName, oldLine, newLine, registeredDate, updatedDate, pullRequest) <> (CommitComment.tupled, CommitComment.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class CommitComment(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
commitId: String,
|
||||||
|
commentId: Int = 0,
|
||||||
|
commentedUserName: String,
|
||||||
|
content: String,
|
||||||
|
fileName: Option[String],
|
||||||
|
oldLine: Option[Int],
|
||||||
|
newLine: Option[Int],
|
||||||
|
registeredDate: java.util.Date,
|
||||||
|
updatedDate: java.util.Date,
|
||||||
|
pullRequest: Boolean
|
||||||
|
) extends Comment
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait GroupMemberComponent { self: Profile =>
|
trait GroupMemberComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -11,10 +11,10 @@ trait GroupMemberComponent { self: Profile =>
|
|||||||
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class GroupMember(
|
|
||||||
groupName: String,
|
|
||||||
userName: String,
|
|
||||||
isManager: Boolean
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class GroupMember(
|
||||||
|
groupName: String,
|
||||||
|
userName: String,
|
||||||
|
isManager: Boolean
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait IssueComponent extends TemplateComponent { self: Profile =>
|
trait IssueComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -31,18 +31,19 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
|||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Issue(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
issueId: Int,
|
|
||||||
openedUserName: String,
|
|
||||||
milestoneId: Option[Int],
|
|
||||||
assignedUserName: Option[String],
|
|
||||||
title: String,
|
|
||||||
content: Option[String],
|
|
||||||
closed: Boolean,
|
|
||||||
registeredDate: java.util.Date,
|
|
||||||
updatedDate: java.util.Date,
|
|
||||||
isPullRequest: Boolean)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Issue(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
openedUserName: String,
|
||||||
|
milestoneId: Option[Int],
|
||||||
|
assignedUserName: Option[String],
|
||||||
|
title: String,
|
||||||
|
content: Option[String],
|
||||||
|
closed: Boolean,
|
||||||
|
registeredDate: java.util.Date,
|
||||||
|
updatedDate: java.util.Date,
|
||||||
|
isPullRequest: Boolean
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -8,12 +8,13 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
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 is labelId.bind)
|
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class IssueLabel(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
issueId: Int,
|
|
||||||
labelId: Int)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class IssueLabel(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
labelId: Int
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait LabelComponent extends TemplateComponent { self: Profile =>
|
trait LabelComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -14,24 +14,24 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
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: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId)
|
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], labelId: Column[Int]) = byLabel(userName, repositoryName, labelId)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case class Label(
|
case class Label(
|
||||||
userName: String,
|
userName: String,
|
||||||
repositoryName: String,
|
repositoryName: String,
|
||||||
labelId: Int = 0,
|
labelId: Int = 0,
|
||||||
labelName: String,
|
labelName: String,
|
||||||
color: String){
|
color: String){
|
||||||
|
|
||||||
val fontColor = {
|
val fontColor = {
|
||||||
val r = color.substring(0, 2)
|
val r = color.substring(0, 2)
|
||||||
val g = color.substring(2, 4)
|
val g = color.substring(2, 4)
|
||||||
val b = color.substring(4, 6)
|
val b = color.substring(4, 6)
|
||||||
|
|
||||||
if(Integer.parseInt(r, 16) + Integer.parseInt(g, 16) + Integer.parseInt(b, 16) > 408){
|
if(Integer.parseInt(r, 16) + Integer.parseInt(g, 16) + Integer.parseInt(b, 16) > 408){
|
||||||
"000000"
|
"000000"
|
||||||
} else {
|
} else {
|
||||||
"FFFFFF"
|
"ffffff"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -17,13 +17,14 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
|||||||
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: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId)
|
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], milestoneId: Column[Int]) = byMilestone(userName, repositoryName, milestoneId)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Milestone(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
milestoneId: Int = 0,
|
|
||||||
title: String,
|
|
||||||
description: Option[String],
|
|
||||||
dueDate: Option[java.util.Date],
|
|
||||||
closedDate: Option[java.util.Date])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Milestone(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
milestoneId: Int = 0,
|
||||||
|
title: String,
|
||||||
|
description: Option[String],
|
||||||
|
dueDate: Option[java.util.Date],
|
||||||
|
closedDate: Option[java.util.Date]
|
||||||
|
)
|
||||||
19
src/main/scala/gitbucket/core/model/Plugin.scala
Normal file
19
src/main/scala/gitbucket/core/model/Plugin.scala
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait PluginComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.simple._
|
||||||
|
import self._
|
||||||
|
|
||||||
|
lazy val Plugins = TableQuery[Plugins]
|
||||||
|
|
||||||
|
class Plugins(tag: Tag) extends Table[Plugin](tag, "PLUGIN"){
|
||||||
|
val pluginId = column[String]("PLUGIN_ID", O PrimaryKey)
|
||||||
|
val version = column[String]("VERSION")
|
||||||
|
def * = (pluginId, version) <> (Plugin.tupled, Plugin.unapply)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class Plugin(
|
||||||
|
pluginId: String,
|
||||||
|
version: String
|
||||||
|
)
|
||||||
50
src/main/scala/gitbucket/core/model/Profile.scala
Normal file
50
src/main/scala/gitbucket/core/model/Profile.scala
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait Profile {
|
||||||
|
val profile: slick.driver.JdbcProfile
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
|
/**
|
||||||
|
* java.util.Date Mapped Column Types
|
||||||
|
*/
|
||||||
|
implicit val dateColumnType = MappedColumnType.base[java.util.Date, java.sql.Timestamp](
|
||||||
|
d => new java.sql.Timestamp(d.getTime),
|
||||||
|
t => new java.util.Date(t.getTime)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Extends Column to add conditional condition
|
||||||
|
*/
|
||||||
|
implicit class RichColumn(c1: Column[Boolean]){
|
||||||
|
def &&(c2: => Column[Boolean], guard: => Boolean): Column[Boolean] = if(guard) c1 && c2 else c1
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns system date.
|
||||||
|
*/
|
||||||
|
def currentDate = new java.util.Date()
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
trait ProfileProvider { self: Profile =>
|
||||||
|
val profile = slick.driver.H2Driver
|
||||||
|
}
|
||||||
|
|
||||||
|
trait CoreProfile extends ProfileProvider with Profile
|
||||||
|
with AccountComponent
|
||||||
|
with ActivityComponent
|
||||||
|
with CollaboratorComponent
|
||||||
|
with CommitCommentComponent
|
||||||
|
with GroupMemberComponent
|
||||||
|
with IssueComponent
|
||||||
|
with IssueCommentComponent
|
||||||
|
with IssueLabelComponent
|
||||||
|
with LabelComponent
|
||||||
|
with MilestoneComponent
|
||||||
|
with PullRequestComponent
|
||||||
|
with RepositoryComponent
|
||||||
|
with SshKeyComponent
|
||||||
|
with WebHookComponent
|
||||||
|
with PluginComponent
|
||||||
|
|
||||||
|
object Profile extends CoreProfile
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -17,16 +17,16 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
|||||||
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId)
|
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) = byIssue(userName, repositoryName, issueId)
|
||||||
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId)
|
def byPrimaryKey(userName: Column[String], repositoryName: Column[String], issueId: Column[Int]) = byIssue(userName, repositoryName, issueId)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class PullRequest(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
issueId: Int,
|
|
||||||
branch: String,
|
|
||||||
requestUserName: String,
|
|
||||||
requestRepositoryName: String,
|
|
||||||
requestBranch: String,
|
|
||||||
commitIdFrom: String,
|
|
||||||
commitIdTo: String
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class PullRequest(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
branch: String,
|
||||||
|
requestUserName: String,
|
||||||
|
requestRepositoryName: String,
|
||||||
|
requestBranch: String,
|
||||||
|
commitIdFrom: String,
|
||||||
|
commitIdTo: String
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -21,19 +21,19 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class Repository(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
isPrivate: Boolean,
|
|
||||||
description: Option[String],
|
|
||||||
defaultBranch: String,
|
|
||||||
registeredDate: java.util.Date,
|
|
||||||
updatedDate: java.util.Date,
|
|
||||||
lastActivityDate: java.util.Date,
|
|
||||||
originUserName: Option[String],
|
|
||||||
originRepositoryName: Option[String],
|
|
||||||
parentUserName: Option[String],
|
|
||||||
parentRepositoryName: Option[String]
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class Repository(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
isPrivate: Boolean,
|
||||||
|
description: Option[String],
|
||||||
|
defaultBranch: String,
|
||||||
|
registeredDate: java.util.Date,
|
||||||
|
updatedDate: java.util.Date,
|
||||||
|
lastActivityDate: java.util.Date,
|
||||||
|
originUserName: Option[String],
|
||||||
|
originRepositoryName: Option[String],
|
||||||
|
parentUserName: Option[String],
|
||||||
|
parentRepositoryName: Option[String]
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait SshKeyComponent { self: Profile =>
|
trait SshKeyComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -12,13 +12,13 @@ trait SshKeyComponent { self: Profile =>
|
|||||||
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) = (this.userName is userName.bind) && (this.sshKeyId is sshKeyId.bind)
|
def byPrimaryKey(userName: String, sshKeyId: Int) = (this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class SshKey(
|
|
||||||
userName: String,
|
|
||||||
sshKeyId: Int = 0,
|
|
||||||
title: String,
|
|
||||||
publicKey: String
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class SshKey(
|
||||||
|
userName: String,
|
||||||
|
sshKeyId: Int = 0,
|
||||||
|
title: String,
|
||||||
|
publicKey: String
|
||||||
|
)
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait WebHookComponent extends TemplateComponent { self: Profile =>
|
trait WebHookComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.simple._
|
import profile.simple._
|
||||||
@@ -9,12 +9,12 @@ trait WebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
def * = (userName, repositoryName, url) <> (WebHook.tupled, WebHook.unapply)
|
def * = (userName, repositoryName, url) <> (WebHook.tupled, WebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url is url.bind)
|
def byPrimaryKey(owner: String, repository: String, url: String) = byRepository(owner, repository) && (this.url === url.bind)
|
||||||
}
|
}
|
||||||
|
|
||||||
case class WebHook(
|
|
||||||
userName: String,
|
|
||||||
repositoryName: String,
|
|
||||||
url: String
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class WebHook(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
url: String
|
||||||
|
)
|
||||||
5
src/main/scala/gitbucket/core/model/package.scala
Normal file
5
src/main/scala/gitbucket/core/model/package.scala
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
package gitbucket.core
|
||||||
|
|
||||||
|
package object model {
|
||||||
|
type Session = slick.jdbc.JdbcBackend#Session
|
||||||
|
}
|
||||||
10
src/main/scala/gitbucket/core/plugin/Images.scala
Normal file
10
src/main/scala/gitbucket/core/plugin/Images.scala
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
package gitbucket.core.plugin
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides a helper method to generate data URI of images registered by plug-in.
|
||||||
|
*/
|
||||||
|
object Images {
|
||||||
|
|
||||||
|
def dataURI(id: String) = s"data:image/png;base64,${PluginRegistry().getImage(id)}"
|
||||||
|
|
||||||
|
}
|
||||||
28
src/main/scala/gitbucket/core/plugin/Plugin.scala
Normal file
28
src/main/scala/gitbucket/core/plugin/Plugin.scala
Normal file
@@ -0,0 +1,28 @@
|
|||||||
|
package gitbucket.core.plugin
|
||||||
|
|
||||||
|
import gitbucket.core.util.Version
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Trait for define plugin interface.
|
||||||
|
* To provide plugin, put Plugin class which mixed in this trait into the package root.
|
||||||
|
*/
|
||||||
|
trait Plugin {
|
||||||
|
|
||||||
|
val pluginId: String
|
||||||
|
val pluginName: String
|
||||||
|
val description: String
|
||||||
|
val versions: Seq[Version]
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is invoked in initialization of plugin system.
|
||||||
|
* Register plugin functionality to PluginRegistry.
|
||||||
|
*/
|
||||||
|
def initialize(registry: PluginRegistry): Unit
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is invoked in shutdown of plugin system.
|
||||||
|
* If the plugin has any resources, release them in this method.
|
||||||
|
*/
|
||||||
|
def shutdown(registry: PluginRegistry): Unit
|
||||||
|
|
||||||
|
}
|
||||||
161
src/main/scala/gitbucket/core/plugin/PluginRegistory.scala
Normal file
161
src/main/scala/gitbucket/core/plugin/PluginRegistory.scala
Normal file
@@ -0,0 +1,161 @@
|
|||||||
|
package gitbucket.core.plugin
|
||||||
|
|
||||||
|
import java.io.{File, FilenameFilter, InputStream}
|
||||||
|
import java.net.URLClassLoader
|
||||||
|
import javax.servlet.ServletContext
|
||||||
|
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||||
|
|
||||||
|
import gitbucket.core.controller.{Context, ControllerBase}
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
import gitbucket.core.util.ControlUtil._
|
||||||
|
import gitbucket.core.util.Directory._
|
||||||
|
import gitbucket.core.util.JDBCUtil._
|
||||||
|
import gitbucket.core.util.{Version, Versions}
|
||||||
|
import org.apache.commons.codec.binary.{Base64, StringUtils}
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
import scala.collection.mutable
|
||||||
|
import scala.collection.mutable.ListBuffer
|
||||||
|
|
||||||
|
class PluginRegistry {
|
||||||
|
|
||||||
|
private val plugins = new ListBuffer[PluginInfo]
|
||||||
|
private val javaScripts = new ListBuffer[(String, String)]
|
||||||
|
private val controllers = new ListBuffer[(ControllerBase, String)]
|
||||||
|
private val images = mutable.Map[String, String]()
|
||||||
|
|
||||||
|
def addPlugin(pluginInfo: PluginInfo): Unit = {
|
||||||
|
plugins += pluginInfo
|
||||||
|
}
|
||||||
|
|
||||||
|
def getPlugins(): List[PluginInfo] = plugins.toList
|
||||||
|
|
||||||
|
def addImage(id: String, in: InputStream): Unit = {
|
||||||
|
val bytes = using(in){ in =>
|
||||||
|
val bytes = new Array[Byte](in.available)
|
||||||
|
in.read(bytes)
|
||||||
|
bytes
|
||||||
|
}
|
||||||
|
val encoded = StringUtils.newStringUtf8(Base64.encodeBase64(bytes, false))
|
||||||
|
images += ((id, encoded))
|
||||||
|
}
|
||||||
|
|
||||||
|
def getImage(id: String): String = images(id)
|
||||||
|
|
||||||
|
def addController(controller: ControllerBase, path: String): Unit = {
|
||||||
|
controllers += ((controller, path))
|
||||||
|
}
|
||||||
|
|
||||||
|
def getControllers(): List[(ControllerBase, String)] = controllers.toList
|
||||||
|
|
||||||
|
def addJavaScript(path: String, script: String): Unit = {
|
||||||
|
javaScripts += Tuple2(path, script)
|
||||||
|
}
|
||||||
|
|
||||||
|
//def getJavaScripts(): List[(String, String)] = javaScripts.toList
|
||||||
|
|
||||||
|
def getJavaScript(currentPath: String): Option[String] = {
|
||||||
|
javaScripts.find(x => currentPath.matches(x._1)).map(_._2)
|
||||||
|
}
|
||||||
|
|
||||||
|
private case class GlobalAction(
|
||||||
|
method: String,
|
||||||
|
path: String,
|
||||||
|
function: (HttpServletRequest, HttpServletResponse, Context) => Any
|
||||||
|
)
|
||||||
|
|
||||||
|
private case class RepositoryAction(
|
||||||
|
method: String,
|
||||||
|
path: String,
|
||||||
|
function: (HttpServletRequest, HttpServletResponse, Context, RepositoryInfo) => Any
|
||||||
|
)
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides entry point to PluginRegistry.
|
||||||
|
*/
|
||||||
|
object PluginRegistry {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[PluginRegistry])
|
||||||
|
|
||||||
|
private val instance = new PluginRegistry()
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the PluginRegistry singleton instance.
|
||||||
|
*/
|
||||||
|
def apply(): PluginRegistry = instance
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initializes all installed plugins.
|
||||||
|
*/
|
||||||
|
def initialize(context: ServletContext, conn: java.sql.Connection): Unit = {
|
||||||
|
val pluginDir = new File(PluginHome)
|
||||||
|
if(pluginDir.exists && pluginDir.isDirectory){
|
||||||
|
pluginDir.listFiles(new FilenameFilter {
|
||||||
|
override def accept(dir: File, name: String): Boolean = name.endsWith(".jar")
|
||||||
|
}).foreach { pluginJar =>
|
||||||
|
val classLoader = new URLClassLoader(Array(pluginJar.toURI.toURL), Thread.currentThread.getContextClassLoader)
|
||||||
|
try {
|
||||||
|
val plugin = classLoader.loadClass("Plugin").newInstance().asInstanceOf[Plugin]
|
||||||
|
|
||||||
|
// Migration
|
||||||
|
val headVersion = plugin.versions.head
|
||||||
|
val currentVersion = conn.find("SELECT * FROM PLUGIN WHERE PLUGIN_ID = ?", plugin.pluginId)(_.getString("VERSION")) match {
|
||||||
|
case Some(x) => {
|
||||||
|
val dim = x.split("\\.")
|
||||||
|
Version(dim(0).toInt, dim(1).toInt)
|
||||||
|
}
|
||||||
|
case None => Version(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
Versions.update(conn, headVersion, currentVersion, plugin.versions, new URLClassLoader(Array(pluginJar.toURI.toURL))){ conn =>
|
||||||
|
currentVersion.versionString match {
|
||||||
|
case "0.0" =>
|
||||||
|
conn.update("INSERT INTO PLUGIN (PLUGIN_ID, VERSION) VALUES (?, ?)", plugin.pluginId, headVersion.versionString)
|
||||||
|
case _ =>
|
||||||
|
conn.update("UPDATE PLUGIN SET VERSION = ? WHERE PLUGIN_ID = ?", headVersion.versionString, plugin.pluginId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize
|
||||||
|
plugin.initialize(instance)
|
||||||
|
instance.addPlugin(PluginInfo(
|
||||||
|
pluginId = plugin.pluginId,
|
||||||
|
pluginName = plugin.pluginName,
|
||||||
|
version = plugin.versions.head.versionString,
|
||||||
|
description = plugin.description,
|
||||||
|
pluginClass = plugin
|
||||||
|
))
|
||||||
|
|
||||||
|
} catch {
|
||||||
|
case e: Exception => {
|
||||||
|
logger.error(s"Error during plugin initialization", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def shutdown(context: ServletContext): Unit = {
|
||||||
|
instance.getPlugins().foreach { pluginInfo =>
|
||||||
|
try {
|
||||||
|
pluginInfo.pluginClass.shutdown(instance)
|
||||||
|
} catch {
|
||||||
|
case e: Exception => {
|
||||||
|
logger.error(s"Error during plugin shutdown", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
case class PluginInfo(
|
||||||
|
pluginId: String,
|
||||||
|
pluginName: String,
|
||||||
|
version: String,
|
||||||
|
description: String,
|
||||||
|
pluginClass: Plugin
|
||||||
|
)
|
||||||
11
src/main/scala/gitbucket/core/plugin/Results.scala
Normal file
11
src/main/scala/gitbucket/core/plugin/Results.scala
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package gitbucket.core.plugin
|
||||||
|
|
||||||
|
import play.twirl.api.Html
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Defines result case classes returned by plugin controller.
|
||||||
|
*/
|
||||||
|
object Results {
|
||||||
|
case class Redirect(path: String)
|
||||||
|
case class Fragment(html: Html)
|
||||||
|
}
|
||||||
11
src/main/scala/gitbucket/core/plugin/Sessions.scala
Normal file
11
src/main/scala/gitbucket/core/plugin/Sessions.scala
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
package gitbucket.core.plugin
|
||||||
|
|
||||||
|
import scala.slick.jdbc.JdbcBackend.Session
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides Slick Session to Plug-ins.
|
||||||
|
*/
|
||||||
|
object Sessions {
|
||||||
|
val sessions = new ThreadLocal[Session]
|
||||||
|
implicit def session: Session = sessions.get()
|
||||||
|
}
|
||||||
@@ -1,13 +1,14 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.{GroupMember, Account}
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
// TODO [Slick 2.0]NOT import directly?
|
import gitbucket.core.util.{StringUtil, LDAPUtil}
|
||||||
import model.dateColumnType
|
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||||
import service.SystemSettingsService.SystemSettings
|
import profile.simple._
|
||||||
import util.StringUtil._
|
import StringUtil._
|
||||||
import util.LDAPUtil
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
// TODO Why is direct import required?
|
||||||
|
import gitbucket.core.model.Profile.dateColumnType
|
||||||
|
|
||||||
trait AccountService {
|
trait AccountService {
|
||||||
|
|
||||||
@@ -39,7 +40,11 @@ trait AccountService {
|
|||||||
// Create or update account by LDAP information
|
// Create or update account by LDAP information
|
||||||
getAccountByUserName(ldapUserInfo.userName, true) match {
|
getAccountByUserName(ldapUserInfo.userName, true) match {
|
||||||
case Some(x) if(!x.isRemoved) => {
|
case Some(x) if(!x.isRemoved) => {
|
||||||
updateAccount(x.copy(mailAddress = ldapUserInfo.mailAddress, fullName = ldapUserInfo.fullName))
|
if(settings.ldap.get.mailAttribute.getOrElse("").isEmpty) {
|
||||||
|
updateAccount(x.copy(fullName = ldapUserInfo.fullName))
|
||||||
|
} else {
|
||||||
|
updateAccount(x.copy(mailAddress = ldapUserInfo.mailAddress, fullName = ldapUserInfo.fullName))
|
||||||
|
}
|
||||||
getAccountByUserName(ldapUserInfo.userName)
|
getAccountByUserName(ldapUserInfo.userName)
|
||||||
}
|
}
|
||||||
case Some(x) if(x.isRemoved) => {
|
case Some(x) if(x.isRemoved) => {
|
||||||
@@ -70,16 +75,16 @@ trait AccountService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
def getAccountByUserName(userName: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
||||||
Accounts filter(t => (t.userName is userName.bind) && (t.removed is false.bind, !includeRemoved)) firstOption
|
Accounts filter(t => (t.userName === userName.bind) && (t.removed === false.bind, !includeRemoved)) firstOption
|
||||||
|
|
||||||
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
def getAccountByMailAddress(mailAddress: String, includeRemoved: Boolean = false)(implicit s: Session): Option[Account] =
|
||||||
Accounts filter(t => (t.mailAddress.toLowerCase is mailAddress.toLowerCase.bind) && (t.removed is false.bind, !includeRemoved)) firstOption
|
Accounts filter(t => (t.mailAddress.toLowerCase === mailAddress.toLowerCase.bind) && (t.removed === false.bind, !includeRemoved)) firstOption
|
||||||
|
|
||||||
def getAllUsers(includeRemoved: Boolean = true)(implicit s: Session): List[Account] =
|
def getAllUsers(includeRemoved: Boolean = true)(implicit s: Session): List[Account] =
|
||||||
if(includeRemoved){
|
if(includeRemoved){
|
||||||
Accounts sortBy(_.userName) list
|
Accounts sortBy(_.userName) list
|
||||||
} else {
|
} else {
|
||||||
Accounts filter (_.removed is false.bind) sortBy(_.userName) list
|
Accounts filter (_.removed === false.bind) sortBy(_.userName) list
|
||||||
}
|
}
|
||||||
|
|
||||||
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
def createAccount(userName: String, password: String, fullName: String, mailAddress: String, isAdmin: Boolean, url: Option[String])
|
||||||
@@ -100,7 +105,7 @@ trait AccountService {
|
|||||||
|
|
||||||
def updateAccount(account: Account)(implicit s: Session): Unit =
|
def updateAccount(account: Account)(implicit s: Session): Unit =
|
||||||
Accounts
|
Accounts
|
||||||
.filter { a => a.userName is account.userName.bind }
|
.filter { a => a.userName === account.userName.bind }
|
||||||
.map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed) }
|
.map { a => (a.password, a.fullName, a.mailAddress, a.isAdmin, a.url.?, a.registeredDate, a.updatedDate, a.lastLoginDate.?, a.removed) }
|
||||||
.update (
|
.update (
|
||||||
account.password,
|
account.password,
|
||||||
@@ -114,10 +119,10 @@ trait AccountService {
|
|||||||
account.isRemoved)
|
account.isRemoved)
|
||||||
|
|
||||||
def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit =
|
def updateAvatarImage(userName: String, image: Option[String])(implicit s: Session): Unit =
|
||||||
Accounts.filter(_.userName is userName.bind).map(_.image.?).update(image)
|
Accounts.filter(_.userName === userName.bind).map(_.image.?).update(image)
|
||||||
|
|
||||||
def updateLastLoginDate(userName: String)(implicit s: Session): Unit =
|
def updateLastLoginDate(userName: String)(implicit s: Session): Unit =
|
||||||
Accounts.filter(_.userName is userName.bind).map(_.lastLoginDate).update(currentDate)
|
Accounts.filter(_.userName === userName.bind).map(_.lastLoginDate).update(currentDate)
|
||||||
|
|
||||||
def createGroup(groupName: String, url: Option[String])(implicit s: Session): Unit =
|
def createGroup(groupName: String, url: Option[String])(implicit s: Session): Unit =
|
||||||
Accounts insert Account(
|
Accounts insert Account(
|
||||||
@@ -135,10 +140,10 @@ trait AccountService {
|
|||||||
isRemoved = false)
|
isRemoved = false)
|
||||||
|
|
||||||
def updateGroup(groupName: String, url: Option[String], removed: Boolean)(implicit s: Session): Unit =
|
def updateGroup(groupName: String, url: Option[String], removed: Boolean)(implicit s: Session): Unit =
|
||||||
Accounts.filter(_.userName is groupName.bind).map(t => t.url.? -> t.removed).update(url, removed)
|
Accounts.filter(_.userName === groupName.bind).map(t => t.url.? -> t.removed).update(url, removed)
|
||||||
|
|
||||||
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
||||||
GroupMembers.filter(_.groupName is groupName.bind).delete
|
GroupMembers.filter(_.groupName === groupName.bind).delete
|
||||||
members.foreach { case (userName, isManager) =>
|
members.foreach { case (userName, isManager) =>
|
||||||
GroupMembers insert GroupMember (groupName, userName, isManager)
|
GroupMembers insert GroupMember (groupName, userName, isManager)
|
||||||
}
|
}
|
||||||
@@ -146,21 +151,26 @@ trait AccountService {
|
|||||||
|
|
||||||
def getGroupMembers(groupName: String)(implicit s: Session): List[GroupMember] =
|
def getGroupMembers(groupName: String)(implicit s: Session): List[GroupMember] =
|
||||||
GroupMembers
|
GroupMembers
|
||||||
.filter(_.groupName is groupName.bind)
|
.filter(_.groupName === groupName.bind)
|
||||||
.sortBy(_.userName)
|
.sortBy(_.userName)
|
||||||
.list
|
.list
|
||||||
|
|
||||||
def getGroupsByUserName(userName: String)(implicit s: Session): List[String] =
|
def getGroupsByUserName(userName: String)(implicit s: Session): List[String] =
|
||||||
GroupMembers
|
GroupMembers
|
||||||
.filter(_.userName is userName.bind)
|
.filter(_.userName === userName.bind)
|
||||||
.sortBy(_.groupName)
|
.sortBy(_.groupName)
|
||||||
.map(_.groupName)
|
.map(_.groupName)
|
||||||
.list
|
.list
|
||||||
|
|
||||||
def removeUserRelatedData(userName: String)(implicit s: Session): Unit = {
|
def removeUserRelatedData(userName: String)(implicit s: Session): Unit = {
|
||||||
GroupMembers.filter(_.userName is userName.bind).delete
|
GroupMembers.filter(_.userName === userName.bind).delete
|
||||||
Collaborators.filter(_.collaboratorName is userName.bind).delete
|
Collaborators.filter(_.collaboratorName === userName.bind).delete
|
||||||
Repositories.filter(_.userName is userName.bind).delete
|
Repositories.filter(_.userName === userName.bind).delete
|
||||||
|
}
|
||||||
|
|
||||||
|
def getGroupNames(userName: String)(implicit s: Session): List[String] = {
|
||||||
|
List(userName) ++
|
||||||
|
Collaborators.filter(_.collaboratorName === userName.bind).sortBy(_.userName).map(_.userName).list
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,9 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.Activity
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
|
import gitbucket.core.util.JGitUtil
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
trait ActivityService {
|
trait ActivityService {
|
||||||
|
|
||||||
@@ -10,9 +12,9 @@ trait ActivityService {
|
|||||||
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||||
.filter { case (t1, t2) =>
|
.filter { case (t1, t2) =>
|
||||||
if(isPublic){
|
if(isPublic){
|
||||||
(t1.activityUserName is activityUserName.bind) && (t2.isPrivate is false.bind)
|
(t1.activityUserName === activityUserName.bind) && (t2.isPrivate === false.bind)
|
||||||
} else {
|
} else {
|
||||||
(t1.activityUserName is activityUserName.bind)
|
(t1.activityUserName === activityUserName.bind)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
@@ -23,7 +25,16 @@ trait ActivityService {
|
|||||||
def getRecentActivities()(implicit s: Session): List[Activity] =
|
def getRecentActivities()(implicit s: Session): List[Activity] =
|
||||||
Activities
|
Activities
|
||||||
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||||
.filter { case (t1, t2) => t2.isPrivate is false.bind }
|
.filter { case (t1, t2) => t2.isPrivate === false.bind }
|
||||||
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
|
.map { case (t1, t2) => t1 }
|
||||||
|
.take(30)
|
||||||
|
.list
|
||||||
|
|
||||||
|
def getRecentActivitiesByOwners(owners : Set[String])(implicit s: Session): List[Activity] =
|
||||||
|
Activities
|
||||||
|
.innerJoin(Repositories).on((t1, t2) => t1.byRepository(t2.userName, t2.repositoryName))
|
||||||
|
.filter { case (t1, t2) => (t2.isPrivate === false.bind) || (t2.userName inSetBind owners) }
|
||||||
.sortBy { case (t1, t2) => t1.activityId desc }
|
.sortBy { case (t1, t2) => t1.activityId desc }
|
||||||
.map { case (t1, t2) => t1 }
|
.map { case (t1, t2) => t1 }
|
||||||
.take(30)
|
.take(30)
|
||||||
@@ -85,6 +96,15 @@ trait ActivityService {
|
|||||||
Some(cut(comment, 200)),
|
Some(cut(comment, 200)),
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
|
def recordCommentCommitActivity(userName: String, repositoryName: String, activityUserName: String, commitId: String, comment: String)
|
||||||
|
(implicit s: Session): Unit =
|
||||||
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
|
"comment_commit",
|
||||||
|
s"[user:${activityUserName}] commented on commit [commit:${userName}/${repositoryName}@${commitId}]",
|
||||||
|
Some(cut(comment, 200)),
|
||||||
|
currentDate
|
||||||
|
)
|
||||||
|
|
||||||
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String)
|
def recordCreateWikiPageActivity(userName: String, repositoryName: String, activityUserName: String, pageName: String)
|
||||||
(implicit s: Session): Unit =
|
(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
@@ -102,7 +122,7 @@ trait ActivityService {
|
|||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordPushActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordPushActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
branchName: String, commits: List[util.JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
branchName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
"push",
|
"push",
|
||||||
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] pushed to [branch:${userName}/${repositoryName}#${branchName}] at [repo:${userName}/${repositoryName}]",
|
||||||
@@ -110,7 +130,7 @@ trait ActivityService {
|
|||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordCreateTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
tagName: String, commits: List[util.JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
"create_tag",
|
"create_tag",
|
||||||
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] created tag [tag:${userName}/${repositoryName}#${tagName}] at [repo:${userName}/${repositoryName}]",
|
||||||
@@ -118,7 +138,7 @@ trait ActivityService {
|
|||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
def recordDeleteTagActivity(userName: String, repositoryName: String, activityUserName: String,
|
||||||
tagName: String, commits: List[util.JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
tagName: String, commits: List[JGitUtil.CommitInfo])(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
"delete_tag",
|
"delete_tag",
|
||||||
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
s"[user:${activityUserName}] deleted tag ${tagName} at [repo:${userName}/${repositoryName}]",
|
||||||
@@ -141,10 +161,10 @@ trait ActivityService {
|
|||||||
None,
|
None,
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String)(implicit s: Session): Unit =
|
def recordForkActivity(userName: String, repositoryName: String, activityUserName: String, forkedUserName: String)(implicit s: Session): Unit =
|
||||||
Activities insert Activity(userName, repositoryName, activityUserName,
|
Activities insert Activity(userName, repositoryName, activityUserName,
|
||||||
"fork",
|
"fork",
|
||||||
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${activityUserName}/${repositoryName}]",
|
s"[user:${activityUserName}] forked [repo:${userName}/${repositoryName}] to [repo:${forkedUserName}/${repositoryName}]",
|
||||||
None,
|
None,
|
||||||
currentDate)
|
currentDate)
|
||||||
|
|
||||||
53
src/main/scala/gitbucket/core/service/CommitsService.scala
Normal file
53
src/main/scala/gitbucket/core/service/CommitsService.scala
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
package gitbucket.core.service
|
||||||
|
|
||||||
|
import gitbucket.core.model.CommitComment
|
||||||
|
import gitbucket.core.util.{StringUtil, Implicits}
|
||||||
|
|
||||||
|
import scala.slick.jdbc.{StaticQuery => Q}
|
||||||
|
import Q.interpolation
|
||||||
|
import gitbucket.core.model.Profile._
|
||||||
|
import profile.simple._
|
||||||
|
import Implicits._
|
||||||
|
import StringUtil._
|
||||||
|
|
||||||
|
|
||||||
|
trait CommitsService {
|
||||||
|
|
||||||
|
def getCommitComments(owner: String, repository: String, commitId: String, pullRequest: Boolean)(implicit s: Session) =
|
||||||
|
CommitComments filter {
|
||||||
|
t => t.byCommit(owner, repository, commitId) && (t.pullRequest === pullRequest || pullRequest)
|
||||||
|
} list
|
||||||
|
|
||||||
|
def getCommitComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
||||||
|
if (commentId forall (_.isDigit))
|
||||||
|
CommitComments filter { t =>
|
||||||
|
t.byPrimaryKey(commentId.toInt) && t.byRepository(owner, repository)
|
||||||
|
} firstOption
|
||||||
|
else
|
||||||
|
None
|
||||||
|
|
||||||
|
def createCommitComment(owner: String, repository: String, commitId: String, loginUser: String,
|
||||||
|
content: String, fileName: Option[String], oldLine: Option[Int], newLine: Option[Int], pullRequest: Boolean)(implicit s: Session): Int =
|
||||||
|
CommitComments.autoInc insert CommitComment(
|
||||||
|
userName = owner,
|
||||||
|
repositoryName = repository,
|
||||||
|
commitId = commitId,
|
||||||
|
commentedUserName = loginUser,
|
||||||
|
content = content,
|
||||||
|
fileName = fileName,
|
||||||
|
oldLine = oldLine,
|
||||||
|
newLine = newLine,
|
||||||
|
registeredDate = currentDate,
|
||||||
|
updatedDate = currentDate,
|
||||||
|
pullRequest = pullRequest)
|
||||||
|
|
||||||
|
def updateCommitComment(commentId: Int, content: String)(implicit s: Session) =
|
||||||
|
CommitComments
|
||||||
|
.filter (_.byPrimaryKey(commentId))
|
||||||
|
.map { t =>
|
||||||
|
t.content -> t.updatedDate
|
||||||
|
}.update (content, currentDate)
|
||||||
|
|
||||||
|
def deleteCommitComment(commentId: Int)(implicit s: Session) =
|
||||||
|
CommitComments filter (_.byPrimaryKey(commentId)) delete
|
||||||
|
}
|
||||||
@@ -1,12 +1,13 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
|
import gitbucket.core.model._
|
||||||
|
import gitbucket.core.util.StringUtil._
|
||||||
|
import gitbucket.core.util.Implicits._
|
||||||
import scala.slick.jdbc.{StaticQuery => Q}
|
import scala.slick.jdbc.{StaticQuery => Q}
|
||||||
import Q.interpolation
|
import Q.interpolation
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.Profile._
|
||||||
import simple._
|
import profile.simple._
|
||||||
import util.Implicits._
|
|
||||||
import util.StringUtil._
|
|
||||||
|
|
||||||
trait IssuesService {
|
trait IssuesService {
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
@@ -42,15 +43,13 @@ trait IssuesService {
|
|||||||
* Returns the count of the search result against issues.
|
* Returns the count of the search result against issues.
|
||||||
*
|
*
|
||||||
* @param condition the search condition
|
* @param condition the search condition
|
||||||
* @param filterUser the filter user name (key is "all", "assigned" or "created_by", value is the user name)
|
|
||||||
* @param onlyPullRequest if true then counts only pull request, false then counts both of issue and pull request.
|
* @param onlyPullRequest if true then counts only pull request, false then counts both of issue and pull request.
|
||||||
* @param repos Tuple of the repository owner and the repository name
|
* @param repos Tuple of the repository owner and the repository name
|
||||||
* @return the count of the search result
|
* @return the count of the search result
|
||||||
*/
|
*/
|
||||||
def countIssue(condition: IssueSearchCondition, filterUser: Map[String, String], onlyPullRequest: Boolean,
|
def countIssue(condition: IssueSearchCondition, onlyPullRequest: Boolean,
|
||||||
repos: (String, String)*)(implicit s: Session): Int =
|
repos: (String, String)*)(implicit s: Session): Int =
|
||||||
// TODO check SQL
|
Query(searchIssueQuery(repos, condition, onlyPullRequest).length).first
|
||||||
Query(searchIssueQuery(repos, condition, filterUser, onlyPullRequest).length).first
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the Map which contains issue count for each labels.
|
* Returns the Map which contains issue count for each labels.
|
||||||
@@ -58,13 +57,12 @@ trait IssuesService {
|
|||||||
* @param owner the repository owner
|
* @param owner the repository owner
|
||||||
* @param repository the repository name
|
* @param repository the repository name
|
||||||
* @param condition the search condition
|
* @param condition the search condition
|
||||||
* @param filterUser the filter user name (key is "all", "assigned" or "created_by", value is the user name)
|
|
||||||
* @return the Map which contains issue count for each labels (key is label name, value is issue count)
|
* @return the Map which contains issue count for each labels (key is label name, value is issue count)
|
||||||
*/
|
*/
|
||||||
def countIssueGroupByLabels(owner: String, repository: String, condition: IssueSearchCondition,
|
def countIssueGroupByLabels(owner: String, repository: String, condition: IssueSearchCondition,
|
||||||
filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = {
|
filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = {
|
||||||
|
|
||||||
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), filterUser, false)
|
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), false)
|
||||||
.innerJoin(IssueLabels).on { (t1, t2) =>
|
.innerJoin(IssueLabels).on { (t1, t2) =>
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
@@ -79,47 +77,22 @@ trait IssuesService {
|
|||||||
}
|
}
|
||||||
.toMap
|
.toMap
|
||||||
}
|
}
|
||||||
/**
|
|
||||||
* Returns list which contains issue count for each repository.
|
|
||||||
* If the issue does not exist, its repository is not included in the result.
|
|
||||||
*
|
|
||||||
* @param condition the search condition
|
|
||||||
* @param filterUser the filter user name (key is "all", "assigned" or "created_by", value is the user name)
|
|
||||||
* @param onlyPullRequest if true then returns only pull request, false then returns both of issue and pull request.
|
|
||||||
* @param repos Tuple of the repository owner and the repository name
|
|
||||||
* @return list which contains issue count for each repository
|
|
||||||
*/
|
|
||||||
def countIssueGroupByRepository(
|
|
||||||
condition: IssueSearchCondition, filterUser: Map[String, String], onlyPullRequest: Boolean,
|
|
||||||
repos: (String, String)*)(implicit s: Session): List[(String, String, Int)] = {
|
|
||||||
searchIssueQuery(repos, condition.copy(repo = None), filterUser, onlyPullRequest)
|
|
||||||
.groupBy { t =>
|
|
||||||
t.userName -> t.repositoryName
|
|
||||||
}
|
|
||||||
.map { case (repo, t) =>
|
|
||||||
(repo._1, repo._2, t.length)
|
|
||||||
}
|
|
||||||
.sortBy(_._3 desc)
|
|
||||||
.list
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the search result against issues.
|
* Returns the search result against issues.
|
||||||
*
|
*
|
||||||
* @param condition the search condition
|
* @param condition the search condition
|
||||||
* @param filterUser the filter user name (key is "all", "assigned", "created_by" or "not_created_by", value is the user name)
|
* @param pullRequest if true then returns only pull requests, false then returns only issues.
|
||||||
* @param onlyPullRequest if true then returns only pull request, false then returns both of issue and pull request.
|
|
||||||
* @param offset the offset for pagination
|
* @param offset the offset for pagination
|
||||||
* @param limit the limit for pagination
|
* @param limit the limit for pagination
|
||||||
* @param repos Tuple of the repository owner and the repository name
|
* @param repos Tuple of the repository owner and the repository name
|
||||||
* @return the search result (list of tuples which contain issue, labels and comment count)
|
* @return the search result (list of tuples which contain issue, labels and comment count)
|
||||||
*/
|
*/
|
||||||
def searchIssue(condition: IssueSearchCondition, filterUser: Map[String, String], onlyPullRequest: Boolean,
|
def searchIssue(condition: IssueSearchCondition, pullRequest: Boolean, offset: Int, limit: Int, repos: (String, String)*)
|
||||||
offset: Int, limit: Int, repos: (String, String)*)
|
(implicit s: Session): List[IssueInfo] = {
|
||||||
(implicit s: Session): List[(Issue, List[Label], Int)] = {
|
|
||||||
|
|
||||||
// get issues and comment count and labels
|
// get issues and comment count and labels
|
||||||
searchIssueQuery(repos, condition, filterUser, onlyPullRequest)
|
searchIssueQuery(repos, condition, pullRequest)
|
||||||
.innerJoin(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) }
|
.innerJoin(IssueOutline).on { (t1, t2) => t1.byIssue(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
.sortBy { case (t1, t2) =>
|
.sortBy { case (t1, t2) =>
|
||||||
(condition.sort match {
|
(condition.sort match {
|
||||||
@@ -136,21 +109,23 @@ trait IssuesService {
|
|||||||
.drop(offset).take(limit)
|
.drop(offset).take(limit)
|
||||||
.leftJoin (IssueLabels) .on { case ((t1, t2), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
|
.leftJoin (IssueLabels) .on { case ((t1, t2), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
|
||||||
.leftJoin (Labels) .on { case (((t1, t2), t3), t4) => t3.byLabel(t4.userName, t4.repositoryName, t4.labelId) }
|
.leftJoin (Labels) .on { case (((t1, t2), t3), t4) => t3.byLabel(t4.userName, t4.repositoryName, t4.labelId) }
|
||||||
.map { case (((t1, t2), t3), t4) =>
|
.leftJoin (Milestones) .on { case ((((t1, t2), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) }
|
||||||
(t1, t2.commentCount, t4.labelId.?, t4.labelName.?, t4.color.?)
|
.map { case ((((t1, t2), t3), t4), t5) =>
|
||||||
|
(t1, t2.commentCount, t4.labelId.?, t4.labelName.?, t4.color.?, t5.title.?)
|
||||||
}
|
}
|
||||||
.list
|
.list
|
||||||
.splitWith { (c1, c2) =>
|
.splitWith { (c1, c2) =>
|
||||||
c1._1.userName == c2._1.userName &&
|
c1._1.userName == c2._1.userName &&
|
||||||
c1._1.repositoryName == c2._1.repositoryName &&
|
c1._1.repositoryName == c2._1.repositoryName &&
|
||||||
c1._1.issueId == c2._1.issueId
|
c1._1.issueId == c2._1.issueId
|
||||||
}
|
}
|
||||||
.map { issues => issues.head match {
|
.map { issues => issues.head match {
|
||||||
case (issue, commentCount, _,_,_) =>
|
case (issue, commentCount, _, _, _, milestone) =>
|
||||||
(issue,
|
IssueInfo(issue,
|
||||||
issues.flatMap { t => t._3.map (
|
issues.flatMap { t => t._3.map (
|
||||||
Label(issue.userName, issue.repositoryName, _, t._4.get, t._5.get)
|
Label(issue.userName, issue.repositoryName, _, t._4.get, t._5.get)
|
||||||
)} toList,
|
)} toList,
|
||||||
|
milestone,
|
||||||
commentCount)
|
commentCount)
|
||||||
}} toList
|
}} toList
|
||||||
}
|
}
|
||||||
@@ -158,21 +133,23 @@ trait IssuesService {
|
|||||||
/**
|
/**
|
||||||
* Assembles query for conditional issue searching.
|
* Assembles query for conditional issue searching.
|
||||||
*/
|
*/
|
||||||
private def searchIssueQuery(repos: Seq[(String, String)], condition: IssueSearchCondition,
|
private def searchIssueQuery(repos: Seq[(String, String)], condition: IssueSearchCondition, pullRequest: Boolean)(implicit s: Session) =
|
||||||
filterUser: Map[String, String], onlyPullRequest: Boolean)(implicit s: Session) =
|
|
||||||
Issues filter { t1 =>
|
Issues filter { t1 =>
|
||||||
condition.repo
|
repos
|
||||||
.map { _.split('/') match { case array => Seq(array(0) -> array(1)) } }
|
.map { case (owner, repository) => t1.byRepository(owner, repository) }
|
||||||
.getOrElse (repos)
|
.foldLeft[Column[Boolean]](false) ( _ || _ ) &&
|
||||||
.map { case (owner, repository) => t1.byRepository(owner, repository) }
|
(t1.closed === (condition.state == "closed").bind) &&
|
||||||
.foldLeft[Column[Boolean]](false) ( _ || _ ) &&
|
//(t1.milestoneId === condition.milestoneId.get.get.bind, condition.milestoneId.flatten.isDefined) &&
|
||||||
(t1.closed is (condition.state == "closed").bind) &&
|
(t1.milestoneId.? isEmpty, condition.milestone == Some(None)) &&
|
||||||
(t1.milestoneId is condition.milestoneId.get.get.bind, condition.milestoneId.flatten.isDefined) &&
|
(t1.assignedUserName === condition.assigned.get.bind, condition.assigned.isDefined) &&
|
||||||
(t1.milestoneId isNull, condition.milestoneId == Some(None)) &&
|
(t1.openedUserName === condition.author.get.bind, condition.author.isDefined) &&
|
||||||
(t1.assignedUserName is filterUser("assigned").bind, filterUser.get("assigned").isDefined) &&
|
(t1.pullRequest === pullRequest.bind) &&
|
||||||
(t1.openedUserName is filterUser("created_by").bind, filterUser.get("created_by").isDefined) &&
|
// Milestone filter
|
||||||
(t1.openedUserName isNot filterUser("not_created_by").bind, filterUser.get("not_created_by").isDefined) &&
|
(Milestones filter { t2 =>
|
||||||
(t1.pullRequest is true.bind, onlyPullRequest) &&
|
(t2.byPrimaryKey(t1.userName, t1.repositoryName, t1.milestoneId)) &&
|
||||||
|
(t2.title === condition.milestone.get.get.bind)
|
||||||
|
} exists, condition.milestone.flatten.isDefined) &&
|
||||||
|
// Label filter
|
||||||
(IssueLabels filter { t2 =>
|
(IssueLabels filter { t2 =>
|
||||||
(t2.byIssue(t1.userName, t1.repositoryName, t1.issueId)) &&
|
(t2.byIssue(t1.userName, t1.repositoryName, t1.issueId)) &&
|
||||||
(t2.labelId in
|
(t2.labelId in
|
||||||
@@ -180,7 +157,19 @@ trait IssuesService {
|
|||||||
(t3.byRepository(t1.userName, t1.repositoryName)) &&
|
(t3.byRepository(t1.userName, t1.repositoryName)) &&
|
||||||
(t3.labelName inSetBind condition.labels)
|
(t3.labelName inSetBind condition.labels)
|
||||||
} map(_.labelId)))
|
} map(_.labelId)))
|
||||||
} exists, condition.labels.nonEmpty)
|
} exists, condition.labels.nonEmpty) &&
|
||||||
|
// Visibility filter
|
||||||
|
(Repositories filter { t2 =>
|
||||||
|
(t2.byRepository(t1.userName, t1.repositoryName)) &&
|
||||||
|
(t2.isPrivate === (condition.visibility == Some("private")).bind)
|
||||||
|
} exists, condition.visibility.nonEmpty) &&
|
||||||
|
// Organization (group) filter
|
||||||
|
(t1.userName inSetBind condition.groups, condition.groups.nonEmpty) &&
|
||||||
|
// Mentioned filter
|
||||||
|
((t1.openedUserName === condition.mentioned.get.bind) || t1.assignedUserName === condition.mentioned.get.bind ||
|
||||||
|
(IssueComments filter { t2 =>
|
||||||
|
(t2.byIssue(t1.userName, t1.repositoryName, t1.issueId)) && (t2.commentedUserName === condition.mentioned.get.bind)
|
||||||
|
} exists), condition.mentioned.isDefined)
|
||||||
}
|
}
|
||||||
|
|
||||||
def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String],
|
def createIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String],
|
||||||
@@ -279,6 +268,7 @@ trait IssuesService {
|
|||||||
|
|
||||||
// Search Issue
|
// Search Issue
|
||||||
val issues = Issues
|
val issues = Issues
|
||||||
|
.filter(_.byRepository(owner, repository))
|
||||||
.innerJoin(IssueOutline).on { case (t1, t2) =>
|
.innerJoin(IssueOutline).on { case (t1, t2) =>
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
@@ -294,6 +284,7 @@ trait IssuesService {
|
|||||||
|
|
||||||
// Search IssueComment
|
// Search IssueComment
|
||||||
val comments = IssueComments
|
val comments = IssueComments
|
||||||
|
.filter(_.byRepository(owner, repository))
|
||||||
.innerJoin(Issues).on { case (t1, t2) =>
|
.innerJoin(Issues).on { case (t1, t2) =>
|
||||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||||
}
|
}
|
||||||
@@ -336,23 +327,65 @@ object IssuesService {
|
|||||||
|
|
||||||
case class IssueSearchCondition(
|
case class IssueSearchCondition(
|
||||||
labels: Set[String] = Set.empty,
|
labels: Set[String] = Set.empty,
|
||||||
milestoneId: Option[Option[Int]] = None,
|
milestone: Option[Option[String]] = None,
|
||||||
repo: Option[String] = None,
|
author: Option[String] = None,
|
||||||
|
assigned: Option[String] = None,
|
||||||
|
mentioned: Option[String] = None,
|
||||||
state: String = "open",
|
state: String = "open",
|
||||||
sort: String = "created",
|
sort: String = "created",
|
||||||
direction: String = "desc"){
|
direction: String = "desc",
|
||||||
|
visibility: Option[String] = None,
|
||||||
|
groups: Set[String] = Set.empty){
|
||||||
|
|
||||||
|
def isEmpty: Boolean = {
|
||||||
|
labels.isEmpty && milestone.isEmpty && author.isEmpty && assigned.isEmpty &&
|
||||||
|
state == "open" && sort == "created" && direction == "desc" && visibility.isEmpty
|
||||||
|
}
|
||||||
|
|
||||||
|
def nonEmpty: Boolean = !isEmpty
|
||||||
|
|
||||||
|
def toFilterString: String = (
|
||||||
|
List(
|
||||||
|
Some(s"is:${state}"),
|
||||||
|
author.map(author => s"author:${author}"),
|
||||||
|
assigned.map(assignee => s"assignee:${assignee}"),
|
||||||
|
mentioned.map(mentioned => s"mentions:${mentioned}")
|
||||||
|
).flatten ++
|
||||||
|
labels.map(label => s"label:${label}") ++
|
||||||
|
List(
|
||||||
|
milestone.map { _ match {
|
||||||
|
case Some(x) => s"milestone:${x}"
|
||||||
|
case None => "no:milestone"
|
||||||
|
}},
|
||||||
|
(sort, direction) match {
|
||||||
|
case ("created" , "desc") => None
|
||||||
|
case ("created" , "asc" ) => Some("sort:created-asc")
|
||||||
|
case ("comments", "desc") => Some("sort:comments-desc")
|
||||||
|
case ("comments", "asc" ) => Some("sort:comments-asc")
|
||||||
|
case ("updated" , "desc") => Some("sort:updated-desc")
|
||||||
|
case ("updated" , "asc" ) => Some("sort:updated-asc")
|
||||||
|
},
|
||||||
|
visibility.map(visibility => s"visibility:${visibility}")
|
||||||
|
).flatten ++
|
||||||
|
groups.map(group => s"group:${group}")
|
||||||
|
).mkString(" ")
|
||||||
|
|
||||||
def toURL: String =
|
def toURL: String =
|
||||||
"?" + List(
|
"?" + List(
|
||||||
if(labels.isEmpty) None else Some("labels=" + urlEncode(labels.mkString(","))),
|
if(labels.isEmpty) None else Some("labels=" + urlEncode(labels.mkString(","))),
|
||||||
milestoneId.map { id => "milestone=" + (id match {
|
milestone.map { _ match {
|
||||||
case Some(x) => x.toString
|
case Some(x) => "milestone=" + urlEncode(x)
|
||||||
case None => "none"
|
case None => "milestone=none"
|
||||||
})},
|
}},
|
||||||
repo.map("for=" + urlEncode(_)),
|
author .map(x => "author=" + urlEncode(x)),
|
||||||
|
assigned .map(x => "assigned=" + urlEncode(x)),
|
||||||
|
mentioned.map(x => "mentioned=" + urlEncode(x)),
|
||||||
Some("state=" + urlEncode(state)),
|
Some("state=" + urlEncode(state)),
|
||||||
Some("sort=" + urlEncode(sort)),
|
Some("sort=" + urlEncode(sort)),
|
||||||
Some("direction=" + urlEncode(direction))).flatten.mkString("&")
|
Some("direction=" + urlEncode(direction)),
|
||||||
|
visibility.map(x => "visibility=" + urlEncode(x)),
|
||||||
|
if(groups.isEmpty) None else Some("groups=" + urlEncode(groups.mkString(",")))
|
||||||
|
).flatten.mkString("&")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -363,17 +396,63 @@ object IssuesService {
|
|||||||
if(value == null || value.isEmpty || (allow.nonEmpty && !allow.contains(value))) None else Some(value)
|
if(value == null || value.isEmpty || (allow.nonEmpty && !allow.contains(value))) None else Some(value)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores IssueSearchCondition instance from filter query.
|
||||||
|
*/
|
||||||
|
def apply(filter: String, milestones: Map[String, Int]): IssueSearchCondition = {
|
||||||
|
val conditions = filter.split("[ \t]+").map { x =>
|
||||||
|
val dim = x.split(":")
|
||||||
|
dim(0) -> dim(1)
|
||||||
|
}.groupBy(_._1).map { case (key, values) =>
|
||||||
|
key -> values.map(_._2).toSeq
|
||||||
|
}
|
||||||
|
|
||||||
|
val (sort, direction) = conditions.get("sort").flatMap(_.headOption).getOrElse("created-desc") match {
|
||||||
|
case "created-asc" => ("created" , "asc" )
|
||||||
|
case "comments-desc" => ("comments", "desc")
|
||||||
|
case "comments-asc" => ("comments", "asc" )
|
||||||
|
case "updated-desc" => ("comments", "desc")
|
||||||
|
case "updated-asc" => ("comments", "asc" )
|
||||||
|
case _ => ("created" , "desc")
|
||||||
|
}
|
||||||
|
|
||||||
|
IssueSearchCondition(
|
||||||
|
conditions.get("label").map(_.toSet).getOrElse(Set.empty),
|
||||||
|
conditions.get("milestone").flatMap(_.headOption) match {
|
||||||
|
case None => None
|
||||||
|
case Some("none") => Some(None)
|
||||||
|
case Some(x) => Some(Some(x)) //milestones.get(x).map(x => Some(x))
|
||||||
|
},
|
||||||
|
conditions.get("author").flatMap(_.headOption),
|
||||||
|
conditions.get("assignee").flatMap(_.headOption),
|
||||||
|
conditions.get("mentions").flatMap(_.headOption),
|
||||||
|
conditions.get("is").getOrElse(Seq.empty).find(x => x == "open" || x == "closed").getOrElse("open"),
|
||||||
|
sort,
|
||||||
|
direction,
|
||||||
|
conditions.get("visibility").flatMap(_.headOption),
|
||||||
|
conditions.get("group").map(_.toSet).getOrElse(Set.empty)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Restores IssueSearchCondition instance from request parameters.
|
||||||
|
*/
|
||||||
def apply(request: HttpServletRequest): IssueSearchCondition =
|
def apply(request: HttpServletRequest): IssueSearchCondition =
|
||||||
IssueSearchCondition(
|
IssueSearchCondition(
|
||||||
param(request, "labels").map(_.split(",").toSet).getOrElse(Set.empty),
|
param(request, "labels").map(_.split(",").toSet).getOrElse(Set.empty),
|
||||||
param(request, "milestone").map{
|
param(request, "milestone").map {
|
||||||
case "none" => None
|
case "none" => None
|
||||||
case x => x.toIntOpt
|
case x => Some(x)
|
||||||
},
|
},
|
||||||
param(request, "for"),
|
param(request, "author"),
|
||||||
|
param(request, "assigned"),
|
||||||
|
param(request, "mentioned"),
|
||||||
param(request, "state", Seq("open", "closed")).getOrElse("open"),
|
param(request, "state", Seq("open", "closed")).getOrElse("open"),
|
||||||
param(request, "sort", Seq("created", "comments", "updated")).getOrElse("created"),
|
param(request, "sort", Seq("created", "comments", "updated")).getOrElse("created"),
|
||||||
param(request, "direction", Seq("asc", "desc")).getOrElse("desc"))
|
param(request, "direction", Seq("asc", "desc")).getOrElse("desc"),
|
||||||
|
param(request, "visibility"),
|
||||||
|
param(request, "groups").map(_.split(",").toSet).getOrElse(Set.empty)
|
||||||
|
)
|
||||||
|
|
||||||
def page(request: HttpServletRequest) = try {
|
def page(request: HttpServletRequest) = try {
|
||||||
val i = param(request, "page").getOrElse("1").toInt
|
val i = param(request, "page").getOrElse("1").toInt
|
||||||
@@ -383,4 +462,6 @@ object IssuesService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
case class IssueInfo(issue: Issue, labels: List[Label], milestone: Option[String], commentCount: Int)
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.Label
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
trait LabelsService {
|
trait LabelsService {
|
||||||
|
|
||||||
@@ -11,8 +12,8 @@ trait LabelsService {
|
|||||||
def getLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Option[Label] =
|
def getLabel(owner: String, repository: String, labelId: Int)(implicit s: Session): Option[Label] =
|
||||||
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).firstOption
|
Labels.filter(_.byPrimaryKey(owner, repository, labelId)).firstOption
|
||||||
|
|
||||||
def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Unit =
|
def createLabel(owner: String, repository: String, labelName: String, color: String)(implicit s: Session): Int =
|
||||||
Labels insert Label(
|
Labels returning Labels.map(_.labelId) += Label(
|
||||||
userName = owner,
|
userName = owner,
|
||||||
repositoryName = repository,
|
repositoryName = repository,
|
||||||
labelName = labelName,
|
labelName = labelName,
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.Milestone
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
// TODO [Slick 2.0]NOT import directly?
|
import profile.simple._
|
||||||
import model.dateColumnType
|
// TODO Why is direct import required?
|
||||||
|
import gitbucket.core.model.Profile.dateColumnType
|
||||||
|
|
||||||
trait MilestonesService {
|
trait MilestonesService {
|
||||||
|
|
||||||
@@ -40,7 +41,7 @@ trait MilestonesService {
|
|||||||
|
|
||||||
def getMilestonesWithIssueCount(owner: String, repository: String)(implicit s: Session): List[(Milestone, Int, Int)] = {
|
def getMilestonesWithIssueCount(owner: String, repository: String)(implicit s: Session): List[(Milestone, Int, Int)] = {
|
||||||
val counts = Issues
|
val counts = Issues
|
||||||
.filter { t => (t.byRepository(owner, repository)) && (t.milestoneId isNotNull) }
|
.filter { t => (t.byRepository(owner, repository)) && (t.milestoneId.? isDefined) }
|
||||||
.groupBy { t => t.milestoneId -> t.closed }
|
.groupBy { t => t.milestoneId -> t.closed }
|
||||||
.map { case (t1, t2) => t1._1 -> t1._2 -> t2.length }
|
.map { case (t1, t2) => t1._1 -> t1._2 -> t2.length }
|
||||||
.toMap
|
.toMap
|
||||||
24
src/main/scala/gitbucket/core/service/PluginService.scala
Normal file
24
src/main/scala/gitbucket/core/service/PluginService.scala
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package gitbucket.core.service
|
||||||
|
|
||||||
|
import gitbucket.core.model.Plugin
|
||||||
|
import gitbucket.core.model.Profile._
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
|
trait PluginService {
|
||||||
|
|
||||||
|
def getPlugins()(implicit s: Session): List[Plugin] =
|
||||||
|
Plugins.sortBy(_.pluginId).list
|
||||||
|
|
||||||
|
def registerPlugin(plugin: Plugin)(implicit s: Session): Unit =
|
||||||
|
Plugins.insert(plugin)
|
||||||
|
|
||||||
|
def updatePlugin(plugin: Plugin)(implicit s: Session): Unit =
|
||||||
|
Plugins.filter(_.pluginId === plugin.pluginId.bind).map(_.version).update(plugin.version)
|
||||||
|
|
||||||
|
def deletePlugin(pluginId: String)(implicit s: Session): Unit =
|
||||||
|
Plugins.filter(_.pluginId === pluginId.bind).delete
|
||||||
|
|
||||||
|
def getPlugin(pluginId: String)(implicit s: Session): Option[Plugin] =
|
||||||
|
Plugins.filter(_.pluginId === pluginId.bind).firstOption
|
||||||
|
|
||||||
|
}
|
||||||
125
src/main/scala/gitbucket/core/service/PullRequestService.scala
Normal file
125
src/main/scala/gitbucket/core/service/PullRequestService.scala
Normal file
@@ -0,0 +1,125 @@
|
|||||||
|
package gitbucket.core.service
|
||||||
|
|
||||||
|
import gitbucket.core.model.{Issue, PullRequest}
|
||||||
|
import gitbucket.core.model.Profile._
|
||||||
|
import gitbucket.core.util.JGitUtil
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
|
trait PullRequestService { self: IssuesService =>
|
||||||
|
import PullRequestService._
|
||||||
|
|
||||||
|
def getPullRequest(owner: String, repository: String, issueId: Int)
|
||||||
|
(implicit s: Session): Option[(Issue, PullRequest)] =
|
||||||
|
getIssue(owner, repository, issueId.toString).flatMap{ issue =>
|
||||||
|
PullRequests.filter(_.byPrimaryKey(owner, repository, issueId)).firstOption.map{
|
||||||
|
pullreq => (issue, pullreq)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def updateCommitId(owner: String, repository: String, issueId: Int, commitIdTo: String, commitIdFrom: String)
|
||||||
|
(implicit s: Session): Unit =
|
||||||
|
PullRequests.filter(_.byPrimaryKey(owner, repository, issueId))
|
||||||
|
.map(pr => pr.commitIdTo -> pr.commitIdFrom)
|
||||||
|
.update((commitIdTo, commitIdFrom))
|
||||||
|
|
||||||
|
def getPullRequestCountGroupByUser(closed: Boolean, owner: Option[String], repository: Option[String])
|
||||||
|
(implicit s: Session): List[PullRequestCount] =
|
||||||
|
PullRequests
|
||||||
|
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
|
.filter { case (t1, t2) =>
|
||||||
|
(t2.closed === closed.bind) &&
|
||||||
|
(t1.userName === owner.get.bind, owner.isDefined) &&
|
||||||
|
(t1.repositoryName === repository.get.bind, repository.isDefined)
|
||||||
|
}
|
||||||
|
.groupBy { case (t1, t2) => t2.openedUserName }
|
||||||
|
.map { case (userName, t) => userName -> t.length }
|
||||||
|
.sortBy(_._2 desc)
|
||||||
|
.list
|
||||||
|
.map { x => PullRequestCount(x._1, x._2) }
|
||||||
|
|
||||||
|
// def getAllPullRequestCountGroupByUser(closed: Boolean, userName: String)(implicit s: Session): List[PullRequestCount] =
|
||||||
|
// PullRequests
|
||||||
|
// .innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
|
// .innerJoin(Repositories).on { case ((t1, t2), t3) => t2.byRepository(t3.userName, t3.repositoryName) }
|
||||||
|
// .filter { case ((t1, t2), t3) =>
|
||||||
|
// (t2.closed === closed.bind) &&
|
||||||
|
// (
|
||||||
|
// (t3.isPrivate === false.bind) ||
|
||||||
|
// (t3.userName === userName.bind) ||
|
||||||
|
// (Collaborators.filter { t4 => t4.byRepository(t3.userName, t3.repositoryName) && (t4.collaboratorName === userName.bind)} exists)
|
||||||
|
// )
|
||||||
|
// }
|
||||||
|
// .groupBy { case ((t1, t2), t3) => t2.openedUserName }
|
||||||
|
// .map { case (userName, t) => userName -> t.length }
|
||||||
|
// .sortBy(_._2 desc)
|
||||||
|
// .list
|
||||||
|
// .map { x => PullRequestCount(x._1, x._2) }
|
||||||
|
|
||||||
|
def createPullRequest(originUserName: String, originRepositoryName: String, issueId: Int,
|
||||||
|
originBranch: String, requestUserName: String, requestRepositoryName: String, requestBranch: String,
|
||||||
|
commitIdFrom: String, commitIdTo: String)(implicit s: Session): Unit =
|
||||||
|
PullRequests insert PullRequest(
|
||||||
|
originUserName,
|
||||||
|
originRepositoryName,
|
||||||
|
issueId,
|
||||||
|
originBranch,
|
||||||
|
requestUserName,
|
||||||
|
requestRepositoryName,
|
||||||
|
requestBranch,
|
||||||
|
commitIdFrom,
|
||||||
|
commitIdTo)
|
||||||
|
|
||||||
|
def getPullRequestsByRequest(userName: String, repositoryName: String, branch: String, closed: Boolean)
|
||||||
|
(implicit s: Session): List[PullRequest] =
|
||||||
|
PullRequests
|
||||||
|
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
|
.filter { case (t1, t2) =>
|
||||||
|
(t1.requestUserName === userName.bind) &&
|
||||||
|
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||||
|
(t1.requestBranch === branch.bind) &&
|
||||||
|
(t2.closed === closed.bind)
|
||||||
|
}
|
||||||
|
.map { case (t1, t2) => t1 }
|
||||||
|
.list
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Fetch pull request contents into refs/pull/${issueId}/head and update pull request table.
|
||||||
|
*/
|
||||||
|
def updatePullRequests(owner: String, repository: String, branch: String)(implicit s: Session): Unit =
|
||||||
|
getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq =>
|
||||||
|
if(Repositories.filter(_.byRepository(pullreq.userName, pullreq.repositoryName)).exists.run){
|
||||||
|
val (commitIdTo, commitIdFrom) = JGitUtil.updatePullRequest(
|
||||||
|
pullreq.userName, pullreq.repositoryName, pullreq.branch, pullreq.issueId,
|
||||||
|
pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch)
|
||||||
|
updateCommitId(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo, commitIdFrom)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def getPullRequestByRequestCommit(userName: String, repositoryName: String, toBranch:String, fromBranch: String, commitId: String)
|
||||||
|
(implicit s: Session): Option[(PullRequest, Issue)] = {
|
||||||
|
if(toBranch == fromBranch){
|
||||||
|
None
|
||||||
|
} else {
|
||||||
|
PullRequests
|
||||||
|
.innerJoin(Issues).on { (t1, t2) => t1.byPrimaryKey(t2.userName, t2.repositoryName, t2.issueId) }
|
||||||
|
.filter { case (t1, t2) =>
|
||||||
|
(t1.userName === userName.bind) &&
|
||||||
|
(t1.repositoryName === repositoryName.bind) &&
|
||||||
|
(t1.branch === toBranch.bind) &&
|
||||||
|
(t1.requestUserName === userName.bind) &&
|
||||||
|
(t1.requestRepositoryName === repositoryName.bind) &&
|
||||||
|
(t1.requestBranch === fromBranch.bind) &&
|
||||||
|
(t1.commitIdTo === commitId.bind)
|
||||||
|
}
|
||||||
|
.firstOption
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
object PullRequestService {
|
||||||
|
|
||||||
|
val PullRequestLimit = 25
|
||||||
|
|
||||||
|
case class PullRequestCount(userName: String, count: Int)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,14 +1,16 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import util.{FileUtil, StringUtil, JGitUtil}
|
import gitbucket.core.model.Issue
|
||||||
import util.Directory._
|
import gitbucket.core.util._
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.StringUtil
|
||||||
|
import Directory._
|
||||||
|
import ControlUtil._
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
import org.eclipse.jgit.treewalk.TreeWalk
|
import org.eclipse.jgit.treewalk.TreeWalk
|
||||||
import org.eclipse.jgit.lib.FileMode
|
import org.eclipse.jgit.lib.FileMode
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import model._
|
import gitbucket.core.model.Profile._
|
||||||
import simple._
|
import profile.simple._
|
||||||
|
|
||||||
trait RepositorySearchService { self: IssuesService =>
|
trait RepositorySearchService { self: IssuesService =>
|
||||||
import RepositorySearchService._
|
import RepositorySearchService._
|
||||||
@@ -20,6 +22,7 @@ trait RepositorySearchService { self: IssuesService =>
|
|||||||
searchIssuesByKeyword(owner, repository, query).map { case (issue, commentCount, content) =>
|
searchIssuesByKeyword(owner, repository, query).map { case (issue, commentCount, content) =>
|
||||||
IssueSearchResult(
|
IssueSearchResult(
|
||||||
issue.issueId,
|
issue.issueId,
|
||||||
|
issue.isPullRequest,
|
||||||
issue.title,
|
issue.title,
|
||||||
issue.openedUserName,
|
issue.openedUserName,
|
||||||
issue.registeredDate,
|
issue.registeredDate,
|
||||||
@@ -111,6 +114,7 @@ object RepositorySearchService {
|
|||||||
|
|
||||||
case class IssueSearchResult(
|
case class IssueSearchResult(
|
||||||
issueId: Int,
|
issueId: Int,
|
||||||
|
isPullRequest: Boolean,
|
||||||
title: String,
|
title: String,
|
||||||
openedUserName: String,
|
openedUserName: String,
|
||||||
registeredDate: java.util.Date,
|
registeredDate: java.util.Date,
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.{Collaborator, Repository, Account}
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
import util.JGitUtil
|
import gitbucket.core.util.JGitUtil
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
trait RepositoryService { self: AccountService =>
|
trait RepositoryService { self: AccountService =>
|
||||||
import RepositoryService._
|
import RepositoryService._
|
||||||
@@ -45,40 +46,65 @@ trait RepositoryService { self: AccountService =>
|
|||||||
(Repositories filter { t => t.byRepository(oldUserName, oldRepositoryName) } firstOption).map { repository =>
|
(Repositories filter { t => t.byRepository(oldUserName, oldRepositoryName) } firstOption).map { repository =>
|
||||||
Repositories insert repository.copy(userName = newUserName, repositoryName = newRepositoryName)
|
Repositories insert repository.copy(userName = newUserName, repositoryName = newRepositoryName)
|
||||||
|
|
||||||
val webHooks = WebHooks .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val webHooks = WebHooks .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val milestones = Milestones .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val milestones = Milestones .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val issueId = IssueId .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val issueId = IssueId .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val issues = Issues .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val issues = Issues .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val pullRequests = PullRequests .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val pullRequests = PullRequests .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val labels = Labels .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val labels = Labels .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val issueComments = IssueComments.filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val issueComments = IssueComments .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val issueLabels = IssueLabels .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val issueLabels = IssueLabels .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val activities = Activities .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val commitComments = CommitComments.filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
val collaborators = Collaborators.filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
val collaborators = Collaborators .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||||
|
|
||||||
Repositories.filter { t =>
|
Repositories.filter { t =>
|
||||||
(t.originUserName is oldUserName.bind) && (t.originRepositoryName is oldRepositoryName.bind)
|
(t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind)
|
||||||
}.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName)
|
}.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName)
|
||||||
|
|
||||||
Repositories.filter { t =>
|
Repositories.filter { t =>
|
||||||
(t.parentUserName is oldUserName.bind) && (t.parentRepositoryName is oldRepositoryName.bind)
|
(t.parentUserName === oldUserName.bind) && (t.parentRepositoryName === oldRepositoryName.bind)
|
||||||
}.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName)
|
}.map { t => t.originUserName -> t.originRepositoryName }.update(newUserName, newRepositoryName)
|
||||||
|
|
||||||
PullRequests.filter { t =>
|
PullRequests.filter { t =>
|
||||||
t.requestRepositoryName is oldRepositoryName.bind
|
t.requestRepositoryName === oldRepositoryName.bind
|
||||||
}.map { t => t.requestUserName -> t.requestRepositoryName }.update(newUserName, newRepositoryName)
|
}.map { t => t.requestUserName -> t.requestRepositoryName }.update(newUserName, newRepositoryName)
|
||||||
|
|
||||||
|
// Updates activity fk before deleting repository because activity is sorted by activityId
|
||||||
|
// and it can't be changed by deleting-and-inserting record.
|
||||||
|
Activities.filter(_.byRepository(oldUserName, oldRepositoryName)).list.foreach { activity =>
|
||||||
|
Activities.filter(_.activityId === activity.activityId.bind)
|
||||||
|
.map(x => (x.userName, x.repositoryName)).update(newUserName, newRepositoryName)
|
||||||
|
}
|
||||||
|
|
||||||
deleteRepository(oldUserName, oldRepositoryName)
|
deleteRepository(oldUserName, oldRepositoryName)
|
||||||
|
|
||||||
WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
WebHooks .insertAll(webHooks .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
Milestones .insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
Milestones.insertAll(milestones .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*)
|
IssueId .insertAll(issueId .map(_.copy(_1 = newUserName, _2 = newRepositoryName)) :_*)
|
||||||
Issues .insertAll(issues .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
|
||||||
|
val newMilestones = Milestones.filter(_.byRepository(newUserName, newRepositoryName)).list
|
||||||
|
Issues.insertAll(issues.map { x => x.copy(
|
||||||
|
userName = newUserName,
|
||||||
|
repositoryName = newRepositoryName,
|
||||||
|
milestoneId = x.milestoneId.map { id =>
|
||||||
|
newMilestones.find(_.title == milestones.find(_.milestoneId == id).get.title).get.milestoneId
|
||||||
|
}
|
||||||
|
)} :_*)
|
||||||
|
|
||||||
PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
PullRequests .insertAll(pullRequests .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
IssueComments .insertAll(issueComments .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
Labels .insertAll(labels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
IssueLabels .insertAll(issueLabels .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
CommitComments.insertAll(commitComments.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||||
Activities .insertAll(activities .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
|
||||||
|
// Convert labelId
|
||||||
|
val oldLabelMap = labels.map(x => (x.labelId, x.labelName)).toMap
|
||||||
|
val newLabelMap = Labels.filter(_.byRepository(newUserName, newRepositoryName)).map(x => (x.labelName, x.labelId)).list.toMap
|
||||||
|
IssueLabels.insertAll(issueLabels.map(x => x.copy(
|
||||||
|
labelId = newLabelMap(oldLabelMap(x.labelId)),
|
||||||
|
userName = newUserName,
|
||||||
|
repositoryName = newRepositoryName
|
||||||
|
)) :_*)
|
||||||
|
|
||||||
if(account.isGroupAccount){
|
if(account.isGroupAccount){
|
||||||
Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*)
|
Collaborators.insertAll(getGroupMembers(newUserName).map(m => Collaborator(newUserName, newRepositoryName, m.userName)) :_*)
|
||||||
} else {
|
} else {
|
||||||
@@ -86,19 +112,19 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update activity messages
|
// Update activity messages
|
||||||
val updateActivities = Activities.filter { t =>
|
Activities.filter { t =>
|
||||||
(t.message like s"%:${oldUserName}/${oldRepositoryName}]%") ||
|
(t.message like s"%:${oldUserName}/${oldRepositoryName}]%") ||
|
||||||
(t.message like s"%:${oldUserName}/${oldRepositoryName}#%")
|
(t.message like s"%:${oldUserName}/${oldRepositoryName}#%") ||
|
||||||
}.map { t => t.activityId -> t.message }.list
|
(t.message like s"%:${oldUserName}/${oldRepositoryName}@%")
|
||||||
|
}.map { t => t.activityId -> t.message }.list.foreach { case (activityId, message) =>
|
||||||
updateActivities.foreach { case (activityId, message) =>
|
Activities.filter(_.activityId === activityId.bind).map(_.message).update(
|
||||||
Activities.filter(_.activityId is activityId.bind).map(_.message).update(
|
|
||||||
message
|
message
|
||||||
.replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]")
|
.replace(s"[repo:${oldUserName}/${oldRepositoryName}]" ,s"[repo:${newUserName}/${newRepositoryName}]")
|
||||||
.replace(s"[branch:${oldUserName}/${oldRepositoryName}#" ,s"[branch:${newUserName}/${newRepositoryName}#")
|
.replace(s"[branch:${oldUserName}/${oldRepositoryName}#" ,s"[branch:${newUserName}/${newRepositoryName}#")
|
||||||
.replace(s"[tag:${oldUserName}/${oldRepositoryName}#" ,s"[tag:${newUserName}/${newRepositoryName}#")
|
.replace(s"[tag:${oldUserName}/${oldRepositoryName}#" ,s"[tag:${newUserName}/${newRepositoryName}#")
|
||||||
.replace(s"[pullreq:${oldUserName}/${oldRepositoryName}#",s"[pullreq:${newUserName}/${newRepositoryName}#")
|
.replace(s"[pullreq:${oldUserName}/${oldRepositoryName}#",s"[pullreq:${newUserName}/${newRepositoryName}#")
|
||||||
.replace(s"[issue:${oldUserName}/${oldRepositoryName}#" ,s"[issue:${newUserName}/${newRepositoryName}#")
|
.replace(s"[issue:${oldUserName}/${oldRepositoryName}#" ,s"[issue:${newUserName}/${newRepositoryName}#")
|
||||||
|
.replace(s"[commit:${oldUserName}/${oldRepositoryName}@" ,s"[commit:${newUserName}/${newRepositoryName}@")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -108,6 +134,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
def deleteRepository(userName: String, repositoryName: String)(implicit s: Session): Unit = {
|
def deleteRepository(userName: String, repositoryName: String)(implicit s: Session): Unit = {
|
||||||
Activities .filter(_.byRepository(userName, repositoryName)).delete
|
Activities .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
Collaborators .filter(_.byRepository(userName, repositoryName)).delete
|
Collaborators .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
|
CommitComments.filter(_.byRepository(userName, repositoryName)).delete
|
||||||
IssueLabels .filter(_.byRepository(userName, repositoryName)).delete
|
IssueLabels .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
Labels .filter(_.byRepository(userName, repositoryName)).delete
|
Labels .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
IssueComments .filter(_.byRepository(userName, repositoryName)).delete
|
IssueComments .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
@@ -117,6 +144,30 @@ trait RepositoryService { self: AccountService =>
|
|||||||
Milestones .filter(_.byRepository(userName, repositoryName)).delete
|
Milestones .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
WebHooks .filter(_.byRepository(userName, repositoryName)).delete
|
WebHooks .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
Repositories .filter(_.byRepository(userName, repositoryName)).delete
|
Repositories .filter(_.byRepository(userName, repositoryName)).delete
|
||||||
|
|
||||||
|
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME
|
||||||
|
Repositories
|
||||||
|
.filter { x => (x.originUserName === userName.bind) && (x.originRepositoryName === repositoryName.bind) }
|
||||||
|
.map { x => (x.userName, x.repositoryName) }
|
||||||
|
.list
|
||||||
|
.foreach { case (userName, repositoryName) =>
|
||||||
|
Repositories
|
||||||
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
|
.map(x => (x.originUserName?, x.originRepositoryName?))
|
||||||
|
.update(None, None)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME
|
||||||
|
Repositories
|
||||||
|
.filter { x => (x.parentUserName === userName.bind) && (x.parentRepositoryName === repositoryName.bind) }
|
||||||
|
.map { x => (x.userName, x.repositoryName) }
|
||||||
|
.list
|
||||||
|
.foreach { case (userName, repositoryName) =>
|
||||||
|
Repositories
|
||||||
|
.filter(_.byRepository(userName, repositoryName))
|
||||||
|
.map(x => (x.parentUserName?, x.parentRepositoryName?))
|
||||||
|
.update(None, None)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -126,7 +177,7 @@ trait RepositoryService { self: AccountService =>
|
|||||||
* @return the list of repository names
|
* @return the list of repository names
|
||||||
*/
|
*/
|
||||||
def getRepositoryNamesOfUser(userName: String)(implicit s: Session): List[String] =
|
def getRepositoryNamesOfUser(userName: String)(implicit s: Session): List[String] =
|
||||||
Repositories filter(_.userName is userName.bind) map (_.repositoryName) list
|
Repositories filter(_.userName === userName.bind) map (_.repositoryName) list
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns the specified repository information.
|
* Returns the specified repository information.
|
||||||
@@ -140,14 +191,14 @@ trait RepositoryService { self: AccountService =>
|
|||||||
(Repositories filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository =>
|
(Repositories filter { t => t.byRepository(userName, repositoryName) } firstOption) map { repository =>
|
||||||
// for getting issue count and pull request count
|
// for getting issue count and pull request count
|
||||||
val issues = Issues.filter { t =>
|
val issues = Issues.filter { t =>
|
||||||
t.byRepository(repository.userName, repository.repositoryName) && (t.closed is false.bind)
|
t.byRepository(repository.userName, repository.repositoryName) && (t.closed === false.bind)
|
||||||
}.map(_.pullRequest).list
|
}.map(_.pullRequest).list
|
||||||
|
|
||||||
new RepositoryInfo(
|
new RepositoryInfo(
|
||||||
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl),
|
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName, baseUrl),
|
||||||
repository,
|
repository,
|
||||||
issues.size,
|
issues.count(_ == false),
|
||||||
issues.filter(_ == true).size,
|
issues.count(_ == true),
|
||||||
getForkedCount(
|
getForkedCount(
|
||||||
repository.originUserName.getOrElse(repository.userName),
|
repository.originUserName.getOrElse(repository.userName),
|
||||||
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
||||||
@@ -156,11 +207,28 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the repositories without private repository that user does not have access right.
|
||||||
|
* Include public repository, private own repository and private but collaborator repository.
|
||||||
|
*
|
||||||
|
* @param userName the user name of collaborator
|
||||||
|
* @return the repository infomation list
|
||||||
|
*/
|
||||||
|
def getAllRepositories(userName: String)(implicit s: Session): List[(String, String)] = {
|
||||||
|
Repositories.filter { t1 =>
|
||||||
|
(t1.isPrivate === false.bind) ||
|
||||||
|
(t1.userName === userName.bind) ||
|
||||||
|
(Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName === userName.bind)} exists)
|
||||||
|
}.sortBy(_.lastActivityDate desc).map{ t =>
|
||||||
|
(t.userName, t.repositoryName)
|
||||||
|
}.list
|
||||||
|
}
|
||||||
|
|
||||||
def getUserRepositories(userName: String, baseUrl: String, withoutPhysicalInfo: Boolean = false)
|
def getUserRepositories(userName: String, baseUrl: String, withoutPhysicalInfo: Boolean = false)
|
||||||
(implicit s: Session): List[RepositoryInfo] = {
|
(implicit s: Session): List[RepositoryInfo] = {
|
||||||
Repositories.filter { t1 =>
|
Repositories.filter { t1 =>
|
||||||
(t1.userName is userName.bind) ||
|
(t1.userName === userName.bind) ||
|
||||||
(Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName is userName.bind)} exists)
|
(Collaborators.filter { t2 => t2.byRepository(t1.userName, t1.repositoryName) && (t2.collaboratorName === userName.bind)} exists)
|
||||||
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
||||||
new RepositoryInfo(
|
new RepositoryInfo(
|
||||||
if(withoutPhysicalInfo){
|
if(withoutPhysicalInfo){
|
||||||
@@ -196,13 +264,13 @@ trait RepositoryService { self: AccountService =>
|
|||||||
case Some(x) if(x.isAdmin) => Repositories
|
case Some(x) if(x.isAdmin) => Repositories
|
||||||
// for Normal Users
|
// for Normal Users
|
||||||
case Some(x) if(!x.isAdmin) =>
|
case Some(x) if(!x.isAdmin) =>
|
||||||
Repositories filter { t => (t.isPrivate is false.bind) || (t.userName is x.userName) ||
|
Repositories filter { t => (t.isPrivate === false.bind) || (t.userName === x.userName) ||
|
||||||
(Collaborators.filter { t2 => t2.byRepository(t.userName, t.repositoryName) && (t2.collaboratorName is x.userName.bind)} exists)
|
(Collaborators.filter { t2 => t2.byRepository(t.userName, t.repositoryName) && (t2.collaboratorName === x.userName.bind)} exists)
|
||||||
}
|
}
|
||||||
// for Guests
|
// for Guests
|
||||||
case None => Repositories filter(_.isPrivate is false.bind)
|
case None => Repositories filter(_.isPrivate === false.bind)
|
||||||
}).filter { t =>
|
}).filter { t =>
|
||||||
repositoryUserName.map { userName => t.userName is userName.bind } getOrElse LiteralColumn(true)
|
repositoryUserName.map { userName => t.userName === userName.bind } getOrElse LiteralColumn(true)
|
||||||
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
||||||
new RepositoryInfo(
|
new RepositoryInfo(
|
||||||
if(withoutPhysicalInfo){
|
if(withoutPhysicalInfo){
|
||||||
@@ -290,15 +358,14 @@ trait RepositoryService { self: AccountService =>
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def getForkedCount(userName: String, repositoryName: String)(implicit s: Session): Int =
|
private def getForkedCount(userName: String, repositoryName: String)(implicit s: Session): Int =
|
||||||
// TODO check SQL
|
|
||||||
Query(Repositories.filter { t =>
|
Query(Repositories.filter { t =>
|
||||||
(t.originUserName is userName.bind) && (t.originRepositoryName is repositoryName.bind)
|
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
|
||||||
}.length).first
|
}.length).first
|
||||||
|
|
||||||
|
|
||||||
def getForkedRepositories(userName: String, repositoryName: String)(implicit s: Session): List[(String, String)] =
|
def getForkedRepositories(userName: String, repositoryName: String)(implicit s: Session): List[(String, String)] =
|
||||||
Repositories.filter { t =>
|
Repositories.filter { t =>
|
||||||
(t.originUserName is userName.bind) && (t.originRepositoryName is repositoryName.bind)
|
(t.originUserName === userName.bind) && (t.originRepositoryName === repositoryName.bind)
|
||||||
}
|
}
|
||||||
.sortBy(_.userName asc).map(t => t.userName -> t.repositoryName).list
|
.sortBy(_.userName asc).map(t => t.userName -> t.repositoryName).list
|
||||||
|
|
||||||
@@ -308,7 +375,7 @@ object RepositoryService {
|
|||||||
|
|
||||||
case class RepositoryInfo(owner: String, name: String, httpUrl: String, repository: Repository,
|
case class RepositoryInfo(owner: String, name: String, httpUrl: String, repository: Repository,
|
||||||
issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int,
|
issueCount: Int, pullCount: Int, commitCount: Int, forkedCount: Int,
|
||||||
branchList: Seq[String], tags: Seq[util.JGitUtil.TagInfo], managers: Seq[String]){
|
branchList: Seq[String], tags: Seq[JGitUtil.TagInfo], managers: Seq[String]){
|
||||||
|
|
||||||
lazy val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(httpUrl).get.group(1)
|
lazy val host = """^https?://(.+?)(:\d+)?/""".r.findFirstMatchIn(httpUrl).get.group(1)
|
||||||
|
|
||||||
@@ -329,4 +396,4 @@ object RepositoryService {
|
|||||||
|
|
||||||
case class RepositoryTreeNode(owner: String, name: String, children: List[RepositoryTreeNode])
|
case class RepositoryTreeNode(owner: String, name: String, children: List[RepositoryTreeNode])
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.{Session, Issue, Account}
|
||||||
import slick.jdbc.JdbcBackend
|
import gitbucket.core.util.Implicits
|
||||||
import util.Implicits.request2Session
|
import gitbucket.core.controller.Context
|
||||||
|
import Implicits.request2Session
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This service is used for a view helper mainly.
|
* This service is used for a view helper mainly.
|
||||||
@@ -12,25 +13,22 @@ import util.Implicits.request2Session
|
|||||||
*/
|
*/
|
||||||
trait RequestCache extends SystemSettingsService with AccountService with IssuesService {
|
trait RequestCache extends SystemSettingsService with AccountService with IssuesService {
|
||||||
|
|
||||||
private implicit def context2Session(implicit context: app.Context): JdbcBackend#Session =
|
private implicit def context2Session(implicit context: Context): Session =
|
||||||
request2Session(context.request)
|
request2Session(context.request)
|
||||||
|
|
||||||
def getIssue(userName: String, repositoryName: String, issueId: String)
|
def getIssue(userName: String, repositoryName: String, issueId: String)(implicit context: Context): Option[Issue] = {
|
||||||
(implicit context: app.Context): Option[Issue] = {
|
|
||||||
context.cache(s"issue.${userName}/${repositoryName}#${issueId}"){
|
context.cache(s"issue.${userName}/${repositoryName}#${issueId}"){
|
||||||
super.getIssue(userName, repositoryName, issueId)
|
super.getIssue(userName, repositoryName, issueId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAccountByUserName(userName: String)
|
def getAccountByUserName(userName: String)(implicit context: Context): Option[Account] = {
|
||||||
(implicit context: app.Context): Option[Account] = {
|
|
||||||
context.cache(s"account.${userName}"){
|
context.cache(s"account.${userName}"){
|
||||||
super.getAccountByUserName(userName)
|
super.getAccountByUserName(userName)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
def getAccountByMailAddress(mailAddress: String)
|
def getAccountByMailAddress(mailAddress: String)(implicit context: Context): Option[Account] = {
|
||||||
(implicit context: app.Context): Option[Account] = {
|
|
||||||
context.cache(s"account.${mailAddress}"){
|
context.cache(s"account.${mailAddress}"){
|
||||||
super.getAccountByMailAddress(mailAddress)
|
super.getAccountByMailAddress(mailAddress)
|
||||||
}
|
}
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.SshKey
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
|
import profile.simple._
|
||||||
|
|
||||||
trait SshKeyService {
|
trait SshKeyService {
|
||||||
|
|
||||||
@@ -9,7 +10,7 @@ trait SshKeyService {
|
|||||||
SshKeys insert SshKey(userName = userName, title = title, publicKey = publicKey)
|
SshKeys insert SshKey(userName = userName, title = title, publicKey = publicKey)
|
||||||
|
|
||||||
def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] =
|
def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] =
|
||||||
SshKeys.filter(_.userName is userName.bind).sortBy(_.sshKeyId).list
|
SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list
|
||||||
|
|
||||||
def deletePublicKey(userName: String, sshKeyId: Int)(implicit s: Session): Unit =
|
def deletePublicKey(userName: String, sshKeyId: Int)(implicit s: Session): Unit =
|
||||||
SshKeys filter (_.byPrimaryKey(userName, sshKeyId)) delete
|
SshKeys filter (_.byPrimaryKey(userName, sshKeyId)) delete
|
||||||
@@ -1,7 +1,8 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import util.Directory._
|
import gitbucket.core.util.{Directory, ControlUtil}
|
||||||
import util.ControlUtil._
|
import Directory._
|
||||||
|
import ControlUtil._
|
||||||
import SystemSettingsService._
|
import SystemSettingsService._
|
||||||
import javax.servlet.http.HttpServletRequest
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
|
||||||
@@ -12,7 +13,10 @@ trait SystemSettingsService {
|
|||||||
def saveSystemSettings(settings: SystemSettings): Unit = {
|
def saveSystemSettings(settings: SystemSettings): Unit = {
|
||||||
defining(new java.util.Properties()){ props =>
|
defining(new java.util.Properties()){ props =>
|
||||||
settings.baseUrl.foreach(x => props.setProperty(BaseURL, x.replaceFirst("/\\Z", "")))
|
settings.baseUrl.foreach(x => props.setProperty(BaseURL, x.replaceFirst("/\\Z", "")))
|
||||||
|
settings.information.foreach(x => props.setProperty(Information, x))
|
||||||
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
props.setProperty(AllowAccountRegistration, settings.allowAccountRegistration.toString)
|
||||||
|
props.setProperty(AllowAnonymousAccess, settings.allowAnonymousAccess.toString)
|
||||||
|
props.setProperty(IsCreateRepoOptionPublic, settings.isCreateRepoOptionPublic.toString)
|
||||||
props.setProperty(Gravatar, settings.gravatar.toString)
|
props.setProperty(Gravatar, settings.gravatar.toString)
|
||||||
props.setProperty(Notification, settings.notification.toString)
|
props.setProperty(Notification, settings.notification.toString)
|
||||||
props.setProperty(Ssh, settings.ssh.toString)
|
props.setProperty(Ssh, settings.ssh.toString)
|
||||||
@@ -37,9 +41,11 @@ trait SystemSettingsService {
|
|||||||
ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x))
|
ldap.bindPassword.foreach(x => props.setProperty(LdapBindPassword, x))
|
||||||
props.setProperty(LdapBaseDN, ldap.baseDN)
|
props.setProperty(LdapBaseDN, ldap.baseDN)
|
||||||
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
|
props.setProperty(LdapUserNameAttribute, ldap.userNameAttribute)
|
||||||
|
ldap.additionalFilterCondition.foreach(x => props.setProperty(LdapAdditionalFilterCondition, x))
|
||||||
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
ldap.fullNameAttribute.foreach(x => props.setProperty(LdapFullNameAttribute, x))
|
||||||
props.setProperty(LdapMailAddressAttribute, ldap.mailAttribute)
|
ldap.mailAttribute.foreach(x => props.setProperty(LdapMailAddressAttribute, x))
|
||||||
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
ldap.tls.foreach(x => props.setProperty(LdapTls, x.toString))
|
||||||
|
ldap.ssl.foreach(x => props.setProperty(LdapSsl, x.toString))
|
||||||
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
ldap.keystore.foreach(x => props.setProperty(LdapKeystore, x))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -59,7 +65,10 @@ trait SystemSettingsService {
|
|||||||
}
|
}
|
||||||
SystemSettings(
|
SystemSettings(
|
||||||
getOptionValue[String](props, BaseURL, None).map(x => x.replaceFirst("/\\Z", "")),
|
getOptionValue[String](props, BaseURL, None).map(x => x.replaceFirst("/\\Z", "")),
|
||||||
|
getOptionValue[String](props, Information, None),
|
||||||
getValue(props, AllowAccountRegistration, false),
|
getValue(props, AllowAccountRegistration, false),
|
||||||
|
getValue(props, AllowAnonymousAccess, true),
|
||||||
|
getValue(props, IsCreateRepoOptionPublic, true),
|
||||||
getValue(props, Gravatar, true),
|
getValue(props, Gravatar, true),
|
||||||
getValue(props, Notification, false),
|
getValue(props, Notification, false),
|
||||||
getValue(props, Ssh, false),
|
getValue(props, Ssh, false),
|
||||||
@@ -85,9 +94,11 @@ trait SystemSettingsService {
|
|||||||
getOptionValue(props, LdapBindPassword, None),
|
getOptionValue(props, LdapBindPassword, None),
|
||||||
getValue(props, LdapBaseDN, ""),
|
getValue(props, LdapBaseDN, ""),
|
||||||
getValue(props, LdapUserNameAttribute, ""),
|
getValue(props, LdapUserNameAttribute, ""),
|
||||||
|
getOptionValue(props, LdapAdditionalFilterCondition, None),
|
||||||
getOptionValue(props, LdapFullNameAttribute, None),
|
getOptionValue(props, LdapFullNameAttribute, None),
|
||||||
getValue(props, LdapMailAddressAttribute, ""),
|
getOptionValue(props, LdapMailAddressAttribute, None),
|
||||||
getOptionValue[Boolean](props, LdapTls, None),
|
getOptionValue[Boolean](props, LdapTls, None),
|
||||||
|
getOptionValue[Boolean](props, LdapSsl, None),
|
||||||
getOptionValue(props, LdapKeystore, None)))
|
getOptionValue(props, LdapKeystore, None)))
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
@@ -103,7 +114,10 @@ object SystemSettingsService {
|
|||||||
|
|
||||||
case class SystemSettings(
|
case class SystemSettings(
|
||||||
baseUrl: Option[String],
|
baseUrl: Option[String],
|
||||||
|
information: Option[String],
|
||||||
allowAccountRegistration: Boolean,
|
allowAccountRegistration: Boolean,
|
||||||
|
allowAnonymousAccess: Boolean,
|
||||||
|
isCreateRepoOptionPublic: Boolean,
|
||||||
gravatar: Boolean,
|
gravatar: Boolean,
|
||||||
notification: Boolean,
|
notification: Boolean,
|
||||||
ssh: Boolean,
|
ssh: Boolean,
|
||||||
@@ -125,9 +139,11 @@ object SystemSettingsService {
|
|||||||
bindPassword: Option[String],
|
bindPassword: Option[String],
|
||||||
baseDN: String,
|
baseDN: String,
|
||||||
userNameAttribute: String,
|
userNameAttribute: String,
|
||||||
|
additionalFilterCondition: Option[String],
|
||||||
fullNameAttribute: Option[String],
|
fullNameAttribute: Option[String],
|
||||||
mailAttribute: String,
|
mailAttribute: Option[String],
|
||||||
tls: Option[Boolean],
|
tls: Option[Boolean],
|
||||||
|
ssl: Option[Boolean],
|
||||||
keystore: Option[String])
|
keystore: Option[String])
|
||||||
|
|
||||||
case class Smtp(
|
case class Smtp(
|
||||||
@@ -144,7 +160,10 @@ object SystemSettingsService {
|
|||||||
val DefaultLdapPort = 389
|
val DefaultLdapPort = 389
|
||||||
|
|
||||||
private val BaseURL = "base_url"
|
private val BaseURL = "base_url"
|
||||||
|
private val Information = "information"
|
||||||
private val AllowAccountRegistration = "allow_account_registration"
|
private val AllowAccountRegistration = "allow_account_registration"
|
||||||
|
private val AllowAnonymousAccess = "allow_anonymous_access"
|
||||||
|
private val IsCreateRepoOptionPublic = "is_create_repository_option_public"
|
||||||
private val Gravatar = "gravatar"
|
private val Gravatar = "gravatar"
|
||||||
private val Notification = "notification"
|
private val Notification = "notification"
|
||||||
private val Ssh = "ssh"
|
private val Ssh = "ssh"
|
||||||
@@ -163,9 +182,11 @@ object SystemSettingsService {
|
|||||||
private val LdapBindPassword = "ldap.bind_password"
|
private val LdapBindPassword = "ldap.bind_password"
|
||||||
private val LdapBaseDN = "ldap.baseDN"
|
private val LdapBaseDN = "ldap.baseDN"
|
||||||
private val LdapUserNameAttribute = "ldap.username_attribute"
|
private val LdapUserNameAttribute = "ldap.username_attribute"
|
||||||
|
private val LdapAdditionalFilterCondition = "ldap.additional_filter_condition"
|
||||||
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
private val LdapFullNameAttribute = "ldap.fullname_attribute"
|
||||||
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
private val LdapMailAddressAttribute = "ldap.mail_attribute"
|
||||||
private val LdapTls = "ldap.tls"
|
private val LdapTls = "ldap.tls"
|
||||||
|
private val LdapSsl = "ldap.ssl"
|
||||||
private val LdapKeystore = "ldap.keystore"
|
private val LdapKeystore = "ldap.keystore"
|
||||||
|
|
||||||
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
private def getValue[A: ClassTag](props: java.util.Properties, key: String, default: A): A =
|
||||||
@@ -187,4 +208,7 @@ object SystemSettingsService {
|
|||||||
else value
|
else value
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// // TODO temporary flag
|
||||||
|
// val enablePluginSystem = Option(System.getProperty("enable.plugin")).getOrElse("false").toBoolean
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -1,12 +1,14 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import model._
|
import gitbucket.core.model.{WebHook, Account}
|
||||||
import simple._
|
import gitbucket.core.model.Profile._
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
import gitbucket.core.util.JGitUtil
|
||||||
|
import profile.simple._
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import service.RepositoryService.RepositoryInfo
|
import RepositoryService.RepositoryInfo
|
||||||
import util.JGitUtil
|
|
||||||
import org.eclipse.jgit.diff.DiffEntry
|
import org.eclipse.jgit.diff.DiffEntry
|
||||||
import util.JGitUtil.CommitInfo
|
import JGitUtil.CommitInfo
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.apache.http.message.BasicNameValuePair
|
import org.apache.http.message.BasicNameValuePair
|
||||||
import org.apache.http.client.entity.UrlEncodedFormEntity
|
import org.apache.http.client.entity.UrlEncodedFormEntity
|
||||||
@@ -43,7 +45,7 @@ trait WebHookService {
|
|||||||
val httpClient = HttpClientBuilder.create.build
|
val httpClient = HttpClientBuilder.create.build
|
||||||
|
|
||||||
webHookURLs.foreach { webHookUrl =>
|
webHookURLs.foreach { webHookUrl =>
|
||||||
val f = future {
|
val f = Future {
|
||||||
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
logger.debug(s"start web hook invocation for ${webHookUrl}")
|
||||||
val httpPost = new HttpPost(webHookUrl.url)
|
val httpPost = new HttpPost(webHookUrl.url)
|
||||||
|
|
||||||
@@ -89,15 +91,15 @@ object WebHookService {
|
|||||||
WebHookCommit(
|
WebHookCommit(
|
||||||
id = commit.id,
|
id = commit.id,
|
||||||
message = commit.fullMessage,
|
message = commit.fullMessage,
|
||||||
timestamp = commit.time.toString,
|
timestamp = commit.commitTime.toString,
|
||||||
url = commitUrl,
|
url = commitUrl,
|
||||||
added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath },
|
added = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.ADD) => x.newPath },
|
||||||
removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath },
|
removed = diffs._1.collect { case x if(x.changeType == DiffEntry.ChangeType.DELETE) => x.oldPath },
|
||||||
modified = diffs._1.collect { case x if(x.changeType != DiffEntry.ChangeType.ADD &&
|
modified = diffs._1.collect { case x if(x.changeType != DiffEntry.ChangeType.ADD &&
|
||||||
x.changeType != DiffEntry.ChangeType.DELETE) => x.newPath },
|
x.changeType != DiffEntry.ChangeType.DELETE) => x.newPath },
|
||||||
author = WebHookUser(
|
author = WebHookUser(
|
||||||
name = commit.committer,
|
name = commit.committerName,
|
||||||
email = commit.mailAddress
|
email = commit.committerEmailAddress
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package service
|
package gitbucket.core.service
|
||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
import gitbucket.core.model.Account
|
||||||
|
import gitbucket.core.util._
|
||||||
|
import gitbucket.core.util.ControlUtil._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import util._
|
|
||||||
import _root_.util.ControlUtil._
|
|
||||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.lib._
|
||||||
import org.eclipse.jgit.dircache.DirCache
|
import org.eclipse.jgit.dircache.DirCache
|
||||||
@@ -12,7 +13,7 @@ import java.io.ByteArrayInputStream
|
|||||||
import org.eclipse.jgit.patch._
|
import org.eclipse.jgit.patch._
|
||||||
import org.eclipse.jgit.api.errors.PatchFormatException
|
import org.eclipse.jgit.api.errors.PatchFormatException
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
import service.RepositoryService.RepositoryInfo
|
import RepositoryService.RepositoryInfo
|
||||||
|
|
||||||
object WikiService {
|
object WikiService {
|
||||||
|
|
||||||
@@ -46,7 +47,7 @@ object WikiService {
|
|||||||
trait WikiService {
|
trait WikiService {
|
||||||
import WikiService._
|
import WikiService._
|
||||||
|
|
||||||
def createWikiRepository(loginAccount: model.Account, owner: String, repository: String): Unit =
|
def createWikiRepository(loginAccount: Account, owner: String, repository: String): Unit =
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
defining(Directory.getWikiRepositoryDir(owner, repository)){ dir =>
|
defining(Directory.getWikiRepositoryDir(owner, repository)){ dir =>
|
||||||
if(!dir.exists){
|
if(!dir.exists){
|
||||||
@@ -64,7 +65,7 @@ trait WikiService {
|
|||||||
if(!JGitUtil.isEmpty(git)){
|
if(!JGitUtil.isEmpty(git)){
|
||||||
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
JGitUtil.getFileList(git, "master", ".").find(_.name == pageName + ".md").map { file =>
|
||||||
WikiPageInfo(file.name, StringUtil.convertFromByteArray(git.getRepository.open(file.id).getBytes),
|
WikiPageInfo(file.name, StringUtil.convertFromByteArray(git.getRepository.open(file.id).getBytes),
|
||||||
file.committer, file.time, file.commitId)
|
file.author, file.time, file.commitId)
|
||||||
}
|
}
|
||||||
} else None
|
} else None
|
||||||
}
|
}
|
||||||
@@ -102,7 +103,7 @@ trait WikiService {
|
|||||||
* Reverts specified changes.
|
* Reverts specified changes.
|
||||||
*/
|
*/
|
||||||
def revertWikiPage(owner: String, repository: String, from: String, to: String,
|
def revertWikiPage(owner: String, repository: String, from: String, to: String,
|
||||||
committer: model.Account, pageName: Option[String]): Boolean = {
|
committer: Account, pageName: Option[String]): Boolean = {
|
||||||
|
|
||||||
case class RevertInfo(operation: String, filePath: String, source: String)
|
case class RevertInfo(operation: String, filePath: String, source: String)
|
||||||
|
|
||||||
@@ -182,7 +183,8 @@ trait WikiService {
|
|||||||
}
|
}
|
||||||
builder.finish()
|
builder.finish()
|
||||||
|
|
||||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
||||||
|
Constants.HEAD, committer.fullName, committer.mailAddress,
|
||||||
pageName match {
|
pageName match {
|
||||||
case Some(x) => s"Revert ${from} ... ${to} on ${x}"
|
case Some(x) => s"Revert ${from} ... ${to} on ${x}"
|
||||||
case None => s"Revert ${from} ... ${to}"
|
case None => s"Revert ${from} ... ${to}"
|
||||||
@@ -203,7 +205,7 @@ trait WikiService {
|
|||||||
* Save the wiki page.
|
* Save the wiki page.
|
||||||
*/
|
*/
|
||||||
def saveWikiPage(owner: String, repository: String, currentPageName: String, newPageName: String,
|
def saveWikiPage(owner: String, repository: String, currentPageName: String, newPageName: String,
|
||||||
content: String, committer: model.Account, message: String, currentId: Option[String]): Option[String] = {
|
content: String, committer: Account, message: String, currentId: Option[String]): Option[String] = {
|
||||||
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
LockUtil.lock(s"${owner}/${repository}/wiki"){
|
||||||
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
using(Git.open(Directory.getWikiRepositoryDir(owner, repository))){ git =>
|
||||||
val builder = DirCache.newInCore.builder()
|
val builder = DirCache.newInCore.builder()
|
||||||
@@ -229,7 +231,8 @@ trait WikiService {
|
|||||||
if(created || updated || removed){
|
if(created || updated || removed){
|
||||||
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
builder.add(JGitUtil.createDirCacheEntry(newPageName + ".md", FileMode.REGULAR_FILE, inserter.insert(Constants.OBJ_BLOB, content.getBytes("UTF-8"))))
|
||||||
builder.finish()
|
builder.finish()
|
||||||
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer.fullName, committer.mailAddress,
|
val newHeadId = JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
||||||
|
Constants.HEAD, committer.fullName, committer.mailAddress,
|
||||||
if(message.trim.length == 0) {
|
if(message.trim.length == 0) {
|
||||||
if(removed){
|
if(removed){
|
||||||
s"Rename ${currentPageName} to ${newPageName}"
|
s"Rename ${currentPageName} to ${newPageName}"
|
||||||
@@ -269,7 +272,8 @@ trait WikiService {
|
|||||||
}
|
}
|
||||||
if(removed){
|
if(removed){
|
||||||
builder.finish()
|
builder.finish()
|
||||||
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter), committer, mailAddress, message)
|
JGitUtil.createNewCommit(git, inserter, headId, builder.getDirCache.writeTree(inserter),
|
||||||
|
Constants.HEAD, committer, mailAddress, message)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package gitbucket.core.servlet
|
||||||
|
|
||||||
|
import javax.servlet._
|
||||||
|
import javax.servlet.http._
|
||||||
|
import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService}
|
||||||
|
import gitbucket.core.util.{ControlUtil, Keys, Implicits}
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import Implicits._
|
||||||
|
import ControlUtil._
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Provides BASIC Authentication for [[GitRepositoryServlet]].
|
||||||
|
*/
|
||||||
|
class BasicAuthenticationFilter extends Filter with RepositoryService with AccountService with SystemSettingsService {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[BasicAuthenticationFilter])
|
||||||
|
|
||||||
|
def init(config: FilterConfig) = {}
|
||||||
|
|
||||||
|
def destroy(): Unit = {}
|
||||||
|
|
||||||
|
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = {
|
||||||
|
implicit val request = req.asInstanceOf[HttpServletRequest]
|
||||||
|
val response = res.asInstanceOf[HttpServletResponse]
|
||||||
|
|
||||||
|
val wrappedResponse = new HttpServletResponseWrapper(response){
|
||||||
|
override def setCharacterEncoding(encoding: String) = {}
|
||||||
|
}
|
||||||
|
|
||||||
|
val isUpdating = request.getRequestURI.endsWith("/git-receive-pack") || "service=git-receive-pack".equals(request.getQueryString)
|
||||||
|
|
||||||
|
val settings = loadSystemSettings()
|
||||||
|
|
||||||
|
try {
|
||||||
|
defining(request.paths){
|
||||||
|
case Array(_, repositoryOwner, repositoryName, _*) =>
|
||||||
|
getRepository(repositoryOwner, repositoryName.replaceFirst("\\.wiki\\.git$|\\.git$", ""), "") match {
|
||||||
|
case Some(repository) => {
|
||||||
|
if(!isUpdating && !repository.repository.isPrivate && settings.allowAnonymousAccess){
|
||||||
|
chain.doFilter(req, wrappedResponse)
|
||||||
|
} else {
|
||||||
|
request.getHeader("Authorization") match {
|
||||||
|
case null => requireAuth(response)
|
||||||
|
case auth => decodeAuthHeader(auth).split(":") match {
|
||||||
|
case Array(username, password) => {
|
||||||
|
authenticate(settings, username, password) match {
|
||||||
|
case Some(account) => {
|
||||||
|
if(isUpdating && hasWritePermission(repository.owner, repository.name, Some(account))){
|
||||||
|
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||||
|
}
|
||||||
|
chain.doFilter(req, wrappedResponse)
|
||||||
|
}
|
||||||
|
case None => requireAuth(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _ => requireAuth(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case None => {
|
||||||
|
logger.debug(s"Repository ${repositoryOwner}/${repositoryName} is not found.")
|
||||||
|
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _ => {
|
||||||
|
logger.debug(s"Not enough path arguments: ${request.paths}")
|
||||||
|
response.sendError(HttpServletResponse.SC_NOT_FOUND)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
case ex: Exception => {
|
||||||
|
logger.error("error", ex)
|
||||||
|
requireAuth(response)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private def requireAuth(response: HttpServletResponse): Unit = {
|
||||||
|
response.setHeader("WWW-Authenticate", "BASIC realm=\"GitBucket\"")
|
||||||
|
response.sendError(HttpServletResponse.SC_UNAUTHORIZED)
|
||||||
|
}
|
||||||
|
|
||||||
|
private def decodeAuthHeader(header: String): String = {
|
||||||
|
try {
|
||||||
|
new String(new sun.misc.BASE64Decoder().decodeBuffer(header.substring(6)))
|
||||||
|
} catch {
|
||||||
|
case _: Throwable => ""
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,5 +1,8 @@
|
|||||||
package servlet
|
package gitbucket.core.servlet
|
||||||
|
|
||||||
|
import gitbucket.core.model.Session
|
||||||
|
import gitbucket.core.service._
|
||||||
|
import gitbucket.core.util._
|
||||||
import org.eclipse.jgit.http.server.GitServlet
|
import org.eclipse.jgit.http.server.GitServlet
|
||||||
import org.eclipse.jgit.lib._
|
import org.eclipse.jgit.lib._
|
||||||
import org.eclipse.jgit.transport._
|
import org.eclipse.jgit.transport._
|
||||||
@@ -9,21 +12,19 @@ import org.slf4j.LoggerFactory
|
|||||||
import javax.servlet.ServletConfig
|
import javax.servlet.ServletConfig
|
||||||
import javax.servlet.ServletContext
|
import javax.servlet.ServletContext
|
||||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||||
import util.{StringUtil, Keys, JGitUtil, Directory}
|
import gitbucket.core.util.StringUtil
|
||||||
import util.ControlUtil._
|
import gitbucket.core.util.ControlUtil._
|
||||||
import util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import service._
|
|
||||||
import WebHookService._
|
import WebHookService._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import util.JGitUtil.CommitInfo
|
import JGitUtil.CommitInfo
|
||||||
import service.IssuesService.IssueSearchCondition
|
import IssuesService.IssueSearchCondition
|
||||||
import slick.jdbc.JdbcBackend
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Git repository via HTTP.
|
* Provides Git repository via HTTP.
|
||||||
*
|
*
|
||||||
* This servlet provides only Git repository functionality.
|
* This servlet provides only Git repository functionality.
|
||||||
* Authentication is provided by [[servlet.BasicAuthenticationFilter]].
|
* Authentication is provided by [[BasicAuthenticationFilter]].
|
||||||
*/
|
*/
|
||||||
class GitRepositoryServlet extends GitServlet with SystemSettingsService {
|
class GitRepositoryServlet extends GitServlet with SystemSettingsService {
|
||||||
|
|
||||||
@@ -95,7 +96,7 @@ class GitBucketReceivePackFactory extends ReceivePackFactory[HttpServletRequest]
|
|||||||
|
|
||||||
import scala.collection.JavaConverters._
|
import scala.collection.JavaConverters._
|
||||||
|
|
||||||
class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: JdbcBackend#Session)
|
class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl: String)(implicit session: Session)
|
||||||
extends PostReceiveHook with PreReceiveHook
|
extends PostReceiveHook with PreReceiveHook
|
||||||
with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService {
|
with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService {
|
||||||
|
|
||||||
@@ -134,8 +135,8 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
|
|
||||||
// Retrieve all issue count in the repository
|
// Retrieve all issue count in the repository
|
||||||
val issueCount =
|
val issueCount =
|
||||||
countIssue(IssueSearchCondition(state = "open"), Map.empty, false, owner -> repository) +
|
countIssue(IssueSearchCondition(state = "open"), false, owner -> repository) +
|
||||||
countIssue(IssueSearchCondition(state = "closed"), Map.empty, false, owner -> repository)
|
countIssue(IssueSearchCondition(state = "closed"), false, owner -> repository)
|
||||||
|
|
||||||
// Extract new commit and apply issue comment
|
// Extract new commit and apply issue comment
|
||||||
val defaultBranch = getRepository(owner, repository, baseUrl).get.repository.defaultBranch
|
val defaultBranch = getRepository(owner, repository, baseUrl).get.repository.defaultBranch
|
||||||
@@ -174,7 +175,7 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
case ReceiveCommand.Type.CREATE |
|
case ReceiveCommand.Type.CREATE |
|
||||||
ReceiveCommand.Type.UPDATE |
|
ReceiveCommand.Type.UPDATE |
|
||||||
ReceiveCommand.Type.UPDATE_NONFASTFORWARD =>
|
ReceiveCommand.Type.UPDATE_NONFASTFORWARD =>
|
||||||
updatePullRequests(branchName)
|
updatePullRequests(owner, repository, branchName)
|
||||||
case _ =>
|
case _ =>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -205,32 +206,10 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
|||||||
private def createIssueComment(commit: CommitInfo) = {
|
private def createIssueComment(commit: CommitInfo) = {
|
||||||
StringUtil.extractIssueId(commit.fullMessage).foreach { issueId =>
|
StringUtil.extractIssueId(commit.fullMessage).foreach { issueId =>
|
||||||
if(getIssue(owner, repository, issueId).isDefined){
|
if(getIssue(owner, repository, issueId).isDefined){
|
||||||
getAccountByMailAddress(commit.mailAddress).foreach { account =>
|
getAccountByMailAddress(commit.committerEmailAddress).foreach { account =>
|
||||||
createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit")
|
createComment(owner, repository, account.userName, issueId.toInt, commit.fullMessage + " " + commit.id, "commit")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Fetch pull request contents into refs/pull/${issueId}/head and update pull request table.
|
|
||||||
*/
|
|
||||||
private def updatePullRequests(branch: String) =
|
|
||||||
getPullRequestsByRequest(owner, repository, branch, false).foreach { pullreq =>
|
|
||||||
if(getRepository(pullreq.userName, pullreq.repositoryName, baseUrl).isDefined){
|
|
||||||
using(Git.open(Directory.getRepositoryDir(pullreq.userName, pullreq.repositoryName)),
|
|
||||||
Git.open(Directory.getRepositoryDir(pullreq.requestUserName, pullreq.requestRepositoryName))){ (oldGit, newGit) =>
|
|
||||||
oldGit.fetch
|
|
||||||
.setRemote(Directory.getRepositoryDir(owner, repository).toURI.toString)
|
|
||||||
.setRefSpecs(new RefSpec(s"refs/heads/${branch}:refs/pull/${pullreq.issueId}/head").setForceUpdate(true))
|
|
||||||
.call
|
|
||||||
|
|
||||||
val commitIdTo = oldGit.getRepository.resolve(s"refs/pull/${pullreq.issueId}/head").getName
|
|
||||||
val commitIdFrom = JGitUtil.getForkedCommitId(oldGit, newGit,
|
|
||||||
pullreq.userName, pullreq.repositoryName, pullreq.branch,
|
|
||||||
pullreq.requestUserName, pullreq.requestRepositoryName, pullreq.requestBranch)
|
|
||||||
updateCommitId(pullreq.userName, pullreq.repositoryName, pullreq.issueId, commitIdTo, commitIdFrom)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
207
src/main/scala/gitbucket/core/servlet/InitializeListener.scala
Normal file
207
src/main/scala/gitbucket/core/servlet/InitializeListener.scala
Normal file
@@ -0,0 +1,207 @@
|
|||||||
|
package gitbucket.core.servlet
|
||||||
|
|
||||||
|
import java.io.File
|
||||||
|
import java.sql.{DriverManager, Connection}
|
||||||
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
|
import gitbucket.core.util._
|
||||||
|
import org.apache.commons.io.FileUtils
|
||||||
|
import javax.servlet.{ServletContextListener, ServletContextEvent}
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import Directory._
|
||||||
|
import ControlUtil._
|
||||||
|
import JDBCUtil._
|
||||||
|
import org.eclipse.jgit.api.Git
|
||||||
|
import gitbucket.core.util.Versions
|
||||||
|
import gitbucket.core.util.Directory
|
||||||
|
import gitbucket.core.plugin._
|
||||||
|
|
||||||
|
object AutoUpdate {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The history of versions. A head of this sequence is the current BitBucket version.
|
||||||
|
*/
|
||||||
|
val versions = Seq(
|
||||||
|
new Version(3, 0),
|
||||||
|
new Version(2, 8),
|
||||||
|
new Version(2, 7) {
|
||||||
|
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||||
|
super.update(conn, cl)
|
||||||
|
conn.select("SELECT * FROM REPOSITORY"){ rs =>
|
||||||
|
// Rename attached files directory from /issues to /comments
|
||||||
|
val userName = rs.getString("USER_NAME")
|
||||||
|
val repoName = rs.getString("REPOSITORY_NAME")
|
||||||
|
defining(Directory.getAttachedDir(userName, repoName)){ newDir =>
|
||||||
|
val oldDir = new File(newDir.getParentFile, "issues")
|
||||||
|
if(oldDir.exists && oldDir.isDirectory){
|
||||||
|
oldDir.renameTo(newDir)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME if it does not exist
|
||||||
|
val originalUserName = rs.getString("ORIGIN_USER_NAME")
|
||||||
|
val originalRepoName = rs.getString("ORIGIN_REPOSITORY_NAME")
|
||||||
|
if(originalUserName != null && originalRepoName != null){
|
||||||
|
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||||
|
originalUserName, originalRepoName) == 0){
|
||||||
|
conn.update("UPDATE REPOSITORY SET ORIGIN_USER_NAME = NULL, ORIGIN_REPOSITORY_NAME = NULL " +
|
||||||
|
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Update PARENT_USER_NAME and PARENT_REPOSITORY_NAME if it does not exist
|
||||||
|
val parentUserName = rs.getString("PARENT_USER_NAME")
|
||||||
|
val parentRepoName = rs.getString("PARENT_REPOSITORY_NAME")
|
||||||
|
if(parentUserName != null && parentRepoName != null){
|
||||||
|
if(conn.selectInt("SELECT COUNT(*) FROM REPOSITORY WHERE USER_NAME = ? AND REPOSITORY_NAME = ?",
|
||||||
|
parentUserName, parentRepoName) == 0){
|
||||||
|
conn.update("UPDATE REPOSITORY SET PARENT_USER_NAME = NULL, PARENT_REPOSITORY_NAME = NULL " +
|
||||||
|
"WHERE USER_NAME = ? AND REPOSITORY_NAME = ?", userName, repoName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Version(2, 6),
|
||||||
|
new Version(2, 5),
|
||||||
|
new Version(2, 4),
|
||||||
|
new Version(2, 3) {
|
||||||
|
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||||
|
super.update(conn, cl)
|
||||||
|
conn.select("SELECT ACTIVITY_ID, ADDITIONAL_INFO FROM ACTIVITY WHERE ACTIVITY_TYPE='push'"){ rs =>
|
||||||
|
val curInfo = rs.getString("ADDITIONAL_INFO")
|
||||||
|
val newInfo = curInfo.split("\n").filter(_ matches "^[0-9a-z]{40}:.*").mkString("\n")
|
||||||
|
if (curInfo != newInfo) {
|
||||||
|
conn.update("UPDATE ACTIVITY SET ADDITIONAL_INFO = ? WHERE ACTIVITY_ID = ?", newInfo, rs.getInt("ACTIVITY_ID"))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ignore {
|
||||||
|
FileUtils.deleteDirectory(Directory.getPluginCacheDir())
|
||||||
|
//FileUtils.deleteDirectory(new File(Directory.PluginHome))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new Version(2, 2),
|
||||||
|
new Version(2, 1),
|
||||||
|
new Version(2, 0){
|
||||||
|
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||||
|
import eu.medsea.mimeutil.{MimeUtil2, MimeType}
|
||||||
|
|
||||||
|
val mimeUtil = new MimeUtil2()
|
||||||
|
mimeUtil.registerMimeDetector("eu.medsea.mimeutil.detector.MagicMimeMimeDetector")
|
||||||
|
|
||||||
|
super.update(conn, cl)
|
||||||
|
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||||
|
defining(Directory.getAttachedDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME"))){ dir =>
|
||||||
|
if(dir.exists && dir.isDirectory){
|
||||||
|
dir.listFiles.foreach { file =>
|
||||||
|
if(file.getName.indexOf('.') < 0){
|
||||||
|
val mimeType = MimeUtil2.getMostSpecificMimeType(mimeUtil.getMimeTypes(file, new MimeType("application/octet-stream"))).toString
|
||||||
|
if(mimeType.startsWith("image/")){
|
||||||
|
file.renameTo(new File(file.getParent, file.getName + "." + mimeType.split("/")(1)))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Version(1, 13),
|
||||||
|
Version(1, 12),
|
||||||
|
Version(1, 11),
|
||||||
|
Version(1, 10),
|
||||||
|
Version(1, 9),
|
||||||
|
Version(1, 8),
|
||||||
|
Version(1, 7),
|
||||||
|
Version(1, 6),
|
||||||
|
Version(1, 5),
|
||||||
|
Version(1, 4),
|
||||||
|
new Version(1, 3){
|
||||||
|
override def update(conn: Connection, cl: ClassLoader): Unit = {
|
||||||
|
super.update(conn, cl)
|
||||||
|
// Fix wiki repository configuration
|
||||||
|
conn.select("SELECT USER_NAME, REPOSITORY_NAME FROM REPOSITORY"){ rs =>
|
||||||
|
using(Git.open(getWikiRepositoryDir(rs.getString("USER_NAME"), rs.getString("REPOSITORY_NAME")))){ git =>
|
||||||
|
defining(git.getRepository.getConfig){ config =>
|
||||||
|
if(!config.getBoolean("http", "receivepack", false)){
|
||||||
|
config.setBoolean("http", null, "receivepack", true)
|
||||||
|
config.save
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Version(1, 2),
|
||||||
|
Version(1, 1),
|
||||||
|
Version(1, 0),
|
||||||
|
Version(0, 0)
|
||||||
|
)
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The head version of BitBucket.
|
||||||
|
*/
|
||||||
|
val headVersion = versions.head
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The version file (GITBUCKET_HOME/version).
|
||||||
|
*/
|
||||||
|
lazy val versionFile = new File(GitBucketHome, "version")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the current version from the version file.
|
||||||
|
*/
|
||||||
|
def getCurrentVersion(): Version = {
|
||||||
|
if(versionFile.exists){
|
||||||
|
FileUtils.readFileToString(versionFile, "UTF-8").trim.split("\\.") match {
|
||||||
|
case Array(majorVersion, minorVersion) => {
|
||||||
|
versions.find { v =>
|
||||||
|
v.majorVersion == majorVersion.toInt && v.minorVersion == minorVersion.toInt
|
||||||
|
}.getOrElse(Version(0, 0))
|
||||||
|
}
|
||||||
|
case _ => Version(0, 0)
|
||||||
|
}
|
||||||
|
} else Version(0, 0)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize GitBucket system.
|
||||||
|
* Update database schema and load plug-ins automatically in the context initializing.
|
||||||
|
*/
|
||||||
|
class InitializeListener extends ServletContextListener {
|
||||||
|
import AutoUpdate._
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[InitializeListener])
|
||||||
|
|
||||||
|
override def contextInitialized(event: ServletContextEvent): Unit = {
|
||||||
|
val dataDir = event.getServletContext.getInitParameter("gitbucket.home")
|
||||||
|
if(dataDir != null){
|
||||||
|
System.setProperty("gitbucket.home", dataDir)
|
||||||
|
}
|
||||||
|
org.h2.Driver.load()
|
||||||
|
|
||||||
|
defining(getConnection()){ conn =>
|
||||||
|
// Migration
|
||||||
|
logger.debug("Start schema update")
|
||||||
|
Versions.update(conn, headVersion, getCurrentVersion(), versions, Thread.currentThread.getContextClassLoader){ conn =>
|
||||||
|
FileUtils.writeStringToFile(versionFile, headVersion.versionString, "UTF-8")
|
||||||
|
}
|
||||||
|
// Load plugins
|
||||||
|
logger.debug("Initialize plugins")
|
||||||
|
PluginRegistry.initialize(event.getServletContext, conn)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
def contextDestroyed(event: ServletContextEvent): Unit = {
|
||||||
|
// Shutdown plugins
|
||||||
|
PluginRegistry.shutdown(event.getServletContext)
|
||||||
|
}
|
||||||
|
|
||||||
|
private def getConnection(): Connection =
|
||||||
|
DriverManager.getConnection(
|
||||||
|
DatabaseConfig.url,
|
||||||
|
DatabaseConfig.user,
|
||||||
|
DatabaseConfig.password)
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,8 +1,9 @@
|
|||||||
package servlet
|
package gitbucket.core.servlet
|
||||||
|
|
||||||
import javax.servlet.http.{HttpSessionEvent, HttpSessionListener}
|
import javax.servlet.http.{HttpSessionEvent, HttpSessionListener}
|
||||||
|
import gitbucket.core.util.Directory
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import util.Directory._
|
import Directory._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes session associated temporary files when session is destroyed.
|
* Removes session associated temporary files when session is destroyed.
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
package gitbucket.core.servlet
|
||||||
|
|
||||||
|
import javax.servlet._
|
||||||
|
import javax.servlet.http.HttpServletRequest
|
||||||
|
import com.mchange.v2.c3p0.ComboPooledDataSource
|
||||||
|
import gitbucket.core.util.DatabaseConfig
|
||||||
|
import org.slf4j.LoggerFactory
|
||||||
|
import slick.jdbc.JdbcBackend.{Database => SlickDatabase, Session}
|
||||||
|
import gitbucket.core.util.Keys
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Controls the transaction with the open session in view pattern.
|
||||||
|
*/
|
||||||
|
class TransactionFilter extends Filter {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(classOf[TransactionFilter])
|
||||||
|
|
||||||
|
def init(config: FilterConfig) = {}
|
||||||
|
|
||||||
|
def destroy(): Unit = {}
|
||||||
|
|
||||||
|
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = {
|
||||||
|
if(req.asInstanceOf[HttpServletRequest].getRequestURI().startsWith("/assets/")){
|
||||||
|
// assets don't need transaction
|
||||||
|
chain.doFilter(req, res)
|
||||||
|
} else {
|
||||||
|
Database() withTransaction { session =>
|
||||||
|
logger.debug("begin transaction")
|
||||||
|
req.setAttribute(Keys.Request.DBSession, session)
|
||||||
|
chain.doFilter(req, res)
|
||||||
|
logger.debug("end transaction")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
object Database {
|
||||||
|
|
||||||
|
private val logger = LoggerFactory.getLogger(Database.getClass)
|
||||||
|
|
||||||
|
private val db: SlickDatabase = {
|
||||||
|
val datasource = new ComboPooledDataSource
|
||||||
|
|
||||||
|
datasource.setDriverClass(DatabaseConfig.driver)
|
||||||
|
datasource.setJdbcUrl(DatabaseConfig.url)
|
||||||
|
datasource.setUser(DatabaseConfig.user)
|
||||||
|
datasource.setPassword(DatabaseConfig.password)
|
||||||
|
|
||||||
|
logger.debug("load database connection pool")
|
||||||
|
|
||||||
|
SlickDatabase.forDataSource(datasource)
|
||||||
|
}
|
||||||
|
|
||||||
|
def apply(): SlickDatabase = db
|
||||||
|
|
||||||
|
def getSession(req: ServletRequest): Session =
|
||||||
|
req.getAttribute(Keys.Request.DBSession).asInstanceOf[Session]
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,24 +1,24 @@
|
|||||||
package ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
|
import gitbucket.core.model.Session
|
||||||
|
import gitbucket.core.service.{RepositoryService, AccountService, SystemSettingsService}
|
||||||
|
import gitbucket.core.servlet.{Database, CommitLogHook}
|
||||||
|
import gitbucket.core.util.{Directory, ControlUtil}
|
||||||
import org.apache.sshd.server.{CommandFactory, Environment, ExitCallback, Command}
|
import org.apache.sshd.server.{CommandFactory, Environment, ExitCallback, Command}
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import java.io.{InputStream, OutputStream}
|
import java.io.{InputStream, OutputStream}
|
||||||
import util.ControlUtil._
|
import ControlUtil._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import util.Directory._
|
import Directory._
|
||||||
import org.eclipse.jgit.transport.{ReceivePack, UploadPack}
|
import org.eclipse.jgit.transport.{ReceivePack, UploadPack}
|
||||||
import org.apache.sshd.server.command.UnknownCommand
|
import org.apache.sshd.server.command.UnknownCommand
|
||||||
import servlet.{Database, CommitLogHook}
|
|
||||||
import service.{AccountService, RepositoryService, SystemSettingsService}
|
|
||||||
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
||||||
import javax.servlet.ServletContext
|
|
||||||
import model.profile.simple.Session
|
|
||||||
|
|
||||||
object GitCommand {
|
object GitCommand {
|
||||||
val CommandRegex = """\Agit-(upload|receive)-pack '/([a-zA-Z0-9\-_.]+)/([a-zA-Z0-9\-_.]+).git'\Z""".r
|
val CommandRegex = """\Agit-(upload|receive)-pack '/([a-zA-Z0-9\-_.]+)/([a-zA-Z0-9\-_.]+).git'\Z""".r
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class GitCommand(val context: ServletContext, val owner: String, val repoName: String) extends Command {
|
abstract class GitCommand(val owner: String, val repoName: String) extends Command {
|
||||||
self: RepositoryService with AccountService =>
|
self: RepositoryService with AccountService =>
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[GitCommand])
|
private val logger = LoggerFactory.getLogger(classOf[GitCommand])
|
||||||
@@ -31,7 +31,7 @@ abstract class GitCommand(val context: ServletContext, val owner: String, val re
|
|||||||
|
|
||||||
private def newTask(user: String): Runnable = new Runnable {
|
private def newTask(user: String): Runnable = new Runnable {
|
||||||
override def run(): Unit = {
|
override def run(): Unit = {
|
||||||
Database(context) withTransaction { implicit session =>
|
Database() withSession { implicit session =>
|
||||||
try {
|
try {
|
||||||
runTask(user)
|
runTask(user)
|
||||||
callback.onExit(0)
|
callback.onExit(0)
|
||||||
@@ -80,7 +80,7 @@ abstract class GitCommand(val context: ServletContext, val owner: String, val re
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitUploadPack(context: ServletContext, owner: String, repoName: String, baseUrl: String) extends GitCommand(context, owner, repoName)
|
class GitUploadPack(owner: String, repoName: String, baseUrl: String) extends GitCommand(owner, repoName)
|
||||||
with RepositoryService with AccountService {
|
with RepositoryService with AccountService {
|
||||||
|
|
||||||
override protected def runTask(user: String)(implicit session: Session): Unit = {
|
override protected def runTask(user: String)(implicit session: Session): Unit = {
|
||||||
@@ -97,7 +97,7 @@ class GitUploadPack(context: ServletContext, owner: String, repoName: String, ba
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitReceivePack(context: ServletContext, owner: String, repoName: String, baseUrl: String) extends GitCommand(context, owner, repoName)
|
class GitReceivePack(owner: String, repoName: String, baseUrl: String) extends GitCommand(owner, repoName)
|
||||||
with SystemSettingsService with RepositoryService with AccountService {
|
with SystemSettingsService with RepositoryService with AccountService {
|
||||||
|
|
||||||
override protected def runTask(user: String)(implicit session: Session): Unit = {
|
override protected def runTask(user: String)(implicit session: Session): Unit = {
|
||||||
@@ -119,15 +119,15 @@ class GitReceivePack(context: ServletContext, owner: String, repoName: String, b
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class GitCommandFactory(context: ServletContext, baseUrl: String) extends CommandFactory {
|
class GitCommandFactory(baseUrl: String) extends CommandFactory {
|
||||||
private val logger = LoggerFactory.getLogger(classOf[GitCommandFactory])
|
private val logger = LoggerFactory.getLogger(classOf[GitCommandFactory])
|
||||||
|
|
||||||
override def createCommand(command: String): Command = {
|
override def createCommand(command: String): Command = {
|
||||||
logger.debug(s"command: $command")
|
logger.debug(s"command: $command")
|
||||||
command match {
|
command match {
|
||||||
case GitCommand.CommandRegex("upload", owner, repoName) => new GitUploadPack(context, owner, repoName, baseUrl)
|
case GitCommand.CommandRegex("upload", owner, repoName) => new GitUploadPack(owner, repoName, baseUrl)
|
||||||
case GitCommand.CommandRegex("receive", owner, repoName) => new GitReceivePack(context, owner, repoName, baseUrl)
|
case GitCommand.CommandRegex("receive", owner, repoName) => new GitReceivePack(owner, repoName, baseUrl)
|
||||||
case _ => new UnknownCommand(command)
|
case _ => new UnknownCommand(command)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
|
import gitbucket.core.service.SystemSettingsService
|
||||||
import org.apache.sshd.common.Factory
|
import org.apache.sshd.common.Factory
|
||||||
import org.apache.sshd.server.{Environment, ExitCallback, Command}
|
import org.apache.sshd.server.{Environment, ExitCallback, Command}
|
||||||
import java.io.{OutputStream, InputStream}
|
import java.io.{OutputStream, InputStream}
|
||||||
import org.eclipse.jgit.lib.Constants
|
import org.eclipse.jgit.lib.Constants
|
||||||
import service.SystemSettingsService
|
|
||||||
|
|
||||||
class NoShell extends Factory[Command] with SystemSettingsService {
|
class NoShell extends Factory[Command] with SystemSettingsService {
|
||||||
override def create(): Command = new Command() {
|
override def create(): Command = new Command() {
|
||||||
@@ -1,16 +1,15 @@
|
|||||||
package ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
|
import gitbucket.core.service.SshKeyService
|
||||||
|
import gitbucket.core.servlet.Database
|
||||||
import org.apache.sshd.server.PublickeyAuthenticator
|
import org.apache.sshd.server.PublickeyAuthenticator
|
||||||
import org.apache.sshd.server.session.ServerSession
|
import org.apache.sshd.server.session.ServerSession
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import service.SshKeyService
|
|
||||||
import servlet.Database
|
|
||||||
import javax.servlet.ServletContext
|
|
||||||
|
|
||||||
class PublicKeyAuthenticator(context: ServletContext) extends PublickeyAuthenticator with SshKeyService {
|
class PublicKeyAuthenticator extends PublickeyAuthenticator with SshKeyService {
|
||||||
|
|
||||||
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
||||||
Database(context) withTransaction { implicit session =>
|
Database() withSession { implicit session =>
|
||||||
getPublicKeys(username).exists { sshKey =>
|
getPublicKeys(username).exists { sshKey =>
|
||||||
SshUtil.str2PublicKey(sshKey.publicKey) match {
|
SshUtil.str2PublicKey(sshKey.publicKey) match {
|
||||||
case Some(publicKey) => key.equals(publicKey)
|
case Some(publicKey) => key.equals(publicKey)
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
import javax.servlet.{ServletContext, ServletContextEvent, ServletContextListener}
|
import javax.servlet.{ServletContextEvent, ServletContextListener}
|
||||||
|
import gitbucket.core.service.SystemSettingsService
|
||||||
|
import gitbucket.core.util.Directory
|
||||||
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
|
import org.apache.sshd.server.keyprovider.SimpleGeneratorHostKeyProvider
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
import util.Directory
|
|
||||||
import service.SystemSettingsService
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean
|
import java.util.concurrent.atomic.AtomicBoolean
|
||||||
|
|
||||||
object SshServer {
|
object SshServer {
|
||||||
@@ -12,17 +12,17 @@ object SshServer {
|
|||||||
private val server = org.apache.sshd.SshServer.setUpDefaultServer()
|
private val server = org.apache.sshd.SshServer.setUpDefaultServer()
|
||||||
private val active = new AtomicBoolean(false)
|
private val active = new AtomicBoolean(false)
|
||||||
|
|
||||||
private def configure(context: ServletContext, port: Int, baseUrl: String) = {
|
private def configure(port: Int, baseUrl: String) = {
|
||||||
server.setPort(port)
|
server.setPort(port)
|
||||||
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
server.setKeyPairProvider(new SimpleGeneratorHostKeyProvider(s"${Directory.GitBucketHome}/gitbucket.ser"))
|
||||||
server.setPublickeyAuthenticator(new PublicKeyAuthenticator(context))
|
server.setPublickeyAuthenticator(new PublicKeyAuthenticator)
|
||||||
server.setCommandFactory(new GitCommandFactory(context, baseUrl))
|
server.setCommandFactory(new GitCommandFactory(baseUrl))
|
||||||
server.setShellFactory(new NoShell)
|
server.setShellFactory(new NoShell)
|
||||||
}
|
}
|
||||||
|
|
||||||
def start(context: ServletContext, port: Int, baseUrl: String) = {
|
def start(port: Int, baseUrl: String) = {
|
||||||
if(active.compareAndSet(false, true)){
|
if(active.compareAndSet(false, true)){
|
||||||
configure(context, port, baseUrl)
|
configure(port, baseUrl)
|
||||||
server.start()
|
server.start()
|
||||||
logger.info(s"Start SSH Server Listen on ${server.getPort}")
|
logger.info(s"Start SSH Server Listen on ${server.getPort}")
|
||||||
}
|
}
|
||||||
@@ -55,8 +55,7 @@ class SshServerListener extends ServletContextListener with SystemSettingsServic
|
|||||||
case None =>
|
case None =>
|
||||||
logger.error("Could not start SshServer because the baseUrl is not configured.")
|
logger.error("Could not start SshServer because the baseUrl is not configured.")
|
||||||
case Some(baseUrl) =>
|
case Some(baseUrl) =>
|
||||||
SshServer.start(sce.getServletContext,
|
SshServer.start(settings.sshPort.getOrElse(SystemSettingsService.DefaultSshPort), baseUrl)
|
||||||
settings.sshPort.getOrElse(SystemSettingsService.DefaultSshPort), baseUrl)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package ssh
|
package gitbucket.core.ssh
|
||||||
|
|
||||||
import java.security.PublicKey
|
import java.security.PublicKey
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@@ -1,10 +1,10 @@
|
|||||||
package util
|
package gitbucket.core.util
|
||||||
|
|
||||||
import app.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import service._
|
import gitbucket.core.service.{RepositoryService, AccountService}
|
||||||
import RepositoryService.RepositoryInfo
|
import RepositoryService.RepositoryInfo
|
||||||
import util.Implicits._
|
import Implicits._
|
||||||
import util.ControlUtil._
|
import ControlUtil._
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Allows only oneself and administrators.
|
* Allows only oneself and administrators.
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
package util
|
package gitbucket.core.util
|
||||||
|
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
@@ -37,4 +37,10 @@ object ControlUtil {
|
|||||||
def using[T](treeWalk: TreeWalk)(f: TreeWalk => T): T =
|
def using[T](treeWalk: TreeWalk)(f: TreeWalk => T): T =
|
||||||
try f(treeWalk) finally treeWalk.release()
|
try f(treeWalk) finally treeWalk.release()
|
||||||
|
|
||||||
|
def ignore[T](f: => Unit): Unit = try {
|
||||||
|
f
|
||||||
|
} catch {
|
||||||
|
case e: Exception => ()
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
19
src/main/scala/gitbucket/core/util/DatabaseConfig.scala
Normal file
19
src/main/scala/gitbucket/core/util/DatabaseConfig.scala
Normal file
@@ -0,0 +1,19 @@
|
|||||||
|
package gitbucket.core.util
|
||||||
|
|
||||||
|
import com.typesafe.config.ConfigFactory
|
||||||
|
import Directory.DatabaseHome
|
||||||
|
|
||||||
|
object DatabaseConfig {
|
||||||
|
|
||||||
|
private val config = ConfigFactory.load("database")
|
||||||
|
private val dbUrl = config.getString("db.url")
|
||||||
|
|
||||||
|
def url(directory: Option[String]): String =
|
||||||
|
dbUrl.replace("${DatabaseHome}", directory.getOrElse(DatabaseHome))
|
||||||
|
|
||||||
|
val url: String = url(None)
|
||||||
|
val user: String = config.getString("db.user")
|
||||||
|
val password: String = config.getString("db.password")
|
||||||
|
val driver: String = config.getString("db.driver")
|
||||||
|
|
||||||
|
}
|
||||||
@@ -1,7 +1,7 @@
|
|||||||
package util
|
package gitbucket.core.util
|
||||||
|
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import util.ControlUtil._
|
import ControlUtil._
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -48,7 +48,7 @@ object Directory {
|
|||||||
* Directory for files which are attached to issue.
|
* Directory for files which are attached to issue.
|
||||||
*/
|
*/
|
||||||
def getAttachedDir(owner: String, repository: String): File =
|
def getAttachedDir(owner: String, repository: String): File =
|
||||||
new File(s"${RepositoryHome}/${owner}/${repository}/issues")
|
new File(s"${RepositoryHome}/${owner}/${repository}/comments")
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Directory for uploaded files by the specified user.
|
* Directory for uploaded files by the specified user.
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package util
|
package gitbucket.core.util
|
||||||
|
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import java.net.URLConnection
|
import java.net.URLConnection
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import util.ControlUtil._
|
import ControlUtil._
|
||||||
import scala.util.Random
|
import scala.util.Random
|
||||||
|
|
||||||
object FileUtil {
|
object FileUtil {
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
package util
|
package gitbucket.core.util
|
||||||
|
|
||||||
|
import gitbucket.core.servlet.Database
|
||||||
|
|
||||||
import scala.util.matching.Regex
|
import scala.util.matching.Regex
|
||||||
import scala.util.control.Exception._
|
import scala.util.control.Exception._
|
||||||
import slick.jdbc.JdbcBackend
|
import slick.jdbc.JdbcBackend
|
||||||
import servlet.Database
|
|
||||||
import javax.servlet.http.{HttpSession, HttpServletRequest}
|
import javax.servlet.http.{HttpSession, HttpServletRequest}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user