mirror of
https://github.com/gitbucket/gitbucket.git
synced 2026-05-08 11:57:37 +02:00
Compare commits
140 Commits
4.10
...
maintenanc
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
014bdb9d5c | ||
|
|
bef65870d8 | ||
|
|
df4b1d6f01 | ||
|
|
c5a53f0719 | ||
|
|
961e21e5a7 | ||
|
|
e33e304644 | ||
|
|
46896da46e | ||
|
|
207aa8b8c1 | ||
|
|
8b4017a082 | ||
|
|
f46f5909f1 | ||
|
|
5337b29532 | ||
|
|
7010b316fd | ||
|
|
6128258cfb | ||
|
|
83e619ecd4 | ||
|
|
3af89a7897 | ||
|
|
1e94b69a68 | ||
|
|
95b1945bc1 | ||
|
|
8aaba606bc | ||
|
|
f40657a7ff | ||
|
|
788e56d926 | ||
|
|
37303a8c5a | ||
|
|
c6449d4c10 | ||
|
|
9c078971ab | ||
|
|
0f0c3c1b1d | ||
|
|
835f35393e | ||
|
|
e576e14460 | ||
|
|
a839e9eab5 | ||
|
|
e7b368ced2 | ||
|
|
d662df5a7d | ||
|
|
7c4a286937 | ||
|
|
2164b8ce31 | ||
|
|
71737eb018 | ||
|
|
ed543847a8 | ||
|
|
c0320d3139 | ||
|
|
b218c2284e | ||
|
|
fce8cbdaef | ||
|
|
f40bdb6494 | ||
|
|
74e940ea3c | ||
|
|
650aff5649 | ||
|
|
9793bfc074 | ||
|
|
0cba10994b | ||
|
|
9df2c221df | ||
|
|
e3c6621398 | ||
|
|
b736f904e9 | ||
|
|
00093728ee | ||
|
|
34c1fce8a2 | ||
|
|
6a520061cf | ||
|
|
c581d9e6b9 | ||
|
|
956af54d4f | ||
|
|
d5a0ade5d9 | ||
|
|
68c2f832ac | ||
|
|
614bba4a0f | ||
|
|
fde075f067 | ||
|
|
ea6bc9ccf0 | ||
|
|
b99c1c3f6e | ||
|
|
1e715d8b06 | ||
|
|
2a3e4af082 | ||
|
|
968c45c77d | ||
|
|
ee8be37f55 | ||
|
|
2d9727a695 | ||
|
|
0aa6e674e9 | ||
|
|
445bf1cc34 | ||
|
|
cfae6d76b2 | ||
|
|
83a27809ef | ||
|
|
5eb41d5b25 | ||
|
|
fe5961c59e | ||
|
|
114c50a354 | ||
|
|
56a39775e8 | ||
|
|
d0fa4da45a | ||
|
|
dcd4c55fb9 | ||
|
|
a7920a7dd7 | ||
|
|
3bb32f11d7 | ||
|
|
0a08879d8c | ||
|
|
c0e04ab0dc | ||
|
|
977e8e2472 | ||
|
|
9ba43071de | ||
|
|
37f940350f | ||
|
|
b65f7d9423 | ||
|
|
b91263ffb3 | ||
|
|
d27b9222ba | ||
|
|
c41c15dbc1 | ||
|
|
25b4b90633 | ||
|
|
cdea9475c1 | ||
|
|
a76d14d81f | ||
|
|
81b7c142d8 | ||
|
|
4d0e0b7bd2 | ||
|
|
4e3c88f1f4 | ||
|
|
f29c80acae | ||
|
|
a2e150817c | ||
|
|
e3aa9d739d | ||
|
|
faa8f8aade | ||
|
|
f165e89a8d | ||
|
|
620c3161cf | ||
|
|
05739f60ce | ||
|
|
57e260df6d | ||
|
|
2cff3884e2 | ||
|
|
5ac01a0617 | ||
|
|
4344228b92 | ||
|
|
8f91499132 | ||
|
|
5b68ca1416 | ||
|
|
2cb29654e9 | ||
|
|
43aff74ad2 | ||
|
|
0d5964bd22 | ||
|
|
8087531d64 | ||
|
|
c939456f21 | ||
|
|
1312276151 | ||
|
|
8fa3bf7850 | ||
|
|
cdc8431865 | ||
|
|
f4da49b5bd | ||
|
|
3e4e278778 | ||
|
|
7b8a5a482a | ||
|
|
0401488ab1 | ||
|
|
a024491296 | ||
|
|
a684fa8a8e | ||
|
|
c5a5c737bf | ||
|
|
dfe2e8dda5 | ||
|
|
994d897b5b | ||
|
|
ec66a79e2b | ||
|
|
d611aa8737 | ||
|
|
07bbbe8ad0 | ||
|
|
3d9e3d8456 | ||
|
|
e56c7472c4 | ||
|
|
0f8ee0d57d | ||
|
|
99f1a0b400 | ||
|
|
c039b763c5 | ||
|
|
bc69a67b05 | ||
|
|
37d2a38517 | ||
|
|
b5f287d75e | ||
|
|
629aaa78d6 | ||
|
|
5a1ec385a8 | ||
|
|
42d3585df5 | ||
|
|
b6390ac383 | ||
|
|
32c307b5a5 | ||
|
|
b0056bc942 | ||
|
|
3fa6652415 | ||
|
|
ae4da97ece | ||
|
|
16f0b68490 | ||
|
|
a0c5414a93 | ||
|
|
be3fc923fc | ||
|
|
684cd714e5 |
13
.editorconfig
Normal file
13
.editorconfig
Normal file
@@ -0,0 +1,13 @@
|
||||
root = true
|
||||
|
||||
[*]
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 2
|
||||
|
||||
[*.java]
|
||||
trim_trailing_whitespace = true
|
||||
insert_final_newline = true
|
||||
indent_style = space
|
||||
indent_size = 4
|
||||
5
.github/CONTRIBUTING.md
vendored
5
.github/CONTRIBUTING.md
vendored
@@ -1,6 +1,7 @@
|
||||
# Guideline for Issues
|
||||
|
||||
- At first, See [FAQ](https://github.com/gitbucket/gitbucket/wiki/FAQ) and check issues whether there is a same question or request in the past.
|
||||
- At first, 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.
|
||||
- We can also support in Japaneses other than English at [gitter room for Japanese](https://gitter.im/gitbucket/gitbucket_ja).
|
||||
- We can also support in Japanese other than English at [gitter room for Japanese](https://gitter.im/gitbucket/gitbucket_ja).
|
||||
- Write an issue in English. At least, write subject in English.
|
||||
- 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.
|
||||
|
||||
1
.gitignore
vendored
1
.gitignore
vendored
@@ -21,3 +21,4 @@ project/plugins/project/
|
||||
# IntelliJ specific
|
||||
.idea/
|
||||
.idea_modules/
|
||||
*.iml
|
||||
|
||||
20
.travis.yml
20
.travis.yml
@@ -16,3 +16,23 @@ cache:
|
||||
- $HOME/.coursier
|
||||
- $HOME/.embedmysql
|
||||
- $HOME/.embedpostgresql
|
||||
matrix:
|
||||
include:
|
||||
- dist: trusty
|
||||
group: edge
|
||||
sudo: required
|
||||
jdk: oraclejdk9
|
||||
script:
|
||||
# https://github.com/sbt/sbt/pull/2951
|
||||
- git clone https://github.com/retronym/java9-rt-export
|
||||
- cd java9-rt-export/
|
||||
- git checkout 1019a2873d057dd7214f4135e84283695728395d
|
||||
- jdk_switcher use oraclejdk8
|
||||
- sbt package
|
||||
- jdk_switcher use oraclejdk9
|
||||
- mkdir -p $HOME/.sbt/0.13/java9-rt-ext; java -jar target/java9-rt-export-*.jar $HOME/.sbt/0.13/java9-rt-ext/rt.jar
|
||||
- jar tf $HOME/.sbt/0.13/java9-rt-ext/rt.jar | grep java/lang/Object
|
||||
- cd ..
|
||||
- echo "sbt.version=0.13.14-RC1" > project/build.properties
|
||||
- wget https://raw.githubusercontent.com/paulp/sbt-extras/9ade5fa54914ca8aded44105bf4b9a60966f3ccd/sbt && chmod +x ./sbt
|
||||
- ./sbt -Dscala.ext.dirs=$HOME/.sbt/0.13/java9-rt-ext test
|
||||
|
||||
5
LICENSE
5
LICENSE
@@ -1,4 +1,3 @@
|
||||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
@@ -179,7 +178,7 @@
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
boilerplate notice, with the fields enclosed by brackets "{}"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
@@ -187,7 +186,7 @@
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright 2013-2016 GitBucket Team
|
||||
Copyright {yyyy} {name of copyright owner}
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
|
||||
51
README.md
51
README.md
@@ -1,31 +1,35 @@
|
||||
GitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://travis-ci.org/gitbucket/gitbucket)
|
||||
0;95;0cGitBucket [](https://gitter.im/gitbucket/gitbucket) [](https://travis-ci.org/gitbucket/gitbucket)
|
||||
=========
|
||||
|
||||
GitBucket is a Git platform powered by Scala offering:
|
||||
GitBucket is a Git web platform powered by Scala offering:
|
||||
|
||||
- Easy installation
|
||||
- Intuitive UI
|
||||
- High extensibility by plugins
|
||||
- API compatibility with GitHub
|
||||
|
||||
You can try an [online demo](https://gitbucket.herokuapp.com/) *(ID: root / Pass: root)* of GitBucket, and also get the latest information at [GitBucket News](https://gitbucket.github.io/gitbucket-news/).
|
||||
|
||||
Features
|
||||
--------
|
||||
The current version of GitBucket provides a basic features below:
|
||||
The current version of GitBucket provides many features such as:
|
||||
|
||||
- Public / Private Git repository (http and ssh access)
|
||||
- Public / Private Git repositories (with http/https and ssh access)
|
||||
- GitLFS support
|
||||
- Repository viewer includes online file editor
|
||||
- Issues, Pull request and Wiki for repositories
|
||||
- Activity timeline and email notification
|
||||
- Repository viewer including an online file editor
|
||||
- Issues, Pull Requests and Wiki for repositories
|
||||
- Activity timeline and email notifications
|
||||
- Account and group management with LDAP integration
|
||||
- Plug-in system
|
||||
- a Plug-in system
|
||||
|
||||
If you want to try the development version of GitBucket, see the [Developer's Guide](https://github.com/gitbucket/gitbucket/blob/master/doc/how_to_run.md).
|
||||
|
||||
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.
|
||||
|
||||
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 **root** / **root**.
|
||||
2. Go to `http://[hostname]:8080/` and log in with ID: **root** / Pass: **root**.
|
||||
|
||||
You can specify following options:
|
||||
|
||||
@@ -45,26 +49,39 @@ To upgrade GitBucket, replace `gitbucket.war` with the new version, after stoppi
|
||||
|
||||
Plugins
|
||||
--------
|
||||
GitBucket has a plug-in system to allow extensions to GitBucket. We provide some official plug-ins:
|
||||
GitBucket has a plug-in system that allows extra functionality. Officially the following plug-ins are provided:
|
||||
|
||||
- [gitbucket-gist-plugin](https://github.com/gitbucket/gitbucket-gist-plugin)
|
||||
- [gitbucket-emoji-plugin](https://github.com/gitbucket/gitbucket-emoji-plugin)
|
||||
- [gitbucket-pages-plugin](https://github.com/gitbucket/gitbucket-pages-plugin)
|
||||
|
||||
You can find more plugins made by the community at [GitBucket community plugins](http://gitbucket-plugins.github.io/).
|
||||
|
||||
Support
|
||||
--------
|
||||
|
||||
- If you have any questions about GitBucket, send it to the [gitter room](https://gitter.im/gitbucket/gitbucket) before opening an issue.
|
||||
- Make sure check whether there is the same question or request in the past.
|
||||
- When raise a new issue, write at least the subject in **English**.
|
||||
- We can also provide support in Japanese at [gitter room for Japanese](https://gitter.im/gitbucket/gitbucket_ja).
|
||||
- The first priority of GitBucket is easy installation and API compatibility with GitHub, so we might reject if your request is against it.
|
||||
- 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.
|
||||
- We can also provide support in Japanese other than English at [gitter room for Japanese](https://gitter.im/gitbucket/gitbucket_ja).
|
||||
- Write an issue in English. At least, write subject in English.
|
||||
- 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.
|
||||
|
||||
Release Notes
|
||||
-------------
|
||||
### 4.12 - 30 Apr 2017
|
||||
- Gist plug-in provides JavaScript to embed snippet
|
||||
- Dropdown menu filter in the branch comparing page
|
||||
- Caution for the embedded H2 database
|
||||
|
||||
### 4.11 - 1 Apr 2017
|
||||
- Deploy keys support
|
||||
- Auto generate avatar images
|
||||
- Collaborators of the private forked repository are copied from the original repository
|
||||
- Cache avatar images in the browser
|
||||
- New extension point to receive events about repository
|
||||
|
||||
### 4.10 - 25 Feb 2017
|
||||
- Update to Scala 2.12 and Scalatra 2.5
|
||||
- Update to Scala 2.12, Scalatra 2.5 and Slick 3.2
|
||||
- Display file size in the file viewer
|
||||
|
||||
### 4.9 - 29 Jan 2017
|
||||
|
||||
15
build.sbt
15
build.sbt
@@ -1,6 +1,6 @@
|
||||
val Organization = "io.github.gitbucket"
|
||||
val Name = "gitbucket"
|
||||
val GitBucketVersion = "4.10.0"
|
||||
val GitBucketVersion = "4.12.1"
|
||||
val ScalatraVersion = "2.5.0"
|
||||
val JettyVersion = "9.3.9.v20160517"
|
||||
|
||||
@@ -10,7 +10,7 @@ sourcesInBase := false
|
||||
organization := Organization
|
||||
name := Name
|
||||
version := GitBucketVersion
|
||||
scalaVersion := "2.12.1"
|
||||
scalaVersion := "2.12.2"
|
||||
|
||||
// dependency settings
|
||||
resolvers ++= Seq(
|
||||
@@ -21,21 +21,21 @@ resolvers ++= Seq(
|
||||
"amateras-snapshot" at "http://amateras.sourceforge.jp/mvn-snapshot/"
|
||||
)
|
||||
libraryDependencies ++= Seq(
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.6.0.201612231935-r",
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.6.0.201612231935-r",
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.http.server" % "4.7.0.201704051617-r",
|
||||
"org.eclipse.jgit" % "org.eclipse.jgit.archive" % "4.7.0.201704051617-r",
|
||||
"org.scalatra" %% "scalatra" % ScalatraVersion,
|
||||
"org.scalatra" %% "scalatra-json" % ScalatraVersion,
|
||||
"org.json4s" %% "json4s-jackson" % "3.5.0",
|
||||
"io.github.gitbucket" %% "scalatra-forms" % "1.1.0",
|
||||
"commons-io" % "commons-io" % "2.4",
|
||||
"io.github.gitbucket" % "solidbase" % "1.0.0",
|
||||
"io.github.gitbucket" % "markedj" % "1.0.9",
|
||||
"io.github.gitbucket" % "markedj" % "1.0.10",
|
||||
"org.apache.commons" % "commons-compress" % "1.11",
|
||||
"org.apache.commons" % "commons-email" % "1.4",
|
||||
"org.apache.httpcomponents" % "httpclient" % "4.5.1",
|
||||
"org.apache.sshd" % "apache-sshd" % "1.2.0",
|
||||
"org.apache.tika" % "tika-core" % "1.13",
|
||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.7",
|
||||
"com.github.takezoe" %% "blocking-slick-32" % "0.0.8",
|
||||
"joda-time" % "joda-time" % "2.9.6",
|
||||
"com.novell.ldap" % "jldap" % "2009-10-07",
|
||||
"com.h2database" % "h2" % "1.4.192",
|
||||
@@ -54,12 +54,13 @@ libraryDependencies ++= Seq(
|
||||
"javax.servlet" % "javax.servlet-api" % "3.1.0" % "provided",
|
||||
"junit" % "junit" % "4.12" % "test",
|
||||
"org.scalatra" %% "scalatra-scalatest" % ScalatraVersion % "test",
|
||||
"org.mockito" % "mockito-core" % "2.7.16" % "test",
|
||||
"com.wix" % "wix-embedded-mysql" % "2.1.4" % "test",
|
||||
"ru.yandex.qatools.embed" % "postgresql-embedded" % "1.14" % "test"
|
||||
)
|
||||
|
||||
// Compiler settings
|
||||
scalacOptions := Seq("-deprecation", "-language:postfixOps", "-Ydelambdafy:method", "-target:jvm-1.8")
|
||||
scalacOptions := Seq("-deprecation", "-language:postfixOps")
|
||||
javacOptions in compile ++= Seq("-target", "8", "-source", "8")
|
||||
javaOptions in Jetty += "-Dlogback.configurationFile=/logback-dev.xml"
|
||||
|
||||
|
||||
@@ -1,2 +0,0 @@
|
||||
%~d0
|
||||
cmd /k cd %~p0
|
||||
@@ -4,15 +4,15 @@ How to run from the source tree
|
||||
Run for Development
|
||||
--------
|
||||
|
||||
If you want to test GitBucket, input following command at the root directory of the source tree.
|
||||
If you want to test GitBucket, type the following command in the root directory of the source tree.
|
||||
|
||||
```
|
||||
$ sbt ~jetty:start
|
||||
```
|
||||
|
||||
Then access to `http://localhost:8080/` by 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 modification is detected and reloaded automatically. You can modify logging configuration by editing `src/main/resources/logback-dev.xml`.
|
||||
Source code modifications are detected and a reloaded happens automatically. You can modify the logging configuration by editing `src/main/resources/logback-dev.xml`.
|
||||
|
||||
Build war file
|
||||
--------
|
||||
@@ -23,9 +23,9 @@ To build war file, run the following command:
|
||||
$ sbt package
|
||||
```
|
||||
|
||||
`gitbucket_2.11-x.x.x.war` is generated into `target/scala-2.11`.
|
||||
`gitbucket_2.12-x.x.x.war` is generated into `target/scala-2.12`.
|
||||
|
||||
To build executable war file, run
|
||||
To build an executable war file, run
|
||||
|
||||
```
|
||||
$ sbt executable
|
||||
@@ -35,8 +35,8 @@ at the top of the source tree. It generates executable `gitbucket.war` into `tar
|
||||
|
||||
Run tests spec
|
||||
---------
|
||||
To run the full serie of tests, run the following command:
|
||||
To run the full series of tests, run the following command:
|
||||
|
||||
```
|
||||
sbt test
|
||||
$ sbt test
|
||||
```
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
Notification Email
|
||||
========
|
||||
|
||||
GitBucket sends email to target users by enabling the notification email by an administrator.
|
||||
GitBucket can send email notification to users if this feature is enabled by an administrator.
|
||||
|
||||
The timing of the notification are as follows:
|
||||
|
||||
@@ -20,4 +20,4 @@ Notified users are as follows:
|
||||
* collaborators
|
||||
* participants
|
||||
|
||||
However, the operation in person is excluded from the target.
|
||||
However, the person performing the operation is excluded from the notification.
|
||||
|
||||
@@ -8,6 +8,8 @@ import java.security.ProtectionDomain;
|
||||
|
||||
public class JettyLauncher {
|
||||
public static void main(String[] args) throws Exception {
|
||||
System.setProperty("java.awt.headless", "true");
|
||||
|
||||
String host = null;
|
||||
int port = 8080;
|
||||
InetSocketAddress address = null;
|
||||
@@ -19,19 +21,25 @@ public class JettyLauncher {
|
||||
if(arg.startsWith("--") && arg.contains("=")) {
|
||||
String[] dim = arg.split("=");
|
||||
if(dim.length >= 2) {
|
||||
if(dim[0].equals("--host")) {
|
||||
host = dim[1];
|
||||
} else if(dim[0].equals("--port")) {
|
||||
port = Integer.parseInt(dim[1]);
|
||||
} else if(dim[0].equals("--prefix")) {
|
||||
contextPath = dim[1];
|
||||
if(!contextPath.startsWith("/")){
|
||||
contextPath = "/" + contextPath;
|
||||
}
|
||||
} else if(dim[0].equals("--gitbucket.home")){
|
||||
System.setProperty("gitbucket.home", dim[1]);
|
||||
} else if(dim[0].equals("--temp_dir")){
|
||||
tmpDirPath = dim[1];
|
||||
switch (dim[0]) {
|
||||
case "--host":
|
||||
host = dim[1];
|
||||
break;
|
||||
case "--port":
|
||||
port = Integer.parseInt(dim[1]);
|
||||
break;
|
||||
case "--prefix":
|
||||
contextPath = dim[1];
|
||||
if (!contextPath.startsWith("/")) {
|
||||
contextPath = "/" + contextPath;
|
||||
}
|
||||
break;
|
||||
case "--gitbucket.home":
|
||||
System.setProperty("gitbucket.home", dim[1]);
|
||||
break;
|
||||
case "--temp_dir":
|
||||
tmpDirPath = dim[1];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
14
src/main/resources/update/gitbucket-core_4.11.xml
Normal file
14
src/main/resources/update/gitbucket-core_4.11.xml
Normal file
@@ -0,0 +1,14 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<changeSet>
|
||||
<createTable tableName="DEPLOY_KEY">
|
||||
<column name="USER_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="REPOSITORY_NAME" type="varchar(100)" nullable="false"/>
|
||||
<column name="DEPLOY_KEY_ID" type="int" nullable="false" autoIncrement="true" unique="true"/>
|
||||
<column name="TITLE" type="varchar(100)" nullable="false"/>
|
||||
<column name="PUBLIC_KEY" type="text" nullable="false"/>
|
||||
<column name="ALLOW_WRITE" type="boolean" nullable="false" defaultValueBoolean="false"/>
|
||||
</createTable>
|
||||
|
||||
<addPrimaryKey constraintName="IDX_DEPLOY_KEY_PK" tableName="DEPLOY_KEY" columnNames="USER_NAME, REPOSITORY_NAME, DEPLOY_KEY_ID"/>
|
||||
<addForeignKeyConstraint constraintName="IDX_DEPLOY_KEY_FK0" baseTableName="DEPLOY_KEY" baseColumnNames="USER_NAME, REPOSITORY_NAME" referencedTableName="REPOSITORY" referencedColumnNames="USER_NAME, REPOSITORY_NAME"/>
|
||||
</changeSet>
|
||||
@@ -28,5 +28,10 @@ object GitBucketCoreModule extends Module("gitbucket-core",
|
||||
new Version("4.9.0",
|
||||
new LiquibaseMigration("update/gitbucket-core_4.9.xml")
|
||||
),
|
||||
new Version("4.10.0")
|
||||
new Version("4.10.0"),
|
||||
new Version("4.11.0",
|
||||
new LiquibaseMigration("update/gitbucket-core_4.11.xml")
|
||||
),
|
||||
new Version("4.12.0"),
|
||||
new Version("4.12.1")
|
||||
)
|
||||
|
||||
@@ -8,7 +8,7 @@ import gitbucket.core.util.RepositoryName
|
||||
*/
|
||||
case class ApiBranch(
|
||||
name: String,
|
||||
// commit: ApiBranchCommit,
|
||||
commit: ApiBranchCommit,
|
||||
protection: ApiBranchProtection)(repositoryName:RepositoryName) extends FieldSerializable {
|
||||
def _links = Map(
|
||||
"self" -> ApiPath(s"/api/v3/repos/${repositoryName.fullName}/branches/${name}"),
|
||||
|
||||
@@ -1,18 +1,28 @@
|
||||
package gitbucket.core.api
|
||||
|
||||
import gitbucket.core.util.JGitUtil.FileInfo
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import java.util.Base64
|
||||
|
||||
case class ApiContents(`type`: String, name: String, content: Option[String], encoding: Option[String])
|
||||
import gitbucket.core.util.JGitUtil.FileInfo
|
||||
import gitbucket.core.util.RepositoryName
|
||||
|
||||
case class ApiContents(
|
||||
`type`: String,
|
||||
name: String,
|
||||
path: String,
|
||||
sha: String,
|
||||
content: Option[String],
|
||||
encoding: Option[String])(repositoryName: RepositoryName){
|
||||
val download_url = ApiPath(s"/api/v3/repos/${repositoryName.fullName}/raw/${sha}/${path}")
|
||||
}
|
||||
|
||||
object ApiContents{
|
||||
def apply(fileInfo: FileInfo, content: Option[Array[Byte]]): ApiContents = {
|
||||
def apply(fileInfo: FileInfo, repositoryName: RepositoryName, content: Option[Array[Byte]]): ApiContents = {
|
||||
if(fileInfo.isDirectory) {
|
||||
ApiContents("dir", fileInfo.name, None, None)
|
||||
ApiContents("dir", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName)
|
||||
} else {
|
||||
content.map(arr =>
|
||||
ApiContents("file", fileInfo.name, Some(Base64.encodeBase64String(arr)), Some("base64"))
|
||||
).getOrElse(ApiContents("file", fileInfo.name, None, None))
|
||||
ApiContents("file", fileInfo.name, fileInfo.path, fileInfo.commitId, Some(Base64.getEncoder.encodeToString(arr)), Some("base64"))(repositoryName)
|
||||
).getOrElse(ApiContents("file", fileInfo.name, fileInfo.path, fileInfo.commitId, None, None)(repositoryName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,8 +19,8 @@ case class CreateAStatus(
|
||||
def isValid: Boolean = {
|
||||
CommitState.valueOf(state).isDefined &&
|
||||
// only http
|
||||
target_url.filterNot(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length<255).isEmpty &&
|
||||
context.filterNot(f => f.length<255).isEmpty &&
|
||||
description.filterNot(f => f.length<1000).isEmpty
|
||||
target_url.forall(f => "\\Ahttps?://".r.findPrefixOf(f).isDefined && f.length < 255) &&
|
||||
context.forall(f => f.length < 255) &&
|
||||
description.forall(f => f.length < 1000)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,7 @@ object JsonFormat {
|
||||
FieldSerializer[ApiPullRequest.Commit]() +
|
||||
FieldSerializer[ApiIssue]() +
|
||||
FieldSerializer[ApiComment]() +
|
||||
FieldSerializer[ApiContents]() +
|
||||
FieldSerializer[ApiLabel]() +
|
||||
ApiBranchProtection.enforcementLevelSerializer
|
||||
|
||||
|
||||
@@ -2,15 +2,15 @@ package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.account.html
|
||||
import gitbucket.core.helper
|
||||
import gitbucket.core.model.GroupMember
|
||||
import gitbucket.core.model.{GroupMember, Role}
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.ssh.SshUtil
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util._
|
||||
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.scalatra.i18n.Messages
|
||||
@@ -60,31 +60,31 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
val sshKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim(label("Key" , text(required, validPublicKey)))
|
||||
"publicKey" -> trim2(label("Key" , text(required, validPublicKey)))
|
||||
)(SshKeyForm.apply)
|
||||
|
||||
val personalTokenForm = mapping(
|
||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||
"note" -> trim(label("Token", text(required, maxlength(100))))
|
||||
)(PersonalTokenForm.apply)
|
||||
|
||||
case class NewGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String], members: String)
|
||||
case class EditGroupForm(groupName: String, description: Option[String], url: Option[String], fileId: Option[String], members: String, clearImage: Boolean)
|
||||
|
||||
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))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||
"members" -> trim(label("Members" ,text(required, members)))
|
||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||
"members" -> trim(label("Members" ,text(required, members)))
|
||||
)(NewGroupForm.apply)
|
||||
|
||||
val editGroupForm = mapping(
|
||||
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier))),
|
||||
"groupName" -> trim(label("Group name" ,text(required, maxlength(100), identifier))),
|
||||
"description" -> trim(label("Group description", optional(text()))),
|
||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||
"members" -> trim(label("Members" ,text(required, members))),
|
||||
"clearImage" -> trim(label("Clear image" ,boolean()))
|
||||
"url" -> trim(label("URL" ,optional(text(maxlength(200))))),
|
||||
"fileId" -> trim(label("File ID" ,optional(text()))),
|
||||
"members" -> trim(label("Members" ,text(required, members))),
|
||||
"clearImage" -> trim(label("Clear image" ,boolean()))
|
||||
)(EditGroupForm.apply)
|
||||
|
||||
case class RepositoryCreationForm(owner: String, name: String, description: Option[String], isPrivate: Boolean, createReadme: Boolean)
|
||||
@@ -149,10 +149,20 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
get("/:userName/_avatar"){
|
||||
val userName = params("userName")
|
||||
getAccountByUserName(userName).flatMap(_.image).map { image =>
|
||||
RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image))
|
||||
} getOrElse {
|
||||
contentType = "image/png"
|
||||
contentType = "image/png"
|
||||
getAccountByUserName(userName).flatMap{ account =>
|
||||
response.setDateHeader("Last-Modified", account.updatedDate.getTime)
|
||||
account.image.map{ image =>
|
||||
Some(RawData(FileUtil.getMimeType(image), new java.io.File(getUserUploadDir(userName), image)))
|
||||
}.getOrElse{
|
||||
if (account.isGroupAccount) {
|
||||
TextAvatarUtil.textGroupAvatar(account.fullName)
|
||||
} else {
|
||||
TextAvatarUtil.textAvatar(account.fullName)
|
||||
}
|
||||
}
|
||||
}.getOrElse{
|
||||
response.setHeader("Cache-Control", "max-age=3600")
|
||||
Thread.currentThread.getContextClassLoader.getResourceAsStream("noimage.png")
|
||||
}
|
||||
}
|
||||
@@ -352,12 +362,16 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
post("/new", newRepositoryForm)(usersOnly { form =>
|
||||
LockUtil.lock(s"${form.owner}/${form.name}"){
|
||||
if(getRepository(form.owner, form.name).isEmpty){
|
||||
// Create the repository
|
||||
createRepository(context.loginAccount.get, form.owner, form.name, form.description, form.isPrivate, form.createReadme)
|
||||
}
|
||||
|
||||
// redirect to the repository
|
||||
redirect(s"/${form.owner}/${form.name}")
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.created(form.owner, form.name))
|
||||
}
|
||||
}
|
||||
|
||||
// redirect to the repository
|
||||
redirect(s"/${form.owner}/${form.name}")
|
||||
})
|
||||
|
||||
get("/:owner/:repository/fork")(readableUsersOnly { repository =>
|
||||
@@ -407,13 +421,15 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
parentUserName = Some(repository.owner)
|
||||
)
|
||||
|
||||
// // Add collaborators for group repository
|
||||
// val ownerAccount = getAccountByUserName(accountName).get
|
||||
// if(ownerAccount.isGroupAccount){
|
||||
// getGroupMembers(accountName).foreach { member =>
|
||||
// addCollaborator(accountName, repository.name, member.userName)
|
||||
// }
|
||||
// }
|
||||
// Set default collaborators for the private fork
|
||||
if(repository.repository.isPrivate){
|
||||
// Copy collaborators from the source repository
|
||||
getCollaborators(repository.owner, repository.name).foreach { case (collaborator, _) =>
|
||||
addCollaborator(accountName, repository.name, collaborator.collaboratorName, collaborator.role)
|
||||
}
|
||||
// Register an owner of the source repository as a collaborator
|
||||
addCollaborator(accountName, repository.name, repository.owner, Role.ADMIN.name)
|
||||
}
|
||||
|
||||
// Insert default labels
|
||||
insertDefaultLabels(accountName, repository.name)
|
||||
@@ -430,6 +446,10 @@ trait AccountControllerBase extends AccountManagementControllerBase {
|
||||
|
||||
// Record activity
|
||||
recordForkActivity(repository.owner, repository.name, loginUserName, accountName)
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.forked(repository.owner, accountName, repository.name))
|
||||
|
||||
// redirect to the repository
|
||||
redirect(s"/${accountName}/${repository.name}")
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import gitbucket.core.model._
|
||||
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
||||
import gitbucket.core.service.PullRequestService._
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.JGitUtil._
|
||||
import gitbucket.core.util._
|
||||
@@ -84,9 +84,10 @@ trait ApiControllerBase extends ControllerBase {
|
||||
|
||||
/**
|
||||
* https://developer.github.com/v3/users/#get-a-single-user
|
||||
* This API also returns group information (as GitHub).
|
||||
*/
|
||||
get("/api/v3/users/:userName") {
|
||||
getAccountByUserName(params("userName")).filterNot(account => account.isGroupAccount).map { account =>
|
||||
getAccountByUserName(params("userName")).map { account =>
|
||||
JsonFormat(ApiUser(account))
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
@@ -118,6 +119,20 @@ trait ApiControllerBase extends ControllerBase {
|
||||
})
|
||||
})
|
||||
|
||||
/**
|
||||
* https://developer.github.com/v3/repos/branches/#get-branch
|
||||
*/
|
||||
get ("/api/v3/repos/:owner/:repo/branches/:branch")(referrersOnly { repository =>
|
||||
//import gitbucket.core.api._
|
||||
(for{
|
||||
branch <- params.get("branch") if repository.branchList.contains(branch)
|
||||
br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch)
|
||||
} yield {
|
||||
val protection = getProtectedBranchInfo(repository.owner, repository.name, branch)
|
||||
JsonFormat(ApiBranch(branch, ApiBranchCommit(br.commitId), ApiBranchProtection(protection))(RepositoryName(repository)))
|
||||
}) getOrElse NotFound()
|
||||
})
|
||||
|
||||
/*
|
||||
* https://developer.github.com/v3/repos/contents/#get-contents
|
||||
*/
|
||||
@@ -169,11 +184,11 @@ trait ApiControllerBase extends ControllerBase {
|
||||
)
|
||||
}
|
||||
case _ =>
|
||||
Some(JsonFormat(ApiContents(f, content)))
|
||||
Some(JsonFormat(ApiContents(f, RepositoryName(repository), content)))
|
||||
}
|
||||
}).getOrElse(NotFound())
|
||||
} else { // directory
|
||||
JsonFormat(fileList.map{f => ApiContents(f, None)})
|
||||
JsonFormat(fileList.map{f => ApiContents(f, RepositoryName(repository), None)})
|
||||
}
|
||||
}
|
||||
})
|
||||
@@ -272,15 +287,16 @@ trait ApiControllerBase extends ControllerBase {
|
||||
patch("/api/v3/repos/:owner/:repo/branches/:branch")(ownerOnly { repository =>
|
||||
import gitbucket.core.api._
|
||||
(for{
|
||||
branch <- params.get("branch") if repository.branchList.find(_ == branch).isDefined
|
||||
branch <- params.get("branch") if repository.branchList.contains(branch)
|
||||
protection <- extractFromJsonBody[ApiBranchProtection.EnablingAndDisabling].map(_.protection)
|
||||
br <- getBranches(repository.owner, repository.name, repository.repository.defaultBranch, repository.repository.originUserName.isEmpty).find(_.name == branch)
|
||||
} yield {
|
||||
if(protection.enabled){
|
||||
enableBranchProtection(repository.owner, repository.name, branch, protection.status.enforcement_level == ApiBranchProtection.Everyone, protection.status.contexts)
|
||||
} else {
|
||||
disableBranchProtection(repository.owner, repository.name, branch)
|
||||
}
|
||||
JsonFormat(ApiBranch(branch, protection)(RepositoryName(repository)))
|
||||
JsonFormat(ApiBranch(branch, ApiBranchCommit(br.commitId), protection)(RepositoryName(repository)))
|
||||
}) getOrElse NotFound()
|
||||
})
|
||||
|
||||
@@ -611,5 +627,19 @@ trait ApiControllerBase extends ControllerBase {
|
||||
private def isEditable(owner: String, repository: String, author: String)(implicit context: Context): Boolean =
|
||||
hasDeveloperRole(owner, repository, context.loginAccount) || author == context.loginAccount.get.userName
|
||||
|
||||
/**
|
||||
* non-GitHub compatible API for Jenkins-Plugin
|
||||
*/
|
||||
get("/api/v3/repos/:owner/:repo/raw/*")(referrersOnly { repository =>
|
||||
val (id, path) = repository.splitPath(multiParams("splat").head)
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(id))
|
||||
|
||||
getPathObjectId(git, path, revCommit).map { objectId =>
|
||||
responseRawFile(git, objectId, path, repository)
|
||||
} getOrElse NotFound()
|
||||
}
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,26 +1,31 @@
|
||||
package gitbucket.core.controller
|
||||
|
||||
import java.io.FileInputStream
|
||||
|
||||
import gitbucket.core.api.ApiError
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.{AccountService, SystemSettingsService}
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.service.{AccountService, SystemSettingsService,RepositoryService}
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
|
||||
import gitbucket.core.util.JGitUtil._
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
import org.json4s._
|
||||
import org.scalatra._
|
||||
import org.scalatra.i18n._
|
||||
import org.scalatra.json._
|
||||
|
||||
import javax.servlet.http.{HttpServletResponse, HttpServletRequest}
|
||||
import javax.servlet.{FilterChain, ServletResponse, ServletRequest}
|
||||
import javax.servlet.http.{HttpServletRequest, HttpServletResponse}
|
||||
import javax.servlet.{FilterChain, ServletRequest, ServletResponse}
|
||||
|
||||
import scala.util.Try
|
||||
|
||||
import net.coobird.thumbnailator.Thumbnails
|
||||
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import org.eclipse.jgit.revwalk.RevCommit
|
||||
import org.eclipse.jgit.treewalk._
|
||||
import org.apache.commons.io.IOUtils
|
||||
|
||||
/**
|
||||
* Provides generic features for controller implementations.
|
||||
@@ -35,10 +40,6 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
contentType = formats("json")
|
||||
}
|
||||
|
||||
// TODO Scala 2.11
|
||||
// // Don't set content type via Accept header.
|
||||
// override def format(implicit request: HttpServletRequest) = ""
|
||||
|
||||
override def doFilter(request: ServletRequest, response: ServletResponse, chain: FilterChain): Unit = try {
|
||||
val httpRequest = request.asInstanceOf[HttpServletRequest]
|
||||
val httpResponse = response.asInstanceOf[HttpServletResponse]
|
||||
@@ -146,7 +147,6 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
}
|
||||
}
|
||||
|
||||
// TODO Scala 2.11
|
||||
override def url(path: String, params: Iterable[(String, Any)] = Iterable.empty,
|
||||
includeContextPath: Boolean = true, includeServletPath: Boolean = true,
|
||||
absolutize: Boolean = true, withSessionId: Boolean = true)
|
||||
@@ -154,6 +154,18 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
if (path.startsWith("http")) path
|
||||
else baseUrl + super.url(path, params, false, false, false)
|
||||
|
||||
/**
|
||||
* Extends scalatra-form's trim rule to eliminate CR and LF.
|
||||
*/
|
||||
protected def trim2[T](valueType: SingleValueType[T]): SingleValueType[T] = new SingleValueType[T](){
|
||||
def convert(value: String, messages: Messages): T = valueType.convert(trim(value), messages)
|
||||
|
||||
override def validate(name: String, value: String, params: Map[String, String], messages: Messages): Seq[(String, String)] =
|
||||
valueType.validate(name, trim(value), params, messages)
|
||||
|
||||
private def trim(value: String): String = if(value == null) null else value.replaceAll("\r\n", "").trim
|
||||
}
|
||||
|
||||
/**
|
||||
* Use this method to response the raw data against XSS.
|
||||
*/
|
||||
@@ -175,6 +187,49 @@ abstract class ControllerBase extends ScalatraFilter
|
||||
case _ => Some(parse(request.body))
|
||||
}).filterNot(_ == JNothing).flatMap(j => Try(j.extract[A]).toOption)
|
||||
}
|
||||
|
||||
protected def getPathObjectId(git: Git, path: String, revCommit: RevCommit): Option[ObjectId] = {
|
||||
@scala.annotation.tailrec
|
||||
def _getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] = walk.next match {
|
||||
case true if(walk.getPathString == path) => Some(walk.getObjectId(0))
|
||||
case true => _getPathObjectId(path, walk)
|
||||
case false => None
|
||||
}
|
||||
|
||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
_getPathObjectId(path, treeWalk)
|
||||
}
|
||||
}
|
||||
|
||||
protected def responseRawFile(git: Git, objectId: ObjectId, path: String,
|
||||
repository: RepositoryService.RepositoryInfo): Unit = {
|
||||
JGitUtil.getObjectLoaderFromId(git, objectId){ loader =>
|
||||
contentType = FileUtil.getMimeType(path)
|
||||
|
||||
if(loader.isLarge){
|
||||
response.setContentLength(loader.getSize.toInt)
|
||||
loader.copyTo(response.outputStream)
|
||||
} else {
|
||||
val bytes = loader.getCachedBytes
|
||||
val text = new String(bytes, "UTF-8")
|
||||
|
||||
val attrs = JGitUtil.getLfsObjects(text)
|
||||
if(attrs.nonEmpty) {
|
||||
response.setContentLength(attrs("size").toInt)
|
||||
val oid = attrs("oid").split(":")(1)
|
||||
|
||||
using(new FileInputStream(FileUtil.getLfsFilePath(repository.owner, repository.name, oid))){ in =>
|
||||
IOUtils.copy(in, response.getOutputStream)
|
||||
}
|
||||
} else {
|
||||
response.setContentLength(loader.getSize.toInt)
|
||||
response.getOutputStream.write(bytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -5,7 +5,7 @@ import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.{AccountService, RepositoryService}
|
||||
import gitbucket.core.servlet.Database
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import org.eclipse.jgit.api.Git
|
||||
|
||||
@@ -4,13 +4,13 @@ import gitbucket.core.helper.xml
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.{Keys, LDAPUtil, ReferrerAuthenticator, UsersAuthenticator}
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
import org.scalatra.Ok
|
||||
|
||||
|
||||
class IndexController extends IndexControllerBase
|
||||
class IndexController extends IndexControllerBase
|
||||
with RepositoryService with ActivityService with AccountService with RepositorySearchService with IssuesService
|
||||
with UsersAuthenticator with ReferrerAuthenticator
|
||||
|
||||
@@ -26,13 +26,13 @@ trait IndexControllerBase extends ControllerBase {
|
||||
"password" -> trim(label("Password", text(required)))
|
||||
)(SignInForm.apply)
|
||||
|
||||
val searchForm = mapping(
|
||||
"query" -> trim(text(required)),
|
||||
"owner" -> trim(text(required)),
|
||||
"repository" -> trim(text(required))
|
||||
)(SearchForm.apply)
|
||||
|
||||
case class SearchForm(query: String, owner: String, repository: String)
|
||||
// val searchForm = mapping(
|
||||
// "query" -> trim(text(required)),
|
||||
// "owner" -> trim(text(required)),
|
||||
// "repository" -> trim(text(required))
|
||||
// )(SearchForm.apply)
|
||||
//
|
||||
// case class SearchForm(query: String, owner: String, repository: String)
|
||||
|
||||
|
||||
get("/"){
|
||||
@@ -163,7 +163,7 @@ trait IndexControllerBase extends ControllerBase {
|
||||
|
||||
get("/search"){
|
||||
val query = params.getOrElse("query", "").trim.toLowerCase
|
||||
val visibleRepositories = getVisibleRepositories(context.loginAccount, None)
|
||||
val visibleRepositories = getVisibleRepositories(context.loginAccount, repositoryUserName = None, withoutPhysicalInfo = true)
|
||||
val repositories = visibleRepositories.filter { repository =>
|
||||
repository.name.toLowerCase.indexOf(query) >= 0 || repository.owner.toLowerCase.indexOf(query) >= 0
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ package gitbucket.core.controller
|
||||
import gitbucket.core.issues.html
|
||||
import gitbucket.core.service.IssuesService._
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.view
|
||||
|
||||
@@ -8,7 +8,7 @@ import gitbucket.core.service.IssuesService._
|
||||
import gitbucket.core.service.PullRequestService._
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
@@ -420,65 +420,61 @@ trait PullRequestsControllerBase extends ControllerBase {
|
||||
post("/:owner/:repository/pulls/new", pullRequestForm)(readableUsersOnly { (form, repository) =>
|
||||
defining(repository.owner, repository.name){ case (owner, name) =>
|
||||
val manageable = isManageable(repository)
|
||||
val editable = isEditable(repository)
|
||||
val loginUserName = context.loginAccount.get.userName
|
||||
|
||||
if(editable) {
|
||||
val loginUserName = context.loginAccount.get.userName
|
||||
val issueId = insertIssue(
|
||||
owner = repository.owner,
|
||||
repository = repository.name,
|
||||
loginUser = loginUserName,
|
||||
title = form.title,
|
||||
content = form.content,
|
||||
assignedUserName = if (manageable) form.assignedUserName else None,
|
||||
milestoneId = if (manageable) form.milestoneId else None,
|
||||
isPullRequest = true)
|
||||
|
||||
val issueId = insertIssue(
|
||||
owner = repository.owner,
|
||||
repository = repository.name,
|
||||
loginUser = loginUserName,
|
||||
title = form.title,
|
||||
content = form.content,
|
||||
assignedUserName = if (manageable) form.assignedUserName else None,
|
||||
milestoneId = if (manageable) form.milestoneId else None,
|
||||
isPullRequest = true)
|
||||
createPullRequest(
|
||||
originUserName = repository.owner,
|
||||
originRepositoryName = repository.name,
|
||||
issueId = issueId,
|
||||
originBranch = form.targetBranch,
|
||||
requestUserName = form.requestUserName,
|
||||
requestRepositoryName = form.requestRepositoryName,
|
||||
requestBranch = form.requestBranch,
|
||||
commitIdFrom = form.commitIdFrom,
|
||||
commitIdTo = form.commitIdTo)
|
||||
|
||||
createPullRequest(
|
||||
originUserName = repository.owner,
|
||||
originRepositoryName = repository.name,
|
||||
issueId = issueId,
|
||||
originBranch = form.targetBranch,
|
||||
requestUserName = form.requestUserName,
|
||||
requestRepositoryName = form.requestRepositoryName,
|
||||
requestBranch = form.requestBranch,
|
||||
commitIdFrom = form.commitIdFrom,
|
||||
commitIdTo = form.commitIdTo)
|
||||
|
||||
// insert labels
|
||||
if (manageable) {
|
||||
form.labelNames.map { value =>
|
||||
val labels = getLabels(owner, name)
|
||||
value.split(",").foreach { labelName =>
|
||||
labels.find(_.labelName == labelName).map { label =>
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
||||
}
|
||||
// insert labels
|
||||
if (manageable) {
|
||||
form.labelNames.map { value =>
|
||||
val labels = getLabels(owner, name)
|
||||
value.split(",").foreach { labelName =>
|
||||
labels.find(_.labelName == labelName).map { label =>
|
||||
registerIssueLabel(repository.owner, repository.name, issueId, label.labelId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// fetch requested branch
|
||||
fetchAsPullRequest(owner, name, form.requestUserName, form.requestRepositoryName, form.requestBranch, issueId)
|
||||
// fetch requested branch
|
||||
fetchAsPullRequest(owner, name, form.requestUserName, form.requestRepositoryName, form.requestBranch, issueId)
|
||||
|
||||
// record activity
|
||||
recordPullRequestActivity(owner, name, loginUserName, issueId, form.title)
|
||||
// record activity
|
||||
recordPullRequestActivity(owner, name, loginUserName, issueId, form.title)
|
||||
|
||||
// call web hook
|
||||
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||
// call web hook
|
||||
callPullRequestWebHook("opened", repository, issueId, context.baseUrl, context.loginAccount.get)
|
||||
|
||||
getIssue(owner, name, issueId.toString) foreach { issue =>
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""), context.loginAccount.get)
|
||||
getIssue(owner, name, issueId.toString) foreach { issue =>
|
||||
// extract references and create refer comment
|
||||
createReferComment(owner, name, issue, form.title + " " + form.content.getOrElse(""), context.loginAccount.get)
|
||||
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issue, form.content.getOrElse("")) {
|
||||
Notifier.msgPullRequest(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
|
||||
}
|
||||
// notifications
|
||||
Notifier().toNotify(repository, issue, form.content.getOrElse("")) {
|
||||
Notifier.msgPullRequest(s"${context.baseUrl}/${owner}/${name}/pull/${issueId}")
|
||||
}
|
||||
}
|
||||
|
||||
redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||
} else Unauthorized()
|
||||
redirect(s"/${owner}/${name}/pull/${issueId}")
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
@@ -2,11 +2,11 @@ package gitbucket.core.controller
|
||||
|
||||
import gitbucket.core.settings.html
|
||||
import gitbucket.core.model.WebHook
|
||||
import gitbucket.core.service.{RepositoryService, AccountService, WebHookService, ProtectedBranchService, CommitStatusService}
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.service.WebHookService._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.JGitUtil._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
@@ -16,14 +16,15 @@ import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
import org.eclipse.jgit.lib.ObjectId
|
||||
import gitbucket.core.model.WebHookContentType
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
|
||||
|
||||
class RepositorySettingsController extends RepositorySettingsControllerBase
|
||||
with RepositoryService with AccountService with WebHookService with ProtectedBranchService with CommitStatusService
|
||||
with RepositoryService with AccountService with WebHookService with ProtectedBranchService with CommitStatusService with DeployKeyService
|
||||
with OwnerAuthenticator with UsersAuthenticator
|
||||
|
||||
trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
self: RepositoryService with AccountService with WebHookService with ProtectedBranchService with CommitStatusService
|
||||
self: RepositoryService with AccountService with WebHookService with ProtectedBranchService with CommitStatusService with DeployKeyService
|
||||
with OwnerAuthenticator with UsersAuthenticator =>
|
||||
|
||||
// for repository options
|
||||
@@ -37,9 +38,9 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
externalWikiUrl: Option[String],
|
||||
allowFork: Boolean
|
||||
)
|
||||
|
||||
|
||||
val optionsForm = mapping(
|
||||
"repositoryName" -> trim(label("Repository Name" , text(required, maxlength(100), identifier, renameRepositoryName))),
|
||||
"repositoryName" -> trim(label("Repository Name" , text(required, maxlength(100), repository, renameRepositoryName))),
|
||||
"description" -> trim(label("Description" , optional(text()))),
|
||||
"isPrivate" -> trim(label("Repository Type" , boolean())),
|
||||
"issuesOption" -> trim(label("Issues Option" , text(required, featureOption))),
|
||||
@@ -56,12 +57,15 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
"defaultBranch" -> trim(label("Default Branch" , text(required, maxlength(100))))
|
||||
)(DefaultBranchForm.apply)
|
||||
|
||||
// // for collaborator addition
|
||||
// case class CollaboratorForm(userName: String)
|
||||
//
|
||||
// val collaboratorForm = mapping(
|
||||
// "userName" -> trim(label("Username", text(required, collaborator)))
|
||||
// )(CollaboratorForm.apply)
|
||||
|
||||
// for deploy key
|
||||
case class DeployKeyForm(title: String, publicKey: String, allowWrite: Boolean)
|
||||
|
||||
val deployKeyForm = mapping(
|
||||
"title" -> trim(label("Title", text(required, maxlength(100)))),
|
||||
"publicKey" -> trim2(label("Key" , text(required))), // TODO duplication check in the repository?
|
||||
"allowWrite" -> trim(label("Key" , boolean()))
|
||||
)(DeployKeyForm.apply)
|
||||
|
||||
// for web hook url addition
|
||||
case class WebHookForm(url: String, events: Set[WebHook.Event], ctype: WebHookContentType, token: Option[String])
|
||||
@@ -88,14 +92,14 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
get("/:owner/:repository/settings")(ownerOnly { repository =>
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Display the Options page.
|
||||
*/
|
||||
get("/:owner/:repository/settings/options")(ownerOnly {
|
||||
html.options(_, flash.get("info"))
|
||||
})
|
||||
|
||||
|
||||
/**
|
||||
* Save the repository options.
|
||||
*/
|
||||
@@ -135,8 +139,17 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
FileUtils.moveDirectory(dir, getLfsDir(repository.owner, form.repositoryName))
|
||||
}
|
||||
}
|
||||
// Move attached directory
|
||||
defining(getAttachedDir(repository.owner, repository.name)){ dir =>
|
||||
if(dir.isDirectory) {
|
||||
FileUtils.moveDirectory(dir, getAttachedDir(repository.owner, form.repositoryName))
|
||||
}
|
||||
}
|
||||
// Delete parent directory
|
||||
FileUtil.deleteDirectoryIfEmpty(getRepositoryFilesDir(repository.owner, repository.name))
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.renamed(repository.owner, repository.name, form.repositoryName))
|
||||
}
|
||||
flash += "info" -> "Repository settings has been updated."
|
||||
redirect(s"/${repository.owner}/${form.repositoryName}/settings/options")
|
||||
@@ -150,7 +163,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
|
||||
/** Update default branch */
|
||||
post("/:owner/:repository/settings/update_default_branch", defaultBranchForm)(ownerOnly { (form, repository) =>
|
||||
if(repository.branchList.find(_ == form.defaultBranch).isEmpty){
|
||||
if(!repository.branchList.contains(form.defaultBranch)){
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/options")
|
||||
} else {
|
||||
saveRepositoryDefaultBranch(repository.owner, repository.name, form.defaultBranch)
|
||||
@@ -167,7 +180,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
get("/:owner/:repository/settings/branches/:branch")(ownerOnly { repository =>
|
||||
import gitbucket.core.api._
|
||||
val branch = params("branch")
|
||||
if(repository.branchList.find(_ == branch).isEmpty){
|
||||
if(!repository.branchList.contains(branch)){
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/branches")
|
||||
} else {
|
||||
val protection = ApiBranchProtection(getProtectedBranchInfo(repository.owner, repository.name, branch))
|
||||
@@ -345,8 +358,17 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
FileUtils.moveDirectory(dir, getLfsDir(form.newOwner, repository.name))
|
||||
}
|
||||
}
|
||||
// Move attached directory
|
||||
defining(getAttachedDir(repository.owner, repository.name)){ dir =>
|
||||
if(dir.isDirectory) {
|
||||
FileUtils.moveDirectory(dir, getAttachedDir(form.newOwner, repository.name))
|
||||
}
|
||||
}
|
||||
// Delere parent directory
|
||||
FileUtil.deleteDirectoryIfEmpty(getRepositoryFilesDir(repository.owner, repository.name))
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.transferred(repository.owner, form.newOwner, repository.name))
|
||||
}
|
||||
}
|
||||
redirect(s"/${form.newOwner}/${repository.name}")
|
||||
@@ -357,6 +379,7 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
*/
|
||||
post("/:owner/:repository/settings/delete")(ownerOnly { repository =>
|
||||
LockUtil.lock(s"${repository.owner}/${repository.name}"){
|
||||
// Delete the repository and related files
|
||||
deleteRepository(repository.owner, repository.name)
|
||||
|
||||
FileUtils.deleteDirectory(getRepositoryDir(repository.owner, repository.name))
|
||||
@@ -365,7 +388,11 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
val lfsDir = getLfsDir(repository.owner, repository.name)
|
||||
FileUtils.deleteDirectory(lfsDir)
|
||||
FileUtil.deleteDirectoryIfEmpty(lfsDir.getParentFile())
|
||||
|
||||
// Call hooks
|
||||
PluginRegistry().getRepositoryHooks.foreach(_.deleted(repository.owner, repository.name))
|
||||
}
|
||||
|
||||
redirect(s"/${repository.owner}")
|
||||
})
|
||||
|
||||
@@ -382,6 +409,24 @@ trait RepositorySettingsControllerBase extends ControllerBase {
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/danger")
|
||||
})
|
||||
|
||||
/** List deploy keys */
|
||||
get("/:owner/:repository/settings/deploykey")(ownerOnly { repository =>
|
||||
html.deploykey(repository, getDeployKeys(repository.owner, repository.name))
|
||||
})
|
||||
|
||||
/** Register a deploy key */
|
||||
post("/:owner/:repository/settings/deploykey", deployKeyForm)(ownerOnly { (form, repository) =>
|
||||
addDeployKey(repository.owner, repository.name, form.title, form.publicKey, form.allowWrite)
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
||||
})
|
||||
|
||||
/** Delete a deploy key */
|
||||
get("/:owner/:repository/settings/deploykey/delete/:id")(ownerOnly { repository =>
|
||||
val deployKeyId = params("id").toInt
|
||||
deleteDeployKey(repository.owner, repository.name, deployKeyId)
|
||||
redirect(s"/${repository.owner}/${repository.name}/settings/deploykey")
|
||||
})
|
||||
|
||||
/**
|
||||
* Provides duplication check for web hook url.
|
||||
*/
|
||||
|
||||
@@ -10,7 +10,7 @@ import gitbucket.core.service._
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.JGitUtil._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.model.{Account, WebHook}
|
||||
@@ -232,7 +232,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
oldFileName = form.oldFileName,
|
||||
content = appendNewLine(convertLineSeparator(form.content, form.lineSeparator), form.lineSeparator),
|
||||
charset = form.charset,
|
||||
message = if(form.oldFileName.exists(_ == form.newFileName)){
|
||||
message = if(form.oldFileName.contains(form.newFileName)){
|
||||
form.message.getOrElse(s"Update ${form.newFileName}")
|
||||
} else {
|
||||
form.message.getOrElse(s"Rename ${form.oldFileName.get} to ${form.newFileName}")
|
||||
@@ -296,34 +296,6 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}.getOrElse(false)
|
||||
}
|
||||
|
||||
private def responseRawFile(git: Git, objectId: ObjectId, path: String,
|
||||
repository: RepositoryService.RepositoryInfo): Unit = {
|
||||
JGitUtil.getObjectLoaderFromId(git, objectId){ loader =>
|
||||
contentType = FileUtil.getMimeType(path)
|
||||
|
||||
if(loader.isLarge){
|
||||
response.setContentLength(loader.getSize.toInt)
|
||||
loader.copyTo(response.outputStream)
|
||||
} else {
|
||||
val bytes = loader.getCachedBytes
|
||||
val text = new String(bytes, "UTF-8")
|
||||
|
||||
val attrs = JGitUtil.getLfsObjects(text)
|
||||
if(attrs.nonEmpty) {
|
||||
response.setContentLength(attrs("size").toInt)
|
||||
val oid = attrs("oid").split(":")(1)
|
||||
|
||||
using(new FileInputStream(FileUtil.getLfsFilePath(repository.owner, repository.name, oid))){ in =>
|
||||
IOUtils.copy(in, response.getOutputStream)
|
||||
}
|
||||
} else {
|
||||
response.setContentLength(loader.getSize.toInt)
|
||||
response.getOutputStream.write(bytes)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
get("/:owner/:repository/blame/*"){
|
||||
blobRoute.action()
|
||||
}
|
||||
@@ -642,7 +614,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
val permission = JGitUtil.processTree(git, headTip){ (path, tree) =>
|
||||
// Add all entries except the editing file
|
||||
if(!newPath.exists(_ == path) && !oldPath.exists(_ == path)){
|
||||
if(!newPath.contains(path) && !oldPath.contains(path)){
|
||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||
}
|
||||
// Retrieve permission if file exists to keep it
|
||||
@@ -696,29 +668,15 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
|
||||
private def getPathObjectId(git: Git, path: String, revCommit: RevCommit): Option[ObjectId] = {
|
||||
@scala.annotation.tailrec
|
||||
def _getPathObjectId(path: String, walk: TreeWalk): Option[ObjectId] = walk.next match {
|
||||
case true if(walk.getPathString == path) => Some(walk.getObjectId(0))
|
||||
case true => _getPathObjectId(path, walk)
|
||||
case false => None
|
||||
}
|
||||
|
||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
treeWalk.setRecursive(true)
|
||||
_getPathObjectId(path, treeWalk)
|
||||
}
|
||||
}
|
||||
|
||||
private def archiveRepository(name: String, suffix: String, repository: RepositoryService.RepositoryInfo): Unit = {
|
||||
val revision = name.stripSuffix(suffix)
|
||||
|
||||
val filename = repository.name + "-" +
|
||||
(if(revision.length == 40) revision.substring(0, 10) else revision).replace('/', '_') + suffix
|
||||
|
||||
|
||||
using(Git.open(getRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, git.getRepository.resolve(revision))
|
||||
val oid = git.getRepository.resolve(revision)
|
||||
val revCommit = JGitUtil.getRevCommitFromId(git, oid)
|
||||
val sha1 = oid.getName()
|
||||
val repositorySuffix = (if(sha1.startsWith(revision)) sha1 else revision).replace('/','-')
|
||||
val filename = repository.name + "-" + repositorySuffix + suffix
|
||||
|
||||
contentType = "application/octet-stream"
|
||||
response.setHeader("Content-Disposition", s"attachment; filename=${filename}")
|
||||
@@ -726,6 +684,7 @@ trait RepositoryViewerControllerBase extends ControllerBase {
|
||||
|
||||
git.archive
|
||||
.setFormat(suffix.tail)
|
||||
.setPrefix(repository.name + "-" + repositorySuffix + "/")
|
||||
.setTree(revCommit)
|
||||
.setOutputStream(response.getOutputStream)
|
||||
.call()
|
||||
|
||||
@@ -9,7 +9,7 @@ import gitbucket.core.ssh.SshServer
|
||||
import gitbucket.core.plugin.PluginRegistry
|
||||
import SystemSettingsService._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
@@ -272,7 +272,7 @@ trait SystemSettingsControllerBase extends AccountManagementControllerBase {
|
||||
}
|
||||
}.toList){ case (groupName, members) =>
|
||||
getAccountByUserName(groupName, true).map { account =>
|
||||
updateGroup(groupName, form.url, form.description, form.isRemoved)
|
||||
updateGroup(groupName, form.description, form.url, form.isRemoved)
|
||||
|
||||
if(form.isRemoved){
|
||||
// Remove from GROUP_MEMBER
|
||||
|
||||
@@ -5,14 +5,14 @@ import gitbucket.core.wiki.html
|
||||
import gitbucket.core.service.{AccountService, ActivityService, RepositoryService, WikiService}
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Directory._
|
||||
import io.github.gitbucket.scalatra.forms._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.scalatra.i18n.Messages
|
||||
|
||||
class WikiController extends WikiControllerBase
|
||||
class WikiController extends WikiControllerBase
|
||||
with WikiService with RepositoryService with AccountService with ActivityService
|
||||
with ReadableUsersAuthenticator with ReferrerAuthenticator
|
||||
|
||||
@@ -20,7 +20,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
self: WikiService with RepositoryService with ActivityService with ReadableUsersAuthenticator with ReferrerAuthenticator =>
|
||||
|
||||
case class WikiPageEditForm(pageName: String, content: String, message: Option[String], currentPageName: String, id: String)
|
||||
|
||||
|
||||
val newForm = mapping(
|
||||
"pageName" -> trim(label("Page name" , text(required, maxlength(40), pagename, unique))),
|
||||
"content" -> trim(label("Content" , text(required, conflictForNew))),
|
||||
@@ -28,7 +28,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
"currentPageName" -> trim(label("Current page name" , text())),
|
||||
"id" -> trim(label("Latest commit id" , text()))
|
||||
)(WikiPageEditForm.apply)
|
||||
|
||||
|
||||
val editForm = mapping(
|
||||
"pageName" -> trim(label("Page name" , text(required, maxlength(40), pagename))),
|
||||
"content" -> trim(label("Content" , text(required, conflictForEdit))),
|
||||
@@ -36,7 +36,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
"currentPageName" -> trim(label("Current page name" , text(required))),
|
||||
"id" -> trim(label("Latest commit id" , text(required)))
|
||||
)(WikiPageEditForm.apply)
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki")(referrersOnly { repository =>
|
||||
getWikiPage(repository.owner, repository.name, "Home").map { page =>
|
||||
html.page("Home", page, getWikiPageList(repository.owner, repository.name),
|
||||
@@ -45,7 +45,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
getWikiPage(repository.owner, repository.name, "_Footer"))
|
||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/Home/_edit")
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/:page")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
|
||||
@@ -56,7 +56,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
getWikiPage(repository.owner, repository.name, "_Footer"))
|
||||
} getOrElse redirect(s"/${repository.owner}/${repository.name}/wiki/${StringUtil.urlEncode(pageName)}/_edit")
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_history")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
|
||||
@@ -67,7 +67,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_compare/:commitId")(referrersOnly { repository =>
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
@@ -77,7 +77,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
isEditable(repository), flash.get("info"))
|
||||
}
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/_compare/:commitId")(referrersOnly { repository =>
|
||||
val Array(from, to) = params("commitId").split("\\.\\.\\.")
|
||||
|
||||
@@ -120,7 +120,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
html.edit(pageName, getWikiPage(repository.owner, repository.name, pageName), repository)
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
|
||||
post("/:owner/:repository/wiki/_edit", editForm)(readableUsersOnly { (form, repository) =>
|
||||
if(isEditable(repository)){
|
||||
defining(context.loginAccount.get){ loginAccount =>
|
||||
@@ -145,13 +145,13 @@ trait WikiControllerBase extends ControllerBase {
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/_new")(readableUsersOnly { repository =>
|
||||
if(isEditable(repository)){
|
||||
html.edit("", None, repository)
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
|
||||
post("/:owner/:repository/wiki/_new", newForm)(readableUsersOnly { (form, repository) =>
|
||||
if(isEditable(repository)){
|
||||
defining(context.loginAccount.get){ loginAccount =>
|
||||
@@ -169,7 +169,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
}
|
||||
} else Unauthorized()
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/:page/_delete")(readableUsersOnly { repository =>
|
||||
if(isEditable(repository)){
|
||||
val pageName = StringUtil.urlDecode(params("page"))
|
||||
@@ -186,7 +186,7 @@ trait WikiControllerBase extends ControllerBase {
|
||||
get("/:owner/:repository/wiki/_pages")(referrersOnly { repository =>
|
||||
html.pages(getWikiPageList(repository.owner, repository.name), repository, isEditable(repository))
|
||||
})
|
||||
|
||||
|
||||
get("/:owner/:repository/wiki/_history")(referrersOnly { repository =>
|
||||
using(Git.open(getWikiRepositoryDir(repository.owner, repository.name))){ git =>
|
||||
JGitUtil.getCommitLog(git, "master") match {
|
||||
|
||||
27
src/main/scala/gitbucket/core/model/DeployKey.scala
Normal file
27
src/main/scala/gitbucket/core/model/DeployKey.scala
Normal file
@@ -0,0 +1,27 @@
|
||||
package gitbucket.core.model
|
||||
|
||||
trait DeployKeyComponent extends TemplateComponent { self: Profile =>
|
||||
import profile.api._
|
||||
|
||||
lazy val DeployKeys = TableQuery[DeployKeys]
|
||||
|
||||
class DeployKeys(tag: Tag) extends Table[DeployKey](tag, "DEPLOY_KEY") with BasicTemplate {
|
||||
val deployKeyId = column[Int]("DEPLOY_KEY_ID", O AutoInc)
|
||||
val title = column[String]("TITLE")
|
||||
val publicKey = column[String]("PUBLIC_KEY")
|
||||
val allowWrite = column[Boolean]("ALLOW_WRITE")
|
||||
def * = (userName, repositoryName, deployKeyId, title, publicKey, allowWrite) <> (DeployKey.tupled, DeployKey.unapply)
|
||||
|
||||
def byPrimaryKey(userName: String, repositoryName: String, deployKeyId: Int) =
|
||||
(this.userName === userName.bind) && (this.repositoryName === repositoryName.bind) && (this.deployKeyId === deployKeyId.bind)
|
||||
}
|
||||
}
|
||||
|
||||
case class DeployKey(
|
||||
userName: String,
|
||||
repositoryName: String,
|
||||
deployKeyId: Int = 0,
|
||||
title: String,
|
||||
publicKey: String,
|
||||
allowWrite: Boolean
|
||||
)
|
||||
@@ -9,10 +9,10 @@ trait MilestoneComponent extends TemplateComponent { self: Profile =>
|
||||
class Milestones(tag: Tag) extends Table[Milestone](tag, "MILESTONE") with MilestoneTemplate {
|
||||
override val milestoneId = column[Int]("MILESTONE_ID", O AutoInc)
|
||||
val title = column[String]("TITLE")
|
||||
val description = column[String]("DESCRIPTION")
|
||||
val dueDate = column[java.util.Date]("DUE_DATE")
|
||||
val closedDate = column[java.util.Date]("CLOSED_DATE")
|
||||
def * = (userName, repositoryName, milestoneId, title, description.?, dueDate.?, closedDate.?) <> (Milestone.tupled, Milestone.unapply)
|
||||
val description = column[Option[String]]("DESCRIPTION")
|
||||
val dueDate = column[Option[java.util.Date]]("DUE_DATE")
|
||||
val closedDate = column[Option[java.util.Date]]("CLOSED_DATE")
|
||||
def * = (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(userName: Rep[String], repositoryName: Rep[String], milestoneId: Rep[Int]) = byMilestone(userName, repositoryName, milestoneId)
|
||||
|
||||
@@ -54,5 +54,6 @@ trait CoreProfile extends ProfileProvider with Profile
|
||||
with WebHookComponent
|
||||
with WebHookEventComponent
|
||||
with ProtectedBranchComponent
|
||||
with DeployKeyComponent
|
||||
|
||||
object Profile extends CoreProfile
|
||||
|
||||
@@ -5,7 +5,7 @@ import gitbucket.core.controller.{Context, ControllerBase}
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import io.github.gitbucket.solidbase.model.Version
|
||||
|
||||
/**
|
||||
@@ -79,6 +79,16 @@ abstract class Plugin {
|
||||
*/
|
||||
def receiveHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[ReceiveHook] = Nil
|
||||
|
||||
/**
|
||||
* Override to add repository hooks.
|
||||
*/
|
||||
val repositoryHooks: Seq[RepositoryHook] = Nil
|
||||
|
||||
/**
|
||||
* Override to add repository hooks.
|
||||
*/
|
||||
def repositoryHooks(registry: PluginRegistry, context: ServletContext, settings: SystemSettings): Seq[RepositoryHook] = Nil
|
||||
|
||||
/**
|
||||
* Override to add global menus.
|
||||
*/
|
||||
@@ -202,6 +212,9 @@ abstract class Plugin {
|
||||
(receiveHooks ++ receiveHooks(registry, context, settings)).foreach { receiveHook =>
|
||||
registry.addReceiveHook(receiveHook)
|
||||
}
|
||||
(repositoryHooks ++ repositoryHooks(registry, context, settings)).foreach { repositoryHook =>
|
||||
registry.addRepositoryHook(repositoryHook)
|
||||
}
|
||||
(globalMenus ++ globalMenus(registry, context, settings)).foreach { globalMenu =>
|
||||
registry.addGlobalMenu(globalMenu)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package gitbucket.core.plugin
|
||||
|
||||
import java.io.{File, FilenameFilter, InputStream}
|
||||
import java.net.URLClassLoader
|
||||
import java.util.Base64
|
||||
import javax.servlet.ServletContext
|
||||
|
||||
import gitbucket.core.controller.{Context, ControllerBase}
|
||||
@@ -9,13 +10,12 @@ import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.ProtectedBranchService.ProtectedBranchReceiveHook
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.service.SystemSettingsService.SystemSettings
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.DatabaseConfig
|
||||
import gitbucket.core.util.Directory._
|
||||
import io.github.gitbucket.solidbase.Solidbase
|
||||
import io.github.gitbucket.solidbase.manager.JDBCVersionManager
|
||||
import io.github.gitbucket.solidbase.model.Module
|
||||
import org.apache.commons.codec.binary.{Base64, StringUtils}
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
import scala.collection.mutable
|
||||
@@ -35,6 +35,7 @@ class PluginRegistry {
|
||||
private val receiveHooks = new ListBuffer[ReceiveHook]
|
||||
receiveHooks += new ProtectedBranchReceiveHook()
|
||||
|
||||
private val repositoryHooks = new ListBuffer[RepositoryHook]
|
||||
private val globalMenus = new ListBuffer[(Context) => Option[Link]]
|
||||
private val repositoryMenus = new ListBuffer[(RepositoryInfo, Context) => Option[Link]]
|
||||
private val repositorySettingTabs = new ListBuffer[(RepositoryInfo, Context) => Option[Link]]
|
||||
@@ -53,7 +54,7 @@ class PluginRegistry {
|
||||
def getPlugins(): List[PluginInfo] = plugins.toList
|
||||
|
||||
def addImage(id: String, bytes: Array[Byte]): Unit = {
|
||||
val encoded = StringUtils.newStringUtf8(Base64.encodeBase64(bytes, false))
|
||||
val encoded = Base64.getEncoder.encodeToString(bytes)
|
||||
images += ((id, encoded))
|
||||
}
|
||||
|
||||
@@ -82,7 +83,7 @@ class PluginRegistry {
|
||||
|
||||
def addRenderer(extension: String, renderer: Renderer): Unit = renderers += ((extension, renderer))
|
||||
|
||||
def getRenderer(extension: String): Renderer = renderers.get(extension).getOrElse(DefaultRenderer)
|
||||
def getRenderer(extension: String): Renderer = renderers.getOrElse(extension, DefaultRenderer)
|
||||
|
||||
def renderableExtensions: Seq[String] = renderers.keys.toSeq
|
||||
|
||||
@@ -102,6 +103,10 @@ class PluginRegistry {
|
||||
|
||||
def getReceiveHooks: Seq[ReceiveHook] = receiveHooks.toSeq
|
||||
|
||||
def addRepositoryHook(repositoryHook: RepositoryHook): Unit = repositoryHooks += repositoryHook
|
||||
|
||||
def getRepositoryHooks: Seq[RepositoryHook] = repositoryHooks.toSeq
|
||||
|
||||
def addGlobalMenu(globalMenu: (Context) => Option[Link]): Unit = globalMenus += globalMenu
|
||||
|
||||
def getGlobalMenus: Seq[(Context) => Option[Link]] = globalMenus.toSeq
|
||||
@@ -170,7 +175,7 @@ object PluginRegistry {
|
||||
}).foreach { pluginJar =>
|
||||
val classLoader = new URLClassLoader(Array(pluginJar.toURI.toURL), Thread.currentThread.getContextClassLoader)
|
||||
try {
|
||||
val plugin = classLoader.loadClass("Plugin").newInstance().asInstanceOf[Plugin]
|
||||
val plugin = classLoader.loadClass("Plugin").getDeclaredConstructor().newInstance().asInstanceOf[Plugin]
|
||||
|
||||
// Migration
|
||||
val solidbase = new Solidbase()
|
||||
|
||||
14
src/main/scala/gitbucket/core/plugin/RepositoryHook.scala
Normal file
14
src/main/scala/gitbucket/core/plugin/RepositoryHook.scala
Normal file
@@ -0,0 +1,14 @@
|
||||
package gitbucket.core.plugin
|
||||
|
||||
import gitbucket.core.model.Profile._
|
||||
import profile.api._
|
||||
|
||||
trait RepositoryHook {
|
||||
|
||||
def created(owner: String, repository: String)(implicit session: Session): Unit = ()
|
||||
def deleted(owner: String, repository: String)(implicit session: Session): Unit = ()
|
||||
def renamed(owner: String, repository: String, newRepository: String)(implicit session: Session): Unit = ()
|
||||
def transferred(owner: String, newOwner: String, repository: String)(implicit session: Session): Unit = ()
|
||||
def forked(owner: String, newOwner: String, repository: String)(implicit session: Session): Unit = ()
|
||||
|
||||
}
|
||||
@@ -27,9 +27,9 @@ trait AccessTokenService {
|
||||
|
||||
do {
|
||||
token = makeAccessTokenString
|
||||
hash = tokenToHash(token)
|
||||
//} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run)
|
||||
} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run)
|
||||
hash = tokenToHash(token)
|
||||
} while (AccessTokens.filter(_.tokenHash === hash.bind).exists.run)
|
||||
|
||||
val newToken = AccessToken(
|
||||
userName = userName,
|
||||
note = note,
|
||||
@@ -42,7 +42,7 @@ trait AccessTokenService {
|
||||
Accounts
|
||||
.join(AccessTokens)
|
||||
.filter { case (ac, t) => (ac.userName === t.userName) && (t.tokenHash === tokenToHash(token).bind) && (ac.removed === false.bind) }
|
||||
.map { case (ac, t) => ac }
|
||||
.map { case (ac, t) => ac }
|
||||
.firstOption
|
||||
|
||||
def getAccessTokens(userName: String)(implicit s: Session): List[AccessToken] =
|
||||
|
||||
@@ -166,8 +166,8 @@ trait AccountService {
|
||||
|
||||
def updateGroup(groupName: String, description: Option[String], url: Option[String], removed: Boolean)(implicit s: Session): Unit =
|
||||
Accounts.filter(_.userName === groupName.bind)
|
||||
.map(t => (t.url.?, t.description.?, t.removed))
|
||||
.update(url, description, removed)
|
||||
.map(t => (t.url.?, t.description.?, t.updatedDate, t.removed))
|
||||
.update(url, description, currentDate, removed)
|
||||
|
||||
def updateGroupMembers(groupName: String, members: List[(String, Boolean)])(implicit s: Session): Unit = {
|
||||
GroupMembers.filter(_.groupName === groupName.bind).delete
|
||||
|
||||
31
src/main/scala/gitbucket/core/service/DeployKeyService.scala
Normal file
31
src/main/scala/gitbucket/core/service/DeployKeyService.scala
Normal file
@@ -0,0 +1,31 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.model.DeployKey
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
|
||||
trait DeployKeyService {
|
||||
|
||||
def addDeployKey(userName: String, repositoryName: String, title: String, publicKey: String, allowWrite: Boolean)
|
||||
(implicit s: Session): Unit =
|
||||
DeployKeys.insert(DeployKey(
|
||||
userName = userName,
|
||||
repositoryName = repositoryName,
|
||||
title = title,
|
||||
publicKey = publicKey,
|
||||
allowWrite = allowWrite
|
||||
))
|
||||
|
||||
def getDeployKeys(userName: String, repositoryName: String)(implicit s: Session): List[DeployKey] =
|
||||
DeployKeys
|
||||
.filter(x => (x.userName === userName.bind) && (x.repositoryName === repositoryName.bind))
|
||||
.sortBy(_.deployKeyId).list
|
||||
|
||||
def getAllDeployKeys()(implicit s: Session): List[DeployKey] =
|
||||
DeployKeys.filter(_.publicKey.trim =!= "").list
|
||||
|
||||
def deleteDeployKey(userName: String, repositoryName: String, deployKeyId: Int)(implicit s: Session): Unit =
|
||||
DeployKeys.filter(_.byPrimaryKey(userName, repositoryName, deployKeyId)).delete
|
||||
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.Issue
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.Notifier
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ package gitbucket.core.service
|
||||
import gitbucket.core.util.JGitUtil.CommitInfo
|
||||
import gitbucket.core.util.StringUtil._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.model.{Issue, PullRequest, IssueComment, IssueLabel, Label, Account, Repository, CommitState, Role}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.model.Profile.dateColumnType
|
||||
|
||||
|
||||
|
||||
trait IssuesService {
|
||||
self: AccountService with RepositoryService =>
|
||||
import IssuesService._
|
||||
@@ -27,33 +26,37 @@ trait IssuesService {
|
||||
def getCommentsForApi(owner: String, repository: String, issueId: Int)(implicit s: Session): List[(IssueComment, Account, Issue)] =
|
||||
IssueComments.filter(_.byIssue(owner, repository, issueId))
|
||||
.filter(_.action inSetBind Set("comment" , "close_comment", "reopen_comment"))
|
||||
.join(Accounts).on( (t1, t2) => t1.commentedUserName === t2.userName )
|
||||
.join(Issues).on{ case ((t1, t2), t3) => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) }
|
||||
.map{ case ((t1, t2), t3) => (t1, t2, t3) }
|
||||
.join(Accounts).on { case t1 ~ t2 => t1.commentedUserName === t2.userName }
|
||||
.join(Issues).on { case t1 ~ t2 ~ t3 => t3.byIssue(t1.userName, t1.repositoryName, t1.issueId) }
|
||||
.map { case t1 ~ t2 ~ t3 => (t1, t2, t3) }
|
||||
.list
|
||||
|
||||
def getMergedComment(owner: String, repository: String, issueId: Int)(implicit s: Session): Option[(IssueComment, Account)] = {
|
||||
getCommentsForApi(owner, repository, issueId).collectFirst { case (comment, account, _) if comment.action == "merged" => (comment, account) }
|
||||
getCommentsForApi(owner, repository, issueId)
|
||||
.collectFirst { case (comment, account, _) if comment.action == "merged" => (comment, account) }
|
||||
}
|
||||
|
||||
def getComment(owner: String, repository: String, commentId: String)(implicit s: Session) =
|
||||
def getComment(owner: String, repository: String, commentId: String)(implicit s: Session): Option[IssueComment] = {
|
||||
if (commentId forall (_.isDigit))
|
||||
IssueComments filter { t =>
|
||||
t.byPrimaryKey(commentId.toInt) && t.byRepository(owner, repository)
|
||||
} firstOption
|
||||
else None
|
||||
}
|
||||
|
||||
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session) =
|
||||
def getIssueLabels(owner: String, repository: String, issueId: Int)(implicit s: Session): List[Label] = {
|
||||
IssueLabels
|
||||
.join(Labels).on { (t1, t2) =>
|
||||
.join(Labels).on { case t1 ~ t2 =>
|
||||
t1.byLabel(t2.userName, t2.repositoryName, t2.labelId)
|
||||
}
|
||||
.filter ( _._1.byIssue(owner, repository, issueId) )
|
||||
.map ( _._2 )
|
||||
.filter { case t1 ~ t2 => t1.byIssue(owner, repository, issueId) }
|
||||
.map { case t1 ~ t2 => t2 }
|
||||
.list
|
||||
}
|
||||
|
||||
def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) =
|
||||
def getIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Option[IssueLabel] = {
|
||||
IssueLabels filter (_.byPrimaryKey(owner, repository, issueId, labelId)) firstOption
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the count of the search result against issues.
|
||||
@@ -63,9 +66,9 @@ trait IssuesService {
|
||||
* @param repos Tuple of the repository owner and the repository name
|
||||
* @return the count of the search result
|
||||
*/
|
||||
def countIssue(condition: IssueSearchCondition, onlyPullRequest: Boolean,
|
||||
repos: (String, String)*)(implicit s: Session): Int =
|
||||
def countIssue(condition: IssueSearchCondition, onlyPullRequest: Boolean, repos: (String, String)*)(implicit s: Session): Int = {
|
||||
Query(searchIssueQuery(repos, condition, onlyPullRequest).length).first
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the Map which contains issue count for each labels.
|
||||
@@ -79,16 +82,16 @@ trait IssuesService {
|
||||
filterUser: Map[String, String])(implicit s: Session): Map[String, Int] = {
|
||||
|
||||
searchIssueQuery(Seq(owner -> repository), condition.copy(labels = Set.empty), false)
|
||||
.join(IssueLabels).on { (t1, t2) =>
|
||||
.join(IssueLabels).on { case t1 ~ t2 =>
|
||||
t1.byIssue(t2.userName, t2.repositoryName, t2.issueId)
|
||||
}
|
||||
.join(Labels).on { case ((t1, t2), t3) =>
|
||||
.join(Labels).on { case t1 ~ t2 ~ t3 =>
|
||||
t2.byLabel(t3.userName, t3.repositoryName, t3.labelId)
|
||||
}
|
||||
.groupBy { case ((t1, t2), t3) =>
|
||||
.groupBy { case t1 ~ t2 ~ t3 =>
|
||||
t3.labelName
|
||||
}
|
||||
.map { case (labelName, t) =>
|
||||
.map { case labelName ~ t =>
|
||||
labelName -> t.length
|
||||
}
|
||||
.list.toMap
|
||||
@@ -96,15 +99,19 @@ trait IssuesService {
|
||||
|
||||
def getCommitStatues(userName: String, repositoryName: String, issueId: Int)(implicit s: Session): Option[CommitStatusInfo] = {
|
||||
val status = PullRequests
|
||||
.filter { pr => (pr.userName === userName.bind) && (pr.repositoryName === repositoryName.bind) && (pr.issueId === issueId.bind) }
|
||||
.join(CommitStatuses).on((pr, cs) => pr.userName === cs.userName && pr.repositoryName === cs.repositoryName && pr.commitIdTo === cs.commitId)
|
||||
.filter { pr =>
|
||||
pr.userName === userName.bind && pr.repositoryName === repositoryName.bind && pr.issueId === issueId.bind
|
||||
}
|
||||
.join(CommitStatuses).on { case pr ~ cs =>
|
||||
pr.userName === cs.userName && pr.repositoryName === cs.repositoryName && pr.commitIdTo === cs.commitId
|
||||
}
|
||||
.list
|
||||
|
||||
if(status.nonEmpty){
|
||||
val (_, cs) = status.head
|
||||
Some(CommitStatusInfo(
|
||||
count = status.length,
|
||||
successCount = status.filter(_._2.state == CommitState.SUCCESS).length,
|
||||
successCount = status.count(_._2.state == CommitState.SUCCESS),
|
||||
context = (if(status.length == 1) Some(cs.context) else None),
|
||||
state = (if(status.length == 1) Some(cs.state) else None),
|
||||
targetUrl = (if(status.length == 1) cs.targetUrl else None),
|
||||
@@ -129,11 +136,11 @@ trait IssuesService {
|
||||
(implicit s: Session): List[IssueInfo] = {
|
||||
// get issues and comment count and labels
|
||||
val result = searchIssueQueryBase(condition, pullRequest, offset, limit, repos)
|
||||
.joinLeft (IssueLabels) .on { case (((t1, t2), i), t3) => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
|
||||
.joinLeft (Labels) .on { case ((((t1, t2), i), t3), t4) => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) }
|
||||
.joinLeft (Milestones) .on { case (((((t1, t2), i), t3), t4), t5) => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) }
|
||||
.sortBy { case (((((t1, t2), i), t3), t4), t5) => i asc }
|
||||
.map { case (((((t1, t2), i), t3), t4), t5) =>
|
||||
.joinLeft (IssueLabels) .on { case t1 ~ t2 ~ i ~ t3 => t1.byIssue(t3.userName, t3.repositoryName, t3.issueId) }
|
||||
.joinLeft (Labels) .on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t3.map(_.byLabel(t4.userName, t4.repositoryName, t4.labelId)) }
|
||||
.joinLeft (Milestones) .on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t1.byMilestone(t5.userName, t5.repositoryName, t5.milestoneId) }
|
||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => i asc }
|
||||
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 =>
|
||||
(t1, t2.commentCount, t4.map(_.labelId), t4.map(_.labelName), t4.map(_.color), t5.map(_.title))
|
||||
}
|
||||
.list
|
||||
@@ -156,9 +163,9 @@ trait IssuesService {
|
||||
(implicit s: Session): List[(Issue, Account)] = {
|
||||
// get issues and comment count and labels
|
||||
searchIssueQueryBase(condition, false, offset, limit, repos)
|
||||
.join(Accounts).on { case (((t1, t2), i), t3) => t3.userName === t1.openedUserName }
|
||||
.sortBy { case (((t1, t2), i), t3) => i asc }
|
||||
.map { case (((t1, t2), i), t3) => (t1, t3) }
|
||||
.join(Accounts).on { case t1 ~ t2 ~ i ~ t3 => t3.userName === t1.openedUserName }
|
||||
.sortBy { case t1 ~ t2 ~ i ~ t3 => i asc }
|
||||
.map { case t1 ~ t2 ~ i ~ t3 => (t1, t3) }
|
||||
.list
|
||||
}
|
||||
|
||||
@@ -169,12 +176,12 @@ trait IssuesService {
|
||||
(implicit s: Session): List[(Issue, Account, Int, PullRequest, Repository, Account)] = {
|
||||
// get issues and comment count and labels
|
||||
searchIssueQueryBase(condition, true, offset, limit, repos)
|
||||
.join(PullRequests).on { case (((t1, t2), i), t3) => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) }
|
||||
.join(Repositories).on { case ((((t1, t2), i), t3), t4) => t4.byRepository(t1.userName, t1.repositoryName) }
|
||||
.join(Accounts).on { case (((((t1, t2), i), t3), t4), t5) => t5.userName === t1.openedUserName }
|
||||
.join(Accounts).on { case ((((((t1, t2), i), t3), t4), t5), t6) => t6.userName === t4.userName }
|
||||
.sortBy { case ((((((t1, t2), i), t3), t4), t5), t6) => i asc }
|
||||
.map { case ((((((t1, t2), i), t3), t4), t5), t6) => (t1, t5, t2.commentCount, t3, t4, t6) }
|
||||
.join(PullRequests).on { case t1 ~ t2 ~ i ~ t3 => t3.byPrimaryKey(t1.userName, t1.repositoryName, t1.issueId) }
|
||||
.join(Repositories).on { case t1 ~ t2 ~ i ~ t3 ~ t4 => t4.byRepository(t1.userName, t1.repositoryName) }
|
||||
.join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 => t5.userName === t1.openedUserName }
|
||||
.join(Accounts ).on { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => t6.userName === t4.userName }
|
||||
.sortBy { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => i asc }
|
||||
.map { case t1 ~ t2 ~ i ~ t3 ~ t4 ~ t5 ~ t6 => (t1, t5, t2.commentCount, t3, t4, t6) }
|
||||
.list
|
||||
}
|
||||
|
||||
@@ -247,36 +254,39 @@ trait IssuesService {
|
||||
|
||||
def insertIssue(owner: String, repository: String, loginUser: String, title: String, content: Option[String],
|
||||
assignedUserName: Option[String], milestoneId: Option[Int],
|
||||
isPullRequest: Boolean = false)(implicit s: Session) =
|
||||
isPullRequest: Boolean = false)(implicit s: Session): Int = {
|
||||
// next id number
|
||||
sql"SELECT ISSUE_ID + 1 FROM ISSUE_ID WHERE USER_NAME = $owner AND REPOSITORY_NAME = $repository FOR UPDATE".as[Int]
|
||||
.firstOption.filter { id =>
|
||||
.firstOption.filter { id =>
|
||||
Issues insert Issue(
|
||||
owner,
|
||||
repository,
|
||||
id,
|
||||
loginUser,
|
||||
milestoneId,
|
||||
assignedUserName,
|
||||
title,
|
||||
content,
|
||||
false,
|
||||
currentDate,
|
||||
currentDate,
|
||||
isPullRequest)
|
||||
owner,
|
||||
repository,
|
||||
id,
|
||||
loginUser,
|
||||
milestoneId,
|
||||
assignedUserName,
|
||||
title,
|
||||
content,
|
||||
false,
|
||||
currentDate,
|
||||
currentDate,
|
||||
isPullRequest)
|
||||
|
||||
// increment issue id
|
||||
IssueId
|
||||
.filter (_.byPrimaryKey(owner, repository))
|
||||
.map (_.issueId)
|
||||
.update (id) > 0
|
||||
.filter(_.byPrimaryKey(owner, repository))
|
||||
.map(_.issueId)
|
||||
.update(id) > 0
|
||||
} get
|
||||
}
|
||||
|
||||
def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) =
|
||||
def registerIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Int = {
|
||||
IssueLabels insert IssueLabel(owner, repository, issueId, labelId)
|
||||
}
|
||||
|
||||
def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session) =
|
||||
def deleteIssueLabel(owner: String, repository: String, issueId: Int, labelId: Int)(implicit s: Session): Int = {
|
||||
IssueLabels filter(_.byPrimaryKey(owner, repository, issueId, labelId)) delete
|
||||
}
|
||||
|
||||
def createComment(owner: String, repository: String, loginUser: String,
|
||||
issueId: Int, content: String, action: String)(implicit s: Session): Int = {
|
||||
@@ -291,29 +301,30 @@ trait IssuesService {
|
||||
updatedDate = currentDate)
|
||||
}
|
||||
|
||||
def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session) = {
|
||||
def updateIssue(owner: String, repository: String, issueId: Int, title: String, content: Option[String])(implicit s: Session): Int = {
|
||||
Issues
|
||||
.filter (_.byPrimaryKey(owner, repository, issueId))
|
||||
.map { t => (t.title, t.content.?, t.updatedDate) }
|
||||
.update (title, content, currentDate)
|
||||
}
|
||||
|
||||
def updateAssignedUserName(owner: String, repository: String, issueId: Int,
|
||||
assignedUserName: Option[String])(implicit s: Session) =
|
||||
def updateAssignedUserName(owner: String, repository: String, issueId: Int, assignedUserName: Option[String])(implicit s: Session): Int = {
|
||||
Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.assignedUserName?).update (assignedUserName)
|
||||
}
|
||||
|
||||
def updateMilestoneId(owner: String, repository: String, issueId: Int,
|
||||
milestoneId: Option[Int])(implicit s: Session) =
|
||||
def updateMilestoneId(owner: String, repository: String, issueId: Int, milestoneId: Option[Int])(implicit s: Session): Int = {
|
||||
Issues.filter (_.byPrimaryKey(owner, repository, issueId)).map(_.milestoneId?).update (milestoneId)
|
||||
}
|
||||
|
||||
def updateComment(commentId: Int, content: String)(implicit s: Session) = {
|
||||
def updateComment(commentId: Int, content: String)(implicit s: Session): Int = {
|
||||
IssueComments.filter (_.byPrimaryKey(commentId)).map(t => (t.content, t.updatedDate)).update(content, currentDate)
|
||||
}
|
||||
|
||||
def deleteComment(commentId: Int)(implicit s: Session) =
|
||||
def deleteComment(commentId: Int)(implicit s: Session): Int = {
|
||||
IssueComments filter (_.byPrimaryKey(commentId)) delete
|
||||
}
|
||||
|
||||
def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session) = {
|
||||
def updateClosed(owner: String, repository: String, issueId: Int, closed: Boolean)(implicit s: Session): Int = {
|
||||
(Issues filter (_.byPrimaryKey(owner, repository, issueId)) map(t => (t.closed, t.updatedDate))).update((closed, currentDate))
|
||||
}
|
||||
|
||||
@@ -325,8 +336,7 @@ trait IssuesService {
|
||||
* @param query the keywords separated by whitespace.
|
||||
* @return issues with comment count and matched content of issue or comment
|
||||
*/
|
||||
def searchIssuesByKeyword(owner: String, repository: String, query: String)
|
||||
(implicit s: Session): List[(Issue, Int, String)] = {
|
||||
def searchIssuesByKeyword(owner: String, repository: String, query: String)(implicit s: Session): List[(Issue, Int, String)] = {
|
||||
//import slick.driver.JdbcDriver.likeEncode
|
||||
val keywords = splitWords(query.toLowerCase)
|
||||
|
||||
@@ -374,7 +384,7 @@ trait IssuesService {
|
||||
}.toList
|
||||
}
|
||||
|
||||
def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)(implicit s: Session) = {
|
||||
def closeIssuesFromMessage(message: String, userName: String, owner: String, repository: String)(implicit s: Session): Unit = {
|
||||
extractCloseId(message).foreach { issueId =>
|
||||
for(issue <- getIssue(owner, repository, issueId) if !issue.closed){
|
||||
createComment(owner, repository, userName, issue.issueId, "Close", "close")
|
||||
@@ -383,7 +393,7 @@ trait IssuesService {
|
||||
}
|
||||
}
|
||||
|
||||
def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session) = {
|
||||
def createReferComment(owner: String, repository: String, fromIssue: Issue, message: String, loginAccount: Account)(implicit s: Session): Unit = {
|
||||
extractIssueId(message).foreach { issueId =>
|
||||
val content = fromIssue.issueId + ":" + fromIssue.title
|
||||
if(getIssue(owner, repository, issueId).isDefined){
|
||||
@@ -395,7 +405,7 @@ trait IssuesService {
|
||||
}
|
||||
}
|
||||
|
||||
def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session) = {
|
||||
def createIssueComment(owner: String, repository: String, commit: CommitInfo)(implicit s: Session): Unit = {
|
||||
extractIssueId(commit.fullMessage).foreach { issueId =>
|
||||
if(getIssue(owner, repository, issueId).isDefined){
|
||||
getAccountByMailAddress(commit.committerEmailAddress).foreach { account =>
|
||||
|
||||
@@ -2,7 +2,7 @@ package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
|
||||
import org.eclipse.jgit.merge.MergeStrategy
|
||||
import org.eclipse.jgit.api.Git
|
||||
|
||||
@@ -21,7 +21,7 @@ trait MilestonesService {
|
||||
def updateMilestone(milestone: Milestone)(implicit s: Session): Unit =
|
||||
Milestones
|
||||
.filter (t => t.byPrimaryKey(milestone.userName, milestone.repositoryName, milestone.milestoneId))
|
||||
.map (t => (t.title, t.description.?, t.dueDate.?, t.closedDate.?))
|
||||
.map (t => (t.title, t.description, t.dueDate, t.closedDate))
|
||||
.update (milestone.title, milestone.description, milestone.dueDate, milestone.closedDate)
|
||||
|
||||
def openMilestone(milestone: Milestone)(implicit s: Session): Unit =
|
||||
|
||||
@@ -76,7 +76,7 @@ object ProtectedBranchService {
|
||||
includeAdministrators: Boolean) extends AccountService with CommitStatusService {
|
||||
|
||||
def isAdministrator(pusher: String)(implicit session: Session): Boolean =
|
||||
pusher == owner || getGroupMembers(owner).filter(gm => gm.userName == pusher && gm.isManager).nonEmpty
|
||||
pusher == owner || getGroupMembers(owner).exists(gm => gm.userName == pusher && gm.isManager)
|
||||
|
||||
/**
|
||||
* Can't be force pushed
|
||||
|
||||
@@ -4,7 +4,7 @@ import gitbucket.core.model.{Issue, PullRequest, CommitStatus, CommitState, Comm
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import difflib.{Delta, DiffUtils}
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util.JGitUtil
|
||||
@@ -265,7 +265,7 @@ object PullRequestService {
|
||||
val summary = stateMap.map{ case (keyState, states) => states.size+" "+keyState.name }.mkString(", ")
|
||||
state -> summary
|
||||
}
|
||||
lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.exists(_==s.context) }
|
||||
lazy val statusesAndRequired:List[(CommitStatus, Boolean)] = statuses.map{ s => s -> branchProtection.contexts.contains(s.context) }
|
||||
lazy val isAllSuccess = commitStateSummary._1==CommitState.SUCCESS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.JGitUtil
|
||||
import gitbucket.core.model.Account
|
||||
|
||||
@@ -4,7 +4,7 @@ import gitbucket.core.model.Issue
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.StringUtil
|
||||
import Directory._
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import org.eclipse.jgit.revwalk.RevWalk
|
||||
import org.eclipse.jgit.treewalk.TreeWalk
|
||||
import org.eclipse.jgit.lib.FileMode
|
||||
|
||||
@@ -2,7 +2,7 @@ package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.controller.Context
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.model.{Account, Collaborator, Repository, RepositoryOptions, Role}
|
||||
import gitbucket.core.model.Profile._
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
@@ -73,6 +73,7 @@ trait RepositoryService { self: AccountService =>
|
||||
val collaborators = Collaborators .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||
val protectedBranches = ProtectedBranches .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||
val protectedBranchContexts = ProtectedBranchContexts.filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||
val deployKeys = DeployKeys .filter(_.byRepository(oldUserName, oldRepositoryName)).list
|
||||
|
||||
Repositories.filter { t =>
|
||||
(t.originUserName === oldUserName.bind) && (t.originRepositoryName === oldRepositoryName.bind)
|
||||
@@ -112,6 +113,7 @@ trait RepositoryService { self: AccountService =>
|
||||
CommitStatuses .insertAll(commitStatuses.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||
ProtectedBranches .insertAll(protectedBranches.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||
ProtectedBranchContexts.insertAll(protectedBranchContexts.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||
DeployKeys .insertAll(deployKeys .map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||
|
||||
// Update source repository of pull requests
|
||||
PullRequests.filter { t =>
|
||||
@@ -126,11 +128,6 @@ trait RepositoryService { self: AccountService =>
|
||||
userName = newUserName,
|
||||
repositoryName = newRepositoryName
|
||||
)) :_*)
|
||||
IssueLabels.insertAll(issueLabels.map(x => x.copy(
|
||||
labelId = newLabelMap(oldLabelMap(x.labelId)),
|
||||
userName = newUserName,
|
||||
repositoryName = newRepositoryName
|
||||
)) :_*)
|
||||
|
||||
// TODO Drop transfered owner from collaborators?
|
||||
Collaborators.insertAll(collaborators.map(_.copy(userName = newUserName, repositoryName = newRepositoryName)) :_*)
|
||||
@@ -168,6 +165,7 @@ trait RepositoryService { self: AccountService =>
|
||||
Milestones .filter(_.byRepository(userName, repositoryName)).delete
|
||||
WebHooks .filter(_.byRepository(userName, repositoryName)).delete
|
||||
WebHookEvents .filter(_.byRepository(userName, repositoryName)).delete
|
||||
DeployKeys .filter(_.byRepository(userName, repositoryName)).delete
|
||||
Repositories .filter(_.byRepository(userName, repositoryName)).delete
|
||||
|
||||
// Update ORIGIN_USER_NAME and ORIGIN_REPOSITORY_NAME
|
||||
@@ -206,7 +204,7 @@ trait RepositoryService { self: AccountService =>
|
||||
|
||||
/**
|
||||
* Returns the specified repository information.
|
||||
*
|
||||
*
|
||||
* @param userName the user name of the repository owner
|
||||
* @param repositoryName the repository name
|
||||
* @return the repository information
|
||||
@@ -264,11 +262,19 @@ trait RepositoryService { self: AccountService =>
|
||||
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName)
|
||||
},
|
||||
repository,
|
||||
getForkedCount(
|
||||
repository.originUserName.getOrElse(repository.userName),
|
||||
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
||||
),
|
||||
getRepositoryManagers(repository.userName))
|
||||
if(withoutPhysicalInfo){
|
||||
-1
|
||||
} else {
|
||||
getForkedCount(
|
||||
repository.originUserName.getOrElse(repository.userName),
|
||||
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
||||
)
|
||||
},
|
||||
if(withoutPhysicalInfo){
|
||||
Nil
|
||||
} else {
|
||||
getRepositoryManagers(repository.userName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,7 +308,7 @@ trait RepositoryService { self: AccountService =>
|
||||
case None => Repositories filter(_.isPrivate === false.bind)
|
||||
}).filter { t =>
|
||||
repositoryUserName.map { userName => t.userName === userName.bind } getOrElse LiteralColumn(true)
|
||||
}.sortBy(_.lastActivityDate desc).list.map{ repository =>
|
||||
}.sortBy(_.lastActivityDate desc).list.map { repository =>
|
||||
new RepositoryInfo(
|
||||
if(withoutPhysicalInfo){
|
||||
new JGitUtil.RepositoryInfo(repository.userName, repository.repositoryName)
|
||||
@@ -310,11 +316,19 @@ trait RepositoryService { self: AccountService =>
|
||||
JGitUtil.getRepositoryInfo(repository.userName, repository.repositoryName)
|
||||
},
|
||||
repository,
|
||||
getForkedCount(
|
||||
repository.originUserName.getOrElse(repository.userName),
|
||||
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
||||
),
|
||||
getRepositoryManagers(repository.userName))
|
||||
if(withoutPhysicalInfo){
|
||||
-1
|
||||
} else {
|
||||
getForkedCount(
|
||||
repository.originUserName.getOrElse(repository.userName),
|
||||
repository.originRepositoryName.getOrElse(repository.repositoryName)
|
||||
)
|
||||
},
|
||||
if(withoutPhysicalInfo) {
|
||||
Nil
|
||||
} else {
|
||||
getRepositoryManagers(repository.userName)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@ import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
trait SshKeyService {
|
||||
|
||||
def addPublicKey(userName: String, title: String, publicKey: String)(implicit s: Session): Unit =
|
||||
SshKeys insert SshKey(userName = userName, title = title, publicKey = publicKey)
|
||||
SshKeys.insert(SshKey(userName = userName, title = title, publicKey = publicKey))
|
||||
|
||||
def getPublicKeys(userName: String)(implicit s: Session): List[SshKey] =
|
||||
SshKeys.filter(_.userName === userName.bind).sortBy(_.sshKeyId).list
|
||||
@@ -16,6 +16,6 @@ trait SshKeyService {
|
||||
SshKeys.filter(_.publicKey.trim =!= "").list
|
||||
|
||||
def deletePublicKey(userName: String, sshKeyId: Int)(implicit s: Session): Unit =
|
||||
SshKeys filter (_.byPrimaryKey(userName, sshKeyId)) delete
|
||||
SshKeys.filter(_.byPrimaryKey(userName, sshKeyId)).delete
|
||||
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.util.{Directory, ControlUtil}
|
||||
import gitbucket.core.util.{Directory, SyntaxSugars}
|
||||
import gitbucket.core.util.Implicits._
|
||||
import Directory._
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import SystemSettingsService._
|
||||
import javax.servlet.http.HttpServletRequest
|
||||
|
||||
@@ -175,9 +175,9 @@ object SystemSettingsService {
|
||||
fromName: Option[String])
|
||||
|
||||
case class SshAddress(
|
||||
host:String,
|
||||
port:Int,
|
||||
genericUser:String)
|
||||
host: String,
|
||||
port: Int,
|
||||
genericUser: String)
|
||||
|
||||
case class Lfs(
|
||||
serverUrl: Option[String])
|
||||
|
||||
@@ -5,7 +5,7 @@ import gitbucket.core.controller.Context
|
||||
import gitbucket.core.model.Account
|
||||
import gitbucket.core.service.RepositoryService.RepositoryInfo
|
||||
import gitbucket.core.util._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import org.eclipse.jgit.treewalk.CanonicalTreeParser
|
||||
import org.eclipse.jgit.lib._
|
||||
@@ -17,10 +17,10 @@ import org.eclipse.jgit.api.errors.PatchFormatException
|
||||
import scala.collection.JavaConverters._
|
||||
|
||||
object WikiService {
|
||||
|
||||
|
||||
/**
|
||||
* The model for wiki page.
|
||||
*
|
||||
*
|
||||
* @param name the page name
|
||||
* @param content the page content
|
||||
* @param committer the last committer
|
||||
@@ -28,10 +28,10 @@ object WikiService {
|
||||
* @param id the latest commit id
|
||||
*/
|
||||
case class WikiPageInfo(name: String, content: String, committer: String, time: Date, id: String)
|
||||
|
||||
|
||||
/**
|
||||
* The model for wiki page history.
|
||||
*
|
||||
*
|
||||
* @param name the page name
|
||||
* @param committer the committer the committer
|
||||
* @param message the commit message
|
||||
@@ -177,7 +177,7 @@ trait WikiService {
|
||||
val headId = git.getRepository.resolve(Constants.HEAD + "^{commit}")
|
||||
|
||||
JGitUtil.processTree(git, headId){ (path, tree) =>
|
||||
if(revertInfo.find(x => x.filePath == path).isEmpty){
|
||||
if(!revertInfo.exists(x => x.filePath == path)){
|
||||
builder.add(JGitUtil.createDirCacheEntry(path, tree.getEntryFileMode, tree.getEntryObjectId))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
||||
private val logger = LoggerFactory.getLogger(classOf[GitAuthenticationFilter])
|
||||
|
||||
def init(config: FilterConfig) = {}
|
||||
|
||||
|
||||
def destroy(): Unit = {}
|
||||
|
||||
|
||||
def doFilter(req: ServletRequest, res: ServletResponse, chain: FilterChain): Unit = {
|
||||
val request = req.asInstanceOf[HttpServletRequest]
|
||||
val response = res.asInstanceOf[HttpServletResponse]
|
||||
@@ -51,21 +51,21 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
||||
|
||||
private def pluginRepository(request: HttpServletRequest, response: HttpServletResponse, chain: FilterChain,
|
||||
settings: SystemSettings, isUpdating: Boolean, filter: GitRepositoryFilter): Unit = {
|
||||
implicit val r = request
|
||||
Database() withSession { implicit session =>
|
||||
val account = for {
|
||||
auth <- Option(request.getHeader("Authorization"))
|
||||
Array(username, password) = AuthUtil.decodeAuthHeader(auth).split(":", 2)
|
||||
account <- authenticate(settings, username, password)
|
||||
} yield {
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
account
|
||||
}
|
||||
|
||||
val account = for {
|
||||
auth <- Option(request.getHeader("Authorization"))
|
||||
Array(username, password) = AuthUtil.decodeAuthHeader(auth).split(":", 2)
|
||||
account <- authenticate(settings, username, password)
|
||||
} yield {
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
account
|
||||
}
|
||||
|
||||
if(filter.filter(request.gitRepositoryPath, account.map(_.userName), settings, isUpdating)){
|
||||
chain.doFilter(request, response)
|
||||
} else {
|
||||
AuthUtil.requireAuth(response)
|
||||
if (filter.filter(request.gitRepositoryPath, account.map(_.userName), settings, isUpdating)) {
|
||||
chain.doFilter(request, response)
|
||||
} else {
|
||||
AuthUtil.requireAuth(response)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,11 +85,16 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
||||
auth <- Option(request.getHeader("Authorization"))
|
||||
Array(username, password) = AuthUtil.decodeAuthHeader(auth).split(":", 2)
|
||||
account <- authenticate(settings, username, password)
|
||||
} yield if (isUpdating || repository.repository.isPrivate) {
|
||||
} yield if (isUpdating) {
|
||||
if (hasDeveloperRole(repository.owner, repository.name, Some(account))) {
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
true
|
||||
} else false
|
||||
} else if(repository.repository.isPrivate){
|
||||
if (hasGuestRole(repository.owner, repository.name, Some(account))) {
|
||||
request.setAttribute(Keys.Request.UserName, account.userName)
|
||||
true
|
||||
} else false
|
||||
} else true
|
||||
passed.getOrElse(false)
|
||||
}
|
||||
@@ -114,4 +119,4 @@ class GitAuthenticationFilter extends Filter with RepositoryService with Account
|
||||
|
||||
action()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import gitbucket.core.util.{FileUtil, StringUtil}
|
||||
import org.apache.commons.io.{FileUtils, IOUtils}
|
||||
import org.json4s.jackson.Serialization._
|
||||
import org.apache.http.HttpStatus
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
|
||||
/**
|
||||
* Provides GitLFS Transfer API
|
||||
|
||||
@@ -10,7 +10,7 @@ import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry}
|
||||
import gitbucket.core.service.IssuesService.IssueSearchCondition
|
||||
import gitbucket.core.service.WebHookService._
|
||||
import gitbucket.core.service._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.Implicits._
|
||||
import gitbucket.core.util._
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -27,7 +27,7 @@ import org.json4s.jackson.Serialization._
|
||||
|
||||
/**
|
||||
* Provides Git repository via HTTP.
|
||||
*
|
||||
*
|
||||
* This servlet provides only Git repository functionality.
|
||||
* Authentication is provided by [[GitAuthenticationFilter]].
|
||||
*/
|
||||
@@ -174,7 +174,7 @@ class CommitLogHook(owner: String, repository: String, pusher: String, baseUrl:
|
||||
extends PostReceiveHook with PreReceiveHook
|
||||
with RepositoryService with AccountService with IssuesService with ActivityService with PullRequestService with WebHookService
|
||||
with WebHookPullRequestService with CommitsService {
|
||||
|
||||
|
||||
private val logger = LoggerFactory.getLogger(classOf[CommitLogHook])
|
||||
private var existIds: Seq[String] = Nil
|
||||
|
||||
|
||||
@@ -26,6 +26,7 @@ class PluginAssetsServlet extends HttpServlet {
|
||||
val bytes = IOUtils.toByteArray(in)
|
||||
resp.setContentLength(bytes.length)
|
||||
resp.setContentType(FileUtil.getContentType(path, bytes))
|
||||
resp.setHeader("Cache-Control", "max-age=3600")
|
||||
resp.getOutputStream.write(bytes)
|
||||
} finally {
|
||||
in.close()
|
||||
|
||||
@@ -2,17 +2,18 @@ package gitbucket.core.ssh
|
||||
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.plugin.{GitRepositoryRouting, PluginRegistry}
|
||||
import gitbucket.core.service.{AccountService, RepositoryService, SystemSettingsService}
|
||||
import gitbucket.core.service.{AccountService, DeployKeyService, RepositoryService, SystemSettingsService}
|
||||
import gitbucket.core.servlet.{CommitLogHook, Database}
|
||||
import gitbucket.core.util.{ControlUtil, Directory}
|
||||
import gitbucket.core.util.{SyntaxSugars, Directory}
|
||||
import org.apache.sshd.server.{Command, CommandFactory, Environment, ExitCallback, SessionAware}
|
||||
import org.apache.sshd.server.session.ServerSession
|
||||
import org.slf4j.LoggerFactory
|
||||
import java.io.{File, InputStream, OutputStream}
|
||||
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import org.eclipse.jgit.api.Git
|
||||
import Directory._
|
||||
import gitbucket.core.ssh.PublicKeyAuthenticator.AuthType
|
||||
import org.eclipse.jgit.transport.{ReceivePack, UploadPack}
|
||||
import org.apache.sshd.server.scp.UnknownCommand
|
||||
import org.eclipse.jgit.errors.RepositoryNotFoundException
|
||||
@@ -25,34 +26,33 @@ object GitCommand {
|
||||
abstract class GitCommand extends Command with SessionAware {
|
||||
|
||||
private val logger = LoggerFactory.getLogger(classOf[GitCommand])
|
||||
|
||||
@volatile protected var err: OutputStream = null
|
||||
@volatile protected var in: InputStream = null
|
||||
@volatile protected var out: OutputStream = null
|
||||
@volatile protected var callback: ExitCallback = null
|
||||
@volatile private var authUser:Option[String] = None
|
||||
@volatile private var authType: Option[AuthType] = None
|
||||
|
||||
protected def runTask(authUser: String): Unit
|
||||
protected def runTask(authType: AuthType): Unit
|
||||
|
||||
private def newTask(): Runnable = new Runnable {
|
||||
override def run(): Unit = {
|
||||
authUser match {
|
||||
case Some(authUser) =>
|
||||
try {
|
||||
runTask(authUser)
|
||||
callback.onExit(0)
|
||||
} catch {
|
||||
case e: RepositoryNotFoundException =>
|
||||
logger.info(e.getMessage)
|
||||
callback.onExit(1, "Repository Not Found")
|
||||
case e: Throwable =>
|
||||
logger.error(e.getMessage, e)
|
||||
callback.onExit(1)
|
||||
}
|
||||
case None =>
|
||||
val message = "User not authenticated"
|
||||
logger.error(message)
|
||||
callback.onExit(1, message)
|
||||
}
|
||||
private def newTask(): Runnable = () => {
|
||||
authType match {
|
||||
case Some(authType) =>
|
||||
try {
|
||||
runTask(authType)
|
||||
callback.onExit(0)
|
||||
} catch {
|
||||
case e: RepositoryNotFoundException =>
|
||||
logger.info(e.getMessage)
|
||||
callback.onExit(1, "Repository Not Found")
|
||||
case e: Throwable =>
|
||||
logger.error(e.getMessage, e)
|
||||
callback.onExit(1)
|
||||
}
|
||||
case None =>
|
||||
val message = "User not authenticated"
|
||||
logger.error(message)
|
||||
callback.onExit(1, message)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -79,32 +79,68 @@ abstract class GitCommand extends Command with SessionAware {
|
||||
this.in = in
|
||||
}
|
||||
|
||||
override def setSession(serverSession:ServerSession) {
|
||||
this.authUser = PublicKeyAuthenticator.getUserName(serverSession)
|
||||
override def setSession(serverSession: ServerSession) {
|
||||
this.authType = PublicKeyAuthenticator.getAuthType(serverSession)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
abstract class DefaultGitCommand(val owner: String, val repoName: String) extends GitCommand {
|
||||
self: RepositoryService with AccountService =>
|
||||
self: RepositoryService with AccountService with DeployKeyService =>
|
||||
|
||||
protected def isWritableUser(username: String, repositoryInfo: RepositoryService.RepositoryInfo)
|
||||
(implicit session: Session): Boolean =
|
||||
getAccountByUserName(username) match {
|
||||
case Some(account) => hasDeveloperRole(repositoryInfo.owner, repositoryInfo.name, Some(account))
|
||||
case None => false
|
||||
protected def userName(authType: AuthType): String = {
|
||||
authType match {
|
||||
case AuthType.UserAuthType(userName) => userName
|
||||
case AuthType.DeployKeyType(_) => owner
|
||||
}
|
||||
}
|
||||
|
||||
protected def isReadableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)
|
||||
(implicit session: Session): Boolean = {
|
||||
authType match {
|
||||
case AuthType.UserAuthType(username) => {
|
||||
getAccountByUserName(username) match {
|
||||
case Some(account) => hasGuestRole(owner, repoName, Some(account))
|
||||
case None => false
|
||||
}
|
||||
}
|
||||
case AuthType.DeployKeyType(key) => {
|
||||
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match {
|
||||
case List(_) => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected def isWritableUser(authType: AuthType, repositoryInfo: RepositoryService.RepositoryInfo)
|
||||
(implicit session: Session): Boolean = {
|
||||
authType match {
|
||||
case AuthType.UserAuthType(username) => {
|
||||
getAccountByUserName(username) match {
|
||||
case Some(account) => hasDeveloperRole(owner, repoName, Some(account))
|
||||
case None => false
|
||||
}
|
||||
}
|
||||
case AuthType.DeployKeyType(key) => {
|
||||
getDeployKeys(owner, repoName).filter(sshKey => SshUtil.str2PublicKey(sshKey.publicKey).contains(key)) match {
|
||||
case List(x) if x.allowWrite => true
|
||||
case _ => false
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
class DefaultGitUploadPack(owner: String, repoName: String) extends DefaultGitCommand(owner, repoName)
|
||||
with RepositoryService with AccountService {
|
||||
with RepositoryService with AccountService with DeployKeyService {
|
||||
|
||||
override protected def runTask(user: String): Unit = {
|
||||
override protected def runTask(authType: AuthType): Unit = {
|
||||
val execute = Database() withSession { implicit session =>
|
||||
getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", "")).map { repositoryInfo =>
|
||||
!repositoryInfo.repository.isPrivate || isWritableUser(user, repositoryInfo)
|
||||
!repositoryInfo.repository.isPrivate || isReadableUser(authType, repositoryInfo)
|
||||
}.getOrElse(false)
|
||||
}
|
||||
|
||||
@@ -119,12 +155,12 @@ class DefaultGitUploadPack(owner: String, repoName: String) extends DefaultGitCo
|
||||
}
|
||||
|
||||
class DefaultGitReceivePack(owner: String, repoName: String, baseUrl: String) extends DefaultGitCommand(owner, repoName)
|
||||
with RepositoryService with AccountService {
|
||||
with RepositoryService with AccountService with DeployKeyService {
|
||||
|
||||
override protected def runTask(user: String): Unit = {
|
||||
override protected def runTask(authType: AuthType): Unit = {
|
||||
val execute = Database() withSession { implicit session =>
|
||||
getRepository(owner, repoName.replaceFirst("\\.wiki\\Z", "")).map { repositoryInfo =>
|
||||
isWritableUser(user, repositoryInfo)
|
||||
isWritableUser(authType, repositoryInfo)
|
||||
}.getOrElse(false)
|
||||
}
|
||||
|
||||
@@ -133,7 +169,7 @@ class DefaultGitReceivePack(owner: String, repoName: String, baseUrl: String) ex
|
||||
val repository = git.getRepository
|
||||
val receive = new ReceivePack(repository)
|
||||
if (!repoName.endsWith(".wiki")) {
|
||||
val hook = new CommitLogHook(owner, repoName, user, baseUrl)
|
||||
val hook = new CommitLogHook(owner, repoName, userName(authType), baseUrl)
|
||||
receive.setPreReceiveHook(hook)
|
||||
receive.setPostReceiveHook(hook)
|
||||
}
|
||||
@@ -143,12 +179,11 @@ class DefaultGitReceivePack(owner: String, repoName: String, baseUrl: String) ex
|
||||
}
|
||||
}
|
||||
|
||||
class PluginGitUploadPack(repoName: String, routing: GitRepositoryRouting) extends GitCommand
|
||||
with SystemSettingsService {
|
||||
class PluginGitUploadPack(repoName: String, routing: GitRepositoryRouting) extends GitCommand with SystemSettingsService {
|
||||
|
||||
override protected def runTask(user: String): Unit = {
|
||||
override protected def runTask(authType: AuthType): Unit = {
|
||||
val execute = Database() withSession { implicit session =>
|
||||
routing.filter.filter("/" + repoName, Some(user), loadSystemSettings(), false)
|
||||
routing.filter.filter("/" + repoName, AuthType.userName(authType), loadSystemSettings(), false)
|
||||
}
|
||||
|
||||
if(execute){
|
||||
@@ -162,13 +197,13 @@ class PluginGitUploadPack(repoName: String, routing: GitRepositoryRouting) exten
|
||||
}
|
||||
}
|
||||
|
||||
class PluginGitReceivePack(repoName: String, routing: GitRepositoryRouting) extends GitCommand
|
||||
with SystemSettingsService {
|
||||
class PluginGitReceivePack(repoName: String, routing: GitRepositoryRouting) extends GitCommand with SystemSettingsService {
|
||||
|
||||
override protected def runTask(user: String): Unit = {
|
||||
override protected def runTask(authType: AuthType): Unit = {
|
||||
val execute = Database() withSession { implicit session =>
|
||||
routing.filter.filter("/" + repoName, Some(user), loadSystemSettings(), true)
|
||||
routing.filter.filter("/" + repoName, AuthType.userName(authType), loadSystemSettings(), true)
|
||||
}
|
||||
|
||||
if(execute){
|
||||
val path = routing.urlPattern.r.replaceFirstIn(repoName, routing.localPath)
|
||||
using(Git.open(new File(Directory.GitBucketHome, path))){ git =>
|
||||
|
||||
@@ -2,73 +2,102 @@ package gitbucket.core.ssh
|
||||
|
||||
import java.security.PublicKey
|
||||
|
||||
import gitbucket.core.service.SshKeyService
|
||||
import gitbucket.core.service.{DeployKeyService, SshKeyService}
|
||||
import gitbucket.core.servlet.Database
|
||||
import gitbucket.core.model.Profile.profile.blockingApi._
|
||||
import gitbucket.core.ssh.PublicKeyAuthenticator.AuthType
|
||||
import org.apache.sshd.server.auth.pubkey.PublickeyAuthenticator
|
||||
import org.apache.sshd.server.session.ServerSession
|
||||
import org.apache.sshd.common.AttributeStore
|
||||
import org.slf4j.LoggerFactory
|
||||
|
||||
object PublicKeyAuthenticator {
|
||||
|
||||
// put in the ServerSession here to be read by GitCommand later
|
||||
private val userNameSessionKey = new AttributeStore.AttributeKey[String]
|
||||
private val authTypeSessionKey = new AttributeStore.AttributeKey[AuthType]
|
||||
|
||||
def putUserName(serverSession:ServerSession, userName:String):Unit =
|
||||
serverSession.setAttribute(userNameSessionKey, userName)
|
||||
def putAuthType(serverSession: ServerSession, authType: AuthType):Unit =
|
||||
serverSession.setAttribute(authTypeSessionKey, authType)
|
||||
|
||||
def getUserName(serverSession:ServerSession):Option[String] =
|
||||
Option(serverSession.getAttribute(userNameSessionKey))
|
||||
def getAuthType(serverSession: ServerSession): Option[AuthType] =
|
||||
Option(serverSession.getAttribute(authTypeSessionKey))
|
||||
|
||||
sealed trait AuthType
|
||||
|
||||
object AuthType {
|
||||
case class UserAuthType(userName: String) extends AuthType
|
||||
case class DeployKeyType(publicKey: PublicKey) extends AuthType
|
||||
|
||||
/**
|
||||
* Retrieves username if authType is UserAuthType, otherwise None.
|
||||
*/
|
||||
def userName(authType: AuthType): Option[String] = {
|
||||
authType match {
|
||||
case UserAuthType(userName) => Some(userName)
|
||||
case _ => None
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class PublicKeyAuthenticator(genericUser:String) extends PublickeyAuthenticator with SshKeyService {
|
||||
class PublicKeyAuthenticator(genericUser: String) extends PublickeyAuthenticator with SshKeyService with DeployKeyService {
|
||||
private val logger = LoggerFactory.getLogger(classOf[PublicKeyAuthenticator])
|
||||
|
||||
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean =
|
||||
if (username == genericUser) authenticateGenericUser(username, key, session, genericUser)
|
||||
else authenticateLoginUser(username, key, session)
|
||||
|
||||
private def authenticateLoginUser(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
||||
val authenticated =
|
||||
Database()
|
||||
.withSession { implicit dbSession => getPublicKeys(username) }
|
||||
.map(_.publicKey)
|
||||
.flatMap(SshUtil.str2PublicKey)
|
||||
.contains(key)
|
||||
if (authenticated) {
|
||||
logger.info(s"authentication as ssh user ${username} succeeded")
|
||||
PublicKeyAuthenticator.putUserName(session, username)
|
||||
override def authenticate(username: String, key: PublicKey, session: ServerSession): Boolean = {
|
||||
Database().withSession { implicit s =>
|
||||
if (username == genericUser) {
|
||||
authenticateGenericUser(username, key, session, genericUser)
|
||||
} else {
|
||||
authenticateLoginUser(username, key, session)
|
||||
}
|
||||
}
|
||||
else {
|
||||
logger.info(s"authentication as ssh user ${username} failed")
|
||||
}
|
||||
|
||||
private def authenticateLoginUser(userName: String, key: PublicKey, session: ServerSession)(implicit s: Session): Boolean = {
|
||||
val authenticated = getPublicKeys(userName).map(_.publicKey).flatMap(SshUtil.str2PublicKey).contains(key)
|
||||
|
||||
if (authenticated) {
|
||||
logger.info(s"authentication as ssh user ${userName} succeeded")
|
||||
PublicKeyAuthenticator.putAuthType(session, AuthType.UserAuthType(userName))
|
||||
} else {
|
||||
logger.info(s"authentication as ssh user ${userName} failed")
|
||||
}
|
||||
authenticated
|
||||
}
|
||||
|
||||
private def authenticateGenericUser(username: String, key: PublicKey, session: ServerSession, genericUser:String): Boolean = {
|
||||
private def authenticateGenericUser(userName: String, key: PublicKey, session: ServerSession, genericUser: String)(implicit s: Session): Boolean = {
|
||||
// find all users having the key we got from ssh
|
||||
val possibleUserNames =
|
||||
Database()
|
||||
.withSession { implicit dbSession => getAllKeys() }
|
||||
.filter { sshKey =>
|
||||
SshUtil.str2PublicKey(sshKey.publicKey).exists(_ == key)
|
||||
}
|
||||
.map(_.userName)
|
||||
.distinct
|
||||
val possibleUserNames = getAllKeys().filter { sshKey =>
|
||||
SshUtil.str2PublicKey(sshKey.publicKey).contains(key)
|
||||
}.map(_.userName).distinct
|
||||
|
||||
// determine the user - if different accounts share the same key, tough luck
|
||||
val uniqueUserName =
|
||||
possibleUserNames match {
|
||||
case List() =>
|
||||
logger.info(s"authentication as generic user ${genericUser} failed, public key not found")
|
||||
None
|
||||
case List(name) =>
|
||||
logger.info(s"authentication as generic user ${genericUser} succeeded, identified ${name}")
|
||||
Some(name)
|
||||
case _ =>
|
||||
logger.info(s"authentication as generic user ${genericUser} failed, public key is ambiguous")
|
||||
None
|
||||
val uniqueUserName = possibleUserNames match {
|
||||
case List(name) => Some(name)
|
||||
case _ => None
|
||||
}
|
||||
|
||||
uniqueUserName.map { userName =>
|
||||
// found public key for user
|
||||
logger.info(s"authentication as generic user ${genericUser} succeeded, identified ${userName}")
|
||||
PublicKeyAuthenticator.putAuthType(session, AuthType.UserAuthType(userName))
|
||||
true
|
||||
}.getOrElse {
|
||||
// search deploy keys
|
||||
val existsDeployKey = getAllDeployKeys().exists { sshKey =>
|
||||
SshUtil.str2PublicKey(sshKey.publicKey).contains(key)
|
||||
}
|
||||
uniqueUserName.foreach(PublicKeyAuthenticator.putUserName(session, _))
|
||||
uniqueUserName.isDefined
|
||||
if(existsDeployKey){
|
||||
// found deploy key for repository
|
||||
PublicKeyAuthenticator.putAuthType(session, AuthType.DeployKeyType(key))
|
||||
logger.info(s"authentication as generic user ${genericUser} succeeded, deploy key was found")
|
||||
true
|
||||
} else {
|
||||
// public key not found
|
||||
logger.info(s"authentication by generic user ${genericUser} failed")
|
||||
false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
package gitbucket.core.ssh
|
||||
|
||||
import java.security.PublicKey
|
||||
import java.util.Base64
|
||||
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
import org.apache.sshd.common.config.keys.KeyUtils
|
||||
import org.apache.sshd.common.util.buffer.ByteArrayBuffer
|
||||
import org.eclipse.jgit.lib.Constants
|
||||
@@ -18,16 +18,17 @@ object SshUtil {
|
||||
val parts = key.split(" ")
|
||||
if (parts.size < 2) {
|
||||
logger.debug(s"Invalid PublicKey Format: ${key}")
|
||||
return None
|
||||
}
|
||||
try {
|
||||
val encodedKey = parts(1)
|
||||
val decode = Base64.decodeBase64(Constants.encodeASCII(encodedKey))
|
||||
Some(new ByteArrayBuffer(decode).getRawPublicKey)
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
logger.debug(e.getMessage, e)
|
||||
None
|
||||
None
|
||||
} else {
|
||||
try {
|
||||
val encodedKey = parts(1)
|
||||
val decode = Base64.getDecoder.decode(Constants.encodeASCII(encodedKey))
|
||||
Some(new ByteArrayBuffer(decode).getRawPublicKey)
|
||||
} catch {
|
||||
case e: Throwable =>
|
||||
logger.debug(e.getMessage, e)
|
||||
None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import java.util.Base64
|
||||
import javax.servlet.http.HttpServletResponse
|
||||
|
||||
/**
|
||||
@@ -13,9 +14,9 @@ object AuthUtil {
|
||||
|
||||
def decodeAuthHeader(header: String): String = {
|
||||
try {
|
||||
new String(new sun.misc.BASE64Decoder().decodeBuffer(header.substring(6)))
|
||||
new String(Base64.getDecoder.decode(header.substring(6)))
|
||||
} catch {
|
||||
case _: Throwable => ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import gitbucket.core.service.{AccountService, RepositoryService}
|
||||
import gitbucket.core.model.Role
|
||||
import RepositoryService.RepositoryInfo
|
||||
import Implicits._
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
|
||||
/**
|
||||
* Allows only oneself and administrators.
|
||||
|
||||
@@ -3,7 +3,7 @@ package gitbucket.core.util
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.apache.tika.Tika
|
||||
import java.io.File
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import scala.util.Random
|
||||
|
||||
object FileUtil {
|
||||
|
||||
@@ -3,7 +3,7 @@ package gitbucket.core.util
|
||||
import java.io._
|
||||
import java.sql._
|
||||
import java.text.SimpleDateFormat
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.mutable.ListBuffer
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import gitbucket.core.service.RepositoryService
|
||||
import org.eclipse.jgit.api.Git
|
||||
import Directory._
|
||||
import StringUtil._
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
|
||||
import scala.annotation.tailrec
|
||||
import scala.collection.JavaConverters._
|
||||
@@ -50,6 +50,7 @@ object JGitUtil {
|
||||
* @param id the object id
|
||||
* @param isDirectory whether is it directory
|
||||
* @param name the file (or directory) name
|
||||
* @param path the file (or directory) complete path
|
||||
* @param message the last commit message
|
||||
* @param commitId the last commit id
|
||||
* @param time the last modified time
|
||||
@@ -57,7 +58,7 @@ object JGitUtil {
|
||||
* @param mailAddress the committer's mail address
|
||||
* @param linkUrl the url of submodule
|
||||
*/
|
||||
case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, message: String, commitId: String,
|
||||
case class FileInfo(id: ObjectId, isDirectory: Boolean, name: String, path: String, message: String, commitId: String,
|
||||
time: Date, author: String, mailAddress: String, linkUrl: Option[String])
|
||||
|
||||
/**
|
||||
@@ -77,7 +78,7 @@ object JGitUtil {
|
||||
case class CommitInfo(id: String, shortMessage: String, fullMessage: String, parents: List[String],
|
||||
authorTime: Date, authorName: String, authorEmailAddress: String,
|
||||
commitTime: Date, committerName: String, committerEmailAddress: String){
|
||||
|
||||
|
||||
def this(rev: org.eclipse.jgit.revwalk.RevCommit) = this(
|
||||
rev.getName,
|
||||
rev.getShortMessage,
|
||||
@@ -158,7 +159,7 @@ object JGitUtil {
|
||||
|
||||
/**
|
||||
* Returns RevCommit from the commit or tag id.
|
||||
*
|
||||
*
|
||||
* @param git the Git object
|
||||
* @param objectId the ObjectId of the commit or tag
|
||||
* @return the RevCommit for the specified commit or tag
|
||||
@@ -239,7 +240,7 @@ object JGitUtil {
|
||||
|
||||
/**
|
||||
* Returns the file list of the specified path.
|
||||
*
|
||||
*
|
||||
* @param git the Git object
|
||||
* @param revision the branch name or commit id
|
||||
* @param path the directory path (optional)
|
||||
@@ -263,13 +264,13 @@ object JGitUtil {
|
||||
}
|
||||
}
|
||||
@tailrec
|
||||
def simplifyPath(tuple: (ObjectId, FileMode, String, Option[String], RevCommit)): (ObjectId, FileMode, String, Option[String], RevCommit) = tuple match {
|
||||
case (oid, FileMode.TREE, name, _, commit ) =>
|
||||
def simplifyPath(tuple: (ObjectId, FileMode, String, String, Option[String], RevCommit)): (ObjectId, FileMode, String, String, Option[String], RevCommit) = tuple match {
|
||||
case (oid, FileMode.TREE, name, path, _, commit ) =>
|
||||
(using(new TreeWalk(git.getRepository)) { walk =>
|
||||
walk.addTree(oid)
|
||||
// single tree child, or None
|
||||
if(walk.next() && walk.getFileMode(0) == FileMode.TREE){
|
||||
Some((walk.getObjectId(0), walk.getFileMode(0), name + "/" + walk.getNameString, None, commit)).filterNot(_ => walk.next())
|
||||
Some((walk.getObjectId(0), walk.getFileMode(0), name + "/" + walk.getNameString, path + "/" + walk.getNameString, None, commit)).filterNot(_ => walk.next())
|
||||
} else {
|
||||
None
|
||||
}
|
||||
@@ -280,14 +281,14 @@ object JGitUtil {
|
||||
case _ => tuple
|
||||
}
|
||||
|
||||
def tupleAdd(tuple:(ObjectId, FileMode, String, Option[String]), rev:RevCommit) = tuple match {
|
||||
case (oid, fmode, name, opt) => (oid, fmode, name, opt, rev)
|
||||
def tupleAdd(tuple:(ObjectId, FileMode, String, String, Option[String]), rev:RevCommit) = tuple match {
|
||||
case (oid, fmode, name, path, opt) => (oid, fmode, name, path, opt, rev)
|
||||
}
|
||||
|
||||
@tailrec
|
||||
def findLastCommits(result:List[(ObjectId, FileMode, String, Option[String], RevCommit)],
|
||||
restList:List[((ObjectId, FileMode, String, Option[String]), Map[RevCommit, RevCommit])],
|
||||
revIterator:java.util.Iterator[RevCommit]): List[(ObjectId, FileMode, String, Option[String], RevCommit)] ={
|
||||
def findLastCommits(result:List[(ObjectId, FileMode, String, String, Option[String], RevCommit)],
|
||||
restList:List[((ObjectId, FileMode, String, String, Option[String]), Map[RevCommit, RevCommit])],
|
||||
revIterator:java.util.Iterator[RevCommit]): List[(ObjectId, FileMode, String, String, Option[String], RevCommit)] ={
|
||||
if(restList.isEmpty){
|
||||
result
|
||||
} else if(!revIterator.hasNext){ // maybe, revCommit has only 1 log. other case, restList be empty
|
||||
@@ -327,13 +328,13 @@ object JGitUtil {
|
||||
}
|
||||
}
|
||||
|
||||
var fileList: List[(ObjectId, FileMode, String, Option[String])] = Nil
|
||||
var fileList: List[(ObjectId, FileMode, String, String, Option[String])] = Nil
|
||||
useTreeWalk(revCommit){ treeWalk =>
|
||||
while (treeWalk.next()) {
|
||||
val linkUrl = if (treeWalk.getFileMode(0) == FileMode.GITLINK) {
|
||||
getSubmodules(git, revCommit.getTree).find(_.path == treeWalk.getPathString).map(_.url)
|
||||
} else None
|
||||
fileList +:= (treeWalk.getObjectId(0), treeWalk.getFileMode(0), treeWalk.getNameString, linkUrl)
|
||||
fileList +:= (treeWalk.getObjectId(0), treeWalk.getFileMode(0), treeWalk.getNameString, treeWalk.getPathString, linkUrl)
|
||||
}
|
||||
}
|
||||
revWalk.markStart(revCommit)
|
||||
@@ -342,11 +343,12 @@ object JGitUtil {
|
||||
val nextParentsMap = Option(lastCommit).map(_.getParents.map(_ -> lastCommit).toMap).getOrElse(Map())
|
||||
findLastCommits(List.empty, fileList.map(a => a -> nextParentsMap), it)
|
||||
.map(simplifyPath)
|
||||
.map { case (objectId, fileMode, name, linkUrl, commit) =>
|
||||
.map { case (objectId, fileMode, name, path, linkUrl, commit) =>
|
||||
FileInfo(
|
||||
objectId,
|
||||
fileMode == FileMode.TREE || fileMode == FileMode.GITLINK,
|
||||
name,
|
||||
path,
|
||||
getSummaryMessage(commit.getFullMessage, commit.getShortMessage),
|
||||
commit.getName,
|
||||
commit.getAuthorIdent.getWhen,
|
||||
@@ -409,7 +411,7 @@ object JGitUtil {
|
||||
|
||||
/**
|
||||
* Returns the commit list of the specified branch.
|
||||
*
|
||||
*
|
||||
* @param git the Git object
|
||||
* @param revision the branch name or commit id
|
||||
* @param page the page number (1-)
|
||||
@@ -419,7 +421,7 @@ object JGitUtil {
|
||||
*/
|
||||
def getCommitLog(git: Git, revision: String, page: Int = 1, limit: Int = 0, path: String = ""): Either[String, (List[CommitInfo], Boolean)] = {
|
||||
val fixedPage = if(page <= 0) 1 else page
|
||||
|
||||
|
||||
@scala.annotation.tailrec
|
||||
def getCommitLog(i: java.util.Iterator[RevCommit], count: Int, logs: List[CommitInfo]): (List[CommitInfo], Boolean) =
|
||||
i.hasNext match {
|
||||
@@ -429,7 +431,7 @@ object JGitUtil {
|
||||
}
|
||||
case _ => (logs, i.hasNext)
|
||||
}
|
||||
|
||||
|
||||
using(new RevWalk(git.getRepository)){ revWalk =>
|
||||
defining(git.getRepository.resolve(revision)){ objectId =>
|
||||
if(objectId == null){
|
||||
@@ -467,10 +469,10 @@ object JGitUtil {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Returns the commit list between two revisions.
|
||||
*
|
||||
*
|
||||
* @param git the Git object
|
||||
* @param from the from revision
|
||||
* @param to the to revision
|
||||
@@ -479,10 +481,10 @@ object JGitUtil {
|
||||
// TODO swap parameters 'from' and 'to'!?
|
||||
def getCommitLog(git: Git, from: String, to: String): List[CommitInfo] =
|
||||
getCommitLogs(git, to)(_.getName == from)
|
||||
|
||||
|
||||
/**
|
||||
* Returns the latest RevCommit of the specified path.
|
||||
*
|
||||
*
|
||||
* @param git the Git object
|
||||
* @param path the path
|
||||
* @param revision the branch name or commit id
|
||||
@@ -536,6 +538,7 @@ object JGitUtil {
|
||||
} else {
|
||||
// initial commit
|
||||
using(new TreeWalk(git.getRepository)){ treeWalk =>
|
||||
treeWalk.setRecursive(true)
|
||||
treeWalk.addTree(revCommit.getTree)
|
||||
val buffer = new scala.collection.mutable.ListBuffer[DiffInfo]()
|
||||
while(treeWalk.next){
|
||||
@@ -949,17 +952,13 @@ object JGitUtil {
|
||||
* @return the last modified commit of specified path
|
||||
*/
|
||||
def getLastModifiedCommit(git: Git, startCommit: RevCommit, path: String): RevCommit = {
|
||||
return git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
|
||||
git.log.add(startCommit).addPath(path).setMaxCount(1).call.iterator.next
|
||||
}
|
||||
|
||||
def getBranches(owner: String, name: String, defaultBranch: String, origin: Boolean): Seq[BranchInfo] = {
|
||||
using(Git.open(getRepositoryDir(owner, name))){ git =>
|
||||
val repo = git.getRepository
|
||||
val defaultObject = if (repo.getAllRefs.keySet().contains(defaultBranch)) {
|
||||
repo.resolve(defaultBranch)
|
||||
} else {
|
||||
git.branchList().call().iterator().next().getObjectId
|
||||
}
|
||||
val defaultObject = repo.resolve(defaultBranch)
|
||||
|
||||
git.branchList.call.asScala.map { ref =>
|
||||
val walk = new RevWalk(repo)
|
||||
@@ -974,7 +973,7 @@ object JGitUtil {
|
||||
None
|
||||
} else {
|
||||
walk.reset()
|
||||
walk.setRevFilter( RevFilter.MERGE_BASE )
|
||||
walk.setRevFilter(RevFilter.MERGE_BASE)
|
||||
walk.markStart(branchCommit)
|
||||
walk.markStart(defaultCommit)
|
||||
val mergeBase = walk.next()
|
||||
@@ -987,7 +986,7 @@ object JGitUtil {
|
||||
}
|
||||
BranchInfo(branchName, committer, when, committerEmail, mergeInfo, ref.getObjectId.name)
|
||||
} finally {
|
||||
walk.dispose();
|
||||
walk.dispose()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import gitbucket.core.model.Account
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import gitbucket.core.service.SystemSettingsService
|
||||
import gitbucket.core.service.SystemSettingsService.Ldap
|
||||
import com.novell.ldap._
|
||||
@@ -111,9 +111,9 @@ object LDAPUtil {
|
||||
}
|
||||
}
|
||||
|
||||
val conn: LDAPConnection =
|
||||
val conn: LDAPConnection =
|
||||
if(ssl) {
|
||||
new LDAPConnection(new LDAPJSSESecureSocketFactory())
|
||||
new LDAPConnection(new LDAPJSSESecureSocketFactory())
|
||||
}else {
|
||||
new LDAPConnection(new LDAPJSSEStartTLSFactory())
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package gitbucket.core.util
|
||||
|
||||
import java.util.concurrent.ConcurrentHashMap
|
||||
import java.util.concurrent.locks.{ReentrantLock, Lock}
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
|
||||
object LockUtil {
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ import org.apache.commons.mail.{DefaultAuthenticator, HtmlEmail}
|
||||
import org.slf4j.LoggerFactory
|
||||
import gitbucket.core.controller.Context
|
||||
import SystemSettingsService.Smtp
|
||||
import ControlUtil.defining
|
||||
import SyntaxSugars.defining
|
||||
|
||||
trait Notifier extends RepositoryService with AccountService with IssuesService {
|
||||
|
||||
|
||||
@@ -1,12 +1,12 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import java.net.{URLDecoder, URLEncoder}
|
||||
import java.util.Base64
|
||||
|
||||
import org.mozilla.universalchardet.UniversalDetector
|
||||
import ControlUtil._
|
||||
import SyntaxSugars._
|
||||
import org.apache.commons.io.input.BOMInputStream
|
||||
import org.apache.commons.io.IOUtils
|
||||
import org.apache.commons.codec.binary.Base64
|
||||
|
||||
import scala.util.control.Exception._
|
||||
|
||||
@@ -34,14 +34,14 @@ object StringUtil {
|
||||
val spec = new javax.crypto.spec.SecretKeySpec(BlowfishKey.getBytes(), "Blowfish")
|
||||
val cipher = javax.crypto.Cipher.getInstance("Blowfish")
|
||||
cipher.init(javax.crypto.Cipher.ENCRYPT_MODE, spec)
|
||||
new String(Base64.encodeBase64(cipher.doFinal(value.getBytes("UTF-8"))), "UTF-8")
|
||||
Base64.getEncoder.encodeToString(cipher.doFinal(value.getBytes("UTF-8")))
|
||||
}
|
||||
|
||||
def decodeBlowfish(value: String): String = {
|
||||
val spec = new javax.crypto.spec.SecretKeySpec(BlowfishKey.getBytes(), "Blowfish")
|
||||
val cipher = javax.crypto.Cipher.getInstance("Blowfish")
|
||||
cipher.init(javax.crypto.Cipher.DECRYPT_MODE, spec)
|
||||
new String(cipher.doFinal(Base64.decodeBase64(value)), "UTF-8")
|
||||
new String(cipher.doFinal(Base64.getDecoder.decode(value)), "UTF-8")
|
||||
}
|
||||
|
||||
def urlEncode(value: String): String = URLEncoder.encode(value, "UTF-8").replace("+", "%20")
|
||||
|
||||
@@ -7,7 +7,7 @@ import scala.language.reflectiveCalls
|
||||
/**
|
||||
* Provides control facilities.
|
||||
*/
|
||||
object ControlUtil {
|
||||
object SyntaxSugars {
|
||||
|
||||
def defining[A, B](value: A)(f: A => B): B = f(value)
|
||||
|
||||
@@ -46,7 +46,11 @@ object ControlUtil {
|
||||
def ignore[T](f: => Unit): Unit = try {
|
||||
f
|
||||
} catch {
|
||||
case e: Exception => ()
|
||||
case _: Exception => ()
|
||||
}
|
||||
|
||||
object ~ {
|
||||
def unapply[A, B](t: (A, B)): Option[(A, B)] = Some(t)
|
||||
}
|
||||
|
||||
}
|
||||
127
src/main/scala/gitbucket/core/util/TextAvatarUtil.scala
Normal file
127
src/main/scala/gitbucket/core/util/TextAvatarUtil.scala
Normal file
@@ -0,0 +1,127 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.awt.image.BufferedImage
|
||||
import javax.imageio.ImageIO
|
||||
import java.awt.{Color, Font, Graphics2D, RenderingHints}
|
||||
import java.awt.font.{FontRenderContext, TextLayout}
|
||||
import java.awt.geom.AffineTransform
|
||||
|
||||
|
||||
object TextAvatarUtil {
|
||||
private val iconSize = 200
|
||||
private val fontSize = 180
|
||||
private val roundSize = 60
|
||||
private val shadowSize = 20
|
||||
private val bgSaturation = 0.68f
|
||||
private val bgBlightness = 0.73f
|
||||
private val shadowBlightness = 0.23f
|
||||
private val font = new Font(Font.SANS_SERIF, Font.PLAIN, fontSize)
|
||||
private val transparent = new Color(0, 0, 0, 0)
|
||||
|
||||
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#relativeluminancedef
|
||||
private def relativeLuminance(c: Color): Double = {
|
||||
val rgb = Seq(c.getRed, c.getGreen, c.getBlue).map{_/255.0}.map{x => if (x <= 0.03928) x / 12.92 else math.pow((x + 0.055) / 1.055, 2.4)}
|
||||
0.2126 * rgb(0) + 0.7152 * rgb(1) + 0.0722 * rgb(2)
|
||||
}
|
||||
|
||||
// https://www.w3.org/TR/2008/REC-WCAG20-20081211/#contrast-ratiodef
|
||||
private def contrastRatio(c1: Color, c2: Color): Double = {
|
||||
val l1 = relativeLuminance(c1)
|
||||
val l2 = relativeLuminance(c2)
|
||||
if (l1 > l2) (l1 + 0.05) / (l2 + 0.05) else (l2 + 0.05) / (l1 + 0.05)
|
||||
}
|
||||
|
||||
private def goodContrastColor(base: Color, c1: Color, c2: Color): Color = {
|
||||
if (contrastRatio(base, c1) > contrastRatio(base, c2)) c1 else c2
|
||||
}
|
||||
|
||||
private def strToHue(text: String): Float = {
|
||||
Integer.parseInt(StringUtil.md5(text).substring(0, 2), 16) / 256f
|
||||
}
|
||||
|
||||
private def getCenterToDraw(drawText: String, font: Font, w: Int, h: Int): (Int, Int) = {
|
||||
val context = new FontRenderContext(new AffineTransform(), true, true)
|
||||
val txt = new TextLayout(drawText, font, context)
|
||||
|
||||
val bounds = txt.getBounds
|
||||
|
||||
val x: Int = ((w - bounds.getWidth) / 2 - bounds.getX).toInt
|
||||
val y: Int = ((h - bounds.getHeight) / 2 - bounds.getY).toInt
|
||||
(x, y)
|
||||
}
|
||||
|
||||
private def textImage(drawText: String, bgColor: Color, fgColor: Color): Array[Byte] = {
|
||||
val canvas = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB)
|
||||
val g = canvas.createGraphics()
|
||||
val center = getCenterToDraw(drawText, font, iconSize, iconSize)
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
|
||||
g.setColor(transparent)
|
||||
g.fillRect(0, 0, iconSize, iconSize)
|
||||
|
||||
g.setColor(bgColor)
|
||||
g.fillRoundRect(0, 0, iconSize, iconSize, roundSize, roundSize)
|
||||
|
||||
g.setColor(fgColor)
|
||||
g.setFont(font)
|
||||
g.drawString(drawText, center._1, center._2)
|
||||
|
||||
g.dispose()
|
||||
|
||||
val stream = new ByteArrayOutputStream
|
||||
ImageIO.write(canvas, "png", stream)
|
||||
stream.toByteArray
|
||||
}
|
||||
|
||||
def textAvatar(nameText: String): Option[Array[Byte]] = {
|
||||
val drawText = nameText.substring(0, 1)
|
||||
|
||||
val bgHue = strToHue(nameText)
|
||||
val bgColor = Color.getHSBColor(bgHue, bgSaturation, bgBlightness)
|
||||
val fgColor = goodContrastColor(bgColor, Color.BLACK, Color.WHITE)
|
||||
|
||||
val font = new Font(Font.SANS_SERIF, Font.PLAIN, fontSize)
|
||||
if (font.canDisplayUpTo(drawText) == -1) Some(textImage(drawText, bgColor, fgColor)) else None
|
||||
}
|
||||
|
||||
private def textGroupImage(drawText: String, bgColor: Color, fgColor: Color, shadowColor: Color): Array[Byte] = {
|
||||
val canvas = new BufferedImage(iconSize, iconSize, BufferedImage.TYPE_INT_ARGB)
|
||||
val g = canvas.createGraphics()
|
||||
val center = getCenterToDraw(drawText, font, iconSize - shadowSize, iconSize - shadowSize)
|
||||
|
||||
g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON)
|
||||
|
||||
g.setColor(transparent)
|
||||
g.fillRect(0, 0, iconSize, iconSize)
|
||||
|
||||
g.setColor(shadowColor)
|
||||
g.fillRect(shadowSize, shadowSize, iconSize, iconSize)
|
||||
|
||||
g.setColor(bgColor)
|
||||
g.fillRect(0, 0, iconSize - shadowSize, iconSize - shadowSize)
|
||||
|
||||
g.setColor(fgColor)
|
||||
|
||||
g.setFont(font)
|
||||
g.drawString(drawText, center._1, center._2)
|
||||
|
||||
g.dispose()
|
||||
|
||||
val stream = new ByteArrayOutputStream
|
||||
ImageIO.write(canvas, "png", stream)
|
||||
stream.toByteArray
|
||||
}
|
||||
|
||||
def textGroupAvatar(nameText: String): Option[Array[Byte]] = {
|
||||
val drawText = nameText.substring(0, 1)
|
||||
|
||||
val bgHue = strToHue(nameText)
|
||||
val bgColor = Color.getHSBColor(bgHue, bgSaturation, bgBlightness)
|
||||
val fgColor = goodContrastColor(bgColor, Color.BLACK, Color.WHITE)
|
||||
val shadowColor = Color.getHSBColor(bgHue, bgSaturation, shadowBlightness)
|
||||
|
||||
if (font.canDisplayUpTo(drawText) == -1) Some(textGroupImage(drawText, bgColor, fgColor, shadowColor)) else None
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ trait AvatarImageProvider { self: RequestCache =>
|
||||
if(account.image.isEmpty && context.settings.gravatar){
|
||||
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
||||
} else {
|
||||
s"""${context.path}/${account.userName}/_avatar"""
|
||||
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
||||
}
|
||||
} getOrElse {
|
||||
s"""${context.path}/_unknown/_avatar"""
|
||||
@@ -31,7 +31,7 @@ trait AvatarImageProvider { self: RequestCache =>
|
||||
if(account.image.isEmpty && context.settings.gravatar){
|
||||
s"""https://www.gravatar.com/avatar/${StringUtil.md5(account.mailAddress.toLowerCase)}?s=${size}&d=retro&r=g"""
|
||||
} else {
|
||||
s"""${context.path}/${account.userName}/_avatar"""
|
||||
s"""${context.path}/${account.userName}/_avatar?${helpers.hashDate(account.updatedDate)}"""
|
||||
}
|
||||
} getOrElse {
|
||||
if(context.settings.gravatar){
|
||||
@@ -49,4 +49,4 @@ trait AvatarImageProvider { self: RequestCache =>
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,7 +44,6 @@ object Markdown {
|
||||
val renderer = new GitBucketMarkedRenderer(options, repository,
|
||||
enableWikiLink, enableRefsLink, enableAnchor, enableTaskList, hasWritePermission, pages)
|
||||
|
||||
//helpers.decorateHtml(Marked.marked(source, options, renderer), repository)
|
||||
Marked.marked(source, options, renderer)
|
||||
}
|
||||
|
||||
|
||||
@@ -74,6 +74,21 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
||||
*/
|
||||
def date(date: Date): String = new SimpleDateFormat("yyyy-MM-dd").format(date)
|
||||
|
||||
/**
|
||||
* Format java.util.Date to "yyyyMMDDHHmmss" (for url hash ex. /some/path.css?19800101010203
|
||||
*/
|
||||
def hashDate(date: Date): String = new SimpleDateFormat("yyyyMMddHHmmss").format(date)
|
||||
|
||||
/**
|
||||
* java.util.Date of boot timestamp.
|
||||
*/
|
||||
val bootDate: Date = new Date()
|
||||
|
||||
/**
|
||||
* hashDate of bootDate for /assets, /plugin-assets
|
||||
*/
|
||||
def hashQuery: String = hashDate(bootDate)
|
||||
|
||||
/**
|
||||
* Returns singular if count is 1, otherwise plural.
|
||||
* If plural is not specified, returns singular + "s" as plural.
|
||||
@@ -209,8 +224,14 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
||||
/**
|
||||
* Returns the url to the root of assets.
|
||||
*/
|
||||
@deprecated("Use assets(path: String)(implicit context: Context) instead.", "4.11.0")
|
||||
def assets(implicit context: Context): String = s"${context.path}/assets"
|
||||
|
||||
/**
|
||||
* Returns the url to the path of assets.
|
||||
*/
|
||||
def assets(path: String)(implicit context: Context): String = s"${context.path}/assets${path}?${hashQuery}"
|
||||
|
||||
/**
|
||||
* Generates the text link to the account page.
|
||||
* If user does not exist or disabled, this method returns user name as text without link.
|
||||
@@ -344,6 +365,10 @@ object helpers extends AvatarImageProvider with LinkConverter with RequestCache
|
||||
decorateHtml(HtmlFormat.fill(out).toString, repository)
|
||||
}
|
||||
|
||||
/**
|
||||
* Decorate a given HTML by TextDecorators which are provided by plug-ins.
|
||||
* TextDecorators are applied to only text parts of a given HTML.
|
||||
*/
|
||||
def decorateHtml(html: String, repository: RepositoryInfo)(implicit context: Context): String = {
|
||||
PluginRegistry().getTextDecorators.foldLeft(html){ case (html, decorator) =>
|
||||
val text = new StringBuilder()
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.account.html.main(account, groupNames, "activity"){
|
||||
<div class="pull-right">
|
||||
<a href="@context.path/@{account.userName}.atom"><img src="@{helpers.assets}/common/images/feed.png" alt="activities"></a>
|
||||
<a href="@context.path/@{account.userName}.atom"><img src="@helpers.assets("/common/images/feed.png")" alt="activities"></a>
|
||||
</div>
|
||||
@gitbucket.core.helper.html.activities(activities)
|
||||
}
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
</div>
|
||||
<form method="POST" action="@context.path/@account.userName/_ssh" validate="true">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Add an SSH Key</div>
|
||||
<div class="panel-heading strong">Add a SSH Key</div>
|
||||
<div class="panel-body">
|
||||
<fieldset class="form-group">
|
||||
<label for="title" class="strong">Title</label>
|
||||
@@ -30,7 +30,7 @@
|
||||
<fieldset class="form-group">
|
||||
<label for="publicKey" class="strong">Key</label>
|
||||
<div><span id="error-publicKey" class="error"></span></div>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 250px;"></textarea>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 200px;"></textarea>
|
||||
</fieldset>
|
||||
<input type="submit" class="btn btn-success" value="Add"/>
|
||||
</div>
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
@plugins.map { plugin =>
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">@plugin.pluginName</div>
|
||||
<div class="panel-heading strong" id="@plugin.pluginId">@plugin.pluginName</div>
|
||||
<div class="panel-body">
|
||||
<div class="row">
|
||||
<label class="col-md-2">Id</label>
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
@(info: Option[Any])(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.util.DatabaseConfig
|
||||
@gitbucket.core.html.main("System settings"){
|
||||
@gitbucket.core.admin.html.menu("system"){
|
||||
@gitbucket.core.helper.html.information(info)
|
||||
@@ -20,7 +21,17 @@
|
||||
</tr>
|
||||
<tr>
|
||||
<td>DATABASE_URL</td>
|
||||
<td>@gitbucket.core.util.DatabaseConfig.url</td>
|
||||
@if(DatabaseConfig.url.startsWith("jdbc:h2:")) {
|
||||
<td class="danger">
|
||||
<p>@gitbucket.core.util.DatabaseConfig.url</p>
|
||||
<p>
|
||||
Your GitBucket is running on embedded H2 database.
|
||||
Recommend to <a href="https://github.com/gitbucket/gitbucket/wiki/External-database-configuration">configure to use external database</a> if you would like to use GitBucket for important purpose.
|
||||
</p>
|
||||
</td>
|
||||
}else{
|
||||
<td>@gitbucket.core.util.DatabaseConfig.url</td>
|
||||
}
|
||||
</tr>
|
||||
</table>
|
||||
<!--====================================================================-->
|
||||
|
||||
@@ -49,10 +49,7 @@ $(function(){
|
||||
$('#filter-box').keyup(function(){
|
||||
var inputVal = $('#filter-box').val();
|
||||
$.each($('li.repo-link a'), function(index, elem) {
|
||||
console.log(inputVal);
|
||||
console.log(elem.text.trim());
|
||||
console.log(elem.text.trim().lastIndexOf(inputVal, 0));
|
||||
if (!inputVal || !elem.text.trim() || elem.text.trim().indexOf(inputVal) >= 0) {
|
||||
if ( !inputVal || !elem.text.trim() || elem.text.trim().toLowerCase().indexOf(inputVal.toLowerCase()) >= 0 ) {
|
||||
$(elem).parent().show();
|
||||
} else {
|
||||
$(elem).parent().hide();
|
||||
|
||||
@@ -31,7 +31,7 @@
|
||||
$('#branch-control-input').keyup(function() {
|
||||
var inputVal = $('#branch-control-input').val();
|
||||
$.each($('#branch-control-input').parent().parent().find('a'), function(index, elem) {
|
||||
if (!inputVal || !elem.text.trim() || elem.text.trim().lastIndexOf(inputVal, 0) >= 0) {
|
||||
if (!inputVal || !elem.text.trim() || elem.text.trim().toLowerCase().indexOf(inputVal.toLowerCase()) >= 0) {
|
||||
$(elem).parent().show();
|
||||
} else {
|
||||
$(elem).parent().hide();
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
Showing <a href="javascript:void(0);" id="toggle-file-list">@diffs.size changed @helpers.plural(diffs.size, "file")</a>
|
||||
<ul id="commit-file-list" style="display: none;">
|
||||
@diffs.zipWithIndex.map { case (diff, i) =>
|
||||
<li@if(i > 0){ class="border"}>
|
||||
<li class="border">
|
||||
<span class="pull-right diffstat" data-diff-id="@i"></span>
|
||||
<a href="#diff-@i">
|
||||
@if(diff.changeType == ChangeType.COPY || diff.changeType == ChangeType.RENAME){
|
||||
@@ -130,8 +130,8 @@
|
||||
</tr>
|
||||
</table>
|
||||
}
|
||||
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script>
|
||||
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
|
||||
<script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
|
||||
<link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
|
||||
<script>
|
||||
$(function(){
|
||||
@if(showIndex){
|
||||
|
||||
@@ -32,7 +32,7 @@ $(function(){
|
||||
$('#@{filter}-input').keyup(function() {
|
||||
var inputVal = $('#@{filter}-input').val();
|
||||
$.each($('#@{filter}-input').parent().parent().find('a'), function(index, elem) {
|
||||
if (!inputVal || !elem.text.trim() || elem.text.trim().lastIndexOf(inputVal, 0) >= 0) {
|
||||
if ( !inputVal || !elem.text.trim() || elem.text.trim().toLowerCase().indexOf(inputVal.toLowerCase()) >=0 ) {
|
||||
$(elem).parent().show();
|
||||
} else {
|
||||
$(elem).parent().hide();
|
||||
|
||||
@@ -38,8 +38,8 @@
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<link href="@helpers.assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
<script src="@helpers.assets/vendors/google-code-prettify/prettify.js"></script>
|
||||
<link href="@helpers.assets("/vendors/google-code-prettify/prettify.css")" type="text/css" rel="stylesheet"/>
|
||||
<script src="@helpers.assets("/vendors/google-code-prettify/prettify.js")"></script>
|
||||
<script>
|
||||
$(function(){
|
||||
@if(elastic){
|
||||
@@ -47,7 +47,7 @@ $(function(){
|
||||
}
|
||||
|
||||
$('#preview@uid').click(function(){
|
||||
$('#preview-area@uid').html('<img src="@helpers.assets/common/images/indicator.gif"> Previewing...');
|
||||
$('#preview-area@uid').html('<img src="@helpers.assets("/common/images/indicator.gif")"> Previewing...');
|
||||
$.post('@helpers.url(repository)/_preview', {
|
||||
content : $('#content@uid').val(),
|
||||
enableWikiLink : @enableWikiLink,
|
||||
|
||||
@@ -13,7 +13,7 @@
|
||||
@gitbucket.core.dashboard.html.tab()
|
||||
<div class="container">
|
||||
<div class="pull-right">
|
||||
<a href="@context.path/activities.atom"><img src="@helpers.assets/common/images/feed.png" alt="activities"></a>
|
||||
<a href="@context.path/activities.atom"><img src="@helpers.assets("/common/images/feed.png")" alt="activities"></a>
|
||||
</div>
|
||||
@gitbucket.core.helper.html.activities(activities)
|
||||
</div>
|
||||
|
||||
@@ -46,7 +46,9 @@
|
||||
} else {
|
||||
referenced the @issueOrPullRequest()
|
||||
}
|
||||
@gitbucket.core.helper.html.datetimeago(comment.registeredDate)
|
||||
<a href="@helpers.url(repository)/issues/@issue.get.issueId#comment-@comment.commentId">
|
||||
@gitbucket.core.helper.html.datetimeago(comment.registeredDate)
|
||||
</a>
|
||||
</span>
|
||||
@if(comment.action != "commit" && comment.action != "merge" && comment.action != "refer"
|
||||
&& (isManageable || context.loginAccount.map(_.userName == comment.commentedUserName).getOrElse(false))){
|
||||
|
||||
@@ -7,42 +7,42 @@
|
||||
<meta charset="utf-8">
|
||||
<title>@title</title>
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||
<link rel="icon" href="@helpers.assets/common/images/gitbucket.png" type="image/vnd.microsoft.icon" />
|
||||
<link rel="icon" href="@helpers.assets("/common/images/gitbucket.png")" type="image/vnd.microsoft.icon" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<link href="@helpers.assets/vendors/bootstrap-3.3.6/css/bootstrap.min.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/octicons-4.2.0/octicons.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/css/bootstrap-datetimepicker.min.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/colorpicker/css/bootstrap-colorpicker.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/google-code-prettify/prettify.css" type="text/css" rel="stylesheet"/>
|
||||
<link href="@helpers.assets/vendors/facebox/facebox.css" rel="stylesheet"/>
|
||||
<link href="@helpers.assets/vendors/AdminLTE-2.3.8/css/AdminLTE.min.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/AdminLTE-2.3.8/css/skins/skin-blue.min.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/vendors/font-awesome-4.6.3/css/font-awesome.min.css" rel="stylesheet">
|
||||
<link href="@helpers.assets/common/css/gitbucket.css" rel="stylesheet">
|
||||
<script src="@helpers.assets/vendors/jquery/jquery-1.12.2.min.js"></script>
|
||||
<script src="@helpers.assets/vendors/dropzone/dropzone.js"></script>
|
||||
<script src="@helpers.assets/common/js/validation.js"></script>
|
||||
<script src="@helpers.assets/common/js/gitbucket.js"></script>
|
||||
<script src="@helpers.assets/vendors/bootstrap-3.3.6/js/bootstrap.js"></script>
|
||||
<script src="@helpers.assets/vendors/bootstrap3-typeahead/bootstrap3-typeahead.js"></script>
|
||||
<script src="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/js/moment.min.js"></script>
|
||||
<script src="@helpers.assets/vendors/bootstrap-datetimepicker-4.17.44/js/bootstrap-datetimepicker.min.js"></script>
|
||||
<script src="@helpers.assets/vendors/colorpicker/js/bootstrap-colorpicker.js"></script>
|
||||
<script src="@helpers.assets/vendors/google-code-prettify/prettify.js"></script>
|
||||
<script src="@helpers.assets/vendors/elastic/jquery.elastic.source.js"></script>
|
||||
<script src="@helpers.assets/vendors/facebox/facebox.js"></script>
|
||||
<script src="@helpers.assets/vendors/jquery-hotkeys/jquery.hotkeys.js"></script>
|
||||
<script src="@helpers.assets/vendors/jquery-textcomplete-1.6.2/jquery.textcomplete.js"></script>
|
||||
<link href="@helpers.assets("/vendors/bootstrap-3.3.6/css/bootstrap.min.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/octicons-4.2.0/octicons.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/css/bootstrap-datetimepicker.min.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/colorpicker/css/bootstrap-colorpicker.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/google-code-prettify/prettify.css")" type="text/css" rel="stylesheet"/>
|
||||
<link href="@helpers.assets("/vendors/facebox/facebox.css")" rel="stylesheet"/>
|
||||
<link href="@helpers.assets("/vendors/AdminLTE-2.3.8/css/AdminLTE.min.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/AdminLTE-2.3.8/css/skins/skin-blue.min.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/vendors/font-awesome-4.6.3/css/font-awesome.min.css")" rel="stylesheet">
|
||||
<link href="@helpers.assets("/common/css/gitbucket.css")" rel="stylesheet">
|
||||
<script src="@helpers.assets("/vendors/jquery/jquery-1.12.2.min.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/dropzone/dropzone.js")"></script>
|
||||
<script src="@helpers.assets("/common/js/validation.js")"></script>
|
||||
<script src="@helpers.assets("/common/js/gitbucket.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/bootstrap-3.3.6/js/bootstrap.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/bootstrap3-typeahead/bootstrap3-typeahead.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/js/moment.min.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/bootstrap-datetimepicker-4.17.44/js/bootstrap-datetimepicker.min.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/colorpicker/js/bootstrap-colorpicker.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/google-code-prettify/prettify.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/elastic/jquery.elastic.source.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/facebox/facebox.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/jquery-hotkeys/jquery.hotkeys.js")"></script>
|
||||
<script src="@helpers.assets("/vendors/jquery-textcomplete-1.6.2/jquery.textcomplete.js")"></script>
|
||||
@repository.map { repository =>
|
||||
<meta name="go-import" content="@context.baseUrl.replaceFirst("^https?://", "")/@repository.owner/@repository.name git @repository.httpUrl" />
|
||||
}
|
||||
<script src="@helpers.assets/vendors/AdminLTE-2.3.8/js/app.js" type="text/javascript"></script>
|
||||
<script src="@helpers.assets("/vendors/AdminLTE-2.3.8/js/app.js")" type="text/javascript"></script>
|
||||
</head>
|
||||
<body class="skin-blue page-load @if(context.sidebarCollapse){sidebar-collapse}">
|
||||
<div class="wrapper">
|
||||
<header class="main-header">
|
||||
<a href="@context.path/" class="logo">
|
||||
<img src="@helpers.assets/common/images/gitbucket.png" style="width: 24px; height: 24px; display: inline;"/>
|
||||
<img src="@helpers.assets("/common/images/gitbucket.png")" style="width: 24px; height: 24px; display: inline;"/>
|
||||
GitBucket
|
||||
<span class="header-version">@gitbucket.core.GitBucketCoreModule.getVersions.last.getVersion</span>
|
||||
</a>
|
||||
|
||||
@@ -43,7 +43,7 @@
|
||||
}
|
||||
</div>
|
||||
<div class="check-conflict" style="display: none;">
|
||||
<img src="@helpers.assets/common/images/indicator.gif"/> Checking...
|
||||
<img src="@helpers.assets("/common/images/indicator.gif")"/> Checking...
|
||||
</div>
|
||||
</div>
|
||||
@if(commits.nonEmpty && context.loginAccount.isDefined){
|
||||
@@ -221,3 +221,27 @@ $(function(){
|
||||
}
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
function dropdownFilter(dropdownItem,placeHolder,id) {
|
||||
$('<li><input id="' + id + '" type="text" class="form-control input-sm dropdown-filter-input" placeholder="' + placeHolder + '"/></li>')
|
||||
.insertBefore($("li:has(a" + dropdownItem + "):first"));
|
||||
$('#'+id).keyup(function() {
|
||||
var inputVal = $('#'+id).val();
|
||||
$.each($('#'+id).parent().parent().find('a'), function(index, elem) {
|
||||
if (!inputVal || !elem.text.trim() || elem.text.trim().toLowerCase().indexOf(inputVal.toLowerCase()) >= 0) {
|
||||
$(elem).parent().show();
|
||||
} else {
|
||||
$(elem).parent().hide();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
$(function(){
|
||||
dropdownFilter('.origin-owner', 'Find Repository...', 'origin-owner-control-input');
|
||||
dropdownFilter('.origin-branch','Find Branch...', 'origin-branch-control-input');
|
||||
dropdownFilter('.forked-owner', 'Find Repository...', 'forked-owner-control-input');
|
||||
dropdownFilter('.forked-branch','Find Branch...', 'forked-branch-control-input');
|
||||
});
|
||||
</script>
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
<div class="check-conflict" style="display: none;">
|
||||
<div class="issue-comment-box" style="background-color: #fbeed5">
|
||||
<div class="box-content"class="issue-content" style="border: 1px solid #c09853; padding: 10px;">
|
||||
<img src="@helpers.assets/common/images/indicator.gif"/> Checking...
|
||||
<img src="@helpers.assets("/common/images/indicator.gif")"/> Checking...
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -63,4 +63,4 @@ $(function(){
|
||||
});
|
||||
}
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -112,20 +112,19 @@
|
||||
<p>
|
||||
<span class="strong">Step 1:</span> From your project repository, check out a new branch and test the changes.
|
||||
</p>
|
||||
@defining(s"git checkout -b ${pullreq.requestUserName}-${pullreq.requestBranch} ${pullreq.branch}\n" +
|
||||
s"git pull ${forkedRepository.httpUrl} ${pullreq.requestBranch}"){ command =>
|
||||
@gitbucket.core.helper.html.copy("merge-command", "merge-command-copy-1", command, "position: absolute; right: 31px;")()
|
||||
<pre style="font-size: 12px; border-radius: 3px;" id="merge-command">@Html(command)</pre>
|
||||
@helpers.pre {
|
||||
git checkout -b @{pullreq.requestUserName}-@{pullreq.requestBranch} @{pullreq.branch}
|
||||
git pull @{forkedRepository.httpUrl} @{pullreq.requestBranch}
|
||||
}
|
||||
</div>
|
||||
<div>
|
||||
<p>
|
||||
<span class="strong">Step 2:</span> Merge the changes and update on the server.
|
||||
</p>
|
||||
@defining(s"git checkout ${pullreq.branch}\ngit merge --no-ff ${pullreq.requestUserName}-${pullreq.requestBranch}\n" +
|
||||
s"git push origin ${pullreq.branch}"){ command =>
|
||||
@gitbucket.core.helper.html.copy("merge-command-2", "merge-command-copy-2", command, "position: absolute; right: 31px;")()
|
||||
<pre style="font-size: 12px; border-radius: 3px;" id="merge-command-2">@command</pre>
|
||||
@helpers.pre {
|
||||
git checkout @{pullreq.branch}
|
||||
git merge --no-ff @{pullreq.requestUserName}-@{pullreq.requestBranch}
|
||||
git push origin @{pullreq.branch}
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -50,10 +50,10 @@
|
||||
</form>
|
||||
}
|
||||
}
|
||||
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script>
|
||||
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
|
||||
<script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
|
||||
<link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
|
||||
<script>
|
||||
$(function(){
|
||||
diffUsingJS('oldText', 'newText', 'diffText', 1);
|
||||
});
|
||||
</script>
|
||||
</script>
|
||||
|
||||
@@ -72,9 +72,9 @@
|
||||
</form>
|
||||
}
|
||||
}
|
||||
<script src="@helpers.assets/vendors/ace/ace.js" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="@helpers.assets/vendors/jsdifflib/difflib.js"></script>
|
||||
<link href="@helpers.assets/vendors/jsdifflib/diffview.css" type="text/css" rel="stylesheet" />
|
||||
<script src="@helpers.assets("/vendors/ace/ace.js")" type="text/javascript" charset="utf-8"></script>
|
||||
<script type="text/javascript" src="@helpers.assets("/vendors/jsdifflib/difflib.js")"></script>
|
||||
<link href="@helpers.assets("/vendors/jsdifflib/diffview.css")" type="text/css" rel="stylesheet" />
|
||||
<script>
|
||||
$(function(){
|
||||
$('#editor').text($('#initial').val());
|
||||
@@ -132,7 +132,7 @@ $(function(){
|
||||
|
||||
@if(fileName.map(helpers.isRenderable _).getOrElse(false)) {
|
||||
// update preview
|
||||
$('#preview').html('<img src="@helpers.assets/common/images/indicator.gif"> Previewing...');
|
||||
$('#preview').html('<img src="@helpers.assets("/common/images/indicator.gif")"> Previewing...');
|
||||
$.post('@helpers.url(repository)/_preview', {
|
||||
content : editor.getValue(),
|
||||
enableWikiLink : false,
|
||||
|
||||
@@ -49,8 +49,8 @@
|
||||
<script>
|
||||
$(function(){
|
||||
$('a[rel*=facebox]').facebox({
|
||||
'loadingImage': '@helpers.assets/vendors/facebox/loading.gif',
|
||||
'closeImage': '@helpers.assets/vendors/facebox/closelabel.png'
|
||||
'loadingImage': '@helpers.assets("/vendors/facebox/loading.gif")',
|
||||
'closeImage': '@helpers.assets("/vendors/facebox/closelabel.png")'
|
||||
});
|
||||
|
||||
$(document).on("click", ".js-fork-owner-select-target", function() {
|
||||
|
||||
@@ -46,14 +46,12 @@
|
||||
</form>
|
||||
</p>
|
||||
|
||||
<table class="table table-bordered table-hover branches">
|
||||
<table class="table table-hover branches">
|
||||
@protectedBranchList.map { branch =>
|
||||
<tr>
|
||||
<td>
|
||||
<span class="branch-name">@branch</span>
|
||||
<span class="branch-action">
|
||||
<a href="@helpers.url(repository)/settings/branches/@helpers.encodeRefName(branch)" class="btn btn-small btn-default">Edit</a>
|
||||
</span>
|
||||
<a href="@helpers.url(repository)/settings/branches/@helpers.urlEncode(branch)" class="btn btn-sm btn-default pull-right">Edit</a>
|
||||
</td>
|
||||
</tr>
|
||||
}
|
||||
@@ -64,4 +62,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,30 +33,30 @@
|
||||
Sorry, we couldn’t find any status checks in the last week for this repository.<br />
|
||||
Please create a commit status by API (<a href="https://developer.github.com/v3/repos/statuses/">Learn more about status checks on GitHub</a>)
|
||||
</div>
|
||||
}else{
|
||||
<div class="js-has_required_statuses" style="display:none">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Choose which status checks must pass before branches can be merged into <b>@branch</b>.</div>
|
||||
<div class="panel-body">
|
||||
@knownContexts.map { context =>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="contexts" value="@context" onclick="update()" @check(protection.status.contexts.find(_ == context))>
|
||||
<span>@context</span>
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
} else {
|
||||
<div class="js-has_required_statuses" style="display:none">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">Choose which status checks must pass before branches can be merged into <b>@branch</b>.</div>
|
||||
<div class="panel-body">
|
||||
@knownContexts.map { context =>
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="contexts" value="@context" onclick="update()" @check(protection.status.contexts.find(_ == context))>
|
||||
<span>@context</span>
|
||||
</label>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="enforce_for_admins" onclick="update()" @check(protection.status.enforcement_level.name=="everyone")>
|
||||
<span class="strong">Include administrators</span>
|
||||
</label>
|
||||
<p class="help-block">Enforce required status checks for repository administrators.</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="checkbox">
|
||||
<label>
|
||||
<input type="checkbox" name="enforce_for_admins" onclick="update()" @check(protection.status.enforcement_level.name=="everyone")>
|
||||
<span class="strong">Include administrators</span>
|
||||
</label>
|
||||
<p class="help-block">Enforce required status checks for repository administrators.</p>
|
||||
</div>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<input class="btn btn-success js-submit-btn" type="submit" value="Save changes" />
|
||||
|
||||
50
src/main/twirl/gitbucket/core/settings/deploykey.scala.html
Normal file
50
src/main/twirl/gitbucket/core/settings/deploykey.scala.html
Normal file
@@ -0,0 +1,50 @@
|
||||
@(repository: gitbucket.core.service.RepositoryService.RepositoryInfo, deployKeys: List[gitbucket.core.model.DeployKey])(implicit context: gitbucket.core.controller.Context)
|
||||
@import gitbucket.core.ssh.SshUtil
|
||||
@import gitbucket.core.view.helpers
|
||||
@gitbucket.core.html.main("Deploy keys", Some(repository)){
|
||||
@gitbucket.core.html.menu("settings", repository){
|
||||
@gitbucket.core.settings.html.menu("deploykeys", repository){
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Deploy keys</div>
|
||||
<div class="panel-body">
|
||||
@if(deployKeys.isEmpty){
|
||||
No keys
|
||||
}
|
||||
@deployKeys.zipWithIndex.map { case (key, i) =>
|
||||
@if(i != 0){
|
||||
<hr>
|
||||
}
|
||||
<strong style="line-height: 30px;">@key.title</strong> (@SshUtil.fingerPrint(key.publicKey).getOrElse("Key is invalid."))
|
||||
@if(key.allowWrite){
|
||||
<label class="label label-warning">Write access</label>
|
||||
}
|
||||
<a href="@helpers.url(repository)/settings/deploykey/delete/@key.deployKeyId" class="btn btn-sm btn-danger pull-right">Delete</a>
|
||||
}
|
||||
</div>
|
||||
</div>
|
||||
<form method="POST" action="@helpers.url(repository)/settings/deploykey" validate="true">
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading strong">Add a deploy key</div>
|
||||
<div class="panel-body">
|
||||
<fieldset class="form-group">
|
||||
<label for="title" class="strong">Title</label>
|
||||
<div><span id="error-title" class="error"></span></div>
|
||||
<input type="text" name="title" id="title" class="form-control"/>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
<label for="publicKey" class="strong">Key</label>
|
||||
<div><span id="error-publicKey" class="error"></span></div>
|
||||
<textarea name="publicKey" id="publicKey" class="form-control" style="height: 200px;"></textarea>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
<label>
|
||||
<input type="checkbox" name="allowWrite"> Allow write access
|
||||
</label>
|
||||
</fieldset>
|
||||
<input type="submit" class="btn btn-success" value="Add"/>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,9 +33,9 @@
|
||||
<fieldset class="form-group">
|
||||
<label class="strong">Content type</label>
|
||||
<div></div>
|
||||
<select name="ctype">
|
||||
<option value="@WebHookContentType.FORM.code" @if(webHook.ctype == WebHookContentType.FORM){selected}>@WebHookContentType.FORM.ctype</option>
|
||||
<option value="@WebHookContentType.JSON.code" @if(webHook.ctype == WebHookContentType.JSON){selected}>@WebHookContentType.JSON.ctype</option>
|
||||
<select name="ctype" class="form-control" style="width: 500px;">
|
||||
<option value="@WebHookContentType.FORM.code" @if(webHook.ctype == WebHookContentType.FORM){selected}>@WebHookContentType.FORM.ctype</option>
|
||||
<option value="@WebHookContentType.JSON.code" @if(webHook.ctype == WebHookContentType.JSON){selected}>@WebHookContentType.JSON.ctype</option>
|
||||
</select>
|
||||
</fieldset>
|
||||
<fieldset class="form-group">
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
<li@if(active=="hooks"){ class="active"}>
|
||||
<a href="@helpers.url(repository)/settings/hooks">Service Hooks</a>
|
||||
</li>
|
||||
<li@if(active=="deploykeys"){ class="active"}>
|
||||
<a href="@helpers.url(repository)/settings/deploykey">Deploy Keys</a>
|
||||
</li>
|
||||
<li@if(active=="danger"){ class="active"}>
|
||||
<a href="@helpers.url(repository)/settings/danger">Danger Zone</a>
|
||||
</li>
|
||||
|
||||
@@ -342,6 +342,8 @@ div.account-image {
|
||||
|
||||
ul.dropdown-menu {
|
||||
padding: 2px 0;
|
||||
overflow: auto;
|
||||
max-height: 100vh;
|
||||
}
|
||||
|
||||
ul.dropdown-menu li {
|
||||
@@ -469,20 +471,6 @@ table.branches>thead>tr>th, table.branches>tbody>tr>td{
|
||||
color: #aaa;
|
||||
line-height: 20px;
|
||||
}
|
||||
.branches .branch-action{
|
||||
/*float: right;*/
|
||||
text-align: right;
|
||||
height: 20px;
|
||||
}
|
||||
.branches .branch-action a {
|
||||
font-size: 100%;
|
||||
}
|
||||
.branches .branch-action a.btn {
|
||||
font-size: 100%;
|
||||
position: relative;
|
||||
top: -6px;
|
||||
}
|
||||
|
||||
.branches .branch-a-b-count{
|
||||
color: rgba(0,0,0,0.5);
|
||||
}
|
||||
@@ -570,6 +558,7 @@ pre.commit-description {
|
||||
background-color: transparent;
|
||||
padding: 2px;
|
||||
margin: 0px;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
|
||||
#repository-url {
|
||||
@@ -600,6 +589,7 @@ ul#commit-file-list {
|
||||
ul#commit-file-list li.border {
|
||||
padding-bottom: 2px;
|
||||
border-top: 1px solid #eee;
|
||||
clear: right;
|
||||
}
|
||||
|
||||
li.L0, li.L1, li.L2, li.L3, li.L4, li.L5, li.L6, li.L7, li.L8, li.L9 {
|
||||
@@ -1141,7 +1131,7 @@ table.diff tbody tr.not-diff:hover td{
|
||||
}
|
||||
|
||||
.not-diff > .comment-box-container {
|
||||
white-space: initial;
|
||||
white-space: normal;
|
||||
line-height: initial;
|
||||
padding: 10px;
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
@import url(https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,600,700,300italic,400italic,600italic);
|
||||
/*!
|
||||
* AdminLTE v2.3.8
|
||||
* Author: Almsaeed Studio
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -29,7 +29,7 @@ class GitBucketCoreModuleSpec extends FunSuite {
|
||||
}
|
||||
|
||||
test("Migration MySQL", ExternalDBTest){
|
||||
val config = aMysqldConfig(v5_7_10)
|
||||
val config = aMysqldConfig(v5_7_latest)
|
||||
.withPort(3306)
|
||||
.withUser("sa", "sa")
|
||||
.withCharset(Charset.UTF8)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.util.Directory._
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import gitbucket.core.util.GitSpecUtil._
|
||||
|
||||
import org.eclipse.jgit.api.Git
|
||||
@@ -119,4 +119,4 @@ class MergeServiceSpec extends FunSpec {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,7 +2,7 @@ package gitbucket.core.service
|
||||
|
||||
import gitbucket.core.GitBucketCoreModule
|
||||
import gitbucket.core.util.{DatabaseConfig, FileUtil}
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
import io.github.gitbucket.solidbase.Solidbase
|
||||
import liquibase.database.core.H2Database
|
||||
import liquibase.database.jvm.JdbcConnection
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package gitbucket.core.util
|
||||
|
||||
import gitbucket.core.util.ControlUtil._
|
||||
import gitbucket.core.util.SyntaxSugars._
|
||||
|
||||
import org.apache.commons.io.FileUtils
|
||||
import org.eclipse.jgit.api.Git
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user