From 8f75ab21d021fb5335ed9e084157cf2bc06caca1 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 9 May 2015 22:25:46 +0200 Subject: [PATCH 1/8] Link Commits tab to current branch from Compare page. --- app/controllers/projects/compare_controller.rb | 3 ++- app/views/projects/commits/_head.html.haml | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/controllers/projects/compare_controller.rb b/app/controllers/projects/compare_controller.rb index 7c20b81c0b..c5f085c236 100644 --- a/app/controllers/projects/compare_controller.rb +++ b/app/controllers/projects/compare_controller.rb @@ -6,11 +6,12 @@ class Projects::CompareController < Projects::ApplicationController before_action :authorize_download_code! def index + @ref = Addressable::URI.unescape(params[:to]) end def show base_ref = Addressable::URI.unescape(params[:from]) - head_ref = Addressable::URI.unescape(params[:to]) + @ref = head_ref = Addressable::URI.unescape(params[:to]) compare_result = CompareService.new.execute( current_user, diff --git a/app/views/projects/commits/_head.html.haml b/app/views/projects/commits/_head.html.haml index a714f5f79e..66101f3f0d 100644 --- a/app/views/projects/commits/_head.html.haml +++ b/app/views/projects/commits/_head.html.haml @@ -1,6 +1,6 @@ %ul.nav.nav-tabs = nav_link(controller: [:commit, :commits]) do - = link_to namespace_project_commits_path(@project.namespace, @project, @repository.root_ref) do + = link_to namespace_project_commits_path(@project.namespace, @project, @ref || @repository.root_ref) do Commits %span.badge= number_with_precision(@repository.commit_count, precision: 0, delimiter: ',') = nav_link(controller: :compare) do From 722e3935893e0493e5783f1a61034fe1481f8cb8 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 9 May 2015 22:26:25 +0200 Subject: [PATCH 2/8] Add Create Merge Request buttons to commits page and push event. --- CHANGELOG | 1 + app/helpers/compare_helper.rb | 24 +++++++++++----------- app/views/events/event/_push.html.haml | 14 ++++++++++++- app/views/projects/commits/show.html.haml | 16 ++++++++++----- app/views/projects/compare/_form.html.haml | 7 ++++--- 5 files changed, 41 insertions(+), 21 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 3206c625cd..2303282f0a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,6 +49,7 @@ v 7.11.0 (unreleased) - Add footnotes support to Markdown (Guillaume Delbergue) - Add current_sign_in_at to UserFull REST api. - Make Sidekiq MemoryKiller shutdown signal configurable + - Add "Create Merge Request" buttons to commits page and push event. v 7.10.2 - Fix CI links on MR page diff --git a/app/helpers/compare_helper.rb b/app/helpers/compare_helper.rb index 01847c6b80..fe339d3215 100644 --- a/app/helpers/compare_helper.rb +++ b/app/helpers/compare_helper.rb @@ -1,21 +1,21 @@ module CompareHelper - def compare_to_mr_button? - @project.merge_requests_enabled && - params[:from].present? && - params[:to].present? && - @repository.branch_names.include?(params[:from]) && - @repository.branch_names.include?(params[:to]) && - params[:from] != params[:to] && + def create_mr_button?(from = params[:from], to = params[:to], project = @project) + project.merge_requests_enabled && + from.present? && + to.present? && + project.repository.branch_names.include?(from) && + project.repository.branch_names.include?(to) && + from != to && !@refs_are_same end - def compare_mr_path + def create_mr_path(from = params[:from], to = params[:to], project = @project) new_namespace_project_merge_request_path( - @project.namespace, - @project, + project.namespace, + project, merge_request: { - source_branch: params[:to], - target_branch: params[:from] + source_branch: to, + target_branch: from } ) end diff --git a/app/views/events/event/_push.html.haml b/app/views/events/event/_push.html.haml index 60d7978b13..1da702be38 100644 --- a/app/views/events/event/_push.html.haml +++ b/app/views/events/event/_push.html.haml @@ -17,15 +17,27 @@ - few_commits.each do |commit| = render "events/commit", commit: commit, project: project + - create_mr = current_user == event.author && event.new_ref? && create_mr_button?(event.project.default_branch, event.ref_name, event.project) - if event.commits_count > 1 %li.commits-stat - if event.commits_count > 2 %span ... and #{event.commits_count - 2} more commits. + - if event.md_ref? - from = event.commit_from - from_label = truncate_sha(from) - else - from = event.project.default_branch - from_label = from + = link_to namespace_project_compare_path(event.project.namespace, event.project, from: from, to: event.commit_to) do - %strong Compare → #{from_label}...#{truncate_sha(event.commit_to)} + Compare #{from_label}...#{truncate_sha(event.commit_to)} + + - if create_mr + or + = link_to create_mr_path(event.project.default_branch, event.ref_name, event.project) do + create a merge request + - elsif create_mr + %li.commits-stat + = link_to create_mr_path(event.project.default_branch, event.ref_name, event.project) do + Create Merge Request diff --git a/app/views/projects/commits/show.html.haml b/app/views/projects/commits/show.html.haml index c8531b090a..e2a8d3ffbb 100644 --- a/app/views/projects/commits/show.html.haml +++ b/app/views/projects/commits/show.html.haml @@ -8,11 +8,17 @@ .tree-ref-holder = render 'shared/ref_switcher', destination: 'commits' -- if current_user && current_user.private_token - .commits-feed-holder.hidden-xs.hidden-sm - = link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Feed", class: 'btn' do - %i.fa.fa-rss - Commits feed +.commits-feed-holder.hidden-xs.hidden-sm + - if create_mr_button?(@repository.root_ref, @ref) + = link_to create_mr_path(@repository.root_ref, @ref), class: 'btn btn-success' do + = icon('plus') + Create Merge Request + + - if current_user && current_user.private_token + = link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Feed", class: 'prepend-left-10 btn' do + = icon("rss") + Commits Feed + %ul.breadcrumb.repo-breadcrumb = commits_breadcrumbs diff --git a/app/views/projects/compare/_form.html.haml b/app/views/projects/compare/_form.html.haml index dfb1dded9e..a0e904cfd8 100644 --- a/app/views/projects/compare/_form.html.haml +++ b/app/views/projects/compare/_form.html.haml @@ -13,9 +13,10 @@ = text_field_tag :to, params[:to], class: "form-control"   = button_tag "Compare", class: "btn btn-create commits-compare-btn" - - if compare_to_mr_button? - = link_to compare_mr_path, class: 'prepend-left-10 btn' do - %strong Make a merge request + - if create_mr_button? + = link_to create_mr_path, class: 'prepend-left-10 btn' do + = icon("plus") + Create Merge Request :javascript From 164d47448831f64c1bb3e193172a2e9fcbb84712 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 9 May 2015 22:55:19 +0200 Subject: [PATCH 3/8] Add Merge Request button to branches page. --- CHANGELOG | 2 +- app/views/projects/branches/_branch.html.haml | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2303282f0a..f069fd30d9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -49,7 +49,7 @@ v 7.11.0 (unreleased) - Add footnotes support to Markdown (Guillaume Delbergue) - Add current_sign_in_at to UserFull REST api. - Make Sidekiq MemoryKiller shutdown signal configurable - - Add "Create Merge Request" buttons to commits page and push event. + - Add "Create Merge Request" buttons to commits and branches pages and push event. v 7.10.2 - Fix CI links on MR page diff --git a/app/views/projects/branches/_branch.html.haml b/app/views/projects/branches/_branch.html.haml index 4e7415be4a..43412624da 100644 --- a/app/views/projects/branches/_branch.html.haml +++ b/app/views/projects/branches/_branch.html.haml @@ -10,16 +10,19 @@ %i.fa.fa-lock protected .pull-right - - if can?(current_user, :download_code, @project) - = render 'projects/repositories/download_archive', ref: branch.name, btn_class: 'btn-grouped btn-group-xs' + - if create_mr_button?(@repository.root_ref, branch.name) + = link_to create_mr_path(@repository.root_ref, branch.name), class: 'btn btn-grouped btn-xs' do + = icon('plus') + Merge Request + - if branch.name != @repository.root_ref = link_to namespace_project_compare_index_path(@project.namespace, @project, from: @repository.root_ref, to: branch.name), class: 'btn btn-grouped btn-xs', method: :post, title: "Compare" do - %i.fa.fa-files-o + = icon("exchange") Compare - if can_remove_branch?(@project, branch.name) = link_to namespace_project_branch_path(@project.namespace, @project, branch.name), class: 'btn btn-grouped btn-xs btn-remove remove-row', method: :delete, data: { confirm: 'Removed branch cannot be restored. Are you sure?'}, remote: true do - %i.fa.fa-trash-o + = icon("trash-o") - if commit %ul.list-unstyled From e80c4447a82553d74267f327060b96807c2e5c0c Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 9 May 2015 23:50:51 +0200 Subject: [PATCH 4/8] Fix spec. --- features/steps/project/commits/commits.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/steps/project/commits/commits.rb b/features/steps/project/commits/commits.rb index 30b1934b36..c888e82e20 100644 --- a/features/steps/project/commits/commits.rb +++ b/features/steps/project/commits/commits.rb @@ -12,7 +12,7 @@ class Spinach::Features::ProjectCommits < Spinach::FeatureSteps end step 'I click atom feed link' do - click_link "Feed" + click_link "Commits Feed" end step 'I see commits atom feed' do From a3edd473b936de0be841c003506a41e0ff941b9e Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sat, 9 May 2015 23:51:50 +0200 Subject: [PATCH 5/8] Improve create_mr_button? performance. --- app/helpers/compare_helper.rb | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/app/helpers/compare_helper.rb b/app/helpers/compare_helper.rb index fe339d3215..f1dc906cab 100644 --- a/app/helpers/compare_helper.rb +++ b/app/helpers/compare_helper.rb @@ -1,12 +1,11 @@ module CompareHelper def create_mr_button?(from = params[:from], to = params[:to], project = @project) - project.merge_requests_enabled && - from.present? && + from.present? && to.present? && - project.repository.branch_names.include?(from) && - project.repository.branch_names.include?(to) && from != to && - !@refs_are_same + project.merge_requests_enabled && + project.repository.branch_names.include?(from) && + project.repository.branch_names.include?(to) end def create_mr_path(from = params[:from], to = params[:to], project = @project) From aa4d19904418cf57369ab9c80d05730c03636baf Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Sun, 10 May 2015 00:39:20 +0200 Subject: [PATCH 6/8] Fix commits feed button. --- app/views/projects/commits/show.html.haml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/app/views/projects/commits/show.html.haml b/app/views/projects/commits/show.html.haml index e2a8d3ffbb..9682100a54 100644 --- a/app/views/projects/commits/show.html.haml +++ b/app/views/projects/commits/show.html.haml @@ -14,10 +14,10 @@ = icon('plus') Create Merge Request - - if current_user && current_user.private_token - = link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Feed", class: 'prepend-left-10 btn' do - = icon("rss") - Commits Feed + - if current_user && current_user.private_token + = link_to namespace_project_commits_path(@project.namespace, @project, @ref, {format: :atom, private_token: current_user.private_token}), title: "Feed", class: 'prepend-left-10 btn' do + = icon("rss") + Commits Feed %ul.breadcrumb.repo-breadcrumb From 783b286ac0ca43033d7b64e360ca6f1aeeafc0d0 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 11 May 2015 11:55:02 +0200 Subject: [PATCH 7/8] Don't symbolize params. --- app/controllers/uploads_controller.rb | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/app/controllers/uploads_controller.rb b/app/controllers/uploads_controller.rb index 17edff68be..28536e359e 100644 --- a/app/controllers/uploads_controller.rb +++ b/app/controllers/uploads_controller.rb @@ -52,13 +52,13 @@ class UploadsController < ApplicationController def upload_model upload_models = { - user: User, - project: Project, - note: Note, - group: Group + "user" => User, + "project" => Project, + "note" => Note, + "group" => Group } - upload_models[params[:model].to_sym] + upload_models[params[:model]] end def upload_mount From 881e11df1be593e1943fa430e5a402f672aeba45 Mon Sep 17 00:00:00 2001 From: Sytse Sijbrandij Date: Mon, 11 May 2015 14:48:39 +0000 Subject: [PATCH 8/8] Small improvements to style guide. --- doc/development/migration_style_guide.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/doc/development/migration_style_guide.md b/doc/development/migration_style_guide.md index db2d8b9972..a102d7987d 100644 --- a/doc/development/migration_style_guide.md +++ b/doc/development/migration_style_guide.md @@ -1,17 +1,20 @@ # Migration Style Guide When writing migrations for GitLab, you have to take into account that -these will be ran by thousands of organizations of all sizes, some with +these will be ran by hundreds of thousands of organizations of all sizes, some with many years of data in their database. In addition, having to take a server offline for a an upgrade small or big is a big burden for most organizations. For this reason it is important that your -migrations are written carefully and adhere to the style guide below. +migrations are written carefully, can be applied online and adhere to the style guide below. When writing your migrations, also consider that databases might have stale data or inconsistencies and guard for that. Try to make as little assumptions as possible about the state of the database. +Please don't depend on GitLab specific code since it can change in future versions. +If needed copy-paste GitLab code into the migration to make make it forward compatible. + ## Comments in the migration Each migration you write needs to have the two following pieces of information @@ -36,4 +39,4 @@ Your migration should be reversible. This is very important, as it should be possible to downgrade in case of a vulnerability or bugs. In your migration, add a comment describing how the reversibility of the -migration was tested. +migration was tested. \ No newline at end of file