summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/api/entities.rb12
-rw-r--r--lib/api/helpers.rb4
-rw-r--r--lib/api/issues.rb14
-rw-r--r--lib/api/merge_requests.rb12
-rw-r--r--lib/api/projects.rb14
-rw-r--r--lib/api/repositories.rb2
-rw-r--r--lib/gitlab/compare_result.rb9
-rw-r--r--lib/gitlab/issues_labels.rb38
-rw-r--r--lib/gitlab/satellite/compare_action.rb35
-rw-r--r--lib/gitlab/satellite/merge_action.rb15
-rw-r--r--lib/gitlab/sidekiq_middleware/arguments_logger.rb10
-rw-r--r--lib/support/nginx/gitlab6
-rw-r--r--lib/support/nginx/gitlab-ssl83
-rw-r--r--lib/tasks/gitlab/shell.rake3
14 files changed, 134 insertions, 123 deletions
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index edde4c70fd7..8731db59e57 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -127,7 +127,7 @@ module API
end
class Issue < ProjectEntity
- expose :label_list, as: :labels
+ expose :label_names, as: :labels
expose :milestone, using: Entities::Milestone
expose :assignee, :author, using: Entities::UserBasic
end
@@ -136,7 +136,7 @@ module API
expose :target_branch, :source_branch, :upvotes, :downvotes
expose :author, :assignee, using: Entities::UserBasic
expose :source_project_id, :target_project_id
- expose :label_list, as: :labels
+ expose :label_names, as: :labels
end
class SSHKey < Grape::Entity
@@ -202,13 +202,13 @@ module API
class Compare < Grape::Entity
expose :commit, using: Entities::RepoCommit do |compare, options|
- if compare.commit
- Commit.new compare.commit
- end
+ Commit.decorate(compare.commits).last
end
+
expose :commits, using: Entities::RepoCommit do |compare, options|
- Commit.decorate compare.commits
+ Commit.decorate(compare.commits)
end
+
expose :diffs, using: Entities::RepoDiff do |compare, options|
compare.diffs
end
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index d7d209e16f7..8189e433789 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -5,6 +5,10 @@ module API
SUDO_HEADER ="HTTP_SUDO"
SUDO_PARAM = :sudo
+ def parse_boolean(value)
+ [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(value)
+ end
+
def current_user
private_token = (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]).to_s
@current_user ||= User.find_by(authentication_token: private_token)
diff --git a/lib/api/issues.rb b/lib/api/issues.rb
index f50be3a815d..b29118b2fd8 100644
--- a/lib/api/issues.rb
+++ b/lib/api/issues.rb
@@ -50,10 +50,15 @@ module API
post ":id/issues" do
required_attributes! [:title]
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id]
- attrs[:label_list] = params[:labels] if params[:labels].present?
+
issue = ::Issues::CreateService.new(user_project, current_user, attrs).execute
if issue.valid?
+ # Find or create labels and attach to issue
+ if params[:labels].present?
+ issue.add_labels_by_names(params[:labels].split(","))
+ end
+
present issue, with: Entities::Issue
else
not_found!
@@ -76,13 +81,16 @@ module API
put ":id/issues/:issue_id" do
issue = user_project.issues.find(params[:issue_id])
authorize! :modify_issue, issue
-
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
- attrs[:label_list] = params[:labels] if params[:labels].present?
issue = ::Issues::UpdateService.new(user_project, current_user, attrs).execute(issue)
if issue.valid?
+ # Find or create labels and attach to issue
+ if params[:labels].present?
+ issue.add_labels_by_names(params[:labels].split(","))
+ end
+
present issue, with: Entities::Issue
else
not_found!
diff --git a/lib/api/merge_requests.rb b/lib/api/merge_requests.rb
index fc1f1254a9e..acca7cb6bad 100644
--- a/lib/api/merge_requests.rb
+++ b/lib/api/merge_requests.rb
@@ -76,10 +76,14 @@ module API
authorize! :write_merge_request, user_project
required_attributes! [:source_branch, :target_branch, :title]
attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :target_project_id, :description]
- attrs[:label_list] = params[:labels] if params[:labels].present?
merge_request = ::MergeRequests::CreateService.new(user_project, current_user, attrs).execute
if merge_request.valid?
+ # Find or create labels and attach to issue
+ if params[:labels].present?
+ merge_request.add_labels_by_names(params[:labels].split(","))
+ end
+
present merge_request, with: Entities::MergeRequest
else
handle_merge_request_errors! merge_request.errors
@@ -103,12 +107,16 @@ module API
#
put ":id/merge_request/:merge_request_id" do
attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :state_event, :description]
- attrs[:label_list] = params[:labels] if params[:labels].present?
merge_request = user_project.merge_requests.find(params[:merge_request_id])
authorize! :modify_merge_request, merge_request
merge_request = ::MergeRequests::UpdateService.new(user_project, current_user, attrs).execute(merge_request)
if merge_request.valid?
+ # Find or create labels and attach to issue
+ if params[:labels].present?
+ merge_request.add_labels_by_names(params[:labels].split(","))
+ end
+
present merge_request, with: Entities::MergeRequest
else
handle_merge_request_errors! merge_request.errors
diff --git a/lib/api/projects.rb b/lib/api/projects.rb
index ab272426ce0..4c0766482f3 100644
--- a/lib/api/projects.rb
+++ b/lib/api/projects.rb
@@ -7,7 +7,7 @@ module API
helpers do
def map_public_to_visibility_level(attrs)
publik = attrs.delete(:public)
- publik = [ true, 1, '1', 't', 'T', 'true', 'TRUE', 'on', 'ON' ].include?(publik)
+ publik = parse_boolean(publik)
attrs[:visibility_level] = Gitlab::VisibilityLevel::PUBLIC if !attrs[:visibility_level].present? && publik == true
attrs
end
@@ -15,10 +15,18 @@ module API
# Get a projects list for authenticated user
#
+ # Parameters:
+ # archived (optional) - if passed, limit by archived status
+ #
# Example Request:
# GET /projects
get do
- @projects = paginate current_user.authorized_projects
+ @query = current_user.authorized_projects
+ # If the archived parameter is passed, limit results accordingly
+ if params[:archived].present?
+ @query = @query.where(archived: parse_boolean(params[:archived]))
+ end
+ @projects = paginate @query
present @projects, with: Entities::Project
end
@@ -222,7 +230,7 @@ module API
# Example Request:
# GET /projects/:id/labels
get ':id/labels' do
- @labels = user_project.issues_labels
+ @labels = user_project.labels
present @labels, with: Entities::Label
end
end
diff --git a/lib/api/repositories.rb b/lib/api/repositories.rb
index d091fa4f035..461ce4e59cf 100644
--- a/lib/api/repositories.rb
+++ b/lib/api/repositories.rb
@@ -147,7 +147,7 @@ module API
get ':id/repository/compare' do
authorize! :download_code, user_project
required_attributes! [:from, :to]
- compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to], MergeRequestDiff::COMMITS_SAFE_SIZE)
+ compare = Gitlab::Git::Compare.new(user_project.repository.raw_repository, params[:from], params[:to])
present compare, with: Entities::Compare
end
diff --git a/lib/gitlab/compare_result.rb b/lib/gitlab/compare_result.rb
new file mode 100644
index 00000000000..d72391dade5
--- /dev/null
+++ b/lib/gitlab/compare_result.rb
@@ -0,0 +1,9 @@
+module Gitlab
+ class CompareResult
+ attr_reader :commits, :diffs
+
+ def initialize(compare)
+ @commits, @diffs = compare.commits, compare.diffs
+ end
+ end
+end
diff --git a/lib/gitlab/issues_labels.rb b/lib/gitlab/issues_labels.rb
index bc49d27b521..0d34976736f 100644
--- a/lib/gitlab/issues_labels.rb
+++ b/lib/gitlab/issues_labels.rb
@@ -1,27 +1,27 @@
module Gitlab
class IssuesLabels
class << self
- def important_labels
- %w(bug critical confirmed)
- end
-
- def warning_labels
- %w(documentation support)
- end
-
- def neutral_labels
- %w(discussion suggestion)
- end
-
- def positive_labels
- %w(feature enhancement)
- end
-
def generate(project)
- labels = important_labels + warning_labels + neutral_labels + positive_labels
+ red = '#d9534f'
+ yellow = '#f0ad4e'
+ blue = '#428bca'
+ green = '#5cb85c'
+
+ labels = [
+ { title: "bug", color: red },
+ { title: "critical", color: red },
+ { title: "confirmed", color: red },
+ { title: "documentation", color: yellow },
+ { title: "support", color: yellow },
+ { title: "discussion", color: blue },
+ { title: "suggestion", color: blue },
+ { title: "feature", color: green },
+ { title: "enhancement", color: green }
+ ]
- project.issues_default_label_list = labels
- project.save
+ labels.each do |label|
+ project.labels.create(label)
+ end
end
end
end
diff --git a/lib/gitlab/satellite/compare_action.rb b/lib/gitlab/satellite/compare_action.rb
index 9c9e69e3515..46c98a8f4ca 100644
--- a/lib/gitlab/satellite/compare_action.rb
+++ b/lib/gitlab/satellite/compare_action.rb
@@ -10,34 +10,16 @@ module Gitlab
@source_project, @source_branch = source_project, source_branch
end
- # Only show what is new in the source branch compared to the target branch, not the other way around.
- # The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
- # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
- def diffs
+ # Compare 2 repositories and return Gitlab::CompareResult object
+ def result
in_locked_and_timed_satellite do |target_repo|
prepare_satellite!(target_repo)
update_satellite_source_and_target!(target_repo)
- common_commit = target_repo.git.native(:merge_base, default_options, ["origin/#{@target_branch}", "source/#{@source_branch}"]).strip
- #this method doesn't take default options
- diffs = target_repo.diff(common_commit, "source/#{@source_branch}")
- diffs = diffs.map { |diff| Gitlab::Git::Diff.new(diff) }
- diffs
- end
- rescue Grit::Git::CommandFailed => ex
- raise BranchesWithoutParent
- end
- # Retrieve an array of commits between the source and the target
- def commits
- in_locked_and_timed_satellite do |target_repo|
- prepare_satellite!(target_repo)
- update_satellite_source_and_target!(target_repo)
- commits = target_repo.commits_between("origin/#{@target_branch}", "source/#{@source_branch}")
- commits = commits.map { |commit| Gitlab::Git::Commit.new(commit, nil) }
- commits
+ Gitlab::CompareResult.new(compare(target_repo))
end
rescue Grit::Git::CommandFailed => ex
- handle_exception(ex)
+ raise BranchesWithoutParent
end
private
@@ -46,10 +28,17 @@ module Gitlab
def update_satellite_source_and_target!(target_repo)
target_repo.remote_add('source', @source_project.repository.path_to_repo)
target_repo.remote_fetch('source')
- target_repo.git.checkout(default_options({b: true}), @target_branch, "origin/#{@target_branch}")
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
end
+
+ def compare(repo)
+ @compare ||= Gitlab::Git::Compare.new(
+ Gitlab::Git::Repository.new(repo.path),
+ "origin/#{@target_branch}",
+ "source/#{@source_branch}"
+ )
+ end
end
end
end
diff --git a/lib/gitlab/satellite/merge_action.rb b/lib/gitlab/satellite/merge_action.rb
index 6c32dfb3ad9..7c9b2294647 100644
--- a/lib/gitlab/satellite/merge_action.rb
+++ b/lib/gitlab/satellite/merge_action.rb
@@ -45,27 +45,30 @@ module Gitlab
handle_exception(ex)
end
- # Get a raw diff of the source to the target
def diff_in_satellite
in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo)
update_satellite_source_and_target!(merge_repo)
- diff = merge_repo.git.native(:diff, default_options, "origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}")
+
+ # Only show what is new in the source branch compared to the target branch, not the other way around.
+ # The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
+ # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
+ common_commit = merge_repo.git.native(:merge_base, default_options, ["origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}"]).strip
+ merge_repo.git.native(:diff, default_options, common_commit, "source/#{merge_request.source_branch}")
end
rescue Grit::Git::CommandFailed => ex
handle_exception(ex)
end
- # Only show what is new in the source branch compared to the target branch, not the other way around.
- # The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
- # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
def diffs_between_satellite
in_locked_and_timed_satellite do |merge_repo|
prepare_satellite!(merge_repo)
update_satellite_source_and_target!(merge_repo)
if merge_request.for_fork?
+ # Only show what is new in the source branch compared to the target branch, not the other way around.
+ # The line below with merge_base is equivalent to diff with three dots (git diff branch1...branch2)
+ # From the git documentation: "git diff A...B" is equivalent to "git diff $(git-merge-base A B) B"
common_commit = merge_repo.git.native(:merge_base, default_options, ["origin/#{merge_request.target_branch}", "source/#{merge_request.source_branch}"]).strip
- #this method doesn't take default options
diffs = merge_repo.diff(common_commit, "source/#{merge_request.source_branch}")
else
raise "Attempt to determine diffs between for a non forked merge request in satellite MergeRequest.id:[#{merge_request.id}]"
diff --git a/lib/gitlab/sidekiq_middleware/arguments_logger.rb b/lib/gitlab/sidekiq_middleware/arguments_logger.rb
new file mode 100644
index 00000000000..7813091ec7b
--- /dev/null
+++ b/lib/gitlab/sidekiq_middleware/arguments_logger.rb
@@ -0,0 +1,10 @@
+module Gitlab
+ module SidekiqMiddleware
+ class ArgumentsLogger
+ def call(worker, job, queue)
+ Sidekiq.logger.info "arguments: #{job['args']}"
+ yield
+ end
+ end
+ end
+end
diff --git a/lib/support/nginx/gitlab b/lib/support/nginx/gitlab
index 36306eeb3a6..49306fb63da 100644
--- a/lib/support/nginx/gitlab
+++ b/lib/support/nginx/gitlab
@@ -20,9 +20,9 @@ upstream gitlab {
}
server {
- listen *:80 default_server; # e.g., listen 192.168.1.1:80; In most cases *:80 is a good idea
- server_name YOUR_SERVER_FQDN; # e.g., server_name source.example.com;
- server_tokens off; # don't show the version number, a security best practice
+ listen *:80 default_server;
+ server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
+ server_tokens off; ## Don't show the nginx version number, a security best practice
root /home/git/gitlab/public;
# Increase this if you want to upload large attachments
diff --git a/lib/support/nginx/gitlab-ssl b/lib/support/nginx/gitlab-ssl
index 22e923b377c..54a4a080a9f 100644
--- a/lib/support/nginx/gitlab-ssl
+++ b/lib/support/nginx/gitlab-ssl
@@ -3,33 +3,11 @@
##
## Modified from nginx http version
## Modified from http://blog.phusion.nl/2012/04/21/tutorial-setting-up-gitlab-on-debian-6/
+## Modified from https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
##
-## Lines starting with two hashes (##) are comments containing information
-## for configuration. One hash (#) comments are actual configuration parameters
-## which you can comment/uncomment to your liking.
-##
-###################################
-## SSL configuration ##
-###################################
-##
-## Optimal configuration is taken from:
-## https://raymii.org/s/tutorials/Strong_SSL_Security_On_nginx.html
-## Make sure to read it and understand what each option does.
-##
-## [Optional] Generate a self-signed ssl certificate:
-## mkdir /etc/nginx/ssl/
-## cd /etc/nginx/ssl/
-## sudo openssl req -newkey rsa:2048 -x509 -nodes -days 3560 -out gitlab.crt -keyout gitlab.key
-## sudo chmod o-r gitlab.key
-##
-## Edit `gitlab-shell/config.yml`:
-## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com`
-## 2) Set "ca_file" to `/etc/nginx/ssl/gitlab.crt`
-## 3) Set "self_signed_cert" to `true`
-## Edit `gitlab/config/gitlab.yml`:
-## 1) Define port for http "port: 443"
-## 2) Enable https "https: true"
-## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
+## Lines starting with two hashes (##) are comments with information.
+## Lines starting with one hash (#) are configuration parameters.
+## The last category can be commented/uncommented to your liking.
##
##################################
## CHUNKED TRANSFER ##
@@ -48,33 +26,41 @@
## [0] https://git.kernel.org/cgit/git/git.git/tree/Documentation/technical/http-protocol.txt#n99
## [1] https://github.com/agentzh/chunkin-nginx-module#status
## [2] https://github.com/agentzh/chunkin-nginx-module
-
+##
+###################################
+## SSL file editing ##
+###################################
+##
+## Edit `gitlab-shell/config.yml`:
+## 1) Set "gitlab_url" param in `gitlab-shell/config.yml` to `https://git.example.com`
+## 2) Set "ca_file" to `/etc/nginx/ssl/gitlab.crt`
+## 3) Set "self_signed_cert" to `true`
+## Edit `gitlab/config/gitlab.yml`:
+## 1) Define port for http "port: 443"
+## 2) Enable https "https: true"
+## 3) Update ssl for gravatar "ssl_url: https://secure.gravatar.com/avatar/%{hash}?s=%{size}&d=mm"
+##
+###################################
+## SSL configuration ##
+###################################
+##
upstream gitlab {
-
- ## Uncomment if you have set up unicorn to listen on a unix socket (recommended).
server unix:/home/git/gitlab/tmp/sockets/gitlab.socket;
-
- ## Uncomment if unicorn is configured to listen on a tcp port.
- ## Check the port number in /home/git/gitlab/config/unicorn.rb
- # server 127.0.0.1:8080;
}
## This is a normal HTTP host which redirects all traffic to the HTTPS host.
server {
- listen *:80;
- ## Replace git.example.com with your FQDN.
- server_name git.example.com;
- server_tokens off;
- ## root doesn't have to be a valid path since we are redirecting
- root /nowhere;
+ listen *:80 default_server;
+ server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
+ server_tokens off; ## Don't show the nginx version number, a security best practice
+ root /nowhere; ## root doesn't have to be a valid path since we are redirecting
rewrite ^ https://$server_name$request_uri permanent;
}
server {
listen 443 ssl;
- ## Replace git.example.com with your FQDN.
- server_name git.example.com;
+ server_name YOUR_SERVER_FQDN; ## Replace this with something like gitlab.example.com
server_tokens off;
root /home/git/gitlab/public;
@@ -93,22 +79,7 @@ server {
ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
ssl_session_cache builtin:1000 shared:SSL:10m;
- ## Enable OCSP stapling to reduce the overhead and latency of running SSL.
- ## Replace with your ssl_trusted_certificate. For more info see:
- ## - https://medium.com/devops-programming/4445f4862461
- ## - https://www.ruby-forum.com/topic/4419319
- ssl_stapling on;
- ssl_stapling_verify on;
- ssl_trusted_certificate /etc/nginx/ssl/stapling.trusted.crt;
- resolver 208.67.222.222 208.67.222.220 valid=300s;
- resolver_timeout 10s;
-
ssl_prefer_server_ciphers on;
- ## [Optional] Generate a stronger DHE parameter (recommended):
- ## cd /etc/ssl/certs
- ## openssl dhparam -out dhparam.pem 2048
- ##
- # ssl_dhparam /etc/ssl/certs/dhparam.pem;
add_header Strict-Transport-Security max-age=63072000;
add_header X-Frame-Options DENY;
diff --git a/lib/tasks/gitlab/shell.rake b/lib/tasks/gitlab/shell.rake
index dfc90bb3339..ff27e6a3066 100644
--- a/lib/tasks/gitlab/shell.rake
+++ b/lib/tasks/gitlab/shell.rake
@@ -4,7 +4,8 @@ namespace :gitlab do
task :install, [:tag, :repo] => :environment do |t, args|
warn_user_is_not_gitlab
- args.with_defaults(tag: "v1.9.3", repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
+ default_version = File.read(File.join(Rails.root, "GITLAB_SHELL_VERSION")).strip
+ args.with_defaults(tag: 'v' + default_version, repo: "https://gitlab.com/gitlab-org/gitlab-shell.git")
user = Settings.gitlab.user
home_dir = Settings.gitlab.user_home