Commit 0a94640e authored by Dmitriy Zaporozhets's avatar Dmitriy Zaporozhets

Merge branch 'refactoring/backend'

parents e6c0673e de6fa5dd
...@@ -24,3 +24,4 @@ db/data.yml ...@@ -24,3 +24,4 @@ db/data.yml
.DS_Store .DS_Store
.chef .chef
vendor/bundle/* vendor/bundle/*
rails_best_practices_output.html
...@@ -8,7 +8,7 @@ branches: ...@@ -8,7 +8,7 @@ branches:
only: only:
- 'master' - 'master'
rvm: rvm:
- 1.9.3 - 1.9.2
services: services:
- mysql - mysql
- postgresql - postgresql
......
...@@ -123,6 +123,8 @@ group :development do ...@@ -123,6 +123,8 @@ group :development do
gem 'better_errors' gem 'better_errors'
gem 'binding_of_caller' gem 'binding_of_caller'
gem 'rails_best_practices'
# Docs generator # Docs generator
gem "sdoc" gem "sdoc"
end end
......
...@@ -132,6 +132,8 @@ GEM ...@@ -132,6 +132,8 @@ GEM
chosen-rails (0.9.8) chosen-rails (0.9.8)
railties (~> 3.0) railties (~> 3.0)
thor (~> 0.14) thor (~> 0.14)
code_analyzer (0.3.1)
sexp_processor
coderay (1.0.8) coderay (1.0.8)
coffee-rails (3.2.2) coffee-rails (3.2.2)
coffee-script (>= 2.2.0) coffee-script (>= 2.2.0)
...@@ -302,6 +304,7 @@ GEM ...@@ -302,6 +304,7 @@ GEM
pg (0.14.1) pg (0.14.1)
polyglot (0.3.3) polyglot (0.3.3)
posix-spawn (0.3.6) posix-spawn (0.3.6)
progressbar (0.12.0)
pry (0.9.10) pry (0.9.10)
coderay (~> 1.0.5) coderay (~> 1.0.5)
method_source (~> 0.8) method_source (~> 0.8)
...@@ -335,6 +338,14 @@ GEM ...@@ -335,6 +338,14 @@ GEM
rails-dev-tweaks (0.6.1) rails-dev-tweaks (0.6.1)
actionpack (~> 3.1) actionpack (~> 3.1)
railties (~> 3.1) railties (~> 3.1)
rails_best_practices (1.13.2)
activesupport
awesome_print
code_analyzer
colored
erubis
i18n
progressbar
railties (3.2.9) railties (3.2.9)
actionpack (= 3.2.9) actionpack (= 3.2.9)
activesupport (= 3.2.9) activesupport (= 3.2.9)
...@@ -393,6 +404,7 @@ GEM ...@@ -393,6 +404,7 @@ GEM
multi_json (~> 1.0) multi_json (~> 1.0)
rubyzip rubyzip
settingslogic (2.0.8) settingslogic (2.0.8)
sexp_processor (4.1.3)
shoulda-matchers (1.3.0) shoulda-matchers (1.3.0)
activesupport (>= 3.0.0) activesupport (>= 3.0.0)
simplecov (0.7.1) simplecov (0.7.1)
...@@ -512,6 +524,7 @@ DEPENDENCIES ...@@ -512,6 +524,7 @@ DEPENDENCIES
rack-mini-profiler rack-mini-profiler
rails (= 3.2.9) rails (= 3.2.9)
rails-dev-tweaks rails-dev-tweaks
rails_best_practices
raphael-rails (= 1.5.2) raphael-rails (= 1.5.2)
rb-fsevent rb-fsevent
rb-inotify rb-inotify
......
/** /**
* =================================== * ===================================
* Contain 3 main UI block elements: * Contain UI block elements:
* .main_box - for show pages * .ui-box - for any block & widgets
* .ui-box - for simple block & widgets
* =================================== * ===================================
*/ */
/** /**
* UI box element * UI Block
* contains top, middle, bottom blocks
* *
*/ */
.main_box { .ui-box {
@extend .borders; background: #F9F9F9;
@extend .prepend-top-20; margin-bottom: 25px;
@extend .append-bottom-20; border: 1px solid #CCC;
border-width: 1px;
@include solid-shade; @include solid-shade;
&.ui-box-show {
margin:20px 0;
background: #FFF;
}
img { max-width: 100%; } img { max-width: 100%; }
...@@ -27,9 +28,9 @@ ...@@ -27,9 +28,9 @@
} }
} }
.top_box_content, .ui-box-head,
.middle_box_content, .ui-box-body,
.bottom_box_content { .ui-box-bottom {
padding: 15px; padding: 15px;
word-wrap: break-word; word-wrap: break-word;
...@@ -39,19 +40,25 @@ ...@@ -39,19 +40,25 @@
border: none; border: none;
padding: 0; padding: 0;
} }
.clearfix {
margin: 0;
}
} }
.top_box_content { .ui-box-head {
.box-title { .box-title {
color: $style_color; color: $style_color;
font-size: 18px; font-size: 18px;
font-weight: normal; font-weight: normal;
line-height: 28px; line-height: 28px;
} }
h3 {
margin: 0;
}
} }
.middle_box_content { .ui-box-body {
@include border-radius(0);
border: none; border: none;
font-size: 12px; font-size: 12px;
background-color: #f5f5f5; background-color: #f5f5f5;
...@@ -59,24 +66,9 @@ ...@@ -59,24 +66,9 @@
border-top: 1px solid #eee; border-top: 1px solid #eee;
} }
.bottom_box_content { .ui-box-bottom {
border-top: 1px solid #eee; border-top: 1px solid #eee;
} }
}
/**
* Big UI Block for show page content
*
*/
.ui-box {
background: #F9F9F9;
margin-bottom: 25px;
border: 1px solid #eaeaea;
@include border-radius(4px);
border-color: #CCC;
@include solid-shade;
&.white { &.white {
background: #fff; background: #fff;
...@@ -86,45 +78,45 @@ ...@@ -86,45 +78,45 @@
margin: 0; margin: 0;
} }
h5, .title { .title {
padding: 0 10px;
@include border-radius(4px 4px 0 0);
@include bg-gray-gradient; @include bg-gray-gradient;
border-top: 1px solid #eaeaea; border-bottom: 1px solid #CCC;
border-bottom: 1px solid #bbb; color: #456;
font-size: 16px;
text-shadow: 0 1px 1px #fff;
padding: 0px 10px;
line-height: 36px;
font-size: 14px;
font-weight: normal;
> a { > a {
text-shadow: 0 1px 1px #fff; text-shadow: 0 1px 1px #fff;
} }
&.small {
line-height: 28px;
font-size: 14px;
line-height: 28px;
text-shadow: 0 1px 1px white;
}
form { form {
padding: 9px 0; margin-bottom: 0;
margin: 0px; margin-top: 3px;
} }
.nav-pills { .nav-pills {
li { > li {
padding: 3px 0; > a {
&.active a { background-color: $style_color; } padding: 13px;
a { margin: 0;
@include border-radius(7px); font-size: 13px;
}
&.active {
> a {
background: #D5D5D5;
color: $style_color;
@include border-radius(0);
border-radius: 0;
border-left: 1px solid #CCC;
border-right: 1px solid #CCC;
} }
} }
} }
} }
.bottom {
@include bg-gray-gradient;
@include border-radius(0 0 4px 4px);
border-bottom: none;
border-top: 1px solid #bbb;
} }
&.padded { &.padded {
...@@ -143,6 +135,7 @@ ...@@ -143,6 +135,7 @@
color: #777; color: #777;
} }
} }
.row_title { .row_title {
font-weight: bold; font-weight: bold;
color: #444; color: #444;
...@@ -151,8 +144,4 @@ ...@@ -151,8 +144,4 @@
text-decoration: underline; text-decoration: underline;
} }
} }
.ui-box-body {
padding: 10px;
}
} }
...@@ -23,14 +23,12 @@ ...@@ -23,14 +23,12 @@
border-bottom: 1px solid #ADF; border-bottom: 1px solid #ADF;
} }
&:first-child {
@include border-radius(4px 4px 0 0);
border-top: none;
}
&:last-child { &:last-child {
@include border-radius(0 0 4px 4px); border-bottom: none;
border: none;
&.bottom {
background: #f5f5f5;
}
} }
.author { color: #999; } .author { color: #999; }
......
...@@ -25,7 +25,7 @@ table { ...@@ -25,7 +25,7 @@ table {
} }
th, td { th, td {
padding: 8px; padding: 10px;
line-height: 18px; line-height: 18px;
text-align: left; text-align: left;
} }
......
.commit-box {
@extend .main_box;
.commit-head {
@extend .top_box_content;
.commit-title {
line-height: 26px;
margin: 0;
}
.commit-description {
font-size: 14px;
border: none;
background-color: white;
padding-top: 10px;
}
.browse-button {
@extend .btn;
@extend .btn-small;
float: right;
}
}
.commit-info {
@extend .middle_box_content;
@extend .clearfix;
.sha-block {
text-align: right;
&:first-child {
padding-bottom: 6px;
}
a {
border-bottom: 1px solid #aaa;
margin-left: 9px;
}
}
&.merge-commit .sha-block {
clear: right;
}
.committer {
padding-left: 32px;
}
.author a,
.committer a {
font-size: 14px;
line-height: 22px;
text-shadow: 0 1px 1px #fff;
color: #777;
&:hover {
color: #999;
}
}
.avatar {
margin-right: 10px;
}
}
}
/** /**
* *
* COMMIT SHOw * COMMIT SHOw
* *
*/ */
.commit-committer-link,
.commit-author-link {
font-size: 13px;
color: #555;
&:hover {
color: #999;
}
}
.diff_file { .diff_file {
border: 1px solid #CCC; border: 1px solid #CCC;
margin-bottom: 1em; margin-bottom: 1em;
...@@ -255,13 +198,6 @@ ...@@ -255,13 +198,6 @@
min-width: 65px; min-width: 65px;
font-family: $monospace; font-family: $monospace;
} }
.commit-author-name {
color: #777;
&:hover {
color: #999;
}
}
} }
.diff_file_header a, .diff_file_header a,
......
.issue_form_box {
@extend .main_box;
.issue_title {
@extend .top_box_content;
.clearfix {
margin-bottom: 0px;
input {
@extend .span8;
}
}
}
.issue_middle_block {
@extend .middle_box_content;
height: 30px;
.issue_assignee {
@extend .span6;
float: left;
}
.issue_milestone {
@extend .span4;
float: left;
}
}
.issue_description {
@extend .bottom_box_content;
}
}
.issues_table { .issues_table {
.issue { .issue {
padding: 7px 10px; padding: 7px 10px;
...@@ -89,31 +61,25 @@ input.check_all_issues { ...@@ -89,31 +61,25 @@ input.check_all_issues {
#issues-table-holder { #issues-table-holder {
.issues_filters { .issues_filters {
form {
padding: 0;
margin: 0;
margin-top:7px
}
} }
.issues_bulk_update { .issues_bulk_update {
margin: 0; margin: 0;
form { form {
padding: 0; float:left;
margin: 0;
margin-top:7px
} }
.update_selected_issues { .update_selected_issues {
position: relative; position: relative;
top:-2px; top:5px;
margin-left: 4px; margin-left: 4px;
float: left; float: left;
} }
.update_issues_text { .update_issues_text {
padding: 3px; padding: 3px;
line-height: 18px; line-height: 28px;
float: left; float: left;
color: #479;
} }
} }
} }
......
/**
* MR form
*
*/
.mr_branch_box {
@extend .ui-box;
margin-bottom: 20px;
.body {
background: #f1f1f1;
}
}
/** /**
* MR -> show: Automerge widget * MR -> show: Automerge widget
...@@ -121,19 +107,3 @@ li.merge_request { ...@@ -121,19 +107,3 @@ li.merge_request {
.mr_direction_tip { .mr_direction_tip {
margin-top:40px margin-top:40px
} }
.merge_requests_form_box {
@extend .main_box;
.merge_requests_middle_box {
@extend .middle_box_content;
height: 30px;
.merge_requests_assignee {
@extend .span6;
float: left;
}
.merge_requests_milestone {
@extend .span4;
float: left;
}
}
}
...@@ -8,16 +8,12 @@ ...@@ -8,16 +8,12 @@
.groups_box, .groups_box,
.projects_box { .projects_box {
> h5 { > .title {
color: $style_color; padding: 2px 15px;
font-size: 16px;
text-shadow: 0 1px 1px #fff;
padding: 2px 10px;
line-height: 32px;
font-size: 14px;
} }
.nav-projects-tabs li { padding: 0; } .nav-projects-tabs li { padding: 0; }
.well-list { .well-list {
li { padding: 15px; }
.arrow { .arrow {
float: right; float: right;
padding: 10px; padding: 10px;
...@@ -109,7 +105,7 @@ ul.nav.nav-projects-tabs { ...@@ -109,7 +105,7 @@ ul.nav.nav-projects-tabs {
li { li {
a { a {
padding: 4px 20px; padding: 6px 25px;
margin-top: 2px; margin-top: 2px;
border-color: #DDD; border-color: #DDD;
background-color: #EEE; background-color: #EEE;
......
...@@ -9,7 +9,7 @@ class CommitLoadContext < BaseContext ...@@ -9,7 +9,7 @@ class CommitLoadContext < BaseContext
status: :ok status: :ok
} }
commit = project.commit(params[:id]) commit = project.repository.commit(params[:id])
if commit if commit
commit = CommitDecorator.decorate(commit) commit = CommitDecorator.decorate(commit)
......
...@@ -9,7 +9,7 @@ module Notes ...@@ -9,7 +9,7 @@ module Notes
@notes = case target_type @notes = case target_type
when "commit" when "commit"
project.commit_notes(project.commit(target_id)).fresh.limit(20) project.commit_notes(project.repository.commit(target_id)).fresh.limit(20)
when "issue" when "issue"
project.issues.find(target_id).notes.inc_author.fresh.limit(20) project.issues.find(target_id).notes.inc_author.fresh.limit(20)
when "merge_request" when "merge_request"
...@@ -18,7 +18,7 @@ module Notes ...@@ -18,7 +18,7 @@ module Notes
project.snippets.find(target_id).notes.fresh project.snippets.find(target_id).notes.fresh
when "wall" when "wall"
# this is the only case, where the order is DESC # this is the only case, where the order is DESC
project.common_notes.order("created_at DESC, id DESC").limit(50) project.notes.common.inc_author_project.order("created_at DESC, id DESC").limit(50)
end end
@notes = if after_id @notes = if after_id
......
class TestHookContext < BaseContext class TestHookContext < BaseContext
def execute def execute
hook = project.hooks.find(params[:id]) hook = project.hooks.find(params[:id])
commits = project.commits(project.default_branch, nil, 3) commits = project.repository.commits(project.default_branch, nil, 3)
data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user)
hook.execute(data) hook.execute(data)
end end
......
...@@ -10,6 +10,7 @@ class Admin::ProjectsController < AdminController ...@@ -10,6 +10,7 @@ class Admin::ProjectsController < AdminController
end end
def show def show
@repository = @project.repository
@users = User.active @users = User.active
@users = @users.not_in_project(@project) if @project.users.present? @users = @users.not_in_project(@project) if @project.users.present?
@users = @users.all @users = @users.all
...@@ -19,7 +20,7 @@ class Admin::ProjectsController < AdminController ...@@ -19,7 +20,7 @@ class Admin::ProjectsController < AdminController
end end
def team_update def team_update
@project.add_users_ids_to_team(params[:user_ids], params[:project_access]) @project.team.add_users_ids(params[:user_ids], params[:project_access])
redirect_to [:admin, @project], notice: 'Project was successfully updated.' redirect_to [:admin, @project], notice: 'Project was successfully updated.'
end end
...@@ -36,7 +37,7 @@ class Admin::ProjectsController < AdminController ...@@ -36,7 +37,7 @@ class Admin::ProjectsController < AdminController
def destroy def destroy
# Delete team first in order to prevent multiple gitolite calls # Delete team first in order to prevent multiple gitolite calls
@project.truncate_team @project.team.truncate
@project.destroy @project.destroy
......
...@@ -19,9 +19,9 @@ class Admin::UsersController < AdminController ...@@ -19,9 +19,9 @@ class Admin::UsersController < AdminController
def team_update def team_update
@admin_user = User.find(params[:id]) @admin_user = User.find(params[:id])
UsersProject.user_bulk_import( UsersProject.add_users_into_projects(
@admin_user,
params[:project_ids], params[:project_ids],
[@admin_user.id],
params[:project_access] params[:project_access]
) )
......
...@@ -76,6 +76,12 @@ class ApplicationController < ActionController::Base ...@@ -76,6 +76,12 @@ class ApplicationController < ActionController::Base
end end
end end
def repository
@repository ||= project.repository
rescue Grit::NoSuchPathError
nil
end
def add_abilities def add_abilities
abilities << Ability abilities << Ability
end end
......
...@@ -9,10 +9,10 @@ class CommitsController < ProjectResourceController ...@@ -9,10 +9,10 @@ class CommitsController < ProjectResourceController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@repo = @project.repo @repo = @project.repository
@limit, @offset = (params[:limit] || 40), (params[:offset] || 0) @limit, @offset = (params[:limit] || 40), (params[:offset] || 0)
@commits = @project.commits(@ref, @path, @limit, @offset) @commits = @repo.commits(@ref, @path, @limit, @offset)
@commits = CommitDecorator.decorate(@commits) @commits = CommitDecorator.decorate(@commits)
respond_to do |format| respond_to do |format|
......
...@@ -83,12 +83,12 @@ class MergeRequestsController < ProjectResourceController ...@@ -83,12 +83,12 @@ class MergeRequestsController < ProjectResourceController
end end
def branch_from def branch_from
@commit = project.commit(params[:ref]) @commit = @repository.commit(params[:ref])
@commit = CommitDecorator.decorate(@commit) @commit = CommitDecorator.decorate(@commit)
end end
def branch_to def branch_to
@commit = project.commit(params[:ref]) @commit = @repository.commit(params[:ref])
@commit = CommitDecorator.decorate(@commit) @commit = CommitDecorator.decorate(@commit)
end end
......
class ProjectResourceController < ApplicationController class ProjectResourceController < ApplicationController
before_filter :project before_filter :project
before_filter :repository
end end
...@@ -2,6 +2,7 @@ require Rails.root.join('lib', 'gitlab', 'graph', 'json_builder') ...@@ -2,6 +2,7 @@ require Rails.root.join('lib', 'gitlab', 'graph', 'json_builder')
class ProjectsController < ProjectResourceController class ProjectsController < ProjectResourceController
skip_before_filter :project, only: [:new, :create] skip_before_filter :project, only: [:new, :create]
skip_before_filter :repository, only: [:new, :create]
# Authorize # Authorize
before_filter :authorize_read_project!, except: [:index, :new, :create] before_filter :authorize_read_project!, except: [:index, :new, :create]
...@@ -58,7 +59,7 @@ class ProjectsController < ProjectResourceController ...@@ -58,7 +59,7 @@ class ProjectsController < ProjectResourceController
respond_to do |format| respond_to do |format|
format.html do format.html do
unless @project.empty_repo? if @project.repository && !@project.repository.empty?
@last_push = current_user.recent_push(@project.id) @last_push = current_user.recent_push(@project.id)
render :show render :show
else else
......
...@@ -31,7 +31,7 @@ class RefsController < ProjectResourceController ...@@ -31,7 +31,7 @@ class RefsController < ProjectResourceController
contents = @tree.contents contents = @tree.contents
@logs = contents.map do |content| @logs = contents.map do |content|
file = params[:path] ? File.join(params[:path], content.name) : content.name file = params[:path] ? File.join(params[:path], content.name) : content.name
last_commit = @project.commits(@commit.id, file, 1).last last_commit = @repo.commits(@commit.id, file, 1).last
last_commit = CommitDecorator.decorate(last_commit) last_commit = CommitDecorator.decorate(last_commit)
{ {
file_name: content.name, file_name: content.name,
...@@ -45,10 +45,10 @@ class RefsController < ProjectResourceController ...@@ -45,10 +45,10 @@ class RefsController < ProjectResourceController
def define_tree_vars def define_tree_vars
params[:path] = nil if params[:path].blank? params[:path] = nil if params[:path].blank?
@repo = project.repo @repo = project.repository
@commit = project.commit(@ref) @commit = @repo.commit(@ref)
@commit = CommitDecorator.decorate(@commit) @commit = CommitDecorator.decorate(@commit)
@tree = Tree.new(@commit.tree, project, @ref, params[:path]) @tree = Tree.new(@commit.tree, @ref, params[:path])
@tree = TreeDecorator.new(@tree) @tree = TreeDecorator.new(@tree)
@hex_path = Digest::SHA1.hexdigest(params[:path] || "") @hex_path = Digest::SHA1.hexdigest(params[:path] || "")
......
...@@ -5,19 +5,19 @@ class RepositoriesController < ProjectResourceController ...@@ -5,19 +5,19 @@ class RepositoriesController < ProjectResourceController
before_filter :require_non_empty_project before_filter :require_non_empty_project
def show def show
@activities = @project.commits_with_refs(20) @activities = @repository.commits_with_refs(20)
end end
def branches def branches
@branches = @project.branches @branches = @repository.branches
end end
def tags def tags
@tags = @project.tags @tags = @repository.tags
end end
def stats def stats
@stats = Gitlab::GitStats.new(@project.repo, @project.root_ref) @stats = Gitlab::GitStats.new(@repository.raw, @repository.root_ref)
@graph = @stats.graph @graph = @stats.graph
end end
...@@ -27,7 +27,7 @@ class RepositoriesController < ProjectResourceController ...@@ -27,7 +27,7 @@ class RepositoriesController < ProjectResourceController
end end
file_path = @project.archive_repo(params[:ref]) file_path = @repository.archive_repo(params[:ref])
if file_path if file_path
# Send file to user # Send file to user
......
...@@ -26,7 +26,7 @@ class ServicesController < ProjectResourceController ...@@ -26,7 +26,7 @@ class ServicesController < ProjectResourceController
end end
def test def test
commits = project.commits(project.default_branch, nil, 3) commits = project.repository.commits(project.default_branch, nil, 3)
data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user) data = project.post_receive_data(commits.last.id, commits.first.id, "refs/heads/#{project.default_branch}", current_user)
@service = project.gitlab_ci_service @service = project.gitlab_ci_service
......
...@@ -16,10 +16,9 @@ class TeamMembersController < ProjectResourceController ...@@ -16,10 +16,9 @@ class TeamMembersController < ProjectResourceController
end end
def create def create
@project.add_users_ids_to_team( users = User.where(id: params[:user_ids])
params[:user_ids],
params[:project_access] @project.team << [users, params[:project_access]]
)
if params[:redirect_to] if params[:redirect_to]
redirect_to params[:redirect_to] redirect_to params[:redirect_to]
...@@ -50,7 +49,7 @@ class TeamMembersController < ProjectResourceController ...@@ -50,7 +49,7 @@ class TeamMembersController < ProjectResourceController
def apply_import def apply_import
giver = Project.find(params[:source_project_id]) giver = Project.find(params[:source_project_id])
status = UsersProject.import_team(giver, project) status = @project.team.import(giver)
notice = status ? "Succesfully imported" : "Import failed" notice = status ? "Succesfully imported" : "Import failed"
redirect_to project_team_members_path(project), notice: notice redirect_to project_team_members_path(project), notice: notice
......
...@@ -22,7 +22,7 @@ class TreeController < ProjectResourceController ...@@ -22,7 +22,7 @@ class TreeController < ProjectResourceController
end end
def edit def edit
@last_commit = @project.last_commit_for(@ref, @path).sha @last_commit = @project.repository.last_commit_for(@ref, @path).sha
end end
def update def update
......
...@@ -6,16 +6,14 @@ class TreeDecorator < ApplicationDecorator ...@@ -6,16 +6,14 @@ class TreeDecorator < ApplicationDecorator
part_path = "" part_path = ""
parts = path.split("\/") parts = path.split("\/")
#parts = parts[0...-1] if is_blob? yield('..', nil) if parts.count > max_links
yield(h.link_to("..", "#")) if parts.count > max_links
parts.each do |part| parts.each do |part|
part_path = File.join(part_path, part) unless part_path.empty? part_path = File.join(part_path, part) unless part_path.empty?
part_path = part if part_path.empty? part_path = part if part_path.empty?
next unless parts.last(2).include?(part) if parts.count > max_links next unless parts.last(2).include?(part) if parts.count > max_links
yield(h.link_to(h.truncate(part, length: 40), h.project_tree_path(project, h.tree_join(ref, part_path)))) yield(part, h.tree_join(ref, part_path))
end end
end end
end end
...@@ -26,7 +24,7 @@ class TreeDecorator < ApplicationDecorator ...@@ -26,7 +24,7 @@ class TreeDecorator < ApplicationDecorator
def up_dir_path def up_dir_path
file = File.join(path, "..") file = File.join(path, "..")
h.project_tree_path(project, h.tree_join(ref, file)) h.tree_join(ref, file)
end end
def readme def readme
......
...@@ -53,7 +53,7 @@ module ApplicationHelper ...@@ -53,7 +53,7 @@ module ApplicationHelper
def last_commit(project) def last_commit(project)
if project.repo_exists? if project.repo_exists?
time_ago_in_words(project.commit.committed_date) + " ago" time_ago_in_words(project.repository.commit.committed_date) + " ago"
else else
"Never" "Never"
end end
...@@ -62,9 +62,11 @@ module ApplicationHelper ...@@ -62,9 +62,11 @@ module ApplicationHelper
end end
def grouped_options_refs(destination = :tree) def grouped_options_refs(destination = :tree)
repository = @project.repository
options = [ options = [
["Branch", @project.branch_names ], ["Branch", repository.branch_names ],
[ "Tag", @project.tag_names ] [ "Tag", repository.tag_names ]
] ]
# If reference is commit id - # If reference is commit id -
...@@ -100,15 +102,15 @@ module ApplicationHelper ...@@ -100,15 +102,15 @@ module ApplicationHelper
] ]
project_nav = [] project_nav = []
if @project && !@project.new_record? if @project && @project.repository && @project.repository.root_ref
project_nav = [ project_nav = [
{ label: "#{@project.name} Issues", url: project_issues_path(@project) }, { label: "#{@project.name} Issues", url: project_issues_path(@project) },
{ label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.root_ref) }, { label: "#{@project.name} Commits", url: project_commits_path(@project, @ref || @project.repository.root_ref) },
{ label: "#{@project.name} Merge Requests", url: project_merge_requests_path(@project) }, { label: "#{@project.name} Merge Requests", url: project_merge_requests_path(@project) },
{ label: "#{@project.name} Milestones", url: project_milestones_path(@project) }, { label: "#{@project.name} Milestones", url: project_milestones_path(@project) },
{ label: "#{@project.name} Snippets", url: project_snippets_path(@project) }, { label: "#{@project.name} Snippets", url: project_snippets_path(@project) },
{ label: "#{@project.name} Team", url: project_team_index_path(@project) }, { label: "#{@project.name} Team", url: project_team_index_path(@project) },
{ label: "#{@project.name} Tree", url: project_tree_path(@project, @ref || @project.root_ref) }, { label: "#{@project.name} Tree", url: project_tree_path(@project, @ref || @project.repository.root_ref) },
{ label: "#{@project.name} Wall", url: wall_project_path(@project) }, { label: "#{@project.name} Wall", url: wall_project_path(@project) },
{ label: "#{@project.name} Wiki", url: project_wikis_path(@project) }, { label: "#{@project.name} Wiki", url: project_wikis_path(@project) },
] ]
...@@ -140,6 +142,7 @@ module ApplicationHelper ...@@ -140,6 +142,7 @@ module ApplicationHelper
event.last_push_to_non_root? && event.last_push_to_non_root? &&
!event.rm_ref? && !event.rm_ref? &&
event.project && event.project &&
event.project.repository &&
event.project.merge_requests_enabled event.project.merge_requests_enabled
end end
......
...@@ -20,20 +20,6 @@ module EventsHelper ...@@ -20,20 +20,6 @@ module EventsHelper
[event.action_name, target].join(" ") [event.action_name, target].join(" ")
end end
def event_image event
event_image_path = if event.push?
"event_push.png"
elsif event.merged?
"event_mr_merged.png"
end
return nil unless event_image_path
content_tag :div, class: 'event_icon' do
image_tag event_image_path
end
end
def event_filter_link key, tooltip def event_filter_link key, tooltip
key = key.to_s key = key.to_s
......
...@@ -4,7 +4,7 @@ module MergeRequestsHelper ...@@ -4,7 +4,7 @@ module MergeRequestsHelper
event.project, event.project,
merge_request: { merge_request: {
source_branch: event.branch_name, source_branch: event.branch_name,
target_branch: event.project.root_ref, target_branch: event.project.repository.root_ref,
title: event.branch_name.titleize title: event.branch_name.titleize
} }
) )
......
...@@ -15,17 +15,19 @@ class Ability ...@@ -15,17 +15,19 @@ class Ability
def project_abilities(user, project) def project_abilities(user, project)
rules = [] rules = []
team = project.team
# Rules based on role in project # Rules based on role in project
if project.master_access_for?(user) if team.masters.include?(user)
rules << project_master_rules rules << project_master_rules
elsif project.dev_access_for?(user) elsif team.developers.include?(user)
rules << project_dev_rules rules << project_dev_rules
elsif project.report_access_for?(user) elsif team.reporters.include?(user)
rules << project_report_rules rules << project_report_rules
elsif project.guest_access_for?(user) elsif team.guests.include?(user)
rules << project_guest_rules rules << project_guest_rules
end end
......
...@@ -11,7 +11,7 @@ class Commit ...@@ -11,7 +11,7 @@ class Commit
attr_accessor :commit, :head, :refs attr_accessor :commit, :head, :refs
delegate :message, :authored_date, :committed_date, :parents, :sha, delegate :message, :authored_date, :committed_date, :parents, :sha,
:date, :committer, :author, :diffs, :tree, :id, :date, :committer, :author, :diffs, :tree, :id, :stats,
:to_patch, to: :commit :to_patch, to: :commit
class << self class << self
...@@ -83,8 +83,8 @@ class Commit ...@@ -83,8 +83,8 @@ class Commit
return result unless from && to return result unless from && to
first = project.commit(to.try(:strip)) first = project.repository.commit(to.try(:strip))
last = project.commit(from.try(:strip)) last = project.repository.commit(from.try(:strip))
if first && last if first && last
result[:same] = (first.id == last.id) result[:same] = (first.id == last.id)
...@@ -98,6 +98,8 @@ class Commit ...@@ -98,6 +98,8 @@ class Commit
end end
def initialize(raw_commit, head = nil) def initialize(raw_commit, head = nil)
raise "Nil as raw commit passed" unless raw_commit
@commit = raw_commit @commit = raw_commit
@head = head @head = head
end end
...@@ -136,7 +138,11 @@ class Commit ...@@ -136,7 +138,11 @@ class Commit
end end
def prev_commit def prev_commit
parents.try :first @prev_commit ||= if parents.present?
Commit.new(parents.first)
else
nil
end
end end
def prev_commit_id def prev_commit_id
......
...@@ -110,26 +110,6 @@ class Event < ActiveRecord::Base ...@@ -110,26 +110,6 @@ class Event < ActiveRecord::Base
target_type == "MergeRequest" target_type == "MergeRequest"
end end
def new_issue?
target_type == "Issue" &&
action == Created
end
def new_merge_request?
target_type == "MergeRequest" &&
action == Created
end
def changed_merge_request?
target_type == "MergeRequest" &&
[Closed, Reopened].include?(action)
end
def changed_issue?
target_type == "Issue" &&
[Closed, Reopened].include?(action)
end
def joined? def joined?
action == Joined action == Joined
end end
...@@ -224,7 +204,7 @@ class Event < ActiveRecord::Base ...@@ -224,7 +204,7 @@ class Event < ActiveRecord::Base
# Max 20 commits from push DESC # Max 20 commits from push DESC
def commits def commits
@commits ||= data[:commits].map { |commit| project.commit(commit[:id]) }.reverse @commits ||= data[:commits].map { |commit| repository.commit(commit[:id]) }.reverse
end end
def commits_count def commits_count
...@@ -245,14 +225,18 @@ class Event < ActiveRecord::Base ...@@ -245,14 +225,18 @@ class Event < ActiveRecord::Base
end end
end end
def repository
project.repository
end
def parent_commit def parent_commit
project.commit(commit_from) repository.commit(commit_from)
rescue => ex rescue => ex
nil nil
end end
def last_commit def last_commit
project.commit(commit_to) repository.commit(commit_to)
rescue => ex rescue => ex
nil nil
end end
......
...@@ -29,10 +29,6 @@ class GitlabCiService < Service ...@@ -29,10 +29,6 @@ class GitlabCiService < Service
hook.save hook.save
end end
def commit_badge_path sha
project_url + "/status?sha=#{sha}"
end
def commit_status_path sha def commit_status_path sha
project_url + "/builds/#{sha}/status.json?token=#{token}" project_url + "/builds/#{sha}/status.json?token=#{token}"
end end
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
# #
# id :integer not null, primary key # id :integer not null, primary key
# note :text # note :text
# noteable_id :string(255)
# noteable_type :string(255) # noteable_type :string(255)
# author_id :integer # author_id :integer
# created_at :datetime not null # created_at :datetime not null
...@@ -12,6 +11,8 @@ ...@@ -12,6 +11,8 @@
# project_id :integer # project_id :integer
# attachment :string(255) # attachment :string(255)
# line_code :string(255) # line_code :string(255)
# commit_id :string(255)
# noteable_id :integer
# #
require 'carrierwave/orm/activerecord' require 'carrierwave/orm/activerecord'
...@@ -42,7 +43,7 @@ class Note < ActiveRecord::Base ...@@ -42,7 +43,7 @@ class Note < ActiveRecord::Base
# Scopes # Scopes
scope :for_commits, ->{ where(noteable_type: "Commit") } scope :for_commits, ->{ where(noteable_type: "Commit") }
scope :common, ->{ where(noteable_id: nil, commit_id: nil) } scope :common, ->{ where(noteable_type: ["", nil]) }
scope :today, ->{ where("created_at >= :date", date: Date.today) } scope :today, ->{ where("created_at >= :date", date: Date.today) }
scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) } scope :last_week, ->{ where("created_at >= :date", date: (Date.today - 7.days)) }
scope :since, ->(day) { where("created_at >= :date", date: (day)) } scope :since, ->(day) { where("created_at >= :date", date: (day)) }
...@@ -70,7 +71,7 @@ class Note < ActiveRecord::Base ...@@ -70,7 +71,7 @@ class Note < ActiveRecord::Base
# override to return commits, which are not active record # override to return commits, which are not active record
def noteable def noteable
if for_commit? if for_commit?
project.commit(commit_id) project.repository.commit(commit_id)
else else
super super
end end
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# private_flag :boolean default(TRUE), not null # private_flag :boolean default(TRUE), not null
# owner_id :integer # creator_id :integer
# default_branch :string(255) # default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null # issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null # wall_enabled :boolean default(TRUE), not null
...@@ -75,7 +75,6 @@ class Project < ActiveRecord::Base ...@@ -75,7 +75,6 @@ class Project < ActiveRecord::Base
validate :check_limit, :repo_name validate :check_limit, :repo_name
# Scopes # Scopes
scope :public_only, where(private_flag: false)
scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) } scope :without_user, ->(user) { where("id NOT IN (:ids)", ids: user.authorized_projects.map(&:id) ) }
scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) } scope :not_in_group, ->(group) { where("id NOT IN (:ids)", ids: group.project_ids ) }
scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) } scope :in_namespace, ->(namespace) { where(namespace_id: namespace.id) }
...@@ -162,6 +161,20 @@ class Project < ActiveRecord::Base ...@@ -162,6 +161,20 @@ class Project < ActiveRecord::Base
end end
end end
def team
@team ||= Team.new(self)
end
def repository
if path
@repository ||= Repository.new(path_with_namespace, default_branch)
else
nil
end
rescue Grit::NoSuchPathError
nil
end
def git_error? def git_error?
error_code == :gitolite error_code == :gitolite
end end
...@@ -198,10 +211,6 @@ class Project < ActiveRecord::Base ...@@ -198,10 +211,6 @@ class Project < ActiveRecord::Base
[Gitlab.config.gitlab.url, path_with_namespace].join("/") [Gitlab.config.gitlab.url, path_with_namespace].join("/")
end end
def common_notes
notes.where(noteable_type: ["", nil]).inc_author_project
end
def build_commit_note(commit) def build_commit_note(commit)
notes.new(commit_id: commit.id, noteable_type: "Commit") notes.new(commit_id: commit.id, noteable_type: "Commit")
end end
...@@ -214,14 +223,6 @@ class Project < ActiveRecord::Base ...@@ -214,14 +223,6 @@ class Project < ActiveRecord::Base
notes.where(commit_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL") notes.where(commit_id: commit.id, noteable_type: "Commit").where("line_code IS NOT NULL")
end end
def public?
!private_flag
end
def private?
private_flag
end
def last_activity def last_activity
last_event last_event
end end
...@@ -284,110 +285,6 @@ class Project < ActiveRecord::Base ...@@ -284,110 +285,6 @@ class Project < ActiveRecord::Base
users_projects.find_by_user_id(user_id) users_projects.find_by_user_id(user_id)
end end
# Add user to project
# with passed access role
def add_user_to_team(user, access_role)
add_user_id_to_team(user.id, access_role)
end
# Add multiple users to project
# with same access role
def add_users_to_team(users, access_role)
add_users_ids_to_team(users.map(&:id), access_role)
end
# Add user to project
# with passed access role by user id
def add_user_id_to_team(user_id, access_role)
users_projects.create(
user_id: user_id,
project_access: access_role
)
end
# Add multiple users to project
# with same access role by user ids
def add_users_ids_to_team(users_ids, access_role)
UsersProject.bulk_import(self, users_ids, access_role)
end
# Update multiple project users
# to same access role by user ids
def update_users_ids_to_role(users_ids, access_role)
UsersProject.bulk_update(self, users_ids, access_role)
end
# Delete multiple users from project by user ids
def delete_users_ids_from_team(users_ids)
UsersProject.bulk_delete(self, users_ids)
end
# Remove all users from project team
def truncate_team
UsersProject.truncate_team(self)
end
# Compatible with all access rights
# Should be rewrited for new access rights
def add_access(user, *access)
access = if access.include?(:admin)
{ project_access: UsersProject::MASTER }
elsif access.include?(:write)
{ project_access: UsersProject::DEVELOPER }
else
{ project_access: UsersProject::REPORTER }
end
opts = { user: user }
opts.merge!(access)
users_projects.create(opts)
end
def reset_access(user)
users_projects.where(project_id: self.id, user_id: user.id).destroy if self.id
end
def repository_readers
repository_members[UsersProject::REPORTER]
end
def repository_writers
repository_members[UsersProject::DEVELOPER]
end
def repository_masters
repository_members[UsersProject::MASTER]
end
def repository_members
keys = Hash.new {|h,k| h[k] = [] }
UsersProject.select("keys.identifier, project_access").
joins(user: :keys).where(project_id: id).
each {|row| keys[row.project_access] << [row.identifier] }
keys[UsersProject::REPORTER] += deploy_keys.pluck(:identifier)
keys
end
def allow_read_for?(user)
!users_projects.where(user_id: user.id).empty?
end
def guest_access_for?(user)
!users_projects.where(user_id: user.id).empty?
end
def report_access_for?(user)
!users_projects.where(user_id: user.id, project_access: [UsersProject::REPORTER, UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
end
def dev_access_for?(user)
!users_projects.where(user_id: user.id, project_access: [UsersProject::DEVELOPER, UsersProject::MASTER]).empty?
end
def master_access_for?(user)
!users_projects.where(user_id: user.id, project_access: [UsersProject::MASTER]).empty?
end
def transfer(new_namespace) def transfer(new_namespace)
Project.transaction do Project.transaction do
old_namespace = namespace old_namespace = namespace
...@@ -464,8 +361,8 @@ class Project < ActiveRecord::Base ...@@ -464,8 +361,8 @@ class Project < ActiveRecord::Base
# Discover the default branch, but only if it hasn't already been set to # Discover the default branch, but only if it hasn't already been set to
# something else # something else
if default_branch.nil? if repository && default_branch.nil?
update_attributes(default_branch: discover_default_branch) update_attributes(default_branch: self.repository.discover_default_branch)
end end
end end
...@@ -517,7 +414,7 @@ class Project < ActiveRecord::Base ...@@ -517,7 +414,7 @@ class Project < ActiveRecord::Base
# #
def post_receive_data(oldrev, newrev, ref, user) def post_receive_data(oldrev, newrev, ref, user)
push_commits = commits_between(oldrev, newrev) push_commits = repository.commits_between(oldrev, newrev)
# Total commits count # Total commits count
push_commits_count = push_commits.size push_commits_count = push_commits.size
...@@ -564,7 +461,7 @@ class Project < ActiveRecord::Base ...@@ -564,7 +461,7 @@ class Project < ActiveRecord::Base
def update_merge_requests(oldrev, newrev, ref, user) def update_merge_requests(oldrev, newrev, ref, user)
return true unless ref =~ /heads/ return true unless ref =~ /heads/
branch_name = ref.gsub("refs/heads/", "") branch_name = ref.gsub("refs/heads/", "")
c_ids = self.commits_between(oldrev, newrev).map(&:id) c_ids = self.repository.commits_between(oldrev, newrev).map(&:id)
# Update code for merge requests # Update code for merge requests
mrs = self.merge_requests.opened.find_all_by_branch(branch_name).all mrs = self.merge_requests.opened.find_all_by_branch(branch_name).all
...@@ -586,97 +483,21 @@ class Project < ActiveRecord::Base ...@@ -586,97 +483,21 @@ class Project < ActiveRecord::Base
end end
def empty_repo? def empty_repo?
!repo_exists? || !has_commits? !repository || repository.empty?
end
def commit(commit_id = nil)
Commit.find_or_first(repo, commit_id, root_ref)
end
def fresh_commits(n = 10)
Commit.fresh_commits(repo, n)
end
def commits_with_refs(n = 20)
Commit.commits_with_refs(repo, n)
end
def commits_since(date)
Commit.commits_since(repo, date)
end
def commits(ref, path = nil, limit = nil, offset = nil)
Commit.commits(repo, ref, path, limit, offset)
end
def last_commit_for(ref, path = nil)
commits(ref, path, 1).first
end
def commits_between(from, to)
Commit.commits_between(repo, from, to)
end end
def satellite def satellite
@satellite ||= Gitlab::Satellite::Satellite.new(self) @satellite ||= Gitlab::Satellite::Satellite.new(self)
end end
def has_post_receive_file?
!!hook_file
end
def valid_post_receive_file?
valid_hook_file == hook_file
end
def valid_hook_file
@valid_hook_file ||= File.read(Rails.root.join('lib', 'hooks', 'post-receive'))
end
def hook_file
@hook_file ||= begin
hook_path = File.join(path_to_repo, 'hooks', 'post-receive')
File.read(hook_path) if File.exists?(hook_path)
end
end
# Returns an Array of branch names
def branch_names
repo.branches.collect(&:name).sort
end
# Returns an Array of Branches
def branches
repo.branches.sort_by(&:name)
end
# Returns an Array of tag names
def tag_names
repo.tags.collect(&:name).sort.reverse
end
# Returns an Array of Tags
def tags
repo.tags.sort_by(&:name).reverse
end
# Returns an Array of branch and tag names
def ref_names
[branch_names + tag_names].flatten
end
def repo def repo
@repo ||= Grit::Repo.new(path_to_repo) repository.raw
end end
def url_to_repo def url_to_repo
gitolite.url_to_repo(path_with_namespace) gitolite.url_to_repo(path_with_namespace)
end end
def path_to_repo
File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git")
end
def namespace_dir def namespace_dir
namespace.try(:path) || '' namespace.try(:path) || ''
end end
...@@ -690,21 +511,11 @@ class Project < ActiveRecord::Base ...@@ -690,21 +511,11 @@ class Project < ActiveRecord::Base
end end
def repo_exists? def repo_exists?
@repo_exists ||= (repo && !repo.branches.empty?) @repo_exists ||= (repository && repository.branches.present?)
rescue rescue
@repo_exists = false @repo_exists = false
end end
def heads
@heads ||= repo.heads
end
def tree(fcommit, path = nil)
fcommit = commit if fcommit == :head
tree = fcommit.tree
path ? (tree / path) : tree
end
def open_branches def open_branches
if protected_branches.empty? if protected_branches.empty?
self.repo.heads self.repo.heads
...@@ -714,61 +525,8 @@ class Project < ActiveRecord::Base ...@@ -714,61 +525,8 @@ class Project < ActiveRecord::Base
end.sort_by(&:name) end.sort_by(&:name)
end end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
# - If one branch is present, returns its name
# - If two or more branches are present, returns the one that has a name
# matching root_ref (default_branch or 'master' if default_branch is nil)
def discover_default_branch
if branch_names.length == 0
nil
elsif branch_names.length == 1
branch_names.first
else
branch_names.select { |v| v == root_ref }.first
end
end
def has_commits?
!!commit
rescue Grit::NoSuchPathError
false
end
def root_ref
default_branch || "master"
end
def root_ref?(branch) def root_ref?(branch)
root_ref == branch repository.root_ref == branch
end
# Archive Project to .tar.gz
#
# Already packed repo archives stored at
# app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
#
def archive_repo(ref)
ref = ref || self.root_ref
commit = self.commit(ref)
return nil unless commit
# Build file path
file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
storage_path = Rails.root.join("tmp", "repositories", self.path_with_namespace)
file_path = File.join(storage_path, file_name)
# Put files into a directory before archiving
prefix = self.path + "/"
# Create file if not exists
unless File.exists?(file_path)
FileUtils.mkdir_p storage_path
file = self.repo.archive_to_file(ref, prefix, file_path)
end
file_path
end end
def ssh_url_to_repo def ssh_url_to_repo
......
...@@ -26,6 +26,6 @@ class ProtectedBranch < ActiveRecord::Base ...@@ -26,6 +26,6 @@ class ProtectedBranch < ActiveRecord::Base
end end
def commit def commit
project.commit(self.name) project.repository.commit(self.name)
end end
end end
class Repository
# Repository directory name with namespace direcotry
# Examples:
# gitlab/gitolite
# diaspora
#
attr_accessor :path_with_namespace
# Grit repo object
attr_accessor :repo
# Default branch in the repository
attr_accessor :root_ref
def initialize(path_with_namespace, root_ref = 'master')
@root_ref = root_ref || "master"
@path_with_namespace = path_with_namespace
# Init grit repo object
repo
end
def raw
repo
end
def path_to_repo
@path_to_repo ||= File.join(Gitlab.config.gitolite.repos_path, "#{path_with_namespace}.git")
end
def repo
@repo ||= Grit::Repo.new(path_to_repo)
end
def commit(commit_id = nil)
Commit.find_or_first(repo, commit_id, root_ref)
end
def fresh_commits(n = 10)
Commit.fresh_commits(repo, n)
end
def commits_with_refs(n = 20)
Commit.commits_with_refs(repo, n)
end
def commits_since(date)
Commit.commits_since(repo, date)
end
def commits(ref, path = nil, limit = nil, offset = nil)
Commit.commits(repo, ref, path, limit, offset)
end
def last_commit_for(ref, path = nil)
commits(ref, path, 1).first
end
def commits_between(from, to)
Commit.commits_between(repo, from, to)
end
def has_post_receive_file?
!!hook_file
end
def valid_post_receive_file?
valid_hook_file == hook_file
end
def valid_hook_file
@valid_hook_file ||= File.read(Rails.root.join('lib', 'hooks', 'post-receive'))
end
def hook_file
@hook_file ||= begin
hook_path = File.join(path_to_repo, 'hooks', 'post-receive')
File.read(hook_path) if File.exists?(hook_path)
end
end
# Returns an Array of branch names
def branch_names
repo.branches.collect(&:name).sort
end
# Returns an Array of Branches
def branches
repo.branches.sort_by(&:name)
end
# Returns an Array of tag names
def tag_names
repo.tags.collect(&:name).sort.reverse
end
# Returns an Array of Tags
def tags
repo.tags.sort_by(&:name).reverse
end
# Returns an Array of branch and tag names
def ref_names
[branch_names + tag_names].flatten
end
def heads
@heads ||= repo.heads
end
def tree(fcommit, path = nil)
fcommit = commit if fcommit == :head
tree = fcommit.tree
path ? (tree / path) : tree
end
def has_commits?
!!commit
rescue Grit::NoSuchPathError
false
end
def empty?
!has_commits?
end
# Discovers the default branch based on the repository's available branches
#
# - If no branches are present, returns nil
# - If one branch is present, returns its name
# - If two or more branches are present, returns the one that has a name
# matching root_ref (default_branch or 'master' if default_branch is nil)
def discover_default_branch
if branch_names.length == 0
nil
elsif branch_names.length == 1
branch_names.first
else
branch_names.select { |v| v == root_ref }.first
end
end
# Archive Project to .tar.gz
#
# Already packed repo archives stored at
# app_root/tmp/repositories/project_name/project_name-commit-id.tag.gz
#
def archive_repo(ref)
ref = ref || self.root_ref
commit = self.commit(ref)
return nil unless commit
# Build file path
file_name = self.path + "-" + commit.id.to_s + ".tar.gz"
storage_path = Rails.root.join("tmp", "repositories", self.path_with_namespace)
file_path = File.join(storage_path, file_name)
# Put files into a directory before archiving
prefix = self.path + "/"
# Create file if not exists
unless File.exists?(file_path)
FileUtils.mkdir_p storage_path
file = self.repo.archive_to_file(ref, prefix, file_path)
end
file_path
end
end
class Team
attr_accessor :project
def initialize(project)
@project = project
end
# Shortcut to add users
#
# Use:
# @team << [@user, :master]
# @team << [@users, :master]
#
def << args
users = args.first
if users.respond_to?(:each)
add_users(users, args.second)
else
add_user(users, args.second)
end
end
def add_user(user, access)
add_users_ids([user.id], access)
end
def add_users(users, access)
add_users_ids(users.map(&:id), access)
end
def add_users_ids(user_ids, access)
UsersProject.add_users_into_projects(
[project.id],
user_ids,
access
)
end
# Remove all users from project team
def truncate
UsersProject.truncate_team(project)
end
def members
project.users_projects
end
def guests
members.guests.map(&:user)
end
def reporters
members.reporters.map(&:user)
end
def developers
members.developers.map(&:user)
end
def masters
members.masters.map(&:user)
end
def repository_readers
repository_members[UsersProject::REPORTER]
end
def repository_writers
repository_members[UsersProject::DEVELOPER]
end
def repository_masters
repository_members[UsersProject::MASTER]
end
def repository_members
keys = Hash.new {|h,k| h[k] = [] }
UsersProject.select("keys.identifier, project_access").
joins(user: :keys).where(project_id: project.id).
each {|row| keys[row.project_access] << [row.identifier] }
keys[UsersProject::REPORTER] += project.deploy_keys.pluck(:identifier)
keys
end
def import(source_project)
target_project = project
source_team = source_project.users_projects.all
target_team = target_project.users_projects.all
target_user_ids = target_team.map(&:user_id)
source_team.reject! do |tm|
# Skip if user already present in team
target_user_ids.include?(tm.user_id)
end
source_team.map! do |tm|
new_tm = tm.dup
new_tm.id = nil
new_tm.project_id = target_project.id
new_tm.skip_git = true
new_tm
end
UsersProject.transaction do
source_team.each do |tm|
tm.save
end
target_project.update_repository
end
true
rescue
false
end
end
class Tree class Tree
include Linguist::BlobHelper include Linguist::BlobHelper
attr_accessor :path, :tree, :project, :ref
attr_accessor :path, :tree, :ref
delegate :contents, :basename, :name, :data, :mime_type, delegate :contents, :basename, :name, :data, :mime_type,
:mode, :size, :text?, :colorize, to: :tree :mode, :size, :text?, :colorize, to: :tree
def initialize(raw_tree, project, ref = nil, path = nil) def initialize(raw_tree, ref = nil, path = nil)
@project, @ref, @path = project, ref, path @ref, @path = ref, path
@tree = if path.present? @tree = if path.present?
raw_tree / path raw_tree / path
else else
......
...@@ -188,7 +188,7 @@ class User < ActiveRecord::Base ...@@ -188,7 +188,7 @@ class User < ActiveRecord::Base
# Team membership in personal projects # Team membership in personal projects
def tm_in_personal_projects def tm_in_personal_projects
personal_projects.users_projects.where(user_id: self.id) UsersProject.where(project_id: personal_projects.map(&:id), user_id: self.id)
end end
# Returns a string for use as a Gitolite user identifier # Returns a string for use as a Gitolite user identifier
......
...@@ -42,7 +42,34 @@ class UsersProject < ActiveRecord::Base ...@@ -42,7 +42,34 @@ class UsersProject < ActiveRecord::Base
scope :in_project, ->(project) { where(project_id: project.id) } scope :in_project, ->(project) { where(project_id: project.id) }
class << self class << self
def add_users_into_projects(project_ids, user_ids, project_access)
# Add users to project teams with passed access option
#
# access can be an integer representing a access code
# or symbol like :master representing role
#
# Ex.
# add_users_into_projects(
# project_ids,
# user_ids,
# UsersProject::MASTER
# )
#
# add_users_into_projects(
# project_ids,
# user_ids,
# :master
# )
#
def add_users_into_projects(project_ids, user_ids, access)
project_access = if roles_hash.has_key?(access)
roles_hash[access]
elsif roles_hash.values.include?(access.to_i)
access
else
raise "Non valid access"
end
UsersProject.transaction do UsersProject.transaction do
project_ids.each do |project_id| project_ids.each do |project_id|
user_ids.each do |user_id| user_ids.each do |user_id|
...@@ -79,36 +106,6 @@ class UsersProject < ActiveRecord::Base ...@@ -79,36 +106,6 @@ class UsersProject < ActiveRecord::Base
truncate_teams [project.id] truncate_teams [project.id]
end end
def import_team(source_project, target_project)
source_team = source_project.users_projects.all
target_team = target_project.users_projects.all
target_user_ids = target_team.map(&:user_id)
source_team.reject! do |tm|
# Skip if user already present in team
target_user_ids.include?(tm.user_id)
end
source_team.map! do |tm|
new_tm = tm.dup
new_tm.id = nil
new_tm.project_id = target_project.id
new_tm.skip_git = true
new_tm
end
UsersProject.transaction do
source_team.each do |tm|
tm.save
end
target_project.update_repository
end
true
rescue
false
end
def bulk_delete(project, user_ids) def bulk_delete(project, user_ids)
UsersProject.transaction do UsersProject.transaction do
UsersProject.where(user_id: user_ids, project_id: project.id).each do |users_project| UsersProject.where(user_id: user_ids, project_id: project.id).each do |users_project|
...@@ -131,14 +128,13 @@ class UsersProject < ActiveRecord::Base ...@@ -131,14 +128,13 @@ class UsersProject < ActiveRecord::Base
end end
end end
# TODO: depreceate in future in favor of add_users_into_projects def roles_hash
def bulk_import(project, user_ids, project_access) {
add_users_into_projects([project.id], user_ids, project_access) guest: GUEST,
end reporter: REPORTER,
developer: DEVELOPER,
# TODO: depreceate in future in favor of add_users_into_projects master: MASTER
def user_bulk_import(user, project_ids, project_access) }
add_users_into_projects(project_ids, [user.id], project_access)
end end
def access_roles def access_roles
......
# encoding: utf-8 # encoding: utf-8
class AttachmentUploader < CarrierWave::Uploader::Base class AttachmentUploader < CarrierWave::Uploader::Base
# Include RMagick or ImageScience support:
# include CarrierWave::RMagick
# include CarrierWave::MiniMagick
# include CarrierWave::ImageScience
# Choose what kind of storage to use for this uploader:
storage :file storage :file
# storage :fog
# Override the directory where uploaded files will be stored.
# This is a sensible default for uploaders that are meant to be mounted:
def store_dir def store_dir
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end end
# Provide a default URL as a default if there hasn't been a file uploaded: def image?
# def default_url %w(png jpg jpeg).include?(file.extension)
# "/images/fallback/" + [version_name, "default.png"].compact.join('_') end
# end
# Process files as they are uploaded:
# process scale: [200, 300]
#
# def scale(width, height)
# # do something
# end
# Create different versions of your uploaded files:
# version :thumb do
# process scale: [50, 50]
# end
# Add a white list of extensions which are allowed to be uploaded.
# For images you might use something like this:
# def extension_white_list
# %w(jpg jpeg gif png)
# end
# Override the filename of the uploaded files:
# Avoid using model.id or version_name here, see uploader/store.rb for details.
# def filename
# "something.jpg" if original_filename
# end
end end
.admin_dash.row .admin_dash.row
.span3 .span3
.ui-box .ui-box
%h5 Projects %h5.title Projects
.data.padded .data.padded
= link_to admin_projects_path do = link_to admin_projects_path do
%h1= Project.count %h1= Project.count
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
= link_to 'New Project', new_project_path, class: "btn small" = link_to 'New Project', new_project_path, class: "btn small"
.span3 .span3
.ui-box .ui-box
%h5 Groups %h5.title Groups
.data.padded .data.padded
= link_to admin_groups_path do = link_to admin_groups_path do
%h1= Group.count %h1= Group.count
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
= link_to 'New Group', new_admin_group_path, class: "btn small" = link_to 'New Group', new_admin_group_path, class: "btn small"
.span3 .span3
.ui-box .ui-box
%h5 Users %h5.title Users
.data.padded .data.padded
= link_to admin_users_path do = link_to admin_users_path do
%h1= User.count %h1= User.count
...@@ -25,7 +25,7 @@ ...@@ -25,7 +25,7 @@
= link_to 'New User', new_admin_user_path, class: "btn small" = link_to 'New User', new_admin_user_path, class: "btn small"
.span3 .span3
.ui-box .ui-box
%h5 %h5.title
Resque Workers Resque Workers
.data.padded .data.padded
- if @resque_accessible - if @resque_accessible
......
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
- if project.repo_exists? - if project.repo_exists?
.clearfix .clearfix
= f.label :default_branch, "Default Branch" = f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, project.heads.map(&:name), {}, style: "width:210px;") .input= f.select(:default_branch, repository.heads.map(&:name), {}, style: "width:210px;")
%fieldset.adv_settings %fieldset.adv_settings
%legend Features: %legend Features:
......
...@@ -4,15 +4,15 @@ ...@@ -4,15 +4,15 @@
%i.icon-edit %i.icon-edit
Edit Edit
- if @project.has_commits? - if @repository && @repository.has_commits?
- if !@project.has_post_receive_file? - if !@repository.has_post_receive_file?
%br %br
.alert.alert-error .alert.alert-error
%span %span
%strong Project has commits but missing post-receive file. %strong Project has commits but missing post-receive file.
%br %br
If you exported project manually - make a link of post-receive hook file from gitolite to project repository If you exported project manually - make a link of post-receive hook file from gitolite to project repository
- elsif !@project.valid_post_receive_file? - elsif !@repository.valid_post_receive_file?
%br %br
.alert.alert-error .alert.alert-error
%span %span
...@@ -65,18 +65,6 @@ ...@@ -65,18 +65,6 @@
Created at: Created at:
%td %td
= @project.created_at.stamp("March 1, 1999") = @project.created_at.stamp("March 1, 1999")
%table.zebra-striped
%thead
%tr
%th Repository
%th
%tr
%td
%b
FS Path:
%td
%code= @project.path_to_repo
%tr %tr
%td %td
%b %b
...@@ -89,6 +77,19 @@ ...@@ -89,6 +77,19 @@
SSH: SSH:
%td %td
= link_to @project.ssh_url_to_repo = link_to @project.ssh_url_to_repo
- if @repository
%table.zebra-striped
%thead
%tr
%th Repository
%th
%tr
%td
%b
FS Path:
%td
%code= @repository.path_to_repo
%tr %tr
%td %td
%b %b
...@@ -100,7 +101,7 @@ ...@@ -100,7 +101,7 @@
%b %b
Post Receive File: Post Receive File:
%td %td
= check_box_tag :post_receive_file, 1, @project.has_post_receive_file?, disabled: true = check_box_tag :post_receive_file, 1, @repository.has_post_receive_file?, disabled: true
%br %br
%h5 %h5
......
= render "commits/commit_box" = render "commits/commit_box"
%p.right.cgray
This commit has
%span.cgreen #{@commit.stats.additions} additions
and
%span.cred #{@commit.stats.deletions} deletions
= render "commits/diffs", diffs: @commit.diffs = render "commits/diffs", diffs: @commit.diffs
= render "notes/notes_with_form", tid: @commit.id, tt: "commit" = render "notes/notes_with_form", tid: @commit.id, tt: "commit"
= render "notes/per_line_form" = render "notes/per_line_form"
:javascript :javascript
$(function(){ $(function(){
PerLineNotes.init(); PerLineNotes.init();
......
.commit-box{class: @commit.parents_count > 1 ? "merge-commit" : ""} .ui-box.ui-box-show
.commit-head .ui-box-head
.right .right
- if @notes_count > 0 - if @notes_count > 0
%span.btn.disabled.grouped %span.btn.disabled.grouped
%i.icon-comment %i.icon-comment
= @notes_count = @notes_count
.left.btn-group .left.btn-group
%a.btn.small.grouped.dropdown-toggle{ data: {toggle: :dropdown} } %a.btn.grouped.dropdown-toggle{ data: {toggle: :dropdown} }
%i.icon-download-alt %i.icon-download-alt
Download as Download as
%span.caret %span.caret
%ul.dropdown-menu %ul.dropdown-menu
%li= link_to "Email Patches", project_commit_path(@project, @commit, format: :patch) %li= link_to "Email Patches", project_commit_path(@project, @commit, format: :patch)
%li= link_to "Plain Diff", project_commit_path(@project, @commit, format: :diff) %li= link_to "Plain Diff", project_commit_path(@project, @commit, format: :diff)
= link_to project_tree_path(@project, @commit), class: "browse-button primary grouped" do = link_to project_tree_path(@project, @commit), class: "btn primary grouped" do
%strong Browse Code » %span Browse Code »
%h3.commit-title.page_title %h3.commit-title.page_title
= gfm escape_once(@commit.title) = gfm escape_once(@commit.title)
- if @commit.description.present? - if @commit.description.present?
%pre.commit-description %pre.commit-description
= gfm escape_once(@commit.description) = gfm escape_once(@commit.description)
.commit-info .ui-box-body
.row .row
.span5 .span5
.author .author
%strong= @commit.author_link avatar: true, size: 40 = @commit.author_link avatar: true, size: 32
authored authored
%time{title: @commit.authored_date.stamp("Aug 21, 2011 9:23pm")} %time{title: @commit.authored_date.stamp("Aug 21, 2011 9:23pm")}
#{time_ago_in_words(@commit.authored_date)} ago #{time_ago_in_words(@commit.authored_date)} ago
- if @commit.different_committer? - if @commit.different_committer?
.committer .committer
&rarr; &rarr;
%strong= @commit.committer_link = @commit.committer_link
committed committed
%time{title: @commit.committed_date.stamp("Aug 21, 2011 9:23pm")} %time{title: @commit.committed_date.stamp("Aug 21, 2011 9:23pm")}
#{time_ago_in_words(@commit.committed_date)} ago #{time_ago_in_words(@commit.committed_date)} ago
.span6.right .span6.pull-right
.pull-right
.sha-block .sha-block
%span.cgray commit %span.cgray commit
%code.label_commit= @commit.id %span.label_commit= @commit.id
.clearfix
.pull-right
.sha-block .sha-block
%span.cgray= pluralize(@commit.parents.count, "parent") %span.cgray= pluralize(@commit.parents.count, "parent")
- @commit.parents.each do |parent| - @commit.parents.each do |parent|
......
- @commits.group_by { |c| c.committed_date.to_date }.each do |day, commits| - @commits.group_by { |c| c.committed_date.to_date }.each do |day, commits|
%div.ui-box %div.ui-box
%h5.small %h5.title
%i.icon-calendar %i.icon-calendar
= day.stamp("28 Aug, 2010") = day.stamp("28 Aug, 2010")
%ul.well-list= render commits %ul.well-list= render commits
...@@ -2,19 +2,19 @@ ...@@ -2,19 +2,19 @@
%li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'} %li= render partial: 'shared/ref_switcher', locals: {destination: 'commits'}
= nav_link(controller: [:commit, :commits]) do = nav_link(controller: [:commit, :commits]) do
= link_to 'Commits', project_commits_path(@project, @project.root_ref) = link_to 'Commits', project_commits_path(@project, @repository.root_ref)
= nav_link(controller: :compare) do = nav_link(controller: :compare) do
= link_to 'Compare', project_compare_index_path(@project) = link_to 'Compare', project_compare_index_path(@project)
= nav_link(html_options: {class: branches_tab_class}) do = nav_link(html_options: {class: branches_tab_class}) do
= link_to project_repository_path(@project) do = link_to project_repository_path(@project) do
Branches Branches
%span.badge= @project.branches.length %span.badge= @repository.branches.length
= nav_link(controller: :repositories, action: :tags) do = nav_link(controller: :repositories, action: :tags) do
= link_to tags_project_repository_path(@project) do = link_to tags_project_repository_path(@project) do
Tags Tags
%span.badge= @project.tags.length %span.badge= @repository.tags.length
= nav_link(controller: :repositories, action: :stats) do = nav_link(controller: :repositories, action: :stats) do
= link_to stats_project_repository_path(@project) do = link_to stats_project_repository_path(@project) do
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
:javascript :javascript
$(function() { $(function() {
var availableTags = #{@project.ref_names.to_json}; var availableTags = #{@project.repository.ref_names.to_json};
$("#from, #to").autocomplete({ $("#from, #to").autocomplete({
source: availableTags, source: availableTags,
......
.groups_box .groups_box
%h5 %h5.title
Groups Groups
%small %small
(#{groups.count}) (#{groups.count})
......
.projects_box .projects_box
%h5 %h5.title
Projects Projects
%small %small
(#{projects.total_count}) (#{projects.total_count})
......
...@@ -13,7 +13,8 @@ ...@@ -13,7 +13,8 @@
- @issues.group_by(&:project).each do |group| - @issues.group_by(&:project).each do |group|
%div.ui-box %div.ui-box
- @project = group[0] - @project = group[0]
%h5= link_to_project @project %h5.title
= link_to_project @project
%ul.well-list.issues_table %ul.well-list.issues_table
- group[1].each do |issue| - group[1].each do |issue|
= render(partial: 'issues/show', locals: {issue: issue}) = render(partial: 'issues/show', locals: {issue: issue})
......
...@@ -12,7 +12,8 @@ ...@@ -12,7 +12,8 @@
- @merge_requests.group_by(&:project).each do |group| - @merge_requests.group_by(&:project).each do |group|
.ui-box .ui-box
- @project = group[0] - @project = group[0]
%h5= link_to_project @project %h5.title
= link_to_project @project
%ul.well-list %ul.well-list
- group[1].each do |merge_request| - group[1].each do |merge_request|
= render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})
......
.projects_box .projects_box
%h5 %h5.title
Projects Projects
%small %small
(#{projects.count}) (#{projects.count})
......
...@@ -9,7 +9,8 @@ ...@@ -9,7 +9,8 @@
- @issues.group_by(&:project).each do |group| - @issues.group_by(&:project).each do |group|
%div.ui-box %div.ui-box
- @project = group[0] - @project = group[0]
%h5= @project.name %h5.title
= @project.name
%ul.well-list.issues_table %ul.well-list.issues_table
- group[1].each do |issue| - group[1].each do |issue|
= render(partial: 'issues/show', locals: {issue: issue}) = render(partial: 'issues/show', locals: {issue: issue})
......
...@@ -8,7 +8,8 @@ ...@@ -8,7 +8,8 @@
- @merge_requests.group_by(&:project).each do |group| - @merge_requests.group_by(&:project).each do |group|
%ul.well-list.ui-box %ul.well-list.ui-box
- @project = group[0] - @project = group[0]
%h5= @project.name %h5.title
= @project.name
- group[1].each do |merge_request| - group[1].each do |merge_request|
= render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request}) = render(partial: 'merge_requests/merge_request', locals: {merge_request: merge_request})
%hr %hr
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
- if can?(current_user, :manage_group, @group) - if can?(current_user, :manage_group, @group)
= render (@project ? "new_member" : "new_group_member") = render (@project ? "new_member" : "new_group_member")
.ui-box .ui-box
%h5 %h5.title
Team Team
%small %small
(#{@users.size}) (#{@users.size})
......
...@@ -6,26 +6,27 @@ ...@@ -6,26 +6,27 @@
- @issue.errors.full_messages.each do |msg| - @issue.errors.full_messages.each do |msg|
%span= msg %span= msg
%br %br
.issue_form_box .ui-box.ui-box-show
.issue_title .ui-box-head
.clearfix .clearfix
= f.label :title do = f.label :title do
%strong= "Subject *" %strong= "Subject *"
.input .input
= f.text_field :title, maxlength: 255, class: "xxlarge js-gfm-input", autofocus: true, required: true = f.text_field :title, maxlength: 255, class: "xxlarge js-gfm-input", autofocus: true, required: true
.issue_middle_block .ui-box-body
.issue_assignee .clearfix
.issue_assignee.pull-left
= f.label :assignee_id do = f.label :assignee_id do
%i.icon-user %i.icon-user
Assign to Assign to
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }, {class: 'chosen'}) .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select a user" }, {class: 'chosen'})
.issue_milestone .issue_milestone.pull-left
= f.label :milestone_id do = f.label :milestone_id do
%i.icon-time %i.icon-time
Milestone Milestone
.input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'}) .input= f.select(:milestone_id, @project.milestones.active.all.collect {|p| [ p.title, p.id ] }, { include_blank: "Select milestone" }, {class: 'chosen'})
.issue_description .ui-box-bottom
.clearfix .clearfix
= f.label :label_list do = f.label :label_list do
%i.icon-tag %i.icon-tag
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
= select_tag('update[milestone_id]', options_from_collection_for_select(issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone") = select_tag('update[milestone_id]', options_from_collection_for_select(issues_active_milestones, "id", "title", params[:milestone_id]), prompt: "Milestone")
= hidden_field_tag 'update[issues_ids]', [] = hidden_field_tag 'update[issues_ids]', []
= hidden_field_tag :f, params[:f] = hidden_field_tag :f, params[:f]
= button_tag "Save", class: "btn update_selected_issues" = button_tag "Save", class: "btn update_selected_issues btn-small save-btn"
.issues_filters .issues_filters
.left .left
%ul.nav.nav-pills.left %ul.nav.nav-pills.left
......
...@@ -24,14 +24,14 @@ ...@@ -24,14 +24,14 @@
&larr; To issues list &larr; To issues list
.main_box .ui-box.ui-box-show
.top_box_content .ui-box-head
%h4.box-title %h4.box-title
- if @issue.closed - if @issue.closed
.error.status_info Closed .error.status_info Closed
= gfm escape_once(@issue.title) = gfm escape_once(@issue.title)
.middle_box_content .ui-box-body
%cite.cgray %cite.cgray
Created by #{link_to_member(@project, @issue.author)} Created by #{link_to_member(@project, @issue.author)}
- if @issue.assignee - if @issue.assignee
...@@ -44,13 +44,13 @@ ...@@ -44,13 +44,13 @@
.right .right
- @issue.labels.each do |label| - @issue.labels.each do |label|
%span.label.label-issue %span
%i.icon-tag %i.icon-tag
= label.name = label.name
&nbsp; &nbsp;
- if @issue.description.present? - if @issue.description.present?
.bottom_box_content .ui-box-bottom
= preserve do = preserve do
= markdown @issue.description = markdown @issue.description
......
...@@ -14,9 +14,9 @@ ...@@ -14,9 +14,9 @@
- if @project.repo_exists? - if @project.repo_exists?
- if can? current_user, :download_code, @project - if can? current_user, :download_code, @project
= nav_link(controller: %w(tree blob blame)) do = nav_link(controller: %w(tree blob blame)) do
= link_to 'Files', project_tree_path(@project, @ref || @project.root_ref) = link_to 'Files', project_tree_path(@project, @ref || @repository.root_ref)
= nav_link(controller: %w(commit commits compare repositories protected_branches)) do = nav_link(controller: %w(commit commits compare repositories protected_branches)) do
= link_to "Commits", project_commits_path(@project, @ref || @project.root_ref) = link_to "Commits", project_commits_path(@project, @ref || @repository.root_ref)
= nav_link(path: 'projects#graph') do = nav_link(path: 'projects#graph') do
= link_to "Network", graph_project_path(@project) = link_to "Network", graph_project_path(@project)
......
...@@ -5,15 +5,15 @@ ...@@ -5,15 +5,15 @@
- @merge_request.errors.full_messages.each do |msg| - @merge_request.errors.full_messages.each do |msg|
%li= msg %li= msg
%h4.cdark 1. Select Branches %fieldset
%br %legend 1. Select Branches
.row .row
.span5 .span5
.mr_branch_box .mr_branch_box
%h5 From (Head Branch) %h5 From (Head Branch)
.body .body
.padded= f.select(:source_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) .padded= f.select(:source_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
.mr_source_commit .mr_source_commit
.span2 .span2
...@@ -22,24 +22,26 @@ ...@@ -22,24 +22,26 @@
.mr_branch_box .mr_branch_box
%h5 To (Base Branch) %h5 To (Base Branch)
.body .body
.padded= f.select(:target_branch, @project.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'}) .padded= f.select(:target_branch, @repository.heads.map(&:name), { include_blank: "Select branch" }, {class: 'chosen span4'})
.mr_target_commit .mr_target_commit
%h4.cdark 2. Fill info %fieldset
%legend 2. Fill info
.ui-box.ui-box-show
.ui-box-head
.clearfix .clearfix
.merge_requests_form_box
.top_box_content
= f.label :title do = f.label :title do
%strong= "Title *" %strong= "Title *"
.input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5, required: true .input= f.text_field :title, class: "input-xxlarge pad js-gfm-input", maxlength: 255, rows: 5, required: true
.merge_requests_middle_box .ui-box-body
.merge_requests_assignee .clearfix
.left
= f.label :assignee_id do = f.label :assignee_id do
%i.icon-user %i.icon-user
Assign to Assign to
.input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, {class: 'chosen span3'}) .input= f.select(:assignee_id, @project.users.all.collect {|p| [ p.name, p.id ] }, { include_blank: "Select user" }, {class: 'chosen span3'})
.merge_requests_milestone .left
= f.label :milestone_id do = f.label :milestone_id do
%i.icon-time %i.icon-time
Milestone Milestone
......
- if @commits.present? - if @commits.present?
.ui-box .ui-box
%h5 %h5.title
%i.icon-list %i.icon-list
Commits (#{@commits.count}) Commits (#{@commits.count})
.merge-request-commits .merge-request-commits
......
.main_box .ui-box.ui-box-show
.top_box_content .ui-box-head
%h4.box-title %h4.box-title
- if @merge_request.merged - if @merge_request.merged
.error.status_info .error.status_info
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
.error.status_info Closed .error.status_info Closed
= gfm escape_once(@merge_request.title) = gfm escape_once(@merge_request.title)
.middle_box_content .ui-box-body
%div %div
%cite.cgray %cite.cgray
Created at #{@merge_request.created_at.stamp("Aug 21, 2011")} by #{link_to_member(@project, @merge_request.author)} Created at #{@merge_request.created_at.stamp("Aug 21, 2011")} by #{link_to_member(@project, @merge_request.author)}
...@@ -22,7 +22,7 @@ ...@@ -22,7 +22,7 @@
- if @merge_request.closed - if @merge_request.closed
.bottom_box_content .ui-box-bottom
- if @merge_request.merged? - if @merge_request.merged?
%span %span
Merged by #{link_to_member(@project, @merge_request.merge_event.author)} Merged by #{link_to_member(@project, @merge_request.merge_event.author)}
......
...@@ -27,8 +27,8 @@ ...@@ -27,8 +27,8 @@
%span All issues for this milestone are closed. You may close milestone now. %span All issues for this milestone are closed. You may close milestone now.
= link_to 'Close Milestone', project_milestone_path(@project, @milestone, milestone: {closed: true }), method: :put, class: "btn small danger" = link_to 'Close Milestone', project_milestone_path(@project, @milestone, milestone: {closed: true }), method: :put, class: "btn small danger"
.main_box .ui-box.ui-box-show
.top_box_content .ui-box-head
%h4.box-title %h4.box-title
- if @milestone.closed - if @milestone.closed
.error.status_info Closed .error.status_info Closed
...@@ -37,7 +37,7 @@ ...@@ -37,7 +37,7 @@
= gfm escape_once(@milestone.title) = gfm escape_once(@milestone.title)
.middle_box_content .ui-box-body
%h5 %h5
Progress: Progress:
%small %small
......
...@@ -34,6 +34,8 @@ ...@@ -34,6 +34,8 @@
= preserve do = preserve do
= markdown(note.note) = markdown(note.note)
- if note.attachment.url - if note.attachment.url
- if note.attachment.image?
= image_tag note.attachment.url, class: 'thumbnail span4'
.right .right
%div.file %div.file
= link_to note.attachment_identifier, note.attachment.url, target: "_blank" = link_to note.attachment_identifier, note.attachment.url, target: "_blank"
......
...@@ -15,13 +15,13 @@ ...@@ -15,13 +15,13 @@
= f.label :path do = f.label :path do
Repository Repository
.controls .controls
= text_field_tag :ppath, @project.path_to_repo, class: "xxlarge", readonly: true = text_field_tag :ppath, @repository.path_to_repo, class: "xxlarge", readonly: true
- unless @project.heads.empty? - unless @repository.heads.empty?
.clearfix .clearfix
= f.label :default_branch, "Default Branch" = f.label :default_branch, "Default Branch"
.input= f.select(:default_branch, @project.heads.map(&:name), {}, style: "width:210px;") .input= f.select(:default_branch, @repository.heads.map(&:name), {}, style: "width:210px;")
%fieldset.features %fieldset.features
%legend Features: %legend Features:
......
...@@ -36,7 +36,7 @@ ...@@ -36,7 +36,7 @@
%td %td
= link_to project_commits_path(@project, branch.name) do = link_to project_commits_path(@project, branch.name) do
%strong= branch.name %strong= branch.name
- if branch.name == @project.root_ref - if @project.root_ref?(branch.name)
%span.label default %span.label default
%td %td
- if branch.commit - if branch.commit
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
- else - else
%i.icon-unlock %i.icon-unlock
%strong= truncate(branch.name, length: 60) %strong= truncate(branch.name, length: 60)
- if branch.name == @project.root_ref - if branch.name == @repository.root_ref
%span.label default %span.label default
%td %td
= link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do = link_to project_commit_path(@project, commit.id), class: 'commit_short_id' do
......
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
= link_to project_commits_path(@project, commit.head.name) do = link_to project_commits_path(@project, commit.head.name) do
%strong %strong
= commit.head.name = commit.head.name
- if commit.head.name == @project.root_ref - if @project.root_ref?(commit.head.name)
%span.label default %span.label default
%td %td
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
%b Total commits: %b Total commits:
%span= @stats.commits_count %span= @stats.commits_count
%p %p
%b Total files in #{@project.root_ref}: %b Total files in #{@repository.root_ref}:
%span= @stats.files_count %span= @stats.files_count
%p %p
%b Authors: %b Authors:
......
...@@ -30,4 +30,10 @@ ...@@ -30,4 +30,10 @@
Download Download
- else - else
%h3 No tags %h3.nothing_here_message
Repository has no tags yet.
%br
%small
Use git tag command to add a new one:
%br
%span.monospace git tag -a v1.4 -m 'version 1.4'
- grouper_project_members(@project).each do |access, members| - grouper_project_members(@project).each do |access, members|
.ui-box .ui-box
%h5 %h5.title
= Project.access_options.key(access).pluralize = Project.access_options.key(access).pluralize
%small= members.size %small= members.size
%ul.well-list %ul.well-list
......
...@@ -3,9 +3,13 @@ ...@@ -3,9 +3,13 @@
%span.arrow %span.arrow
= link_to project_tree_path(@project, @ref) do = link_to project_tree_path(@project, @ref) do
= @project.name = @project.name
- tree.breadcrumbs(6) do |link| - tree.breadcrumbs(6) do |title, path|
\/ \/
%li= link %li
- if path
= link_to truncate(title, length: 40), project_tree_path(@project, path)
- else
= link_to title, '#'
.clear .clear
%div.tree_progress %div.tree_progress
...@@ -26,7 +30,7 @@ ...@@ -26,7 +30,7 @@
%tr.tree-item %tr.tree-item
%td.tree-item-file-name %td.tree-item-file-name
= image_tag "file_empty.png", size: '16x16' = image_tag "file_empty.png", size: '16x16'
= link_to "..", tree.up_dir_path = link_to "..", project_tree_path(@project, tree.up_dir_path)
%td %td
%td %td
%td %td
......
...@@ -6,12 +6,12 @@ ...@@ -6,12 +6,12 @@
- @wiki.errors.full_messages.each do |msg| - @wiki.errors.full_messages.each do |msg|
%li= msg %li= msg
.main_box .ui-box.ui-box-show
.top_box_content .ui-box-head
= f.label :title = f.label :title
.input= f.text_field :title, class: 'span8' .input= f.text_field :title, class: 'span8'
= f.hidden_field :slug = f.hidden_field :slug
.middle_box_content .ui-box-body
.input .input
%span.cgray %span.cgray
Wiki content is parsed with #{link_to "GitLab Flavored Markdown", help_markdown_path, target: '_blank'}. Wiki content is parsed with #{link_to "GitLab Flavored Markdown", help_markdown_path, target: '_blank'}.
...@@ -19,7 +19,7 @@ ...@@ -19,7 +19,7 @@
%code [Link Title](page-slug) %code [Link Title](page-slug)
\. \.
.bottom_box_content .ui-box-bottom
= f.label :content = f.label :content
.input= f.text_area :content, class: 'span8 js-gfm-input' .input= f.text_area :content, class: 'span8 js-gfm-input'
.actions .actions
......
...@@ -11,7 +11,7 @@ class PostReceive ...@@ -11,7 +11,7 @@ class PostReceive
# Ignore push from non-gitlab users # Ignore push from non-gitlab users
user = if identifier.eql? Gitlab.config.gitolite.admin_key user = if identifier.eql? Gitlab.config.gitolite.admin_key
email = project.commit(newrev).author.email rescue nil email = project.repository.commit(newrev).author.email rescue nil
User.find_by_email(email) if email User.find_by_email(email) if email
elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier) elsif /^[A-Z0-9._%a-z\-]+@(?:[A-Z0-9a-z\-]+\.)+[A-Za-z]{2,4}$/.match(identifier)
User.find_by_email(identifier) User.find_by_email(identifier)
......
...@@ -16,7 +16,7 @@ class AdminGroups < Spinach::FeatureSteps ...@@ -16,7 +16,7 @@ class AdminGroups < Spinach::FeatureSteps
@project = create(:project, group: @group) @project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project) @event = create(:closed_issue_event, project: @project)
@project.add_access current_user, :admin @project.team << [current_user, :master]
end end
And 'Create gitlab user "John"' do And 'Create gitlab user "John"' do
......
...@@ -61,7 +61,7 @@ class Dashboard < Spinach::FeatureSteps ...@@ -61,7 +61,7 @@ class Dashboard < Spinach::FeatureSteps
And 'I own project "Shop"' do And 'I own project "Shop"' do
@project = create :project, name: 'Shop' @project = create :project, name: 'Shop'
@project.add_access(@user, :admin) @project.team << [@user, :master]
end end
And 'I have group with projects' do And 'I have group with projects' do
...@@ -69,7 +69,7 @@ class Dashboard < Spinach::FeatureSteps ...@@ -69,7 +69,7 @@ class Dashboard < Spinach::FeatureSteps
@project = create(:project, group: @group) @project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project) @event = create(:closed_issue_event, project: @project)
@project.add_access current_user, :admin @project.team << [current_user, :master]
end end
And 'project "Shop" has push event' do And 'project "Shop" has push event' do
......
...@@ -13,7 +13,7 @@ class DashboardIssues < Spinach::FeatureSteps ...@@ -13,7 +13,7 @@ class DashboardIssues < Spinach::FeatureSteps
And 'I have assigned issues' do And 'I have assigned issues' do
project = create :project project = create :project
project.add_access(@user, :read, :write) project.team << [@user, :master]
2.times { create :issue, author: @user, assignee: @user, project: project } 2.times { create :issue, author: @user, assignee: @user, project: project }
end end
......
...@@ -14,8 +14,8 @@ class DashboardMergeRequests < Spinach::FeatureSteps ...@@ -14,8 +14,8 @@ class DashboardMergeRequests < Spinach::FeatureSteps
project1 = create :project project1 = create :project
project2 = create :project project2 = create :project
project1.add_access(@user, :read, :write) project1.team << [@user, :master]
project2.add_access(@user, :read, :write) project2.team << [@user, :master]
merge_request1 = create :merge_request, author: @user, project: project1 merge_request1 = create :merge_request, author: @user, project: project1
merge_request2 = create :merge_request, author: @user, project: project2 merge_request2 = create :merge_request, author: @user, project: project2
......
class DashboardSearch < Spinach::FeatureSteps class DashboardSearch < Spinach::FeatureSteps
include SharedAuthentication include SharedAuthentication
include SharedPaths include SharedPaths
include SharedProject
Given 'I search for "Sho"' do Given 'I search for "Sho"' do
fill_in "dashboard_search", with: "Sho" fill_in "dashboard_search", with: "Sho"
...@@ -11,11 +12,6 @@ class DashboardSearch < Spinach::FeatureSteps ...@@ -11,11 +12,6 @@ class DashboardSearch < Spinach::FeatureSteps
page.should have_link "Shop" page.should have_link "Shop"
end end
And 'I own project "Shop"' do
@project = create(:project, :name => "Shop")
@project.add_access(@user, :admin)
end
Given 'I search for "Contibuting"' do Given 'I search for "Contibuting"' do
fill_in "dashboard_search", with: "Contibuting" fill_in "dashboard_search", with: "Contibuting"
click_button "Search" click_button "Search"
......
...@@ -13,7 +13,7 @@ class Groups < Spinach::FeatureSteps ...@@ -13,7 +13,7 @@ class Groups < Spinach::FeatureSteps
@project = create(:project, group: @group) @project = create(:project, group: @group)
@event = create(:closed_issue_event, project: @project) @event = create(:closed_issue_event, project: @project)
@project.add_access current_user, :admin @project.team << [current_user, :master]
end end
And 'I should see projects activity feed' do And 'I should see projects activity feed' do
......
...@@ -3,13 +3,13 @@ class CreateProject < Spinach::FeatureSteps ...@@ -3,13 +3,13 @@ class CreateProject < Spinach::FeatureSteps
include SharedPaths include SharedPaths
And 'fill project form with valid data' do And 'fill project form with valid data' do
fill_in 'project_name', :with => 'NewProject' fill_in 'project_name', with: 'Empty'
click_button "Create project" click_button "Create project"
end end
Then 'I should see project page' do Then 'I should see project page' do
current_path.should == project_path(Project.last) current_path.should == project_path(Project.last)
page.should have_content "NewProject" page.should have_content "Empty"
end end
And 'I should see empty project instuctions' do And 'I should see empty project instuctions' do
......
...@@ -4,7 +4,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps ...@@ -4,7 +4,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
include SharedPaths include SharedPaths
Then 'I see project commits' do Then 'I see project commits' do
commit = @project.commit commit = @project.repository.commit
page.should have_content(@project.name) page.should have_content(@project.name)
page.should have_content(commit.message) page.should have_content(commit.message)
page.should have_content(commit.id.to_s[0..5]) page.should have_content(commit.id.to_s[0..5])
...@@ -15,7 +15,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps ...@@ -15,7 +15,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
end end
Then 'I see commits atom feed' do Then 'I see commits atom feed' do
commit = CommitDecorator.decorate(@project.commit) commit = CommitDecorator.decorate(@project.repository.commit)
page.response_headers['Content-Type'].should have_content("application/atom+xml") page.response_headers['Content-Type'].should have_content("application/atom+xml")
page.body.should have_selector("title", :text => "Recent commits to #{@project.name}") page.body.should have_selector("title", :text => "Recent commits to #{@project.name}")
page.body.should have_selector("author email", :text => commit.author_email) page.body.should have_selector("author email", :text => commit.author_email)
...@@ -48,7 +48,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps ...@@ -48,7 +48,7 @@ class ProjectBrowseCommits < Spinach::FeatureSteps
page.should have_selector('ul.breadcrumb span.divider', count: 3) page.should have_selector('ul.breadcrumb span.divider', count: 3)
page.should have_selector('ul.breadcrumb a', count: 4) page.should have_selector('ul.breadcrumb a', count: 4)
find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path}\/commits\/master\z/) find('ul.breadcrumb li:first a')['href'].should match(/#{@project.path_with_namespace}\/commits\/master\z/)
find('ul.breadcrumb li:last a')['href'].should match(%r{master/app/models/project\.rb\z}) find('ul.breadcrumb li:last a')['href'].should match(%r{master/app/models/project\.rb\z})
end end
......
...@@ -84,18 +84,18 @@ class ProjectTeamManagement < Spinach::FeatureSteps ...@@ -84,18 +84,18 @@ class ProjectTeamManagement < Spinach::FeatureSteps
And '"Sam" is "Shop" developer' do And '"Sam" is "Shop" developer' do
user = User.find_by_name("Sam") user = User.find_by_name("Sam")
project = Project.find_by_name("Shop") project = Project.find_by_name("Shop")
project.add_access(user, :write) project.team << [user, :developer]
end end
Given 'I own project "Website"' do Given 'I own project "Website"' do
@project = create(:project, :name => "Website") @project = create(:project, :name => "Website")
@project.add_access(@user, :admin) @project.team << [@user, :master]
end end
And '"Mike" is "Website" reporter' do And '"Mike" is "Website" reporter' do
user = User.find_by_name("Mike") user = User.find_by_name("Mike")
project = Project.find_by_name("Website") project = Project.find_by_name("Website")
project.add_access(user, :read) project.team << [user, :reporter]
end end
And 'I click link "Import team from another project"' do And 'I click link "Import team from another project"' do
......
...@@ -114,15 +114,15 @@ module SharedPaths ...@@ -114,15 +114,15 @@ module SharedPaths
end end
Given "I visit my project's files page" do Given "I visit my project's files page" do
visit project_tree_path(@project, @project.root_ref) visit project_tree_path(@project, root_ref)
end end
Given "I visit my project's commits page" do Given "I visit my project's commits page" do
visit project_commits_path(@project, @project.root_ref, {limit: 5}) visit project_commits_path(@project, root_ref, {limit: 5})
end end
Given "I visit my project's commits page for a specific path" do Given "I visit my project's commits page for a specific path" do
visit project_commits_path(@project, @project.root_ref + "/app/models/project.rb", {limit: 5}) visit project_commits_path(@project, root_ref + "/app/models/project.rb", {limit: 5})
end end
Given 'I visit my project\'s commits stats page' do Given 'I visit my project\'s commits stats page' do
...@@ -174,7 +174,7 @@ module SharedPaths ...@@ -174,7 +174,7 @@ module SharedPaths
end end
Given 'I visit project commits page' do Given 'I visit project commits page' do
visit project_commits_path(@project, @project.root_ref, {limit: 5}) visit project_commits_path(@project, root_ref, {limit: 5})
end end
Given 'I visit project commits page for stable branch' do Given 'I visit project commits page for stable branch' do
...@@ -182,7 +182,7 @@ module SharedPaths ...@@ -182,7 +182,7 @@ module SharedPaths
end end
Given 'I visit project source page' do Given 'I visit project source page' do
visit project_tree_path(@project, @project.root_ref) visit project_tree_path(@project, root_ref)
end end
Given 'I visit blob file from repo' do Given 'I visit blob file from repo' do
...@@ -240,4 +240,8 @@ module SharedPaths ...@@ -240,4 +240,8 @@ module SharedPaths
Given 'I visit project wiki page' do Given 'I visit project wiki page' do
visit project_wiki_path(@project, :index) visit project_wiki_path(@project, :index)
end end
def root_ref
@project.repository.root_ref
end
end end
...@@ -4,13 +4,13 @@ module SharedProject ...@@ -4,13 +4,13 @@ module SharedProject
# Create a project without caring about what it's called # Create a project without caring about what it's called
And "I own a project" do And "I own a project" do
@project = create(:project) @project = create(:project)
@project.add_access(@user, :admin) @project.team << [@user, :master]
end end
# Create a specific project called "Shop" # Create a specific project called "Shop"
And 'I own project "Shop"' do And 'I own project "Shop"' do
@project = create(:project, :name => "Shop") @project = create(:project, name: "Shop")
@project.add_access(@user, :admin) @project.team << [@user, :master]
end end
def current_project def current_project
......
...@@ -13,7 +13,7 @@ module Gitlab ...@@ -13,7 +13,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects/:id/notes # GET /projects/:id/notes
get ":id/notes" do get ":id/notes" do
@notes = user_project.common_notes @notes = user_project.notes.common
present paginate(@notes), with: Entities::Note present paginate(@notes), with: Entities::Note
end end
...@@ -25,7 +25,7 @@ module Gitlab ...@@ -25,7 +25,7 @@ module Gitlab
# Example Request: # Example Request:
# GET /projects/:id/notes/:note_id # GET /projects/:id/notes/:note_id
get ":id/notes/:note_id" do get ":id/notes/:note_id" do
@note = user_project.common_notes.find(params[:note_id]) @note = user_project.notes.common.find(params[:note_id])
present @note, with: Entities::Note present @note, with: Entities::Note
end end
......
...@@ -257,7 +257,7 @@ module Gitlab ...@@ -257,7 +257,7 @@ module Gitlab
per_page = params[:per_page] || 20 per_page = params[:per_page] || 20
ref = params[:ref_name] || user_project.try(:default_branch) || 'master' ref = params[:ref_name] || user_project.try(:default_branch) || 'master'
commits = user_project.commits(ref, nil, per_page, page * per_page) commits = user_project.repository.commits(ref, nil, per_page, page * per_page)
present CommitDecorator.decorate(commits), with: Entities::RepoCommit present CommitDecorator.decorate(commits), with: Entities::RepoCommit
end end
...@@ -375,10 +375,10 @@ module Gitlab ...@@ -375,10 +375,10 @@ module Gitlab
ref = params[:sha] ref = params[:sha]
commit = user_project.commit ref commit = user_project.repository.commit ref
not_found! "Commit" unless commit not_found! "Commit" unless commit
tree = Tree.new commit.tree, user_project, ref, params[:filepath] tree = Tree.new commit.tree, ref, params[:filepath]
not_found! "File" unless tree.try(:tree) not_found! "File" unless tree.try(:tree)
content_type tree.mime_type content_type tree.mime_type
......
...@@ -68,7 +68,7 @@ module ExtractsPath ...@@ -68,7 +68,7 @@ module ExtractsPath
id = input id = input
id += '/' unless id.ends_with?('/') id += '/' unless id.ends_with?('/')
valid_refs = @project.ref_names valid_refs = @project.repository.ref_names
valid_refs.select! { |v| id.start_with?("#{v}/") } valid_refs.select! { |v| id.start_with?("#{v}/") }
if valid_refs.length != 1 if valid_refs.length != 1
...@@ -114,9 +114,9 @@ module ExtractsPath ...@@ -114,9 +114,9 @@ module ExtractsPath
@id = File.join(@ref, @path) @id = File.join(@ref, @path)
@commit = CommitDecorator.decorate(@project.commit(@ref)) @commit = CommitDecorator.decorate(@project.repository.commit(@ref))
@tree = Tree.new(@commit.tree, @project, @ref, @path) @tree = Tree.new(@commit.tree, @ref, @path)
@tree = TreeDecorator.new(@tree) @tree = TreeDecorator.new(@tree)
raise InvalidPathError if @tree.invalid? raise InvalidPathError if @tree.invalid?
......
...@@ -82,7 +82,7 @@ module Gitlab ...@@ -82,7 +82,7 @@ module Gitlab
end end
def destroy_project(project) def destroy_project(project)
FileUtils.rm_rf(project.path_to_repo) FileUtils.rm_rf(project.repository.path_to_repo)
conf.rm_repo(project.path_with_namespace) conf.rm_repo(project.path_with_namespace)
end end
...@@ -138,9 +138,9 @@ module Gitlab ...@@ -138,9 +138,9 @@ module Gitlab
::Gitolite::Config::Repo.new(repo_name) ::Gitolite::Config::Repo.new(repo_name)
end end
name_readers = project.repository_readers name_readers = project.team.repository_readers
name_writers = project.repository_writers name_writers = project.team.repository_writers
name_masters = project.repository_masters name_masters = project.team.repository_masters
pr_br = project.protected_branches.map(&:name).join("$ ") pr_br = project.protected_branches.map(&:name).join("$ ")
......
...@@ -170,7 +170,7 @@ module Gitlab ...@@ -170,7 +170,7 @@ module Gitlab
end end
def reference_commit(identifier) def reference_commit(identifier)
if @project.valid_repo? && commit = @project.commit(identifier) if @project.valid_repo? && commit = @project.repository.commit(identifier)
link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}")) link_to(identifier, project_commit_path(@project, commit), html_options.merge(title: CommitDecorator.new(commit).link_title, class: "gfm gfm-commit #{html_options[:class]}"))
end end
end end
......
...@@ -31,7 +31,7 @@ module Gitlab ...@@ -31,7 +31,7 @@ module Gitlab
merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch) merge_repo.git.push({raise: true, timeout: true}, :origin, merge_request.target_branch)
# remove source branch # remove source branch
if merge_request.should_remove_source_branch && !project.root_ref?(merge_request.source_branch) if merge_request.should_remove_source_branch && !project.repository.root_ref?(merge_request.source_branch)
# will raise CommandFailed when push fails # will raise CommandFailed when push fails
merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}") merge_repo.git.push({raise: true, timeout: true}, :origin, ":#{merge_request.source_branch}")
end end
......
...@@ -38,7 +38,7 @@ module StaticModel ...@@ -38,7 +38,7 @@ module StaticModel
end end
def ==(other) def ==(other)
if other.is_a? StaticModel if other.is_a? ::StaticModel
id == other.id id == other.id
else else
super super
......
...@@ -3,12 +3,12 @@ require 'spec_helper' ...@@ -3,12 +3,12 @@ require 'spec_helper'
describe CommitController do describe CommitController do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:user) { create(:user) } let(:user) { create(:user) }
let(:commit) { project.last_commit_for("master") } let(:commit) { project.repository.last_commit_for("master") }
before do before do
sign_in(user) sign_in(user)
project.add_access(user, :read, :admin) project.team << [user, :master]
end end
describe "#show" do describe "#show" do
......
...@@ -7,7 +7,7 @@ describe CommitsController do ...@@ -7,7 +7,7 @@ describe CommitsController do
before do before do
sign_in(user) sign_in(user)
project.add_access(user, :read, :admin) project.team << [user, :master]
end end
describe "GET show" do describe "GET show" do
......
...@@ -7,7 +7,7 @@ describe MergeRequestsController do ...@@ -7,7 +7,7 @@ describe MergeRequestsController do
before do before do
sign_in(user) sign_in(user)
project.add_access(user, :read, :admin) project.team << [user, :master]
MergeRequestsController.any_instance.stub(validates_merge_request: true) MergeRequestsController.any_instance.stub(validates_merge_request: true)
end end
......
...@@ -7,7 +7,7 @@ describe TreeController do ...@@ -7,7 +7,7 @@ describe TreeController do
before do before do
sign_in(user) sign_in(user)
project.add_access(user, :read, :admin) project.team << [user, :master]
project.stub(:branches).and_return(['master', 'foo/bar/baz']) project.stub(:branches).and_return(['master', 'foo/bar/baz'])
project.stub(:tags).and_return(['v1.0.0', 'v2.0.0']) project.stub(:tags).and_return(['v1.0.0', 'v2.0.0'])
......
...@@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do ...@@ -4,7 +4,7 @@ describe GitlabMarkdownHelper do
let!(:project) { create(:project) } let!(:project) { create(:project) }
let(:user) { create(:user, username: 'gfm') } let(:user) { create(:user, username: 'gfm') }
let(:commit) { CommitDecorator.decorate(project.commit) } let(:commit) { CommitDecorator.decorate(project.repository.commit) }
let(:issue) { create(:issue, project: project) } let(:issue) { create(:issue, project: project) }
let(:merge_request) { create(:merge_request, project: project) } let(:merge_request) { create(:merge_request, project: project) }
let(:snippet) { create(:snippet, project: project) } let(:snippet) { create(:snippet, project: project) }
...@@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do ...@@ -85,7 +85,7 @@ describe GitlabMarkdownHelper do
let(:expected) { project_team_member_path(project, member) } let(:expected) { project_team_member_path(project, member) }
before do before do
project.add_access(user, :admin) project.team << [user, :master]
end end
it "should link using a simple name" do it "should link using a simple name" do
...@@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do ...@@ -314,7 +314,7 @@ describe GitlabMarkdownHelper do
end end
it "should handle references in lists" do it "should handle references in lists" do
project.add_access(user, :admin) project.team << [user, :master]
actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}" actual = "\n* dark: ##{issue.id}\n* light by @#{member.user.username}"
......
...@@ -7,7 +7,7 @@ describe ExtractsPath do ...@@ -7,7 +7,7 @@ describe ExtractsPath do
before do before do
@project = project @project = project
project.stub(:ref_names).and_return(['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']) project.stub(repository: stub(ref_names: ['master', 'foo/bar/baz', 'v1.0.0', 'v2.0.0']))
project.stub(path_with_namespace: 'gitlab/gitlab-ci') project.stub(path_with_namespace: 'gitlab/gitlab-ci')
end end
......
require 'spec_helper' require 'spec_helper'
describe Commit do describe Commit do
let(:commit) { create(:project).commit } let(:commit) { create(:project).repository.commit }
describe CommitDecorator do describe CommitDecorator do
let(:decorator) { CommitDecorator.new(commit) } let(:decorator) { CommitDecorator.new(commit) }
......
...@@ -35,10 +35,6 @@ describe GitlabCiService do ...@@ -35,10 +35,6 @@ describe GitlabCiService do
) )
end end
describe :commit_badge_path do
it { @service.commit_badge_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/status?sha=2ab7834c"}
end
describe :commit_status_path do describe :commit_status_path do
it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c/status.json?token=verySecret"} it { @service.commit_status_path("2ab7834c").should == "http://ci.gitlab.org/projects/2/builds/2ab7834c/status.json?token=verySecret"}
end end
......
...@@ -4,7 +4,6 @@ ...@@ -4,7 +4,6 @@
# #
# id :integer not null, primary key # id :integer not null, primary key
# note :text # note :text
# noteable_id :string(255)
# noteable_type :string(255) # noteable_type :string(255)
# author_id :integer # author_id :integer
# created_at :datetime not null # created_at :datetime not null
...@@ -12,6 +11,8 @@ ...@@ -12,6 +11,8 @@
# project_id :integer # project_id :integer
# attachment :string(255) # attachment :string(255)
# line_code :string(255) # line_code :string(255)
# commit_id :string(255)
# noteable_id :integer
# #
require 'spec_helper' require 'spec_helper'
...@@ -76,7 +77,7 @@ describe Note do ...@@ -76,7 +77,7 @@ describe Note do
end end
let(:project) { create(:project) } let(:project) { create(:project) }
let(:commit) { project.commit } let(:commit) { project.repository.commit }
describe "Commit notes" do describe "Commit notes" do
before do before do
......
...@@ -2,6 +2,7 @@ require 'spec_helper' ...@@ -2,6 +2,7 @@ require 'spec_helper'
describe Project, "Hooks" do describe Project, "Hooks" do
let(:project) { create(:project) } let(:project) { create(:project) }
before do before do
@key = create(:key, user: project.owner) @key = create(:key, user: project.owner)
@user = @key.user @user = @key.user
...@@ -70,8 +71,9 @@ describe Project, "Hooks" do ...@@ -70,8 +71,9 @@ describe Project, "Hooks" do
context "when gathering commit data" do context "when gathering commit data" do
before do before do
@oldrev, @newrev, @ref = project.fresh_commits(2).last.sha, project.fresh_commits(2).first.sha, 'refs/heads/master' @oldrev, @newrev, @ref = project.repository.fresh_commits(2).last.sha,
@commit = project.fresh_commits(2).first project.repository.fresh_commits(2).first.sha, 'refs/heads/master'
@commit = project.repository.fresh_commits(2).first
# Fill nil/empty attributes # Fill nil/empty attributes
project.description = "This is a description" project.description = "This is a description"
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# private_flag :boolean default(TRUE), not null # private_flag :boolean default(TRUE), not null
# owner_id :integer # creator_id :integer
# default_branch :string(255) # default_branch :string(255)
# issues_enabled :boolean default(TRUE), not null # issues_enabled :boolean default(TRUE), not null
# wall_enabled :boolean default(TRUE), not null # wall_enabled :boolean default(TRUE), not null
...@@ -75,57 +75,16 @@ describe Project do ...@@ -75,57 +75,16 @@ describe Project do
end end
describe "Respond to" do describe "Respond to" do
it { should respond_to(:public?) }
it { should respond_to(:private?) }
it { should respond_to(:url_to_repo) } it { should respond_to(:url_to_repo) }
it { should respond_to(:path_to_repo) }
it { should respond_to(:valid_repo?) }
it { should respond_to(:repo_exists?) } it { should respond_to(:repo_exists?) }
# Repository Role
it { should respond_to(:tree) }
it { should respond_to(:root_ref) }
it { should respond_to(:repo) }
it { should respond_to(:tags) }
it { should respond_to(:commit) }
it { should respond_to(:commits) }
it { should respond_to(:commits_between) }
it { should respond_to(:commits_with_refs) }
it { should respond_to(:commits_since) }
it { should respond_to(:commits_between) }
it { should respond_to(:satellite) } it { should respond_to(:satellite) }
it { should respond_to(:update_repository) } it { should respond_to(:update_repository) }
it { should respond_to(:destroy_repository) } it { should respond_to(:destroy_repository) }
it { should respond_to(:archive_repo) }
# Authority Role
it { should respond_to(:add_access) }
it { should respond_to(:reset_access) }
it { should respond_to(:repository_writers) }
it { should respond_to(:repository_masters) }
it { should respond_to(:repository_readers) }
it { should respond_to(:allow_read_for?) }
it { should respond_to(:guest_access_for?) }
it { should respond_to(:report_access_for?) }
it { should respond_to(:dev_access_for?) }
it { should respond_to(:master_access_for?) }
# Team Role
it { should respond_to(:team_member_by_name_or_email) }
it { should respond_to(:team_member_by_id) }
it { should respond_to(:add_user_to_team) }
it { should respond_to(:add_users_to_team) }
it { should respond_to(:add_user_id_to_team) }
it { should respond_to(:add_users_ids_to_team) }
# Project Push Role
it { should respond_to(:observe_push) } it { should respond_to(:observe_push) }
it { should respond_to(:update_merge_requests) } it { should respond_to(:update_merge_requests) }
it { should respond_to(:execute_hooks) } it { should respond_to(:execute_hooks) }
it { should respond_to(:post_receive_data) } it { should respond_to(:post_receive_data) }
it { should respond_to(:trigger_post_receive) } it { should respond_to(:trigger_post_receive) }
# Namespaced Project Role
it { should respond_to(:transfer) } it { should respond_to(:transfer) }
it { should respond_to(:name_with_namespace) } it { should respond_to(:name_with_namespace) }
it { should respond_to(:namespace_owner) } it { should respond_to(:namespace_owner) }
...@@ -138,11 +97,6 @@ describe Project do ...@@ -138,11 +97,6 @@ describe Project do
project.url_to_repo.should == Gitlab.config.gitolite.ssh_path_prefix + "somewhere.git" project.url_to_repo.should == Gitlab.config.gitolite.ssh_path_prefix + "somewhere.git"
end end
it "should return path to repo" do
project = Project.new(path: "somewhere")
project.path_to_repo.should == Rails.root.join("tmp", "repositories", "somewhere")
end
it "returns the full web URL for this repo" do it "returns the full web URL for this repo" do
project = Project.new(path: "somewhere") project = Project.new(path: "somewhere")
project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere" project.web_url.should == "#{Gitlab.config.gitlab.url}/somewhere"
...@@ -269,4 +223,16 @@ describe Project do ...@@ -269,4 +223,16 @@ describe Project do
it { @project.to_param.should == "gitlab-ci" } it { @project.to_param.should == "gitlab-ci" }
end end
end end
describe :repository do
let(:project) { create(:project) }
it "should return valid repo" do
project.repository.should be_kind_of(Repository)
end
it "should return nil" do
Project.new(path: "empty").repository.should be_nil
end
end
end end
...@@ -44,7 +44,7 @@ describe ProtectedBranch do ...@@ -44,7 +44,7 @@ describe ProtectedBranch do
let(:branch) { create(:protected_branch) } let(:branch) { create(:protected_branch) }
it 'commits itself to its project' do it 'commits itself to its project' do
branch.project.should_receive(:commit).with(branch.name) branch.project.repository.should_receive(:commit).with(branch.name)
branch.commit branch.commit
end end
end end
......
require 'spec_helper' require "spec_helper"
describe Project, "Repository" do describe Repository do
let(:project) { create(:project) } let(:project) { create(:project) }
let(:repository) { project.repository }
describe "#empty_repo?" do describe "Respond to" do
it "should return true if the repo doesn't exist" do subject { repository }
project.stub(repo_exists?: false, has_commits?: true)
project.should be_empty_repo
end
it "should return true if the repo has commits" do it { should respond_to(:repo) }
project.stub(repo_exists?: true, has_commits?: false) it { should respond_to(:tree) }
project.should be_empty_repo it { should respond_to(:root_ref) }
it { should respond_to(:tags) }
it { should respond_to(:commit) }
it { should respond_to(:commits) }
it { should respond_to(:commits_between) }
it { should respond_to(:commits_with_refs) }
it { should respond_to(:commits_since) }
it { should respond_to(:commits_between) }
end end
it "should return false if the repo exists and has commits" do
project.stub(repo_exists?: true, has_commits?: true)
project.should_not be_empty_repo
end
end
describe "#discover_default_branch" do describe "#discover_default_branch" do
let(:master) { 'master' } let(:master) { 'master' }
let(:stable) { 'stable' } let(:stable) { 'stable' }
it "returns 'master' when master exists" do it "returns 'master' when master exists" do
project.should_receive(:branch_names).at_least(:once).and_return([stable, master]) repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'master' repository.discover_default_branch.should == 'master'
end end
it "returns non-master when master exists but default branch is set to something else" do it "returns non-master when master exists but default branch is set to something else" do
project.default_branch = 'stable' repository.root_ref = 'stable'
project.should_receive(:branch_names).at_least(:once).and_return([stable, master]) repository.should_receive(:branch_names).at_least(:once).and_return([stable, master])
project.discover_default_branch.should == 'stable' repository.discover_default_branch.should == 'stable'
end end
it "returns a non-master branch when only one exists" do it "returns a non-master branch when only one exists" do
project.should_receive(:branch_names).at_least(:once).and_return([stable]) repository.should_receive(:branch_names).at_least(:once).and_return([stable])
project.discover_default_branch.should == 'stable' repository.discover_default_branch.should == 'stable'
end end
it "returns nil when no branch exists" do it "returns nil when no branch exists" do
project.should_receive(:branch_names).at_least(:once).and_return([]) repository.should_receive(:branch_names).at_least(:once).and_return([])
project.discover_default_branch.should be_nil repository.discover_default_branch.should be_nil
end
end
describe "#root_ref" do
it "returns default_branch when set" do
project.default_branch = 'stable'
project.root_ref.should == 'stable'
end
it "returns 'master' when default_branch is nil" do
project.default_branch = nil
project.root_ref.should == 'master'
end
end
describe "#root_ref?" do
it "returns true when branch is root_ref" do
project.default_branch = 'stable'
project.root_ref?('stable').should be_true
end
it "returns false when branch is not root_ref" do
project.default_branch = nil
project.root_ref?('stable').should be_false
end
end
describe :repo do
it "should return valid repo" do
project.repo.should be_kind_of(Grit::Repo)
end
it "should return nil" do
lambda { Project.new(path: "invalid").repo }.should raise_error(Grit::NoSuchPathError)
end
it "should return nil" do
lambda { Project.new.repo }.should raise_error(TypeError)
end end
end end
describe :commit do describe :commit do
it "should return first head commit if without params" do it "should return first head commit if without params" do
project.commit.id.should == project.repo.commits.first.id repository.commit.id.should == repository.repo.commits.first.id
end end
it "should return valid commit" do it "should return valid commit" do
project.commit(ValidCommit::ID).should be_valid_commit repository.commit(ValidCommit::ID).should be_valid_commit
end end
it "should return nil" do it "should return nil" do
project.commit("+123_4532530XYZ").should be_nil repository.commit("+123_4532530XYZ").should be_nil
end end
end end
describe :tree do describe :tree do
before do before do
@commit = project.commit(ValidCommit::ID) @commit = repository.commit(ValidCommit::ID)
end end
it "should raise error w/o arguments" do it "should raise error w/o arguments" do
lambda { project.tree }.should raise_error lambda { repository.tree }.should raise_error
end end
it "should return root tree for commit" do it "should return root tree for commit" do
tree = project.tree(@commit) tree = repository.tree(@commit)
tree.contents.size.should == ValidCommit::FILES_COUNT tree.contents.size.should == ValidCommit::FILES_COUNT
tree.contents.map(&:name).should == ValidCommit::FILES tree.contents.map(&:name).should == ValidCommit::FILES
end end
it "should return root tree for commit with correct path" do it "should return root tree for commit with correct path" do
tree = project.tree(@commit, ValidCommit::C_FILE_PATH) tree = repository.tree(@commit, ValidCommit::C_FILE_PATH)
tree.contents.map(&:name).should == ValidCommit::C_FILES tree.contents.map(&:name).should == ValidCommit::C_FILES
end end
it "should return root tree for commit with incorrect path" do it "should return root tree for commit with incorrect path" do
project.tree(@commit, "invalid_path").should be_nil repository.tree(@commit, "invalid_path").should be_nil
end end
end end
describe "fresh commits" do describe "fresh commits" do
let(:project) { create(:project) } it { repository.fresh_commits(3).count.should == 3 }
it { repository.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
it { project.fresh_commits(3).count.should == 3 } it { repository.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
it { project.fresh_commits.first.id.should == "bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a" }
it { project.fresh_commits.last.id.should == "f403da73f5e62794a0447aca879360494b08f678" }
end end
describe "commits_between" do describe "commits_between" do
let(:project) { create(:project) }
subject do subject do
commits = project.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff", commits = repository.commits_between("3a4b4fb4cde7809f033822a171b9feae19d41fff",
"8470d70da67355c9c009e4401746b1d5410af2e3") "8470d70da67355c9c009e4401746b1d5410af2e3")
commits.map { |c| c.id } commits.map { |c| c.id }
end end
...@@ -144,16 +102,4 @@ describe Project, "Repository" do ...@@ -144,16 +102,4 @@ describe Project, "Repository" do
it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") } it { should include("f0f14c8eaba69ebddd766498a9d0b0e79becd633") }
it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") } it { should_not include("bcf03b5de6c33f3869ef70d68cf06e679d1d7f9a") }
end end
describe :valid_repo? do
it "should be valid repo" do
project = create(:project)
project.valid_repo?.should be_true
end
it "should be invalid repo" do
project = Project.new(name: "ok_name", path: "/INVALID_PATH/", path: "NEOK")
project.valid_repo?.should be_false
end
end
end end
...@@ -56,7 +56,7 @@ describe SystemHook do ...@@ -56,7 +56,7 @@ describe SystemHook do
user = create(:user) user = create(:user)
project = create(:project) project = create(:project)
with_resque do with_resque do
project.add_access(user, :admin) project.team << [user, :master]
end end
WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once WebMock.should have_requested(:post, @system_hook.url).with(body: /user_add_to_team/).once
end end
...@@ -64,7 +64,7 @@ describe SystemHook do ...@@ -64,7 +64,7 @@ describe SystemHook do
it "project_destroy hook" do it "project_destroy hook" do
user = create(:user) user = create(:user)
project = create(:project) project = create(:project)
project.add_access(user, :admin) project.team << [user, :master]
with_resque do with_resque do
project.users_projects.clear project.users_projects.clear
end end
......
require "spec_helper"
describe Team do
let(:team) { create(:project).team }
describe "Respond to" do
subject { team }
it { should respond_to(:developers) }
it { should respond_to(:masters) }
it { should respond_to(:reporters) }
it { should respond_to(:guests) }
it { should respond_to(:repository_writers) }
it { should respond_to(:repository_masters) }
it { should respond_to(:repository_readers) }
end
end
...@@ -48,10 +48,10 @@ describe UsersProject do ...@@ -48,10 +48,10 @@ describe UsersProject do
@user_1 = create :user @user_1 = create :user
@user_2 = create :user @user_2 = create :user
@project_1.add_access @user_1, :write @project_1.team << [ @user_1, :developer ]
@project_2.add_access @user_2, :read @project_2.team << [ @user_2, :reporter ]
@status = UsersProject.import_team(@project_1, @project_2) @status = @project_2.team.import(@project_1)
end end
it { @status.should be_true } it { @status.should be_true }
...@@ -101,8 +101,8 @@ describe UsersProject do ...@@ -101,8 +101,8 @@ describe UsersProject do
@user_1 = create :user @user_1 = create :user
@user_2 = create :user @user_2 = create :user
@project_1.add_access @user_1, :write @project_1.team << [ @user_1, :developer]
@project_2.add_access @user_2, :read @project_2.team << [ @user_2, :reporter]
UsersProject.truncate_teams([@project_1.id, @project_2.id]) UsersProject.truncate_teams([@project_1.id, @project_2.id])
end end
......
...@@ -6,7 +6,7 @@ describe Gitlab::API do ...@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user) } let(:user) { create(:user) }
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:issue) { create(:issue, author: user, assignee: user, project: project) } let!(:issue) { create(:issue, author: user, assignee: user, project: project) }
before { project.add_access(user, :read) } before { project.team << [user, :reporter] }
describe "GET /issues" do describe "GET /issues" do
context "when unauthenticated" do context "when unauthenticated" do
......
...@@ -6,7 +6,7 @@ describe Gitlab::API do ...@@ -6,7 +6,7 @@ describe Gitlab::API do
let(:user) { create(:user ) } let(:user) { create(:user ) }
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") } let!(:merge_request) { create(:merge_request, author: user, assignee: user, project: project, title: "Test") }
before { project.add_access(user, :read) } before { project.team << [user, :reporters] }
describe "GET /projects/:id/merge_requests" do describe "GET /projects/:id/merge_requests" do
context "when unauthenticated" do context "when unauthenticated" do
......
...@@ -7,7 +7,7 @@ describe Gitlab::API do ...@@ -7,7 +7,7 @@ describe Gitlab::API do
let!(:project) { create(:project, namespace: user.namespace ) } let!(:project) { create(:project, namespace: user.namespace ) }
let!(:milestone) { create(:milestone, project: project) } let!(:milestone) { create(:milestone, project: project) }
before { project.add_access(user, :read) } before { project.team << [user, :developer] }
describe "GET /projects/:id/milestones" do describe "GET /projects/:id/milestones" do
it "should return project milestones" do it "should return project milestones" do
......
...@@ -10,7 +10,7 @@ describe Gitlab::API do ...@@ -10,7 +10,7 @@ describe Gitlab::API do
let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) } let!(:issue_note) { create(:note, noteable: issue, project: project, author: user) }
let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) } let!(:snippet_note) { create(:note, noteable: snippet, project: project, author: user) }
let!(:wall_note) { create(:note, project: project, author: user) } let!(:wall_note) { create(:note, project: project, author: user) }
before { project.add_access(user, :read) } before { project.team << [user, :reporter] }
describe "GET /projects/:id/notes" do describe "GET /projects/:id/notes" do
context "when unauthenticated" do context "when unauthenticated" do
......
...@@ -11,7 +11,7 @@ describe Gitlab::API do ...@@ -11,7 +11,7 @@ describe Gitlab::API do
let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') } let!(:snippet) { create(:snippet, author: user, project: project, title: 'example') }
let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) } let!(:users_project) { create(:users_project, user: user, project: project, project_access: UsersProject::MASTER) }
let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) } let!(:users_project2) { create(:users_project, user: user3, project: project, project_access: UsersProject::DEVELOPER) }
before { project.add_access(user, :read) } before { project.team << [user, :reporter] }
describe "GET /projects" do describe "GET /projects" do
context "when unauthenticated" do context "when unauthenticated" do
...@@ -226,14 +226,14 @@ describe Gitlab::API do ...@@ -226,14 +226,14 @@ describe Gitlab::API do
describe "GET /projects/:id/repository/commits" do describe "GET /projects/:id/repository/commits" do
context "authorized user" do context "authorized user" do
before { project.add_access(user2, :read) } before { project.team << [user2, :reporter] }
it "should return project commits" do it "should return project commits" do
get api("/projects/#{project.id}/repository/commits", user) get api("/projects/#{project.id}/repository/commits", user)
response.status.should == 200 response.status.should == 200
json_response.should be_an Array json_response.should be_an Array
json_response.first['id'].should == project.commit.id json_response.first['id'].should == project.repository.commit.id
end end
end end
......
...@@ -6,7 +6,7 @@ describe "Issues Feed" do ...@@ -6,7 +6,7 @@ describe "Issues Feed" do
let!(:project) { create(:project, namespace: user.namespace) } let!(:project) { create(:project, namespace: user.namespace) }
let!(:issue) { create(:issue, author: user, project: project) } let!(:issue) { create(:issue, author: user, project: project) }
before { project.add_access(user, :read, :write) } before { project.team << [user, :developer] }
context "when authenticated" do context "when authenticated" do
it "should render atom feed" do it "should render atom feed" do
......
...@@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do ...@@ -6,7 +6,7 @@ describe "Gitlab Flavored Markdown" do
let(:merge_request) { create(:merge_request, project: project) } let(:merge_request) { create(:merge_request, project: project) }
let(:fred) do let(:fred) do
u = create(:user, name: "fred") u = create(:user, name: "fred")
project.add_access(u, :admin) project.team << [u, :master]
u u
end end
...@@ -33,11 +33,11 @@ describe "Gitlab Flavored Markdown" do ...@@ -33,11 +33,11 @@ describe "Gitlab Flavored Markdown" do
project.repo.gc_auto project.repo.gc_auto
end end
let(:commit) { project.commits(@branch_name).first } let(:commit) { project.repository.commits(@branch_name).first }
before do before do
login_as :user login_as :user
project.add_access(@user, :read, :write) project.team << [@user, :developer]
end end
describe "for commits" do describe "for commits" do
......
...@@ -7,8 +7,7 @@ describe "Issues" do ...@@ -7,8 +7,7 @@ describe "Issues" do
login_as :user login_as :user
user2 = create(:user) user2 = create(:user)
project.add_access(@user, :read, :write) project.team << [[@user, user2], :developer]
project.add_access(user2, :read, :write)
end end
describe "Edit issue" do describe "Edit issue" do
......
...@@ -5,7 +5,7 @@ describe "Projects", "DeployKeys" do ...@@ -5,7 +5,7 @@ describe "Projects", "DeployKeys" do
before do before do
login_as :user login_as :user
project.add_access(@user, :read, :write, :admin) project.team << [@user, :master]
end end
describe "GET /keys" do describe "GET /keys" do
......
...@@ -6,7 +6,7 @@ describe "Projects" do ...@@ -6,7 +6,7 @@ describe "Projects" do
describe "GET /projects/show" do describe "GET /projects/show" do
before do before do
@project = create(:project, namespace: @user.namespace) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read) @project.team << [@user, :reporter]
visit project_path(@project) visit project_path(@project)
end end
...@@ -19,7 +19,7 @@ describe "Projects" do ...@@ -19,7 +19,7 @@ describe "Projects" do
describe "GET /projects/:id/edit" do describe "GET /projects/:id/edit" do
before do before do
@project = create(:project) @project = create(:project)
@project.add_access(@user, :admin, :read) @project.team << [@user, :master]
visit edit_project_path(@project) visit edit_project_path(@project)
end end
...@@ -38,7 +38,7 @@ describe "Projects" do ...@@ -38,7 +38,7 @@ describe "Projects" do
describe "PUT /projects/:id" do describe "PUT /projects/:id" do
before do before do
@project = create(:project, namespace: @user.namespace) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :admin, :read) @project.team << [@user, :master]
visit edit_project_path(@project) visit edit_project_path(@project)
...@@ -59,7 +59,7 @@ describe "Projects" do ...@@ -59,7 +59,7 @@ describe "Projects" do
describe "DELETE /projects/:id" do describe "DELETE /projects/:id" do
before do before do
@project = create(:project, namespace: @user.namespace) @project = create(:project, namespace: @user.namespace)
@project.add_access(@user, :read, :admin) @project.team << [@user, :master]
visit edit_project_path(@project) visit edit_project_path(@project)
end end
......
...@@ -4,7 +4,7 @@ describe "Search" do ...@@ -4,7 +4,7 @@ describe "Search" do
before do before do
login_as :user login_as :user
@project = create(:project) @project = create(:project)
@project.add_access(@user, :read) @project.team << [@user, :reporter]
visit search_path visit search_path
fill_in "search", with: @project.name[0..3] fill_in "search", with: @project.name[0..3]
click_button "Search" click_button "Search"
......
...@@ -22,10 +22,10 @@ describe "Application access" do ...@@ -22,10 +22,10 @@ describe "Application access" do
before do before do
# full access # full access
project.users_projects.create(user: master, project_access: UsersProject::MASTER) project.team << [master, :master]
# readonly # readonly
project.users_projects.create(user: reporter, project_access: UsersProject::REPORTER) project.team << [reporter, :reporter]
end end
describe "GET /project_code" do describe "GET /project_code" do
...@@ -40,7 +40,7 @@ describe "Application access" do ...@@ -40,7 +40,7 @@ describe "Application access" do
end end
describe "GET /project_code/tree/master" do describe "GET /project_code/tree/master" do
subject { project_tree_path(project, project.root_ref) } subject { project_tree_path(project, project.repository.root_ref) }
it { should be_allowed_for master } it { should be_allowed_for master }
it { should be_allowed_for reporter } it { should be_allowed_for reporter }
...@@ -51,7 +51,7 @@ describe "Application access" do ...@@ -51,7 +51,7 @@ describe "Application access" do
end end
describe "GET /project_code/commits/master" do describe "GET /project_code/commits/master" do
subject { project_commits_path(project, project.root_ref, limit: 1) } subject { project_commits_path(project, project.repository.root_ref, limit: 1) }
it { should be_allowed_for master } it { should be_allowed_for master }
it { should be_allowed_for reporter } it { should be_allowed_for reporter }
...@@ -62,7 +62,7 @@ describe "Application access" do ...@@ -62,7 +62,7 @@ describe "Application access" do
end end
describe "GET /project_code/commit/:sha" do describe "GET /project_code/commit/:sha" do
subject { project_commit_path(project, project.commit) } subject { project_commit_path(project, project.repository.commit) }
it { should be_allowed_for master } it { should be_allowed_for master }
it { should be_allowed_for reporter } it { should be_allowed_for reporter }
...@@ -107,7 +107,7 @@ describe "Application access" do ...@@ -107,7 +107,7 @@ describe "Application access" do
describe "GET /project_code/blob" do describe "GET /project_code/blob" do
before do before do
commit = project.commit commit = project.repository.commit
path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name path = commit.tree.contents.select { |i| i.is_a?(Grit::Blob)}.first.name
@blob_path = project_blob_path(project, File.join(commit.id, path)) @blob_path = project_blob_path(project, File.join(commit.id, path))
end end
......
...@@ -5,7 +5,7 @@ describe "Snippets" do ...@@ -5,7 +5,7 @@ describe "Snippets" do
before do before do
login_as :user login_as :user
project.add_access(@user, :read, :write) project.team << [@user, :developer]
end end
describe "GET /snippets" do describe "GET /snippets" do
...@@ -26,7 +26,7 @@ describe "Snippets" do ...@@ -26,7 +26,7 @@ describe "Snippets" do
before do before do
# admin access to remove snippet # admin access to remove snippet
@user.users_projects.destroy_all @user.users_projects.destroy_all
project.add_access(@user, :read, :write, :admin) project.team << [@user, :master]
visit edit_project_snippet_path(project, @snippet) visit edit_project_snippet_path(project, @snippet)
end end
......
require "repository"
require "project"
# Stubs out all Git repository access done by models so that specs can run # Stubs out all Git repository access done by models so that specs can run
# against fake repositories without Grit complaining that they don't exist. # against fake repositories without Grit complaining that they don't exist.
class Project class Project
def path_to_repo def repository
if new_record? || path == 'newproject' if path == "empty" || !path
# There are a couple Project specs and features that expect the Project's nil
# path to be in the returned path, so let's patronize them.
Rails.root.join('tmp', 'repositories', path)
else else
# For everything else, just give it the path to one of our real seeded GitLabTestRepo.new(path_with_namespace)
# repos.
Rails.root.join('tmp', 'repositories', 'gitlabhq')
end end
end end
...@@ -27,3 +26,9 @@ class Project ...@@ -27,3 +26,9 @@ class Project
end end
end end
end end
class GitLabTestRepo < Repository
def repo
@repo ||= Grit::Repo.new(Rails.root.join('tmp', 'repositories', 'gitlabhq'))
end
end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment