Merge branch 'master' into fixes/api
Conflicts: spec/requests/api/projects_spec.rb
This commit is contained in:
commit
eefb27f5ae
134 changed files with 1116 additions and 859 deletions
|
@ -20,7 +20,7 @@ module Gitlab
|
|||
class Project < Grape::Entity
|
||||
expose :id, :name, :description, :default_branch
|
||||
expose :owner, using: Entities::UserBasic
|
||||
expose :private_flag, as: :private
|
||||
expose :public
|
||||
expose :path, :path_with_namespace
|
||||
expose :issues_enabled, :merge_requests_enabled, :wall_enabled, :wiki_enabled, :created_at
|
||||
expose :namespace
|
||||
|
@ -35,12 +35,11 @@ module Gitlab
|
|||
class Group < Grape::Entity
|
||||
expose :id, :name, :path, :owner_id
|
||||
end
|
||||
|
||||
|
||||
class GroupDetail < Group
|
||||
expose :projects, using: Entities::Project
|
||||
end
|
||||
|
||||
|
||||
class RepoObject < Grape::Entity
|
||||
expose :name, :commit
|
||||
expose :protected do |repo, options|
|
||||
|
@ -63,7 +62,7 @@ module Gitlab
|
|||
class Milestone < Grape::Entity
|
||||
expose :id
|
||||
expose (:project_id) {|milestone| milestone.project.id}
|
||||
expose :title, :description, :due_date, :closed, :updated_at, :created_at
|
||||
expose :title, :description, :due_date, :state, :updated_at, :created_at
|
||||
end
|
||||
|
||||
class Issue < Grape::Entity
|
||||
|
@ -73,7 +72,7 @@ module Gitlab
|
|||
expose :label_list, as: :labels
|
||||
expose :milestone, using: Entities::Milestone
|
||||
expose :assignee, :author, using: Entities::UserBasic
|
||||
expose :closed, :updated_at, :created_at
|
||||
expose :state, :updated_at, :created_at
|
||||
end
|
||||
|
||||
class SSHKey < Grape::Entity
|
||||
|
@ -81,7 +80,7 @@ module Gitlab
|
|||
end
|
||||
|
||||
class MergeRequest < Grape::Entity
|
||||
expose :id, :target_branch, :source_branch, :project_id, :title, :closed, :merged
|
||||
expose :id, :target_branch, :source_branch, :project_id, :title, :state
|
||||
expose :author, :assignee, using: Entities::UserBasic
|
||||
end
|
||||
|
||||
|
|
|
@ -40,7 +40,9 @@ module Gitlab
|
|||
|
||||
get "/check" do
|
||||
{
|
||||
api_version: '3'
|
||||
api_version: Gitlab::API.version,
|
||||
gitlab_version: Gitlab::VERSION,
|
||||
gitlab_rev: Gitlab::REVISION,
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -69,14 +69,14 @@ module Gitlab
|
|||
# assignee_id (optional) - The ID of a user to assign issue
|
||||
# milestone_id (optional) - The ID of a milestone to assign issue
|
||||
# labels (optional) - The labels of an issue
|
||||
# closed (optional) - The state of an issue (0 = false, 1 = true)
|
||||
# state (optional) - The state of an issue (close|reopen)
|
||||
# Example Request:
|
||||
# PUT /projects/:id/issues/:issue_id
|
||||
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, :closed]
|
||||
attrs = attributes_for_keys [:title, :description, :assignee_id, :milestone_id, :state_event]
|
||||
attrs[:label_list] = params[:labels] if params[:labels].present?
|
||||
IssueObserver.current_user = current_user
|
||||
if @issue.update_attributes attrs
|
||||
|
|
|
@ -91,12 +91,12 @@ module Gitlab
|
|||
# target_branch - The target branch
|
||||
# assignee_id - Assignee user ID
|
||||
# title - Title of MR
|
||||
# closed - Status of MR. true - closed
|
||||
# state_event - Status of MR. (close|reopen|merge)
|
||||
# Example:
|
||||
# PUT /projects/:id/merge_request/:merge_request_id
|
||||
#
|
||||
put ":id/merge_request/:merge_request_id" do
|
||||
attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :closed]
|
||||
attrs = attributes_for_keys [:source_branch, :target_branch, :assignee_id, :title, :state_event]
|
||||
merge_request = user_project.merge_requests.find(params[:merge_request_id])
|
||||
|
||||
authorize! :modify_merge_request, merge_request
|
||||
|
|
|
@ -74,14 +74,14 @@ module Gitlab
|
|||
# title (optional) - The title of a milestone
|
||||
# description (optional) - The description of a milestone
|
||||
# due_date (optional) - The due date of a milestone
|
||||
# closed (optional) - The status of the milestone
|
||||
# state (optional) - The status of the milestone (close|activate)
|
||||
# Example Request:
|
||||
# PUT /projects/:id/milestones/:milestone_id
|
||||
put ":id/milestones/:milestone_id" do
|
||||
authorize! :admin_milestone, user_project
|
||||
|
||||
@milestone = user_project.milestones.find(params[:milestone_id])
|
||||
attrs = attributes_for_keys [:title, :description, :due_date, :closed]
|
||||
attrs = attributes_for_keys [:title, :description, :due_date, :state_event]
|
||||
if @milestone.update_attributes attrs
|
||||
present @milestone, with: Entities::Milestone
|
||||
else
|
||||
|
|
|
@ -184,6 +184,7 @@ module Gitlab
|
|||
# Example Request:
|
||||
# GET /projects/:id/hooks/:hook_id
|
||||
get ":id/hooks/:hook_id" do
|
||||
authorize! :admin_project, user_project
|
||||
@hook = user_project.hooks.find(params[:hook_id])
|
||||
present @hook, with: Entities::Hook
|
||||
end
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
require_relative 'shell_env'
|
||||
|
||||
module Grack
|
||||
class Auth < Rack::Auth::Basic
|
||||
attr_accessor :user, :project
|
||||
|
@ -7,9 +9,6 @@ module Grack
|
|||
@request = Rack::Request.new(env)
|
||||
@auth = Request.new(env)
|
||||
|
||||
# Pass Gitolite update hook
|
||||
ENV['GL_BYPASS_UPDATE_HOOK'] = "true"
|
||||
|
||||
# Need this patch due to the rails mount
|
||||
@env['PATH_INFO'] = @request.path
|
||||
@env['SCRIPT_NAME'] = ""
|
||||
|
@ -35,8 +34,7 @@ module Grack
|
|||
self.user = User.find_by_email(login) || User.find_by_username(login)
|
||||
return false unless user.try(:valid_password?, password)
|
||||
|
||||
# Set GL_USER env variable
|
||||
ENV['GL_USER'] = user.email
|
||||
Gitlab::ShellEnv.set_env(user)
|
||||
end
|
||||
|
||||
# Git upload and receive
|
||||
|
|
|
@ -10,7 +10,7 @@ module Gitlab
|
|||
# add_repository("gitlab/gitlab-ci")
|
||||
#
|
||||
def add_repository(name)
|
||||
system("/home/git/gitlab-shell/bin/gitlab-projects add-project #{name}.git")
|
||||
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects add-project #{name}.git")
|
||||
end
|
||||
|
||||
# Import repository
|
||||
|
@ -21,7 +21,7 @@ module Gitlab
|
|||
# import_repository("gitlab/gitlab-ci", "https://github.com/randx/six.git")
|
||||
#
|
||||
def import_repository(name, url)
|
||||
system("/home/git/gitlab-shell/bin/gitlab-projects import-project #{name}.git #{url}")
|
||||
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects import-project #{name}.git #{url}")
|
||||
end
|
||||
|
||||
# Remove repository from file system
|
||||
|
@ -32,7 +32,7 @@ module Gitlab
|
|||
# remove_repository("gitlab/gitlab-ci")
|
||||
#
|
||||
def remove_repository(name)
|
||||
system("/home/git/gitlab-shell/bin/gitlab-projects rm-project #{name}.git")
|
||||
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-projects rm-project #{name}.git")
|
||||
end
|
||||
|
||||
# Add new key to gitlab-shell
|
||||
|
@ -41,7 +41,7 @@ module Gitlab
|
|||
# add_key("key-42", "sha-rsa ...")
|
||||
#
|
||||
def add_key(key_id, key_content)
|
||||
system("/home/git/gitlab-shell/bin/gitlab-keys add-key #{key_id} \"#{key_content}\"")
|
||||
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys add-key #{key_id} \"#{key_content}\"")
|
||||
end
|
||||
|
||||
# Remove ssh key from gitlab shell
|
||||
|
@ -50,12 +50,16 @@ module Gitlab
|
|||
# remove_key("key-342", "sha-rsa ...")
|
||||
#
|
||||
def remove_key(key_id, key_content)
|
||||
system("/home/git/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"")
|
||||
system("#{gitlab_shell_user_home}/gitlab-shell/bin/gitlab-keys rm-key #{key_id} \"#{key_content}\"")
|
||||
end
|
||||
|
||||
|
||||
def url_to_repo path
|
||||
Gitlab.config.gitlab_shell.ssh_path_prefix + "#{path}.git"
|
||||
end
|
||||
|
||||
def gitlab_shell_user_home
|
||||
File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}")
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
|
17
lib/gitlab/backend/shell_env.rb
Normal file
17
lib/gitlab/backend/shell_env.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
module Gitlab
|
||||
# This module provide 2 methods
|
||||
# to set specific ENV variabled for GitLab Shell
|
||||
module ShellEnv
|
||||
extend self
|
||||
|
||||
def set_env(user)
|
||||
# Set GL_ID env variable
|
||||
ENV['GL_ID'] = "user-#{user.id}"
|
||||
end
|
||||
|
||||
def reset_env
|
||||
# Reset GL_ID env variable
|
||||
ENV['GL_ID'] = nil
|
||||
end
|
||||
end
|
||||
end
|
|
@ -10,6 +10,10 @@ module Gitlab
|
|||
/\A[a-zA-Z][a-zA-Z0-9_\-\. ]*\z/
|
||||
end
|
||||
|
||||
def name_regex
|
||||
/\A[a-zA-Z0-9_\-\. ]*\z/
|
||||
end
|
||||
|
||||
def path_regex
|
||||
default_regex
|
||||
end
|
||||
|
|
|
@ -17,6 +17,8 @@ module Gitlab
|
|||
# * Locks the satellite repo
|
||||
# * Yields the prepared satellite repo
|
||||
def in_locked_and_timed_satellite
|
||||
Gitlab::ShellEnv.set_env(user)
|
||||
|
||||
Grit::Git.with_timeout(options[:git_timeout]) do
|
||||
project.satellite.lock do
|
||||
return yield project.satellite.repo
|
||||
|
@ -28,6 +30,8 @@ module Gitlab
|
|||
rescue Grit::Git::GitTimeout => ex
|
||||
Gitlab::GitLogger.error(ex.message)
|
||||
return false
|
||||
ensure
|
||||
Gitlab::ShellEnv.reset_env
|
||||
end
|
||||
|
||||
# * Clears the satellite
|
||||
|
|
|
@ -40,8 +40,8 @@ namespace :gitlab do
|
|||
|
||||
puts ""
|
||||
puts "GitLab information".yellow
|
||||
puts "Version:\t#{Gitlab::Version}"
|
||||
puts "Revision:\t#{Gitlab::Revision}"
|
||||
puts "Version:\t#{Gitlab::VERSION}"
|
||||
puts "Revision:\t#{Gitlab::REVISION}"
|
||||
puts "Directory:\t#{Rails.root}"
|
||||
puts "DB Adapter:\t#{database_adapter}"
|
||||
puts "URL:\t\t#{Gitlab.config.gitlab.url}"
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
namespace :gitlab do
|
||||
desc "GITLAB | Setup production application"
|
||||
task :setup => :environment do
|
||||
setup
|
||||
setup_db
|
||||
end
|
||||
|
||||
def setup
|
||||
def setup_db
|
||||
warn_user_is_not_gitlab
|
||||
|
||||
puts "This will create the necessary database tables and seed the database."
|
||||
|
|
|
@ -25,12 +25,13 @@ namespace :gitlab do
|
|||
def setup
|
||||
warn_user_is_not_gitlab
|
||||
|
||||
gitlab_shell_authorized_keys = File.join(File.expand_path("~#{Gitlab.config.gitlab_shell.ssh_user}"),'.ssh/authorized_keys')
|
||||
puts "This will rebuild an authorized_keys file."
|
||||
puts "You will lose any data stored in /home/git/.ssh/authorized_keys."
|
||||
puts "You will lose any data stored in #{gitlab_shell_authorized_keys}."
|
||||
ask_to_continue
|
||||
puts ""
|
||||
|
||||
system("echo '# Managed by gitlab-shell' > /home/git/.ssh/authorized_keys")
|
||||
system("echo '# Managed by gitlab-shell' > #{gitlab_shell_authorized_keys}")
|
||||
|
||||
Key.find_each(batch_size: 1000) do |key|
|
||||
if Gitlab::Shell.new.add_key(key.shell_id, key.key)
|
||||
|
|
|
@ -77,8 +77,7 @@ namespace :gitlab do
|
|||
end
|
||||
|
||||
def gid_for(group_name)
|
||||
group_line = File.read("/etc/group").lines.select{|l| l.start_with?("#{group_name}:")}.first
|
||||
group_line.split(":")[2].to_i
|
||||
Etc.getgrnam(group_name).gid
|
||||
end
|
||||
|
||||
def warn_user_is_not_gitlab
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue