From c55685d265b628d457fc065df2559fc89996cef9 Mon Sep 17 00:00:00 2001 From: Alexander Tanayno Date: Wed, 18 Apr 2018 12:04:40 +0000 Subject: add restart of gitlab-pages to apply gitlab pages settings --- doc/administration/pages/index.md | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/doc/administration/pages/index.md b/doc/administration/pages/index.md index 00c631fdaae..c342a82ef7b 100644 --- a/doc/administration/pages/index.md +++ b/doc/administration/pages/index.md @@ -124,6 +124,12 @@ The Pages daemon doesn't listen to the outside world. ``` 1. [Reconfigure GitLab][reconfigure] +1. Restart gitlab-pages by running the following command: + + ```ruby + sudo gitlab-ctl restart gitlab-pages + ``` + Watch the [video tutorial][video-admin] for this configuration. @@ -155,6 +161,11 @@ outside world. respectively. 1. [Reconfigure GitLab][reconfigure] +1. Restart gitlab-pages by running the following command: + + ```ruby + sudo gitlab-ctl restart gitlab-pages + ``` ## Advanced configuration @@ -192,6 +203,11 @@ world. Custom domains are supported, but no TLS. listens on. If you don't have IPv6, you can omit the IPv6 address. 1. [Reconfigure GitLab][reconfigure] +1. Restart gitlab-pages by running the following command: + + ```ruby + sudo gitlab-ctl restart gitlab-pages + ``` ### Custom domains with TLS support @@ -225,6 +241,11 @@ world. Custom domains and TLS are supported. listens on. If you don't have IPv6, you can omit the IPv6 address. 1. [Reconfigure GitLab][reconfigure] +1. Restart gitlab-pages by running the following command: + + ```ruby + sudo gitlab-ctl restart gitlab-pages + ``` ### Custom domain verification @@ -252,6 +273,11 @@ are stored. ``` 1. [Reconfigure GitLab][reconfigure] +1. Restart gitlab-pages by running the following command: + + ```ruby + sudo gitlab-ctl restart gitlab-pages + ``` ## Set maximum pages size -- cgit v1.2.3 From 5a29a304be5fc86a5bbe61764c47cdd8069e2103 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Thu, 5 Apr 2018 17:17:02 +0200 Subject: Shows new branch/mr button even when branch exists --- .../javascripts/create_merge_request_dropdown.js | 33 +++++++----- app/controllers/projects/issues_controller.rb | 6 +-- app/models/issue.rb | 16 ++++-- .../unreleased/42803-show-new-branch-mr-button.yml | 5 ++ spec/javascripts/issue_spec.js | 1 + spec/models/issue_spec.rb | 63 ++++++++++++++++++++++ 6 files changed, 104 insertions(+), 20 deletions(-) create mode 100644 changelogs/unreleased/42803-show-new-branch-mr-button.yml diff --git a/app/assets/javascripts/create_merge_request_dropdown.js b/app/assets/javascripts/create_merge_request_dropdown.js index fb1fc9cd32e..a88b6971f90 100644 --- a/app/assets/javascripts/create_merge_request_dropdown.js +++ b/app/assets/javascripts/create_merge_request_dropdown.js @@ -84,20 +84,21 @@ export default class CreateMergeRequestDropdown { if (data.can_create_branch) { this.available(); this.enable(); + this.updateBranchName(data.suggested_branch_name); if (!this.droplabInitialized) { this.droplabInitialized = true; this.initDroplab(); this.bindEvents(); } - } else if (data.has_related_branch) { + } else { this.hide(); } }) .catch(() => { this.unavailable(); this.disable(); - Flash('Failed to check if a new branch can be created.'); + Flash(__('Failed to check related branches.')); }); } @@ -409,13 +410,16 @@ export default class CreateMergeRequestDropdown { this.unavailableButton.classList.remove('hide'); } + updateBranchName(suggestedBranchName) { + this.branchInput.value = suggestedBranchName; + this.updateCreatePaths('branch', suggestedBranchName); + } + updateInputState(target, ref, result) { // target - 'branch' or 'ref' - which the input field we are searching a ref for. // ref - string - what a user typed. // result - string - what has been found on backend. - const pathReplacement = `$1${ref}`; - // If a found branch equals exact the same text a user typed, // that means a new branch cannot be created as it already exists. if (ref === result) { @@ -426,18 +430,12 @@ export default class CreateMergeRequestDropdown { this.refIsValid = true; this.refInput.dataset.value = ref; this.showAvailableMessage('ref'); - this.createBranchPath = this.createBranchPath.replace(this.regexps.ref.createBranchPath, - pathReplacement); - this.createMrPath = this.createMrPath.replace(this.regexps.ref.createMrPath, - pathReplacement); + this.updateCreatePaths(target, ref); } } else if (target === 'branch') { this.branchIsValid = true; this.showAvailableMessage('branch'); - this.createBranchPath = this.createBranchPath.replace(this.regexps.branch.createBranchPath, - pathReplacement); - this.createMrPath = this.createMrPath.replace(this.regexps.branch.createMrPath, - pathReplacement); + this.updateCreatePaths(target, ref); } else { this.refIsValid = false; this.refInput.dataset.value = ref; @@ -457,4 +455,15 @@ export default class CreateMergeRequestDropdown { this.disableCreateAction(); } } + + // target - 'branch' or 'ref' + // ref - string - the new value to use as branch or ref + updateCreatePaths(target, ref) { + const pathReplacement = `$1${ref}`; + + this.createBranchPath = this.createBranchPath.replace(this.regexps[target].createBranchPath, + pathReplacement); + this.createMrPath = this.createMrPath.replace(this.regexps[target].createMrPath, + pathReplacement); + } } diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index 767e492f566..d69015c8665 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -134,11 +134,11 @@ class Projects::IssuesController < Projects::ApplicationController def can_create_branch can_create = current_user && can?(current_user, :push_code, @project) && - @issue.can_be_worked_on?(current_user) + @issue.can_be_worked_on? respond_to do |format| format.json do - render json: { can_create_branch: can_create, has_related_branch: @issue.has_related_branch? } + render json: { can_create_branch: can_create, suggested_branch_name: @issue.suggested_branch_name } end end end @@ -177,7 +177,7 @@ class Projects::IssuesController < Projects::ApplicationController end def authorize_create_merge_request! - render_404 unless can?(current_user, :push_code, @project) && @issue.can_be_worked_on?(current_user) + render_404 unless can?(current_user, :push_code, @project) && @issue.can_be_worked_on? end def render_issue_json diff --git a/app/models/issue.rb b/app/models/issue.rb index 7611e83647c..c34c35bcd34 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -194,6 +194,15 @@ class Issue < ActiveRecord::Base branches_with_iid - branches_with_merge_request end + def suggested_branch_name + return to_branch_name unless project.repository.branch_exists?(to_branch_name) + + index = 2 + index += 1 while project.repository.branch_exists?("#{to_branch_name}-#{index}") + + "#{to_branch_name}-#{index}" + end + # Returns boolean if a related branch exists for the current issue # ignores merge requests branchs def has_related_branch? @@ -248,11 +257,8 @@ class Issue < ActiveRecord::Base end end - def can_be_worked_on?(current_user) - !self.closed? && - !self.project.forked? && - self.related_branches(current_user).empty? && - self.closed_by_merge_requests(current_user).empty? + def can_be_worked_on? + !self.closed? && !self.project.forked? end # Returns `true` if the current issue can be viewed by either a logged in User diff --git a/changelogs/unreleased/42803-show-new-branch-mr-button.yml b/changelogs/unreleased/42803-show-new-branch-mr-button.yml new file mode 100644 index 00000000000..d689ff7f001 --- /dev/null +++ b/changelogs/unreleased/42803-show-new-branch-mr-button.yml @@ -0,0 +1,5 @@ +--- +title: Show new branch/mr button even when branch exists +merge_request: 17712 +author: Jacopo Beschi @jacopo-beschi +type: added diff --git a/spec/javascripts/issue_spec.js b/spec/javascripts/issue_spec.js index f37426a72d4..047ecab27db 100644 --- a/spec/javascripts/issue_spec.js +++ b/spec/javascripts/issue_spec.js @@ -92,6 +92,7 @@ describe('Issue', function() { function mockCanCreateBranch(canCreateBranch) { mock.onGet(/(.*)\/can_create_branch$/).reply(200, { can_create_branch: canCreateBranch, + suggested_branch_name: 'foo-99', }); } diff --git a/spec/models/issue_spec.rb b/spec/models/issue_spec.rb index 11154291368..128acf83686 100644 --- a/spec/models/issue_spec.rb +++ b/spec/models/issue_spec.rb @@ -376,6 +376,48 @@ describe Issue do end end + describe '#suggested_branch_name' do + let(:repository) { double } + + subject { build(:issue) } + + before do + allow(subject.project).to receive(:repository).and_return(repository) + end + + context '#to_branch_name does not exists' do + before do + allow(repository).to receive(:branch_exists?).and_return(false) + end + + it 'returns #to_branch_name' do + expect(subject.suggested_branch_name).to eq(subject.to_branch_name) + end + end + + context '#to_branch_name exists not ending with -index' do + before do + allow(repository).to receive(:branch_exists?).and_return(true) + allow(repository).to receive(:branch_exists?).with(/#{subject.to_branch_name}-\d/).and_return(false) + end + + it 'returns #to_branch_name ending with -2' do + expect(subject.suggested_branch_name).to eq("#{subject.to_branch_name}-2") + end + end + + context '#to_branch_name exists ending with -index' do + before do + allow(repository).to receive(:branch_exists?).and_return(true) + allow(repository).to receive(:branch_exists?).with("#{subject.to_branch_name}-3").and_return(false) + end + + it 'returns #to_branch_name ending with max index + 1' do + expect(subject.suggested_branch_name).to eq("#{subject.to_branch_name}-3") + end + end + end + describe '#has_related_branch?' do let(:issue) { create(:issue, title: "Blue Bell Knoll") } subject { issue.has_related_branch? } @@ -425,6 +467,27 @@ describe Issue do end end + describe '#can_be_worked_on?' do + let(:project) { build(:project) } + subject { build(:issue, :opened, project: project) } + + context 'is closed' do + subject { build(:issue, :closed) } + + it { is_expected.not_to be_can_be_worked_on } + end + + context 'project is forked' do + before do + allow(project).to receive(:forked?).and_return(true) + end + + it { is_expected.not_to be_can_be_worked_on } + end + + it { is_expected.to be_can_be_worked_on } + end + describe '#participants' do context 'using a public project' do let(:project) { create(:project, :public) } -- cgit v1.2.3 From 4f2e494772eb5f31929ecfdb439dfa4baa56521c Mon Sep 17 00:00:00 2001 From: Jacopo Date: Fri, 13 Apr 2018 16:21:22 +0200 Subject: Checked in new translation keys --- locale/gitlab.pot | 3 +++ 1 file changed, 3 insertions(+) diff --git a/locale/gitlab.pot b/locale/gitlab.pot index 0eec9793391..cd30783c274 100644 --- a/locale/gitlab.pot +++ b/locale/gitlab.pot @@ -1776,6 +1776,9 @@ msgstr "" msgid "Failed to change the owner" msgstr "" +msgid "Failed to check related branches." +msgstr "" + msgid "Failed to remove issue from board, please try again." msgstr "" -- cgit v1.2.3 From 6ae3098eb8f01406190942e8952866dd9af81dde Mon Sep 17 00:00:00 2001 From: Jacopo Date: Thu, 19 Apr 2018 08:59:37 +0200 Subject: Uses Uniquify to calculate Issue#suggested_branch_name --- app/models/concerns/uniquify.rb | 7 +++++-- app/models/issue.rb | 8 ++++---- spec/models/concerns/uniquify_spec.rb | 7 +++++++ 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/app/models/concerns/uniquify.rb b/app/models/concerns/uniquify.rb index a7fe5951b6e..db51ed2dbeb 100644 --- a/app/models/concerns/uniquify.rb +++ b/app/models/concerns/uniquify.rb @@ -3,11 +3,14 @@ class Uniquify # by appending a counter to it. Uniqueness is determined by # repeated calls to the passed block. # + # You can pass an initial value for the counter, if not given + # counting starts from 1. + # # If `base` is a function/proc, we expect that calling it with a # candidate counter returns a string to test/return. - def string(base) + def string(base, counter = nil) @base = base - @counter = nil + @counter = counter increment_counter! while yield(base_string) base_string diff --git a/app/models/issue.rb b/app/models/issue.rb index c34c35bcd34..51028a404c2 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -197,10 +197,10 @@ class Issue < ActiveRecord::Base def suggested_branch_name return to_branch_name unless project.repository.branch_exists?(to_branch_name) - index = 2 - index += 1 while project.repository.branch_exists?("#{to_branch_name}-#{index}") - - "#{to_branch_name}-#{index}" + start_counting_from = 2 + Uniquify.new.string(-> (counter) { "#{to_branch_name}-#{counter}" }, start_counting_from) do |suggested_branch_name| + project.repository.branch_exists?(suggested_branch_name) + end end # Returns boolean if a related branch exists for the current issue diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb index 914730718e7..00341213bbe 100644 --- a/spec/models/concerns/uniquify_spec.rb +++ b/spec/models/concerns/uniquify_spec.rb @@ -22,6 +22,13 @@ describe Uniquify do expect(result).to eq('test_string2') end + it 'allows to pass an initial value for the counter' do + start_counting_from = 2 + result = uniquify.string('test_string', start_counting_from) { |s| s == 'test_string' } + + expect(result).to eq('test_string2') + end + it 'allows passing in a base function that defines the location of the counter' do result = uniquify.string(-> (counter) { "test_#{counter}_string" }) do |s| s == 'test__string' -- cgit v1.2.3 From 9000626a60c889c76ff1dfc8c6247f15953ca993 Mon Sep 17 00:00:00 2001 From: Jacopo Date: Thu, 19 Apr 2018 11:31:01 +0200 Subject: Moves Uniquify counter in the initializer --- app/models/concerns/uniquify.rb | 27 ++++++++++++++++----------- app/models/issue.rb | 2 +- spec/models/concerns/uniquify_spec.rb | 4 +++- 3 files changed, 20 insertions(+), 13 deletions(-) diff --git a/app/models/concerns/uniquify.rb b/app/models/concerns/uniquify.rb index db51ed2dbeb..549a76da20e 100644 --- a/app/models/concerns/uniquify.rb +++ b/app/models/concerns/uniquify.rb @@ -1,16 +1,21 @@ +# Uniquify +# +# Return a version of the given 'base' string that is unique +# by appending a counter to it. Uniqueness is determined by +# repeated calls to the passed block. +# +# You can pass an initial value for the counter, if not given +# counting starts from 1. +# +# If `base` is a function/proc, we expect that calling it with a +# candidate counter returns a string to test/return. class Uniquify - # Return a version of the given 'base' string that is unique - # by appending a counter to it. Uniqueness is determined by - # repeated calls to the passed block. - # - # You can pass an initial value for the counter, if not given - # counting starts from 1. - # - # If `base` is a function/proc, we expect that calling it with a - # candidate counter returns a string to test/return. - def string(base, counter = nil) - @base = base + def initialize(counter = nil) @counter = counter + end + + def string(base) + @base = base increment_counter! while yield(base_string) base_string diff --git a/app/models/issue.rb b/app/models/issue.rb index 51028a404c2..0332bfa9371 100644 --- a/app/models/issue.rb +++ b/app/models/issue.rb @@ -198,7 +198,7 @@ class Issue < ActiveRecord::Base return to_branch_name unless project.repository.branch_exists?(to_branch_name) start_counting_from = 2 - Uniquify.new.string(-> (counter) { "#{to_branch_name}-#{counter}" }, start_counting_from) do |suggested_branch_name| + Uniquify.new(start_counting_from).string(-> (counter) { "#{to_branch_name}-#{counter}" }) do |suggested_branch_name| project.repository.branch_exists?(suggested_branch_name) end end diff --git a/spec/models/concerns/uniquify_spec.rb b/spec/models/concerns/uniquify_spec.rb index 00341213bbe..6cd2de6dcce 100644 --- a/spec/models/concerns/uniquify_spec.rb +++ b/spec/models/concerns/uniquify_spec.rb @@ -24,7 +24,9 @@ describe Uniquify do it 'allows to pass an initial value for the counter' do start_counting_from = 2 - result = uniquify.string('test_string', start_counting_from) { |s| s == 'test_string' } + uniquify = described_class.new(start_counting_from) + + result = uniquify.string('test_string') { |s| s == 'test_string' } expect(result).to eq('test_string2') end -- cgit v1.2.3 From 12aab8ff6a6d8dba7ab682586b89bb1b800b82e2 Mon Sep 17 00:00:00 2001 From: Filipa Lacerda Date: Thu, 19 Apr 2018 15:36:37 +0100 Subject: Prettify vue shared component & improve tests to match guidelines --- .../vue_shared/components/ci_badge_link.vue | 88 ++++++------ .../javascripts/vue_shared/components/ci_icon.vue | 75 +++++------ .../vue_shared/components/clipboard_button.vue | 76 ++++++----- .../vue_shared/components/ci_icon_spec.js | 149 +++++++++------------ .../vue_shared/components/clipboard_button_spec.js | 2 +- 5 files changed, 191 insertions(+), 199 deletions(-) diff --git a/app/assets/javascripts/vue_shared/components/ci_badge_link.vue b/app/assets/javascripts/vue_shared/components/ci_badge_link.vue index 5324d5dc797..0d64efcbf68 100644 --- a/app/assets/javascripts/vue_shared/components/ci_badge_link.vue +++ b/app/assets/javascripts/vue_shared/components/ci_badge_link.vue @@ -1,52 +1,52 @@