From 7812cb77c81cb199c7c8fd276130238ccabb856d Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:20:04 +0900 Subject: [PATCH 01/23] Fix typo. --- lib/gitlab/graph/json_builder.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 4b3687e0..fc58d7f2 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -49,7 +49,7 @@ module Gitlab # list of commits. As well as returns date list # corelated with time set on commits. # - # @param [Array] comits to index + # @param [Array] commits to index # # @return [Array] list of commit dates corelated with time on commits def index_commits From 1e907498a944c22db79e9cfbd26ee7f10fe1a091 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:34:35 +0900 Subject: [PATCH 02/23] The commit is marked and displayed in the center. --- app/views/graph/show.html.haml | 3 ++- vendor/assets/javascripts/branch-graph.js | 21 +++++++++++++++------ 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml index ca3a8706..4ca75d68 100644 --- a/app/views/graph/show.html.haml +++ b/app/views/graph/show.html.haml @@ -14,6 +14,7 @@ branch_graph = new BranchGraph($("#holder"), { url: '#{project_graph_path(@project, @ref, format: :json)}', commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', - ref: '#{@ref}' + ref: '#{@ref}', + commit_id: '#{@commit && @commit.id}' }); }); diff --git a/vendor/assets/javascripts/branch-graph.js b/vendor/assets/javascripts/branch-graph.js index 7929d3b2..fb22953a 100644 --- a/vendor/assets/javascripts/branch-graph.js +++ b/vendor/assets/javascripts/branch-graph.js @@ -161,14 +161,23 @@ if (this.commits[i].refs) { this.appendLabel(x, y, this.commits[i].refs); - - // The main branch is displayed in the center. - re = new RegExp('(^| )' + this.options.ref + '( |$)'); - if (this.commits[i].refs.match(re)) { - scrollLeft = x - graphWidth / 2; - } } + // mark commit and displayed in the center + if (this.commits[i].id == this.options.commit_id) { + r.path([ + 'M', x, y - 5, + 'L', x + 4, y - 15, + 'L', x - 4, y - 15, + 'Z' + ]).attr({ + "fill": "#000", + "fill-opacity": .7, + "stroke": "none" + }); + scrollLeft = x - graphWidth / 2; + } + this.appendAnchor(top, this.commits[i], x, y); } top.toFront(); From 81cc1cb87b2056b11640c9887bd40674c9d7925e Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:42:30 +0900 Subject: [PATCH 03/23] Enable to display the commit older than 650th commit. --- app/controllers/graph_controller.rb | 2 +- lib/gitlab/graph/json_builder.rb | 66 ++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 20 deletions(-) diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb index 30ec5e89..c4d745e9 100644 --- a/app/controllers/graph_controller.rb +++ b/app/controllers/graph_controller.rb @@ -10,7 +10,7 @@ class GraphController < ProjectResourceController respond_to do |format| format.html format.json do - graph = Gitlab::Graph::JsonBuilder.new(project, @ref) + graph = Gitlab::Graph::JsonBuilder.new(project, @ref, @commit) render :json => graph.to_json end end diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index fc58d7f2..05e16f3d 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -9,9 +9,10 @@ module Gitlab @max_count ||= 650 end - def initialize project, ref + def initialize project, ref, commit @project = project @ref = ref + @commit = commit @repo = project.repo @ref_cache = {} @@ -31,7 +32,8 @@ module Gitlab # Get commits from repository # def collect_commits - @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count}).dup + + @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count, skip: to_commit}).dup # Decorate with app/models/commit.rb @commits.map! { |commit| ::Commit.new(commit) } @@ -53,37 +55,24 @@ module Gitlab # # @return [Array] list of commit dates corelated with time on commits def index_commits - days, heads, times = [], [], [] + days, times = [], [] map = {} commits.reverse.each_with_index do |c,i| c.time = i days[i] = c.committed_date map[c.id] = c - heads += c.refs unless c.refs.nil? times[i] = c end - heads.select!{|h| h.is_a? Grit::Head or h.is_a? Grit::Remote} - # sort heads so the master is top and current branches are closer - heads.sort! do |a,b| - if a.name == @ref - -1 - elsif b.name == @ref - 1 - else - b.commit.committed_date <=> a.commit.committed_date - end - end - @_reserved = {} days.each_index do |i| @_reserved[i] = [] end - heads.each do |h| - if map.include? h.commit.id then - place_chain(map[h.commit.id], map) + commits_sort_by_ref.each do |commit| + if map.include? commit.id then + place_chain(map[commit.id], map) end end @@ -95,6 +84,45 @@ module Gitlab days end + # Skip count that the target commit is displayed in center. + def to_commit + commits = Grit::Commit.find_all(repo, nil) + commit_index = commits.index do |c| + c.id == @commit.id + end + + if commit_index && (self.class.max_count / 2 < commit_index) then + # get max index that commit is displayed in the center. + commit_index - self.class.max_count / 2 + else + 0 + end + end + + def commits_sort_by_ref + commits.sort do |a,b| + if include_ref?(a) + -1 + elsif include_ref?(b) + 1 + else + b.committed_date <=> a.committed_date + end + end + end + + def include_ref?(commit) + heads = commit.refs.select do |ref| + ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) + end + + heads.map! do |head| + head.name + end + + heads.include?(@ref) + end + def find_free_parent_spaces(commit, map, times) spaces = [] From 8ff5cf9cd5193b7135f53de3b62dd50bcbbfc2dc Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 12:46:31 +0900 Subject: [PATCH 04/23] Add search box for the commit. --- app/controllers/graph_controller.rb | 10 ++++++++++ app/views/graph/_head.html.haml | 9 +++++++++ app/views/graph/show.html.haml | 9 +++------ 3 files changed, 22 insertions(+), 6 deletions(-) create mode 100644 app/views/graph/_head.html.haml diff --git a/app/controllers/graph_controller.rb b/app/controllers/graph_controller.rb index c4d745e9..c370433e 100644 --- a/app/controllers/graph_controller.rb +++ b/app/controllers/graph_controller.rb @@ -7,6 +7,16 @@ class GraphController < ProjectResourceController before_filter :require_non_empty_project def show + if params.has_key?(:q) && params[:q].blank? + redirect_to project_graph_path(@project, params[:id]) + return + end + + if params.has_key?(:q) + @q = params[:q] + @commit = @project.repository.commit(@q) || @commit + end + respond_to do |format| format.html format.json do diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml new file mode 100644 index 00000000..7e1b4644 --- /dev/null +++ b/app/views/graph/_head.html.haml @@ -0,0 +1,9 @@ +%ul.nav.nav-tabs + %li + = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} + %li.pull-right.search + = form_tag project_graph_path(@project, params[:id]), method: :get, class: 'navbar-form' do |f| + = label_tag :search , "Looking for commit:" + = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input" + +%h3.page_title Project Network Graph diff --git a/app/views/graph/show.html.haml b/app/views/graph/show.html.haml index 4ca75d68..e45aca1d 100644 --- a/app/views/graph/show.html.haml +++ b/app/views/graph/show.html.haml @@ -1,7 +1,4 @@ -%h3.page_title Project Network Graph -%br -= render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} -%br += render "head" .graph_holder %h4 %small You can move around the graph by using the arrow keys. @@ -12,9 +9,9 @@ var branch_graph; $(function(){ branch_graph = new BranchGraph($("#holder"), { - url: '#{project_graph_path(@project, @ref, format: :json)}', + url: '#{project_graph_path(@project, @ref, q: @q, format: :json)}', commit_url: '#{project_commit_path(@project, 'ae45ca32').gsub("ae45ca32", "%s")}', ref: '#{@ref}', - commit_id: '#{@commit && @commit.id}' + commit_id: '#{@commit.id}' }); }); From df85c9c06ae3d687bb6ec2f2d11a8ae71fa8ed5f Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 14:59:13 +0900 Subject: [PATCH 05/23] Fix bug when it has been switched to tag. --- lib/extracts_path.rb | 5 ++++- lib/gitlab/graph/json_builder.rb | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/extracts_path.rb b/lib/extracts_path.rb index 976ac018..fb595e18 100644 --- a/lib/extracts_path.rb +++ b/lib/extracts_path.rb @@ -117,7 +117,10 @@ module ExtractsPath @id = File.join(@ref, @path) - @commit = CommitDecorator.decorate(@project.repository.commit(@ref)) + # It is used "@project.repository.commits(@ref, @path, 1, 0)", + # because "@project.repository.commit(@ref)" returns wrong commit when @ref is tag name. + commits = @project.repository.commits(@ref, @path, 1, 0) + @commit = CommitDecorator.decorate(commits.first) @tree = Tree.new(@commit.tree, @ref, @path) @tree = TreeDecorator.new(@tree) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 05e16f3d..8f31c820 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -113,7 +113,7 @@ module Gitlab def include_ref?(commit) heads = commit.refs.select do |ref| - ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) + ref.is_a?(Grit::Head) or ref.is_a?(Grit::Remote) or ref.is_a?(Grit::Tag) end heads.map! do |head| From 9dccecc9b54240a7088ceac554c3f9b6b24d51f7 Mon Sep 17 00:00:00 2001 From: Sato Hiroyuki Date: Tue, 5 Feb 2013 19:58:49 +0900 Subject: [PATCH 06/23] Sort the commits on network graph by commiter date. Author date is not updated, if the commits is rebased. So the network graph having many rebased commit turns round and round, that it is very difficult to undarstand history. --- lib/gitlab/graph/json_builder.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/graph/json_builder.rb b/lib/gitlab/graph/json_builder.rb index 8f31c820..cc971a24 100644 --- a/lib/gitlab/graph/json_builder.rb +++ b/lib/gitlab/graph/json_builder.rb @@ -33,7 +33,7 @@ module Gitlab # def collect_commits - @commits = Grit::Commit.find_all(repo, nil, {max_count: self.class.max_count, skip: to_commit}).dup + @commits = Grit::Commit.find_all(repo, nil, {topo_order: true, max_count: self.class.max_count, skip: to_commit}).dup # Decorate with app/models/commit.rb @commits.map! { |commit| ::Commit.new(commit) } @@ -86,7 +86,7 @@ module Gitlab # Skip count that the target commit is displayed in center. def to_commit - commits = Grit::Commit.find_all(repo, nil) + commits = Grit::Commit.find_all(repo, nil, {topo_order: true}) commit_index = commits.index do |c| c.id == @commit.id end From 1b4ba3eb99e30bded9bffea20c457af5e08a58f2 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Wed, 6 Feb 2013 12:44:09 +0100 Subject: [PATCH 07/23] Add user delete option. --- app/controllers/registrations_controller.rb | 11 +++++++++++ app/views/profiles/account.html.haml | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb index cbac7613..b7ee7561 100644 --- a/app/controllers/registrations_controller.rb +++ b/app/controllers/registrations_controller.rb @@ -1,6 +1,17 @@ class RegistrationsController < Devise::RegistrationsController before_filter :signup_enabled? + def destroy + if current_user.owned_projects.count > 0 + redirect_to account_profile_path, alert: "Remove projects and groups before removing account." and return + end + current_user.destroy + + respond_to do |format| + format.html { redirect_to new_user_session_path, notice: "Account successfully removed." } + end + end + private def signup_enabled? diff --git a/app/views/profiles/account.html.haml b/app/views/profiles/account.html.haml index 2ad000b8..9f81fc81 100644 --- a/app/views/profiles/account.html.haml +++ b/app/views/profiles/account.html.haml @@ -77,4 +77,10 @@ .input = f.submit 'Save username', class: "btn btn-save" - +- if Gitlab.config.gitlab.signup_enabled + %fieldset.update-username + %legend + Remove account + %small.cred.pull-right + Before removing the account you must remove all projects! + = link_to 'Delete account', user_registration_path, confirm: "REMOVE #{current_user.name}? Are you sure?", method: :delete, class: "btn btn-remove delete-key btn-small pull-right" \ No newline at end of file From 4ce3ef41deb59e5ff9da6f879c27d65677997477 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 6 Feb 2013 08:50:35 -0500 Subject: [PATCH 08/23] Disable autocomplete for admin/users form Fixes #2796 --- app/views/admin/users/_form.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index 51b05c05..f833c295 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -11,17 +11,17 @@ .clearfix = f.label :name .input - = f.text_field :name, required: true + = f.text_field :name, required: true, :autocomplete => "off" %span.help-inline * required .clearfix = f.label :username .input - = f.text_field :username, required: true + = f.text_field :username, required: true, :autocomplete => "off" %span.help-inline * required .clearfix = f.label :email .input - = f.text_field :email, required: true + = f.text_field :email, required: true, :autocomplete => "off" %span.help-inline * required %fieldset From c9777518e3455913389128a272e0c3e6c0a74d63 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 6 Feb 2013 09:26:46 -0500 Subject: [PATCH 09/23] Ruby 1.9 hash syntax --- app/views/admin/users/_form.html.haml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index f833c295..8684a902 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -11,17 +11,17 @@ .clearfix = f.label :name .input - = f.text_field :name, required: true, :autocomplete => "off" + = f.text_field :name, required: true, autocomplete: "off" %span.help-inline * required .clearfix = f.label :username .input - = f.text_field :username, required: true, :autocomplete => "off" + = f.text_field :username, required: true, autocomplete: "off" %span.help-inline * required .clearfix = f.label :email .input - = f.text_field :email, required: true, :autocomplete => "off" + = f.text_field :email, required: true, autocomplete:"off" %span.help-inline * required %fieldset From 6474797d1cc48d1a9fb0659b1b28cc27580558a1 Mon Sep 17 00:00:00 2001 From: Jon Evans Date: Wed, 6 Feb 2013 09:27:09 -0500 Subject: [PATCH 10/23] Update app/views/admin/users/_form.html.haml --- app/views/admin/users/_form.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/admin/users/_form.html.haml b/app/views/admin/users/_form.html.haml index 8684a902..48876338 100644 --- a/app/views/admin/users/_form.html.haml +++ b/app/views/admin/users/_form.html.haml @@ -21,7 +21,7 @@ .clearfix = f.label :email .input - = f.text_field :email, required: true, autocomplete:"off" + = f.text_field :email, required: true, autocomplete: "off" %span.help-inline * required %fieldset From 40e7846f3e25b7f679c9dda719c135fca1ef3d5b Mon Sep 17 00:00:00 2001 From: Sebastian Ziebell Date: Fri, 8 Feb 2013 17:04:08 +0100 Subject: [PATCH 11/23] Status code 404 returned when retrieving non existent branch (issue #2922) Accessing a repository branch that does not exist returns a 404 error instead of 200 now. Added a test. --- lib/api/projects.rb | 1 + spec/requests/api/projects_spec.rb | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/lib/api/projects.rb b/lib/api/projects.rb index a16243aa..5e4c564c 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -230,6 +230,7 @@ module Gitlab # GET /projects/:id/repository/branches/:branch get ":id/repository/branches/:branch" do @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } + error!("Branch does not exist", 404) if @branch.nil? present @branch, with: Entities::RepoObject, project: user_project end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index d932fd9e..16fd1b93 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -109,6 +109,11 @@ describe Gitlab::API do json_response['commit']['id'].should == '621491c677087aa243f165eab467bfdfbee00be1' json_response['protected'].should == false end + + it "should return a 404 error if branch is not available" do + get api("/projects/#{project.id}/repository/branches/unknown", user) + response.status.should == 404 + end end describe "PUT /projects/:id/repository/branches/:branch/protect" do From 2bd955961cdb6d0fa7e51e8fbb61581d6b101b05 Mon Sep 17 00:00:00 2001 From: Sebastian Ziebell Date: Sat, 9 Feb 2013 20:54:52 +0100 Subject: [PATCH 12/23] Changed function to `not_found`. Instead of using funtion `error!` the function `not_found!` is used to return 404 error. Adjusted documentation accordingly. --- doc/api/repositories.md | 3 +++ lib/api/projects.rb | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/doc/api/repositories.md b/doc/api/repositories.md index bc6ca70a..fd0ef1f5 100644 --- a/doc/api/repositories.md +++ b/doc/api/repositories.md @@ -79,6 +79,9 @@ Parameters: } ``` +Will return status code `200` on success or `404 Not found` if the branch is not available. + + ## Protect a project repository branch Protect a single project repository branch. diff --git a/lib/api/projects.rb b/lib/api/projects.rb index 5e4c564c..d416121a 100644 --- a/lib/api/projects.rb +++ b/lib/api/projects.rb @@ -230,7 +230,7 @@ module Gitlab # GET /projects/:id/repository/branches/:branch get ":id/repository/branches/:branch" do @branch = user_project.repo.heads.find { |item| item.name == params[:branch] } - error!("Branch does not exist", 404) if @branch.nil? + not_found!("Branch does not exist") if @branch.nil? present @branch, with: Entities::RepoObject, project: user_project end From f339af858b25cc32ac1bc0c46add29a6a3f43b51 Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 11 Feb 2013 13:06:37 +0100 Subject: [PATCH 13/23] Test the delete acount option. --- spec/requests/profile_spec.rb | 48 +++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 spec/requests/profile_spec.rb diff --git a/spec/requests/profile_spec.rb b/spec/requests/profile_spec.rb new file mode 100644 index 00000000..c18d8f92 --- /dev/null +++ b/spec/requests/profile_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe "Profile account page" do + let(:user) { create(:user) } + + before do + login_as :user + end + + describe "when signup is enabled" do + before do + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true) + visit account_profile_path + end + it { page.should have_content("Remove account") } + + it "should delete the account", js: true do + expect { click_link "Delete account" }.to change {User.count}.by(-1) + current_path.should == new_user_session_path + end + end + + describe "when signup is enabled and user has a project" do + before do + Gitlab.config.gitlab.stub(:signup_enabled).and_return(true) + @project = create(:project, namespace: @user.namespace) + @project.team << [@user, :master] + visit account_profile_path + end + it { page.should have_content("Remove account") } + + it "should not allow user to delete the account" do + expect { click_link "Delete account" }.not_to change {User.count}.by(-1) + end + end + + describe "when signup is disabled" do + before do + Gitlab.config.gitlab.stub(:signup_enabled).and_return(false) + visit account_profile_path + end + + it "should not have option to remove account" do + page.should_not have_content("Remove account") + current_path.should == account_profile_path + end + end +end \ No newline at end of file From 483f720861e7aa018b581dce7bb52d4650405edf Mon Sep 17 00:00:00 2001 From: Marin Jankovski Date: Mon, 11 Feb 2013 13:12:41 +0100 Subject: [PATCH 14/23] UPdate field name. --- app/views/profiles/account.html.haml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/profiles/account.html.haml b/app/views/profiles/account.html.haml index 9f81fc81..5465d1f9 100644 --- a/app/views/profiles/account.html.haml +++ b/app/views/profiles/account.html.haml @@ -78,7 +78,7 @@ = f.submit 'Save username', class: "btn btn-save" - if Gitlab.config.gitlab.signup_enabled - %fieldset.update-username + %fieldset.remove-account %legend Remove account %small.cred.pull-right From 9a22ac63eca587d5efd56d626b7579236734cda0 Mon Sep 17 00:00:00 2001 From: Andrew8xx8 Date: Tue, 12 Feb 2013 10:54:56 +0400 Subject: [PATCH 15/23] Dynamic values must be in blocks if FG --- spec/factories.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/factories.rb b/spec/factories.rb index 0e0c04f9..ae9066cb 100644 --- a/spec/factories.rb +++ b/spec/factories.rb @@ -123,7 +123,7 @@ FactoryGirl.define do factory :event do factory :closed_issue_event do project - action Event::Closed + action { Event::Closed } target factory: :closed_issue author factory: :user end From b5db541338314b01423d79fb9155e8c4ddc5d494 Mon Sep 17 00:00:00 2001 From: Andrew8xx8 Date: Tue, 12 Feb 2013 11:16:45 +0400 Subject: [PATCH 16/23] All scopes must be in lambdas --- app/models/concerns/issuable.rb | 6 +++--- app/models/event.rb | 4 ++-- app/models/milestone.rb | 4 ++-- app/models/namespace.rb | 2 +- app/models/note.rb | 4 ++-- app/models/project.rb | 2 +- app/models/snippet.rb | 6 +++--- app/models/user.rb | 8 ++++---- app/models/users_project.rb | 8 ++++---- 9 files changed, 22 insertions(+), 22 deletions(-) diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index 8872cf59..645b35ec 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -19,12 +19,12 @@ module Issuable validates :title, presence: true, length: { within: 0..255 } validates :closed, inclusion: { in: [true, false] } - scope :opened, where(closed: false) - scope :closed, where(closed: true) + scope :opened, -> { where(closed: false) } + scope :closed, -> { where(closed: true) } scope :of_group, ->(group) { where(project_id: group.project_ids) } scope :of_user_team, ->(team) { where(project_id: team.project_ids, assignee_id: team.member_ids) } scope :assigned, ->(u) { where(assignee_id: u.id)} - scope :recent, order("created_at DESC") + scope :recent, -> { order("created_at DESC") } delegate :name, :email, diff --git a/app/models/event.rb b/app/models/event.rb index d0ba6154..97b1e330 100644 --- a/app/models/event.rb +++ b/app/models/event.rb @@ -42,8 +42,8 @@ class Event < ActiveRecord::Base serialize :data # Scopes - scope :recent, order("created_at DESC") - scope :code_push, where(action: Pushed) + scope :recent, -> { order("created_at DESC") } + scope :code_push, -> { where(action: Pushed) } scope :in_projects, ->(project_ids) { where(project_id: project_ids).recent } class << self diff --git a/app/models/milestone.rb b/app/models/milestone.rb index 8b4c895d..457fe18f 100644 --- a/app/models/milestone.rb +++ b/app/models/milestone.rb @@ -20,8 +20,8 @@ class Milestone < ActiveRecord::Base has_many :issues has_many :merge_requests - scope :active, where(closed: false) - scope :closed, where(closed: true) + scope :active, -> { where(closed: false) } + scope :closed, -> { where(closed: true) } validates :title, presence: true validates :project, presence: true diff --git a/app/models/namespace.rb b/app/models/namespace.rb index 547d383d..4e157839 100644 --- a/app/models/namespace.rb +++ b/app/models/namespace.rb @@ -29,7 +29,7 @@ class Namespace < ActiveRecord::Base after_update :move_dir after_destroy :rm_dir - scope :root, where('type IS NULL') + scope :root, -> { where('type IS NULL') } def self.search query where("name LIKE :query OR path LIKE :query", query: "%#{query}%") diff --git a/app/models/note.rb b/app/models/note.rb index ded126b4..97f6bf6e 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -43,8 +43,8 @@ class Note < ActiveRecord::Base # Scopes scope :for_commit_id, ->(commit_id) { where(noteable_type: "Commit", commit_id: commit_id) } - scope :inline, where("line_code IS NOT NULL") - scope :not_inline, where("line_code IS NULL") + scope :inline, -> { where("line_code IS NOT NULL") } + scope :not_inline, -> { where("line_code IS NULL") } scope :common, ->{ where(noteable_type: ["", nil]) } scope :fresh, ->{ order("created_at ASC, id ASC") } diff --git a/app/models/project.rb b/app/models/project.rb index 8c747743..c1e04899 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -91,7 +91,7 @@ class Project < ActiveRecord::Base scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } - scope :public, where(public: true) + scope :public, -> { where(public: true) } class << self def abandoned diff --git a/app/models/snippet.rb b/app/models/snippet.rb index 806d346c..c4ee35e0 100644 --- a/app/models/snippet.rb +++ b/app/models/snippet.rb @@ -31,9 +31,9 @@ class Snippet < ActiveRecord::Base validates :content, presence: true # Scopes - scope :fresh, order("created_at DESC") - scope :non_expired, where(["expires_at IS NULL OR expires_at > ?", Time.current]) - scope :expired, where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) + scope :fresh, -> { order("created_at DESC") } + scope :non_expired, -> { where(["expires_at IS NULL OR expires_at > ?", Time.current]) } + scope :expired, -> { where(["expires_at IS NOT NULL AND expires_at < ?", Time.current]) } def self.content_types [ diff --git a/app/models/user.rb b/app/models/user.rb index 5b0df09a..8c1a8b42 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -87,10 +87,10 @@ class User < ActiveRecord::Base delegate :path, to: :namespace, allow_nil: true, prefix: true # Scopes - scope :admins, where(admin: true) - scope :blocked, where(blocked: true) - scope :active, where(blocked: false) - scope :alphabetically, order('name ASC') + scope :admins, -> { where(admin: true) } + scope :blocked, -> { where(blocked: true) } + scope :active, -> { where(blocked: false) } + scope :alphabetically, -> { order('name ASC') } scope :in_team, ->(team){ where(id: team.member_ids) } scope :not_in_team, ->(team){ where('users.id NOT IN (:ids)', ids: team.member_ids) } scope :potential_team_members, ->(team) { team.members.any? ? active.not_in_team(team) : active } diff --git a/app/models/users_project.rb b/app/models/users_project.rb index dd8ceb9d..486aaa69 100644 --- a/app/models/users_project.rb +++ b/app/models/users_project.rb @@ -32,10 +32,10 @@ class UsersProject < ActiveRecord::Base delegate :name, :username, :email, to: :user, prefix: true - scope :guests, where(project_access: GUEST) - scope :reporters, where(project_access: REPORTER) - scope :developers, where(project_access: DEVELOPER) - scope :masters, where(project_access: MASTER) + scope :guests, -> { where(project_access: GUEST) } + scope :reporters, -> { where(project_access: REPORTER) } + scope :developers, -> { where(project_access: DEVELOPER) } + scope :masters, -> { where(project_access: MASTER) } scope :in_project, ->(project) { where(project_id: project.id) } scope :in_projects, ->(projects) { where(project_id: project_ids) } From 918e2213e71cb1a6c0cc7fd4249c51db90a2614c Mon Sep 17 00:00:00 2001 From: Yuri Feldman Date: Tue, 12 Feb 2013 18:56:53 +1100 Subject: [PATCH 17/23] Test to show incorrect routing to Compare controller --- spec/routing/project_routing_spec.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/routing/project_routing_spec.rb b/spec/routing/project_routing_spec.rb index f94bedc7..9cf5d913 100644 --- a/spec/routing/project_routing_spec.rb +++ b/spec/routing/project_routing_spec.rb @@ -392,6 +392,7 @@ end describe BlobController, "routing" do it "to #show" do get("/gitlabhq/blob/master/app/models/project.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/project.rb') + get("/gitlabhq/blob/master/app/models/compare.rb").should route_to('blob#show', project_id: 'gitlabhq', id: 'master/app/models/compare.rb') end end From 2d0c3e4c6dff291aa85e8bda18b8ac85e92c1994 Mon Sep 17 00:00:00 2001 From: Yuri Feldman Date: Tue, 12 Feb 2013 19:26:42 +1100 Subject: [PATCH 18/23] Fix for incorrect routing to the Compare controller --- config/routes.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/routes.rb b/config/routes.rb index 47c8a412..88667db1 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -166,12 +166,12 @@ Gitlab::Application.routes.draw do get "files" end + resources :blob, only: [:show], constraints: {id: /.+/} resources :tree, only: [:show, :edit, :update], constraints: {id: /.+/} resources :commit, only: [:show], constraints: {id: /[[:alnum:]]{6,40}/} resources :commits, only: [:show], constraints: {id: /.+/} resources :compare, only: [:index, :create] resources :blame, only: [:show], constraints: {id: /.+/} - resources :blob, only: [:show], constraints: {id: /.+/} resources :graph, only: [:show], constraints: {id: /.+/} match "/compare/:from...:to" => "compare#show", as: "compare", :via => [:get, :post], constraints: {from: /.+/, to: /.+/} From 806b76a168536ef05b20c5449f19164ea149583f Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 12 Feb 2013 11:46:50 +0200 Subject: [PATCH 19/23] rename scope to prevent name collision --- app/controllers/public/projects_controller.rb | 2 +- app/models/project.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/controllers/public/projects_controller.rb b/app/controllers/public/projects_controller.rb index 4108fe5f..b929b23e 100644 --- a/app/controllers/public/projects_controller.rb +++ b/app/controllers/public/projects_controller.rb @@ -6,7 +6,7 @@ class Public::ProjectsController < ApplicationController layout 'public' def index - @projects = Project.public + @projects = Project.public_only @projects = @projects.includes(:namespace).order("namespaces.path, projects.name ASC").page(params[:page]).per(20) end end diff --git a/app/models/project.rb b/app/models/project.rb index c1e04899..acc1b8d2 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -91,7 +91,7 @@ class Project < ActiveRecord::Base scope :sorted_by_activity, ->() { order("(SELECT max(events.created_at) FROM events WHERE events.project_id = projects.id) DESC") } scope :personal, ->(user) { where(namespace_id: user.namespace_id) } scope :joined, ->(user) { where("namespace_id != ?", user.namespace_id) } - scope :public, -> { where(public: true) } + scope :public_only, -> { where(public: true) } class << self def abandoned From 4c0c90865502e5a1c22933e51e53a1625d0bd61a Mon Sep 17 00:00:00 2001 From: Michael Lee Date: Tue, 12 Feb 2013 23:01:55 +0800 Subject: [PATCH 20/23] Update lib/tasks/sidekiq.rake Mac OS uses launchd instead of /etc/init.d to start daemons and tasks to be started by launchd MUST NOT daemon itself. So "nohup" here won't work for Mac OS. Can we add a "launchd" task to the rake file so that we can start sidekiq as "bundle exec rake sidekiq:launchd" ? --- lib/tasks/sidekiq.rake | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/lib/tasks/sidekiq.rake b/lib/tasks/sidekiq.rake index 67e8daaf..cf99951e 100644 --- a/lib/tasks/sidekiq.rake +++ b/lib/tasks/sidekiq.rake @@ -8,7 +8,12 @@ namespace :sidekiq do task :start do run "nohup bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1 &" end - + + desc "GITLAB | Start sidekiq with launchd on Mac OS X" + task :launchd do + run "bundle exec sidekiq -q post_receive,mailer,system_hook,project_web_hook,gitlab_shell,common,default -e #{Rails.env} -P #{pidfile} >> #{Rails.root.join("log", "sidekiq.log")} 2>&1" + end + def pidfile Rails.root.join("tmp", "pids", "sidekiq.pid") end From 622dae76cc0e9e3c76c5d2ba18efeb139644881e Mon Sep 17 00:00:00 2001 From: Dmitriy Zaporozhets Date: Tue, 12 Feb 2013 19:22:40 +0200 Subject: [PATCH 21/23] style network graph form a bit --- .../stylesheets/gitlab_bootstrap/common.scss | 1 + app/views/graph/_head.html.haml | 23 ++++++++++++------- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/app/assets/stylesheets/gitlab_bootstrap/common.scss b/app/assets/stylesheets/gitlab_bootstrap/common.scss index cb292bc7..dcfd610e 100644 --- a/app/assets/stylesheets/gitlab_bootstrap/common.scss +++ b/app/assets/stylesheets/gitlab_bootstrap/common.scss @@ -20,6 +20,7 @@ .hint { font-style: italic; color: #999; } .light { color: #888 } .tiny { font-weight: normal } +.vtop { vertical-align: top; } /** ALERT MESSAGES **/ diff --git a/app/views/graph/_head.html.haml b/app/views/graph/_head.html.haml index 7e1b4644..fba9a958 100644 --- a/app/views/graph/_head.html.haml +++ b/app/views/graph/_head.html.haml @@ -1,9 +1,16 @@ -%ul.nav.nav-tabs - %li - = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} - %li.pull-right.search - = form_tag project_graph_path(@project, params[:id]), method: :get, class: 'navbar-form' do |f| - = label_tag :search , "Looking for commit:" - = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input" - %h3.page_title Project Network Graph +%hr + +.clearfix + .pull-left + = render partial: 'shared/ref_switcher', locals: {destination: 'graph', path: @path} + + .search.pull-right + = form_tag project_graph_path(@project, params[:id]), method: :get do |f| + .control-group + = label_tag :search , "Looking for commit:", class: 'control-label light' + .controls + = text_field_tag :q, @q, placeholder: "Input SHA", class: "search-input xlarge" + = button_tag type: 'submit', class: 'btn vtop' do + %i.icon-search + From 6b96ca47e036759aa9f3c636b2f0e32ac36651c8 Mon Sep 17 00:00:00 2001 From: Martin Bastien Date: Tue, 12 Feb 2013 12:42:36 -0500 Subject: [PATCH 22/23] Some fix for gitlab:gitlab_shell:check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixing issue #2970 --- lib/tasks/gitlab/check.rake | 45 +++++++++++++------------------------ 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 4e252f02..3caa1dce 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -311,7 +311,7 @@ namespace :gitlab do "Remove \"-e \" so the line starts with PATH" ) for_more_information( - see_installation_guide_section("Gitolite"), + see_installation_guide_section("Gitlab Shell"), "https://github.com/gitlabhq/gitlabhq/issues/1059" ) fix_and_rerun @@ -368,10 +368,10 @@ namespace :gitlab do namespace :gitlab_shell do - desc "GITLAB | Check the configuration of Gitolite" + desc "GITLAB | Check the configuration of Gitlab Shell" task check: :environment do warn_user_is_not_gitlab - start_checking "Gitolite" + start_checking "Gitlab Shell" check_repo_base_exists check_repo_base_is_not_symlink @@ -380,7 +380,7 @@ namespace :gitlab do check_post_receive_hook_is_up_to_date check_repos_post_receive_hooks_is_link - finished_checking "Gitolite" + finished_checking "Gitlab Shell" end @@ -392,7 +392,7 @@ namespace :gitlab do print "post-receive hook up-to-date? ... " hook_file = "post-receive" - gitlab_shell_hooks_path = File.join(Gitlab.config.gitlab_shell.hooks_path, "common") + gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user @@ -401,22 +401,7 @@ namespace :gitlab do return end - gitlab_shell_hook_content = File.read(gitlab_shell_hook_file) - gitlab_hook_file = Rails.root.join.join("lib", "hooks", hook_file) - gitlab_hook_content = File.read(gitlab_hook_file) - - if gitlab_shell_hook_content == gitlab_hook_content - puts "yes".green - else - puts "no".red - try_fixing_it( - "sudo -u #{gitlab_shell_ssh_user} cp #{gitlab_hook_file} #{gitlab_shell_hook_file}" - ) - for_more_information( - see_installation_guide_section "Setup GitLab Hooks" - ) - fix_and_rerun - end + puts "yes".green end def check_repo_base_exists @@ -430,12 +415,12 @@ namespace :gitlab do puts "no".red puts "#{repo_base_path} is missing".red try_fixing_it( - "This should have been created when setting up Gitolite.", + "This should have been created when setting up Gitlab Shell.", "Make sure it's set correctly in config/gitlab.yml", - "Make sure Gitolite is installed correctly." + "Make sure Gitlab Shell is installed correctly." ) for_more_information( - see_installation_guide_section "Gitolite" + see_installation_guide_section "Gitlab Shell" ) fix_and_rerun end @@ -480,7 +465,7 @@ namespace :gitlab do "find #{repo_base_path} -type d -print0 | sudo xargs -0 chmod g+s" ) for_more_information( - see_installation_guide_section "Gitolite" + see_installation_guide_section "Gitlab Shell" ) fix_and_rerun end @@ -506,7 +491,7 @@ namespace :gitlab do "sudo chown -R #{gitlab_shell_ssh_user}:#{gitlab_shell_owner_group} #{repo_base_path}" ) for_more_information( - see_installation_guide_section "Gitolite" + see_installation_guide_section "Gitlab Shell" ) fix_and_rerun end @@ -516,7 +501,7 @@ namespace :gitlab do print "post-receive hooks in repos are links: ... " hook_file = "post-receive" - gitlab_shell_hooks_path = File.join(Gitlab.config.gitlab_shell.hooks_path, "common") + gitlab_shell_hooks_path = Gitlab.config.gitlab_shell.hooks_path gitlab_shell_hook_file = File.join(gitlab_shell_hooks_path, hook_file) gitlab_shell_ssh_user = Gitlab.config.gitlab_shell.ssh_user @@ -545,7 +530,7 @@ namespace :gitlab do "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( - "lib/support/rewrite-hooks.sh" + "#{gitlab_shell_user_home}/support/rewrite-hooks.sh" ) fix_and_rerun next @@ -555,7 +540,7 @@ namespace :gitlab do File.realpath(project_hook_file) == File.realpath(gitlab_shell_hook_file) puts "ok".green else - puts "not a link to Gitolite's hook".red + puts "not a link to Gitlab Shell's hook".red try_fixing_it( "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) @@ -577,7 +562,7 @@ namespace :gitlab do end def gitlab_shell_version - gitlab_shell_version_file = "#{gitlab_shell_user_home}/gitlab_shell/src/VERSION" + gitlab_shell_version_file = "#{gitlab_shell_user_home}/VERSION" if File.readable?(gitlab_shell_version_file) File.read(gitlab_shell_version_file) end From 8353bd8ee320bebe955582af2122b7a0683e53c9 Mon Sep 17 00:00:00 2001 From: Martin Bastien Date: Tue, 12 Feb 2013 12:49:11 -0500 Subject: [PATCH 23/23] Forgot gitlab-shell folder --- lib/tasks/gitlab/check.rake | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index 3caa1dce..6a138396 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -530,7 +530,7 @@ namespace :gitlab do "sudo -u #{gitlab_shell_ssh_user} ln -sf #{gitlab_shell_hook_file} #{project_hook_file}" ) for_more_information( - "#{gitlab_shell_user_home}/support/rewrite-hooks.sh" + "#{gitlab_shell_user_home}/gitlab-shell/support/rewrite-hooks.sh" ) fix_and_rerun next @@ -562,7 +562,7 @@ namespace :gitlab do end def gitlab_shell_version - gitlab_shell_version_file = "#{gitlab_shell_user_home}/VERSION" + gitlab_shell_version_file = "#{gitlab_shell_user_home}/gitlab-shell/VERSION" if File.readable?(gitlab_shell_version_file) File.read(gitlab_shell_version_file) end