mirror of
https://github.com/gitbucket/gitbucket.git
synced 2025-11-05 13:05:50 +01:00
Compare commits
492 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
753403b4c8 | ||
|
|
5a0f9f8bbb | ||
|
|
8fa22b4de2 | ||
|
|
d17cae16fd | ||
|
|
c4c48962cf | ||
|
|
4140e92f0b | ||
|
|
887e560a1b | ||
|
|
e2d70181e8 | ||
|
|
148c453dbc | ||
|
|
f6ee9d311d | ||
|
|
35209e43bb | ||
|
|
4a3ecf063d | ||
|
|
4c79101624 | ||
|
|
921b01661b | ||
|
|
c63301d8e6 | ||
|
|
c9ed9d2237 | ||
|
|
ca55cbe456 | ||
|
|
d4828613ee | ||
|
|
a0be02ce2f | ||
|
|
9b8016a4d5 | ||
|
|
8fdd3bfd21 | ||
|
|
695a061e3c | ||
|
|
bd50d9218e | ||
|
|
d8f13bc1ce | ||
|
|
ed84d1a3c9 | ||
|
|
3c765d879c | ||
|
|
4c76b6dd96 | ||
|
|
7e66917993 | ||
|
|
eb0f985399 | ||
|
|
3a2908c3a3 | ||
|
|
f13c10859f | ||
|
|
8e8a314c91 | ||
|
|
dad0478b87 | ||
|
|
240b34016d | ||
|
|
2c164d630c | ||
|
|
3d12a9038f | ||
|
|
71fc02b5cd | ||
|
|
74caaa3d94 | ||
|
|
e024c12521 | ||
|
|
1d0c364947 | ||
|
|
88e59405c5 | ||
|
|
8160c93c15 | ||
|
|
3c8113d607 | ||
|
|
8e2f421e76 | ||
|
|
56df833b4a | ||
|
|
119d7d0be0 | ||
|
|
d4d2ca19a1 | ||
|
|
4ce5597d67 | ||
|
|
17888327b3 | ||
|
|
997def54ab | ||
|
|
a407e75459 | ||
|
|
cece53aad9 | ||
|
|
a2d63bc5f8 | ||
|
|
0c81c63ab7 | ||
|
|
3e8f1eee22 | ||
|
|
a91d1def45 | ||
|
|
032e6d1c57 | ||
|
|
93eb133cba | ||
|
|
b7b78842da | ||
|
|
8100ccaf5f | ||
|
|
936e1c0e96 | ||
|
|
1a7274e475 | ||
|
|
ac7b83b6ed | ||
|
|
e298279032 | ||
|
|
f7e58c28c6 | ||
|
|
18f3bc4056 | ||
|
|
4638f82889 | ||
|
|
4396b6eab5 | ||
|
|
594ae2bb7e | ||
|
|
429cf54bd4 | ||
|
|
274357abc4 | ||
|
|
0e21247755 | ||
|
|
37f2868ff3 | ||
|
|
6a85e25a62 | ||
|
|
a91b1c7e79 | ||
|
|
bfd9ecd130 | ||
|
|
ec888e94fd | ||
|
|
a19c80bef2 | ||
|
|
7b9ade2698 | ||
|
|
d03f28eeb9 | ||
|
|
288dd788bc | ||
|
|
2069a5a931 | ||
|
|
8a434cbd15 | ||
|
|
faafe49848 | ||
|
|
17a72292ce | ||
|
|
9ae09f1801 | ||
|
|
abbba17e4b | ||
|
|
479d5da17e | ||
|
|
dec7890d04 | ||
|
|
61910a6667 | ||
|
|
ac2119ac3b | ||
|
|
8c71cd7369 | ||
|
|
ec8b6ff18f | ||
|
|
e214804d57 | ||
|
|
39448f2e3c | ||
|
|
79dc6fc247 | ||
|
|
a800f305f2 | ||
|
|
67e0fb6b3f | ||
|
|
e401d30159 | ||
|
|
504e651828 | ||
|
|
7a8da2f074 | ||
|
|
1e47e96634 | ||
|
|
69502480b4 | ||
|
|
5833e3fcca | ||
|
|
4e47ffb1d2 | ||
|
|
3056333a7c | ||
|
|
ad0cd7f625 | ||
|
|
dedaa263ce | ||
|
|
bccf729102 | ||
|
|
a244c61e56 | ||
|
|
37594935f0 | ||
|
|
e521c2158b | ||
|
|
b1c8a8c76e | ||
|
|
8d92f210f0 | ||
|
|
287281923c | ||
|
|
6f18135574 | ||
|
|
58cf9bec3b | ||
|
|
b7a45e9901 | ||
|
|
f5585b39c6 | ||
|
|
9c3ef37274 | ||
|
|
e904c0b689 | ||
|
|
237f97f069 | ||
|
|
1eb2a04090 | ||
|
|
cda6106858 | ||
|
|
8c4ce5e5f4 | ||
|
|
b5ee6431c4 | ||
|
|
bd06e6d4dc | ||
|
|
3b607e74ed | ||
|
|
dc16474ed3 | ||
|
|
dc0f088be0 | ||
|
|
2718e10044 | ||
|
|
4213dcb8a2 | ||
|
|
39afb31200 | ||
|
|
8e1ce1c96a | ||
|
|
fdfd8293d6 | ||
|
|
b7d3be6a14 | ||
|
|
bb5c809749 | ||
|
|
a2cbe7cbf5 | ||
|
|
b1fb09ac99 | ||
|
|
201ae7e7db | ||
|
|
2978decb84 | ||
|
|
5fbbd4d5f3 | ||
|
|
4abd363f62 | ||
|
|
8288db60a9 | ||
|
|
6cdf679571 | ||
|
|
51179acc12 | ||
|
|
1ff27d3e17 | ||
|
|
1e9bce3d5a | ||
|
|
8811ea2b58 | ||
|
|
be7cdd0a28 | ||
|
|
611a05aa48 | ||
|
|
9f95a757a2 | ||
|
|
58b577453c | ||
|
|
78acfd87e8 | ||
|
|
bf9cb26164 | ||
|
|
68a99ada0b | ||
|
|
1d841ce171 | ||
|
|
ccfdbfd276 | ||
|
|
70d584d56d | ||
|
|
a49ffb07be | ||
|
|
baa9caf010 | ||
|
|
22025c875f | ||
|
|
3806995a50 | ||
|
|
94d2650491 | ||
|
|
844f24afa4 | ||
|
|
083396a8e4 | ||
|
|
e02769056b | ||
|
|
024f8e8d80 | ||
|
|
3b4a7c3c47 | ||
|
|
d9838d9cba | ||
|
|
b3ca4468cd | ||
|
|
452e41603a | ||
|
|
b41de4a770 | ||
|
|
3423d2f2f3 | ||
|
|
9269acc64d | ||
|
|
18b5f20f1c | ||
|
|
68d592a8ff | ||
|
|
ee18d96f98 | ||
|
|
6d3687cbdf | ||
|
|
1ef1a2983b | ||
|
|
47850fe0fa | ||
|
|
055a37cac0 | ||
|
|
333deb4756 | ||
|
|
34cde4b09a | ||
|
|
5091b4838c | ||
|
|
2e83289061 | ||
|
|
e11f651002 | ||
|
|
be684a567d | ||
|
|
97e552b10f | ||
|
|
5bb8046c32 | ||
|
|
e7192655f7 | ||
|
|
19ba09740c | ||
|
|
d169777722 | ||
|
|
ff8a5f6b77 | ||
|
|
ec953df156 | ||
|
|
d6a191d95b | ||
|
|
aba428bba1 | ||
|
|
6ab37fd596 | ||
|
|
73fc70f55b | ||
|
|
aad18b7a50 | ||
|
|
cc278be5cd | ||
|
|
d0f4f82a0f | ||
|
|
1dcbf386b1 | ||
|
|
414afd285c | ||
|
|
35b645d8b5 | ||
|
|
b3cba53866 | ||
|
|
a4773bb3ca | ||
|
|
863d8a4af5 | ||
|
|
3fccd7b53c | ||
|
|
dd2760eaf7 | ||
|
|
824bafa739 | ||
|
|
60cdaec05f | ||
|
|
c204a435b3 | ||
|
|
37accd92d6 | ||
|
|
01fd0ee1f0 | ||
|
|
fab1c74473 | ||
|
|
0d8fcfd28d | ||
|
|
b91a7c32a6 | ||
|
|
7f665c649b | ||
|
|
dcbadb4071 | ||
|
|
e3096d15ff | ||
|
|
a83c24e7b3 | ||
|
|
73457c9658 | ||
|
|
cfc8d9f3f1 | ||
|
|
8f423b83ea | ||
|
|
1e7ac532b6 | ||
|
|
0fd1db4596 | ||
|
|
0755b7ab7f | ||
|
|
052382e5c4 | ||
|
|
f44a63cec1 | ||
|
|
603d67354a | ||
|
|
aafa423b9f | ||
|
|
2da9d0a801 | ||
|
|
b60c112a74 | ||
|
|
843ed6df37 | ||
|
|
0f0a849677 | ||
|
|
682901ccbb | ||
|
|
048fdb8837 | ||
|
|
3353616789 | ||
|
|
b6cb4c865f | ||
|
|
1fcfd093f7 | ||
|
|
3f27c6e733 | ||
|
|
b6bd9bfc3b | ||
|
|
6c392f0056 | ||
|
|
9a38de9a23 | ||
|
|
8883600090 | ||
|
|
ab822a3c27 | ||
|
|
0e4d64de23 | ||
|
|
fbc6bd36bd | ||
|
|
ed90ca2dce | ||
|
|
537ef92149 | ||
|
|
d51afa7d40 | ||
|
|
975cffff48 | ||
|
|
d92e9c00e8 | ||
|
|
12d72cbb19 | ||
|
|
e7a6f0930b | ||
|
|
d8e03bed1f | ||
|
|
f48c087cd8 | ||
|
|
917663e0df | ||
|
|
556ddbc926 | ||
|
|
1c6f37b8e8 | ||
|
|
720a329a50 | ||
|
|
220a8f076a | ||
|
|
43be8333c7 | ||
|
|
08706ab4df | ||
|
|
b1196657e0 | ||
|
|
334bd0c919 | ||
|
|
cf0f896972 | ||
|
|
d21ca3ff8a | ||
|
|
83f1f16de7 | ||
|
|
0fa2ccf107 | ||
|
|
18e3dd431b | ||
|
|
f25dee2249 | ||
|
|
575ffa9580 | ||
|
|
f17af5aeb0 | ||
|
|
639f153589 | ||
|
|
fb07098c13 | ||
|
|
74fc08b039 | ||
|
|
2776e00004 | ||
|
|
5932fce303 | ||
|
|
39c9fc4261 | ||
|
|
89ea4509a3 | ||
|
|
d19d838ead | ||
|
|
633a2699a8 | ||
|
|
e79bca4a3c | ||
|
|
f8ab480d20 | ||
|
|
a14129e340 | ||
|
|
5ec39df6e0 | ||
|
|
956e0c6321 | ||
|
|
0660a9203a | ||
|
|
1b660272a1 | ||
|
|
d9ef9b874d | ||
|
|
7824f796ee | ||
|
|
838a8d4c7b | ||
|
|
8db9f77f91 | ||
|
|
4f82a469d9 | ||
|
|
0f6ae8559b | ||
|
|
3f4b2eec35 | ||
|
|
a020601d3a | ||
|
|
d511205588 | ||
|
|
fc896b2ea1 | ||
|
|
3819670535 | ||
|
|
067669a18c | ||
|
|
bef7cee8db | ||
|
|
cb9f56fc22 | ||
|
|
719a521f06 | ||
|
|
413754976f | ||
|
|
4530cfc068 | ||
|
|
fcc7d6da2d | ||
|
|
33e565d029 | ||
|
|
6a1da37e9a | ||
|
|
897cc5eea4 | ||
|
|
5cbea281af | ||
|
|
e74db57b75 | ||
|
|
6b2d124d09 | ||
|
|
7b3c77db8c | ||
|
|
1bcab5c2c7 | ||
|
|
16020e9a7d | ||
|
|
dfd3e22986 | ||
|
|
48d7a20fb7 | ||
|
|
04108a0a1a | ||
|
|
e0bab59846 | ||
|
|
1004c83bc4 | ||
|
|
502bb450e3 | ||
|
|
fb03b0bec7 | ||
|
|
2c3a1c9c92 | ||
|
|
73b7ee2d57 | ||
|
|
71df890f39 | ||
|
|
1fdac404b1 | ||
|
|
47be1e60bb | ||
|
|
1c05f50954 | ||
|
|
ce26a48fd7 | ||
|
|
26e0838ae0 | ||
|
|
6b5b0db20a | ||
|
|
5973c8cb85 | ||
|
|
f683439c73 | ||
|
|
625f3655ec | ||
|
|
4a5ab1ae71 | ||
|
|
3bcae2c6d2 | ||
|
|
4441eff657 | ||
|
|
9fed83e222 | ||
|
|
42ea9bac65 | ||
|
|
2aba827772 | ||
|
|
31e84bd543 | ||
|
|
ba471b8bf7 | ||
|
|
90ec95494d | ||
|
|
e72dbad765 | ||
|
|
ed63ea4674 | ||
|
|
559a52404f | ||
|
|
5e80848524 | ||
|
|
055a4f0798 | ||
|
|
6f432e537c | ||
|
|
a2abbbbd63 | ||
|
|
16707b99e6 | ||
|
|
80a4ed62cc | ||
|
|
b713a334f0 | ||
|
|
ec6264c04c | ||
|
|
44bb1ab565 | ||
|
|
523ee025ac | ||
|
|
d193c6399c | ||
|
|
8c9715f4d9 | ||
|
|
3bbdcd5f14 | ||
|
|
c183d3b0b5 | ||
|
|
b6f0c6bf57 | ||
|
|
8719e834f3 | ||
|
|
f23b8c6d61 | ||
|
|
d46be31ea8 | ||
|
|
9bb36e4cb2 | ||
|
|
2780fb9605 | ||
|
|
b69e2d299a | ||
|
|
a07bd7b1a4 | ||
|
|
d605455678 | ||
|
|
781b1169a2 | ||
|
|
80112d3437 | ||
|
|
131af7f4fa | ||
|
|
1ceac4ef9f | ||
|
|
b7aa3e69f4 | ||
|
|
62231c41b2 | ||
|
|
6c0a33712b | ||
|
|
e192624489 | ||
|
|
68609e44de | ||
|
|
c8e3af6072 | ||
|
|
9f7048a19c | ||
|
|
cbdc0528ca | ||
|
|
444facc95b | ||
|
|
ed40ddaa45 | ||
|
|
43c629b3e5 | ||
|
|
0d2c156579 | ||
|
|
ab218f8540 | ||
|
|
4b8a375890 | ||
|
|
9c3a5f3f0a | ||
|
|
1bcfbec29c | ||
|
|
781940436a | ||
|
|
7f226a6ab1 | ||
|
|
f538950d64 | ||
|
|
142be65893 | ||
|
|
8b01e5bc1f | ||
|
|
bde0aab207 | ||
|
|
31ecfef1c9 | ||
|
|
0fdae4c334 | ||
|
|
3ea7de974b | ||
|
|
34a7990d1d | ||
|
|
709d759d09 | ||
|
|
2d47252b27 | ||
|
|
8586e141fc | ||
|
|
e3887e6872 | ||
|
|
fd658c35ee | ||
|
|
ca4c1b237f | ||
|
|
92b17fd719 | ||
|
|
b4453531a3 | ||
|
|
de72a9223f | ||
|
|
ae26e3031e | ||
|
|
c26b41cfc2 | ||
|
|
2c4ee664ab | ||
|
|
911cd45965 | ||
|
|
320cc58c62 | ||
|
|
cfa1638e3c | ||
|
|
27264bf59a | ||
|
|
935283272e | ||
|
|
ea440294b1 | ||
|
|
df8435bf6a | ||
|
|
4fe019b11f | ||
|
|
538c79705a | ||
|
|
e94d972741 | ||
|
|
c58a9aca6a | ||
|
|
a6612e8522 | ||
|
|
bd455b9a0a | ||
|
|
122853f1f6 | ||
|
|
debbc21bf3 | ||
|
|
d991fdcbd9 | ||
|
|
78cc8f14fd | ||
|
|
09f1a06267 | ||
|
|
6fb910a939 | ||
|
|
9e891a0168 | ||
|
|
0bc77ce453 | ||
|
|
a46c821673 | ||
|
|
cae843d18f | ||
|
|
40ffc689b0 | ||
|
|
65afbd25b8 | ||
|
|
458b30610f | ||
|
|
a89608a2e2 | ||
|
|
0f45311d5e | ||
|
|
447ed6ce88 | ||
|
|
ab358a10bc | ||
|
|
5148851d49 | ||
|
|
068ecd30fe | ||
|
|
5396c0ee58 | ||
|
|
2328c1878b | ||
|
|
bc9a6f464a | ||
|
|
4613fd4cb4 | ||
|
|
ff89c8805c | ||
|
|
95d98c525b | ||
|
|
bc78a38570 | ||
|
|
8db2398dd8 | ||
|
|
e073ca74da | ||
|
|
50e899bf83 | ||
|
|
5ddd6234e3 | ||
|
|
84fa11b5df | ||
|
|
f51db60fc7 | ||
|
|
351e72e8c2 | ||
|
|
a0f54b0b8e | ||
|
|
4c491e40c7 | ||
|
|
54440d9cde | ||
|
|
ea8333844c | ||
|
|
fc34df7008 | ||
|
|
d49d62edfc | ||
|
|
246e2e2de4 | ||
|
|
83b48d26ce | ||
|
|
3d40094925 | ||
|
|
2d7e8526ed | ||
|
|
7768f4c4dd | ||
|
|
e43fabf895 | ||
|
|
7cf83979a6 | ||
|
|
1ecc30c570 | ||
|
|
ee0721f40d | ||
|
|
07836edf84 | ||
|
|
bfbe40e027 | ||
|
|
842d3b6185 | ||
|
|
086437ca4f | ||
|
|
6e48435f38 | ||
|
|
3b8e903cb5 | ||
|
|
55308f2deb | ||
|
|
a913a95d5b | ||
|
|
870a20721c | ||
|
|
df81f6e364 | ||
|
|
d4a892bf7f | ||
|
|
41d13db5d4 | ||
|
|
c63e20ce7d | ||
|
|
736fdafea4 | ||
|
|
1dfe76e21c | ||
|
|
e7ddfc7ebb | ||
|
|
66be84289d |
4
.github/CODEOWNERS
vendored
Normal file
4
.github/CODEOWNERS
vendored
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
* @takezoe
|
||||||
|
|
||||||
|
build.sbt @xuwei-k
|
||||||
|
project/* @xuwei-k
|
||||||
2
.github/CONTRIBUTING.md
vendored
2
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,6 @@
|
|||||||
# The guidelines for contributing
|
# The guidelines for contributing
|
||||||
|
|
||||||
- At first, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues and pull requests whether there is a same request in the past.
|
- At first, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues and pull requests whether there is a same request in the past.
|
||||||
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles. If you don't wanna waste your time to make a pull request, ask us about your idea at [gitter room](https://gitter.im/gitbucket/gitbucket) before staring your work.
|
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles. If you don't wanna waste your time to make a pull request, ask us about your idea at [gitter room](https://gitter.im/gitbucket/gitbucket) before starting your work.
|
||||||
- You can edit the GitBucket documentation on Wiki if you have a GitHub account. When you find any mistakes or lacks in the documentation, please update it directly.
|
- You can edit the GitBucket documentation on Wiki if you have a GitHub account. When you find any mistakes or lacks in the documentation, please update it directly.
|
||||||
- All your contributions are handled as [Apache Software License, Version 2.0](https://github.com/gitbucket/gitbucket/blob/master/LICENSE). When you create a pull request or update the documentation, we assume you agreed this clause.
|
- All your contributions are handled as [Apache Software License, Version 2.0](https://github.com/gitbucket/gitbucket/blob/master/LICENSE). When you create a pull request or update the documentation, we assume you agreed this clause.
|
||||||
|
|||||||
2
.github/ISSUE_TEMPLATE.md
vendored
2
.github/ISSUE_TEMPLATE.md
vendored
@@ -12,7 +12,7 @@
|
|||||||
**Deployment mode**: *explain here how you use GitBucket : standalone app, under webcontainer (which one), with an http frontend (nginx, httpd, ...)*
|
**Deployment mode**: *explain here how you use GitBucket : standalone app, under webcontainer (which one), with an http frontend (nginx, httpd, ...)*
|
||||||
|
|
||||||
**Problem description**:
|
**Problem description**:
|
||||||
- *be as explicit has you can*
|
- *be as explicit as you can*
|
||||||
- *describe the problem and its symptoms*
|
- *describe the problem and its symptoms*
|
||||||
- *explain how to reproduce*
|
- *explain how to reproduce*
|
||||||
- *attach whatever information that can help understanding the context (screen capture, log files)*
|
- *attach whatever information that can help understanding the context (screen capture, log files)*
|
||||||
|
|||||||
14
.github/workflows/build.yml
vendored
14
.github/workflows/build.yml
vendored
@@ -5,13 +5,14 @@ on: [push, pull_request]
|
|||||||
jobs:
|
jobs:
|
||||||
build:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
|
timeout-minutes: 30
|
||||||
strategy:
|
strategy:
|
||||||
matrix:
|
matrix:
|
||||||
java: [8, 11]
|
java: [8, 11, 17]
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v2
|
- uses: actions/checkout@v3
|
||||||
- name: Cache
|
- name: Cache
|
||||||
uses: actions/cache@v2
|
uses: actions/cache@v3
|
||||||
env:
|
env:
|
||||||
cache-name: cache-sbt-libs
|
cache-name: cache-sbt-libs
|
||||||
with:
|
with:
|
||||||
@@ -21,15 +22,18 @@ jobs:
|
|||||||
~/.cache/coursier/v1
|
~/.cache/coursier/v1
|
||||||
key: build-${{ env.cache-name }}-${{ hashFiles('build.sbt') }}
|
key: build-${{ env.cache-name }}-${{ hashFiles('build.sbt') }}
|
||||||
- name: Set up JDK
|
- name: Set up JDK
|
||||||
uses: actions/setup-java@v1
|
uses: actions/setup-java@v3
|
||||||
with:
|
with:
|
||||||
java-version: ${{ matrix.java }}
|
java-version: ${{ matrix.java }}
|
||||||
|
distribution: adopt
|
||||||
- name: Run tests
|
- name: Run tests
|
||||||
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
run: sbt scalafmtSbtCheck scalafmtCheck test:scalafmtCheck test
|
||||||
|
- name: Scala 3
|
||||||
|
run: sbt '++ 3.1.2!' update # TODO
|
||||||
- name: Build executable
|
- name: Build executable
|
||||||
run: sbt executable
|
run: sbt executable
|
||||||
- name: Upload artifacts
|
- name: Upload artifacts
|
||||||
uses: actions/upload-artifact@v2
|
uses: actions/upload-artifact@v3
|
||||||
with:
|
with:
|
||||||
name: gitbucket-java${{ matrix.java }}-${{ github.sha }}
|
name: gitbucket-java${{ matrix.java }}-${{ github.sha }}
|
||||||
path: ./target/executable/gitbucket.*
|
path: ./target/executable/gitbucket.*
|
||||||
|
|||||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -2,6 +2,8 @@
|
|||||||
*.log
|
*.log
|
||||||
.ensime
|
.ensime
|
||||||
.ensime_cache
|
.ensime_cache
|
||||||
|
.DS_Store
|
||||||
|
.java-version
|
||||||
|
|
||||||
# sbt specific
|
# sbt specific
|
||||||
dist/*
|
dist/*
|
||||||
|
|||||||
9
.scala-steward.conf
Normal file
9
.scala-steward.conf
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
updates.limit = 3
|
||||||
|
|
||||||
|
updates.includeScala = true
|
||||||
|
|
||||||
|
updates.pin = [
|
||||||
|
{ groupId = "org.eclipse.jetty", version = "9." }
|
||||||
|
{ groupId = "org.eclipse.jgit", version = "5." }
|
||||||
|
{ groupId = "com.zaxxer", version = "4." }
|
||||||
|
]
|
||||||
66
CHANGELOG.md
66
CHANGELOG.md
@@ -1,7 +1,71 @@
|
|||||||
# Changelog
|
# Changelog
|
||||||
All changes to the project will be documented in this file.
|
All changes to the project will be documented in this file.
|
||||||
|
|
||||||
### 4.35.0 - 25 Dec 2020
|
## 4.38.3 - 30 Oct 2022
|
||||||
|
- Fix several issues around multiple assignees in issues and pull requests
|
||||||
|
- Fix IllegalStateException when returning unknown avatar image
|
||||||
|
|
||||||
|
## 4.38.2 - 20 Sep 2022
|
||||||
|
- Resurrect assignee icons on the issue list
|
||||||
|
|
||||||
|
## 4.38.1 - 10 Sep 2022
|
||||||
|
- Fix comment diff in Chrome 105
|
||||||
|
- Fix Markdown table CSS
|
||||||
|
- Fix HTML rendering of multiple asignees
|
||||||
|
|
||||||
|
## 4.38.0 - 3 Sep 2022
|
||||||
|
- Support multiple assignees for Issues and Pull requests
|
||||||
|
- Custom fields for issues and pull requests
|
||||||
|
- Reset password by users
|
||||||
|
- Allow to configure Jetty idle timeout in standalone mode
|
||||||
|
- Horizontal scroll for too wide tables in Markdown
|
||||||
|
- Hide header content on signin and register page
|
||||||
|
- Fix the default charset of the online editor in the repository viewer
|
||||||
|
- Fix the milestone count
|
||||||
|
- Some improvements and bugfixes for WebAPI and WebHook
|
||||||
|
|
||||||
|
## 4.37.2 - 16 Jan 2022
|
||||||
|
- Fixed a security issue reported by [Positive Technologies](https://www.ptsecurity.com/ww-en/). Great thanks for their detailed report and close support!
|
||||||
|
|
||||||
|
## 4.37.1 - 14 Dec 2021
|
||||||
|
- Update gist-plugin and notification-plugin
|
||||||
|
- Fix SSHCommand extension point for apache-sshd 2.x
|
||||||
|
|
||||||
|
## 4.37.0 - 11 Dec 2021
|
||||||
|
- Enhance Git Reference APIs
|
||||||
|
- Add milestone data to issue list API
|
||||||
|
- Support "all" in issue list API
|
||||||
|
- Support EDDSA in signed commit verification
|
||||||
|
- Support custom SSH url
|
||||||
|
- Relax max passward length limitation
|
||||||
|
- Relax max webhook url length limitation
|
||||||
|
|
||||||
|
## 4.36.2 - 16 Aug 2021
|
||||||
|
- Escape user name in avatar image tag
|
||||||
|
|
||||||
|
## 4.36.1 - 22 Jul 2021
|
||||||
|
- Bump gitbucket-gist-plugin to 4.21.0
|
||||||
|
|
||||||
|
## 4.36.0 - 17 Jul 2021
|
||||||
|
- Tag selector in the repository viewer
|
||||||
|
- Link issues/pull requests of other repositories
|
||||||
|
- Files and lines can be linked in the diff view
|
||||||
|
- Option to disable XSS protection
|
||||||
|
|
||||||
|
## 4.35.3 - 14 Jan 2021
|
||||||
|
- Fix a bug that Wiki page cannot be deleted
|
||||||
|
- Fix a deployment issue on Tomcat
|
||||||
|
|
||||||
|
## 4.35.2 - 30 Dec 2020
|
||||||
|
- Upgrade gitbucket-notifications-plugin to 1.10.0
|
||||||
|
- Upgrade oauth2-oidc-sdk to 8.29.1 to solve dependency issue
|
||||||
|
|
||||||
|
## 4.35.1 - 29 Dec 2020
|
||||||
|
- Fix database migration issue which happens if webhook is configured
|
||||||
|
- Call push webhook when pull request is merged
|
||||||
|
- Show commit status at commits tab of pull request
|
||||||
|
|
||||||
|
## 4.35.0 - 25 Dec 2020
|
||||||
- Editor and source viewer color theme
|
- Editor and source viewer color theme
|
||||||
- Auto completion for issues and pull requests
|
- Auto completion for issues and pull requests
|
||||||
- Upload image from clipboard
|
- Upload image from clipboard
|
||||||
|
|||||||
48
README.md
48
README.md
@@ -1,4 +1,4 @@
|
|||||||
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/actions?query=workflow%3Abuild+branch%3Amaster) [](https://maven-badges.herokuapp.com/maven-central/io.github.gitbucket/gitbucket_2.13) [](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
|
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/actions?query=workflow%3Abuild+branch%3Amaster) [](https://index.scala-lang.org/gitbucket/gitbucket/gitbucket) [](https://github.com/gitbucket/gitbucket/blob/master/LICENSE)
|
||||||
=========
|
=========
|
||||||
|
|
||||||
GitBucket is a Git web platform powered by Scala offering:
|
GitBucket is a Git web platform powered by Scala offering:
|
||||||
@@ -8,7 +8,7 @@ GitBucket is a Git web platform powered by Scala offering:
|
|||||||
- High extensibility by plugins
|
- High extensibility by plugins
|
||||||
- API compatibility with GitHub
|
- API compatibility with GitHub
|
||||||
|
|
||||||
You can try an [online demo](https://gitbucket.herokuapp.com/) *(ID: root / Pass: root)* of GitBucket, and also get the latest information at [GitBucket News](https://gitbucket.github.io/gitbucket-news/).
|

|
||||||
|
|
||||||
Features
|
Features
|
||||||
--------
|
--------
|
||||||
@@ -22,8 +22,6 @@ The current version of GitBucket provides many features such as:
|
|||||||
- Account and group management with LDAP integration
|
- Account and group management with LDAP integration
|
||||||
- a Plug-in system
|
- a Plug-in system
|
||||||
|
|
||||||
If you want to try the development version of GitBucket, see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/readme.md).
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
--------
|
--------
|
||||||
GitBucket requires **Java8**. You have to install it, if it is not already installed.
|
GitBucket requires **Java8**. You have to install it, if it is not already installed.
|
||||||
@@ -31,7 +29,7 @@ GitBucket requires **Java8**. You have to install it, if it is not already insta
|
|||||||
1. Download the latest **gitbucket.war** from [the releases page](https://github.com/gitbucket/gitbucket/releases) and run it by `java -jar gitbucket.war`.
|
1. Download the latest **gitbucket.war** from [the releases page](https://github.com/gitbucket/gitbucket/releases) and run it by `java -jar gitbucket.war`.
|
||||||
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
|
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
|
||||||
|
|
||||||
You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc)
|
You can also deploy `gitbucket.war` to a servlet container which supports Servlet 3.0 (like Jetty, Tomcat, JBoss, etc). Note that GitBucket doesn't support Jakarta EE yet.
|
||||||
|
|
||||||
For more information about installation on Mac or Windows Server (with IIS), or configuration of Apache or Nginx and also integration with other tools or services such as Jenkins or Slack, see [Wiki](https://github.com/gitbucket/gitbucket/wiki).
|
For more information about installation on Mac or Windows Server (with IIS), or configuration of Apache or Nginx and also integration with other tools or services such as Jenkins or Slack, see [Wiki](https://github.com/gitbucket/gitbucket/wiki).
|
||||||
|
|
||||||
@@ -48,24 +46,42 @@ GitBucket has a plug-in system that allows extra functionality. Officially the f
|
|||||||
|
|
||||||
You can find more plugins made by the community at [GitBucket community plugins](https://gitbucket-plugins.github.io/).
|
You can find more plugins made by the community at [GitBucket community plugins](https://gitbucket-plugins.github.io/).
|
||||||
|
|
||||||
|
Building and Development
|
||||||
|
-----------
|
||||||
|
If you want to try the development version of GitBucket, or want to contribute to the project, please see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/readme.md).
|
||||||
|
It provides instructions on building from source and on setting up an IDE for debugging.
|
||||||
|
It also contains documentation of the core concepts used within the project.
|
||||||
|
|
||||||
Support
|
Support
|
||||||
--------
|
--------
|
||||||
|
|
||||||
- If you have any questions about GitBucket, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues whether there is a same question or request in the past.
|
- If you have any questions about GitBucket, see [Wiki](https://github.com/gitbucket/gitbucket/wiki) and check issues whether there is a same question or request in the past.
|
||||||
- If you can't find same question and report, send it to [gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
- If you can't find same question and report, send it to our [Gitter room](https://gitter.im/gitbucket/gitbucket) before raising an issue.
|
||||||
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
- The highest priority of GitBucket is the ease of installation and API compatibility with GitHub, so your feature request might be rejected if they go against those principles.
|
||||||
|
|
||||||
What's New in 4.34.x
|
What's New in 4.38.x
|
||||||
-------------
|
-------------
|
||||||
### 4.35.0 - 25 Dec 2020
|
## 4.38.3 - 30 Oct 2022
|
||||||
|
- Fix several issues around multiple assignees in issues and pull requests
|
||||||
|
- Fix IllegalStateException when returning unknown avatar image
|
||||||
|
|
||||||
- Editor and source viewer color theme
|
## 4.38.2 - 20 Sep 2022
|
||||||
- Auto completion for issues and pull requests
|
- Resurrect assignee icons on the issue list
|
||||||
- Upload image from clipboard
|
|
||||||
- Close multiple issues by commit comment
|
## 4.38.1 - 10 Sep 2022
|
||||||
- Create pull request from online editor
|
- Fix comment diff in Chrome 105
|
||||||
- Milestone overview
|
- Fix Markdown table CSS
|
||||||
- Commit status at various places
|
- Fix HTML rendering of multiple asignees
|
||||||
- WebAPI coverage improvements
|
|
||||||
|
## 4.38.0 - 3 Sep 2022
|
||||||
|
- Support multiple assignees for Issues and Pull requests
|
||||||
|
- Custom fields for issues and pull requests
|
||||||
|
- Reset password by users
|
||||||
|
- Allow to configure Jetty idle timeout in standalone mode
|
||||||
|
- Horizontal scroll for too wide tables in Markdown
|
||||||
|
- Hide header content on signin and register page
|
||||||
|
- Fix the default charset of the online editor in the repository viewer
|
||||||
|
- Fix the milestone count
|
||||||
|
- Some improvements and bugfixes for WebAPI and WebHook
|
||||||
|
|
||||||
See the [change log](CHANGELOG.md) for all of the updates.
|
See the [change log](CHANGELOG.md) for all of the updates.
|
||||||
|
|||||||
129
build.sbt
129
build.sbt
@@ -1,96 +1,109 @@
|
|||||||
import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
|
import com.typesafe.sbt.license.{DepModuleInfo, LicenseInfo}
|
||||||
import com.typesafe.sbt.pgp.PgpKeys._
|
import com.jsuereth.sbtpgp.PgpKeys._
|
||||||
|
|
||||||
val Organization = "io.github.gitbucket"
|
val Organization = "io.github.gitbucket"
|
||||||
val Name = "gitbucket"
|
val Name = "gitbucket"
|
||||||
val GitBucketVersion = "4.35.0"
|
val GitBucketVersion = "4.38.3"
|
||||||
val ScalatraVersion = "2.7.0"
|
val ScalatraVersion = "2.8.4"
|
||||||
val JettyVersion = "9.4.32.v20200930"
|
val JettyVersion = "9.4.49.v20220914"
|
||||||
val JgitVersion = "5.9.0.202009080501-r"
|
val JgitVersion = "5.13.1.202206130422-r"
|
||||||
|
|
||||||
lazy val root = (project in file("."))
|
lazy val root = (project in file("."))
|
||||||
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
.enablePlugins(SbtTwirl, ScalatraPlugin)
|
||||||
.settings(
|
|
||||||
)
|
|
||||||
|
|
||||||
sourcesInBase := false
|
sourcesInBase := false
|
||||||
organization := Organization
|
organization := Organization
|
||||||
name := Name
|
name := Name
|
||||||
version := GitBucketVersion
|
version := GitBucketVersion
|
||||||
scalaVersion := "2.13.1"
|
scalaVersion := "2.13.10"
|
||||||
|
|
||||||
scalafmtOnCompile := true
|
// scalafmtOnCompile := true
|
||||||
|
|
||||||
coverageExcludedPackages := ".*\\.html\\..*"
|
coverageExcludedPackages := ".*\\.html\\..*"
|
||||||
|
|
||||||
// dependency settings
|
// dependency settings
|
||||||
resolvers ++= Seq(
|
resolvers ++= Seq(
|
||||||
Classpaths.typesafeReleases,
|
Classpaths.typesafeReleases,
|
||||||
Resolver.jcenterRepo,
|
|
||||||
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
"sonatype-snapshot" at "https://oss.sonatype.org/content/repositories/snapshots/"
|
||||||
)
|
)
|
||||||
|
|
||||||
libraryDependencies ++= Seq(
|
libraryDependencies ++= Seq(
|
||||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % JgitVersion,
|
||||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % JgitVersion,
|
||||||
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
"org.scalatra" %% "scalatra" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
||||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
"org.scalatra" %% "scalatra-json" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
||||||
"org.scalatra" %% "scalatra-forms" % ScalatraVersion,
|
"org.scalatra" %% "scalatra-forms" % ScalatraVersion cross CrossVersion.for3Use2_13,
|
||||||
"org.json4s" %% "json4s-jackson" % "3.6.10",
|
"org.json4s" %% "json4s-jackson" % "4.0.6" cross CrossVersion.for3Use2_13,
|
||||||
"commons-io" % "commons-io" % "2.8.0",
|
"commons-io" % "commons-io" % "2.11.0",
|
||||||
"io.github.gitbucket" % "solidbase" % "1.0.3",
|
"io.github.gitbucket" % "solidbase" % "1.0.5",
|
||||||
"io.github.gitbucket" % "markedj" % "1.0.16",
|
"io.github.gitbucket" % "markedj" % "1.0.17",
|
||||||
"org.apache.commons" % "commons-compress" % "1.20",
|
"org.apache.commons" % "commons-compress" % "1.21",
|
||||||
"org.apache.commons" % "commons-email" % "1.5",
|
"org.apache.commons" % "commons-email" % "1.5",
|
||||||
"commons-net" % "commons-net" % "3.7",
|
"commons-net" % "commons-net" % "3.8.0",
|
||||||
"org.apache.httpcomponents" % "httpclient" % "4.5.12",
|
"org.apache.httpcomponents" % "httpclient" % "4.5.13",
|
||||||
"org.apache.sshd" % "apache-sshd" % "2.1.0" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
"org.apache.sshd" % "apache-sshd" % "2.9.1" exclude ("org.slf4j", "slf4j-jdk14") exclude ("org.apache.sshd", "sshd-mina") exclude ("org.apache.sshd", "sshd-netty"),
|
||||||
"org.apache.tika" % "tika-core" % "1.24.1",
|
"org.apache.tika" % "tika-core" % "2.5.0",
|
||||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12",
|
"com.github.takezoe" %% "blocking-slick-32" % "0.0.12" cross CrossVersion.for3Use2_13,
|
||||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||||
"com.h2database" % "h2" % "1.4.199",
|
"com.h2database" % "h2" % "1.4.199",
|
||||||
"org.mariadb.jdbc" % "mariadb-java-client" % "2.7.0",
|
"org.mariadb.jdbc" % "mariadb-java-client" % "3.0.8",
|
||||||
"org.postgresql" % "postgresql" % "42.2.6",
|
"org.postgresql" % "postgresql" % "42.5.0",
|
||||||
"ch.qos.logback" % "logback-classic" % "1.2.3",
|
"ch.qos.logback" % "logback-classic" % "1.2.11",
|
||||||
"com.zaxxer" % "HikariCP" % "3.4.5",
|
"com.zaxxer" % "HikariCP" % "4.0.3" exclude ("org.slf4j", "slf4j-api"),
|
||||||
"com.typesafe" % "config" % "1.4.0",
|
"com.typesafe" % "config" % "1.4.2",
|
||||||
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
"fr.brouillard.oss.security.xhub" % "xhub4j-core" % "1.1.0",
|
||||||
"com.github.bkromhout" % "java-diff-utils" % "2.1.1",
|
"io.github.java-diff-utils" % "java-diff-utils" % "4.12",
|
||||||
"org.cache2k" % "cache2k-all" % "1.2.4.Final",
|
"org.cache2k" % "cache2k-all" % "1.6.0.Final",
|
||||||
"net.coobird" % "thumbnailator" % "0.4.12",
|
"net.coobird" % "thumbnailator" % "0.4.18",
|
||||||
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
"com.github.zafarkhaja" % "java-semver" % "0.9.0",
|
||||||
"com.nimbusds" % "oauth2-oidc-sdk" % "5.64.4",
|
"com.nimbusds" % "oauth2-oidc-sdk" % "10.1",
|
||||||
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
"org.eclipse.jetty" % "jetty-webapp" % JettyVersion % "provided",
|
||||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||||
"junit" % "junit" % "4.13" % "test",
|
"junit" % "junit" % "4.13.2" % "test",
|
||||||
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test" cross CrossVersion.for3Use2_13,
|
||||||
"org.mockito" % "mockito-core" % "3.3.3" % "test",
|
"org.mockito" % "mockito-core" % "4.8.1" % "test",
|
||||||
"com.dimafeng" %% "testcontainers-scala" % "0.37.0" % "test",
|
"com.dimafeng" %% "testcontainers-scala" % "0.40.11" % "test",
|
||||||
"org.testcontainers" % "mysql" % "1.14.3" % "test",
|
"org.testcontainers" % "mysql" % "1.17.5" % "test",
|
||||||
"org.testcontainers" % "postgresql" % "1.14.3" % "test",
|
"org.testcontainers" % "postgresql" % "1.17.5" % "test",
|
||||||
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
"net.i2p.crypto" % "eddsa" % "0.3.0",
|
||||||
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
"is.tagomor.woothee" % "woothee-java" % "1.11.0",
|
||||||
"org.ec4j.core" % "ec4j-core" % "0.0.3",
|
"org.ec4j.core" % "ec4j-core" % "0.3.0",
|
||||||
"org.kohsuke" % "github-api" % "1.116" % "test"
|
"org.kohsuke" % "github-api" % "1.313" % "test"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
libraryDependencies ~= {
|
||||||
|
_.map {
|
||||||
|
case x if x.name == "twirl-api" =>
|
||||||
|
x cross CrossVersion.for3Use2_13
|
||||||
|
case x =>
|
||||||
|
x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Compiler settings
|
// Compiler settings
|
||||||
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-opt:l:method")
|
scalacOptions := Seq(
|
||||||
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
"-deprecation",
|
||||||
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
"-language:postfixOps",
|
||||||
|
"-opt:l:method",
|
||||||
|
"-feature",
|
||||||
|
"-Wunused:imports",
|
||||||
|
"-Wconf:cat=unused&src=twirl/.*:s,cat=unused&src=scala/gitbucket/core/model/[^/]+\\.scala:s"
|
||||||
|
)
|
||||||
|
compile / javacOptions ++= Seq("-target", "8", "-source", "8")
|
||||||
|
Jetty / javaOptions += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||||
|
|
||||||
// Test settings
|
// Test settings
|
||||||
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
//testOptions in Test += Tests.Argument("-l", "ExternalDBTest")
|
||||||
javaOptions in Test += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
Test / javaOptions += "-Dgitbucket.home=target/gitbucket_home_for_test"
|
||||||
testOptions in Test += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
Test / testOptions += Tests.Setup(() => new java.io.File("target/gitbucket_home_for_test").mkdir())
|
||||||
fork in Test := true
|
Test / fork := true
|
||||||
|
|
||||||
// Packaging options
|
// Packaging options
|
||||||
packageOptions += Package.MainClass("JettyLauncher")
|
packageOptions += Package.MainClass("JettyLauncher")
|
||||||
|
|
||||||
// Assembly settings
|
// Assembly settings
|
||||||
test in assembly := {}
|
assembly / test := {}
|
||||||
assemblyMergeStrategy in assembly := {
|
assembly / assemblyMergeStrategy := {
|
||||||
case PathList("META-INF", xs @ _*) =>
|
case PathList("META-INF", xs @ _*) =>
|
||||||
(xs map { _.toLowerCase }) match {
|
(xs map { _.toLowerCase }) match {
|
||||||
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
case ("manifest.mf" :: Nil) => MergeStrategy.discard
|
||||||
@@ -122,9 +135,9 @@ libraryDependencies ++= Seq(
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Run package task before test to generate target/webapp for integration test
|
// Run package task before test to generate target/webapp for integration test
|
||||||
test in Test := {
|
Test / test := {
|
||||||
_root_.sbt.Keys.`package`.value
|
_root_.sbt.Keys.`package`.value
|
||||||
(test in Test).value
|
(Test / test).value
|
||||||
}
|
}
|
||||||
|
|
||||||
val executableKey = TaskKey[File]("executable")
|
val executableKey = TaskKey[File]("executable")
|
||||||
@@ -155,7 +168,7 @@ executableKey := {
|
|||||||
IO unzip (warFile, temp)
|
IO unzip (warFile, temp)
|
||||||
|
|
||||||
// include launcher classes
|
// include launcher classes
|
||||||
val classDir = (Keys.classDirectory in Compile).value
|
val classDir = (Compile / Keys.classDirectory).value
|
||||||
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
val launchClasses = Seq("JettyLauncher.class" /*, "HttpsSupportConnector.class" */ )
|
||||||
launchClasses foreach { name =>
|
launchClasses foreach { name =>
|
||||||
IO copyFile (classDir / name, temp / name)
|
IO copyFile (classDir / name, temp / name)
|
||||||
@@ -186,7 +199,7 @@ executableKey := {
|
|||||||
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
manifest.getMainAttributes put (AttrName.MANIFEST_VERSION, "1.0")
|
||||||
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
manifest.getMainAttributes put (AttrName.MAIN_CLASS, "JettyLauncher")
|
||||||
val outputFile = workDir / warName
|
val outputFile = workDir / warName
|
||||||
IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest)
|
IO jar (contentMappings.map { case (file, path) => (file, path.toString) }, outputFile, manifest, None)
|
||||||
|
|
||||||
// generate checksums
|
// generate checksums
|
||||||
Seq(
|
Seq(
|
||||||
@@ -258,12 +271,7 @@ pomExtra := (
|
|||||||
</developers>
|
</developers>
|
||||||
)
|
)
|
||||||
|
|
||||||
licenseOverrides := {
|
Test / testOptions ++= {
|
||||||
case DepModuleInfo("com.github.bkromhout", "java-diff-utils", _) =>
|
|
||||||
LicenseInfo(LicenseCategory.Apache, "Apache-2.0", "http://www.apache.org/licenses/LICENSE-2.0")
|
|
||||||
}
|
|
||||||
|
|
||||||
testOptions in Test ++= {
|
|
||||||
if (scala.util.Properties.isWin) {
|
if (scala.util.Properties.isWin) {
|
||||||
Seq(
|
Seq(
|
||||||
Tests.Exclude(
|
Tests.Exclude(
|
||||||
@@ -276,3 +284,8 @@ testOptions in Test ++= {
|
|||||||
Nil
|
Nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Jetty / javaOptions ++= Seq(
|
||||||
|
"-Xdebug",
|
||||||
|
"-Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=8000"
|
||||||
|
)
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Authentication in Controller
|
|||||||
========
|
========
|
||||||
GitBucket provides many [authenticators](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/util/Authenticator.scala) to access controlling in the controller.
|
GitBucket provides many [authenticators](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/util/Authenticator.scala) to access controlling in the controller.
|
||||||
|
|
||||||
For example, in the case of `RepositoryViwerController`,
|
For example, in the case of `RepositoryViewerController`,
|
||||||
it references three authenticators: `ReadableUsersAuthenticator`, `ReferrerAuthenticator` and `CollaboratorsAuthenticator`.
|
it references three authenticators: `ReadableUsersAuthenticator`, `ReferrerAuthenticator` and `CollaboratorsAuthenticator`.
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
@@ -19,13 +19,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
...
|
...
|
||||||
```
|
```
|
||||||
|
|
||||||
Authenticators provides a method to add guard to actions in the controller:
|
Authenticators provide a method to add guard to actions in the controller:
|
||||||
|
|
||||||
- `ReadableUsersAuthenticator` provides `readableUsersOnly` method
|
- `ReadableUsersAuthenticator` provides `readableUsersOnly` method
|
||||||
- `ReferrerAuthenticator` provides `referrersOnly` method
|
- `ReferrerAuthenticator` provides `referrersOnly` method
|
||||||
- `CollaboratorsAuthenticator` provides `collaboratorsOnly` method
|
- `CollaboratorsAuthenticator` provides `collaboratorsOnly` method
|
||||||
|
|
||||||
These methods are available in each actions as below:
|
These methods are available in each action as below:
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
// Allows only the repository owner (or manager for group repository) and administrators.
|
// Allows only the repository owner (or manager for group repository) and administrators.
|
||||||
@@ -38,7 +38,7 @@ get("/:owner/:repository/new/*")(collaboratorsOnly { repository =>
|
|||||||
...
|
...
|
||||||
})
|
})
|
||||||
|
|
||||||
// Allows only signed in users which can access the repository.
|
// Allows only signed-in users which can access the repository.
|
||||||
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
...
|
...
|
||||||
})
|
})
|
||||||
@@ -50,11 +50,11 @@ Currently, GitBucket provides below authenticators:
|
|||||||
|--------------------------|-----------------|--------------------------------------------------------------------------------------|
|
|--------------------------|-----------------|--------------------------------------------------------------------------------------|
|
||||||
|OneselfAuthenticator |oneselfOnly |Allows only oneself and administrators. |
|
|OneselfAuthenticator |oneselfOnly |Allows only oneself and administrators. |
|
||||||
|OwnerAuthenticator |ownerOnly |Allows only the repository owner and administrators. |
|
|OwnerAuthenticator |ownerOnly |Allows only the repository owner and administrators. |
|
||||||
|UsersAuthenticator |usersOnly |Allows only signed in users. |
|
|UsersAuthenticator |usersOnly |Allows only signed-in users. |
|
||||||
|AdminAuthenticator |adminOnly |Allows only administrators. |
|
|AdminAuthenticator |adminOnly |Allows only administrators. |
|
||||||
|CollaboratorsAuthenticator|collaboratorsOnly|Allows only collaborators and administrators. |
|
|CollaboratorsAuthenticator|collaboratorsOnly|Allows only collaborators and administrators. |
|
||||||
|ReferrerAuthenticator |referrersOnly |Allows only the repository owner (or manager for group repository) and administrators.|
|
|ReferrerAuthenticator |referrersOnly |Allows only the repository owner (or manager for group repository) and administrators.|
|
||||||
|ReadableUsersAuthenticator|readableUsersOnly|Allows only signed in users which can access the repository. |
|
|ReadableUsersAuthenticator|readableUsersOnly|Allows only signed-in users which can access the repository. |
|
||||||
|GroupManagerAuthenticator |managersOnly |Allows only the group managers. |
|
|GroupManagerAuthenticator |managersOnly |Allows only the group managers. |
|
||||||
|
|
||||||
Of course, if you make a new plugin, you can define a your own authenticator according to requirement in your plugin.
|
Of course, if you make a new plugin, you can implement your own authenticator according to requirement in your plugin.
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ Automatic Schema Updating
|
|||||||
========
|
========
|
||||||
GitBucket updates database schema automatically using [Solidbase](https://github.com/gitbucket/solidbase) in the first run after the upgrading.
|
GitBucket updates database schema automatically using [Solidbase](https://github.com/gitbucket/solidbase) in the first run after the upgrading.
|
||||||
|
|
||||||
To release a new version of GitBucket, add the version definition to the [gitbucket.core.GitBucketCoreModule](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/GitBucketCoreModule.scala) at first.
|
To release a new version of GitBucket, add the version definition to [gitbucket.core.GitBucketCoreModule](https://github.com/gitbucket/gitbucket/blob/master/src/main/scala/gitbucket/core/GitBucketCoreModule.scala) at first.
|
||||||
|
|
||||||
```scala
|
```scala
|
||||||
object GitBucketCoreModule extends Module("gitbucket-core",
|
object GitBucketCoreModule extends Module("gitbucket-core",
|
||||||
@@ -17,7 +17,7 @@ object GitBucketCoreModule extends Module("gitbucket-core",
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
Next, add a XML file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) with a filenane defined in `GitBucketCoreModule`.
|
Next, add a XML file which updates database schema into [/src/main/resources/update/](https://github.com/gitbucket/gitbucket/tree/master/src/main/resources/update) with a filename defined in `GitBucketCoreModule`.
|
||||||
|
|
||||||
```xml
|
```xml
|
||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
@@ -31,9 +31,9 @@ Next, add a XML file which updates database schema into [/src/main/resources/upd
|
|||||||
</changeSet>
|
</changeSet>
|
||||||
```
|
```
|
||||||
|
|
||||||
Solidbase stores the current version to `VERSIONS` table and checks it at start-up. If the stored version differs from the actual version, it executes differences between the stored version and the actual version.
|
Solidbase stores the current version to `VERSIONS` table and checks it at start-up. If the stored version different from the actual version, it executes differences between the stored version and the actual version.
|
||||||
|
|
||||||
We can add the SQL file instead of the XML file using `SqlMigration`. It try to load a SQL file from classpath as following order:
|
We can add the SQL file instead of the XML file using `SqlMigration`. It tries to load a SQL file from classpath in the following order:
|
||||||
|
|
||||||
1. Specified path (if specified)
|
1. Specified path (if specified)
|
||||||
2. `${moduleId}_${version}_${database}.sql`
|
2. `${moduleId}_${version}_${database}.sql`
|
||||||
@@ -51,4 +51,4 @@ object GitBucketCoreModule extends Module("gitbucket-core",
|
|||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
See more details [README of Solidbase](https://github.com/gitbucket/solidbase).
|
See more details at [README of Solidbase](https://github.com/gitbucket/solidbase).
|
||||||
|
|||||||
@@ -18,12 +18,12 @@ $ sbt ~jetty:start
|
|||||||
|
|
||||||
Then access `http://localhost:8080/` in your browser. The default administrator account is `root` and password is `root`.
|
Then access `http://localhost:8080/` in your browser. The default administrator account is `root` and password is `root`.
|
||||||
|
|
||||||
Source code modifications are detected and a reloaded happens automatically. You can modify the logging configuration by editing `src/main/resources/logback-dev.xml`.
|
Source code modifications are detected and a reloading happens automatically. You can modify the logging configuration by editing `src/main/resources/logback-dev.xml`.
|
||||||
|
|
||||||
Build war file
|
Build war file
|
||||||
--------
|
--------
|
||||||
|
|
||||||
To build war file, run the following command:
|
To build a war file, run the following command:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
$ sbt package
|
$ sbt package
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 203 KiB After Width: | Height: | Size: 112 KiB |
@@ -1 +1 @@
|
|||||||
sbt.version=1.4.4
|
sbt.version=1.7.2
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
|
||||||
|
|
||||||
addSbtPlugin("com.geirsson" % "sbt-scalafmt" % "1.5.1")
|
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.4.6")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.0")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-twirl" % "1.5.1")
|
||||||
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.15.0")
|
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.0.0")
|
||||||
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
addSbtPlugin("org.scalatra.sbt" % "sbt-scalatra" % "1.0.4")
|
||||||
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "1.1.2")
|
addSbtPlugin("com.github.sbt" % "sbt-pgp" % "2.1.2")
|
||||||
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
addSbtPlugin("com.typesafe.sbt" % "sbt-license-report" % "1.2.0")
|
||||||
addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2")
|
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "2.0.0")
|
||||||
addSbtPlugin("org.scoverage" % "sbt-scoverage" % "1.6.1")
|
|
||||||
|
addDependencyTreePlugin
|
||||||
|
|||||||
@@ -1,51 +1,101 @@
|
|||||||
import org.eclipse.jetty.server.ConnectionFactory;
|
import org.eclipse.jetty.http.HttpVersion;
|
||||||
import org.eclipse.jetty.server.Connector;
|
|
||||||
import org.eclipse.jetty.server.Handler;
|
import org.eclipse.jetty.server.Handler;
|
||||||
|
import org.eclipse.jetty.server.HttpConfiguration;
|
||||||
import org.eclipse.jetty.server.HttpConnectionFactory;
|
import org.eclipse.jetty.server.HttpConnectionFactory;
|
||||||
|
import org.eclipse.jetty.server.SecureRequestCustomizer;
|
||||||
import org.eclipse.jetty.server.Server;
|
import org.eclipse.jetty.server.Server;
|
||||||
|
import org.eclipse.jetty.server.ServerConnector;
|
||||||
|
import org.eclipse.jetty.server.SslConnectionFactory;
|
||||||
|
import org.eclipse.jetty.server.handler.HandlerList;
|
||||||
|
import org.eclipse.jetty.server.handler.SecuredRedirectHandler;
|
||||||
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
import org.eclipse.jetty.server.handler.StatisticsHandler;
|
||||||
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
import org.eclipse.jetty.server.session.DefaultSessionCache;
|
||||||
import org.eclipse.jetty.server.session.FileSessionDataStore;
|
import org.eclipse.jetty.server.session.FileSessionDataStore;
|
||||||
import org.eclipse.jetty.server.session.SessionCache;
|
import org.eclipse.jetty.server.session.SessionCache;
|
||||||
import org.eclipse.jetty.server.session.SessionHandler;
|
import org.eclipse.jetty.server.session.SessionHandler;
|
||||||
|
import org.eclipse.jetty.util.ssl.SslContextFactory;
|
||||||
import org.eclipse.jetty.webapp.WebAppContext;
|
import org.eclipse.jetty.webapp.WebAppContext;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.InetSocketAddress;
|
|
||||||
import java.security.ProtectionDomain;
|
import java.security.ProtectionDomain;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import static java.util.function.Function.identity;
|
||||||
|
import static java.util.stream.Collectors.toSet;
|
||||||
|
|
||||||
public class JettyLauncher {
|
public class JettyLauncher {
|
||||||
|
|
||||||
|
private interface Defaults {
|
||||||
|
|
||||||
|
String CONNECTORS = "http";
|
||||||
|
String HOST = "0.0.0.0";
|
||||||
|
|
||||||
|
int HTTP_PORT = 8080;
|
||||||
|
int HTTPS_PORT = 8443;
|
||||||
|
|
||||||
|
boolean REDIRECT_HTTPS = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface Connectors {
|
||||||
|
|
||||||
|
String HTTP = "http";
|
||||||
|
String HTTPS = "https";
|
||||||
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws Exception {
|
public static void main(String[] args) throws Exception {
|
||||||
System.setProperty("java.awt.headless", "true");
|
System.setProperty("java.awt.headless", "true");
|
||||||
|
|
||||||
String host = null;
|
String connectors = getEnvironmentVariable("gitbucket.connectors");
|
||||||
String port = null;
|
String host = getEnvironmentVariable("gitbucket.host");
|
||||||
InetSocketAddress address = null;
|
String port = getEnvironmentVariable("gitbucket.port");
|
||||||
String contextPath = "/";
|
String securePort = getEnvironmentVariable("gitbucket.securePort");
|
||||||
String tmpDirPath="";
|
String keyStorePath = getEnvironmentVariable("gitbucket.keyStorePath");
|
||||||
boolean forceHttps = false;
|
String keyStorePassword = getEnvironmentVariable("gitbucket.keyStorePassword");
|
||||||
|
String keyManagerPassword = getEnvironmentVariable("gitbucket.keyManagerPassword");
|
||||||
|
String redirectHttps = getEnvironmentVariable("gitbucket.redirectHttps");
|
||||||
|
String contextPath = getEnvironmentVariable("gitbucket.prefix");
|
||||||
|
String tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
||||||
|
String jettyIdleTimeout = getEnvironmentVariable("gitbucket.jettyIdleTimeout");
|
||||||
boolean saveSessions = false;
|
boolean saveSessions = false;
|
||||||
|
|
||||||
host = getEnvironmentVariable("gitbucket.host");
|
|
||||||
port = getEnvironmentVariable("gitbucket.port");
|
|
||||||
contextPath = getEnvironmentVariable("gitbucket.prefix");
|
|
||||||
tmpDirPath = getEnvironmentVariable("gitbucket.tempDir");
|
|
||||||
|
|
||||||
for(String arg: args) {
|
for(String arg: args) {
|
||||||
if(arg.equals("--save_sessions")) {
|
if(arg.equals("--save_sessions")) {
|
||||||
saveSessions = true;
|
saveSessions = true;
|
||||||
}
|
}
|
||||||
if(arg.startsWith("--") && arg.contains("=")) {
|
if(arg.startsWith("--") && arg.contains("=")) {
|
||||||
String[] dim = arg.split("=");
|
String[] dim = arg.split("=", 2);
|
||||||
if(dim.length >= 2) {
|
if(dim.length == 2) {
|
||||||
switch (dim[0]) {
|
switch (dim[0]) {
|
||||||
|
case "--connectors":
|
||||||
|
connectors = dim[1];
|
||||||
|
break;
|
||||||
case "--host":
|
case "--host":
|
||||||
host = dim[1];
|
host = dim[1];
|
||||||
break;
|
break;
|
||||||
case "--port":
|
case "--port":
|
||||||
port = dim[1];
|
port = dim[1];
|
||||||
break;
|
break;
|
||||||
|
case "--secure_port":
|
||||||
|
securePort = dim[1];
|
||||||
|
break;
|
||||||
|
case "--key_store_path":
|
||||||
|
keyStorePath = dim[1];
|
||||||
|
break;
|
||||||
|
case "--key_store_password":
|
||||||
|
keyStorePassword = dim[1];
|
||||||
|
break;
|
||||||
|
case "--key_manager_password":
|
||||||
|
keyManagerPassword = dim[1];
|
||||||
|
break;
|
||||||
|
case "--redirect_https":
|
||||||
|
redirectHttps = dim[1];
|
||||||
|
break;
|
||||||
case "--prefix":
|
case "--prefix":
|
||||||
contextPath = dim[1];
|
contextPath = dim[1];
|
||||||
break;
|
break;
|
||||||
@@ -58,6 +108,9 @@ public class JettyLauncher {
|
|||||||
case "--plugin_dir":
|
case "--plugin_dir":
|
||||||
System.setProperty("gitbucket.pluginDir", dim[1]);
|
System.setProperty("gitbucket.pluginDir", dim[1]);
|
||||||
break;
|
break;
|
||||||
|
case "--jetty_idle_timeout":
|
||||||
|
jettyIdleTimeout = dim[1];
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -67,38 +120,74 @@ public class JettyLauncher {
|
|||||||
contextPath = "/" + contextPath;
|
contextPath = "/" + contextPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(host != null) {
|
final String hostName = InetAddress.getByName(fallback(host, Defaults.HOST)).getHostName();
|
||||||
address = new InetSocketAddress(host, getPort(port));
|
|
||||||
|
final Server server = new Server();
|
||||||
|
|
||||||
|
final Set<String> connectorsSet = Stream.of(fallback(connectors, Defaults.CONNECTORS)
|
||||||
|
.toLowerCase().split(",")).map(String::trim).collect(toSet());
|
||||||
|
|
||||||
|
final List<ServerConnector> connectorInstances = new ArrayList<>();
|
||||||
|
|
||||||
|
final HttpConfiguration httpConfig = new HttpConfiguration();
|
||||||
|
httpConfig.setSendServerVersion(false);
|
||||||
|
if (connectorsSet.contains(Connectors.HTTPS)) {
|
||||||
|
httpConfig.setSecurePort(fallback(securePort, Defaults.HTTPS_PORT, Integer::parseInt));
|
||||||
|
}
|
||||||
|
if (jettyIdleTimeout != null && jettyIdleTimeout.trim().length() != 0) {
|
||||||
|
httpConfig.setIdleTimeout(Long.parseLong(jettyIdleTimeout.trim()));
|
||||||
} else {
|
} else {
|
||||||
address = new InetSocketAddress(getPort(port));
|
httpConfig.setIdleTimeout(300000L); // default is 5min
|
||||||
}
|
}
|
||||||
|
|
||||||
Server server = new Server(address);
|
if (connectorsSet.contains(Connectors.HTTP)) {
|
||||||
|
final ServerConnector connector = new ServerConnector(server, new HttpConnectionFactory(httpConfig));
|
||||||
|
connector.setHost(hostName);
|
||||||
|
connector.setPort(fallback(port, Defaults.HTTP_PORT, Integer::parseInt));
|
||||||
|
|
||||||
// SelectChannelConnector connector = new SelectChannelConnector();
|
connectorInstances.add(connector);
|
||||||
// if(host != null) {
|
}
|
||||||
// connector.setHost(host);
|
|
||||||
// }
|
|
||||||
// connector.setMaxIdleTime(1000 * 60 * 60);
|
|
||||||
// connector.setSoLingerTime(-1);
|
|
||||||
// connector.setPort(port);
|
|
||||||
// server.addConnector(connector);
|
|
||||||
|
|
||||||
// Disabling Server header
|
if (connectorsSet.contains(Connectors.HTTPS)) {
|
||||||
for (Connector connector : server.getConnectors()) {
|
final SslContextFactory sslContextFactory = new SslContextFactory.Server();
|
||||||
for (ConnectionFactory factory : connector.getConnectionFactories()) {
|
|
||||||
if (factory instanceof HttpConnectionFactory) {
|
sslContextFactory.setKeyStorePath(requireNonNull(keyStorePath,
|
||||||
((HttpConnectionFactory) factory).getHttpConfiguration().setSendServerVersion(false);
|
"You must specify a path to an SSL keystore via the --key_store_path command line argument" +
|
||||||
}
|
" or GITBUCKET_KEYSTOREPATH environment variable."));
|
||||||
}
|
|
||||||
|
sslContextFactory.setKeyStorePassword(requireNonNull(keyStorePassword,
|
||||||
|
"You must specify a an SSL keystore password via the --key_store_password argument" +
|
||||||
|
" or GITBUCKET_KEYSTOREPASSWORD environment variable."));
|
||||||
|
|
||||||
|
sslContextFactory.setKeyManagerPassword(requireNonNull(keyManagerPassword,
|
||||||
|
"You must specify a key manager password via the --key_manager_password' argument" +
|
||||||
|
" or GITBUCKET_KEYMANAGERPASSWORD environment variable."));
|
||||||
|
|
||||||
|
final HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
|
||||||
|
httpsConfig.addCustomizer(new SecureRequestCustomizer());
|
||||||
|
|
||||||
|
final ServerConnector connector = new ServerConnector(server,
|
||||||
|
new SslConnectionFactory(sslContextFactory, HttpVersion.HTTP_1_1.asString()),
|
||||||
|
new HttpConnectionFactory(httpsConfig));
|
||||||
|
|
||||||
|
connector.setHost(hostName);
|
||||||
|
connector.setPort(fallback(securePort, Defaults.HTTPS_PORT, Integer::parseInt));
|
||||||
|
|
||||||
|
connectorInstances.add(connector);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
require(!connectorInstances.isEmpty(),
|
||||||
|
"No server connectors could be configured, please check your --connectors command line argument" +
|
||||||
|
" or GITBUCKET_CONNECTORS environment variable.");
|
||||||
|
|
||||||
|
server.setConnectors(connectorInstances.toArray(new ServerConnector[0]));
|
||||||
|
|
||||||
WebAppContext context = new WebAppContext();
|
WebAppContext context = new WebAppContext();
|
||||||
|
|
||||||
if(saveSessions) {
|
if(saveSessions) {
|
||||||
File sessDir = new File(getGitBucketHome(), "sessions");
|
File sessDir = new File(getGitBucketHome(), "sessions");
|
||||||
if(!sessDir.exists()){
|
if(!sessDir.exists()){
|
||||||
sessDir.mkdirs();
|
mkdir(sessDir);
|
||||||
}
|
}
|
||||||
SessionHandler sessions = context.getSessionHandler();
|
SessionHandler sessions = context.getSessionHandler();
|
||||||
SessionCache cache = new DefaultSessionCache(sessions);
|
SessionCache cache = new DefaultSessionCache(sessions);
|
||||||
@@ -112,7 +201,7 @@ public class JettyLauncher {
|
|||||||
if(tmpDirPath == null || tmpDirPath.equals("")){
|
if(tmpDirPath == null || tmpDirPath.equals("")){
|
||||||
tmpDir = new File(getGitBucketHome(), "tmp");
|
tmpDir = new File(getGitBucketHome(), "tmp");
|
||||||
if(!tmpDir.exists()){
|
if(!tmpDir.exists()){
|
||||||
tmpDir.mkdirs();
|
mkdir(tmpDir);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
tmpDir = new File(tmpDirPath);
|
tmpDir = new File(tmpDirPath);
|
||||||
@@ -136,13 +225,16 @@ public class JettyLauncher {
|
|||||||
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
|
context.setDescriptor(location.toExternalForm() + "/WEB-INF/web.xml");
|
||||||
context.setServer(server);
|
context.setServer(server);
|
||||||
context.setWar(location.toExternalForm());
|
context.setWar(location.toExternalForm());
|
||||||
if (forceHttps) {
|
|
||||||
context.setInitParameter("org.scalatra.ForceHttps", "true");
|
final HandlerList handlers = new HandlerList();
|
||||||
|
|
||||||
|
if (fallback(redirectHttps, Defaults.REDIRECT_HTTPS, Boolean::parseBoolean)) {
|
||||||
|
handlers.addHandler(new SecuredRedirectHandler());
|
||||||
}
|
}
|
||||||
|
|
||||||
Handler handler = addStatisticsHandler(context);
|
handlers.addHandler(addStatisticsHandler(context));
|
||||||
|
|
||||||
server.setHandler(handler);
|
server.setHandler(handlers);
|
||||||
server.setStopAtShutdown(true);
|
server.setStopAtShutdown(true);
|
||||||
server.setStopTimeout(7_000);
|
server.setStopTimeout(7_000);
|
||||||
server.start();
|
server.start();
|
||||||
@@ -170,11 +262,28 @@ public class JettyLauncher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int getPort(String port){
|
private static <T, R> T fallback(R value, T defaultValue, Function<R, T> converter) {
|
||||||
if(port == null) {
|
return value == null ? defaultValue : converter.apply(value);
|
||||||
return 8080;
|
}
|
||||||
} else {
|
|
||||||
return Integer.parseInt(port);
|
private static <T> T fallback(T value, T defaultValue) {
|
||||||
|
return fallback(value, defaultValue, identity());
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void require(boolean condition, String message) {
|
||||||
|
if (!condition) {
|
||||||
|
throw new IllegalArgumentException(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static <T> T requireNonNull(T value, String message) {
|
||||||
|
require(value != null, message);
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void mkdir(File dir) {
|
||||||
|
if (!dir.mkdirs()) {
|
||||||
|
throw new RuntimeException("Unable to create directory: " + dir);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -20,15 +20,15 @@ public class PatchUtil {
|
|||||||
public static String apply(String source, String patch, FileHeader fh)
|
public static String apply(String source, String patch, FileHeader fh)
|
||||||
throws IOException, PatchApplyException {
|
throws IOException, PatchApplyException {
|
||||||
RawText rt = new RawText(source.getBytes("UTF-8"));
|
RawText rt = new RawText(source.getBytes("UTF-8"));
|
||||||
List<String> oldLines = new ArrayList<String>(rt.size());
|
List<String> oldLines = new ArrayList<>(rt.size());
|
||||||
for (int i = 0; i < rt.size(); i++)
|
for (int i = 0; i < rt.size(); i++)
|
||||||
oldLines.add(rt.getString(i));
|
oldLines.add(rt.getString(i));
|
||||||
List<String> newLines = new ArrayList<String>(oldLines);
|
List<String> newLines = new ArrayList<>(oldLines);
|
||||||
for (HunkHeader hh : fh.getHunks()) {
|
for (HunkHeader hh : fh.getHunks()) {
|
||||||
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
ByteArrayOutputStream out = new ByteArrayOutputStream();
|
||||||
out.write(patch.getBytes("UTF-8"), hh.getStartOffset(), hh.getEndOffset() - hh.getStartOffset());
|
out.write(patch.getBytes("UTF-8"), hh.getStartOffset(), hh.getEndOffset() - hh.getStartOffset());
|
||||||
RawText hrt = new RawText(out.toByteArray());
|
RawText hrt = new RawText(out.toByteArray());
|
||||||
List<String> hunkLines = new ArrayList<String>(hrt.size());
|
List<String> hunkLines = new ArrayList<>(hrt.size());
|
||||||
for (int i = 0; i < hrt.size(); i++)
|
for (int i = 0; i < hrt.size(); i++)
|
||||||
hunkLines.add(hrt.getString(i));
|
hunkLines.add(hrt.getString(i));
|
||||||
int pos = 0;
|
int pos = 0;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
notifications:1.9.0
|
notifications:1.11.0
|
||||||
gist:4.20.0
|
gist:4.22.0
|
||||||
emoji:4.6.0
|
emoji:4.6.0
|
||||||
pages:1.9.0
|
pages:1.10.0
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 3.0 KiB After Width: | Height: | Size: 1.5 KiB |
@@ -1,18 +0,0 @@
|
|||||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
|
||||||
SELECT
|
|
||||||
A.USER_NAME,
|
|
||||||
A.REPOSITORY_NAME,
|
|
||||||
A.ISSUE_ID,
|
|
||||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT
|
|
||||||
FROM ISSUE A
|
|
||||||
LEFT OUTER JOIN (
|
|
||||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
|
||||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
|
||||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
|
||||||
) B
|
|
||||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
|
||||||
LEFT OUTER JOIN (
|
|
||||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
|
||||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
|
||||||
) C
|
|
||||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID);
|
|
||||||
@@ -343,4 +343,28 @@
|
|||||||
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_PK" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH, CONTEXT"/>
|
<addPrimaryKey constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_PK" tableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" columnNames="USER_NAME, REPOSITORY_NAME, BRANCH, CONTEXT"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_FK0" baseTableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" baseColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" referencedTableName="PROTECTED_BRANCH" referencedColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" onDelete="CASCADE" onUpdate="CASCADE"/>
|
<addForeignKeyConstraint constraintName="IDX_PROTECTED_BRANCH_REQUIRE_CONTEXT_FK0" baseTableName="PROTECTED_BRANCH_REQUIRE_CONTEXT" baseColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" referencedTableName="PROTECTED_BRANCH" referencedColumnNames="USER_NAME, REPOSITORY_NAME, BRANCH" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- ISSUE_OUTLINE_VIEW -->
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<sql>
|
||||||
|
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||||
|
SELECT
|
||||||
|
A.USER_NAME,
|
||||||
|
A.REPOSITORY_NAME,
|
||||||
|
A.ISSUE_ID,
|
||||||
|
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT
|
||||||
|
FROM ISSUE A
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||||
|
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||||
|
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||||
|
) B
|
||||||
|
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||||
|
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||||
|
) C
|
||||||
|
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
||||||
|
</sql>
|
||||||
|
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|||||||
@@ -1,26 +0,0 @@
|
|||||||
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
|
||||||
|
|
||||||
SELECT
|
|
||||||
A.USER_NAME,
|
|
||||||
A.REPOSITORY_NAME,
|
|
||||||
A.ISSUE_ID,
|
|
||||||
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT,
|
|
||||||
COALESCE(D.ORDERING, 9999) AS PRIORITY
|
|
||||||
|
|
||||||
FROM ISSUE A
|
|
||||||
|
|
||||||
LEFT OUTER JOIN (
|
|
||||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
|
||||||
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
|
||||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
|
||||||
) B
|
|
||||||
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
|
||||||
|
|
||||||
LEFT OUTER JOIN (
|
|
||||||
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
|
||||||
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
|
||||||
) C
|
|
||||||
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
|
||||||
|
|
||||||
LEFT OUTER JOIN PRIORITY D
|
|
||||||
ON (A.PRIORITY_ID = D.PRIORITY_ID);
|
|
||||||
@@ -35,4 +35,28 @@
|
|||||||
<column name="URL" type="varchar(200)" nullable="false"/>
|
<column name="URL" type="varchar(200)" nullable="false"/>
|
||||||
<column name="EVENT" type="varchar(30)" nullable="false"/>
|
<column name="EVENT" type="varchar(30)" nullable="false"/>
|
||||||
</createTable>
|
</createTable>
|
||||||
|
|
||||||
|
<sql>
|
||||||
|
CREATE OR REPLACE VIEW ISSUE_OUTLINE_VIEW AS
|
||||||
|
SELECT
|
||||||
|
A.USER_NAME,
|
||||||
|
A.REPOSITORY_NAME,
|
||||||
|
A.ISSUE_ID,
|
||||||
|
COALESCE(B.COMMENT_COUNT, 0) + COALESCE(C.COMMENT_COUNT, 0) AS COMMENT_COUNT,
|
||||||
|
COALESCE(D.ORDERING, 9999) AS PRIORITY
|
||||||
|
FROM ISSUE A
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM ISSUE_COMMENT
|
||||||
|
WHERE ACTION IN ('comment', 'close_comment', 'reopen_comment')
|
||||||
|
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||||
|
) B
|
||||||
|
ON (A.USER_NAME = B.USER_NAME AND A.REPOSITORY_NAME = B.REPOSITORY_NAME AND A.ISSUE_ID = B.ISSUE_ID)
|
||||||
|
LEFT OUTER JOIN (
|
||||||
|
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, COUNT(COMMENT_ID) AS COMMENT_COUNT FROM COMMIT_COMMENT
|
||||||
|
GROUP BY USER_NAME, REPOSITORY_NAME, ISSUE_ID
|
||||||
|
) C
|
||||||
|
ON (A.USER_NAME = C.USER_NAME AND A.REPOSITORY_NAME = C.REPOSITORY_NAME AND A.ISSUE_ID = C.ISSUE_ID)
|
||||||
|
LEFT OUTER JOIN PRIORITY D
|
||||||
|
ON (A.PRIORITY_ID = D.PRIORITY_ID);
|
||||||
|
</sql>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|||||||
@@ -1,17 +1,35 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<changeSet>
|
<changeSet>
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- WEB_HOOK -->
|
||||||
|
<!--================================================================================================-->
|
||||||
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
||||||
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK"/>
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK"/>
|
||||||
<dropPrimaryKey tableName="WEB_HOOK" constraintName="IDX_WEB_HOOK_PK"/>
|
<dropPrimaryKey constraintName="IDX_WEB_HOOK_PK" tableName="WEB_HOOK"/>
|
||||||
<addColumn tableName="WEB_HOOK">
|
|
||||||
<column name="HOOK_ID" type="int" nullable="false" unique="true"/>
|
<createTable tableName="WEB_HOOK_2">
|
||||||
</addColumn>
|
<column name="HOOK_ID" type="int" nullable="true" autoIncrement="true" unique="false" primaryKeyName="IDX_WEB_HOOK_PK" primaryKey="true" />
|
||||||
<addPrimaryKey constraintName="IDX_WEB_HOOK_PK" tableName="WEB_HOOK" columnNames="USER_NAME, REPOSITORY_NAME, URL, HOOK_ID"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="URL" type="varchar(200)" nullable="false"/>
|
||||||
|
<column name="TOKEN" type="varchar(100)" nullable="true"/>
|
||||||
|
<column name="CTYPE" type="varchar(10)" nullable="true"/>
|
||||||
|
</createTable>
|
||||||
|
|
||||||
|
<sql>
|
||||||
|
INSERT INTO WEB_HOOK_2 (USER_NAME, REPOSITORY_NAME, URL, TOKEN, CTYPE) SELECT USER_NAME, REPOSITORY_NAME, URL, TOKEN, CTYPE FROM WEB_HOOK
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<renameTable newTableName="WEB_HOOK_BK" oldTableName="WEB_HOOK"/>
|
||||||
|
<renameTable newTableName="WEB_HOOK" oldTableName="WEB_HOOK_2"/>
|
||||||
|
|
||||||
<addUniqueConstraint constraintName="IDX_WEB_HOOK_1" tableName="WEB_HOOK" columnNames="USER_NAME, REPOSITORY_NAME, URL"/>
|
<addUniqueConstraint constraintName="IDX_WEB_HOOK_1" tableName="WEB_HOOK" columnNames="USER_NAME, REPOSITORY_NAME, URL"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_FK0" baseTableName="WEB_HOOK" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, URL" referencedTableName="WEB_HOOK" referencedColumnNames="USER_NAME, REPOSITORY_NAME, URL" onDelete="CASCADE" onUpdate="CASCADE"/>
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, URL" referencedTableName="WEB_HOOK" referencedColumnNames="USER_NAME, REPOSITORY_NAME, URL" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
<addAutoIncrement columnName="HOOK_ID" columnDataType="int" tableName="WEB_HOOK"/>
|
|
||||||
|
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- ACCOUNT_PREFERENCE -->
|
||||||
|
<!--================================================================================================-->
|
||||||
<createTable tableName="ACCOUNT_PREFERENCE">
|
<createTable tableName="ACCOUNT_PREFERENCE">
|
||||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
<column name="HIGHLIGHTER_THEME" type="varchar(100)" nullable="false" defaultValue="prettify"/>
|
<column name="HIGHLIGHTER_THEME" type="varchar(100)" nullable="false" defaultValue="prettify"/>
|
||||||
|
|||||||
6
src/main/resources/update/gitbucket-core_4.36.xml
Normal file
6
src/main/resources/update/gitbucket-core_4.36.xml
Normal file
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<addColumn tableName="REPOSITORY">
|
||||||
|
<column name="SAFE_MODE" type="boolean" nullable="false" defaultValue="true"/>
|
||||||
|
</addColumn>
|
||||||
|
</changeSet>
|
||||||
7
src/main/resources/update/gitbucket-core_4.37.xml
Normal file
7
src/main/resources/update/gitbucket-core_4.37.xml
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<dropForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT"/>
|
||||||
|
<modifyDataType columnName="URL" newDataType="varchar(400)" tableName="WEB_HOOK_EVENT"/>
|
||||||
|
<modifyDataType columnName="URL" newDataType="varchar(400)" tableName="WEB_HOOK"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_WEB_HOOK_EVENT_FK0" baseTableName="WEB_HOOK_EVENT" baseColumnNames="USER_NAME, REPOSITORY_NAME, URL" referencedTableName="WEB_HOOK" referencedColumnNames="USER_NAME, REPOSITORY_NAME, URL" onDelete="CASCADE" onUpdate="CASCADE"/>
|
||||||
|
</changeSet>
|
||||||
53
src/main/resources/update/gitbucket-core_4.38.xml
Normal file
53
src/main/resources/update/gitbucket-core_4.38.xml
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<changeSet>
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- CUSTOM_FIELD -->
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<createTable tableName="CUSTOM_FIELD">
|
||||||
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="FIELD_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
||||||
|
<column name="FIELD_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="FIELD_TYPE" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="ENABLE_FOR_ISSUES" type="boolean" nullable="false"/>
|
||||||
|
<column name="ENABLE_FOR_PULL_REQUESTS" type="boolean" nullable="false"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey constraintName="IDX_CUSTOM_FIELD_PK" tableName="CUSTOM_FIELD" columnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_CUSTOM_FIELD_FK0" baseTableName="CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||||
|
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- ISSUE_CUSTOM_FIELD -->
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<createTable tableName="ISSUE_CUSTOM_FIELD">
|
||||||
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="ISSUE_ID" type="int" nullable="false"/>
|
||||||
|
<column name="FIELD_ID" type="int" nullable="false"/>
|
||||||
|
<column name="VALUE" type="varchar(200)" nullable="true"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey constraintName="IDX_ISSUE_CUSTOM_FIELD_PK" tableName="ISSUE_CUSTOM_FIELD" columnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID, FIELD_ID"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_CUSTOM_FIELD_FK0" baseTableName="ISSUE_CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_CUSTOM_FIELD_FK1" baseTableName="ISSUE_CUSTOM_FIELD" baseColumnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID" referencedTableName="CUSTOM_FIELD" referencedColumnNames="USER_NAME, REPOSITORY_NAME, FIELD_ID"/>
|
||||||
|
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<!-- ISSUE_ASSIGNEE -->
|
||||||
|
<!--================================================================================================-->
|
||||||
|
<createTable tableName="ISSUE_ASSIGNEE">
|
||||||
|
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
<column name="ISSUE_ID" type="int" nullable="false"/>
|
||||||
|
<column name="ASSIGNEE_USER_NAME" type="varchar(100)" nullable="false"/>
|
||||||
|
</createTable>
|
||||||
|
<addPrimaryKey constraintName="IDX_ISSUE_ASSIGNEE_PK" tableName="ISSUE_ASSIGNEE" columnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNEE_USER_NAME"/>
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_ASSIGNEE_FK0" baseTableName="ISSUE_ASSIGNEE" baseColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID" referencedTableName="ISSUE" referencedColumnNames="USER_NAME, REPOSITORY_NAME, ISSUE_ID"/>
|
||||||
|
<!--
|
||||||
|
<addForeignKeyConstraint constraintName="IDX_ISSUE_ASSIGNEE_FK1" baseTableName="ISSUE_ASSIGNEE" baseColumnNames="ASSIGNEE_USER_NAME" referencedTableName="ACCOUNT" referencedColumnNames="USER_NAME"/>
|
||||||
|
-->
|
||||||
|
|
||||||
|
<sql>
|
||||||
|
INSERT INTO ISSUE_ASSIGNEE (USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNEE_USER_NAME)
|
||||||
|
SELECT USER_NAME, REPOSITORY_NAME, ISSUE_ID, ASSIGNED_USER_NAME FROM ISSUE WHERE ASSIGNED_USER_NAME IS NOT NULL
|
||||||
|
</sql>
|
||||||
|
|
||||||
|
<dropColumn tableName="ISSUE" columnName="ASSIGNED_USER_NAME"/>
|
||||||
|
</changeSet>
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
-- DELETE COLLABORATORS IN GROUP REPOSITORIES
|
|
||||||
DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE)
|
|
||||||
@@ -30,4 +30,9 @@
|
|||||||
<dropColumn tableName="REPOSITORY" columnName="ENABLE_WIKI"/>
|
<dropColumn tableName="REPOSITORY" columnName="ENABLE_WIKI"/>
|
||||||
<dropColumn tableName="REPOSITORY" columnName="ALLOW_WIKI_EDITING"/>
|
<dropColumn tableName="REPOSITORY" columnName="ALLOW_WIKI_EDITING"/>
|
||||||
<dropColumn tableName="REPOSITORY" columnName="ENABLE_ISSUES"/>
|
<dropColumn tableName="REPOSITORY" columnName="ENABLE_ISSUES"/>
|
||||||
|
|
||||||
|
<!-- DELETE COLLABORATORS IN GROUP REPOSITORIES -->
|
||||||
|
<sql>
|
||||||
|
DELETE FROM COLLABORATOR WHERE USER_NAME IN (SELECT USER_NAME FROM ACCOUNT WHERE GROUP_ACCOUNT = TRUE)
|
||||||
|
</sql>
|
||||||
</changeSet>
|
</changeSet>
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ import java.util.EnumSet
|
|||||||
import javax.servlet._
|
import javax.servlet._
|
||||||
|
|
||||||
import gitbucket.core.controller.{ReleaseController, _}
|
import gitbucket.core.controller.{ReleaseController, _}
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
|
||||||
import gitbucket.core.service.SystemSettingsService
|
import gitbucket.core.service.SystemSettingsService
|
||||||
import gitbucket.core.servlet._
|
import gitbucket.core.servlet._
|
||||||
import gitbucket.core.util.Directory
|
import gitbucket.core.util.Directory
|
||||||
|
|||||||
@@ -3,16 +3,15 @@ package gitbucket.core
|
|||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.nio.charset.StandardCharsets
|
import java.nio.charset.StandardCharsets
|
||||||
import java.sql.Connection
|
import java.sql.Connection
|
||||||
import java.util
|
|
||||||
import java.util.UUID
|
import java.util.UUID
|
||||||
|
|
||||||
import gitbucket.core.model.Activity
|
import gitbucket.core.model.Activity
|
||||||
import gitbucket.core.util.Directory.ActivityLog
|
import gitbucket.core.util.Directory.ActivityLog
|
||||||
import gitbucket.core.util.JDBCUtil
|
import gitbucket.core.util.JDBCUtil
|
||||||
import io.github.gitbucket.solidbase.Solidbase
|
import io.github.gitbucket.solidbase.Solidbase
|
||||||
import io.github.gitbucket.solidbase.migration.{LiquibaseMigration, Migration, SqlMigration}
|
import io.github.gitbucket.solidbase.migration.{LiquibaseMigration, Migration}
|
||||||
import io.github.gitbucket.solidbase.model.{Module, Version}
|
import io.github.gitbucket.solidbase.model.{Module, Version}
|
||||||
import org.json4s.NoTypeHints
|
import org.json4s.{Formats, NoTypeHints}
|
||||||
import org.json4s.jackson.Serialization
|
import org.json4s.jackson.Serialization
|
||||||
import org.json4s.jackson.Serialization.write
|
import org.json4s.jackson.Serialization.write
|
||||||
|
|
||||||
@@ -21,11 +20,7 @@ import scala.util.Using
|
|||||||
object GitBucketCoreModule
|
object GitBucketCoreModule
|
||||||
extends Module(
|
extends Module(
|
||||||
"gitbucket-core",
|
"gitbucket-core",
|
||||||
new Version(
|
new Version("4.0.0", new LiquibaseMigration("update/gitbucket-core_4.0.xml")),
|
||||||
"4.0.0",
|
|
||||||
new LiquibaseMigration("update/gitbucket-core_4.0.xml"),
|
|
||||||
new SqlMigration("update/gitbucket-core_4.0.sql")
|
|
||||||
),
|
|
||||||
new Version("4.1.0"),
|
new Version("4.1.0"),
|
||||||
new Version("4.2.0", new LiquibaseMigration("update/gitbucket-core_4.2.xml")),
|
new Version("4.2.0", new LiquibaseMigration("update/gitbucket-core_4.2.xml")),
|
||||||
new Version("4.2.1"),
|
new Version("4.2.1"),
|
||||||
@@ -33,11 +28,7 @@ object GitBucketCoreModule
|
|||||||
new Version("4.4.0"),
|
new Version("4.4.0"),
|
||||||
new Version("4.5.0"),
|
new Version("4.5.0"),
|
||||||
new Version("4.6.0", new LiquibaseMigration("update/gitbucket-core_4.6.xml")),
|
new Version("4.6.0", new LiquibaseMigration("update/gitbucket-core_4.6.xml")),
|
||||||
new Version(
|
new Version("4.7.0", new LiquibaseMigration("update/gitbucket-core_4.7.xml")),
|
||||||
"4.7.0",
|
|
||||||
new LiquibaseMigration("update/gitbucket-core_4.7.xml"),
|
|
||||||
new SqlMigration("update/gitbucket-core_4.7.sql")
|
|
||||||
),
|
|
||||||
new Version("4.7.1"),
|
new Version("4.7.1"),
|
||||||
new Version("4.8"),
|
new Version("4.8"),
|
||||||
new Version("4.9.0", new LiquibaseMigration("update/gitbucket-core_4.9.xml")),
|
new Version("4.9.0", new LiquibaseMigration("update/gitbucket-core_4.9.xml")),
|
||||||
@@ -46,11 +37,7 @@ object GitBucketCoreModule
|
|||||||
new Version("4.12.0"),
|
new Version("4.12.0"),
|
||||||
new Version("4.12.1"),
|
new Version("4.12.1"),
|
||||||
new Version("4.13.0"),
|
new Version("4.13.0"),
|
||||||
new Version(
|
new Version("4.14.0", new LiquibaseMigration("update/gitbucket-core_4.14.xml")),
|
||||||
"4.14.0",
|
|
||||||
new LiquibaseMigration("update/gitbucket-core_4.14.xml"),
|
|
||||||
new SqlMigration("update/gitbucket-core_4.14.sql")
|
|
||||||
),
|
|
||||||
new Version("4.14.1"),
|
new Version("4.14.1"),
|
||||||
new Version("4.15.0"),
|
new Version("4.15.0"),
|
||||||
new Version("4.16.0"),
|
new Version("4.16.0"),
|
||||||
@@ -84,8 +71,8 @@ object GitBucketCoreModule
|
|||||||
new Version(
|
new Version(
|
||||||
"4.34.0",
|
"4.34.0",
|
||||||
new Migration() {
|
new Migration() {
|
||||||
override def migrate(moduleId: String, version: String, context: util.Map[String, AnyRef]): Unit = {
|
override def migrate(moduleId: String, version: String, context: java.util.Map[String, AnyRef]): Unit = {
|
||||||
implicit val formats = Serialization.formats(NoTypeHints)
|
implicit val formats: Formats = Serialization.formats(NoTypeHints)
|
||||||
import JDBCUtil._
|
import JDBCUtil._
|
||||||
|
|
||||||
val conn = context.get(Solidbase.CONNECTION).asInstanceOf[Connection]
|
val conn = context.get(Solidbase.CONNECTION).asInstanceOf[Connection]
|
||||||
@@ -115,4 +102,17 @@ object GitBucketCoreModule
|
|||||||
new LiquibaseMigration("update/gitbucket-core_4.34.xml")
|
new LiquibaseMigration("update/gitbucket-core_4.34.xml")
|
||||||
),
|
),
|
||||||
new Version("4.35.0", new LiquibaseMigration("update/gitbucket-core_4.35.xml")),
|
new Version("4.35.0", new LiquibaseMigration("update/gitbucket-core_4.35.xml")),
|
||||||
|
new Version("4.35.1"),
|
||||||
|
new Version("4.35.2"),
|
||||||
|
new Version("4.35.3"),
|
||||||
|
new Version("4.36.0", new LiquibaseMigration("update/gitbucket-core_4.36.xml")),
|
||||||
|
new Version("4.36.1"),
|
||||||
|
new Version("4.36.2"),
|
||||||
|
new Version("4.37.0", new LiquibaseMigration("update/gitbucket-core_4.37.xml")),
|
||||||
|
new Version("4.37.1"),
|
||||||
|
new Version("4.37.2"),
|
||||||
|
new Version("4.38.0", new LiquibaseMigration("update/gitbucket-core_4.38.xml")),
|
||||||
|
new Version("4.38.1"),
|
||||||
|
new Version("4.38.2"),
|
||||||
|
new Version("4.38.3")
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -66,7 +66,7 @@ object ApiBranchProtection {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
implicit val enforcementLevelSerializer = new CustomSerializer[EnforcementLevel](
|
implicit val enforcementLevelSerializer: CustomSerializer[EnforcementLevel] = new CustomSerializer[EnforcementLevel](
|
||||||
format =>
|
format =>
|
||||||
(
|
(
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -97,7 +97,7 @@ object ApiCommits {
|
|||||||
ApiCommits(
|
ApiCommits(
|
||||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||||
sha = commitInfo.id,
|
sha = commitInfo.id,
|
||||||
html_url = ApiPath(s"${repositoryName.fullName}/commit/${commitInfo.id}"),
|
html_url = ApiPath(s"/${repositoryName.fullName}/commit/${commitInfo.id}"),
|
||||||
comment_url = ApiPath(""), // TODO no API for commit comment
|
comment_url = ApiPath(""), // TODO no API for commit comment
|
||||||
commit = Commit(
|
commit = Commit(
|
||||||
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${commitInfo.id}"),
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ object ApiContents {
|
|||||||
"file",
|
"file",
|
||||||
fileInfo.name,
|
fileInfo.name,
|
||||||
fileInfo.path,
|
fileInfo.path,
|
||||||
fileInfo.commitId,
|
fileInfo.id.getName,
|
||||||
Some(Base64.getEncoder.encodeToString(arr)),
|
Some(Base64.getEncoder.encodeToString(arr)),
|
||||||
Some("base64")
|
Some("base64")
|
||||||
)(repositoryName)
|
)(repositoryName)
|
||||||
|
|||||||
@@ -12,15 +12,16 @@ case class ApiIssue(
|
|||||||
number: Int,
|
number: Int,
|
||||||
title: String,
|
title: String,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
assignee: Option[ApiUser],
|
assignees: List[ApiUser],
|
||||||
labels: List[ApiLabel],
|
labels: List[ApiLabel],
|
||||||
state: String,
|
state: String,
|
||||||
created_at: Date,
|
created_at: Date,
|
||||||
updated_at: Date,
|
updated_at: Date,
|
||||||
body: String
|
body: String,
|
||||||
|
milestone: Option[ApiMilestone]
|
||||||
)(repositoryName: RepositoryName, isPullRequest: Boolean) {
|
)(repositoryName: RepositoryName, isPullRequest: Boolean) {
|
||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
val assignees = List(assignee).flatten
|
val assignee = assignees.headOption
|
||||||
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
val comments_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/issues/${number}/comments")
|
||||||
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}")
|
val html_url = ApiPath(s"/${repositoryName.fullName}/${if (isPullRequest) { "pull" } else { "issues" }}/${number}")
|
||||||
val pull_request = if (isPullRequest) {
|
val pull_request = if (isPullRequest) {
|
||||||
@@ -42,15 +43,17 @@ object ApiIssue {
|
|||||||
issue: Issue,
|
issue: Issue,
|
||||||
repositoryName: RepositoryName,
|
repositoryName: RepositoryName,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
assignee: Option[ApiUser],
|
assignees: List[ApiUser],
|
||||||
labels: List[ApiLabel]
|
labels: List[ApiLabel],
|
||||||
|
milestone: Option[ApiMilestone]
|
||||||
): ApiIssue =
|
): ApiIssue =
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
number = issue.issueId,
|
number = issue.issueId,
|
||||||
title = issue.title,
|
title = issue.title,
|
||||||
user = user,
|
user = user,
|
||||||
assignee = assignee,
|
assignees = assignees,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
|
milestone = milestone,
|
||||||
state = if (issue.closed) { "closed" } else { "open" },
|
state = if (issue.closed) { "closed" } else { "open" },
|
||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
created_at = issue.registeredDate,
|
created_at = issue.registeredDate,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
import gitbucket.core.plugin.{PluginRegistry, PluginInfo}
|
import gitbucket.core.plugin.PluginInfo
|
||||||
|
|
||||||
case class ApiPlugin(
|
case class ApiPlugin(
|
||||||
id: String,
|
id: String,
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ case class ApiPullRequest(
|
|||||||
body: String,
|
body: String,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
labels: List[ApiLabel],
|
labels: List[ApiLabel],
|
||||||
assignee: Option[ApiUser],
|
assignees: List[ApiUser],
|
||||||
draft: Option[Boolean]
|
draft: Option[Boolean]
|
||||||
) {
|
) {
|
||||||
val id = 0 // dummy id
|
val id = 0 // dummy id
|
||||||
|
val assignee = assignees.headOption
|
||||||
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
val html_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}")
|
||||||
//val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
|
//val diff_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.diff")
|
||||||
//val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
|
//val patch_url = ApiPath(s"${base.repo.html_url.path}/pull/${number}.patch")
|
||||||
@@ -45,7 +46,7 @@ object ApiPullRequest {
|
|||||||
baseRepo: ApiRepository,
|
baseRepo: ApiRepository,
|
||||||
user: ApiUser,
|
user: ApiUser,
|
||||||
labels: List[ApiLabel],
|
labels: List[ApiLabel],
|
||||||
assignee: Option[ApiUser],
|
assignees: List[ApiUser],
|
||||||
mergedComment: Option[(IssueComment, Account)]
|
mergedComment: Option[(IssueComment, Account)]
|
||||||
): ApiPullRequest =
|
): ApiPullRequest =
|
||||||
ApiPullRequest(
|
ApiPullRequest(
|
||||||
@@ -63,7 +64,7 @@ object ApiPullRequest {
|
|||||||
body = issue.content.getOrElse(""),
|
body = issue.content.getOrElse(""),
|
||||||
user = user,
|
user = user,
|
||||||
labels = labels,
|
labels = labels,
|
||||||
assignee = assignee,
|
assignees = assignees,
|
||||||
draft = Some(pullRequest.isDraft)
|
draft = Some(pullRequest.isDraft)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,55 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
case class ApiObject(sha: String)
|
import gitbucket.core.util.JGitUtil.TagInfo
|
||||||
|
import gitbucket.core.util.RepositoryName
|
||||||
|
import org.eclipse.jgit.lib.Ref
|
||||||
|
|
||||||
case class ApiRef(ref: String, `object`: ApiObject)
|
case class ApiRefCommit(
|
||||||
|
sha: String,
|
||||||
|
`type`: String,
|
||||||
|
url: ApiPath
|
||||||
|
)
|
||||||
|
|
||||||
|
case class ApiRef(
|
||||||
|
ref: String,
|
||||||
|
node_id: String = "",
|
||||||
|
url: ApiPath,
|
||||||
|
`object`: ApiRefCommit,
|
||||||
|
)
|
||||||
|
|
||||||
|
object ApiRef {
|
||||||
|
|
||||||
|
def fromRef(
|
||||||
|
repositoryName: RepositoryName,
|
||||||
|
ref: Ref
|
||||||
|
): ApiRef =
|
||||||
|
ApiRef(
|
||||||
|
ref = ref.getName,
|
||||||
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/${ref.getName}"),
|
||||||
|
`object` = ApiRefCommit(
|
||||||
|
sha = ref.getObjectId.getName,
|
||||||
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${ref.getObjectId.getName}"),
|
||||||
|
`type` = "commit"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
def fromTag(
|
||||||
|
repositoryName: RepositoryName,
|
||||||
|
tagInfo: TagInfo
|
||||||
|
): ApiRef =
|
||||||
|
ApiRef(
|
||||||
|
ref = s"refs/tags/${tagInfo.name}",
|
||||||
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/git/refs/tags/${tagInfo.name}"),
|
||||||
|
//the GH api distinguishes between "releases" and plain git tags
|
||||||
|
//for "releases", the api returns a reference to the release object (with type `tag`)
|
||||||
|
//this would be something like s"/api/v3/repos/${repositoryName.fullName}/git/tags/<hash-of-tag>"
|
||||||
|
//with a hash for the tag, which I do not fully understand
|
||||||
|
//since this is not yet implemented in GB, we always return a link to the plain `commit` object,
|
||||||
|
//which GH does for tags that are not annotated
|
||||||
|
`object` = ApiRefCommit(
|
||||||
|
sha = tagInfo.objectId,
|
||||||
|
url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/commits/${tagInfo.objectId}"),
|
||||||
|
`type` = "commit"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ case class ApiRepository(
|
|||||||
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
val url = ApiPath(s"/api/v3/repos/${full_name}")
|
||||||
val clone_url = ApiPath(s"/git/${full_name}.git")
|
val clone_url = ApiPath(s"/git/${full_name}.git")
|
||||||
val html_url = ApiPath(s"/${full_name}")
|
val html_url = ApiPath(s"/${full_name}")
|
||||||
val ssh_url = Some(SshPath(s":${full_name}.git"))
|
val ssh_url = Some(SshPath(""))
|
||||||
}
|
}
|
||||||
|
|
||||||
object ApiRepository {
|
object ApiRepository {
|
||||||
|
|||||||
@@ -1,29 +0,0 @@
|
|||||||
package gitbucket.core.api
|
|
||||||
|
|
||||||
import gitbucket.core.util.RepositoryName
|
|
||||||
|
|
||||||
case class ApiTagCommit(
|
|
||||||
sha: String,
|
|
||||||
url: ApiPath
|
|
||||||
)
|
|
||||||
|
|
||||||
case class ApiTag(
|
|
||||||
name: String,
|
|
||||||
commit: ApiTagCommit,
|
|
||||||
zipball_url: ApiPath,
|
|
||||||
tarball_url: ApiPath
|
|
||||||
)
|
|
||||||
|
|
||||||
object ApiTag {
|
|
||||||
def apply(
|
|
||||||
tagName: String,
|
|
||||||
repositoryName: RepositoryName,
|
|
||||||
commitId: String
|
|
||||||
): ApiTag =
|
|
||||||
ApiTag(
|
|
||||||
name = tagName,
|
|
||||||
commit = ApiTagCommit(sha = commitId, url = ApiPath(s"/${repositoryName.fullName}/commits/${commitId}")),
|
|
||||||
zipball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.zip"),
|
|
||||||
tarball_url = ApiPath(s"/${repositoryName.fullName}/archive/${tagName}.tar.gz")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,6 @@
|
|||||||
package gitbucket.core.api
|
package gitbucket.core.api
|
||||||
|
|
||||||
import gitbucket.core.model.Profile.{RepositoryWebHookEvents, RepositoryWebHooks}
|
|
||||||
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
||||||
import gitbucket.core.util.RepositoryName
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* https://docs.github.com/en/rest/reference/repos#webhooks
|
* https://docs.github.com/en/rest/reference/repos#webhooks
|
||||||
|
|||||||
@@ -86,7 +86,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val newForm = mapping(
|
val newForm = mapping(
|
||||||
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("User name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -98,7 +98,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
)(AccountNewForm.apply)
|
)(AccountNewForm.apply)
|
||||||
|
|
||||||
val editForm = mapping(
|
val editForm = mapping(
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -128,6 +128,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
"highlighterTheme" -> trim(label("Theme", text(required)))
|
"highlighterTheme" -> trim(label("Theme", text(required)))
|
||||||
)(SyntaxHighlighterThemeForm.apply)
|
)(SyntaxHighlighterThemeForm.apply)
|
||||||
|
|
||||||
|
val resetPasswordEmailForm = mapping(
|
||||||
|
"mailAddress" -> trim(label("Email", text(required)))
|
||||||
|
)(ResetPasswordEmailForm.apply)
|
||||||
|
|
||||||
|
val resetPasswordForm = mapping(
|
||||||
|
"token" -> trim(label("Token", text(required))),
|
||||||
|
"password" -> trim(label("Password", text(required, maxlength(40))))
|
||||||
|
)(ResetPasswordForm.apply)
|
||||||
|
|
||||||
case class NewGroupForm(
|
case class NewGroupForm(
|
||||||
groupName: String,
|
groupName: String,
|
||||||
description: Option[String],
|
description: Option[String],
|
||||||
@@ -143,6 +152,13 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
members: String,
|
members: String,
|
||||||
clearImage: Boolean
|
clearImage: Boolean
|
||||||
)
|
)
|
||||||
|
case class ResetPasswordEmailForm(
|
||||||
|
mailAddress: String
|
||||||
|
)
|
||||||
|
case class ResetPasswordForm(
|
||||||
|
token: String,
|
||||||
|
password: String
|
||||||
|
)
|
||||||
|
|
||||||
val newGroupForm = mapping(
|
val newGroupForm = mapping(
|
||||||
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"groupName" -> trim(label("Group name", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
@@ -434,7 +450,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
post("/:userName/_personalToken", personalTokenForm)(oneselfOnly { form =>
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName).map { x =>
|
getAccountByUserName(userName).foreach { x =>
|
||||||
val (tokenId, token) = generateAccessToken(userName, form.note)
|
val (tokenId, token) = generateAccessToken(userName, form.note)
|
||||||
flash.update("generatedToken", (tokenId, token))
|
flash.update("generatedToken", (tokenId, token))
|
||||||
}
|
}
|
||||||
@@ -602,7 +618,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/register") {
|
get("/register") {
|
||||||
if (context.settings.allowAccountRegistration) {
|
if (context.settings.basicBehavior.allowAccountRegistration) {
|
||||||
if (context.loginAccount.isDefined) {
|
if (context.loginAccount.isDefined) {
|
||||||
redirect("/")
|
redirect("/")
|
||||||
} else {
|
} else {
|
||||||
@@ -612,7 +628,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
post("/register", newForm) { form =>
|
post("/register", newForm) { form =>
|
||||||
if (context.settings.allowAccountRegistration) {
|
if (context.settings.basicBehavior.allowAccountRegistration) {
|
||||||
createAccount(
|
createAccount(
|
||||||
form.userName,
|
form.userName,
|
||||||
pbkdf2_sha256(form.password),
|
pbkdf2_sha256(form.password),
|
||||||
@@ -628,8 +644,67 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
} else NotFound()
|
} else NotFound()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
get("/reset") {
|
||||||
|
if (context.settings.basicBehavior.allowResetPassword) {
|
||||||
|
html.reset()
|
||||||
|
} else NotFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/reset", resetPasswordEmailForm) { form =>
|
||||||
|
if (context.settings.basicBehavior.allowResetPassword) {
|
||||||
|
getAccountByMailAddress(form.mailAddress).foreach { account =>
|
||||||
|
val token = generateResetPasswordToken(form.mailAddress)
|
||||||
|
val mailer = new Mailer(context.settings)
|
||||||
|
mailer.send(
|
||||||
|
form.mailAddress,
|
||||||
|
"Reset password",
|
||||||
|
s"""Hello, ${account.fullName}!
|
||||||
|
|
|
||||||
|
|You requested to reset the password for your GitBucket account.
|
||||||
|
|If you are not sure about the request, you can ignore this email.
|
||||||
|
|Otherwise, click the following link to set the new password:
|
||||||
|
|${context.baseUrl}/reset/form/${token}
|
||||||
|
|""".stripMargin
|
||||||
|
)
|
||||||
|
}
|
||||||
|
redirect("/reset/sent")
|
||||||
|
} else NotFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/reset/sent") {
|
||||||
|
if (context.settings.basicBehavior.allowResetPassword) {
|
||||||
|
html.resetsent()
|
||||||
|
} else NotFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/reset/form/:token") {
|
||||||
|
if (context.settings.basicBehavior.allowResetPassword) {
|
||||||
|
val token = params("token")
|
||||||
|
decodeResetPasswordToken(token)
|
||||||
|
.map { _ =>
|
||||||
|
html.resetform(token)
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound())
|
||||||
|
} else NotFound()
|
||||||
|
}
|
||||||
|
|
||||||
|
post("/reset/form", resetPasswordForm) { form =>
|
||||||
|
if (context.settings.basicBehavior.allowResetPassword) {
|
||||||
|
decodeResetPasswordToken(form.token)
|
||||||
|
.flatMap { mailAddress =>
|
||||||
|
getAccountByMailAddress(mailAddress).map { account =>
|
||||||
|
updateAccount(account.copy(password = pbkdf2_sha256(form.password)))
|
||||||
|
html.resetcomplete()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.getOrElse(NotFound())
|
||||||
|
} else NotFound()
|
||||||
|
}
|
||||||
|
|
||||||
get("/groups/new")(usersOnly {
|
get("/groups/new")(usersOnly {
|
||||||
html.creategroup(List(GroupMember("", context.loginAccount.get.userName, true)))
|
context.withLoginAccount { loginAccount =>
|
||||||
|
html.creategroup(List(GroupMember("", loginAccount.userName, true)))
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/groups/new", newGroupForm)(usersOnly { form =>
|
post("/groups/new", newGroupForm)(usersOnly { form =>
|
||||||
@@ -650,16 +725,14 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:groupName/_editgroup")(managersOnly {
|
get("/:groupName/_editgroup")(managersOnly {
|
||||||
defining(params("groupName")) { groupName =>
|
val groupName = params("groupName")
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, true).map { account =>
|
||||||
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
html.editgroup(account, getGroupMembers(groupName), flash.get("info"))
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:groupName/_deletegroup")(managersOnly {
|
get("/:groupName/_deletegroup")(managersOnly {
|
||||||
defining(params("groupName")) {
|
val groupName = params("groupName")
|
||||||
groupName =>
|
|
||||||
// Remove from GROUP_MEMBER
|
// Remove from GROUP_MEMBER
|
||||||
updateGroupMembers(groupName, Nil)
|
updateGroupMembers(groupName, Nil)
|
||||||
// Disable group
|
// Disable group
|
||||||
@@ -673,14 +746,12 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getWikiRepositoryDir(groupName, repositoryName))
|
||||||
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
// FileUtils.deleteDirectory(getTemporaryDir(groupName, repositoryName))
|
||||||
// }
|
// }
|
||||||
}
|
|
||||||
redirect("/")
|
redirect("/")
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:groupName/_editgroup", editGroupForm)(managersOnly { form =>
|
post("/:groupName/_editgroup", editGroupForm)(managersOnly { form =>
|
||||||
defining(
|
val groupName = params("groupName")
|
||||||
params("groupName"),
|
val members = form.members
|
||||||
form.members
|
|
||||||
.split(",")
|
.split(",")
|
||||||
.map {
|
.map {
|
||||||
_.split(":") match {
|
_.split(":") match {
|
||||||
@@ -688,8 +759,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
) {
|
|
||||||
case (groupName, members) =>
|
|
||||||
getAccountByUserName(groupName, true).map { account =>
|
getAccountByUserName(groupName, true).map { account =>
|
||||||
updateGroup(groupName, form.description, form.url, false)
|
updateGroup(groupName, form.description, form.url, false)
|
||||||
|
|
||||||
@@ -709,25 +779,35 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect(s"/${groupName}/_editgroup")
|
redirect(s"/${groupName}/_editgroup")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the new repository form.
|
* Show the new repository form.
|
||||||
*/
|
*/
|
||||||
get("/new")(usersOnly {
|
get("/new")(usersOnly {
|
||||||
html.newrepo(getGroupsByUserName(context.loginAccount.get.userName), context.settings.isCreateRepoOptionPublic)
|
context.withLoginAccount { loginAccount =>
|
||||||
|
html.newrepo(getGroupsByUserName(loginAccount.userName), context.settings.basicBehavior.isCreateRepoOptionPublic)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create new repository.
|
* Create new repository.
|
||||||
*/
|
*/
|
||||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||||
if (context.settings.repositoryOperation.create || context.loginAccount.get.isAdmin) {
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (context.settings.basicBehavior.repositoryOperation.create || loginAccount.isAdmin) {
|
||||||
LockUtil.lock(s"${form.owner}/${form.name}") {
|
LockUtil.lock(s"${form.owner}/${form.name}") {
|
||||||
if (getRepository(form.owner, form.name).isEmpty) {
|
if (getRepository(form.owner, form.name).isDefined) {
|
||||||
|
// redirect to the repository if repository already exists
|
||||||
|
redirect(s"/${form.owner}/${form.name}")
|
||||||
|
} else if (!canCreateRepository(form.owner, loginAccount)) {
|
||||||
|
// Permission error
|
||||||
|
Forbidden()
|
||||||
|
} else {
|
||||||
|
// create repository asynchronously
|
||||||
createRepository(
|
createRepository(
|
||||||
context.loginAccount.get,
|
loginAccount,
|
||||||
form.owner,
|
form.owner,
|
||||||
form.name,
|
form.name,
|
||||||
form.description,
|
form.description,
|
||||||
@@ -735,16 +815,18 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
form.initOption,
|
form.initOption,
|
||||||
form.sourceUrl
|
form.sourceUrl
|
||||||
)
|
)
|
||||||
}
|
|
||||||
}
|
|
||||||
// redirect to the repository
|
// redirect to the repository
|
||||||
redirect(s"/${form.owner}/${form.name}")
|
redirect(s"/${form.owner}/${form.name}")
|
||||||
|
}
|
||||||
|
}
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||||
val loginAccount = context.loginAccount.get
|
context.withLoginAccount {
|
||||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
loginAccount =>
|
||||||
|
if (repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val groups = getGroupsByUserName(loginUserName)
|
val groups = getGroupsByUserName(loginUserName)
|
||||||
groups match {
|
groups match {
|
||||||
@@ -765,18 +847,22 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
case _ => redirect(s"/${loginUserName}")
|
case _ => redirect(s"/${loginUserName}")
|
||||||
}
|
}
|
||||||
} else BadRequest()
|
} else BadRequest()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/fork", accountForm)(readableUsersOnly { (form, repository) =>
|
||||||
val loginAccount = context.loginAccount.get
|
context.withLoginAccount {
|
||||||
if (repository.repository.options.allowFork && (context.settings.repositoryOperation.fork || loginAccount.isAdmin)) {
|
loginAccount =>
|
||||||
|
if (repository.repository.options.allowFork && (context.settings.basicBehavior.repositoryOperation.fork || loginAccount.isAdmin)) {
|
||||||
val loginUserName = loginAccount.userName
|
val loginUserName = loginAccount.userName
|
||||||
val accountName = form.accountName
|
val accountName = form.accountName
|
||||||
|
|
||||||
if (getRepository(accountName, repository.name).isDefined ||
|
if (getRepository(accountName, repository.name).isDefined) {
|
||||||
(accountName != loginUserName && !getGroupsByUserName(loginUserName).contains(accountName))) {
|
|
||||||
// redirect to the repository if repository already exists
|
// redirect to the repository if repository already exists
|
||||||
redirect(s"/${accountName}/${repository.name}")
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
|
} else if (!canCreateRepository(accountName, loginAccount)) {
|
||||||
|
// Permission error
|
||||||
|
Forbidden()
|
||||||
} else {
|
} else {
|
||||||
// fork repository asynchronously
|
// fork repository asynchronously
|
||||||
forkRepository(accountName, repository, loginUserName)
|
forkRepository(accountName, repository, loginUserName)
|
||||||
@@ -784,6 +870,7 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect(s"/${accountName}/${repository.name}")
|
redirect(s"/${accountName}/${repository.name}")
|
||||||
}
|
}
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
private def existsAccount: Constraint = new Constraint() {
|
private def existsAccount: Constraint = new Constraint() {
|
||||||
|
|||||||
@@ -100,4 +100,16 @@ trait ApiControllerBase extends ControllerBase {
|
|||||||
get("/api/v3/gitbucket/plugins") {
|
get("/api/v3/gitbucket/plugins") {
|
||||||
PluginRegistry().getPlugins().map { ApiPlugin(_) }
|
PluginRegistry().getPlugins().map { ApiPlugin(_) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* https://docs.github.com/en/enterprise-server@2.21/rest/reference/meta#get-github-enterprise-server-meta-information
|
||||||
|
*/
|
||||||
|
get("/api/v3/meta") {
|
||||||
|
JsonFormat(
|
||||||
|
Map(
|
||||||
|
"https://api.github.com/meta" -> context.loginAccount.isDefined,
|
||||||
|
"installed_version" -> "2.21.0"
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ import org.eclipse.jgit.revwalk.RevCommit
|
|||||||
import org.eclipse.jgit.treewalk._
|
import org.eclipse.jgit.treewalk._
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
import org.json4s.Formats
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides generic features for controller implementations.
|
* Provides generic features for controller implementations.
|
||||||
@@ -43,7 +44,7 @@ abstract class ControllerBase
|
|||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(getClass)
|
private val logger = LoggerFactory.getLogger(getClass)
|
||||||
|
|
||||||
implicit val jsonFormats = gitbucket.core.api.JsonFormat.jsonFormats
|
implicit val jsonFormats: Formats = gitbucket.core.api.JsonFormat.jsonFormats
|
||||||
|
|
||||||
before("/api/v3/*") {
|
before("/api/v3/*") {
|
||||||
contentType = formats("json")
|
contentType = formats("json")
|
||||||
@@ -157,11 +158,8 @@ abstract class ControllerBase
|
|||||||
org.scalatra.Unauthorized(
|
org.scalatra.Unauthorized(
|
||||||
redirect(
|
redirect(
|
||||||
"/signin?redirect=" + StringUtil.urlEncode(
|
"/signin?redirect=" + StringUtil.urlEncode(
|
||||||
defining(request.getQueryString) { queryString =>
|
request.getRequestURI
|
||||||
request.getRequestURI.substring(request.getContextPath.length) + (if (queryString != null)
|
.substring(request.getContextPath.length) + Option(request.getQueryString).map("?" + _).getOrElse("")
|
||||||
"?" + queryString
|
|
||||||
else "")
|
|
||||||
}
|
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
@@ -255,7 +253,7 @@ abstract class ControllerBase
|
|||||||
repository: RepositoryService.RepositoryInfo
|
repository: RepositoryService.RepositoryInfo
|
||||||
): Unit = {
|
): Unit = {
|
||||||
JGitUtil.getObjectLoaderFromId(git, objectId) { loader =>
|
JGitUtil.getObjectLoaderFromId(git, objectId) { loader =>
|
||||||
contentType = FileUtil.getSafeMimeType(path)
|
contentType = FileUtil.getSafeMimeType(path, repository.repository.options.safeMode)
|
||||||
|
|
||||||
if (loader.isLarge) {
|
if (loader.isLarge) {
|
||||||
response.setContentLength(loader.getSize.toInt)
|
response.setContentLength(loader.getSize.toInt)
|
||||||
@@ -302,14 +300,21 @@ case class Context(
|
|||||||
}
|
}
|
||||||
val sidebarCollapse = request.getSession.getAttribute("sidebar-collapse") != null
|
val sidebarCollapse = request.getSession.getAttribute("sidebar-collapse") != null
|
||||||
|
|
||||||
|
def withLoginAccount(f: Account => Any): Any = {
|
||||||
|
loginAccount match {
|
||||||
|
case Some(loginAccount) => f(loginAccount)
|
||||||
|
case None => Unauthorized()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get object from cache.
|
* Get object from cache.
|
||||||
*
|
*
|
||||||
* If object has not been cached with the specified key then retrieves by given action.
|
* If object has not been cached with the specified key then retrieves by given action.
|
||||||
* Cached object are available during a request.
|
* Cached object are available during a request.
|
||||||
*/
|
*/
|
||||||
def cache[A](key: String)(action: => A): A =
|
def cache[A](key: String)(action: => A): A = {
|
||||||
defining(Keys.Request.Cache(key)) { cacheKey =>
|
val cacheKey = Keys.Request.Cache(key)
|
||||||
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
Option(request.getAttribute(cacheKey).asInstanceOf[A]).getOrElse {
|
||||||
val newObject = action
|
val newObject = action
|
||||||
request.setAttribute(cacheKey, newObject)
|
request.setAttribute(cacheKey, newObject)
|
||||||
@@ -421,7 +426,7 @@ trait AccountManagementControllerBase extends ControllerBase {
|
|||||||
"new"
|
"new"
|
||||||
)
|
)
|
||||||
|
|
||||||
protected def reservedNames(): Constraint = new Constraint() {
|
protected def reservedNames: Constraint = new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
override def validate(name: String, value: String, messages: Messages): Option[String] =
|
||||||
if (allReservedNames.contains(value.toLowerCase)) {
|
if (allReservedNames.contains(value.toLowerCase)) {
|
||||||
Some(s"${value} is reserved")
|
Some(s"${value} is reserved")
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.dashboard.html
|
import gitbucket.core.dashboard.html
|
||||||
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
import gitbucket.core.util.{Keys, UsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -34,45 +35,63 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
with UsersAuthenticator =>
|
with UsersAuthenticator =>
|
||||||
|
|
||||||
get("/dashboard/repos")(usersOnly {
|
get("/dashboard/repos")(usersOnly {
|
||||||
|
context.withLoginAccount { loginAccount =>
|
||||||
val repos = getVisibleRepositories(
|
val repos = getVisibleRepositories(
|
||||||
context.loginAccount,
|
context.loginAccount,
|
||||||
None,
|
None,
|
||||||
withoutPhysicalInfo = true,
|
withoutPhysicalInfo = true,
|
||||||
limit = context.settings.limitVisibleRepositories
|
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||||
)
|
)
|
||||||
html.repos(getGroupNames(context.loginAccount.get.userName), repos, repos)
|
html.repos(getGroupNames(loginAccount.userName), repos, repos)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues")(usersOnly {
|
get("/dashboard/issues")(usersOnly {
|
||||||
searchIssues("created_by")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchIssues(loginAccount, "created_by")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/assigned")(usersOnly {
|
get("/dashboard/issues/assigned")(usersOnly {
|
||||||
searchIssues("assigned")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchIssues(loginAccount, "assigned")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/created_by")(usersOnly {
|
get("/dashboard/issues/created_by")(usersOnly {
|
||||||
searchIssues("created_by")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchIssues(loginAccount, "created_by")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/issues/mentioned")(usersOnly {
|
get("/dashboard/issues/mentioned")(usersOnly {
|
||||||
searchIssues("mentioned")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchIssues(loginAccount, "mentioned")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls")(usersOnly {
|
get("/dashboard/pulls")(usersOnly {
|
||||||
searchPullRequests("created_by")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchPullRequests(loginAccount, "created_by")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/created_by")(usersOnly {
|
get("/dashboard/pulls/created_by")(usersOnly {
|
||||||
searchPullRequests("created_by")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchPullRequests(loginAccount, "created_by")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/assigned")(usersOnly {
|
get("/dashboard/pulls/assigned")(usersOnly {
|
||||||
searchPullRequests("assigned")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchPullRequests(loginAccount, "assigned")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/dashboard/pulls/mentioned")(usersOnly {
|
get("/dashboard/pulls/mentioned")(usersOnly {
|
||||||
searchPullRequests("mentioned")
|
context.withLoginAccount { loginAccount =>
|
||||||
|
searchPullRequests(loginAccount, "mentioned")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
private def getOrCreateCondition(key: String, filter: String, userName: String) = {
|
||||||
@@ -85,10 +104,10 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(filter: String) = {
|
private def searchIssues(loginAccount: Account, filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
|
|
||||||
val userName = context.loginAccount.get.userName
|
val userName = loginAccount.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardIssues, filter, userName)
|
||||||
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
val userRepos = getUserRepositories(userName, true).map(repo => repo.owner -> repo.name)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
@@ -110,16 +129,16 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
context.loginAccount,
|
context.loginAccount,
|
||||||
None,
|
None,
|
||||||
withoutPhysicalInfo = true,
|
withoutPhysicalInfo = true,
|
||||||
limit = context.settings.limitVisibleRepositories
|
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private def searchPullRequests(filter: String) = {
|
private def searchPullRequests(loginAccount: Account, filter: String) = {
|
||||||
import IssuesService._
|
import IssuesService._
|
||||||
import PullRequestService._
|
import PullRequestService._
|
||||||
|
|
||||||
val userName = context.loginAccount.get.userName
|
val userName = loginAccount.userName
|
||||||
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
val condition = getOrCreateCondition(Keys.Session.DashboardPulls, filter, userName)
|
||||||
val allRepos = getAllRepositories(userName)
|
val allRepos = getAllRepositories(userName)
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
@@ -152,7 +171,7 @@ trait DashboardControllerBase extends ControllerBase {
|
|||||||
context.loginAccount,
|
context.loginAccount,
|
||||||
None,
|
None,
|
||||||
withoutPhysicalInfo = true,
|
withoutPhysicalInfo = true,
|
||||||
limit = context.settings.limitVisibleRepositories
|
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import gitbucket.core.model.Account
|
|||||||
import gitbucket.core.service.{AccountService, ReleaseService, RepositoryService}
|
import gitbucket.core.service.{AccountService, ReleaseService, RepositoryService}
|
||||||
import gitbucket.core.servlet.Database
|
import gitbucket.core.servlet.Database
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
@@ -18,6 +17,7 @@ import org.apache.commons.io.{FileUtils, IOUtils}
|
|||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
import gitbucket.core.service.SystemSettingsService
|
import gitbucket.core.service.SystemSettingsService
|
||||||
|
import slick.jdbc.JdbcBackend.Session
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides Ajax based file upload functionality.
|
* Provides Ajax based file upload functionality.
|
||||||
@@ -37,10 +37,10 @@ class FileUploadController
|
|||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
FileUtil.isImage
|
FileUtil.isImage(_)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,7 +49,7 @@ class FileUploadController
|
|||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils
|
FileUtils
|
||||||
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get)
|
.writeByteArrayToFile(new File(getTemporaryDir(session.getId), FileUtil.checkFilename(fileId)), file.get())
|
||||||
session += Keys.Session.Upload(fileId) -> file.name
|
session += Keys.Session.Upload(fileId) -> file.name
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -65,7 +65,7 @@ class FileUploadController
|
|||||||
getAttachedDir(params("owner"), params("repository")),
|
getAttachedDir(params("owner"), params("repository")),
|
||||||
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
FileUtil.checkFilename(fileId + "." + FileUtil.getExtension(file.getName))
|
||||||
),
|
),
|
||||||
file.get
|
file.get()
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -131,7 +131,7 @@ class FileUploadController
|
|||||||
} getOrElse BadRequest()
|
} getOrElse BadRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
post("/release/:owner/:repository/:tag") {
|
post("/release/:owner/:repository/*") {
|
||||||
setMultipartConfigForLargeFile()
|
setMultipartConfigForLargeFile()
|
||||||
session
|
session
|
||||||
.get(Keys.Session.LoginAccount)
|
.get(Keys.Session.LoginAccount)
|
||||||
@@ -139,12 +139,12 @@ class FileUploadController
|
|||||||
case _: Account =>
|
case _: Account =>
|
||||||
val owner = params("owner")
|
val owner = params("owner")
|
||||||
val repository = params("repository")
|
val repository = params("repository")
|
||||||
val tag = params("tag")
|
val tag = multiParams("splat").head
|
||||||
execute(
|
execute(
|
||||||
{ (file, fileId) =>
|
{ (file, fileId) =>
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
new File(getReleaseFilesDir(owner, repository), FileUtil.checkFilename(tag + "/" + fileId)),
|
||||||
file.get
|
file.get()
|
||||||
)
|
)
|
||||||
},
|
},
|
||||||
_ => true
|
_ => true
|
||||||
@@ -178,7 +178,7 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
private def onlyWikiEditable(owner: String, repository: String, loginAccount: Account)(action: => Any): Any = {
|
||||||
implicit val session = Database.getSession(request)
|
implicit val session: Session = Database.getSession(request)
|
||||||
getRepository(owner, repository) match {
|
getRepository(owner, repository) match {
|
||||||
case Some(x) =>
|
case Some(x) =>
|
||||||
x.repository.options.wikiOption match {
|
x.repository.options.wikiOption match {
|
||||||
@@ -191,14 +191,13 @@ class FileUploadController
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def execute(f: (FileItem, String) => Unit, mimeTypeChcker: (String) => Boolean) =
|
private def execute(f: (FileItem, String) => Unit, mimeTypeChecker: (String) => Boolean) =
|
||||||
fileParams.get("file") match {
|
fileParams.get("file") match {
|
||||||
case Some(file) if (mimeTypeChcker(file.name)) =>
|
case Some(file) if mimeTypeChecker(file.name) =>
|
||||||
defining(FileUtil.generateFileId) { fileId =>
|
val fileId = FileUtil.generateFileId
|
||||||
f(file, fileId)
|
f(file, fileId)
|
||||||
contentType = "text/plain"
|
contentType = "text/plain"
|
||||||
Ok(fileId)
|
Ok(fileId)
|
||||||
}
|
|
||||||
case _ => BadRequest()
|
case _ => BadRequest()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import gitbucket.core.helper.xml
|
|||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.Account
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view.helpers._
|
import gitbucket.core.view.helpers._
|
||||||
import org.scalatra.Ok
|
import org.scalatra.Ok
|
||||||
@@ -70,7 +69,7 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
Some(account),
|
Some(account),
|
||||||
None,
|
None,
|
||||||
withoutPhysicalInfo = true,
|
withoutPhysicalInfo = true,
|
||||||
limit = context.settings.limitVisibleRepositories
|
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||||
),
|
),
|
||||||
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
showBannerToCreatePersonalAccessToken = hasAccountFederation(account.userName) && !hasAccessToken(
|
||||||
account.userName
|
account.userName
|
||||||
@@ -237,13 +236,13 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
// TODO Move to RepositoryViewrController?
|
// TODO Move to RepositoryViewrController?
|
||||||
get("/:owner/:repository/search")(referrersOnly { repository =>
|
get("/:owner/:repository/search")(referrersOnly { repository =>
|
||||||
defining(params.getOrElse("q", "").trim, params.getOrElse("type", "code")) {
|
val query = params.getOrElse("q", "").trim
|
||||||
case (query, target) =>
|
val target = params.getOrElse("type", "code")
|
||||||
val page = try {
|
val page = try {
|
||||||
val i = params.getOrElse("page", "1").toInt
|
val i = params.getOrElse("page", "1").toInt
|
||||||
if (i <= 0) 1 else i
|
if (i <= 0) 1 else i
|
||||||
} catch {
|
} catch {
|
||||||
case e: NumberFormatException => 1
|
case _: NumberFormatException => 1
|
||||||
}
|
}
|
||||||
|
|
||||||
target.toLowerCase match {
|
target.toLowerCase match {
|
||||||
@@ -281,7 +280,6 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/search") {
|
get("/search") {
|
||||||
@@ -291,11 +289,11 @@ trait IndexControllerBase extends ControllerBase {
|
|||||||
context.loginAccount,
|
context.loginAccount,
|
||||||
None,
|
None,
|
||||||
withoutPhysicalInfo = true,
|
withoutPhysicalInfo = true,
|
||||||
limit = context.settings.limitVisibleRepositories
|
limit = context.settings.basicBehavior.limitVisibleRepositories
|
||||||
)
|
)
|
||||||
|
|
||||||
val repositories = {
|
val repositories = {
|
||||||
context.settings.limitVisibleRepositories match {
|
context.settings.basicBehavior.limitVisibleRepositories match {
|
||||||
case true =>
|
case true =>
|
||||||
getVisibleRepositories(
|
getVisibleRepositories(
|
||||||
context.loginAccount,
|
context.loginAccount,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import gitbucket.core.issues.html
|
import gitbucket.core.issues.html
|
||||||
|
import gitbucket.core.model.{Account, CustomFieldBehavior}
|
||||||
import gitbucket.core.service.IssuesService._
|
import gitbucket.core.service.IssuesService._
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
@@ -21,6 +21,7 @@ class IssuesController
|
|||||||
with ActivityService
|
with ActivityService
|
||||||
with HandleCommentService
|
with HandleCommentService
|
||||||
with IssueCreationService
|
with IssueCreationService
|
||||||
|
with CustomFieldsService
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
@@ -41,6 +42,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
with ActivityService
|
with ActivityService
|
||||||
with HandleCommentService
|
with HandleCommentService
|
||||||
with IssueCreationService
|
with IssueCreationService
|
||||||
|
with CustomFieldsService
|
||||||
with ReadableUsersAuthenticator
|
with ReadableUsersAuthenticator
|
||||||
with ReferrerAuthenticator
|
with ReferrerAuthenticator
|
||||||
with WritableUsersAuthenticator
|
with WritableUsersAuthenticator
|
||||||
@@ -51,7 +53,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
case class IssueCreateForm(
|
case class IssueCreateForm(
|
||||||
title: String,
|
title: String,
|
||||||
content: Option[String],
|
content: Option[String],
|
||||||
assignedUserName: Option[String],
|
assigneeUserNames: Option[String],
|
||||||
milestoneId: Option[Int],
|
milestoneId: Option[Int],
|
||||||
priorityId: Option[Int],
|
priorityId: Option[Int],
|
||||||
labelNames: Option[String]
|
labelNames: Option[String]
|
||||||
@@ -62,7 +64,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
val issueCreateForm = mapping(
|
val issueCreateForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required))),
|
"title" -> trim(label("Title", text(required))),
|
||||||
"content" -> trim(optional(text())),
|
"content" -> trim(optional(text())),
|
||||||
"assignedUserName" -> trim(optional(text())),
|
"assigneeUserNames" -> trim(optional(text())),
|
||||||
"milestoneId" -> trim(optional(number())),
|
"milestoneId" -> trim(optional(number())),
|
||||||
"priorityId" -> trim(optional(number())),
|
"priorityId" -> trim(optional(number())),
|
||||||
"labelNames" -> trim(optional(text()))
|
"labelNames" -> trim(optional(text()))
|
||||||
@@ -95,21 +97,22 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/:id")(referrersOnly { repository =>
|
||||||
defining(repository.owner, repository.name, params("id")) {
|
val issueId = params("id")
|
||||||
case (owner, name, issueId) =>
|
getIssue(repository.owner, repository.name, issueId) map {
|
||||||
getIssue(owner, name, issueId) map {
|
|
||||||
issue =>
|
issue =>
|
||||||
if (issue.isPullRequest) {
|
if (issue.isPullRequest) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
} else {
|
} else {
|
||||||
html.issue(
|
html.issue(
|
||||||
issue,
|
issue,
|
||||||
getComments(owner, name, issueId.toInt),
|
getComments(repository.owner, repository.name, issueId.toInt),
|
||||||
getIssueLabels(owner, name, issueId.toInt),
|
getIssueLabels(repository.owner, repository.name, issueId.toInt),
|
||||||
getAssignableUserNames(owner, name),
|
getIssueAssignees(repository.owner, repository.name, issueId.toInt),
|
||||||
getMilestonesWithIssueCount(owner, name),
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
getPriorities(owner, name),
|
getMilestonesWithIssueCount(repository.owner, repository.name),
|
||||||
getLabels(owner, name),
|
getPriorities(repository.owner, repository.name),
|
||||||
|
getLabels(repository.owner, repository.name),
|
||||||
|
getCustomFieldsWithValue(repository.owner, repository.name, issueId.toInt).filter(_._1.enableForIssues),
|
||||||
isIssueEditable(repository),
|
isIssueEditable(repository),
|
||||||
isIssueManageable(repository),
|
isIssueManageable(repository),
|
||||||
isIssueCommentManageable(repository),
|
isIssueCommentManageable(repository),
|
||||||
@@ -117,90 +120,112 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
get("/:owner/:repository/issues/new")(readableUsersOnly { repository =>
|
||||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||||
defining(repository.owner, repository.name) {
|
|
||||||
case (owner, name) =>
|
|
||||||
html.create(
|
html.create(
|
||||||
getAssignableUserNames(owner, name),
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
getMilestones(owner, name),
|
getMilestones(repository.owner, repository.name),
|
||||||
getPriorities(owner, name),
|
getPriorities(repository.owner, repository.name),
|
||||||
getDefaultPriority(owner, name),
|
getDefaultPriority(repository.owner, repository.name),
|
||||||
getLabels(owner, name),
|
getLabels(repository.owner, repository.name),
|
||||||
|
getCustomFields(repository.owner, repository.name).filter(_.enableForIssues),
|
||||||
isIssueManageable(repository),
|
isIssueManageable(repository),
|
||||||
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
getContentTemplate(repository, "ISSUE_TEMPLATE"),
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issues/new", issueCreateForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
if (isIssueEditable(repository)) { // TODO Should this check is provided by authenticator?
|
||||||
val issue = createIssue(
|
val issue = createIssue(
|
||||||
repository,
|
repository,
|
||||||
form.title,
|
form.title,
|
||||||
form.content,
|
form.content,
|
||||||
form.assignedUserName,
|
form.assigneeUserNames.toSeq.flatMap(_.split(",")),
|
||||||
form.milestoneId,
|
form.milestoneId,
|
||||||
form.priorityId,
|
form.priorityId,
|
||||||
form.labelNames.toSeq.flatMap(_.split(",")),
|
form.labelNames.toSeq.flatMap(_.split(",")),
|
||||||
context.loginAccount.get
|
loginAccount
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// Insert custom field values
|
||||||
|
params.toMap.foreach {
|
||||||
|
case (key, value) =>
|
||||||
|
if (key.startsWith("custom-field-")) {
|
||||||
|
getCustomField(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
key.replaceFirst("^custom-field-", "").toInt
|
||||||
|
).foreach { field =>
|
||||||
|
CustomFieldBehavior.validate(field, value, messages) match {
|
||||||
|
case None =>
|
||||||
|
insertOrUpdateCustomFieldValue(field, repository.owner, repository.name, issue.issueId, value)
|
||||||
|
case Some(_) => halt(400)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
redirect(s"/${issue.userName}/${issue.repositoryName}/issues/${issue.issueId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit_title/:id", issueTitleEditForm)(readableUsersOnly { (title, repository) =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount {
|
||||||
case (owner, name) =>
|
loginAccount =>
|
||||||
getIssue(owner, name, params("id")).map {
|
getIssue(repository.owner, repository.name, params("id")).map {
|
||||||
issue =>
|
issue =>
|
||||||
if (isEditableContent(owner, name, issue.openedUserName)) {
|
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||||
if (issue.title != title) {
|
if (issue.title != title) {
|
||||||
// update issue
|
// update issue
|
||||||
updateIssue(owner, name, issue.issueId, title, issue.content)
|
updateIssue(repository.owner, repository.name, issue.issueId, title, issue.content)
|
||||||
// extract references and create refer comment
|
// extract references and create refer comment
|
||||||
createReferComment(owner, name, issue.copy(title = title), title, context.loginAccount.get)
|
createReferComment(repository.owner, repository.name, issue.copy(title = title), title, loginAccount)
|
||||||
createComment(
|
createComment(
|
||||||
owner,
|
repository.owner,
|
||||||
name,
|
repository.name,
|
||||||
context.loginAccount.get.userName,
|
loginAccount.userName,
|
||||||
issue.issueId,
|
issue.issueId,
|
||||||
issue.title + "\r\n" + title,
|
issue.title + "\r\n" + title,
|
||||||
"change_title"
|
"change_title"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
ajaxPost("/:owner/:repository/issues/edit/:id", issueEditForm)(readableUsersOnly { (content, repository) =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount {
|
||||||
case (owner, name) =>
|
loginAccount =>
|
||||||
getIssue(owner, name, params("id")).map { issue =>
|
getIssue(repository.owner, repository.name, params("id")).map { issue =>
|
||||||
if (isEditableContent(owner, name, issue.openedUserName)) {
|
if (isEditableContent(repository.owner, repository.name, issue.openedUserName, loginAccount)) {
|
||||||
// update issue
|
// update issue
|
||||||
updateIssue(owner, name, issue.issueId, issue.title, content)
|
updateIssue(repository.owner, repository.name, issue.issueId, issue.title, content)
|
||||||
// extract references and create refer comment
|
// extract references and create refer comment
|
||||||
createReferComment(owner, name, issue, content.getOrElse(""), context.loginAccount.get)
|
createReferComment(repository.owner, repository.name, issue, content.getOrElse(""), loginAccount)
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/issues/_data/${issue.issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/issues/_data/${issue.issueId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
val actionOpt =
|
val actionOpt =
|
||||||
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
params
|
||||||
|
.get("action")
|
||||||
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
handleComment(issue, Some(form.content), repository, actionOpt) map {
|
||||||
case (issue, id) =>
|
case (issue, id) =>
|
||||||
redirect(
|
redirect(
|
||||||
@@ -208,12 +233,17 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/issue_comments/state", issueStateForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
getIssue(repository.owner, repository.name, form.issueId.toString).flatMap { issue =>
|
||||||
val actionOpt =
|
val actionOpt =
|
||||||
params.get("action").filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName))
|
params
|
||||||
|
.get("action")
|
||||||
|
.filter(_ => isEditableContent(issue.userName, issue.repositoryName, issue.openedUserName, loginAccount))
|
||||||
handleComment(issue, form.content, repository, actionOpt) map {
|
handleComment(issue, form.content, repository, actionOpt) map {
|
||||||
case (issue, id) =>
|
case (issue, id) =>
|
||||||
redirect(
|
redirect(
|
||||||
@@ -221,25 +251,25 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/issue_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount {
|
||||||
case (owner, name) =>
|
loginAccount =>
|
||||||
getComment(owner, name, params("id")).map { comment =>
|
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
if (isEditableContent(owner, name, comment.commentedUserName)) {
|
if (isEditableContent(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
updateComment(comment.issueId, comment.commentId, form.content)
|
updateComment(repository.owner, repository.name, comment.issueId, comment.commentId, form.content)
|
||||||
redirect(s"/${owner}/${name}/issue_comments/_data/${comment.commentId}")
|
redirect(s"/${repository.owner}/${repository.name}/issue_comments/_data/${comment.commentId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issue_comments/delete/:id")(readableUsersOnly { repository =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount { loginAccount =>
|
||||||
case (owner, name) =>
|
getComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
getComment(owner, name, params("id")).map { comment =>
|
if (isDeletableComment(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
if (isDeletableComment(owner, name, comment.commentedUserName)) {
|
|
||||||
Ok(deleteComment(repository.owner, repository.name, comment.issueId, comment.commentId))
|
Ok(deleteComment(repository.owner, repository.name, comment.issueId, comment.commentId))
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -247,9 +277,11 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issues/_data/:id")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
getIssue(repository.owner, repository.name, params("id")) map {
|
getIssue(repository.owner, repository.name, params("id")) map {
|
||||||
x =>
|
x =>
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName)) {
|
if (isEditableContent(x.userName, x.repositoryName, x.openedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
case t if t == "html" => html.editissue(x.content, x.issueId, repository)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
@@ -273,12 +305,15 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/issue_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
getComment(repository.owner, repository.name, params("id")) map {
|
getComment(repository.owner, repository.name, params("id")) map {
|
||||||
x =>
|
x =>
|
||||||
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName)) {
|
if (isEditableContent(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
@@ -301,6 +336,7 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/new/label")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/new/label")(writableUsersOnly { repository =>
|
||||||
@@ -310,28 +346,27 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/new")(writableUsersOnly { repository =>
|
||||||
defining(params("id").toInt) { issueId =>
|
val issueId = params("id").toInt
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
registerIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/label/delete")(writableUsersOnly { repository =>
|
||||||
defining(params("id").toInt) { issueId =>
|
val issueId = params("id").toInt
|
||||||
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
deleteIssueLabel(repository.owner, repository.name, issueId, params("labelId").toInt, true)
|
||||||
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
html.labellist(getIssueLabels(repository.owner, repository.name, issueId))
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/assign")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/assignee/new")(writableUsersOnly { repository =>
|
||||||
updateAssignedUserName(
|
val issueId = params("id").toInt
|
||||||
repository.owner,
|
registerIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), true)
|
||||||
repository.name,
|
Ok()
|
||||||
params("id").toInt,
|
})
|
||||||
assignedUserName("assignedUserName"),
|
|
||||||
true
|
ajaxPost("/:owner/:repository/issues/:id/assignee/delete")(writableUsersOnly { repository =>
|
||||||
)
|
val issueId = params("id").toInt
|
||||||
Ok("updated")
|
deleteIssueAssignee(repository.owner, repository.name, issueId, params("assigneeUserName"), true)
|
||||||
|
Ok()
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/issues/:id/milestone")(writableUsersOnly { repository =>
|
||||||
@@ -352,9 +387,37 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
Ok("updated")
|
Ok("updated")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/customfield_validation/:fieldId")(writableUsersOnly { repository =>
|
||||||
|
val fieldId = params("fieldId").toInt
|
||||||
|
val value = params("value")
|
||||||
|
getCustomField(repository.owner, repository.name, fieldId)
|
||||||
|
.flatMap { field =>
|
||||||
|
CustomFieldBehavior.validate(field, value, messages).map { error =>
|
||||||
|
Ok(error)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.getOrElse(Ok())
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxPost("/:owner/:repository/issues/:id/customfield/:fieldId")(writableUsersOnly { repository =>
|
||||||
|
val issueId = params("id").toInt
|
||||||
|
val fieldId = params("fieldId").toInt
|
||||||
|
val value = params("value")
|
||||||
|
|
||||||
|
for {
|
||||||
|
_ <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||||
|
field <- getCustomField(repository.owner, repository.name, fieldId)
|
||||||
|
} {
|
||||||
|
CustomFieldBehavior.validate(field, value, messages) match {
|
||||||
|
case None => insertOrUpdateCustomFieldValue(field, repository.owner, repository.name, issueId, value)
|
||||||
|
case Some(_) => halt(400)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Ok(value)
|
||||||
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/state")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/state")(writableUsersOnly { repository =>
|
||||||
defining(params.get("value")) {
|
val action = params.get("value")
|
||||||
action =>
|
|
||||||
action match {
|
action match {
|
||||||
case Some("open") =>
|
case Some("open") =>
|
||||||
executeBatch(repository) { issueId =>
|
executeBatch(repository) { issueId =>
|
||||||
@@ -362,17 +425,19 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
handleComment(issue, None, repository, Some("reopen"))
|
handleComment(issue, None, repository, Some("reopen"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (params("uri").nonEmpty) {
|
||||||
|
redirect(params("uri"))
|
||||||
|
}
|
||||||
case Some("close") =>
|
case Some("close") =>
|
||||||
executeBatch(repository) { issueId =>
|
executeBatch(repository) { issueId =>
|
||||||
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
getIssue(repository.owner, repository.name, issueId.toString).foreach { issue =>
|
||||||
handleComment(issue, None, repository, Some("close"))
|
handleComment(issue, None, repository, Some("close"))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case _ => BadRequest()
|
|
||||||
}
|
|
||||||
if (params("uri").nonEmpty) {
|
if (params("uri").nonEmpty) {
|
||||||
redirect(params("uri"))
|
redirect(params("uri"))
|
||||||
}
|
}
|
||||||
|
case _ => BadRequest()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -390,30 +455,33 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/assign")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/assign")(writableUsersOnly { repository =>
|
||||||
defining(assignedUserName("value")) { value =>
|
val value = assignedUserName("value")
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
//updateAssignedUserName(repository.owner, repository.name, _, value, true)
|
||||||
|
value match {
|
||||||
|
case Some(assignedUserName) =>
|
||||||
|
registerIssueAssignee(repository.owner, repository.name, _, assignedUserName, true)
|
||||||
|
case None =>
|
||||||
|
deleteAllIssueAssignees(repository.owner, repository.name, _, true)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (params("uri").nonEmpty) {
|
if (params("uri").nonEmpty) {
|
||||||
redirect(params("uri"))
|
redirect(params("uri"))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/milestone")(writableUsersOnly { repository =>
|
||||||
defining(milestoneId("value")) { value =>
|
val value = milestoneId("value")
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
updateMilestoneId(repository.owner, repository.name, _, value, true)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
post("/:owner/:repository/issues/batchedit/priority")(writableUsersOnly { repository =>
|
||||||
defining(priorityId("value")) { value =>
|
val value = priorityId("value")
|
||||||
executeBatch(repository) {
|
executeBatch(repository) {
|
||||||
updatePriorityId(repository.owner, repository.name, _, value, true)
|
updatePriorityId(repository.owner, repository.name, _, value, true)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/_attached/:file")(referrersOnly { repository =>
|
get("/:owner/:repository/_attached/:file")(referrersOnly { repository =>
|
||||||
@@ -464,48 +532,51 @@ trait IssuesControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
private def searchIssues(repository: RepositoryService.RepositoryInfo) = {
|
||||||
defining(repository.owner, repository.name) {
|
|
||||||
case (owner, repoName) =>
|
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
// retrieve search condition
|
// retrieve search condition
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
// search issues
|
// search issues
|
||||||
val issues =
|
val issues =
|
||||||
searchIssue(condition, IssueSearchOption.Issues, (page - 1) * IssueLimit, IssueLimit, owner -> repoName)
|
searchIssue(
|
||||||
|
condition,
|
||||||
|
IssueSearchOption.Issues,
|
||||||
|
(page - 1) * IssueLimit,
|
||||||
|
IssueLimit,
|
||||||
|
repository.owner -> repository.name
|
||||||
|
)
|
||||||
|
|
||||||
html.list(
|
html.list(
|
||||||
"issues",
|
"issues",
|
||||||
issues.map(issue => (issue, None)),
|
issues.map(issue => (issue, None)),
|
||||||
page,
|
page,
|
||||||
getAssignableUserNames(owner, repoName),
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
getMilestones(owner, repoName),
|
getMilestones(repository.owner, repository.name),
|
||||||
getPriorities(owner, repoName),
|
getPriorities(repository.owner, repository.name),
|
||||||
getLabels(owner, repoName),
|
getLabels(repository.owner, repository.name),
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, owner -> repoName),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, owner -> repoName),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.Issues, repository.owner -> repository.name),
|
||||||
condition,
|
condition,
|
||||||
repository,
|
repository,
|
||||||
isIssueEditable(repository),
|
isIssueEditable(repository),
|
||||||
isIssueManageable(repository)
|
isIssueManageable(repository)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether an issue or a comment is editable by a logged-in user.
|
* Tests whether an issue or a comment is editable by a logged-in user.
|
||||||
*/
|
*/
|
||||||
private def isEditableContent(owner: String, repository: String, author: String)(
|
private def isEditableContent(owner: String, repository: String, author: String, loginAccount: Account)(
|
||||||
implicit context: Context
|
implicit context: Context
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasDeveloperRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Tests whether an issue comment is deletable by a logged-in user.
|
* Tests whether an issue comment is deletable by a logged-in user.
|
||||||
*/
|
*/
|
||||||
private def isDeletableComment(owner: String, repository: String, author: String)(
|
private def isDeletableComment(owner: String, repository: String, author: String, loginAccount: Account)(
|
||||||
implicit context: Context
|
implicit context: Context
|
||||||
): Boolean = {
|
): Boolean = {
|
||||||
hasOwnerRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasOwnerRole(owner, repository, context.loginAccount) || author == loginAccount.userName
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/issues/labels")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/labels")(referrersOnly { repository =>
|
||||||
html.list(
|
html.list(
|
||||||
getLabels(repository.owner, repository.name),
|
getLabels(repository.owner, repository.name),
|
||||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
@@ -59,7 +59,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
html.label(
|
html.label(
|
||||||
getLabel(repository.owner, repository.name, labelId).get,
|
getLabel(repository.owner, repository.name, labelId).get,
|
||||||
// TODO futility
|
// TODO futility
|
||||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
@@ -76,7 +76,7 @@ trait LabelsControllerBase extends ControllerBase {
|
|||||||
html.label(
|
html.label(
|
||||||
getLabel(repository.owner, repository.name, params("labelId").toInt).get,
|
getLabel(repository.owner, repository.name, params("labelId").toInt).get,
|
||||||
// TODO futility
|
// TODO futility
|
||||||
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByLabels(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -29,9 +29,10 @@ trait PreProcessControllerBase extends ControllerBase {
|
|||||||
* If anonymous access is allowed, pass all requests.
|
* If anonymous access is allowed, pass all requests.
|
||||||
* But if it's not allowed, demands authentication except some paths.
|
* But if it's not allowed, demands authentication except some paths.
|
||||||
*/
|
*/
|
||||||
get(!context.settings.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
get(!context.settings.basicBehavior.allowAnonymousAccess, context.loginAccount.isEmpty) {
|
||||||
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
if (!context.currentPath.startsWith("/assets") && !context.currentPath.startsWith("/signin") &&
|
||||||
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
!context.currentPath.startsWith("/register") && !context.currentPath.endsWith("/info/refs") &&
|
||||||
|
!context.currentPath.startsWith("/plugin-assets") &&
|
||||||
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
!PluginRegistry().getAnonymousAccessiblePaths().exists { path =>
|
||||||
context.currentPath.startsWith(path)
|
context.currentPath.startsWith(path)
|
||||||
}) {
|
}) {
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/issues/priorities")(referrersOnly { repository =>
|
get("/:owner/:repository/issues/priorities")(referrersOnly { repository =>
|
||||||
html.list(
|
html.list(
|
||||||
getPriorities(repository.owner, repository.name),
|
getPriorities(repository.owner, repository.name),
|
||||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
@@ -60,7 +60,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
createPriority(repository.owner, repository.name, form.priorityName, form.description, form.color.substring(1))
|
createPriority(repository.owner, repository.name, form.priorityName, form.description, form.color.substring(1))
|
||||||
html.priority(
|
html.priority(
|
||||||
getPriority(repository.owner, repository.name, priorityId).get,
|
getPriority(repository.owner, repository.name, priorityId).get,
|
||||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
@@ -84,7 +84,7 @@ trait PrioritiesControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
html.priority(
|
html.priority(
|
||||||
getPriority(repository.owner, repository.name, params("priorityId").toInt).get,
|
getPriority(repository.owner, repository.name, params("priorityId").toInt).get,
|
||||||
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition(), Map.empty),
|
countIssueGroupByPriorities(repository.owner, repository.name, IssuesService.IssueSearchCondition()),
|
||||||
repository,
|
repository,
|
||||||
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import gitbucket.core.service.IssuesService._
|
|||||||
import gitbucket.core.service.PullRequestService._
|
import gitbucket.core.service.PullRequestService._
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
@@ -26,6 +25,7 @@ class PullRequestsController
|
|||||||
with PullRequestService
|
with PullRequestService
|
||||||
with MilestonesService
|
with MilestonesService
|
||||||
with LabelsService
|
with LabelsService
|
||||||
|
with CustomFieldsService
|
||||||
with CommitsService
|
with CommitsService
|
||||||
with ActivityService
|
with ActivityService
|
||||||
with WebHookPullRequestService
|
with WebHookPullRequestService
|
||||||
@@ -45,6 +45,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
with IssuesService
|
with IssuesService
|
||||||
with MilestonesService
|
with MilestonesService
|
||||||
with LabelsService
|
with LabelsService
|
||||||
|
with CustomFieldsService
|
||||||
with CommitsService
|
with CommitsService
|
||||||
with ActivityService
|
with ActivityService
|
||||||
with PullRequestService
|
with PullRequestService
|
||||||
@@ -58,7 +59,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
with PrioritiesService =>
|
with PrioritiesService =>
|
||||||
|
|
||||||
val pullRequestForm = mapping(
|
val pullRequestForm = mapping(
|
||||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
"title" -> trim(label("Title", text(required))),
|
||||||
"content" -> trim(label("Content", optional(text()))),
|
"content" -> trim(label("Content", optional(text()))),
|
||||||
"targetUserName" -> trim(text(required, maxlength(100))),
|
"targetUserName" -> trim(text(required, maxlength(100))),
|
||||||
"targetBranch" -> trim(text(required, maxlength(100))),
|
"targetBranch" -> trim(text(required, maxlength(100))),
|
||||||
@@ -68,7 +69,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
"commitIdFrom" -> trim(text(required, maxlength(40))),
|
"commitIdFrom" -> trim(text(required, maxlength(40))),
|
||||||
"commitIdTo" -> trim(text(required, maxlength(40))),
|
"commitIdTo" -> trim(text(required, maxlength(40))),
|
||||||
"isDraft" -> trim(boolean(required)),
|
"isDraft" -> trim(boolean(required)),
|
||||||
"assignedUserName" -> trim(optional(text())),
|
"assigneeUserNames" -> trim(optional(text())),
|
||||||
"milestoneId" -> trim(optional(number())),
|
"milestoneId" -> trim(optional(number())),
|
||||||
"priorityId" -> trim(optional(number())),
|
"priorityId" -> trim(optional(number())),
|
||||||
"labelNames" -> trim(optional(text()))
|
"labelNames" -> trim(optional(text()))
|
||||||
@@ -91,7 +92,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
commitIdFrom: String,
|
commitIdFrom: String,
|
||||||
commitIdTo: String,
|
commitIdTo: String,
|
||||||
isDraft: Boolean,
|
isDraft: Boolean,
|
||||||
assignedUserName: Option[String],
|
assigneeUserNames: Option[String],
|
||||||
milestoneId: Option[Int],
|
milestoneId: Option[Int],
|
||||||
priorityId: Option[Int],
|
priorityId: Option[Int],
|
||||||
labelNames: Option[String]
|
labelNames: Option[String]
|
||||||
@@ -111,24 +112,31 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
val owner = repository.owner
|
getPullRequest(repository.owner, repository.name, issueId) map {
|
||||||
val name = repository.name
|
|
||||||
getPullRequest(owner, name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
getRequestCompareInfo(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdFrom,
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdTo
|
||||||
|
)
|
||||||
|
|
||||||
html.conversation(
|
html.conversation(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
commits.flatten,
|
commits.flatten,
|
||||||
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
||||||
diffs.size,
|
diffs.size,
|
||||||
getIssueLabels(owner, name, issueId),
|
getIssueLabels(repository.owner, repository.name, issueId),
|
||||||
getAssignableUserNames(owner, name),
|
getIssueAssignees(repository.owner, repository.name, issueId),
|
||||||
getMilestonesWithIssueCount(owner, name),
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
getPriorities(owner, name),
|
getMilestonesWithIssueCount(repository.owner, repository.name),
|
||||||
getLabels(owner, name),
|
getPriorities(repository.owner, repository.name),
|
||||||
|
getLabels(repository.owner, repository.name),
|
||||||
|
getCustomFieldsWithValue(repository.owner, repository.name, issueId).filter(_._1.enableForPullRequests),
|
||||||
isEditable(repository),
|
isEditable(repository),
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
||||||
@@ -136,25 +144,6 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
getRepository(pullreq.requestUserName, pullreq.requestRepositoryName),
|
getRepository(pullreq.requestUserName, pullreq.requestRepositoryName),
|
||||||
flash.iterator.map(f => f._1 -> f._2.toString).toMap
|
flash.iterator.map(f => f._1 -> f._2.toString).toMap
|
||||||
)
|
)
|
||||||
|
|
||||||
// html.pullreq(
|
|
||||||
// issue,
|
|
||||||
// pullreq,
|
|
||||||
// comments,
|
|
||||||
// getIssueLabels(owner, name, issueId),
|
|
||||||
// getAssignableUserNames(owner, name),
|
|
||||||
// getMilestonesWithIssueCount(owner, name),
|
|
||||||
// getPriorities(owner, name),
|
|
||||||
// getLabels(owner, name),
|
|
||||||
// commits,
|
|
||||||
// diffs,
|
|
||||||
// isEditable(repository),
|
|
||||||
// isManageable(repository),
|
|
||||||
// hasDeveloperRole(pullreq.requestUserName, pullreq.requestRepositoryName, context.loginAccount),
|
|
||||||
// repository,
|
|
||||||
// getRepository(pullreq.requestUserName, pullreq.requestRepositoryName),
|
|
||||||
// flash.toMap.map(f => f._1 -> f._2.toString)
|
|
||||||
// )
|
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
})
|
})
|
||||||
@@ -162,18 +151,29 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/commits")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
val owner = repository.owner
|
getPullRequest(repository.owner, repository.name, issueId) map {
|
||||||
val name = repository.name
|
|
||||||
getPullRequest(owner, name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
getRequestCompareInfo(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdFrom,
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdTo
|
||||||
|
)
|
||||||
|
|
||||||
|
val commitsWithStatus = commits.map { day =>
|
||||||
|
day.map { commit =>
|
||||||
|
(commit, getCommitStatusWithSummary(repository.owner, repository.name, commit.id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
html.commits(
|
html.commits(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
commits,
|
commitsWithStatus,
|
||||||
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
||||||
diffs.size,
|
diffs.size,
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
repository
|
repository
|
||||||
@@ -185,19 +185,24 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
get("/:owner/:repository/pull/:id/files")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
val owner = repository.owner
|
getPullRequest(repository.owner, repository.name, issueId) map {
|
||||||
val name = repository.name
|
|
||||||
getPullRequest(owner, name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val (commits, diffs) =
|
val (commits, diffs) =
|
||||||
getRequestCompareInfo(owner, name, pullreq.commitIdFrom, owner, name, pullreq.commitIdTo)
|
getRequestCompareInfo(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdFrom,
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pullreq.commitIdTo
|
||||||
|
)
|
||||||
|
|
||||||
html.files(
|
html.files(
|
||||||
issue,
|
issue,
|
||||||
pullreq,
|
pullreq,
|
||||||
diffs,
|
diffs,
|
||||||
commits.flatten,
|
commits.flatten,
|
||||||
getPullRequestComments(owner, name, issue.issueId, commits.flatten),
|
getPullRequestComments(repository.owner, repository.name, issue.issueId, commits.flatten),
|
||||||
isManageable(repository),
|
isManageable(repository),
|
||||||
repository
|
repository
|
||||||
)
|
)
|
||||||
@@ -208,39 +213,35 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
ajaxGet("/:owner/:repository/pull/:id/mergeguide")(referrersOnly { repository =>
|
||||||
params("id").toIntOpt.flatMap {
|
params("id").toIntOpt.flatMap {
|
||||||
issueId =>
|
issueId =>
|
||||||
val owner = repository.owner
|
getPullRequest(repository.owner, repository.name, issueId) map {
|
||||||
val name = repository.name
|
|
||||||
getPullRequest(owner, name, issueId) map {
|
|
||||||
case (issue, pullreq) =>
|
case (issue, pullreq) =>
|
||||||
val conflictMessage = LockUtil.lock(s"${owner}/${name}") {
|
val conflictMessage = LockUtil.lock(s"${repository.owner}/${repository.name}") {
|
||||||
checkConflict(owner, name, pullreq.branch, issueId)
|
checkConflict(repository.owner, repository.name, pullreq.branch, issueId)
|
||||||
}
|
}
|
||||||
val hasMergePermission = hasDeveloperRole(owner, name, context.loginAccount)
|
val hasMergePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount)
|
||||||
val branchProtection = getProtectedBranchInfo(owner, name, pullreq.branch)
|
val branchProtection = getProtectedBranchInfo(repository.owner, repository.name, pullreq.branch)
|
||||||
val mergeStatus = PullRequestService.MergeStatus(
|
val mergeStatus = PullRequestService.MergeStatus(
|
||||||
conflictMessage = conflictMessage,
|
conflictMessage = conflictMessage,
|
||||||
commitStatuses = getCommitStatuses(owner, name, pullreq.commitIdTo),
|
commitStatuses = getCommitStatuses(repository.owner, repository.name, pullreq.commitIdTo),
|
||||||
branchProtection = branchProtection,
|
branchProtection = branchProtection,
|
||||||
branchIsOutOfDate = JGitUtil.getShaByRef(owner, name, pullreq.branch) != Some(pullreq.commitIdFrom),
|
branchIsOutOfDate = JGitUtil.getShaByRef(repository.owner, repository.name, pullreq.branch) != Some(
|
||||||
needStatusCheck = context.loginAccount
|
pullreq.commitIdFrom
|
||||||
.map { u =>
|
),
|
||||||
|
needStatusCheck = context.loginAccount.forall { u =>
|
||||||
branchProtection.needStatusCheck(u.userName)
|
branchProtection.needStatusCheck(u.userName)
|
||||||
}
|
},
|
||||||
.getOrElse(true),
|
|
||||||
hasUpdatePermission = hasDeveloperRole(
|
hasUpdatePermission = hasDeveloperRole(
|
||||||
pullreq.requestUserName,
|
pullreq.requestUserName,
|
||||||
pullreq.requestRepositoryName,
|
pullreq.requestRepositoryName,
|
||||||
context.loginAccount
|
context.loginAccount
|
||||||
) &&
|
) &&
|
||||||
context.loginAccount
|
context.loginAccount.exists { u =>
|
||||||
.map { u =>
|
|
||||||
!getProtectedBranchInfo(
|
!getProtectedBranchInfo(
|
||||||
pullreq.requestUserName,
|
pullreq.requestUserName,
|
||||||
pullreq.requestRepositoryName,
|
pullreq.requestRepositoryName,
|
||||||
pullreq.requestBranch
|
pullreq.requestBranch
|
||||||
).needStatusCheck(u.userName)
|
).needStatusCheck(u.userName)
|
||||||
}
|
},
|
||||||
.getOrElse(false),
|
|
||||||
hasMergePermission = hasMergePermission,
|
hasMergePermission = hasMergePermission,
|
||||||
commitIdTo = pullreq.commitIdTo
|
commitIdTo = pullreq.commitIdTo
|
||||||
)
|
)
|
||||||
@@ -357,29 +358,28 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pull/:id/merge", mergeForm)(writableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount { loginAccount =>
|
||||||
params("id").toIntOpt.flatMap { issueId =>
|
params("id").toIntOpt.flatMap { issueId =>
|
||||||
val owner = repository.owner
|
|
||||||
val name = repository.name
|
|
||||||
|
|
||||||
mergePullRequest(
|
mergePullRequest(
|
||||||
repository,
|
repository,
|
||||||
issueId,
|
issueId,
|
||||||
context.loginAccount.get,
|
loginAccount,
|
||||||
form.message,
|
form.message,
|
||||||
form.strategy,
|
form.strategy,
|
||||||
form.isDraft,
|
form.isDraft,
|
||||||
context.settings
|
context.settings
|
||||||
) match {
|
) match {
|
||||||
case Right(objectId) => redirect(s"/${owner}/${name}/pull/${issueId}")
|
case Right(objectId) => redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
case Left(message) => Some(BadRequest(message))
|
case Left(message) => Some(BadRequest(message))
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
get("/:owner/:repository/compare")(referrersOnly { forkedRepository =>
|
||||||
val headBranch: Option[String] = params.get("head")
|
val headBranch = params.get("head")
|
||||||
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
(forkedRepository.repository.originUserName, forkedRepository.repository.originRepositoryName) match {
|
||||||
case (Some(originUserName), Some(originRepositoryName)) => {
|
case (Some(originUserName), Some(originRepositoryName)) =>
|
||||||
getRepository(originUserName, originRepositoryName).map {
|
getRepository(originUserName, originRepositoryName).map {
|
||||||
originRepository =>
|
originRepository =>
|
||||||
Using.resources(
|
Using.resources(
|
||||||
@@ -396,8 +396,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
case _ =>
|
||||||
case _ => {
|
|
||||||
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(forkedRepository.owner, forkedRepository.name))) { git =>
|
||||||
JGitUtil.getDefaultBranch(git, forkedRepository).map {
|
JGitUtil.getDefaultBranch(git, forkedRepository).map {
|
||||||
case (_, defaultBranch) =>
|
case (_, defaultBranch) =>
|
||||||
@@ -409,15 +408,14 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/compare/*...*")(referrersOnly { forkedRepository =>
|
private def getOriginRepositoryName(
|
||||||
val Seq(origin, forked) = multiParams("splat")
|
originOwner: String,
|
||||||
val (originOwner, originId) = parseCompareIdentifier(origin, forkedRepository.owner)
|
forkedOwner: String,
|
||||||
val (forkedOwner, forkedId) = parseCompareIdentifier(forked, forkedRepository.owner)
|
forkedRepository: RepositoryInfo
|
||||||
|
): Option[String] = {
|
||||||
(for (originRepositoryName <- if (originOwner == forkedOwner) {
|
if (originOwner == forkedOwner) {
|
||||||
// Self repository
|
// Self repository
|
||||||
Some(forkedRepository.name)
|
Some(forkedRepository.name)
|
||||||
} else if (forkedRepository.repository.originUserName.isEmpty) {
|
} else if (forkedRepository.repository.originUserName.isEmpty) {
|
||||||
@@ -436,13 +434,21 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
x.repository.originRepositoryName == forkedRepository.repository.originRepositoryName
|
x.repository.originRepositoryName == forkedRepository.repository.originRepositoryName
|
||||||
}
|
}
|
||||||
.map(_.repository.repositoryName)
|
.map(_.repository.repositoryName)
|
||||||
};
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get("/:owner/:repository/compare/*...*")(referrersOnly { forkedRepository =>
|
||||||
|
val Seq(origin, forked) = multiParams("splat")
|
||||||
|
val (originOwner, originId) = parseCompareIdentifier(origin, forkedRepository.owner)
|
||||||
|
val (forkedOwner, forkedId) = parseCompareIdentifier(forked, forkedRepository.owner)
|
||||||
|
|
||||||
|
(for (originRepositoryName <- getOriginRepositoryName(originOwner, forkedOwner, forkedRepository);
|
||||||
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
originRepository <- getRepository(originOwner, originRepositoryName)) yield {
|
||||||
val (oldId, newId) =
|
val (oldId, newId) =
|
||||||
getPullRequestCommitFromTo(originRepository, forkedRepository, originId, forkedId)
|
getPullRequestCommitFromTo(originRepository, forkedRepository, originId, forkedId)
|
||||||
|
|
||||||
(oldId, newId) match {
|
(oldId, newId) match {
|
||||||
case (Some(oldId), Some(newId)) => {
|
case (Some(oldId), Some(newId)) =>
|
||||||
val (commits, diffs) = getRequestCompareInfo(
|
val (commits, diffs) = getRequestCompareInfo(
|
||||||
originRepository.owner,
|
originRepository.owner,
|
||||||
originRepository.name,
|
originRepository.name,
|
||||||
@@ -475,8 +481,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
(repository.userName, repository.repositoryName, repository.defaultBranch)
|
||||||
},
|
},
|
||||||
commits.flatten
|
commits.flatten
|
||||||
.map(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false))
|
.flatMap(commit => getCommitComments(forkedRepository.owner, forkedRepository.name, commit.id, false))
|
||||||
.flatten
|
|
||||||
.toList,
|
.toList,
|
||||||
originId,
|
originId,
|
||||||
forkedId,
|
forkedId,
|
||||||
@@ -491,9 +496,9 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
getMilestones(originRepository.owner, originRepository.name),
|
getMilestones(originRepository.owner, originRepository.name),
|
||||||
getPriorities(originRepository.owner, originRepository.name),
|
getPriorities(originRepository.owner, originRepository.name),
|
||||||
getDefaultPriority(originRepository.owner, originRepository.name),
|
getDefaultPriority(originRepository.owner, originRepository.name),
|
||||||
getLabels(originRepository.owner, originRepository.name)
|
getLabels(originRepository.owner, originRepository.name),
|
||||||
|
getCustomFields(originRepository.owner, originRepository.name).filter(_.enableForPullRequests)
|
||||||
)
|
)
|
||||||
}
|
|
||||||
case (oldId, newId) =>
|
case (oldId, newId) =>
|
||||||
redirect(
|
redirect(
|
||||||
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/" +
|
s"/${forkedRepository.owner}/${forkedRepository.name}/compare/" +
|
||||||
@@ -505,6 +510,54 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
})
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/diff/:id")(referrersOnly { repository =>
|
||||||
|
(for {
|
||||||
|
commitId <- params.get("id")
|
||||||
|
path <- params.get("path")
|
||||||
|
diff <- getSingleDiff(repository.owner, repository.name, commitId, path)
|
||||||
|
} yield {
|
||||||
|
contentType = formats("json")
|
||||||
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map(
|
||||||
|
"oldContent" -> diff.oldContent,
|
||||||
|
"newContent" -> diff.newContent
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
ajaxGet("/:owner/:repository/diff/*...*")(referrersOnly { forkedRepository =>
|
||||||
|
val Seq(origin, forked) = multiParams("splat")
|
||||||
|
val (originOwner, originId) = parseCompareIdentifier(origin, forkedRepository.owner)
|
||||||
|
val (forkedOwner, forkedId) = parseCompareIdentifier(forked, forkedRepository.owner)
|
||||||
|
|
||||||
|
(for {
|
||||||
|
path <- params.get("path")
|
||||||
|
originRepositoryName <- getOriginRepositoryName(originOwner, forkedOwner, forkedRepository)
|
||||||
|
originRepository <- getRepository(originOwner, originRepositoryName)
|
||||||
|
(oldId, newId) = getPullRequestCommitFromTo(originRepository, forkedRepository, originId, forkedId)
|
||||||
|
oldId <- oldId
|
||||||
|
newId <- newId
|
||||||
|
diff <- getSingleDiff(
|
||||||
|
originRepository.owner,
|
||||||
|
originRepository.name,
|
||||||
|
oldId.getName,
|
||||||
|
forkedRepository.owner,
|
||||||
|
forkedRepository.name,
|
||||||
|
newId.getName,
|
||||||
|
path
|
||||||
|
)
|
||||||
|
} yield {
|
||||||
|
contentType = formats("json")
|
||||||
|
org.json4s.jackson.Serialization.write(
|
||||||
|
Map(
|
||||||
|
"oldContent" -> diff.oldContent,
|
||||||
|
"newContent" -> diff.newContent
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}) getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/compare/*...*/mergecheck")(readableUsersOnly { forkedRepository =>
|
ajaxGet("/:owner/:repository/compare/*...*/mergecheck")(readableUsersOnly { forkedRepository =>
|
||||||
val Seq(origin, forked) = multiParams("splat")
|
val Seq(origin, forked) = multiParams("splat")
|
||||||
val (originOwner, tmpOriginBranch) = parseCompareIdentifier(origin, forkedRepository.owner)
|
val (originOwner, tmpOriginBranch) = parseCompareIdentifier(origin, forkedRepository.owner)
|
||||||
@@ -543,18 +596,16 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount {
|
||||||
case (owner, name) =>
|
loginAccount =>
|
||||||
val manageable = isManageable(repository)
|
val manageable = isManageable(repository)
|
||||||
val loginUserName = context.loginAccount.get.userName
|
|
||||||
|
|
||||||
val issueId = insertIssue(
|
val issueId = insertIssue(
|
||||||
owner = repository.owner,
|
owner = repository.owner,
|
||||||
repository = repository.name,
|
repository = repository.name,
|
||||||
loginUser = loginUserName,
|
loginUser = loginAccount.userName,
|
||||||
title = form.title,
|
title = form.title,
|
||||||
content = form.content,
|
content = form.content,
|
||||||
assignedUserName = if (manageable) form.assignedUserName else None,
|
|
||||||
milestoneId = if (manageable) form.milestoneId else None,
|
milestoneId = if (manageable) form.milestoneId else None,
|
||||||
priorityId = if (manageable) form.priorityId else None,
|
priorityId = if (manageable) form.priorityId else None,
|
||||||
isPullRequest = true
|
isPullRequest = true
|
||||||
@@ -570,14 +621,20 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
commitIdFrom = form.commitIdFrom,
|
commitIdFrom = form.commitIdFrom,
|
||||||
commitIdTo = form.commitIdTo,
|
commitIdTo = form.commitIdTo,
|
||||||
isDraft = form.isDraft,
|
isDraft = form.isDraft,
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
)
|
)
|
||||||
|
|
||||||
// insert labels
|
|
||||||
if (manageable) {
|
if (manageable) {
|
||||||
|
// insert assignees
|
||||||
|
form.assigneeUserNames.foreach { value =>
|
||||||
|
value.split(",").foreach { userName =>
|
||||||
|
registerIssueAssignee(repository.owner, repository.name, issueId, userName)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// insert labels
|
||||||
form.labelNames.foreach { value =>
|
form.labelNames.foreach { value =>
|
||||||
val labels = getLabels(owner, name)
|
val labels = getLabels(repository.owner, repository.name)
|
||||||
value.split(",").foreach { labelName =>
|
value.split(",").foreach { labelName =>
|
||||||
labels.find(_.labelName == labelName).map { label =>
|
labels.find(_.labelName == labelName).map { label =>
|
||||||
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
||||||
@@ -586,7 +643,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
redirect(s"/${owner}/${name}/pull/${issueId}")
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -633,9 +690,7 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
html.proposals(proposedBranches, targetRepository, repository)
|
html.proposals(proposedBranches, targetRepository, repository)
|
||||||
})
|
})
|
||||||
|
|
||||||
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) =
|
private def searchPullRequests(userName: Option[String], repository: RepositoryService.RepositoryInfo) = {
|
||||||
defining(repository.owner, repository.name) {
|
|
||||||
case (owner, repoName) =>
|
|
||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
// retrieve search condition
|
// retrieve search condition
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
@@ -645,12 +700,12 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
IssueSearchOption.PullRequests,
|
IssueSearchOption.PullRequests,
|
||||||
(page - 1) * PullRequestLimit,
|
(page - 1) * PullRequestLimit,
|
||||||
PullRequestLimit,
|
PullRequestLimit,
|
||||||
owner -> repoName
|
repository.owner -> repository.name
|
||||||
)
|
)
|
||||||
// commit status
|
// commit status
|
||||||
val status = issues.map { issue =>
|
val status = issues.map { issue =>
|
||||||
issue.commitId.flatMap { commitId =>
|
issue.commitId.flatMap { commitId =>
|
||||||
getCommitStatusWithSummary(owner, repoName, commitId)
|
getCommitStatusWithSummary(repository.owner, repository.name, commitId)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -658,12 +713,12 @@ trait PullRequestsControllerBase extends ControllerBase {
|
|||||||
"pulls",
|
"pulls",
|
||||||
issues.zip(status),
|
issues.zip(status),
|
||||||
page,
|
page,
|
||||||
getAssignableUserNames(owner, repoName),
|
getAssignableUserNames(repository.owner, repository.name),
|
||||||
getMilestones(owner, repoName),
|
getMilestones(repository.owner, repository.name),
|
||||||
getPriorities(owner, repoName),
|
getPriorities(repository.owner, repository.name),
|
||||||
getLabels(owner, repoName),
|
getLabels(repository.owner, repository.name),
|
||||||
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, owner -> repoName),
|
countIssue(condition.copy(state = "open"), IssueSearchOption.PullRequests, repository.owner -> repository.name),
|
||||||
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, owner -> repoName),
|
countIssue(condition.copy(state = "closed"), IssueSearchOption.PullRequests, repository.owner -> repository.name),
|
||||||
condition,
|
condition,
|
||||||
repository,
|
repository,
|
||||||
isEditable(repository),
|
isEditable(repository),
|
||||||
|
|||||||
@@ -63,8 +63,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/:tag")(referrersOnly { repository =>
|
get("/:owner/:repository/releases/*")(referrersOnly { repository =>
|
||||||
val tagName = params("tag")
|
val tagName = multiParams("splat").head
|
||||||
getRelease(repository.owner, repository.name, tagName)
|
getRelease(repository.owner, repository.name, tagName)
|
||||||
.map { release =>
|
.map { release =>
|
||||||
html.release(
|
html.release(
|
||||||
@@ -77,8 +77,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/:tag/assets/:fileId")(referrersOnly { repository =>
|
get("/:owner/:repository/releases/*/assets/:fileId")(referrersOnly { repository =>
|
||||||
val tagName = params("tag")
|
val tagName = multiParams("splat").head
|
||||||
val fileId = params("fileId")
|
val fileId = params("fileId")
|
||||||
(for {
|
(for {
|
||||||
_ <- repository.tags.find(_.name == tagName)
|
_ <- repository.tags.find(_.name == tagName)
|
||||||
@@ -93,8 +93,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
}).getOrElse(NotFound())
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/:tag/create")(writableUsersOnly { repository =>
|
get("/:owner/:repository/releases/*/create")(writableUsersOnly { repository =>
|
||||||
val tagName = params("tag")
|
val tagName = multiParams("splat").head
|
||||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||||
|
|
||||||
repository.tags
|
repository.tags
|
||||||
@@ -105,9 +105,10 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/:tag/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/releases/*/create", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||||
val tagName = params("tag")
|
context.withLoginAccount {
|
||||||
val loginAccount = context.loginAccount.get
|
loginAccount =>
|
||||||
|
val tagName = multiParams("splat").head
|
||||||
|
|
||||||
// Insert into RELEASE
|
// Insert into RELEASE
|
||||||
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
createRelease(repository.owner, repository.name, form.name, form.content, tagName, loginAccount)
|
||||||
@@ -132,11 +133,12 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
recordActivity(releaseInfo)
|
recordActivity(releaseInfo)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
redirect(s"/${repository.owner}/${repository.name}/releases/${tagName}")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/changelog/*...*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/changelog/*...*")(writableUsersOnly { repository =>
|
||||||
val Seq(previousTag, currentTag) = multiParams("splat")
|
val Seq(previousTag, currentTag) = multiParams("splat")
|
||||||
val previousTagId = repository.tags.collectFirst { case x if x.name == previousTag => x.id }.getOrElse("")
|
val previousTagId = repository.tags.collectFirst { case x if x.name == previousTag => x.commitId }.getOrElse("")
|
||||||
|
|
||||||
val commitLog = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
val commitLog = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val commits = JGitUtil.getCommitLog(git, previousTagId, currentTag).reverse
|
val commits = JGitUtil.getCommitLog(git, previousTagId, currentTag).reverse
|
||||||
@@ -150,8 +152,8 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
commitLog
|
commitLog
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/releases/:tag/edit")(writableUsersOnly { repository =>
|
get("/:owner/:repository/releases/*/edit")(writableUsersOnly { repository =>
|
||||||
val tagName = params("tag")
|
val tagName = multiParams("splat").head
|
||||||
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
val previousTags = repository.tags.takeWhile(_.name != tagName).reverse
|
||||||
|
|
||||||
(for {
|
(for {
|
||||||
@@ -168,13 +170,14 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
}).getOrElse(NotFound())
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/:tag/edit", releaseForm)(writableUsersOnly {
|
post("/:owner/:repository/releases/*/edit", releaseForm)(writableUsersOnly { (form, repository) =>
|
||||||
(form, repository) =>
|
context.withLoginAccount {
|
||||||
val tagName = params("tag")
|
loginAccount =>
|
||||||
val loginAccount = context.loginAccount.get
|
val tagName = multiParams("splat").head
|
||||||
|
|
||||||
getRelease(repository.owner, repository.name, tagName)
|
getRelease(repository.owner, repository.name, tagName)
|
||||||
.map { release =>
|
.map {
|
||||||
|
release =>
|
||||||
// Update RELEASE
|
// Update RELEASE
|
||||||
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
updateRelease(repository.owner, repository.name, tagName, form.name, form.content)
|
||||||
|
|
||||||
@@ -210,10 +213,11 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
redirect(s"/${release.userName}/${release.repositoryName}/releases/${tagName}")
|
||||||
}
|
}
|
||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/releases/:tag/delete")(writableUsersOnly { repository =>
|
post("/:owner/:repository/releases/*/delete")(writableUsersOnly { repository =>
|
||||||
val tagName = params("tag")
|
val tagName = multiParams("splat").head
|
||||||
getRelease(repository.owner, repository.name, tagName).foreach { release =>
|
getRelease(repository.owner, repository.name, tagName).foreach { release =>
|
||||||
FileUtils.deleteDirectory(
|
FileUtils.deleteDirectory(
|
||||||
new File(getReleaseFilesDir(repository.owner, repository.name), FileUtil.checkFilename(release.tag))
|
new File(getReleaseFilesDir(repository.owner, repository.name), FileUtil.checkFilename(release.tag))
|
||||||
@@ -224,7 +228,6 @@ trait ReleaseControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
private def fetchReleases(repository: RepositoryService.RepositoryInfo, page: Int) = {
|
||||||
|
|
||||||
import gitbucket.core.service.ReleaseService._
|
import gitbucket.core.service.ReleaseService._
|
||||||
|
|
||||||
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
val (offset, limit) = ((page - 1) * ReleaseLimit, ReleaseLimit)
|
||||||
|
|||||||
@@ -1,8 +1,7 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import java.time.{LocalDateTime, ZoneId, ZoneOffset}
|
import java.time.{LocalDateTime, ZoneOffset}
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
import gitbucket.core.settings.html
|
import gitbucket.core.settings.html
|
||||||
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
import gitbucket.core.model.{RepositoryWebHook, WebHook}
|
||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
@@ -21,7 +20,7 @@ import org.eclipse.jgit.lib.Constants
|
|||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
import org.scalatra.Forbidden
|
import org.scalatra.{Forbidden, Ok}
|
||||||
|
|
||||||
class RepositorySettingsController
|
class RepositorySettingsController
|
||||||
extends RepositorySettingsControllerBase
|
extends RepositorySettingsControllerBase
|
||||||
@@ -31,6 +30,7 @@ class RepositorySettingsController
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
|
with CustomFieldsService
|
||||||
with ActivityService
|
with ActivityService
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator
|
with UsersAuthenticator
|
||||||
@@ -43,6 +43,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
with ProtectedBranchService
|
with ProtectedBranchService
|
||||||
with CommitStatusService
|
with CommitStatusService
|
||||||
with DeployKeyService
|
with DeployKeyService
|
||||||
|
with CustomFieldsService
|
||||||
with ActivityService
|
with ActivityService
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
with UsersAuthenticator =>
|
with UsersAuthenticator =>
|
||||||
@@ -57,7 +58,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
externalWikiUrl: Option[String],
|
externalWikiUrl: Option[String],
|
||||||
allowFork: Boolean,
|
allowFork: Boolean,
|
||||||
mergeOptions: Seq[String],
|
mergeOptions: Seq[String],
|
||||||
defaultMergeOption: String
|
defaultMergeOption: String,
|
||||||
|
safeMode: Boolean
|
||||||
)
|
)
|
||||||
|
|
||||||
val optionsForm = mapping(
|
val optionsForm = mapping(
|
||||||
@@ -69,7 +71,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"externalWikiUrl" -> trim(label("External Wiki URL", optional(text(maxlength(200))))),
|
"externalWikiUrl" -> trim(label("External Wiki URL", optional(text(maxlength(200))))),
|
||||||
"allowFork" -> trim(label("Allow Forking", boolean())),
|
"allowFork" -> trim(label("Allow Forking", boolean())),
|
||||||
"mergeOptions" -> mergeOptions,
|
"mergeOptions" -> mergeOptions,
|
||||||
"defaultMergeOption" -> trim(label("Default merge strategy", text(required)))
|
"defaultMergeOption" -> trim(label("Default merge strategy", text(required))),
|
||||||
|
"safeMode" -> trim(label("XSS protection", boolean()))
|
||||||
)(OptionsForm.apply).verifying { form =>
|
)(OptionsForm.apply).verifying { form =>
|
||||||
if (!form.mergeOptions.contains(form.defaultMergeOption)) {
|
if (!form.mergeOptions.contains(form.defaultMergeOption)) {
|
||||||
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
Seq("defaultMergeOption" -> s"This merge strategy isn't enabled.")
|
||||||
@@ -119,6 +122,21 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
"newOwner" -> trim(label("New owner", text(required, transferUser)))
|
"newOwner" -> trim(label("New owner", text(required, transferUser)))
|
||||||
)(TransferOwnerShipForm.apply)
|
)(TransferOwnerShipForm.apply)
|
||||||
|
|
||||||
|
// for custom field
|
||||||
|
case class CustomFieldForm(
|
||||||
|
fieldName: String,
|
||||||
|
fieldType: String,
|
||||||
|
enableForIssues: Boolean,
|
||||||
|
enableForPullRequests: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
val customFieldForm = mapping(
|
||||||
|
"fieldName" -> trim(label("Field name", text(required, maxlength(100)))),
|
||||||
|
"fieldType" -> trim(label("Field type", text(required))),
|
||||||
|
"enableForIssues" -> trim(label("Enable for issues", boolean(required))),
|
||||||
|
"enableForPullRequests" -> trim(label("Enable for pull requests", boolean(required))),
|
||||||
|
)(CustomFieldForm.apply)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Redirect to the Options page.
|
* Redirect to the Options page.
|
||||||
*/
|
*/
|
||||||
@@ -150,7 +168,8 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
form.externalWikiUrl,
|
form.externalWikiUrl,
|
||||||
form.allowFork,
|
form.allowFork,
|
||||||
form.mergeOptions,
|
form.mergeOptions,
|
||||||
form.defaultMergeOption
|
form.defaultMergeOption,
|
||||||
|
form.safeMode
|
||||||
)
|
)
|
||||||
flash.update("info", "Repository settings has been updated.")
|
flash.update("info", "Repository settings has been updated.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||||
@@ -342,7 +361,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
.map(
|
.map(
|
||||||
res =>
|
res =>
|
||||||
Map(
|
Map(
|
||||||
"status" -> res.getStatusLine(),
|
"status" -> res.getStatusLine.getStatusCode,
|
||||||
"body" -> EntityUtils.toString(res.getEntity()),
|
"body" -> EntityUtils.toString(res.getEntity()),
|
||||||
"headers" -> _headers(res.getAllHeaders())
|
"headers" -> _headers(res.getAllHeaders())
|
||||||
)
|
)
|
||||||
@@ -385,7 +404,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
* Rename repository.
|
* Rename repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/rename", renameForm)(ownerOnly { (form, repository) =>
|
||||||
if (context.settings.repositoryOperation.rename || context.loginAccount.get.isAdmin) {
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (context.settings.basicBehavior.repositoryOperation.rename || loginAccount.isAdmin) {
|
||||||
if (repository.name != form.repositoryName) {
|
if (repository.name != form.repositoryName) {
|
||||||
// Update database and move git repository
|
// Update database and move git repository
|
||||||
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
renameRepository(repository.owner, repository.name, repository.owner, form.repositoryName)
|
||||||
@@ -393,20 +414,23 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
val renameInfo = RenameRepositoryInfo(
|
val renameInfo = RenameRepositoryInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
form.repositoryName,
|
form.repositoryName,
|
||||||
context.loginAccount.get.userName,
|
loginAccount.userName,
|
||||||
repository.name
|
repository.name
|
||||||
)
|
)
|
||||||
recordActivity(renameInfo)
|
recordActivity(renameInfo)
|
||||||
}
|
}
|
||||||
redirect(s"/${repository.owner}/${form.repositoryName}")
|
redirect(s"/${repository.owner}/${form.repositoryName}")
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Transfer repository ownership.
|
* Transfer repository ownership.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
post("/:owner/:repository/settings/transfer", transferForm)(ownerOnly { (form, repository) =>
|
||||||
if (context.settings.repositoryOperation.transfer || context.loginAccount.get.isAdmin) {
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (context.settings.basicBehavior.repositoryOperation.transfer || loginAccount.isAdmin) {
|
||||||
// Change repository owner
|
// Change repository owner
|
||||||
if (repository.owner != form.newOwner) {
|
if (repository.owner != form.newOwner) {
|
||||||
// Update database and move git repository
|
// Update database and move git repository
|
||||||
@@ -415,24 +439,27 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
val renameInfo = RenameRepositoryInfo(
|
val renameInfo = RenameRepositoryInfo(
|
||||||
form.newOwner,
|
form.newOwner,
|
||||||
repository.name,
|
repository.name,
|
||||||
context.loginAccount.get.userName,
|
loginAccount.userName,
|
||||||
repository.owner
|
repository.owner
|
||||||
)
|
)
|
||||||
recordActivity(renameInfo)
|
recordActivity(renameInfo)
|
||||||
}
|
}
|
||||||
redirect(s"/${form.newOwner}/${repository.name}")
|
redirect(s"/${form.newOwner}/${repository.name}")
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Delete the repository.
|
* Delete the repository.
|
||||||
*/
|
*/
|
||||||
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
||||||
if (context.settings.repositoryOperation.delete || context.loginAccount.get.isAdmin) {
|
context.withLoginAccount { loginAccount =>
|
||||||
|
if (context.settings.basicBehavior.repositoryOperation.delete || loginAccount.isAdmin) {
|
||||||
// Delete the repository and related files
|
// Delete the repository and related files
|
||||||
deleteRepository(repository.repository)
|
deleteRepository(repository.repository)
|
||||||
redirect(s"/${repository.owner}")
|
redirect(s"/${repository.owner}")
|
||||||
} else Forbidden()
|
} else Forbidden()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -466,6 +493,58 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
|||||||
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
||||||
})
|
})
|
||||||
|
|
||||||
|
/** Custom fields for issues and pull requests */
|
||||||
|
get("/:owner/:repository/settings/issues")(ownerOnly { repository =>
|
||||||
|
val customFields = getCustomFields(repository.owner, repository.name)
|
||||||
|
html.issues(customFields, repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** New custom field form */
|
||||||
|
get("/:owner/:repository/settings/issues/fields/new")(ownerOnly { repository =>
|
||||||
|
html.issuesfieldform(None, repository)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Add custom field */
|
||||||
|
ajaxPost("/:owner/:repository/settings/issues/fields/new", customFieldForm)(ownerOnly { (form, repository) =>
|
||||||
|
val fieldId = createCustomField(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
form.fieldName,
|
||||||
|
form.fieldType,
|
||||||
|
form.enableForIssues,
|
||||||
|
form.enableForPullRequests
|
||||||
|
)
|
||||||
|
html.issuesfield(getCustomField(repository.owner, repository.name, fieldId).get)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Edit custom field form */
|
||||||
|
ajaxGet("/:owner/:repository/settings/issues/fields/:fieldId/edit")(ownerOnly { repository =>
|
||||||
|
getCustomField(repository.owner, repository.name, params("fieldId").toInt).map { customField =>
|
||||||
|
html.issuesfieldform(Some(customField), repository)
|
||||||
|
} getOrElse NotFound()
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Update custom field */
|
||||||
|
ajaxPost("/:owner/:repository/settings/issues/fields/:fieldId/edit", customFieldForm)(ownerOnly {
|
||||||
|
(form, repository) =>
|
||||||
|
updateCustomField(
|
||||||
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
params("fieldId").toInt,
|
||||||
|
form.fieldName,
|
||||||
|
form.fieldType,
|
||||||
|
form.enableForIssues,
|
||||||
|
form.enableForPullRequests
|
||||||
|
)
|
||||||
|
html.issuesfield(getCustomField(repository.owner, repository.name, params("fieldId").toInt).get)
|
||||||
|
})
|
||||||
|
|
||||||
|
/** Delete custom field */
|
||||||
|
ajaxPost("/:owner/:repository/settings/issues/fields/:fieldId/delete")(ownerOnly { repository =>
|
||||||
|
deleteCustomField(repository.owner, repository.name, params("fieldId").toInt)
|
||||||
|
Ok()
|
||||||
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides duplication check for web hook url.
|
* Provides duplication check for web hook url.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import java.io.{File, FileInputStream, FileOutputStream}
|
import java.io.{File, FileInputStream, FileOutputStream}
|
||||||
|
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||||
import gitbucket.core.repo.html
|
import gitbucket.core.repo.html
|
||||||
@@ -11,12 +10,11 @@ import gitbucket.core.service._
|
|||||||
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
import gitbucket.core.service.RepositoryCommitFileService.CommitFile
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.Directory._
|
import gitbucket.core.util.Directory._
|
||||||
import gitbucket.core.model.Account
|
import gitbucket.core.model.{Account, WebHook}
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
import gitbucket.core.service.WebHookService.{WebHookCreatePayload, WebHookPushPayload}
|
||||||
import gitbucket.core.view
|
import gitbucket.core.view
|
||||||
import gitbucket.core.view.helpers
|
import gitbucket.core.view.helpers
|
||||||
import org.apache.commons.compress.archivers.{ArchiveEntry, ArchiveOutputStream}
|
import org.apache.commons.compress.archivers.{ArchiveEntry, ArchiveOutputStream}
|
||||||
@@ -221,10 +219,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
gitbucket.core.repo.html.creating(owner, repository)
|
gitbucket.core.repo.html.creating(owner, repository)
|
||||||
} else {
|
} else {
|
||||||
params.get("go-get") match {
|
params.get("go-get") match {
|
||||||
case Some("1") =>
|
case Some("1") => getRepository(owner, repository).map(gitbucket.core.html.goget(_)) getOrElse NotFound()
|
||||||
defining(request.paths) { paths =>
|
|
||||||
getRepository(owner, repository).map(gitbucket.core.html.goget(_)) getOrElse NotFound()
|
|
||||||
}
|
|
||||||
case _ => referrersOnly(fileList(_))
|
case _ => referrersOnly(fileList(_))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -271,23 +266,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
branchName,
|
branchName,
|
||||||
repository,
|
repository,
|
||||||
logs
|
logs
|
||||||
.map {
|
.map { commit =>
|
||||||
commit =>
|
|
||||||
(
|
(
|
||||||
CommitInfo(
|
commit.copy(verified = commit.commitSign.flatMap(GpgUtil.verifySign)),
|
||||||
id = commit.id,
|
|
||||||
shortMessage = commit.shortMessage,
|
|
||||||
fullMessage = commit.fullMessage,
|
|
||||||
parents = commit.parents,
|
|
||||||
authorTime = commit.authorTime,
|
|
||||||
authorName = commit.authorName,
|
|
||||||
authorEmailAddress = commit.authorEmailAddress,
|
|
||||||
commitTime = commit.commitTime,
|
|
||||||
committerName = commit.committerName,
|
|
||||||
committerEmailAddress = commit.committerEmailAddress,
|
|
||||||
commitSign = commit.commitSign,
|
|
||||||
verified = commit.commitSign.flatMap(GpgUtil.verifySign)
|
|
||||||
),
|
|
||||||
JGitUtil.getTagsOnCommit(git, commit.id),
|
JGitUtil.getTagsOnCommit(git, commit.id),
|
||||||
getCommitStatusWithSummary(repository.owner, repository.name, commit.id)
|
getCommitStatusWithSummary(repository.owner, repository.name, commit.id)
|
||||||
)
|
)
|
||||||
@@ -306,9 +287,11 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/new/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/new/*")(writableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
@@ -323,12 +306,15 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
commit = revCommit.getName
|
commit = revCommit.getName
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/upload/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/upload/*")(writableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
html.upload(
|
html.upload(
|
||||||
@@ -339,41 +325,20 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
revCommit.name
|
revCommit.name
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/upload", uploadForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/upload", uploadForm)(writableUsersOnly { (form, repository) =>
|
||||||
val files = form.uploadFiles.split("\n").map { line =>
|
def _commit(
|
||||||
val i = line.indexOf(':')
|
branchName: String,
|
||||||
CommitFile(line.substring(0, i).trim, line.substring(i + 1).trim)
|
newFiles: Seq[CommitFile],
|
||||||
}
|
loginAccount: Account
|
||||||
|
): Either[String, ObjectId] = {
|
||||||
val newFiles = files.map { file =>
|
|
||||||
file.copy(name = if (form.path.length == 0) file.name else s"${form.path}/${file.name}")
|
|
||||||
}
|
|
||||||
|
|
||||||
if (form.newBranch) {
|
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
|
||||||
val objectId = _commit(newBranchName)
|
|
||||||
val issueId =
|
|
||||||
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
|
||||||
} else {
|
|
||||||
_commit(form.branch)
|
|
||||||
if (form.path.length == 0) {
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}")
|
|
||||||
} else {
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${form.branch}/${form.path}")
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
def _commit(branchName: String): ObjectId = {
|
|
||||||
commitFiles(
|
commitFiles(
|
||||||
repository = repository,
|
repository = repository,
|
||||||
branch = branchName,
|
branch = branchName,
|
||||||
path = form.path,
|
|
||||||
files = files.toIndexedSeq,
|
|
||||||
message = form.message.getOrElse("Add files via upload"),
|
message = form.message.getOrElse("Add files via upload"),
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
) {
|
) {
|
||||||
case (git, headTip, builder, inserter) =>
|
case (git, headTip, builder, inserter) =>
|
||||||
@@ -393,18 +358,67 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
val files = form.uploadFiles
|
||||||
|
.split("\n")
|
||||||
|
.map { line =>
|
||||||
|
val i = line.indexOf(':')
|
||||||
|
CommitFile(line.substring(0, i).trim, line.substring(i + 1).trim)
|
||||||
|
}
|
||||||
|
.toSeq
|
||||||
|
|
||||||
|
val newFiles = files.map { file =>
|
||||||
|
file.copy(name = if (form.path.length == 0) file.name else s"${form.path}/${file.name}")
|
||||||
|
}
|
||||||
|
|
||||||
|
if (form.newBranch) {
|
||||||
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
|
_commit(newBranchName, newFiles, loginAccount) match {
|
||||||
|
case Right(objectId) =>
|
||||||
|
val issueId =
|
||||||
|
createIssueAndPullRequest(
|
||||||
|
repository,
|
||||||
|
form.branch,
|
||||||
|
newBranchName,
|
||||||
|
form.commit,
|
||||||
|
objectId.name,
|
||||||
|
form.message,
|
||||||
|
loginAccount
|
||||||
|
)
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_commit(form.branch, newFiles, loginAccount) match {
|
||||||
|
case Right(_) =>
|
||||||
|
if (form.path.length == 0) {
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}")
|
||||||
|
} else {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}/${encodeRefName(form.path)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/edit/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/edit/*")(writableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
val (branch, path) = repository.splitPath(multiParams("splat").head)
|
||||||
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
val protectedBranch = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||||
.needStatusCheck(context.loginAccount.get.userName)
|
.needStatusCheck(loginAccount.userName)
|
||||||
|
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(branch))
|
||||||
|
|
||||||
getPathObjectId(git, path, revCommit).map {
|
getPathObjectId(git, path, revCommit)
|
||||||
|
.map {
|
||||||
objectId =>
|
objectId =>
|
||||||
val paths = path.split("/")
|
val paths = path.split("/")
|
||||||
val info = EditorConfigUtil.getEditorConfigInfo(git, branch, path)
|
val info = EditorConfigUtil.getEditorConfigInfo(git, branch, path)
|
||||||
@@ -414,7 +428,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repository = repository,
|
repository = repository,
|
||||||
pathList = paths.take(paths.size - 1).toList,
|
pathList = paths.take(paths.size - 1).toList,
|
||||||
fileName = Some(paths.last),
|
fileName = Some(paths.last),
|
||||||
content = JGitUtil.getContentInfo(git, path, objectId),
|
content = JGitUtil.getContentInfo(git, path, objectId, repository.repository.options.safeMode),
|
||||||
protectedBranch = protectedBranch,
|
protectedBranch = protectedBranch,
|
||||||
commit = revCommit.getName,
|
commit = revCommit.getName,
|
||||||
newLineMode = info.newLineMode,
|
newLineMode = info.newLineMode,
|
||||||
@@ -423,6 +437,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/remove/*")(writableUsersOnly { repository =>
|
||||||
@@ -438,7 +453,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
repository = repository,
|
repository = repository,
|
||||||
pathList = paths.take(paths.size - 1).toList,
|
pathList = paths.take(paths.size - 1).toList,
|
||||||
fileName = paths.last,
|
fileName = paths.last,
|
||||||
content = JGitUtil.getContentInfo(git, path, objectId),
|
content = JGitUtil.getContentInfo(git, path, objectId, repository.repository.options.safeMode),
|
||||||
commit = revCommit.getName
|
commit = revCommit.getName
|
||||||
)
|
)
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -446,21 +461,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/create", editorForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/create", editorForm)(writableUsersOnly { (form, repository) =>
|
||||||
if (form.newBranch) {
|
def _commit(branchName: String, loginAccount: Account): Either[String, ObjectId] = {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
|
||||||
val objectId = _commit(newBranchName)
|
|
||||||
val issueId =
|
|
||||||
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
|
||||||
} else {
|
|
||||||
_commit(form.branch)
|
|
||||||
redirect(
|
|
||||||
s"/${repository.owner}/${repository.name}/blob/${form.branch}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
|
||||||
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
def _commit(branchName: String): ObjectId = {
|
|
||||||
commitFile(
|
commitFile(
|
||||||
repository = repository,
|
repository = repository,
|
||||||
branch = branchName,
|
branch = branchName,
|
||||||
@@ -471,28 +472,50 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
charset = form.charset,
|
charset = form.charset,
|
||||||
message = form.message.getOrElse(s"Create ${form.newFileName}"),
|
message = form.message.getOrElse(s"Create ${form.newFileName}"),
|
||||||
commit = form.commit,
|
commit = form.commit,
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
|
).map(_._1)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (form.newBranch) {
|
||||||
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
|
_commit(newBranchName, loginAccount) match {
|
||||||
|
case Right(objectId) =>
|
||||||
|
val issueId =
|
||||||
|
createIssueAndPullRequest(
|
||||||
|
repository,
|
||||||
|
form.branch,
|
||||||
|
newBranchName,
|
||||||
|
form.commit,
|
||||||
|
objectId.name,
|
||||||
|
form.message,
|
||||||
|
loginAccount
|
||||||
)
|
)
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_commit(form.branch, loginAccount) match {
|
||||||
|
case Right(_) =>
|
||||||
|
if (form.path.length == 0) {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${encodeRefName(form.path)}/${urlEncode(form.newFileName)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/update", editorForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/update", editorForm)(writableUsersOnly { (form, repository) =>
|
||||||
if (form.newBranch) {
|
def _commit(branchName: String, loginAccount: Account): Either[String, ObjectId] = {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
|
||||||
val objectId = _commit(newBranchName)
|
|
||||||
val issueId =
|
|
||||||
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
|
||||||
} else {
|
|
||||||
_commit(form.branch)
|
|
||||||
redirect(
|
|
||||||
s"/${repository.owner}/${repository.name}/blob/${urlEncode(form.branch)}/${if (form.path.length == 0) urlEncode(form.newFileName)
|
|
||||||
else s"${form.path}/${urlEncode(form.newFileName)}"}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
def _commit(branchName: String): ObjectId = {
|
|
||||||
commitFile(
|
commitFile(
|
||||||
repository = repository,
|
repository = repository,
|
||||||
branch = branchName,
|
branch = branchName,
|
||||||
@@ -507,28 +530,50 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
|
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
|
||||||
},
|
},
|
||||||
commit = form.commit,
|
commit = form.commit,
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
|
).map(_._1)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (form.newBranch) {
|
||||||
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
|
_commit(newBranchName, loginAccount) match {
|
||||||
|
case Right(objectId) =>
|
||||||
|
val issueId =
|
||||||
|
createIssueAndPullRequest(
|
||||||
|
repository,
|
||||||
|
form.branch,
|
||||||
|
newBranchName,
|
||||||
|
form.commit,
|
||||||
|
objectId.name,
|
||||||
|
form.message,
|
||||||
|
loginAccount
|
||||||
)
|
)
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_commit(form.branch, loginAccount) match {
|
||||||
|
case Right(_) =>
|
||||||
|
if (form.path.length == 0) {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${urlEncode(form.newFileName)}"
|
||||||
|
)
|
||||||
|
} else {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/blob/${encodeRefName(form.branch)}/${encodeRefName(form.path)}/${urlEncode(form.newFileName)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/remove", deleteForm)(writableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/remove", deleteForm)(writableUsersOnly { (form, repository) =>
|
||||||
if (form.newBranch) {
|
def _commit(branchName: String, loginAccount: Account): Either[String, ObjectId] = {
|
||||||
val newBranchName = createNewBranchForPullRequest(repository, form.branch)
|
|
||||||
val objectId = _commit(newBranchName)
|
|
||||||
val issueId =
|
|
||||||
createIssueAndPullRequest(repository, form.branch, newBranchName, form.commit, objectId.name, form.message)
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
|
||||||
} else {
|
|
||||||
_commit(form.branch)
|
|
||||||
redirect(
|
|
||||||
s"/${repository.owner}/${repository.name}/tree/${form.branch}${if (form.path.length == 0) ""
|
|
||||||
else "/" + form.path}"
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
def _commit(branchName: String): ObjectId = {
|
|
||||||
commitFile(
|
commitFile(
|
||||||
repository = repository,
|
repository = repository,
|
||||||
branch = branchName,
|
branch = branchName,
|
||||||
@@ -539,26 +584,80 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
charset = "",
|
charset = "",
|
||||||
message = form.message.getOrElse(s"Delete ${form.fileName}"),
|
message = form.message.getOrElse(s"Delete ${form.fileName}"),
|
||||||
commit = form.commit,
|
commit = form.commit,
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
|
).map(_._1)
|
||||||
|
}
|
||||||
|
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
|
if (form.newBranch) {
|
||||||
|
val newBranchName = createNewBranchForPullRequest(repository, form.branch, loginAccount)
|
||||||
|
_commit(newBranchName, loginAccount) match {
|
||||||
|
case Right(objectId) =>
|
||||||
|
val issueId =
|
||||||
|
createIssueAndPullRequest(
|
||||||
|
repository,
|
||||||
|
form.branch,
|
||||||
|
newBranchName,
|
||||||
|
form.commit,
|
||||||
|
objectId.name,
|
||||||
|
form.message,
|
||||||
|
loginAccount
|
||||||
)
|
)
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/pull/${issueId}")
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_commit(form.branch, loginAccount) match {
|
||||||
|
case Right(_) =>
|
||||||
|
if (form.path.isEmpty) {
|
||||||
|
redirect(s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}")
|
||||||
|
} else {
|
||||||
|
redirect(
|
||||||
|
s"/${repository.owner}/${repository.name}/tree/${encodeRefName(form.branch)}/${encodeRefName(form.path)}"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
case Left(error) => Forbidden(gitbucket.core.html.error(error))
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getNewBranchName(repository: RepositoryInfo): String = {
|
private def getNewBranchName(repository: RepositoryInfo, loginAccount: Account): String = {
|
||||||
var i = 1
|
var i = 1
|
||||||
val branchNamePrefix = cutTail(context.loginAccount.get.userName.replaceAll("[^a-zA-Z0-9-_]", "-"), 25)
|
val branchNamePrefix = cutTail(loginAccount.userName.replaceAll("[^a-zA-Z0-9-_]", "-"), 25)
|
||||||
while (repository.branchList.exists(p => p.contains(s"$branchNamePrefix-patch-$i"))) {
|
while (repository.branchList.exists(p => p.contains(s"$branchNamePrefix-patch-$i"))) {
|
||||||
i += 1
|
i += 1
|
||||||
}
|
}
|
||||||
s"$branchNamePrefix-patch-$i"
|
s"$branchNamePrefix-patch-$i"
|
||||||
}
|
}
|
||||||
|
|
||||||
private def createNewBranchForPullRequest(repository: RepositoryInfo, baseBranchName: String): String = {
|
private def createNewBranchForPullRequest(
|
||||||
val newBranchName = getNewBranchName(repository)
|
repository: RepositoryInfo,
|
||||||
|
baseBranchName: String,
|
||||||
|
loginAccount: Account
|
||||||
|
): String = {
|
||||||
|
val newBranchName = getNewBranchName(repository, loginAccount)
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JGitUtil.createBranch(git, baseBranchName, newBranchName)
|
JGitUtil.createBranch(git, baseBranchName, newBranchName)
|
||||||
}
|
}
|
||||||
|
// Call webhook
|
||||||
|
val settings = loadSystemSettings()
|
||||||
|
callWebHookOf(repository.owner, repository.name, WebHook.Create, settings) {
|
||||||
|
for {
|
||||||
|
sender <- Some(loginAccount)
|
||||||
|
owner <- getAccountByUserName(repository.owner)
|
||||||
|
} yield {
|
||||||
|
WebHookCreatePayload(
|
||||||
|
sender,
|
||||||
|
repository,
|
||||||
|
owner,
|
||||||
|
ref = newBranchName,
|
||||||
|
refType = "branch"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
newBranchName
|
newBranchName
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -568,15 +667,15 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
requestBranch: String,
|
requestBranch: String,
|
||||||
commitIdFrom: String,
|
commitIdFrom: String,
|
||||||
commitIdTo: String,
|
commitIdTo: String,
|
||||||
commitMessage: Option[String]
|
commitMessage: Option[String],
|
||||||
|
loginAccount: Account
|
||||||
): Int = {
|
): Int = {
|
||||||
val issueId = insertIssue(
|
val issueId = insertIssue(
|
||||||
owner = repository.owner,
|
owner = repository.owner,
|
||||||
repository = repository.name,
|
repository = repository.name,
|
||||||
loginUser = context.loginAccount.get.userName,
|
loginUser = loginAccount.userName,
|
||||||
title = requestBranch,
|
title = requestBranch,
|
||||||
content = commitMessage,
|
content = commitMessage,
|
||||||
assignedUserName = None,
|
|
||||||
milestoneId = None,
|
milestoneId = None,
|
||||||
priorityId = None,
|
priorityId = None,
|
||||||
isPullRequest = true
|
isPullRequest = true
|
||||||
@@ -591,7 +690,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
commitIdFrom = commitIdFrom,
|
commitIdFrom = commitIdFrom,
|
||||||
commitIdTo = commitIdTo,
|
commitIdTo = commitIdTo,
|
||||||
isDraft = false,
|
isDraft = false,
|
||||||
loginAccount = context.loginAccount.get,
|
loginAccount = loginAccount,
|
||||||
settings = context.settings
|
settings = context.settings
|
||||||
)
|
)
|
||||||
issueId
|
issueId
|
||||||
@@ -621,7 +720,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
getPathObjectId(git, path, revCommit).map {
|
getPathObjectId(git, path, revCommit).map {
|
||||||
objectId =>
|
objectId =>
|
||||||
if (raw) {
|
if (raw) {
|
||||||
// Download (This route is left for backword compatibility)
|
// Download (This route is left for backward compatibility)
|
||||||
responseRawFile(git, objectId, path, repository)
|
responseRawFile(git, objectId, path, repository)
|
||||||
} else {
|
} else {
|
||||||
val info = EditorConfigUtil.getEditorConfigInfo(git, id, path)
|
val info = EditorConfigUtil.getEditorConfigInfo(git, id, path)
|
||||||
@@ -629,7 +728,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
branch = id,
|
branch = id,
|
||||||
repository = repository,
|
repository = repository,
|
||||||
pathList = path.split("/").toList,
|
pathList = path.split("/").toList,
|
||||||
content = JGitUtil.getContentInfo(git, path, objectId),
|
content = JGitUtil.getContentInfo(git, path, objectId, repository.repository.options.safeMode),
|
||||||
latestCommit = new JGitUtil.CommitInfo(JGitUtil.getLastModifiedCommit(git, revCommit, path)),
|
latestCommit = new JGitUtil.CommitInfo(JGitUtil.getLastModifiedCommit(git, revCommit, path)),
|
||||||
hasWritePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
hasWritePermission = hasDeveloperRole(repository.owner, repository.name, context.loginAccount),
|
||||||
isBlame = request.paths(2) == "blame",
|
isBlame = request.paths(2) == "blame",
|
||||||
@@ -704,8 +803,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
try {
|
try {
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
git =>
|
git =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))) {
|
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||||
revCommit =>
|
|
||||||
val diffs = JGitUtil.getDiffs(git, None, id, true, false)
|
val diffs = JGitUtil.getDiffs(git, None, id, true, false)
|
||||||
val oldCommitId = JGitUtil.getParentCommitId(git, id)
|
val oldCommitId = JGitUtil.getParentCommitId(git, id)
|
||||||
|
|
||||||
@@ -724,7 +822,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
flash.get("error")
|
flash.get("error")
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} catch {
|
} catch {
|
||||||
case e: MissingObjectException => NotFound()
|
case e: MissingObjectException => NotFound()
|
||||||
}
|
}
|
||||||
@@ -756,11 +853,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/commit/:id/comment/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount { loginAccount =>
|
||||||
val id = params("id")
|
val id = params("id")
|
||||||
createCommitComment(
|
createCommitComment(
|
||||||
repository,
|
repository,
|
||||||
id,
|
id,
|
||||||
context.loginAccount.get,
|
loginAccount,
|
||||||
form.content,
|
form.content,
|
||||||
form.fileName,
|
form.fileName,
|
||||||
form.oldLineNumber,
|
form.oldLineNumber,
|
||||||
@@ -770,6 +868,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/commit/${id}")
|
redirect(s"/${repository.owner}/${repository.name}/commit/${id}")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/commit/:id/comment/_form")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/commit/:id/comment/_form")(readableUsersOnly { repository =>
|
||||||
@@ -791,11 +890,13 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/commit/:id/comment/_data/new", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
val id = params("id")
|
val id = params("id")
|
||||||
val commentId = createCommitComment(
|
val commentId = createCommitComment(
|
||||||
repository,
|
repository,
|
||||||
id,
|
id,
|
||||||
context.loginAccount.get,
|
loginAccount,
|
||||||
form.content,
|
form.content,
|
||||||
form.fileName,
|
form.fileName,
|
||||||
form.oldLineNumber,
|
form.oldLineNumber,
|
||||||
@@ -807,12 +908,15 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get
|
val comment = getCommitComment(repository.owner, repository.name, commentId.toString).get
|
||||||
helper.html
|
helper.html
|
||||||
.commitcomment(comment, hasDeveloperRole(repository.owner, repository.name, context.loginAccount), repository)
|
.commitcomment(comment, hasDeveloperRole(repository.owner, repository.name, context.loginAccount), repository)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository =>
|
ajaxGet("/:owner/:repository/commit_comments/_data/:id")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
getCommitComment(repository.owner, repository.name, params("id")) map {
|
getCommitComment(repository.owner, repository.name, params("id")) map {
|
||||||
x =>
|
x =>
|
||||||
if (isEditable(x.userName, x.repositoryName, x.commentedUserName)) {
|
if (isEditable(x.userName, x.repositoryName, x.commentedUserName, loginAccount)) {
|
||||||
params.get("dataType") collect {
|
params.get("dataType") collect {
|
||||||
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
case t if t == "html" => html.editcomment(x.content, x.commentId, repository)
|
||||||
} getOrElse {
|
} getOrElse {
|
||||||
@@ -835,25 +939,25 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/commit_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
ajaxPost("/:owner/:repository/commit_comments/edit/:id", commentForm)(readableUsersOnly { (form, repository) =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount {
|
||||||
case (owner, name) =>
|
loginAccount =>
|
||||||
getCommitComment(owner, name, params("id")).map { comment =>
|
getCommitComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
if (isEditable(owner, name, comment.commentedUserName)) {
|
if (isEditable(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
updateCommitComment(comment.commentId, form.content)
|
updateCommitComment(comment.commentId, form.content)
|
||||||
redirect(s"/${owner}/${name}/commit_comments/_data/${comment.commentId}")
|
redirect(s"/${repository.owner}/${repository.name}/commit_comments/_data/${comment.commentId}")
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
ajaxPost("/:owner/:repository/commit_comments/delete/:id")(readableUsersOnly { repository =>
|
ajaxPost("/:owner/:repository/commit_comments/delete/:id")(readableUsersOnly { repository =>
|
||||||
defining(repository.owner, repository.name) {
|
context.withLoginAccount { loginAccount =>
|
||||||
case (owner, name) =>
|
getCommitComment(repository.owner, repository.name, params("id")).map { comment =>
|
||||||
getCommitComment(owner, name, params("id")).map { comment =>
|
if (isEditable(repository.owner, repository.name, comment.commentedUserName, loginAccount)) {
|
||||||
if (isEditable(owner, name, comment.commentedUserName)) {
|
|
||||||
Ok(deleteCommitComment(comment.commentId))
|
Ok(deleteCommitComment(comment.commentId))
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
@@ -924,11 +1028,47 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
post("/:owner/:repository/branches")(writableUsersOnly { repository =>
|
||||||
val newBranchName = params.getOrElse("new", halt(400))
|
val newBranchName = params.getOrElse("new", halt(400))
|
||||||
val fromBranchName = params.getOrElse("from", halt(400))
|
val fromBranchName = params.getOrElse("from", halt(400))
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) {
|
||||||
JGitUtil.createBranch(git, fromBranchName, newBranchName)
|
git =>
|
||||||
} match {
|
JGitUtil.createBranch(git, fromBranchName, newBranchName) match {
|
||||||
case Right(message) =>
|
case Right(message) =>
|
||||||
flash.update("info", message)
|
flash.update("info", message)
|
||||||
|
val settings = loadSystemSettings()
|
||||||
|
val newCommitId = git.getRepository.resolve(s"refs/heads/${newBranchName}")
|
||||||
|
val oldCommitId = ObjectId.fromString("0" * 40)
|
||||||
|
// call push webhook
|
||||||
|
callWebHookOf(repository.owner, repository.name, WebHook.Push, settings) {
|
||||||
|
for {
|
||||||
|
pusherAccount <- context.loginAccount
|
||||||
|
ownerAccount <- getAccountByUserName(repository.owner)
|
||||||
|
} yield {
|
||||||
|
WebHookPushPayload(
|
||||||
|
git,
|
||||||
|
pusherAccount,
|
||||||
|
newBranchName,
|
||||||
|
repository,
|
||||||
|
List(),
|
||||||
|
ownerAccount,
|
||||||
|
newId = newCommitId,
|
||||||
|
oldId = oldCommitId
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// call create webhook
|
||||||
|
callWebHookOf(repository.owner, repository.name, WebHook.Create, settings) {
|
||||||
|
for {
|
||||||
|
sender <- context.loginAccount
|
||||||
|
owner <- getAccountByUserName(repository.owner)
|
||||||
|
} yield {
|
||||||
|
WebHookCreatePayload(
|
||||||
|
sender,
|
||||||
|
repository,
|
||||||
|
owner,
|
||||||
|
ref = newBranchName,
|
||||||
|
refType = "branch"
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
redirect(
|
redirect(
|
||||||
s"/${repository.owner}/${repository.name}/tree/${StringUtil.urlEncode(newBranchName).replace("%2F", "/")}"
|
s"/${repository.owner}/${repository.name}/tree/${StringUtil.urlEncode(newBranchName).replace("%2F", "/")}"
|
||||||
)
|
)
|
||||||
@@ -936,22 +1076,26 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
flash.update("error", message)
|
flash.update("error", message)
|
||||||
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
redirect(s"/${repository.owner}/${repository.name}/tree/${fromBranchName}")
|
||||||
}
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Deletes branch.
|
* Deletes branch.
|
||||||
*/
|
*/
|
||||||
get("/:owner/:repository/delete/*")(writableUsersOnly { repository =>
|
get("/:owner/:repository/delete/*")(writableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
val branchName = multiParams("splat").head
|
val branchName = multiParams("splat").head
|
||||||
val userName = context.loginAccount.get.userName
|
|
||||||
if (repository.repository.defaultBranch != branchName) {
|
if (repository.repository.defaultBranch != branchName) {
|
||||||
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
git.branchDelete().setForce(true).setBranchNames(branchName).call()
|
git.branchDelete().setForce(true).setBranchNames(branchName).call()
|
||||||
val deleteBranchInfo = DeleteBranchInfo(repository.owner, repository.name, userName, branchName)
|
val deleteBranchInfo =
|
||||||
|
DeleteBranchInfo(repository.owner, repository.name, loginAccount.userName, branchName)
|
||||||
recordActivity(deleteBranchInfo)
|
recordActivity(deleteBranchInfo)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
redirect(s"/${repository.owner}/${repository.name}/branches")
|
redirect(s"/${repository.owner}/${repository.name}/branches")
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -1037,7 +1181,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
// get specified commit
|
// get specified commit
|
||||||
JGitUtil.getDefaultBranch(git, repository, revstr).map {
|
JGitUtil.getDefaultBranch(git, repository, revstr).map {
|
||||||
case (objectId, revision) =>
|
case (objectId, revision) =>
|
||||||
defining(JGitUtil.getRevCommitFromId(git, objectId)) { revCommit =>
|
val revCommit = JGitUtil.getRevCommitFromId(git, objectId)
|
||||||
val lastModifiedCommit =
|
val lastModifiedCommit =
|
||||||
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
if (path == ".") revCommit else JGitUtil.getLastModifiedCommit(git, revCommit, path)
|
||||||
val commitCount = JGitUtil.getCommitCount(git, lastModifiedCommit.getName)
|
val commitCount = JGitUtil.getCommitCount(git, lastModifiedCommit.getName)
|
||||||
@@ -1084,7 +1228,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
flash.get("info"),
|
flash.get("info"),
|
||||||
flash.get("error")
|
flash.get("error")
|
||||||
)
|
)
|
||||||
}
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1115,10 +1258,12 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
if (treeWalk != null) {
|
if (treeWalk != null) {
|
||||||
while (treeWalk.next()) {
|
while (treeWalk.next()) {
|
||||||
|
if (treeWalk.getFileMode != FileMode.GITLINK) {
|
||||||
val entryPath =
|
val entryPath =
|
||||||
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
if (path.isEmpty) baseName + "/" + treeWalk.getPathString
|
||||||
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
else path.split("/").last + treeWalk.getPathString.substring(path.length)
|
||||||
val mode = treeWalk.getFileMode.getBits
|
val mode = treeWalk.getFileMode.getBits
|
||||||
|
|
||||||
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
|
JGitUtil.openFile(git, repository, commit.getTree, treeWalk.getPathString) { in =>
|
||||||
val tempFile = File.createTempFile("gitbucket", ".archive")
|
val tempFile = File.createTempFile("gitbucket", ".archive")
|
||||||
val size = Using.resource(new FileOutputStream(tempFile)) { out =>
|
val size = Using.resource(new FileOutputStream(tempFile)) { out =>
|
||||||
@@ -1149,6 +1294,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val suffix =
|
val suffix =
|
||||||
path.split("/").lastOption.collect { case x if x.length > 0 => "-" + x.replace('/', '_') }.getOrElse("")
|
path.split("/").lastOption.collect { case x if x.length > 0 => "-" + x.replace('/', '_') }.getOrElse("")
|
||||||
@@ -1204,8 +1350,9 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
private def isEditable(owner: String, repository: String, author: String, loginAccount: Account): Boolean = {
|
||||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
hasDeveloperRole(owner, repository, Some(loginAccount)) || author == loginAccount.userName
|
||||||
|
}
|
||||||
|
|
||||||
private def conflict: Constraint = new Constraint() {
|
private def conflict: 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] = {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package gitbucket.core.controller
|
package gitbucket.core.controller
|
||||||
|
|
||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
|
|
||||||
import gitbucket.core.admin.html
|
import gitbucket.core.admin.html
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
import gitbucket.core.plugin.PluginRegistry
|
||||||
import gitbucket.core.service.SystemSettingsService._
|
import gitbucket.core.service.SystemSettingsService._
|
||||||
@@ -9,7 +8,6 @@ import gitbucket.core.service.{AccountService, RepositoryService}
|
|||||||
import gitbucket.core.ssh.SshServer
|
import gitbucket.core.ssh.SshServer
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.StringUtil._
|
import gitbucket.core.util.StringUtil._
|
||||||
import gitbucket.core.util.SyntaxSugars._
|
|
||||||
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
import gitbucket.core.util.{AdminAuthenticator, Mailer}
|
||||||
import org.apache.commons.io.IOUtils
|
import org.apache.commons.io.IOUtils
|
||||||
import org.apache.commons.mail.EmailException
|
import org.apache.commons.mail.EmailException
|
||||||
@@ -36,7 +34,9 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
private val form = mapping(
|
private val form = mapping(
|
||||||
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
"baseUrl" -> trim(label("Base URL", optional(text()))),
|
||||||
"information" -> trim(label("Information", optional(text()))),
|
"information" -> trim(label("Information", optional(text()))),
|
||||||
|
"basicBehavior" -> mapping(
|
||||||
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
"allowAccountRegistration" -> trim(label("Account registration", boolean())),
|
||||||
|
"allowResetPassword" -> trim(label("Reset password", boolean())),
|
||||||
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
"allowAnonymousAccess" -> trim(label("Anonymous access", boolean())),
|
||||||
"isCreateRepoOptionPublic" -> trim(label("Default visibility of new repository", boolean())),
|
"isCreateRepoOptionPublic" -> trim(label("Default visibility of new repository", boolean())),
|
||||||
"repositoryOperation" -> mapping(
|
"repositoryOperation" -> mapping(
|
||||||
@@ -49,10 +49,23 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
"gravatar" -> trim(label("Gravatar", boolean())),
|
"gravatar" -> trim(label("Gravatar", boolean())),
|
||||||
"notification" -> trim(label("Notification", boolean())),
|
"notification" -> trim(label("Notification", boolean())),
|
||||||
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
"limitVisibleRepositories" -> trim(label("limitVisibleRepositories", boolean())),
|
||||||
|
)(BasicBehavior.apply),
|
||||||
"ssh" -> mapping(
|
"ssh" -> mapping(
|
||||||
"enabled" -> trim(label("SSH access", boolean())),
|
"enabled" -> trim(label("SSH access", boolean())),
|
||||||
"host" -> trim(label("SSH host", optional(text()))),
|
"bindAddress" -> mapping(
|
||||||
"port" -> trim(label("SSH port", optional(number())))
|
"host" -> trim(label("Bind SSH host", optional(text()))),
|
||||||
|
"port" -> trim(label("Bind SSH port", optional(number()))),
|
||||||
|
)(
|
||||||
|
(hostOption, portOption) =>
|
||||||
|
hostOption.map(h => SshAddress(h, portOption.getOrElse(DefaultSshPort), GenericSshUser))
|
||||||
|
),
|
||||||
|
"publicAddress" -> mapping(
|
||||||
|
"host" -> trim(label("Public SSH host", optional(text()))),
|
||||||
|
"port" -> trim(label("Public SSH port", optional(number()))),
|
||||||
|
)(
|
||||||
|
(hostOption, portOption) =>
|
||||||
|
hostOption.map(h => SshAddress(h, portOption.getOrElse(PublicSshPort), GenericSshUser))
|
||||||
|
),
|
||||||
)(Ssh.apply),
|
)(Ssh.apply),
|
||||||
"useSMTP" -> trim(label("SMTP", boolean())),
|
"useSMTP" -> trim(label("SMTP", boolean())),
|
||||||
"smtp" -> optionalIfNotChecked(
|
"smtp" -> optionalIfNotChecked(
|
||||||
@@ -117,8 +130,8 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
if (settings.ssh.enabled && settings.baseUrl.isEmpty) {
|
||||||
Some("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
Some("baseUrl" -> "Base URL is required if SSH access is enabled.")
|
||||||
} else None,
|
} else None,
|
||||||
if (settings.ssh.enabled && settings.ssh.sshHost.isEmpty) {
|
if (settings.ssh.enabled && settings.ssh.bindAddress.isEmpty) {
|
||||||
Some("sshHost" -> "SSH host is required if SSH access is enabled.")
|
Some("ssh.bindAddress.host" -> "SSH bind host is required if SSH access is enabled.")
|
||||||
} else None
|
} else None
|
||||||
).flatten
|
).flatten
|
||||||
}
|
}
|
||||||
@@ -187,7 +200,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val newUserForm = mapping(
|
val newUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier, uniqueUserName, reservedNames))),
|
||||||
"password" -> trim(label("Password", text(required, maxlength(20)))),
|
"password" -> trim(label("Password", text(required, maxlength(40)))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress()))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -201,7 +214,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
val editUserForm = mapping(
|
val editUserForm = mapping(
|
||||||
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
"userName" -> trim(label("Username", text(required, maxlength(100), identifier))),
|
||||||
"password" -> trim(label("Password", optional(text(maxlength(20))))),
|
"password" -> trim(label("Password", optional(text(maxlength(40))))),
|
||||||
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
"fullName" -> trim(label("Full Name", text(required, maxlength(100)))),
|
||||||
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
"mailAddress" -> trim(label("Mail Address", text(required, maxlength(100), uniqueMailAddress("userName")))),
|
||||||
"extraMailAddresses" -> list(
|
"extraMailAddresses" -> list(
|
||||||
@@ -309,12 +322,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
post("/admin/system", form)(adminOnly { form =>
|
post("/admin/system", form)(adminOnly { form =>
|
||||||
saveSystemSettings(form)
|
saveSystemSettings(form)
|
||||||
|
|
||||||
if (form.sshAddress != context.settings.sshAddress) {
|
if (form.ssh.bindAddress != context.settings.sshBindAddress || form.ssh.publicAddress != context.settings.sshPublicAddress) {
|
||||||
SshServer.stop()
|
SshServer.stop()
|
||||||
for {
|
for {
|
||||||
sshAddress <- form.sshAddress
|
bindAddress <- form.ssh.bindAddress
|
||||||
|
publicAddress <- form.ssh.publicAddress.orElse(form.ssh.bindAddress)
|
||||||
baseUrl <- form.baseUrl
|
baseUrl <- form.baseUrl
|
||||||
} SshServer.start(sshAddress, baseUrl)
|
} SshServer.start(bindAddress, publicAddress, baseUrl)
|
||||||
}
|
}
|
||||||
|
|
||||||
flash.update("info", "System settings has been updated.")
|
flash.update("info", "System settings has been updated.")
|
||||||
@@ -323,7 +337,12 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
|
|
||||||
post("/admin/system/sendmail", sendMailForm)(adminOnly { form =>
|
post("/admin/system/sendmail", sendMailForm)(adminOnly { form =>
|
||||||
try {
|
try {
|
||||||
new Mailer(context.settings.copy(smtp = Some(form.smtp), notification = true)).send(
|
new Mailer(
|
||||||
|
context.settings.copy(
|
||||||
|
smtp = Some(form.smtp),
|
||||||
|
basicBehavior = context.settings.basicBehavior.copy(notification = true)
|
||||||
|
)
|
||||||
|
).send(
|
||||||
to = form.testAddress,
|
to = form.testAddress,
|
||||||
subject = "Test message from GitBucket",
|
subject = "Test message from GitBucket",
|
||||||
textMsg = "This is a test message from GitBucket.",
|
textMsg = "This is a test message from GitBucket.",
|
||||||
@@ -362,8 +381,8 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users")(adminOnly {
|
get("/admin/users")(adminOnly {
|
||||||
val includeRemoved = params.get("includeRemoved").map(_.toBoolean).getOrElse(false)
|
val includeRemoved = params.get("includeRemoved").exists(_.toBoolean)
|
||||||
val includeGroups = params.get("includeGroups").map(_.toBoolean).getOrElse(false)
|
val includeGroups = params.get("includeGroups").exists(_.toBoolean)
|
||||||
val users = getAllUsers(includeRemoved, includeGroups)
|
val users = getAllUsers(includeRemoved, includeGroups)
|
||||||
val members = users.collect {
|
val members = users.collect {
|
||||||
case account if (account.isGroupAccount) =>
|
case account if (account.isGroupAccount) =>
|
||||||
@@ -463,15 +482,13 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
get("/admin/users/:groupName/_editgroup")(adminOnly {
|
||||||
defining(params("groupName")) { groupName =>
|
val groupName = params("groupName")
|
||||||
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
html.usergroup(getAccountByUserName(groupName, true), getGroupMembers(groupName))
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
post("/admin/users/:groupName/_editgroup", editGroupForm)(adminOnly { form =>
|
||||||
defining(
|
val groupName = params("groupName")
|
||||||
params("groupName"),
|
val members = form.members
|
||||||
form.members
|
|
||||||
.split(",")
|
.split(",")
|
||||||
.map {
|
.map {
|
||||||
_.split(":") match {
|
_.split(":") match {
|
||||||
@@ -479,8 +496,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
.toList
|
.toList
|
||||||
) {
|
|
||||||
case (groupName, members) =>
|
|
||||||
getAccountByUserName(groupName, true).map {
|
getAccountByUserName(groupName, true).map {
|
||||||
account =>
|
account =>
|
||||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||||
@@ -511,7 +527,6 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
redirect("/admin/users")
|
redirect("/admin/users")
|
||||||
|
|
||||||
} getOrElse NotFound()
|
} getOrElse NotFound()
|
||||||
}
|
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/admin/data")(adminOnly {
|
get("/admin/data")(adminOnly {
|
||||||
@@ -559,12 +574,11 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
|||||||
protected def disableByNotYourself(paramName: String): Constraint =
|
protected def disableByNotYourself(paramName: String): Constraint =
|
||||||
new Constraint() {
|
new Constraint() {
|
||||||
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
params.get(paramName).flatMap { userName =>
|
for {
|
||||||
if (userName == context.loginAccount.get.userName && params.get("removed") == Some("true"))
|
userName <- params.get(paramName)
|
||||||
Some("You can't disable your account yourself")
|
loginAccount <- context.loginAccount
|
||||||
else
|
if userName == loginAccount.userName && params.get("removed") == Some("true")
|
||||||
None
|
} yield "You can't disable your account yourself"
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -136,11 +136,13 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, Some(pageName))) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, Some(pageName))) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}")
|
||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
@@ -149,19 +151,23 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/_revert/:commitId")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||||
|
|
||||||
if (revertWikiPage(repository.owner, repository.name, from, to, context.loginAccount.get, None)) {
|
if (revertWikiPage(repository.owner, repository.name, from, to, loginAccount, None)) {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
} else {
|
} else {
|
||||||
flash.update("info", "This patch was not able to be reversed.")
|
flash.update("info", "This patch was not able to be reversed.")
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
redirect(s"/${repository.owner}/${repository.name}/wiki/_compare/${from}...${to}")
|
||||||
}
|
}
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_edit")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_edit")(readableUsersOnly { repository =>
|
||||||
@@ -172,9 +178,9 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
||||||
if (isEditable(repository)) {
|
context.withLoginAccount {
|
||||||
defining(context.loginAccount.get) {
|
|
||||||
loginAccount =>
|
loginAccount =>
|
||||||
|
if (isEditable(repository)) {
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -201,8 +207,8 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
||||||
@@ -212,9 +218,9 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
})
|
})
|
||||||
|
|
||||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||||
if (isEditable(repository)) {
|
context.withLoginAccount {
|
||||||
defining(context.loginAccount.get) {
|
|
||||||
loginAccount =>
|
loginAccount =>
|
||||||
|
if (isEditable(repository)) {
|
||||||
saveWikiPage(
|
saveWikiPage(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -242,15 +248,23 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
} else {
|
} else {
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
}
|
}
|
||||||
}
|
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
if (isEditable(repository)) {
|
if (isEditable(repository)) {
|
||||||
val pageName = StringUtil.urlDecode(params("page"))
|
val pageName = StringUtil.urlDecode(params("page"))
|
||||||
|
deleteWikiPage(
|
||||||
defining(context.loginAccount.get) { loginAccount =>
|
repository.owner,
|
||||||
|
repository.name,
|
||||||
|
pageName,
|
||||||
|
loginAccount.fullName,
|
||||||
|
loginAccount.mailAddress,
|
||||||
|
s"Destroyed ${pageName}"
|
||||||
|
)
|
||||||
val deleteWikiInfo = DeleteWikiInfo(
|
val deleteWikiInfo = DeleteWikiInfo(
|
||||||
repository.owner,
|
repository.owner,
|
||||||
repository.name,
|
repository.name,
|
||||||
@@ -261,8 +275,8 @@ trait WikiControllerBase extends ControllerBase {
|
|||||||
updateLastActivityDate(repository.owner, repository.name)
|
updateLastActivityDate(repository.owner, repository.name)
|
||||||
|
|
||||||
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
redirect(s"/${repository.owner}/${repository.name}/wiki")
|
||||||
}
|
|
||||||
} else Unauthorized()
|
} else Unauthorized()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiObject, ApiRef, CreateARef, JsonFormat, UpdateARef}
|
import gitbucket.core.api.{ApiError, ApiRef, CreateARef, JsonFormat, UpdateARef}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.ReferrerAuthenticator
|
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
import gitbucket.core.util.{ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.lib.ObjectId
|
import org.eclipse.jgit.lib.ObjectId
|
||||||
import org.eclipse.jgit.lib.RefUpdate.Result
|
import org.eclipse.jgit.lib.RefUpdate.Result
|
||||||
@@ -14,47 +15,38 @@ import scala.jdk.CollectionConverters._
|
|||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
|
||||||
trait ApiGitReferenceControllerBase extends ControllerBase {
|
trait ApiGitReferenceControllerBase extends ControllerBase {
|
||||||
self: ReferrerAuthenticator =>
|
self: ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||||
|
|
||||||
private val logger = LoggerFactory.getLogger(classOf[ApiGitReferenceControllerBase])
|
private val logger = LoggerFactory.getLogger(classOf[ApiGitReferenceControllerBase])
|
||||||
|
|
||||||
|
get("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { repository =>
|
||||||
|
val result = Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
|
val refs = git
|
||||||
|
.getRepository()
|
||||||
|
.getRefDatabase()
|
||||||
|
.getRefsByPrefix("refs")
|
||||||
|
.asScala
|
||||||
|
|
||||||
|
refs.map(ApiRef.fromRef(RepositoryName(s"${repository.owner}/${repository.name}"), _))
|
||||||
|
}
|
||||||
|
JsonFormat(result)
|
||||||
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* i. Get a reference
|
* i. Get a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#get-a-reference
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/git/ref/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/git/ref/*")(referrersOnly { repository =>
|
||||||
getRef()
|
val revstr = multiParams("splat").head
|
||||||
|
getRef(revstr, repository)
|
||||||
})
|
})
|
||||||
|
|
||||||
// Some versions of GHE support this path
|
// Some versions of GHE support this path
|
||||||
get("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { repository =>
|
||||||
logger.warn("git/refs/ endpoint may not be compatible with GitHub API v3. Consider using git/ref/ endpoint instead")
|
logger.warn("git/refs/ endpoint may not be compatible with GitHub API v3. Consider using git/ref/ endpoint instead")
|
||||||
getRef()
|
|
||||||
})
|
|
||||||
|
|
||||||
private def getRef() = {
|
|
||||||
val revstr = multiParams("splat").head
|
val revstr = multiParams("splat").head
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
getRef(revstr, repository)
|
||||||
val ref = git.getRepository().findRef(revstr)
|
|
||||||
|
|
||||||
if (ref != null) {
|
|
||||||
val sha = ref.getObjectId().name()
|
|
||||||
JsonFormat(ApiRef(revstr, ApiObject(sha)))
|
|
||||||
|
|
||||||
} else {
|
|
||||||
val refs = git
|
|
||||||
.getRepository()
|
|
||||||
.getRefDatabase()
|
|
||||||
.getRefsByPrefix("refs/")
|
|
||||||
.asScala
|
|
||||||
|
|
||||||
JsonFormat(refs.map { ref =>
|
|
||||||
val sha = ref.getObjectId().name()
|
|
||||||
ApiRef(revstr, ApiObject(sha))
|
|
||||||
})
|
})
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ii. Get all references
|
* ii. Get all references
|
||||||
@@ -65,17 +57,17 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
* iii. Create a reference
|
* iii. Create a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#create-a-reference
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { _ =>
|
post("/api/v3/repos/:owner/:repository/git/refs")(referrersOnly { repository =>
|
||||||
extractFromJsonBody[CreateARef].map {
|
extractFromJsonBody[CreateARef].map {
|
||||||
data =>
|
data =>
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.owner))) { git =>
|
||||||
val ref = git.getRepository.findRef(data.ref)
|
val ref = git.getRepository.findRef(data.ref)
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
val update = git.getRepository.updateRef(data.ref)
|
val update = git.getRepository.updateRef(data.ref)
|
||||||
update.setNewObjectId(ObjectId.fromString(data.sha))
|
update.setNewObjectId(ObjectId.fromString(data.sha))
|
||||||
val result = update.update()
|
val result = update.update()
|
||||||
result match {
|
result match {
|
||||||
case Result.NEW => JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
case Result.NEW => JsonFormat(ApiRef.fromRef(RepositoryName(repository.owner, repository.name), ref))
|
||||||
case _ => UnprocessableEntity(result.name())
|
case _ => UnprocessableEntity(result.name())
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
@@ -89,11 +81,11 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
* iv. Update a reference
|
* iv. Update a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#update-a-reference
|
||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { _ =>
|
patch("/api/v3/repos/:owner/:repository/git/refs/*")(writableUsersOnly { repository =>
|
||||||
val refName = multiParams("splat").mkString("/")
|
val refName = multiParams("splat").mkString("/")
|
||||||
extractFromJsonBody[UpdateARef].map {
|
extractFromJsonBody[UpdateARef].map {
|
||||||
data =>
|
data =>
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.owner))) { git =>
|
||||||
val ref = git.getRepository.findRef(refName)
|
val ref = git.getRepository.findRef(refName)
|
||||||
if (ref == null) {
|
if (ref == null) {
|
||||||
UnprocessableEntity("Ref does not exist.")
|
UnprocessableEntity("Ref does not exist.")
|
||||||
@@ -104,7 +96,7 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
val result = update.update()
|
val result = update.update()
|
||||||
result match {
|
result match {
|
||||||
case Result.FORCED | Result.FAST_FORWARD | Result.NO_CHANGE =>
|
case Result.FORCED | Result.FAST_FORWARD | Result.NO_CHANGE =>
|
||||||
JsonFormat(ApiRef(update.getName, ApiObject(update.getNewObjectId.getName)))
|
JsonFormat(ApiRef.fromRef(RepositoryName(repository), update.getRef))
|
||||||
case _ => UnprocessableEntity(result.name())
|
case _ => UnprocessableEntity(result.name())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,7 +108,7 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
* v. Delete a reference
|
* v. Delete a reference
|
||||||
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#delete-a-reference
|
* https://docs.github.com/en/free-pro-team@latest/rest/reference/git#delete-a-reference
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/git/refs/*")(referrersOnly { _ =>
|
delete("/api/v3/repos/:owner/:repository/git/refs/*")(writableUsersOnly { _ =>
|
||||||
val refName = multiParams("splat").mkString("/")
|
val refName = multiParams("splat").mkString("/")
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
val ref = git.getRepository.findRef(refName)
|
val ref = git.getRepository.findRef(refName)
|
||||||
@@ -133,4 +125,34 @@ trait ApiGitReferenceControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
private def notFound(): ApiError = {
|
||||||
|
response.setStatus(404)
|
||||||
|
ApiError("Not Found")
|
||||||
|
}
|
||||||
|
|
||||||
|
protected def getRef(revstr: String, repository: RepositoryInfo): AnyRef = {
|
||||||
|
logger.debug(s"getRef: path '${revstr}'")
|
||||||
|
|
||||||
|
val name = RepositoryName(repository)
|
||||||
|
val result = JsonFormat(revstr match {
|
||||||
|
case "tags" => repository.tags.map(ApiRef.fromTag(name, _))
|
||||||
|
case x if x.startsWith("tags/") =>
|
||||||
|
val tagName = x.substring("tags/".length)
|
||||||
|
repository.tags.find(_.name == tagName) match {
|
||||||
|
case Some(tagInfo) => ApiRef.fromTag(name, tagInfo)
|
||||||
|
case None => notFound()
|
||||||
|
}
|
||||||
|
case other =>
|
||||||
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
|
git.getRepository().findRef(other) match {
|
||||||
|
case null => notFound()
|
||||||
|
case ref => ApiRef.fromRef(name, ref)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
logger.debug(s"json result: $result")
|
||||||
|
result
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import gitbucket.core.controller.{Context, ControllerBase}
|
|||||||
import gitbucket.core.service._
|
import gitbucket.core.service._
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
||||||
import org.scalatra.{ActionResult, NoContent}
|
import org.scalatra.ActionResult
|
||||||
|
|
||||||
trait ApiIssueCommentControllerBase extends ControllerBase {
|
trait ApiIssueCommentControllerBase extends ControllerBase {
|
||||||
self: AccountService
|
self: AccountService
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ import gitbucket.core.model.{Account, Issue}
|
|||||||
import gitbucket.core.service.{AccountService, IssueCreationService, IssuesService, MilestonesService}
|
import gitbucket.core.service.{AccountService, IssueCreationService, IssuesService, MilestonesService}
|
||||||
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
||||||
import gitbucket.core.service.PullRequestService.PullRequestLimit
|
import gitbucket.core.service.PullRequestService.PullRequestLimit
|
||||||
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName, UsersAuthenticator}
|
import gitbucket.core.util.{ReadableUsersAuthenticator, ReferrerAuthenticator, RepositoryName}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
|
||||||
trait ApiIssueControllerBase extends ControllerBase {
|
trait ApiIssueControllerBase extends ControllerBase {
|
||||||
@@ -29,9 +29,9 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
val page = IssueSearchCondition.page(request)
|
val page = IssueSearchCondition.page(request)
|
||||||
// TODO: more api spec condition
|
// TODO: more api spec condition
|
||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
val baseOwner = getAccountByUserName(repository.owner).get
|
//val baseOwner = getAccountByUserName(repository.owner).get
|
||||||
|
|
||||||
val issues: List[(Issue, Account, Option[Account])] =
|
val issues: List[(Issue, Account, List[Account])] =
|
||||||
searchIssueByApi(
|
searchIssueByApi(
|
||||||
condition = condition,
|
condition = condition,
|
||||||
offset = (page - 1) * PullRequestLimit,
|
offset = (page - 1) * PullRequestLimit,
|
||||||
@@ -40,14 +40,15 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
JsonFormat(issues.map {
|
JsonFormat(issues.map {
|
||||||
case (issue, issueUser, assignedUser) =>
|
case (issue, issueUser, assigneeUsers) =>
|
||||||
ApiIssue(
|
ApiIssue(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
repositoryName = RepositoryName(repository),
|
repositoryName = RepositoryName(repository),
|
||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
assignee = assignedUser.map(ApiUser(_)),
|
assignees = assigneeUsers.map(ApiUser(_)),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository)))
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
|
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
@@ -60,7 +61,8 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
(for {
|
(for {
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
issue <- getIssue(repository.owner, repository.name, issueId.toString)
|
||||||
users = getAccountsByUserNames(Set(issue.openedUserName) ++ issue.assignedUserName, Set())
|
assigneeUsers = getIssueAssignees(repository.owner, repository.name, issueId)
|
||||||
|
users = getAccountsByUserNames(Set(issue.openedUserName) ++ assigneeUsers.map(_.assigneeUserName), Set())
|
||||||
openedUser <- users.get(issue.openedUserName)
|
openedUser <- users.get(issue.openedUserName)
|
||||||
} yield {
|
} yield {
|
||||||
JsonFormat(
|
JsonFormat(
|
||||||
@@ -68,8 +70,9 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
issue,
|
issue,
|
||||||
RepositoryName(repository),
|
RepositoryName(repository),
|
||||||
ApiUser(openedUser),
|
ApiUser(openedUser),
|
||||||
issue.assignedUserName.flatMap(users.get(_)).map(ApiUser(_)),
|
assigneeUsers.flatMap(x => users.get(x.assigneeUserName)).map(ApiUser(_)),
|
||||||
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository)))
|
getIssueLabels(repository.owner, repository.name, issue.issueId).map(ApiLabel(_, RepositoryName(repository))),
|
||||||
|
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
@@ -90,7 +93,7 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
repository,
|
repository,
|
||||||
data.title,
|
data.title,
|
||||||
data.body,
|
data.body,
|
||||||
data.assignees.headOption,
|
data.assignees,
|
||||||
milestone.map(_.milestoneId),
|
milestone.map(_.milestoneId),
|
||||||
None,
|
None,
|
||||||
data.labels,
|
data.labels,
|
||||||
@@ -101,9 +104,12 @@ trait ApiIssueControllerBase extends ControllerBase {
|
|||||||
issue,
|
issue,
|
||||||
RepositoryName(repository),
|
RepositoryName(repository),
|
||||||
ApiUser(loginAccount),
|
ApiUser(loginAccount),
|
||||||
issue.assignedUserName.flatMap(getAccountByUserName(_)).map(ApiUser(_)),
|
getIssueAssignees(repository.owner, repository.name, issue.issueId)
|
||||||
|
.flatMap(x => getAccountByUserName(x.assigneeUserName, false))
|
||||||
|
.map(ApiUser.apply),
|
||||||
getIssueLabels(repository.owner, repository.name, issue.issueId)
|
getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository)))
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
|
issue.milestoneId.flatMap { getApiMilestone(repository, _) }
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[Seq[String]];
|
data <- extractFromJsonBody[Seq[String]]
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
} yield {
|
} yield {
|
||||||
data.map { labelName =>
|
data.map { labelName =>
|
||||||
@@ -160,7 +160,7 @@ trait ApiIssueLabelControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
put("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/issues/:id/labels")(writableUsersOnly { repository =>
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[Seq[String]];
|
data <- extractFromJsonBody[Seq[String]]
|
||||||
issueId <- params("id").toIntOpt
|
issueId <- params("id").toIntOpt
|
||||||
} yield {
|
} yield {
|
||||||
deleteAllIssueLabels(repository.owner, repository.name, issueId, true)
|
deleteAllIssueLabels(repository.owner, repository.name, issueId, true)
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package gitbucket.core.controller.api
|
|||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.MilestonesService
|
import gitbucket.core.service.MilestonesService
|
||||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
|
||||||
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
import gitbucket.core.util.{ReferrerAuthenticator, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import org.scalatra.NoContent
|
import org.scalatra.NoContent
|
||||||
@@ -102,17 +101,4 @@ trait ApiIssueMilestoneControllerBase extends ControllerBase {
|
|||||||
NoContent()
|
NoContent()
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getApiMilestone(repository: RepositoryInfo, milestoneId: Int): Option[ApiMilestone] = {
|
|
||||||
getMilestonesWithIssueCount(repository.owner, repository.name)
|
|
||||||
.find(p => p._1.milestoneId == milestoneId)
|
|
||||||
.map(
|
|
||||||
milestoneWithIssue =>
|
|
||||||
ApiMilestone(
|
|
||||||
repository.repository,
|
|
||||||
milestoneWithIssue._1,
|
|
||||||
milestoneWithIssue._2,
|
|
||||||
milestoneWithIssue._3
|
|
||||||
)
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiGroup, CreateAGroup, ApiRepository, ApiUser, JsonFormat}
|
import gitbucket.core.api.{ApiGroup, CreateAGroup, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
val condition = IssueSearchCondition(request)
|
val condition = IssueSearchCondition(request)
|
||||||
val baseOwner = getAccountByUserName(repository.owner).get
|
val baseOwner = getAccountByUserName(repository.owner).get
|
||||||
|
|
||||||
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, Option[Account])] =
|
val issues: List[(Issue, Account, Int, PullRequest, Repository, Account, List[Account])] =
|
||||||
searchPullRequestByApi(
|
searchPullRequestByApi(
|
||||||
condition = condition,
|
condition = condition,
|
||||||
offset = (page - 1) * PullRequestLimit,
|
offset = (page - 1) * PullRequestLimit,
|
||||||
@@ -49,7 +49,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
)
|
)
|
||||||
|
|
||||||
JsonFormat(issues.map {
|
JsonFormat(issues.map {
|
||||||
case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignee) =>
|
case (issue, issueUser, commentCount, pullRequest, headRepo, headOwner, assignees) =>
|
||||||
ApiPullRequest(
|
ApiPullRequest(
|
||||||
issue = issue,
|
issue = issue,
|
||||||
pullRequest = pullRequest,
|
pullRequest = pullRequest,
|
||||||
@@ -58,7 +58,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository))),
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
assignee = assignee.map(ApiUser.apply),
|
assignees = assignees.map(ApiUser.apply),
|
||||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@@ -99,7 +99,6 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
loginUser = context.loginAccount.get.userName,
|
loginUser = context.loginAccount.get.userName,
|
||||||
title = createPullReq.title,
|
title = createPullReq.title,
|
||||||
content = createPullReq.body,
|
content = createPullReq.body,
|
||||||
assignedUserName = None,
|
|
||||||
milestoneId = None,
|
milestoneId = None,
|
||||||
priorityId = None,
|
priorityId = None,
|
||||||
isPullRequest = true
|
isPullRequest = true
|
||||||
@@ -230,9 +229,9 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
if (checkConflict(repository.owner, repository.name, pullReq.branch, issueId).isDefined) {
|
||||||
NoContent
|
NoContent
|
||||||
} else {
|
} else {
|
||||||
NotFound
|
NotFound()
|
||||||
}
|
}
|
||||||
}).getOrElse(NotFound)
|
}).getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -319,8 +318,8 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
baseOwner <- users.get(repository.owner)
|
baseOwner <- users.get(repository.owner)
|
||||||
headOwner <- users.get(pullRequest.requestUserName)
|
headOwner <- users.get(pullRequest.requestUserName)
|
||||||
issueUser <- users.get(issue.openedUserName)
|
issueUser <- users.get(issue.openedUserName)
|
||||||
assignee = issue.assignedUserName.flatMap { userName =>
|
assignees = getIssueAssignees(repository.owner, repository.name, issueId).flatMap { assignedUser =>
|
||||||
getAccountByUserName(userName, false)
|
getAccountByUserName(assignedUser.assigneeUserName, false)
|
||||||
}
|
}
|
||||||
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
|
headRepo <- getRepository(pullRequest.requestUserName, pullRequest.requestRepositoryName)
|
||||||
} yield {
|
} yield {
|
||||||
@@ -332,7 +331,7 @@ trait ApiPullRequestControllerBase extends ControllerBase {
|
|||||||
user = ApiUser(issueUser),
|
user = ApiUser(issueUser),
|
||||||
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
labels = getIssueLabels(repository.owner, repository.name, issue.issueId)
|
||||||
.map(ApiLabel(_, RepositoryName(repository))),
|
.map(ApiLabel(_, RepositoryName(repository))),
|
||||||
assignee = assignee.map(ApiUser.apply),
|
assignees = assignees.map(ApiUser.apply),
|
||||||
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
mergedComment = getMergedComment(repository.owner, repository.name, issue.issueId)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import java.io.{ByteArrayInputStream, File}
|
import java.io.File
|
||||||
|
|
||||||
import gitbucket.core.api._
|
import gitbucket.core.api._
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
@@ -7,9 +7,8 @@ import gitbucket.core.service.{AccountService, ReleaseService}
|
|||||||
import gitbucket.core.util.Directory.getReleaseFilesDir
|
import gitbucket.core.util.Directory.getReleaseFilesDir
|
||||||
import gitbucket.core.util.{FileUtil, ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
import gitbucket.core.util.{FileUtil, ReferrerAuthenticator, RepositoryName, WritableUsersAuthenticator}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.util.SyntaxSugars.defining
|
|
||||||
import org.apache.commons.io.FileUtils
|
import org.apache.commons.io.FileUtils
|
||||||
import org.scalatra.{Created, NoContent}
|
import org.scalatra.NoContent
|
||||||
|
|
||||||
trait ApiReleaseControllerBase extends ControllerBase {
|
trait ApiReleaseControllerBase extends ControllerBase {
|
||||||
self: AccountService with ReleaseService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
self: AccountService with ReleaseService with ReferrerAuthenticator with WritableUsersAuthenticator =>
|
||||||
@@ -87,7 +86,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* vi. Edit a release
|
* vi. Edit a release
|
||||||
* https://developer.github.com/v3/repos/releases/#edit-a-release
|
* https://developer.github.com/v3/repos/releases/#edit-a-release
|
||||||
* Incompatiblity info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
* Incompatibility info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
||||||
*/
|
*/
|
||||||
patch("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
patch("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
||||||
(for {
|
(for {
|
||||||
@@ -104,7 +103,7 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
/**
|
/**
|
||||||
* vii. Delete a release
|
* vii. Delete a release
|
||||||
* https://developer.github.com/v3/repos/releases/#delete-a-release
|
* https://developer.github.com/v3/repos/releases/#delete-a-release
|
||||||
* Incompatiblity info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
* Incompatibility info: GitHub API requires :release_id, but GitBucket API requires :tag_name
|
||||||
*/
|
*/
|
||||||
delete("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
delete("/api/v3/repos/:owner/:repository/releases/:tag")(writableUsersOnly { repository =>
|
||||||
val tag = params("tag")
|
val tag = params("tag")
|
||||||
@@ -120,13 +119,13 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
* ix. Upload a release asset
|
* ix. Upload a release asset
|
||||||
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
* https://developer.github.com/v3/repos/releases/#upload-a-release-asset
|
||||||
*/
|
*/
|
||||||
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly { repository =>
|
post("/api/v3/repos/:owner/:repository/releases/:tag/assets")(writableUsersOnly {
|
||||||
|
repository =>
|
||||||
val name = params("name")
|
val name = params("name")
|
||||||
val tag = params("tag")
|
val tag = params("tag")
|
||||||
getRelease(repository.owner, repository.name, tag)
|
getRelease(repository.owner, repository.name, tag)
|
||||||
.map {
|
.map { release =>
|
||||||
release =>
|
val fileId = FileUtil.generateFileId
|
||||||
defining(FileUtil.generateFileId) { fileId =>
|
|
||||||
val buf = new Array[Byte](request.inputStream.available())
|
val buf = new Array[Byte](request.inputStream.available())
|
||||||
request.inputStream.read(buf)
|
request.inputStream.read(buf)
|
||||||
FileUtils.writeByteArrayToFile(
|
FileUtils.writeByteArrayToFile(
|
||||||
@@ -153,7 +152,6 @@ trait ApiReleaseControllerBase extends ControllerBase {
|
|||||||
ApiError("Unknown error")
|
ApiError("Unknown error")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
.getOrElse(NotFound())
|
.getOrElse(NotFound())
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -9,9 +9,23 @@ import gitbucket.core.util.JGitUtil.{CommitInfo, getBranches, getBranchesOfCommi
|
|||||||
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
import gitbucket.core.util.{JGitUtil, ReferrerAuthenticator, RepositoryName}
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
import org.eclipse.jgit.revwalk.RevWalk
|
import org.eclipse.jgit.revwalk.RevWalk
|
||||||
|
import org.eclipse.jgit.revwalk.filter.{
|
||||||
|
AndRevFilter,
|
||||||
|
AuthorRevFilter,
|
||||||
|
CommitTimeRevFilter,
|
||||||
|
MaxCountRevFilter,
|
||||||
|
RevFilter,
|
||||||
|
SkipRevFilter
|
||||||
|
}
|
||||||
|
import org.eclipse.jgit.treewalk.filter.{AndTreeFilter, PathFilterGroup, TreeFilter}
|
||||||
|
import scala.collection.mutable.ListBuffer
|
||||||
import scala.jdk.CollectionConverters._
|
import scala.jdk.CollectionConverters._
|
||||||
import scala.util.Using
|
import scala.util.Using
|
||||||
|
import math.min
|
||||||
|
import java.time.LocalDateTime
|
||||||
|
import java.time.format.DateTimeFormatter._
|
||||||
|
import java.util.Date
|
||||||
|
import java.time.ZoneOffset
|
||||||
|
|
||||||
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
||||||
self: AccountService with CommitsService with ProtectedBranchService with ReferrerAuthenticator =>
|
self: AccountService with CommitsService with ProtectedBranchService with ReferrerAuthenticator =>
|
||||||
@@ -22,8 +36,13 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
get("/api/v3/repos/:owner/:repository/commits")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/commits")(referrersOnly { repository =>
|
||||||
val owner = repository.owner
|
val owner = repository.owner
|
||||||
val name = repository.name
|
val name = repository.name
|
||||||
// TODO: The following parameters need to be implemented. [:path, :author, :since, :until]
|
val sha = params.get("sha").filter(_.nonEmpty).getOrElse("HEAD")
|
||||||
val sha = params.getOrElse("sha", "refs/heads/master")
|
val page = params.get("page").filter(_.nonEmpty).getOrElse("1").toInt
|
||||||
|
val per_page = min(params.get("per_page").filter(_.nonEmpty).getOrElse("30").toInt, 100)
|
||||||
|
val author = params.get("author").filter(_.nonEmpty)
|
||||||
|
val path = params.get("path").filter(_.nonEmpty)
|
||||||
|
val since = params.get("since").filter(_.nonEmpty)
|
||||||
|
val until = params.get("until").filter(_.nonEmpty)
|
||||||
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
Using.resource(Git.open(getRepositoryDir(owner, name))) {
|
||||||
git =>
|
git =>
|
||||||
val repo = git.getRepository
|
val repo = git.getRepository
|
||||||
@@ -31,7 +50,37 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
revWalk =>
|
revWalk =>
|
||||||
val objectId = repo.resolve(sha)
|
val objectId = repo.resolve(sha)
|
||||||
revWalk.markStart(revWalk.parseCommit(objectId))
|
revWalk.markStart(revWalk.parseCommit(objectId))
|
||||||
JsonFormat(revWalk.asScala.take(30).map {
|
if (path.nonEmpty) {
|
||||||
|
revWalk.setTreeFilter(
|
||||||
|
AndTreeFilter.create(PathFilterGroup.createFromStrings(path.get), TreeFilter.ANY_DIFF)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
val revfilters = new ListBuffer[(RevFilter)]()
|
||||||
|
if (author.nonEmpty) {
|
||||||
|
revfilters += AuthorRevFilter.create(author.get)
|
||||||
|
}
|
||||||
|
if (since.nonEmpty) {
|
||||||
|
revfilters += CommitTimeRevFilter.after(
|
||||||
|
Date.from(LocalDateTime.parse(since.get, ISO_DATE_TIME).toInstant(ZoneOffset.UTC))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (until.nonEmpty) {
|
||||||
|
revfilters += CommitTimeRevFilter.before(
|
||||||
|
Date.from(LocalDateTime.parse(until.get, ISO_DATE_TIME).toInstant(ZoneOffset.UTC))
|
||||||
|
)
|
||||||
|
}
|
||||||
|
if (page > 1) {
|
||||||
|
revfilters += SkipRevFilter.create(page * per_page - 2)
|
||||||
|
}
|
||||||
|
revfilters += MaxCountRevFilter.create(per_page);
|
||||||
|
revWalk.setRevFilter(
|
||||||
|
if (revfilters.size > 1) {
|
||||||
|
AndRevFilter.create(revfilters.toArray)
|
||||||
|
} else {
|
||||||
|
revfilters(0)
|
||||||
|
}
|
||||||
|
)
|
||||||
|
JsonFormat(revWalk.asScala.map {
|
||||||
commit =>
|
commit =>
|
||||||
val commitInfo = new CommitInfo(commit)
|
val commitInfo = new CommitInfo(commit)
|
||||||
ApiCommits(
|
ApiCommits(
|
||||||
@@ -40,7 +89,7 @@ trait ApiRepositoryCommitControllerBase extends ControllerBase {
|
|||||||
diffs = JGitUtil.getDiffs(git, commitInfo.parents.headOption, commitInfo.id, false, true),
|
diffs = JGitUtil.getDiffs(git, commitInfo.parents.headOption, commitInfo.id, false, true),
|
||||||
author = getAccount(commitInfo.authorName, commitInfo.authorEmailAddress),
|
author = getAccount(commitInfo.authorName, commitInfo.authorEmailAddress),
|
||||||
committer = getAccount(commitInfo.committerName, commitInfo.committerEmailAddress),
|
committer = getAccount(commitInfo.committerName, commitInfo.committerEmailAddress),
|
||||||
commentCount = getCommitComment(repository.owner, repository.name, commitInfo.id.toString).size
|
commentCount = getCommitComment(repository.owner, repository.name, commitInfo.id).size
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
package gitbucket.core.controller.api
|
package gitbucket.core.controller.api
|
||||||
import gitbucket.core.api.{ApiContents, ApiError, CreateAFile, JsonFormat}
|
import gitbucket.core.api.{ApiCommit, ApiContents, ApiError, CreateAFile, JsonFormat}
|
||||||
import gitbucket.core.controller.ControllerBase
|
import gitbucket.core.controller.ControllerBase
|
||||||
import gitbucket.core.plugin.PluginRegistry
|
|
||||||
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
import gitbucket.core.service.{RepositoryCommitFileService, RepositoryService}
|
||||||
import gitbucket.core.util.Directory.getRepositoryDir
|
import gitbucket.core.util.Directory.getRepositoryDir
|
||||||
import gitbucket.core.util.JGitUtil.{FileInfo, getContentFromId, getFileList}
|
import gitbucket.core.util.JGitUtil.{CommitInfo, FileInfo, getContentFromId, getFileList}
|
||||||
import gitbucket.core.util._
|
import gitbucket.core.util._
|
||||||
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
import gitbucket.core.view.helpers.{isRenderable, renderMarkup}
|
||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
@@ -36,7 +35,7 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get contents
|
* ii. Get contents
|
||||||
* https://developer.github.com/v3/repos/contents/#get-contents
|
* https://docs.github.com/en/rest/reference/repos#get-repository-content
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/contents")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/contents")(referrersOnly { repository =>
|
||||||
getContents(repository, ".", params.getOrElse("ref", repository.repository.defaultBranch))
|
getContents(repository, ".", params.getOrElse("ref", repository.repository.defaultBranch))
|
||||||
@@ -44,19 +43,13 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. Get contents
|
* ii. Get contents
|
||||||
* https://developer.github.com/v3/repos/contents/#get-contents
|
* https://docs.github.com/en/rest/reference/repos#get-repository-content
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/contents/*")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/contents/*")(referrersOnly { repository =>
|
||||||
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
getContents(repository, multiParams("splat").head, params.getOrElse("ref", repository.repository.defaultBranch))
|
||||||
})
|
})
|
||||||
|
|
||||||
private def getContents(
|
private def getFileInfo(git: Git, revision: String, pathStr: String, ignoreCase: Boolean): Option[FileInfo] = {
|
||||||
repository: RepositoryService.RepositoryInfo,
|
|
||||||
path: String,
|
|
||||||
refStr: String,
|
|
||||||
ignoreCase: Boolean = false
|
|
||||||
) = {
|
|
||||||
def getFileInfo(git: Git, revision: String, pathStr: String, ignoreCase: Boolean): Option[FileInfo] = {
|
|
||||||
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
val (dirName, fileName) = pathStr.lastIndexOf('/') match {
|
||||||
case -1 =>
|
case -1 =>
|
||||||
(".", pathStr)
|
(".", pathStr)
|
||||||
@@ -72,6 +65,12 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private def getContents(
|
||||||
|
repository: RepositoryService.RepositoryInfo,
|
||||||
|
path: String,
|
||||||
|
refStr: String,
|
||||||
|
ignoreCase: Boolean = false
|
||||||
|
) = {
|
||||||
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) { git =>
|
||||||
val fileList = getFileList(git, refStr, path, maxFiles = context.settings.repositoryViewer.maxFiles)
|
val fileList = getFileList(git, refStr, path, maxFiles = context.settings.repositoryViewer.maxFiles)
|
||||||
if (fileList.isEmpty) { // file or NotFound
|
if (fileList.isEmpty) { // file or NotFound
|
||||||
@@ -127,15 +126,16 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/*
|
|
||||||
|
/**
|
||||||
* iii. Create a file or iv. Update a file
|
* iii. Create a file or iv. Update a file
|
||||||
* https://developer.github.com/v3/repos/contents/#create-a-file
|
* https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents
|
||||||
* https://developer.github.com/v3/repos/contents/#update-a-file
|
|
||||||
* if sha is presented, update a file else create a file.
|
* if sha is presented, update a file else create a file.
|
||||||
* requested #2112
|
* requested #2112
|
||||||
*/
|
*/
|
||||||
|
|
||||||
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
put("/api/v3/repos/:owner/:repository/contents/*")(writableUsersOnly { repository =>
|
||||||
|
context.withLoginAccount {
|
||||||
|
loginAccount =>
|
||||||
JsonFormat(for {
|
JsonFormat(for {
|
||||||
data <- extractFromJsonBody[CreateAFile]
|
data <- extractFromJsonBody[CreateAFile]
|
||||||
} yield {
|
} yield {
|
||||||
@@ -146,10 +146,18 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
}
|
}
|
||||||
val paths = multiParams("splat").head.split("/")
|
val paths = multiParams("splat").head.split("/")
|
||||||
val path = paths.take(paths.size - 1).toList.mkString("/")
|
val path = paths.take(paths.size - 1).toList.mkString("/")
|
||||||
if (data.sha.isDefined && data.sha.get != commit) {
|
Using.resource(Git.open(getRepositoryDir(params("owner"), params("repository")))) {
|
||||||
ApiError("The blob SHA is not matched.", Some("https://developer.github.com/v3/repos/contents/#update-a-file"))
|
git =>
|
||||||
} else {
|
val fileInfo = getFileInfo(git, commit, path, false)
|
||||||
val objectId = commitFile(
|
|
||||||
|
fileInfo match {
|
||||||
|
case Some(f) if !data.sha.contains(f.id.getName) =>
|
||||||
|
ApiError(
|
||||||
|
"The blob SHA is not matched.",
|
||||||
|
Some("https://docs.github.com/en/rest/reference/repos#create-or-update-file-contents")
|
||||||
|
)
|
||||||
|
case _ =>
|
||||||
|
commitFile(
|
||||||
repository,
|
repository,
|
||||||
branch,
|
branch,
|
||||||
path,
|
path,
|
||||||
@@ -158,25 +166,48 @@ trait ApiRepositoryContentsControllerBase extends ControllerBase {
|
|||||||
StringUtil.base64Decode(data.content),
|
StringUtil.base64Decode(data.content),
|
||||||
data.message,
|
data.message,
|
||||||
commit,
|
commit,
|
||||||
context.loginAccount.get,
|
loginAccount,
|
||||||
data.committer.map(_.name).getOrElse(context.loginAccount.get.fullName),
|
data.committer.map(_.name).getOrElse(loginAccount.fullName),
|
||||||
data.committer.map(_.email).getOrElse(context.loginAccount.get.mailAddress),
|
data.committer.map(_.email).getOrElse(loginAccount.mailAddress),
|
||||||
context.settings
|
context.settings
|
||||||
|
) match {
|
||||||
|
case Left(error) =>
|
||||||
|
ApiError(s"Failed to commit a file: ${error}", None)
|
||||||
|
case Right((_, None)) =>
|
||||||
|
ApiError("Failed to commit a file.", None)
|
||||||
|
case Right((commitId, Some(blobId))) =>
|
||||||
|
Map(
|
||||||
|
"content" -> ApiContents(
|
||||||
|
"file",
|
||||||
|
paths.last,
|
||||||
|
path,
|
||||||
|
blobId.name,
|
||||||
|
Some(data.content),
|
||||||
|
Some("base64")
|
||||||
|
)(RepositoryName(repository)),
|
||||||
|
"commit" -> ApiCommit(
|
||||||
|
git,
|
||||||
|
RepositoryName(repository),
|
||||||
|
new CommitInfo(JGitUtil.getRevCommitFromId(git, commitId))
|
||||||
)
|
)
|
||||||
ApiContents("file", paths.last, path, objectId.name, None, None)(RepositoryName(repository))
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Delete a file
|
* v. Delete a file
|
||||||
* https://developer.github.com/v3/repos/contents/#delete-a-file
|
* https://docs.github.com/en/rest/reference/repos#delete-a-file
|
||||||
* should be implemented
|
* should be implemented
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Get archive link
|
* vi. Download a repository archive (tar/zip)
|
||||||
* https://developer.github.com/v3/repos/contents/#get-archive-link
|
* https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-tar
|
||||||
|
* https://docs.github.com/en/rest/reference/repos#download-a-repository-archive-zip
|
||||||
*/
|
*/
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import gitbucket.core.util._
|
|||||||
import gitbucket.core.util.Implicits._
|
import gitbucket.core.util.Implicits._
|
||||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||||
import org.eclipse.jgit.api.Git
|
import org.eclipse.jgit.api.Git
|
||||||
|
import org.scalatra.Forbidden
|
||||||
|
|
||||||
import scala.concurrent.Await
|
import scala.concurrent.Await
|
||||||
import scala.concurrent.duration.Duration
|
import scala.concurrent.duration.Duration
|
||||||
@@ -15,6 +16,7 @@ import scala.util.Using
|
|||||||
|
|
||||||
trait ApiRepositoryControllerBase extends ControllerBase {
|
trait ApiRepositoryControllerBase extends ControllerBase {
|
||||||
self: RepositoryService
|
self: RepositoryService
|
||||||
|
with ApiGitReferenceControllerBase
|
||||||
with RepositoryCreationService
|
with RepositoryCreationService
|
||||||
with AccountService
|
with AccountService
|
||||||
with OwnerAuthenticator
|
with OwnerAuthenticator
|
||||||
@@ -26,7 +28,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* i. List your repositories
|
* i. List your repositories
|
||||||
* https://developer.github.com/v3/repos/#list-your-repositories
|
* https://docs.github.com/en/rest/reference/repos#list-repositories-for-the-authenticated-user
|
||||||
*/
|
*/
|
||||||
get("/api/v3/user/repos")(usersOnly {
|
get("/api/v3/user/repos")(usersOnly {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Option(context.loginAccount.get.userName)).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Option(context.loginAccount.get.userName)).map { r =>
|
||||||
@@ -36,7 +38,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* ii. List user repositories
|
* ii. List user repositories
|
||||||
* https://developer.github.com/v3/repos/#list-user-repositories
|
* https://docs.github.com/en/rest/reference/repos#list-repositories-for-a-user
|
||||||
*/
|
*/
|
||||||
get("/api/v3/users/:userName/repos") {
|
get("/api/v3/users/:userName/repos") {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("userName"))).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("userName"))).map { r =>
|
||||||
@@ -46,7 +48,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* iii. List organization repositories
|
* iii. List organization repositories
|
||||||
* https://developer.github.com/v3/repos/#list-organization-repositories
|
* https://docs.github.com/en/rest/reference/repos#list-organization-repositories
|
||||||
*/
|
*/
|
||||||
get("/api/v3/orgs/:orgName/repos") {
|
get("/api/v3/orgs/:orgName/repos") {
|
||||||
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("orgName"))).map { r =>
|
JsonFormat(getVisibleRepositories(context.loginAccount, Some(params("orgName"))).map { r =>
|
||||||
@@ -56,7 +58,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* iv. List all public repositories
|
* iv. List all public repositories
|
||||||
* https://developer.github.com/v3/repos/#list-public-repositories
|
* https://docs.github.com/en/rest/reference/repos#list-public-repositories
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repositories") {
|
get("/api/v3/repositories") {
|
||||||
JsonFormat(getPublicRepositories().map { r =>
|
JsonFormat(getPublicRepositories().map { r =>
|
||||||
@@ -66,13 +68,12 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* v. Create
|
* v. Create
|
||||||
* https://developer.github.com/v3/repos/#create
|
|
||||||
* Implemented with two methods (user/orgs)
|
* Implemented with two methods (user/orgs)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create user repository
|
* Create user repository
|
||||||
* https://developer.github.com/v3/repos/#create
|
* https://docs.github.com/en/rest/reference/repos#create-a-repository-for-the-authenticated-user
|
||||||
*/
|
*/
|
||||||
post("/api/v3/user/repos")(usersOnly {
|
post("/api/v3/user/repos")(usersOnly {
|
||||||
val owner = context.loginAccount.get.userName
|
val owner = context.loginAccount.get.userName
|
||||||
@@ -80,7 +81,12 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
||||||
} yield {
|
} yield {
|
||||||
LockUtil.lock(s"${owner}/${data.name}") {
|
LockUtil.lock(s"${owner}/${data.name}") {
|
||||||
if (getRepository(owner, data.name).isEmpty) {
|
if (getRepository(owner, data.name).isDefined) {
|
||||||
|
ApiError(
|
||||||
|
"A repository with this name already exists on this account",
|
||||||
|
Some("https://developer.github.com/v3/repos/#create")
|
||||||
|
)
|
||||||
|
} else {
|
||||||
val f = createRepository(
|
val f = createRepository(
|
||||||
context.loginAccount.get,
|
context.loginAccount.get,
|
||||||
owner,
|
owner,
|
||||||
@@ -95,11 +101,6 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
getRepository(owner, data.name)(session).get
|
getRepository(owner, data.name)(session).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get)))
|
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(owner).get)))
|
||||||
} else {
|
|
||||||
ApiError(
|
|
||||||
"A repository with this name already exists on this account",
|
|
||||||
Some("https://developer.github.com/v3/repos/#create")
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
@@ -107,15 +108,22 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Create group repository
|
* Create group repository
|
||||||
* https://developer.github.com/v3/repos/#create
|
* https://docs.github.com/en/rest/reference/repos#create-an-organization-repository
|
||||||
*/
|
*/
|
||||||
post("/api/v3/orgs/:org/repos")(managersOnly {
|
post("/api/v3/orgs/:org/repos")(usersOnly {
|
||||||
val groupName = params("org")
|
val groupName = params("org")
|
||||||
(for {
|
(for {
|
||||||
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
data <- extractFromJsonBody[CreateARepository] if data.isValid
|
||||||
} yield {
|
} yield {
|
||||||
LockUtil.lock(s"${groupName}/${data.name}") {
|
LockUtil.lock(s"${groupName}/${data.name}") {
|
||||||
if (getRepository(groupName, data.name).isEmpty) {
|
if (getRepository(groupName, data.name).isDefined) {
|
||||||
|
ApiError(
|
||||||
|
"A repository with this name already exists for this group",
|
||||||
|
Some("https://developer.github.com/v3/repos/#create")
|
||||||
|
)
|
||||||
|
} else if (!canCreateRepository(groupName, context.loginAccount.get)) {
|
||||||
|
Forbidden()
|
||||||
|
} else {
|
||||||
val f = createRepository(
|
val f = createRepository(
|
||||||
context.loginAccount.get,
|
context.loginAccount.get,
|
||||||
groupName,
|
groupName,
|
||||||
@@ -129,11 +137,6 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
getRepository(groupName, data.name).get
|
getRepository(groupName, data.name).get
|
||||||
}
|
}
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get)))
|
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(groupName).get)))
|
||||||
} else {
|
|
||||||
ApiError(
|
|
||||||
"A repository with this name already exists for this group",
|
|
||||||
Some("https://developer.github.com/v3/repos/#create")
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}) getOrElse NotFound()
|
}) getOrElse NotFound()
|
||||||
@@ -141,7 +144,7 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* vi. Get
|
* vi. Get
|
||||||
* https://developer.github.com/v3/repos/#get
|
* https://docs.github.com/en/rest/reference/repos#get-a-repository
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository")(referrersOnly { repository =>
|
||||||
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(repository.owner).get)))
|
JsonFormat(ApiRepository(repository, ApiUser(getAccountByUserName(repository.owner).get)))
|
||||||
@@ -149,32 +152,32 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* vii. Edit
|
* vii. Edit
|
||||||
* https://developer.github.com/v3/repos/#edit
|
* https://docs.github.com/en/rest/reference/repos#update-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* viii. List all topics for a repository
|
* viii. List all topics for a repository
|
||||||
* https://developer.github.com/v3/repos/#list-all-topics-for-a-repository
|
* https://docs.github.com/en/rest/reference/repos#get-all-repository-topics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* ix. Replace all topics for a repository
|
* ix. Replace all topics for a repository
|
||||||
* https://developer.github.com/v3/repos/#replace-all-topics-for-a-repository
|
* https://docs.github.com/en/rest/reference/repos#replace-all-repository-topics
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* x. List contributors
|
* x. List contributors
|
||||||
* https://developer.github.com/v3/repos/#list-contributors
|
* https://docs.github.com/en/rest/reference/repos#list-repository-contributors
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xi. List languages
|
* xi. List languages
|
||||||
* https://developer.github.com/v3/repos/#list-languages
|
* https://docs.github.com/en/rest/reference/repos#list-repository-languages
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xii. List teams
|
* xii. List teams
|
||||||
* https://developer.github.com/v3/repos/#list-teams
|
* https://docs.github.com/en/rest/reference/repos#list-repository-teams
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -182,19 +185,21 @@ trait ApiRepositoryControllerBase extends ControllerBase {
|
|||||||
* https://docs.github.com/en/rest/reference/repos#list-repository-tags
|
* https://docs.github.com/en/rest/reference/repos#list-repository-tags
|
||||||
*/
|
*/
|
||||||
get("/api/v3/repos/:owner/:repository/tags")(referrersOnly { repository =>
|
get("/api/v3/repos/:owner/:repository/tags")(referrersOnly { repository =>
|
||||||
|
Using.resource(Git.open(getRepositoryDir(repository.owner, repository.name))) { git =>
|
||||||
JsonFormat(
|
JsonFormat(
|
||||||
repository.tags.map(tagInfo => ApiTag(tagInfo.name, RepositoryName(repository), tagInfo.id))
|
self.getRef("tags", repository)
|
||||||
)
|
)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xiv. Delete a repository
|
* xiv. Delete a repository
|
||||||
* https://developer.github.com/v3/repos/#delete-a-repository
|
* https://docs.github.com/en/rest/reference/repos#delete-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* xv. Transfer a repository
|
* xv. Transfer a repository
|
||||||
* https://developer.github.com/v3/repos/#transfer-a-repository
|
* https://docs.github.com/en/rest/reference/repos#transfer-a-repository
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ trait ApiUserControllerBase extends ControllerBase {
|
|||||||
*/
|
*/
|
||||||
delete("/api/v3/users/:userName/suspended")(adminOnly {
|
delete("/api/v3/users/:userName/suspended")(adminOnly {
|
||||||
val userName = params("userName")
|
val userName = params("userName")
|
||||||
getAccountByUserName(userName) match {
|
getAccountByUserName(userName, true) match {
|
||||||
case Some(targetAccount) =>
|
case Some(targetAccount) =>
|
||||||
updateAccount(targetAccount.copy(isRemoved = false))
|
updateAccount(targetAccount.copy(isRemoved = false))
|
||||||
NoContent()
|
NoContent()
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait AccessTokenComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
val tokenHash = column[String]("TOKEN_HASH")
|
val tokenHash = column[String]("TOKEN_HASH")
|
||||||
val note = column[String]("NOTE")
|
val note = column[String]("NOTE")
|
||||||
def * = (accessTokenId, userName, tokenHash, note) <> (AccessToken.tupled, AccessToken.unapply)
|
def * = (accessTokenId, userName, tokenHash, note).<>(AccessToken.tupled, AccessToken.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case class AccessToken(
|
case class AccessToken(
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ trait AccountComponent { self: Profile =>
|
|||||||
groupAccount,
|
groupAccount,
|
||||||
removed,
|
removed,
|
||||||
description.?
|
description.?
|
||||||
) <> (Account.tupled, Account.unapply)
|
).<>(Account.tupled, Account.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountExtraMailAddressComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
val extraMailAddress = column[String]("EXTRA_MAIL_ADDRESS", O PrimaryKey)
|
||||||
def * =
|
def * =
|
||||||
(userName, extraMailAddress) <> (AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
(userName, extraMailAddress).<>(AccountExtraMailAddress.tupled, AccountExtraMailAddress.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountFederationComponent { self: Profile =>
|
|||||||
val issuer = column[String]("ISSUER")
|
val issuer = column[String]("ISSUER")
|
||||||
val subject = column[String]("SUBJECT")
|
val subject = column[String]("SUBJECT")
|
||||||
val userName = column[String]("USER_NAME")
|
val userName = column[String]("USER_NAME")
|
||||||
def * = (issuer, subject, userName) <> (AccountFederation.tupled, AccountFederation.unapply)
|
def * = (issuer, subject, userName).<>(AccountFederation.tupled, AccountFederation.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
def byPrimaryKey(issuer: String, subject: String): Rep[Boolean] =
|
||||||
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
(this.issuer === issuer.bind) && (this.subject === subject.bind)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait AccountPreferenceComponent { self: Profile =>
|
|||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val highlighterTheme = column[String]("HIGHLIGHTER_THEME")
|
val highlighterTheme = column[String]("HIGHLIGHTER_THEME")
|
||||||
def * =
|
def * =
|
||||||
(userName, highlighterTheme) <> (AccountPreference.tupled, AccountPreference.unapply)
|
(userName, highlighterTheme).<>(AccountPreference.tupled, AccountPreference.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String): Rep[Boolean] = this.userName === userName.bind
|
def byPrimaryKey(userName: String): Rep[Boolean] = this.userName === userName.bind
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package gitbucket.core.model
|
|||||||
trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
|
|
||||||
private implicit val whContentTypeColumnType =
|
private implicit val whContentTypeColumnType: BaseColumnType[WebHookContentType] =
|
||||||
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
||||||
|
|
||||||
lazy val AccountWebHooks = TableQuery[AccountWebHooks]
|
lazy val AccountWebHooks = TableQuery[AccountWebHooks]
|
||||||
@@ -12,7 +12,7 @@ trait AccountWebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val token = column[Option[String]]("TOKEN")
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE")
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
def * = (userName, url, ctype, token) <> ((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
def * = (userName, url, ctype, token).<>((AccountWebHook.apply _).tupled, AccountWebHook.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byPrimaryKey(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait AccountWebHookEventComponent extends TemplateComponent {
|
trait AccountWebHookEventComponent extends TemplateComponent { self: Profile =>
|
||||||
self: Profile =>
|
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import gitbucket.core.model.Profile.AccountWebHooks
|
import gitbucket.core.model.Profile.AccountWebHooks
|
||||||
|
|
||||||
@@ -14,7 +12,7 @@ trait AccountWebHookEventComponent extends TemplateComponent {
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
|
|
||||||
def * = (userName, url, event) <> ((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
def * = (userName, url, event).<>((AccountWebHookEvent.apply _).tupled, AccountWebHookEvent.unapply)
|
||||||
|
|
||||||
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
def byAccountWebHook(userName: String, url: String) = (this.userName === userName.bind) && (this.url === url.bind)
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ trait CollaboratorComponent extends TemplateComponent { self: Profile =>
|
|||||||
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
class Collaborators(tag: Tag) extends Table[Collaborator](tag, "COLLABORATOR") with BasicTemplate {
|
||||||
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
val collaboratorName = column[String]("COLLABORATOR_NAME")
|
||||||
val role = column[String]("ROLE")
|
val role = column[String]("ROLE")
|
||||||
def * = (userName, repositoryName, collaboratorName, role) <> (Collaborator.tupled, Collaborator.unapply)
|
def * = (userName, repositoryName, collaboratorName, role).<>(Collaborator.tupled, Collaborator.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
def byPrimaryKey(owner: String, repository: String, collaborator: String) =
|
||||||
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
byRepository(owner, repository) && (collaboratorName === collaborator.bind)
|
||||||
|
|||||||
@@ -20,7 +20,8 @@ trait IssueCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
val registeredDate = column[java.util.Date]("REGISTERED_DATE")
|
||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate) <> (IssueComment.tupled, IssueComment.unapply)
|
(userName, repositoryName, issueId, commentId, action, commentedUserName, content, registeredDate, updatedDate)
|
||||||
|
.<>(IssueComment.tupled, IssueComment.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
@@ -74,7 +75,7 @@ trait CommitCommentComponent extends TemplateComponent { self: Profile =>
|
|||||||
originalCommitId,
|
originalCommitId,
|
||||||
originalOldLine,
|
originalOldLine,
|
||||||
originalNewLine
|
originalNewLine
|
||||||
) <> (CommitComment.tupled, CommitComment.unapply)
|
).<>(CommitComment.tupled, CommitComment.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
def byPrimaryKey(commentId: Int) = this.commentId === commentId.bind
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,8 @@ trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
|||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
implicit val commitStateColumnType = MappedColumnType.base[CommitState, String](b => b.name, i => CommitState(i))
|
implicit val commitStateColumnType: BaseColumnType[CommitState] =
|
||||||
|
MappedColumnType.base[CommitState, String](b => b.name, i => CommitState(i))
|
||||||
|
|
||||||
lazy val CommitStatuses = TableQuery[CommitStatuses]
|
lazy val CommitStatuses = TableQuery[CommitStatuses]
|
||||||
class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate {
|
class CommitStatuses(tag: Tag) extends Table[CommitStatus](tag, "COMMIT_STATUS") with CommitTemplate {
|
||||||
@@ -29,7 +30,7 @@ trait CommitStatusComponent extends TemplateComponent { self: Profile =>
|
|||||||
creator,
|
creator,
|
||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate
|
updatedDate
|
||||||
) <> ((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
).<>((CommitStatus.apply _).tupled, CommitStatus.unapply)
|
||||||
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
def byPrimaryKey(id: Int) = commitStatusId === id.bind
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -77,7 +78,7 @@ object CommitState {
|
|||||||
|
|
||||||
val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE)
|
val values: Vector[CommitState] = Vector(PENDING, SUCCESS, ERROR, FAILURE)
|
||||||
|
|
||||||
private val map: Map[String, CommitState] = values.map(enum => enum.name -> enum).toMap
|
private val map: Map[String, CommitState] = values.map(e => e.name -> e).toMap
|
||||||
|
|
||||||
def apply(name: String): CommitState = map(name)
|
def apply(name: String): CommitState = map(name)
|
||||||
|
|
||||||
|
|||||||
191
src/main/scala/gitbucket/core/model/CustomField.scala
Normal file
191
src/main/scala/gitbucket/core/model/CustomField.scala
Normal file
@@ -0,0 +1,191 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
import gitbucket.core.controller.Context
|
||||||
|
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||||
|
import gitbucket.core.util.StringUtil
|
||||||
|
import gitbucket.core.view.helpers
|
||||||
|
import org.scalatra.i18n.Messages
|
||||||
|
|
||||||
|
trait CustomFieldComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.api._
|
||||||
|
|
||||||
|
lazy val CustomFields = TableQuery[CustomFields]
|
||||||
|
|
||||||
|
class CustomFields(tag: Tag) extends Table[CustomField](tag, "CUSTOM_FIELD") with BasicTemplate {
|
||||||
|
val fieldId = column[Int]("FIELD_ID", O AutoInc)
|
||||||
|
val fieldName = column[String]("FIELD_NAME")
|
||||||
|
val fieldType = column[String]("FIELD_TYPE")
|
||||||
|
val enableForIssues = column[Boolean]("ENABLE_FOR_ISSUES")
|
||||||
|
val enableForPullRequests = column[Boolean]("ENABLE_FOR_PULL_REQUESTS")
|
||||||
|
def * =
|
||||||
|
(userName, repositoryName, fieldId, fieldName, fieldType, enableForIssues, enableForPullRequests)
|
||||||
|
.<>(CustomField.tupled, CustomField.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(userName: String, repositoryName: String, fieldId: Int) =
|
||||||
|
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.fieldId === fieldId.bind)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class CustomField(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
fieldId: Int = 0,
|
||||||
|
fieldName: String,
|
||||||
|
fieldType: String, // long, double, string, or date
|
||||||
|
enableForIssues: Boolean,
|
||||||
|
enableForPullRequests: Boolean
|
||||||
|
)
|
||||||
|
|
||||||
|
trait CustomFieldBehavior {
|
||||||
|
def createHtml(repository: RepositoryInfo, fieldId: Int)(implicit conext: Context): String
|
||||||
|
def fieldHtml(repository: RepositoryInfo, issueId: Int, fieldId: Int, value: String, editable: Boolean)(
|
||||||
|
implicit context: Context
|
||||||
|
): String
|
||||||
|
def validate(name: String, value: String, messages: Messages): Option[String]
|
||||||
|
}
|
||||||
|
|
||||||
|
object CustomFieldBehavior {
|
||||||
|
def validate(field: CustomField, value: String, messages: Messages): Option[String] = {
|
||||||
|
if (value.isEmpty) None
|
||||||
|
else {
|
||||||
|
CustomFieldBehavior(field.fieldType).flatMap { behavior =>
|
||||||
|
behavior.validate(field.fieldName, value, messages)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
def apply(fieldType: String): Option[CustomFieldBehavior] = {
|
||||||
|
fieldType match {
|
||||||
|
case "long" => Some(LongFieldBehavior)
|
||||||
|
case "double" => Some(DoubleFieldBehavior)
|
||||||
|
case "string" => Some(StringFieldBehavior)
|
||||||
|
case "date" => Some(DateFieldBehavior)
|
||||||
|
case _ => None
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case object LongFieldBehavior extends TextFieldBehavior {
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
|
try {
|
||||||
|
value.toLong
|
||||||
|
None
|
||||||
|
} catch {
|
||||||
|
case _: NumberFormatException => Some(messages("error.number").format(name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case object DoubleFieldBehavior extends TextFieldBehavior {
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
|
try {
|
||||||
|
value.toDouble
|
||||||
|
None
|
||||||
|
} catch {
|
||||||
|
case _: NumberFormatException => Some(messages("error.number").format(name))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case object StringFieldBehavior extends TextFieldBehavior
|
||||||
|
case object DateFieldBehavior extends TextFieldBehavior {
|
||||||
|
private val pattern = "yyyy-MM-dd"
|
||||||
|
override protected val fieldType: String = "date"
|
||||||
|
|
||||||
|
override def validate(name: String, value: String, messages: Messages): Option[String] = {
|
||||||
|
try {
|
||||||
|
new java.text.SimpleDateFormat(pattern).parse(value)
|
||||||
|
None
|
||||||
|
} catch {
|
||||||
|
case _: java.text.ParseException =>
|
||||||
|
Some(messages("error.datePattern").format(name, pattern))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
trait TextFieldBehavior extends CustomFieldBehavior {
|
||||||
|
protected val fieldType = "text"
|
||||||
|
|
||||||
|
def createHtml(repository: RepositoryInfo, fieldId: Int)(implicit context: Context): String = {
|
||||||
|
val sb = new StringBuilder
|
||||||
|
sb.append(
|
||||||
|
s"""<input type="$fieldType" class="form-control input-sm" id="custom-field-$fieldId" name="custom-field-$fieldId" data-field-id="$fieldId" style="width: 120px;"/>"""
|
||||||
|
)
|
||||||
|
sb.append(s"""<script>
|
||||||
|
|$$('#custom-field-$fieldId').focusout(function(){
|
||||||
|
| const $$this = $$(this);
|
||||||
|
| const fieldId = $$this.data('field-id');
|
||||||
|
| $$.post('${helpers.url(repository)}/issues/customfield_validation/' + fieldId,
|
||||||
|
| { value: $$this.val() },
|
||||||
|
| function(data){
|
||||||
|
| if (data != '') {
|
||||||
|
| $$('#custom-field-$fieldId-error').text(data);
|
||||||
|
| } else {
|
||||||
|
| $$('#custom-field-$fieldId-error').text('');
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
| );
|
||||||
|
|});
|
||||||
|
|</script>
|
||||||
|
|""".stripMargin)
|
||||||
|
sb.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
def fieldHtml(repository: RepositoryInfo, issueId: Int, fieldId: Int, value: String, editable: Boolean)(
|
||||||
|
implicit context: Context
|
||||||
|
): String = {
|
||||||
|
val sb = new StringBuilder
|
||||||
|
sb.append(
|
||||||
|
s"""<span id="custom-field-$fieldId-label" class="custom-field-label">${StringUtil
|
||||||
|
.escapeHtml(value)}</span>""".stripMargin
|
||||||
|
)
|
||||||
|
if (editable) {
|
||||||
|
sb.append(
|
||||||
|
s"""<input type="$fieldType" id="custom-field-$fieldId-editor" class="form-control input-sm custom-field-editor" data-field-id="$fieldId" style="width: 120px; display: none;"/>"""
|
||||||
|
)
|
||||||
|
sb.append(s"""<script>
|
||||||
|
|$$('#custom-field-$fieldId-label').click(function(){
|
||||||
|
| const $$this = $$(this);
|
||||||
|
| $$this.hide();
|
||||||
|
| $$this.next().val($$this.text()).show().focus();
|
||||||
|
|});
|
||||||
|
|
|
||||||
|
|$$('#custom-field-$fieldId-editor').focusout(function(){
|
||||||
|
| const $$this = $$(this);
|
||||||
|
| const fieldId = $$this.data('field-id');
|
||||||
|
| $$.post('${helpers.url(repository)}/issues/customfield_validation/' + fieldId,
|
||||||
|
| { value: $$this.val() },
|
||||||
|
| function(data){
|
||||||
|
| if (data != '') {
|
||||||
|
| $$('#custom-field-$fieldId-error').text(data);
|
||||||
|
| } else {
|
||||||
|
| $$('#custom-field-$fieldId-error').text('');
|
||||||
|
| $$.post('${helpers.url(repository)}/issues/$issueId/customfield/' + fieldId,
|
||||||
|
| { value: $$this.val() },
|
||||||
|
| function(data){
|
||||||
|
| $$this.hide();
|
||||||
|
| $$this.prev().text(data).show();
|
||||||
|
| }
|
||||||
|
| );
|
||||||
|
| }
|
||||||
|
| }
|
||||||
|
| );
|
||||||
|
|});
|
||||||
|
|
|
||||||
|
|// ESC key handling in text field
|
||||||
|
|$$('#custom-field-$fieldId-editor').keyup(function(e){
|
||||||
|
| if (e.keyCode == 27) {
|
||||||
|
| const $$this = $$(this);
|
||||||
|
| $$this.hide();
|
||||||
|
| $$this.prev().show();
|
||||||
|
| }
|
||||||
|
| if (e.keyCode == 13) {
|
||||||
|
| $$('#custom-field-$fieldId-editor').blur();
|
||||||
|
| }
|
||||||
|
|});
|
||||||
|
|</script>
|
||||||
|
|""".stripMargin)
|
||||||
|
}
|
||||||
|
sb.toString()
|
||||||
|
}
|
||||||
|
|
||||||
|
def validate(name: String, value: String, messages: Messages): Option[String] = None
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ trait DeployKeyComponent extends TemplateComponent { self: Profile =>
|
|||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite) <> (DeployKey.tupled, DeployKey.unapply)
|
(userName, repositoryName, deployKeyId, title, publicKey, allowWrite).<>(DeployKey.tupled, DeployKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ trait GpgKeyComponent { self: Profile =>
|
|||||||
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
val gpgKeyId = column[Long]("GPG_KEY_ID")
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, keyId, gpgKeyId, title, publicKey) <> (GpgKey.tupled, GpgKey.unapply)
|
def * = (userName, keyId, gpgKeyId, title, publicKey).<>(GpgKey.tupled, GpgKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, keyId: Int) =
|
def byPrimaryKey(userName: String, keyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
(this.userName === userName.bind) && (this.keyId === keyId.bind)
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait GroupMemberComponent { self: Profile =>
|
|||||||
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
val groupName = column[String]("GROUP_NAME", O PrimaryKey)
|
||||||
val userName = column[String]("USER_NAME", O PrimaryKey)
|
val userName = column[String]("USER_NAME", O PrimaryKey)
|
||||||
val isManager = column[Boolean]("MANAGER")
|
val isManager = column[Boolean]("MANAGER")
|
||||||
def * = (groupName, userName, isManager) <> (GroupMember.tupled, GroupMember.unapply)
|
def * = (groupName, userName, isManager).<>(GroupMember.tupled, GroupMember.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,7 +27,6 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
|||||||
with MilestoneTemplate
|
with MilestoneTemplate
|
||||||
with PriorityTemplate {
|
with PriorityTemplate {
|
||||||
val openedUserName = column[String]("OPENED_USER_NAME")
|
val openedUserName = column[String]("OPENED_USER_NAME")
|
||||||
val assignedUserName = column[String]("ASSIGNED_USER_NAME")
|
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val content = column[String]("CONTENT")
|
val content = column[String]("CONTENT")
|
||||||
val closed = column[Boolean]("CLOSED")
|
val closed = column[Boolean]("CLOSED")
|
||||||
@@ -42,14 +41,13 @@ trait IssueComponent extends TemplateComponent { self: Profile =>
|
|||||||
openedUserName,
|
openedUserName,
|
||||||
milestoneId.?,
|
milestoneId.?,
|
||||||
priorityId.?,
|
priorityId.?,
|
||||||
assignedUserName.?,
|
|
||||||
title,
|
title,
|
||||||
content.?,
|
content.?,
|
||||||
closed,
|
closed,
|
||||||
registeredDate,
|
registeredDate,
|
||||||
updatedDate,
|
updatedDate,
|
||||||
pullRequest
|
pullRequest
|
||||||
) <> (Issue.tupled, Issue.unapply)
|
).<>(Issue.tupled, Issue.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
def byPrimaryKey(owner: String, repository: String, issueId: Int) = byIssue(owner, repository, issueId)
|
||||||
}
|
}
|
||||||
@@ -62,7 +60,6 @@ case class Issue(
|
|||||||
openedUserName: String,
|
openedUserName: String,
|
||||||
milestoneId: Option[Int],
|
milestoneId: Option[Int],
|
||||||
priorityId: Option[Int],
|
priorityId: Option[Int],
|
||||||
assignedUserName: Option[String],
|
|
||||||
title: String,
|
title: String,
|
||||||
content: Option[String],
|
content: Option[String],
|
||||||
closed: Boolean,
|
closed: Boolean,
|
||||||
|
|||||||
26
src/main/scala/gitbucket/core/model/IssueAssignee.scala
Normal file
26
src/main/scala/gitbucket/core/model/IssueAssignee.scala
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait IssueAssigneeComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.api._
|
||||||
|
import self._
|
||||||
|
|
||||||
|
lazy val IssueAssignees = TableQuery[IssueAssignees]
|
||||||
|
|
||||||
|
class IssueAssignees(tag: Tag) extends Table[IssueAssignee](tag, "ISSUE_ASSIGNEE") with IssueTemplate {
|
||||||
|
val assigneeUserName = column[String]("ASSIGNEE_USER_NAME")
|
||||||
|
def * =
|
||||||
|
(userName, repositoryName, issueId, assigneeUserName)
|
||||||
|
.<>(IssueAssignee.tupled, IssueAssignee.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(owner: String, repository: String, issueId: Int, assigneeUserName: String) = {
|
||||||
|
byIssue(owner, repository, issueId) && this.assigneeUserName === assigneeUserName.bind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class IssueAssignee(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
assigneeUserName: String
|
||||||
|
)
|
||||||
31
src/main/scala/gitbucket/core/model/IssueCustomFields.scala
Normal file
31
src/main/scala/gitbucket/core/model/IssueCustomFields.scala
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
package gitbucket.core.model
|
||||||
|
|
||||||
|
trait IssueCustomFieldComponent extends TemplateComponent { self: Profile =>
|
||||||
|
import profile.api._
|
||||||
|
import self._
|
||||||
|
|
||||||
|
lazy val IssueCustomFields = TableQuery[IssueCustomFields]
|
||||||
|
|
||||||
|
class IssueCustomFields(tag: Tag) extends Table[IssueCustomField](tag, "ISSUE_CUSTOM_FIELD") {
|
||||||
|
val userName = column[String]("USER_NAME", O.PrimaryKey)
|
||||||
|
val repositoryName = column[String]("REPOSITORY_NAME", O.PrimaryKey)
|
||||||
|
val issueId = column[Int]("ISSUE_ID", O.PrimaryKey)
|
||||||
|
val fieldId = column[Int]("FIELD_ID", O.PrimaryKey)
|
||||||
|
val value = column[String]("VALUE")
|
||||||
|
def * =
|
||||||
|
(userName, repositoryName, issueId, fieldId, value)
|
||||||
|
.<>(IssueCustomField.tupled, IssueCustomField.unapply)
|
||||||
|
|
||||||
|
def byPrimaryKey(owner: String, repository: String, issueId: Int, fieldId: Int) = {
|
||||||
|
this.userName === owner.bind && this.repositoryName === repository.bind && this.issueId === issueId.bind && this.fieldId === fieldId.bind
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
case class IssueCustomField(
|
||||||
|
userName: String,
|
||||||
|
repositoryName: String,
|
||||||
|
issueId: Int,
|
||||||
|
fieldId: Int,
|
||||||
|
value: String
|
||||||
|
)
|
||||||
@@ -6,7 +6,7 @@ trait IssueLabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val IssueLabels = TableQuery[IssueLabels]
|
lazy val IssueLabels = TableQuery[IssueLabels]
|
||||||
|
|
||||||
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
class IssueLabels(tag: Tag) extends Table[IssueLabel](tag, "ISSUE_LABEL") with IssueTemplate with LabelTemplate {
|
||||||
def * = (userName, repositoryName, issueId, labelId) <> (IssueLabel.tupled, IssueLabel.unapply)
|
def * = (userName, repositoryName, issueId, labelId).<>(IssueLabel.tupled, IssueLabel.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
def byPrimaryKey(owner: String, repository: String, issueId: Int, labelId: Int) =
|
||||||
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
byIssue(owner, repository, issueId) && (this.labelId === labelId.bind)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ trait LabelComponent extends TemplateComponent { self: Profile =>
|
|||||||
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
override val labelId = column[Int]("LABEL_ID", O AutoInc)
|
||||||
override val labelName = column[String]("LABEL_NAME")
|
override val labelName = column[String]("LABEL_NAME")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * = (userName, repositoryName, labelId, labelName, color) <> (Label.tupled, Label.unapply)
|
def * = (userName, repositoryName, labelId, labelName, color).<>(Label.tupled, Label.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
def byPrimaryKey(owner: String, repository: String, labelId: Int) = byLabel(owner, repository, labelId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], labelId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
|||||||
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
||||||
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate) <> (Milestone.tupled, Milestone.unapply)
|
(userName, repositoryName, milestoneId, title, description, dueDate, closedDate)
|
||||||
|
.<>(Milestone.tupled, Milestone.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
def byPrimaryKey(owner: String, repository: String, milestoneId: Int) = byMilestone(owner, repository, milestoneId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) =
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ trait PriorityComponent extends TemplateComponent { self: Profile =>
|
|||||||
val isDefault = column[Boolean]("IS_DEFAULT")
|
val isDefault = column[Boolean]("IS_DEFAULT")
|
||||||
val color = column[String]("COLOR")
|
val color = column[String]("COLOR")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color) <> (Priority.tupled, Priority.unapply)
|
(userName, repositoryName, priorityId, priorityName, description.?, isDefault, ordering, color)
|
||||||
|
.<>(Priority.tupled, Priority.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
def byPrimaryKey(owner: String, repository: String, priorityId: Int) = byPriority(owner, repository, priorityId)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], priorityId: Rep[Int]) =
|
||||||
|
|||||||
@@ -10,7 +10,8 @@ trait Profile {
|
|||||||
/**
|
/**
|
||||||
* java.util.Date Mapped Column Types
|
* java.util.Date Mapped Column Types
|
||||||
*/
|
*/
|
||||||
implicit val dateColumnType = MappedColumnType.base[java.util.Date, java.sql.Timestamp](
|
implicit val dateColumnType: BaseColumnType[java.util.Date] =
|
||||||
|
MappedColumnType.base[java.util.Date, java.sql.Timestamp](
|
||||||
d => new java.sql.Timestamp(d.getTime),
|
d => new java.sql.Timestamp(d.getTime),
|
||||||
t => new java.util.Date(t.getTime)
|
t => new java.util.Date(t.getTime)
|
||||||
)
|
)
|
||||||
@@ -18,7 +19,8 @@ trait Profile {
|
|||||||
/**
|
/**
|
||||||
* WebHookBase.Event Column Types
|
* WebHookBase.Event Column Types
|
||||||
*/
|
*/
|
||||||
implicit val eventColumnType = MappedColumnType.base[WebHook.Event, String](_.name, WebHook.Event.valueOf(_))
|
implicit val eventColumnType: BaseColumnType[WebHook.Event] =
|
||||||
|
MappedColumnType.base[WebHook.Event, String](_.name, WebHook.Event.valueOf(_))
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Extends Column to add conditional condition
|
* Extends Column to add conditional condition
|
||||||
@@ -45,7 +47,7 @@ trait CoreProfile
|
|||||||
with Profile
|
with Profile
|
||||||
with AccessTokenComponent
|
with AccessTokenComponent
|
||||||
with AccountComponent
|
with AccountComponent
|
||||||
with ActivityComponent // ActivityComponent has been deprecated, but keep it for binary compatibility
|
with ActivityComponent
|
||||||
with CollaboratorComponent
|
with CollaboratorComponent
|
||||||
with CommitCommentComponent
|
with CommitCommentComponent
|
||||||
with CommitStatusComponent
|
with CommitStatusComponent
|
||||||
@@ -71,5 +73,8 @@ trait CoreProfile
|
|||||||
with ReleaseAssetComponent
|
with ReleaseAssetComponent
|
||||||
with AccountExtraMailAddressComponent
|
with AccountExtraMailAddressComponent
|
||||||
with AccountPreferenceComponent
|
with AccountPreferenceComponent
|
||||||
|
with CustomFieldComponent
|
||||||
|
with IssueCustomFieldComponent
|
||||||
|
with IssueAssigneeComponent
|
||||||
|
|
||||||
object Profile extends CoreProfile
|
object Profile extends CoreProfile
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
lazy val ProtectedBranches = TableQuery[ProtectedBranches]
|
||||||
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
class ProtectedBranches(tag: Tag) extends Table[ProtectedBranch](tag, "PROTECTED_BRANCH") with BranchTemplate {
|
||||||
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
val statusCheckAdmin = column[Boolean]("STATUS_CHECK_ADMIN")
|
||||||
def * = (userName, repositoryName, branch, statusCheckAdmin) <> (ProtectedBranch.tupled, ProtectedBranch.unapply)
|
def * = (userName, repositoryName, branch, statusCheckAdmin).<>(ProtectedBranch.tupled, ProtectedBranch.unapply)
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
def byPrimaryKey(userName: String, repositoryName: String, branch: String) =
|
||||||
byBranch(userName, repositoryName, branch)
|
byBranch(userName, repositoryName, branch)
|
||||||
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
def byPrimaryKey(userName: Rep[String], repositoryName: Rep[String], branch: Rep[String]) =
|
||||||
@@ -20,7 +20,7 @@ trait ProtectedBranchComponent extends TemplateComponent { self: Profile =>
|
|||||||
with BranchTemplate {
|
with BranchTemplate {
|
||||||
val context = column[String]("CONTEXT")
|
val context = column[String]("CONTEXT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, branch, context) <> (ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
(userName, repositoryName, branch, context).<>(ProtectedBranchContext.tupled, ProtectedBranchContext.unapply)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ trait PullRequestComponent extends TemplateComponent { self: Profile =>
|
|||||||
commitIdFrom,
|
commitIdFrom,
|
||||||
commitIdTo,
|
commitIdTo,
|
||||||
isDraft
|
isDraft
|
||||||
) <> (PullRequest.tupled, PullRequest.unapply)
|
).<>(PullRequest.tupled, PullRequest.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
def byPrimaryKey(userName: String, repositoryName: String, issueId: Int) =
|
||||||
byIssue(userName, repositoryName, issueId)
|
byIssue(userName, repositoryName, issueId)
|
||||||
|
|||||||
@@ -2,9 +2,7 @@ package gitbucket.core.model
|
|||||||
|
|
||||||
import java.util.Date
|
import java.util.Date
|
||||||
|
|
||||||
trait ReleaseAssetComponent extends TemplateComponent {
|
trait ReleaseAssetComponent extends TemplateComponent { self: Profile =>
|
||||||
self: Profile =>
|
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
@@ -21,7 +19,8 @@ trait ReleaseAssetComponent extends TemplateComponent {
|
|||||||
val updatedDate = column[Date]("UPDATED_DATE")
|
val updatedDate = column[Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate) <> (ReleaseAsset.tupled, ReleaseAsset.unapply)
|
(userName, repositoryName, tag, releaseAssetId, fileName, label, size, uploader, registeredDate, updatedDate)
|
||||||
|
.<>(ReleaseAsset.tupled, ReleaseAsset.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
def byPrimaryKey(owner: String, repository: String, tag: String, fileName: String) =
|
||||||
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
byTag(owner, repository, tag) && (this.fileName === fileName.bind)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package gitbucket.core.model
|
package gitbucket.core.model
|
||||||
|
|
||||||
trait ReleaseTagComponent extends TemplateComponent {
|
trait ReleaseTagComponent extends TemplateComponent { self: Profile =>
|
||||||
self: Profile =>
|
|
||||||
|
|
||||||
import profile.api._
|
import profile.api._
|
||||||
import self._
|
import self._
|
||||||
|
|
||||||
@@ -17,7 +15,8 @@ trait ReleaseTagComponent extends TemplateComponent {
|
|||||||
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
val updatedDate = column[java.util.Date]("UPDATED_DATE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate) <> (ReleaseTag.tupled, ReleaseTag.unapply)
|
(userName, repositoryName, name, tag, author, content, registeredDate, updatedDate)
|
||||||
|
.<>(ReleaseTag.tupled, ReleaseTag.unapply)
|
||||||
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
def byPrimaryKey(owner: String, repository: String, tag: String) = byTag(owner, repository, tag)
|
||||||
def byTag(owner: String, repository: String, tag: String) =
|
def byTag(owner: String, repository: String, tag: String) =
|
||||||
byRepository(owner, repository) && (this.tag === tag.bind)
|
byRepository(owner, repository) && (this.tag === tag.bind)
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
val allowFork = column[Boolean]("ALLOW_FORK")
|
val allowFork = column[Boolean]("ALLOW_FORK")
|
||||||
val mergeOptions = column[String]("MERGE_OPTIONS")
|
val mergeOptions = column[String]("MERGE_OPTIONS")
|
||||||
val defaultMergeOption = column[String]("DEFAULT_MERGE_OPTION")
|
val defaultMergeOption = column[String]("DEFAULT_MERGE_OPTION")
|
||||||
|
val safeMode = column[Boolean]("SAFE_MODE")
|
||||||
|
|
||||||
def * =
|
def * =
|
||||||
(
|
(
|
||||||
@@ -41,8 +42,18 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
parentUserName.?,
|
parentUserName.?,
|
||||||
parentRepositoryName.?
|
parentRepositoryName.?
|
||||||
),
|
),
|
||||||
(issuesOption, externalIssuesUrl.?, wikiOption, externalWikiUrl.?, allowFork, mergeOptions, defaultMergeOption)
|
(
|
||||||
).shaped <> ({
|
issuesOption,
|
||||||
|
externalIssuesUrl.?,
|
||||||
|
wikiOption,
|
||||||
|
externalWikiUrl.?,
|
||||||
|
allowFork,
|
||||||
|
mergeOptions,
|
||||||
|
defaultMergeOption,
|
||||||
|
safeMode
|
||||||
|
)
|
||||||
|
).shaped.<>(
|
||||||
|
{
|
||||||
case (repository, options) =>
|
case (repository, options) =>
|
||||||
Repository(
|
Repository(
|
||||||
repository._1,
|
repository._1,
|
||||||
@@ -81,7 +92,8 @@ trait RepositoryComponent extends TemplateComponent { self: Profile =>
|
|||||||
)
|
)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
)
|
||||||
|
|
||||||
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
def byPrimaryKey(owner: String, repository: String) = byRepository(owner, repository)
|
||||||
}
|
}
|
||||||
@@ -110,5 +122,6 @@ case class RepositoryOptions(
|
|||||||
externalWikiUrl: Option[String],
|
externalWikiUrl: Option[String],
|
||||||
allowFork: Boolean,
|
allowFork: Boolean,
|
||||||
mergeOptions: String,
|
mergeOptions: String,
|
||||||
defaultMergeOption: String
|
defaultMergeOption: String,
|
||||||
|
safeMode: Boolean
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ package gitbucket.core.model
|
|||||||
trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
||||||
import profile.api._
|
import profile.api._
|
||||||
|
|
||||||
implicit val whContentTypeColumnType =
|
implicit val whContentTypeColumnType: BaseColumnType[WebHookContentType] =
|
||||||
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
MappedColumnType.base[WebHookContentType, String](whct => whct.code, code => WebHookContentType.valueOf(code))
|
||||||
|
|
||||||
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
lazy val RepositoryWebHooks = TableQuery[RepositoryWebHooks]
|
||||||
@@ -14,7 +14,8 @@ trait RepositoryWebHookComponent extends TemplateComponent { self: Profile =>
|
|||||||
val token = column[Option[String]]("TOKEN")
|
val token = column[Option[String]]("TOKEN")
|
||||||
val ctype = column[WebHookContentType]("CTYPE")
|
val ctype = column[WebHookContentType]("CTYPE")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, hookId, url, ctype, token) <> ((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
(userName, repositoryName, hookId, url, ctype, token)
|
||||||
|
.<>((RepositoryWebHook.apply _).tupled, RepositoryWebHook.unapply)
|
||||||
|
|
||||||
def byRepositoryUrl(owner: String, repository: String, url: String) =
|
def byRepositoryUrl(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ trait RepositoryWebHookEventComponent extends TemplateComponent { self: Profile
|
|||||||
val url = column[String]("URL")
|
val url = column[String]("URL")
|
||||||
val event = column[WebHook.Event]("EVENT")
|
val event = column[WebHook.Event]("EVENT")
|
||||||
def * =
|
def * =
|
||||||
(userName, repositoryName, url, event) <> ((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
(userName, repositoryName, url, event).<>((RepositoryWebHookEvent.apply _).tupled, RepositoryWebHookEvent.unapply)
|
||||||
|
|
||||||
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
def byRepositoryWebHook(owner: String, repository: String, url: String) =
|
||||||
byRepository(owner, repository) && (this.url === url.bind)
|
byRepository(owner, repository) && (this.url === url.bind)
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ trait SshKeyComponent { self: Profile =>
|
|||||||
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
val sshKeyId = column[Int]("SSH_KEY_ID", O AutoInc)
|
||||||
val title = column[String]("TITLE")
|
val title = column[String]("TITLE")
|
||||||
val publicKey = column[String]("PUBLIC_KEY")
|
val publicKey = column[String]("PUBLIC_KEY")
|
||||||
def * = (userName, sshKeyId, title, publicKey) <> (SshKey.tupled, SshKey.unapply)
|
def * = (userName, sshKeyId, title, publicKey).<>(SshKey.tupled, SshKey.unapply)
|
||||||
|
|
||||||
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
def byPrimaryKey(userName: String, sshKeyId: Int) =
|
||||||
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
(this.userName === userName.bind) && (this.sshKeyId === sshKeyId.bind)
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ object WebHookContentType {
|
|||||||
|
|
||||||
val values: Vector[WebHookContentType] = Vector(JSON, FORM)
|
val values: Vector[WebHookContentType] = Vector(JSON, FORM)
|
||||||
|
|
||||||
private val map: Map[String, WebHookContentType] = values.map(enum => enum.code -> enum).toMap
|
private val map: Map[String, WebHookContentType] = values.map(e => e.code -> e).toMap
|
||||||
|
|
||||||
def apply(code: String): WebHookContentType = map(code)
|
def apply(code: String): WebHookContentType = map(code)
|
||||||
|
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user