Skip to content
代码片段 群组 项目
未验证 提交 0426f56e 编辑于 作者: Manoj M J's avatar Manoj M J 提交者: GitLab
浏览文件

Housekeeper: Add support for `ci.skip`

上级 cdf3f840
No related branches found
No related tags found
无相关合并请求
......@@ -69,6 +69,9 @@ module Keeps
change.changed_files = [file_name]
# to push changes without triggering a pipeline.
change.push_options.ci_skip = true
yield(change)
end
end
......
# frozen_string_literal: true
require 'gitlab/housekeeper/push_options'
module Gitlab
module Housekeeper
class Change
......@@ -10,12 +12,14 @@ class Change
:labels,
:keep_class,
:changelog_type,
:mr_web_url
:mr_web_url,
:push_options
attr_reader :reviewers
def initialize
@labels = []
@reviewers = []
@push_options = PushOptions.new
end
def reviewers=(reviewers)
......
......@@ -2,6 +2,7 @@
require 'logger'
require 'gitlab/housekeeper/shell'
require 'gitlab/housekeeper/push_options'
module Gitlab
module Housekeeper
......@@ -46,8 +47,11 @@ def create_commit(change)
Shell.execute("git", "commit", "-m", change.commit_message)
end
def push(branch_name)
Shell.execute('git', 'push', '-f', housekeeper_remote, "#{branch_name}:#{branch_name}")
def push(branch_name, push_options = PushOptions.new)
push_command = ['git', 'push', '-f', housekeeper_remote, "#{branch_name}:#{branch_name}"]
push_command << '-o ci.skip' if push_options.ci_skip
Shell.execute(*push_command)
end
private
......
# frozen_string_literal: true
module Gitlab
module Housekeeper
class PushOptions
attr_accessor :ci_skip
def initialize
@ci_skip = false
end
end
end
end
......@@ -105,7 +105,10 @@ def require_keeps
end
def print_change_details(change, branch_name)
puts "Merge request URL: #{change.mr_web_url || '(known after create)'}, on branch #{branch_name}".yellowish
base_message = "Merge request URL: #{change.mr_web_url || '(known after create)'}, on branch #{branch_name}."
base_message << " CI skipped." if change.push_options.ci_skip
puts base_message.yellowish
puts "=> #{change.identifiers.join(': ')}".purple
puts '=> Title:'.purple
......@@ -137,7 +140,7 @@ def create(change, branch_name)
target_project_id: housekeeper_target_project_id
)
git.push(branch_name) unless non_housekeeper_changes.include?(:code)
git.push(branch_name, change.push_options) unless non_housekeeper_changes.include?(:code)
gitlab_client.create_or_update_merge_request(
change: change,
......
......@@ -17,6 +17,7 @@
expect(change.labels).to eq([])
expect(change.reviewers).to eq([])
expect(change.push_options.ci_skip).to eq(false)
end
end
......
......@@ -130,6 +130,8 @@ def setup_and_checkout_another_branch
end
describe '#push' do
let(:push_options) { ::Gitlab::Housekeeper::PushOptions.new }
before do
# Needed to check if remote exists
allow(::Gitlab::Housekeeper::Shell).to receive(:execute)
......@@ -152,7 +154,7 @@ def setup_and_checkout_another_branch
expect(::Gitlab::Housekeeper::Shell).to receive(:execute)
.with('git', 'push', '-f', 'housekeeper', 'the-branch-name:the-branch-name')
git.push('the-branch-name')
git.push('the-branch-name', push_options)
end
end
......@@ -160,7 +162,18 @@ def setup_and_checkout_another_branch
expect(::Gitlab::Housekeeper::Shell).to receive(:execute)
.with('git', 'push', '-f', 'origin', 'the-branch-name:the-branch-name')
git.push('the-branch-name')
git.push('the-branch-name', push_options)
end
context 'with push options defined' do
it 'pushes with push options set' do
expect(::Gitlab::Housekeeper::Shell).to receive(:execute)
.with('git', 'push', '-f', 'origin', 'the-branch-name:the-branch-name', '-o ci.skip')
push_options.ci_skip = true
git.push('the-branch-name', push_options)
end
end
end
end
......
# frozen_string_literal: true
require 'spec_helper'
require 'gitlab/housekeeper/push_options'
RSpec.describe ::Gitlab::Housekeeper::PushOptions do
describe '#initialize' do
it 'sets ci_skip to false by default' do
push_options = described_class.new
expect(push_options.ci_skip).to be false
end
end
end
......@@ -95,12 +95,12 @@
.with('git', '--no-pager', 'diff', '--color=always', 'master',
'the-identifier-for-the-first-change', '--', 'change1.txt', 'change2.txt')
expect(git).to receive(:push)
.with('the-identifier-for-the-first-change')
.with('the-identifier-for-the-first-change', change1.push_options)
expect(::Gitlab::Housekeeper::Shell).to receive(:execute)
.with('git', '--no-pager', 'diff', '--color=always', 'master',
'the-identifier-for-the-second-change', '--', 'change1.txt', 'change2.txt')
expect(git).to receive(:push)
.with('the-identifier-for-the-second-change')
.with('the-identifier-for-the-second-change', change2.push_options)
# Merge requests get created
expect(gitlab_client).to receive(:create_or_update_merge_request)
......@@ -163,7 +163,7 @@
.with('git', '--no-pager', 'diff', '--color=always', 'master',
'the-identifier-for-the-second-change', '--', 'change1.txt', 'change2.txt')
expect(git).to receive(:push)
.with('the-identifier-for-the-second-change')
.with('the-identifier-for-the-second-change', change2.push_options)
# Merge requests get created
expect(gitlab_client).to receive(:create_or_update_merge_request)
......@@ -207,9 +207,9 @@
expect(::Gitlab::Housekeeper::Substitutor).to receive(:perform).with(change2)
expect(git).not_to receive(:push)
.with('the-identifier-for-the-first-change')
.with('the-identifier-for-the-first-change', change1.push_options)
expect(git).to receive(:push)
.with('the-identifier-for-the-second-change')
.with('the-identifier-for-the-second-change', change2.push_options)
expect(gitlab_client).to receive(:create_or_update_merge_request)
.with(
......
0% 加载中 .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册