Commit e6e68627 authored by Dan Davison's avatar Dan Davison

Merge branch 'ml-qa-use-project-default-branch' into 'master'

Use project default branch in QA tests

See merge request gitlab-org/gitlab!48967
parents ea68aad4 81412946
...@@ -14,7 +14,7 @@ module QA ...@@ -14,7 +14,7 @@ module QA
include Support::Run include Support::Run
attr_writer :use_lfs, :gpg_key_id attr_writer :use_lfs, :gpg_key_id
attr_accessor :env_vars attr_accessor :env_vars, :default_branch
InvalidCredentialsError = Class.new(RuntimeError) InvalidCredentialsError = Class.new(RuntimeError)
...@@ -25,6 +25,7 @@ module QA ...@@ -25,6 +25,7 @@ module QA
self.env_vars = [%Q{HOME="#{tmp_home_dir}"}] self.env_vars = [%Q{HOME="#{tmp_home_dir}"}]
@use_lfs = false @use_lfs = false
@gpg_key_id = nil @gpg_key_id = nil
@default_branch = Runtime::Env.default_branch
end end
def self.perform(*args) def self.perform(*args)
...@@ -123,7 +124,7 @@ module QA ...@@ -123,7 +124,7 @@ module QA
run_git("git rev-parse --abbrev-ref HEAD").to_s run_git("git rev-parse --abbrev-ref HEAD").to_s
end end
def push_changes(branch = 'master', push_options: nil) def push_changes(branch = @default_branch, push_options: nil)
cmd = ['git push'] cmd = ['git push']
cmd << push_options_hash_to_string(push_options) cmd << push_options_hash_to_string(push_options)
cmd << uri cmd << uri
...@@ -209,6 +210,13 @@ module QA ...@@ -209,6 +210,13 @@ module QA
File.delete(netrc_file_path) if File.exist?(netrc_file_path) File.delete(netrc_file_path) if File.exist?(netrc_file_path)
end end
def remote_branches
# This gets the remote branch names
# When executed on a fresh repo it returns the default branch name
run_git('git --no-pager branch --list --remotes --format="%(refname:lstrip=3)"').to_s.split("\n")
end
private private
attr_reader :uri, :username, :password, :ssh, :use_lfs attr_reader :uri, :username, :password, :ssh, :use_lfs
......
...@@ -70,7 +70,7 @@ module QA ...@@ -70,7 +70,7 @@ module QA
end end
end end
def duplicate_dashboard(save_as = 'test_duplication.yml', commit_option = 'Commit to master branch') def duplicate_dashboard(save_as = 'test_duplication.yml', commit_option = 'Commit to default branch')
click_element :actions_menu_dropdown click_element :actions_menu_dropdown
click_on 'Duplicate current dashboard' click_on 'Duplicate current dashboard'
fill_element :duplicate_dashboard_filename_field, "#{SecureRandom.hex(8)}-#{save_as}" fill_element :duplicate_dashboard_filename_field, "#{SecureRandom.hex(8)}-#{save_as}"
......
...@@ -20,7 +20,7 @@ module QA ...@@ -20,7 +20,7 @@ module QA
end end
end end
def wait_for_push_new_branch(branch_name = "master") def wait_for_push_new_branch(branch_name = self.default_branch)
QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push_new_branch with branch_name "#{branch_name}"]) QA::Runtime::Logger.debug(%Q[#{self.class.name} - wait_for_push_new_branch with branch_name "#{branch_name}"])
wait_for_event do wait_for_event do
events(action: 'pushed').any? { |event| event.dig(:push_data, :ref) == branch_name } events(action: 'pushed').any? { |event| event.dig(:push_data, :ref) == branch_name }
......
...@@ -30,7 +30,7 @@ module QA ...@@ -30,7 +30,7 @@ module QA
end end
def branch def branch
@branch ||= "master" @branch ||= project.default_branch
end end
def fabricate! def fabricate!
......
...@@ -34,7 +34,7 @@ module QA ...@@ -34,7 +34,7 @@ module QA
attribute :target do attribute :target do
Repository::ProjectPush.fabricate! do |resource| Repository::ProjectPush.fabricate! do |resource|
resource.project = project resource.project = project
resource.branch_name = 'master' resource.branch_name = project.default_branch
resource.new_branch = @target_new_branch resource.new_branch = @target_new_branch
resource.remote_branch = target_branch resource.remote_branch = target_branch
end end
...@@ -56,7 +56,6 @@ module QA ...@@ -56,7 +56,6 @@ module QA
@title = 'QA test - merge request' @title = 'QA test - merge request'
@description = 'This is a test merge request' @description = 'This is a test merge request'
@source_branch = "qa-test-feature-#{SecureRandom.hex(8)}" @source_branch = "qa-test-feature-#{SecureRandom.hex(8)}"
@target_branch = "master"
@assignee = nil @assignee = nil
@milestone = nil @milestone = nil
@labels = [] @labels = []
...@@ -68,7 +67,7 @@ module QA ...@@ -68,7 +67,7 @@ module QA
end end
def fabricate! def fabricate!
populate(:target, :source) populate_target_and_source_if_required
project.visit! project.visit!
Page::Project::Show.perform(&:new_merge_request) Page::Project::Show.perform(&:new_merge_request)
...@@ -89,7 +88,7 @@ module QA ...@@ -89,7 +88,7 @@ module QA
def fabricate_via_api! def fabricate_via_api!
resource_web_url(api_get) resource_web_url(api_get)
rescue ResourceNotFoundError rescue ResourceNotFoundError
populate(:target, :source) unless @no_preparation populate_target_and_source_if_required
super super
end end
...@@ -144,6 +143,12 @@ module QA ...@@ -144,6 +143,12 @@ module QA
super(api_resource) super(api_resource)
end end
def populate_target_and_source_if_required
@target_branch ||= project.default_branch
populate(:target, :source) unless @no_preparation
end
end end
end end
end end
...@@ -22,7 +22,6 @@ module QA ...@@ -22,7 +22,6 @@ module QA
attribute :variables attribute :variables
def initialize def initialize
@ref = 'master'
@variables = [] @variables = []
end end
...@@ -34,6 +33,10 @@ module QA ...@@ -34,6 +33,10 @@ module QA
Page::Project::Pipeline::New.perform(&:click_run_pipeline_button) Page::Project::Pipeline::New.perform(&:click_run_pipeline_button)
end end
def ref
project.default_branch
end
def api_get_path def api_get_path
"/projects/#{project.id}/pipelines/#{id}" "/projects/#{project.id}/pipelines/#{id}"
end end
......
...@@ -15,7 +15,6 @@ module QA ...@@ -15,7 +15,6 @@ module QA
attr_writer :github_personal_access_token attr_writer :github_personal_access_token
attr_writer :github_repository_path attr_writer :github_repository_path
attribute :default_branch
attribute :id attribute :id
attribute :name attribute :name
attribute :add_name_uuid attribute :add_name_uuid
...@@ -26,6 +25,10 @@ module QA ...@@ -26,6 +25,10 @@ module QA
attribute :template_name attribute :template_name
attribute :import attribute :import
attribute :default_branch do
api_response[:default_branch] || Runtime::Env.default_branch
end
attribute :group do attribute :group do
Group.fabricate! Group.fabricate!
end end
......
...@@ -81,7 +81,7 @@ module QA ...@@ -81,7 +81,7 @@ module QA
def api_post_body def api_post_body
{ {
branch: @branch || "master", branch: @branch || project.default_branch,
author_email: @author_email || Runtime::User.default_email, author_email: @author_email || Runtime::User.default_email,
author_name: @author_name || Runtime::User.username, author_name: @author_name || Runtime::User.username,
commit_message: commit_message, commit_message: commit_message,
......
...@@ -23,7 +23,6 @@ module QA ...@@ -23,7 +23,6 @@ module QA
@file_name = "file-#{SecureRandom.hex(8)}.txt" @file_name = "file-#{SecureRandom.hex(8)}.txt"
@file_content = '# This is test project' @file_content = '# This is test project'
@commit_message = "This is a test commit" @commit_message = "This is a test commit"
@branch_name = 'master'
@new_branch = true @new_branch = true
@project_name = 'project-with-code' @project_name = 'project-with-code'
@wait_for_push = true @wait_for_push = true
...@@ -39,6 +38,8 @@ module QA ...@@ -39,6 +38,8 @@ module QA
end end
def fabricate! def fabricate!
@branch_name ||= project.default_branch
super super
project.wait_for_push @commit_message if @wait_for_push project.wait_for_push @commit_message if @wait_for_push
end end
......
...@@ -17,7 +17,6 @@ module QA ...@@ -17,7 +17,6 @@ module QA
@file_name = "file-#{SecureRandom.hex(8)}.txt" @file_name = "file-#{SecureRandom.hex(8)}.txt"
@file_content = '# This is test file' @file_content = '# This is test file'
@commit_message = "This is a test commit" @commit_message = "This is a test commit"
@branch_name = 'master'
@new_branch = true @new_branch = true
@repository_http_uri = "" @repository_http_uri = ""
@ssh_key = nil @ssh_key = nil
...@@ -78,6 +77,8 @@ module QA ...@@ -78,6 +77,8 @@ module QA
@output += repository.clone @output += repository.clone
repository.configure_identity(name, email) repository.configure_identity(name, email)
@branch_name ||= default_branch(repository)
@output += repository.checkout(branch_name, new_branch: new_branch) @output += repository.checkout(branch_name, new_branch: new_branch)
if @tag_name if @tag_name
...@@ -105,6 +106,10 @@ module QA ...@@ -105,6 +106,10 @@ module QA
private private
def default_branch(repository)
repository.remote_branches.last || Runtime::Env.default_branch
end
def commit_to(repository) def commit_to(repository)
@gpg_key_id.nil? ? repository.commit(@commit_message) : repository.commit_with_gpg(@commit_message) @gpg_key_id.nil? ? repository.commit(@commit_message) : repository.commit_with_gpg(@commit_message)
end end
......
...@@ -12,11 +12,14 @@ module QA ...@@ -12,11 +12,14 @@ module QA
end end
end end
def branch_name
@branch_name ||= wiki.project.default_branch
end
def initialize def initialize
@file_name = 'Home.md' @file_name = 'Home.md'
@file_content = 'This line was created using git push' @file_content = 'This line was created using git push'
@commit_message = 'Updating using git push' @commit_message = 'Updating using git push'
@branch_name = 'master'
@new_branch = false @new_branch = false
end end
......
...@@ -63,7 +63,7 @@ module QA ...@@ -63,7 +63,7 @@ module QA
end end
def pipeline_from_project_name def pipeline_from_project_name
ci_project_name.to_s.start_with?('gitlab-qa') ? 'master' : ci_project_name ci_project_name.to_s.start_with?('gitlab-qa') ? Runtime::Env.default_branch : ci_project_name
end end
def additional_repository_storage def additional_repository_storage
...@@ -102,6 +102,10 @@ module QA ...@@ -102,6 +102,10 @@ module QA
enabled?(ENV['QA_DEBUG'], default: false) enabled?(ENV['QA_DEBUG'], default: false)
end end
def default_branch
ENV['QA_DEFAULT_BRANCH'] || 'master'
end
def log_destination def log_destination
ENV['QA_LOG_PATH'] || $stdout ENV['QA_LOG_PATH'] || $stdout
end end
......
...@@ -37,7 +37,7 @@ module QA ...@@ -37,7 +37,7 @@ module QA
Support::Waiter.wait_until(retry_on_exception: true, sleep_interval: 5) do Support::Waiter.wait_until(retry_on_exception: true, sleep_interval: 5) do
Resource::Repository::Commit.fabricate_via_api! do |commits| Resource::Repository::Commit.fabricate_via_api! do |commits|
commits.project = project commits.project = project
commits.sha = 'master' commits.sha = project.default_branch
end end
end end
......
...@@ -21,27 +21,29 @@ module QA ...@@ -21,27 +21,29 @@ module QA
a_hash_including(name: project_name, path: project_name) a_hash_including(name: project_name, path: project_name)
) )
default_branch = json_body[:default_branch].to_s.empty? ? Runtime::Env.default_branch : json_body[:default_branch]
create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md") create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md")
post create_file_request.url, branch: 'master', content: 'Hello world', commit_message: 'Add README.md' post create_file_request.url, branch: default_branch, content: 'Hello world', commit_message: 'Add README.md'
expect_status(201) expect_status(201)
expect(json_body).to match( expect(json_body).to match(
a_hash_including(branch: 'master', file_path: 'README.md') a_hash_including(branch: default_branch, file_path: 'README.md')
) )
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", ref: 'master') get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", ref: default_branch)
get get_file_request.url get get_file_request.url
expect_status(200) expect_status(200)
expect(json_body).to match( expect(json_body).to match(
a_hash_including( a_hash_including(
ref: 'master', ref: default_branch,
file_path: 'README.md', file_name: 'README.md', file_path: 'README.md', file_name: 'README.md',
encoding: 'base64', content: 'SGVsbG8gd29ybGQ=' encoding: 'base64', content: 'SGVsbG8gd29ybGQ='
) )
) )
delete_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", branch: 'master', commit_message: 'Remove README.md') delete_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/README.md", branch: default_branch, commit_message: 'Remove README.md')
delete delete_file_request.url delete delete_file_request.url
expect_status(204) expect_status(204)
...@@ -80,10 +82,12 @@ module QA ...@@ -80,10 +82,12 @@ module QA
create_project_request = Runtime::API::Request.new(@api_client, '/projects') create_project_request = Runtime::API::Request.new(@api_client, '/projects')
post create_project_request.url, path: project_name, name: project_name post create_project_request.url, path: project_name, name: project_name
default_branch = json_body[:default_branch].to_s.empty? ? Runtime::Env.default_branch : json_body[:default_branch]
create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg") create_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg")
post create_file_request.url, branch: 'master', content: svg_file, commit_message: 'Add test.svg' post create_file_request.url, branch: default_branch, content: svg_file, commit_message: 'Add test.svg'
get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg/raw", ref: 'master') get_file_request = Runtime::API::Request.new(@api_client, "/projects/#{sanitized_project_path}/repository/files/test.svg/raw", ref: default_branch)
3.times do 3.times do
response = get get_file_request.url response = get get_file_request.url
......
...@@ -42,7 +42,7 @@ module QA ...@@ -42,7 +42,7 @@ module QA
end end
let!(:pipeline_id) do let!(:pipeline_id) do
pipeline_create_request = Runtime::API::Request.new(api_client, "/projects/#{project.id}/pipeline?ref=master") pipeline_create_request = Runtime::API::Request.new(api_client, "/projects/#{project.id}/pipeline?ref=#{project.default_branch}")
JSON.parse(post(pipeline_create_request.url, nil))['id'] JSON.parse(post(pipeline_create_request.url, nil))['id']
end end
......
...@@ -6,17 +6,18 @@ module QA ...@@ -6,17 +6,18 @@ module QA
it 'user creates an event in the activity page upon Git push', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/407' do it 'user creates an event in the activity page upon Git push', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/407' do
Flow::Login.sign_in Flow::Login.sign_in
Resource::Repository::ProjectPush.fabricate! do |push| project = Resource::Repository::ProjectPush.fabricate! do |push|
push.file_name = 'README.md' push.file_name = 'README.md'
push.file_content = '# This is a test project' push.file_content = '# This is a test project'
push.commit_message = 'Add README.md' push.commit_message = 'Add README.md'
end.project.visit! end.project
project.visit!
Page::Project::Menu.perform(&:click_activity) Page::Project::Menu.perform(&:click_activity)
Page::Project::Activity.perform do |activity| Page::Project::Activity.perform do |activity|
activity.click_push_events activity.click_push_events
expect(activity).to have_content('pushed new branch master') expect(activity).to have_content("pushed new branch #{project.default_branch}")
end end
end end
end end
......
...@@ -36,7 +36,6 @@ module QA ...@@ -36,7 +36,6 @@ module QA
QA::Support::Retrier.retry_on_exception do QA::Support::Retrier.retry_on_exception do
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = project push.project = project
push.branch_name = 'master'
push.new_branch = false push.new_branch = false
push.file_name = "file_#{SecureRandom.hex(4)}.txt" push.file_name = "file_#{SecureRandom.hex(4)}.txt"
end end
......
...@@ -80,7 +80,6 @@ module QA ...@@ -80,7 +80,6 @@ module QA
def push_commit(commit_message) def push_commit(commit_message)
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.branch_name = 'master'
push.commit_message = commit_message push.commit_message = commit_message
push.file_content = commit_message push.file_content = commit_message
push.project = project push.project = project
...@@ -101,7 +100,7 @@ module QA ...@@ -101,7 +100,7 @@ module QA
end end
def master_branch_exists? def master_branch_exists?
project.repository_branches.map { |item| item[:name] }.include?("master") project.repository_branches.map { |item| item[:name] }.include?(project.default_branch)
end end
end end
end end
......
...@@ -27,7 +27,6 @@ module QA ...@@ -27,7 +27,6 @@ module QA
push.project = project push.project = project
push.file_name = "other.txt" push.file_name = "other.txt"
push.file_content = "New file added!" push.file_content = "New file added!"
push.branch_name = "master"
push.new_branch = false push.new_branch = false
end end
......
...@@ -37,8 +37,8 @@ module QA ...@@ -37,8 +37,8 @@ module QA
mr_page.click_diffs_tab mr_page.click_diffs_tab
mr_page.click_target_version_dropdown mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)') expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (HEAD)")
expect(mr_page.version_dropdown_content).not_to include('master (base)') expect(mr_page.version_dropdown_content).not_to include("#{project.default_branch} (base)")
expect(mr_page).to have_file(merge_request.file_name) expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).not_to have_file(new_file_name) expect(mr_page).not_to have_file(new_file_name)
end end
...@@ -62,8 +62,8 @@ module QA ...@@ -62,8 +62,8 @@ module QA
mr_page.click_diffs_tab mr_page.click_diffs_tab
mr_page.click_target_version_dropdown mr_page.click_target_version_dropdown
expect(mr_page.version_dropdown_content).to include('master (HEAD)') expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (HEAD)")
expect(mr_page.version_dropdown_content).to include('master (base)') expect(mr_page.version_dropdown_content).to include("#{project.default_branch} (base)")
expect(mr_page).to have_file(merge_request.file_name) expect(mr_page).to have_file(merge_request.file_name)
expect(mr_page).to have_file(new_file_name) expect(mr_page).to have_file(new_file_name)
end end
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
module QA module QA
RSpec.describe 'Create' do RSpec.describe 'Create' do
describe 'Create, list, and delete branches via web' do describe 'Create, list, and delete branches via web' do
master_branch = 'master' master_branch = nil
second_branch = 'second-branch' second_branch = 'second-branch'
third_branch = 'third-branch' third_branch = 'third-branch'
file_1_master = 'file.txt' file_1_master = 'file.txt'
...@@ -21,12 +21,16 @@ module QA ...@@ -21,12 +21,16 @@ module QA
project = Resource::Project.fabricate_via_api! do |proj| project = Resource::Project.fabricate_via_api! do |proj|
proj.name = 'project-qa-test' proj.name = 'project-qa-test'
proj.description = 'project for qa test' proj.description = 'project for qa test'
proj.initialize_with_readme = true
end end
master_branch = project.default_branch
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.uri = project.repository_http_location.uri repository.uri = project.repository_http_location.uri
repository.use_default_credentials repository.use_default_credentials
repository.try_add_credentials_to_netrc repository.try_add_credentials_to_netrc
repository.default_branch = master_branch
repository.act do repository.act do
clone clone
......
...@@ -7,7 +7,6 @@ module QA ...@@ -7,7 +7,6 @@ module QA
let(:changed_content) { 'changes' } let(:changed_content) { 'changes' }
let(:commit_message) { 'Changes to snippets' } let(:commit_message) { 'Changes to snippets' }
let(:added_content) { 'updated ' } let(:added_content) { 'updated ' }
let(:branch_name) { 'master' }
let(:snippet) do let(:snippet) do
Resource::Snippet.fabricate! do |snippet| Resource::Snippet.fabricate! do |snippet|
...@@ -41,7 +40,7 @@ module QA ...@@ -41,7 +40,7 @@ module QA
end end
it 'clones, pushes, and pulls a snippet over HTTP, edits via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/826' do it 'clones, pushes, and pulls a snippet over HTTP, edits via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/826' do
Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
push.repository_http_uri = repository_uri_http push.repository_http_uri = repository_uri_http
push.file_name = new_file push.file_name = new_file
push.file_content = changed_content push.file_content = changed_content
...@@ -61,7 +60,7 @@ module QA ...@@ -61,7 +60,7 @@ module QA
Git::Repository.perform do |repository| Git::Repository.perform do |repository|
repository.init_repository repository.init_repository
repository.pull(repository_uri_http, branch_name) repository.pull(repository_uri_http, push.branch_name)
expect(repository.commits.size).to eq(3) expect(repository.commits.size).to eq(3)
expect(repository.commits.first).to include('Update snippet') expect(repository.commits.first).to include('Update snippet')
...@@ -70,7 +69,7 @@ module QA ...@@ -70,7 +69,7 @@ module QA
end end
it 'clones, pushes, and pulls a snippet over SSH, deletes via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/825' do it 'clones, pushes, and pulls a snippet over SSH, deletes via UI', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/825' do
Resource::Repository::Push.fabricate! do |push| push = Resource::Repository::Push.fabricate! do |push|
push.repository_ssh_uri = repository_uri_ssh push.repository_ssh_uri = repository_uri_ssh
push.ssh_key = ssh_key push.ssh_key = ssh_key
push.file_name = new_file push.file_name = new_file
...@@ -90,7 +89,7 @@ module QA ...@@ -90,7 +89,7 @@ module QA
repository.use_ssh_key(ssh_key) repository.use_ssh_key(ssh_key)
repository.init_repository repository.init_repository
expect { repository.pull(repository_uri_ssh, branch_name) } expect { repository.pull(repository_uri_ssh, push.branch_name) }
.to raise_error(QA::Support::Run::CommandError, /fatal: Could not read from remote repository\./) .to raise_error(QA::Support::Run::CommandError, /fatal: Could not read from remote repository\./)
end end
end end
......
...@@ -7,7 +7,7 @@ module QA ...@@ -7,7 +7,7 @@ module QA
let(:changed_content) { 'changes' } let(:changed_content) { 'changes' }
let(:commit_message) { 'Changes to snippets' } let(:commit_message) { 'Changes to snippets' }
let(:added_content) { 'updated ' } let(:added_content) { 'updated ' }
let(:branch_name) { 'master' } let(:branch_name) { snippet.project.default_branch }
let(:snippet) do let(:snippet) do
Resource::ProjectSnippet.fabricate! do |snippet| Resource::ProjectSnippet.fabricate! do |snippet|
......
...@@ -54,7 +54,7 @@ module QA ...@@ -54,7 +54,7 @@ module QA
script: script:
- 'gradle publish' - 'gradle publish'
only: only:
- master - "#{project.default_branch}"
tags: tags:
- "runner-for-#{project.name}" - "runner-for-#{project.name}"
YAML YAML
......
...@@ -51,7 +51,7 @@ module QA ...@@ -51,7 +51,7 @@ module QA
- dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text - dotnet nuget add source "$CI_SERVER_URL/api/v4/projects/$CI_PROJECT_ID/packages/nuget/index.json" --name gitlab --username gitlab-ci-token --password $CI_JOB_TOKEN --store-password-in-clear-text
- dotnet nuget push "bin/Release/*.nupkg" --source gitlab - dotnet nuget push "bin/Release/*.nupkg" --source gitlab
only: only:
- master - "#{project.default_branch}"
tags: tags:
- "runner-for-#{project.name}" - "runner-for-#{project.name}"
YAML YAML
......
...@@ -24,13 +24,7 @@ module QA ...@@ -24,13 +24,7 @@ module QA
file_name: '.gitlab-ci.yml', file_name: '.gitlab-ci.yml',
template: 'custom_gitlab-ci', template: 'custom_gitlab-ci',
file_path: 'gitlab-ci/custom_gitlab-ci.yml', file_path: 'gitlab-ci/custom_gitlab-ci.yml',
content: content: 'gitlab-ci.yml template test'
<<~CI
job:
script: echo "Skipped"
except:
- master
CI
}, },
{ {
file_name: 'LICENSE', file_name: 'LICENSE',
......
...@@ -26,7 +26,7 @@ module QA ...@@ -26,7 +26,7 @@ module QA
end end
it 'merge request assigns code owners as approvers', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/605' do it 'merge request assigns code owners as approvers', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/605' do
# Commit CODEOWNERS to master # Commit CODEOWNERS to default branch
Resource::Repository::Commit.fabricate_via_api! do |commit| Resource::Repository::Commit.fabricate_via_api! do |commit|
commit.project = project commit.project = project
commit.commit_message = 'Add CODEOWNERS and test files' commit.commit_message = 'Add CODEOWNERS and test files'
...@@ -69,7 +69,7 @@ module QA ...@@ -69,7 +69,7 @@ module QA
end.visit! end.visit!
# Check that the merge request assigns the original code owner as an # Check that the merge request assigns the original code owner as an
# approver (because the current CODEOWNERS file in the master branch # approver (because the current CODEOWNERS file in the default branch
# doesn't have the new owner yet) # doesn't have the new owner yet)
Page::MergeRequest::Show.perform do |show| Page::MergeRequest::Show.perform do |show|
show.edit! show.edit!
......
...@@ -3,55 +3,57 @@ ...@@ -3,55 +3,57 @@
module QA module QA
RSpec.describe 'Create' do RSpec.describe 'Create' do
describe 'File Locking' do describe 'File Locking' do
before do let(:user_one) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1) }
Flow::Login.sign_in let(:user_two) { Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2) }
@user_one = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_1, Runtime::Env.gitlab_qa_password_1) let(:project) do
@user_two = Resource::User.fabricate_or_use(Runtime::Env.gitlab_qa_username_2, Runtime::Env.gitlab_qa_password_2) Resource::Project.fabricate_via_api! do |project|
@project = Resource::Project.fabricate_via_api! do |project|
project.name = 'file_locking' project.name = 'file_locking'
end end
end
before do
Flow::Login.sign_in
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project push.project = project
push.file_name = 'file' push.file_name = 'file'
push.file_content = SecureRandom.hex(100000) push.file_content = SecureRandom.hex(100000)
end end
add_to_project user: @user_one add_to_project user: user_one
add_to_project user: @user_two add_to_project user: user_two
Resource::ProtectedBranch.unprotect_via_api! do |branch| Resource::ProtectedBranch.unprotect_via_api! do |branch|
branch.project = @project branch.project = project
branch.branch_name = 'master' branch.branch_name = project.default_branch
end end
end end
it 'locks a directory and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/557' do it 'locks a directory and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/557' do
push branch: 'master', file: 'directory/file', as_user: @user_one push branch: project.default_branch, file: 'directory/file', as_user: user_one
sign_out_and_sign_in_as user: @user_one sign_out_and_sign_in_as user: user_one
go_to_directory go_to_directory
click_lock click_lock
expect_error_on_push for_file: 'directory/file', as_user: @user_two expect_error_on_push for_file: 'directory/file', as_user: user_two
expect_no_error_on_push for_file: 'directory/file', as_user: @user_one expect_no_error_on_push for_file: 'directory/file', as_user: user_one
end end
it 'locks a file and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/558' do it 'locks a file and tries to push as a second user', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/558' do
sign_out_and_sign_in_as user: @user_one sign_out_and_sign_in_as user: user_one
go_to_file go_to_file
click_lock click_lock
expect_error_on_push as_user: @user_two expect_error_on_push as_user: user_two
expect_no_error_on_push as_user: @user_one expect_no_error_on_push as_user: user_one
end end
it 'checks file locked by other user to be disabled', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/556' do it 'checks file locked by other user to be disabled', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/556' do
go_to_file go_to_file
click_lock click_lock
sign_out_and_sign_in_as user: @user_one sign_out_and_sign_in_as user: user_one
go_to_file go_to_file
Page::File::Show.perform do |show| Page::File::Show.perform do |show|
...@@ -60,28 +62,28 @@ module QA ...@@ -60,28 +62,28 @@ module QA
end end
it 'creates a merge request and fails to merge', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/40125', type: :bug }, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/559' do it 'creates a merge request and fails to merge', quarantine: { issue: 'https://gitlab.com/gitlab-org/gitlab/issues/40125', type: :bug }, testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/559' do
push branch: 'test', as_user: @user_one push branch: 'test', as_user: user_one
merge_request = Resource::MergeRequest.fabricate_via_api! do |merge_request| merge_request = Resource::MergeRequest.fabricate_via_api! do |merge_request|
merge_request.project = @project merge_request.project = project
merge_request.source_branch = 'test' merge_request.source_branch = 'test'
merge_request.target_branch = 'master' merge_request.target_branch = project.default_branch
merge_request.no_preparation = true merge_request.no_preparation = true
end end
go_to_file go_to_file
click_lock click_lock
sign_out_and_sign_in_as user: @user_one sign_out_and_sign_in_as user: user_one
try_to_merge merge_request: merge_request try_to_merge merge_request: merge_request
Page::MergeRequest::Show.perform(&:wait_for_merge_request_error_message) Page::MergeRequest::Show.perform(&:wait_for_merge_request_error_message)
expect(page).to have_text("locked by #{admin_username}") expect(page).to have_text("locked by #{admin_username}")
end end
it 'locks a file and unlocks in list', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/555' do it 'locks a file and unlocks in list', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/555' do
sign_out_and_sign_in_as user: @user_one sign_out_and_sign_in_as user: user_one
go_to_file go_to_file
click_lock click_lock
@project.visit! project.visit!
Page::Project::Menu.perform(&:go_to_repository_locked_files) Page::Project::Menu.perform(&:go_to_repository_locked_files)
EE::Page::Project::PathLocks::Index.perform do |list| EE::Page::Project::PathLocks::Index.perform do |list|
...@@ -89,7 +91,7 @@ module QA ...@@ -89,7 +91,7 @@ module QA
list.unlock_file 'file' list.unlock_file 'file'
end end
expect_no_error_on_push as_user: @user_two expect_no_error_on_push as_user: user_two
end end
def try_to_merge(merge_request:) def try_to_merge(merge_request:)
...@@ -106,14 +108,14 @@ module QA ...@@ -106,14 +108,14 @@ module QA
end end
def go_to_file def go_to_file
@project.visit! project.visit!
Page::Project::Show.perform do |project_page| Page::Project::Show.perform do |project_page|
project_page.click_file 'file' project_page.click_file 'file'
end end
end end
def go_to_directory def go_to_directory
@project.visit! project.visit!
Page::Project::Show.perform do |project_page| Page::Project::Show.perform do |project_page|
project_page.click_file 'directory' project_page.click_file 'directory'
end end
...@@ -126,15 +128,15 @@ module QA ...@@ -126,15 +128,15 @@ module QA
def add_to_project(user:) def add_to_project(user:)
Resource::ProjectMember.fabricate_via_api! do |member| Resource::ProjectMember.fabricate_via_api! do |member|
member.user = user member.user = user
member.project = @project member.project = project
member.access_level = member.level[:developer] member.access_level = member.level[:developer]
end end
end end
def push(branch: 'master', file: 'file', as_user:) def push(branch: project.default_branch, file: 'file', as_user:)
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project push.project = project
push.new_branch = false unless branch != 'master' push.new_branch = false unless branch != project.default_branch
push.file_name = file push.file_name = file
push.file_content = SecureRandom.hex(100000) push.file_content = SecureRandom.hex(100000)
push.user = as_user push.user = as_user
...@@ -143,12 +145,12 @@ module QA ...@@ -143,12 +145,12 @@ module QA
end end
def expect_error_on_push(for_file: 'file', as_user:) def expect_error_on_push(for_file: 'file', as_user:)
expect { push branch: 'master', file: for_file, as_user: as_user }.to raise_error( expect { push branch: project.default_branch, file: for_file, as_user: as_user }.to raise_error(
QA::Support::Run::CommandError) QA::Support::Run::CommandError)
end end
def expect_no_error_on_push(for_file: 'file', as_user:) def expect_no_error_on_push(for_file: 'file', as_user:)
expect { push branch: 'master', file: for_file, as_user: as_user }.not_to raise_error expect { push branch: project.default_branch, file: for_file, as_user: as_user }.not_to raise_error
end end
def admin_username def admin_username
......
...@@ -10,7 +10,7 @@ module QA ...@@ -10,7 +10,7 @@ module QA
@file_name_limitation = 'denied_file' @file_name_limitation = 'denied_file'
@file_size_limitation = 1 @file_size_limitation = 1
@authors_email_limitation = %{(#{Regexp.escape(@creator.email)}|#{@root.email})} @authors_email_limitation = %{(#{Regexp.escape(@creator.email)}|#{@root.email})}
@branch_name_limitation = 'master' @branch_name_limitation = @project.default_branch
@needed_phrase_limitation = 'allowed commit' @needed_phrase_limitation = 'allowed commit'
@deny_message_phrase_limitation = 'denied commit' @deny_message_phrase_limitation = 'denied commit'
...@@ -89,7 +89,7 @@ module QA ...@@ -89,7 +89,7 @@ module QA
it 'restricts removal of tag', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/650' do it 'restricts removal of tag', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/650' do
tag = Resource::Tag.fabricate_via_api! do |tag| tag = Resource::Tag.fabricate_via_api! do |tag|
tag.project = @project tag.project = @project
tag.ref = 'master' tag.ref = @project.default_branch
tag.name = "test_tag_#{SecureRandom.hex(8)}" tag.name = "test_tag_#{SecureRandom.hex(8)}"
end end
...@@ -173,7 +173,7 @@ module QA ...@@ -173,7 +173,7 @@ module QA
Resource::Repository::ProjectPush.fabricate! do |push| Resource::Repository::ProjectPush.fabricate! do |push|
push.project = @project push.project = @project
push.commit_message = commit_message push.commit_message = commit_message
push.new_branch = branch != 'master' push.new_branch = branch != @project.default_branch
push.branch_name = branch push.branch_name = branch
push.user = user if user != @root push.user = user if user != @root
push.files = file if tag.nil? push.files = file if tag.nil?
...@@ -182,13 +182,13 @@ module QA ...@@ -182,13 +182,13 @@ module QA
end end
end end
def expect_no_error_on_push(commit_message: 'allowed commit', branch: 'master', file:, user: @creator, tag: nil, gpg: nil) def expect_no_error_on_push(commit_message: 'allowed commit', branch: @project.default_branch, file:, user: @creator, tag: nil, gpg: nil)
expect do expect do
push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg
end.not_to raise_error end.not_to raise_error
end end
def expect_error_on_push(commit_message: 'allowed commit', branch: 'master', file:, user: @creator, tag: nil, gpg: nil, error: nil) def expect_error_on_push(commit_message: 'allowed commit', branch: @project.default_branch, file:, user: @creator, tag: nil, gpg: nil, error: nil)
expect do expect do
push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg push commit_message: commit_message, branch: branch, file: file, user: user, tag: tag, gpg: gpg
end.to raise_error(QA::Support::Run::CommandError, /#{error}/) end.to raise_error(QA::Support::Run::CommandError, /#{error}/)
......
...@@ -63,7 +63,7 @@ module QA ...@@ -63,7 +63,7 @@ module QA
it 'creates a pipeline with merged results', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do it 'creates a pipeline with merged results', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/562' do
branch_name = "merged-results-#{SecureRandom.hex(8)}" branch_name = "merged-results-#{SecureRandom.hex(8)}"
# Create a branch that will be merged into master # Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project project_push.project = project
project_push.new_branch = true project_push.new_branch = true
...@@ -98,7 +98,7 @@ module QA ...@@ -98,7 +98,7 @@ module QA
it 'merges via a merge train', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/561' do it 'merges via a merge train', testcase: 'https://gitlab.com/gitlab-org/quality/testcases/-/issues/561' do
branch_name = "merge-train-#{SecureRandom.hex(8)}" branch_name = "merge-train-#{SecureRandom.hex(8)}"
# Create a branch that will be merged into master # Create a branch that will be merged into the default branch
Resource::Repository::ProjectPush.fabricate! do |project_push| Resource::Repository::ProjectPush.fabricate! do |project_push|
project_push.project = project project_push.project = project
project_push.new_branch = true project_push.new_branch = true
......
...@@ -46,9 +46,9 @@ module QA ...@@ -46,9 +46,9 @@ module QA
merge_request = Resource::MergeRequest.fabricate_via_api! do |mr| merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project mr.project = @project
mr.source_branch = 'secure-mr' mr.source_branch = 'secure-mr'
mr.target_branch = 'master' mr.target_branch = @project.default_branch
mr.source = @source mr.source = @source
mr.target = 'master' mr.target = @project.default_branch
mr.target_new_branch = false mr.target_new_branch = false
end end
......
...@@ -41,8 +41,8 @@ module QA ...@@ -41,8 +41,8 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr| @merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project mr.project = @project
mr.source_branch = 'license-management-mr' mr.source_branch = 'license-management-mr'
mr.target_branch = 'master' mr.target_branch = @project.default_branch
mr.target = 'master' mr.target = @project.default_branch
mr.file_name = 'gl-license-scanning-report.json' mr.file_name = 'gl-license-scanning-report.json'
mr.file_content = mr.file_content =
<<~FILE_UPDATE <<~FILE_UPDATE
......
...@@ -37,9 +37,9 @@ module QA ...@@ -37,9 +37,9 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr| @merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project mr.project = @project
mr.source_branch = 'secure-mr' mr.source_branch = 'secure-mr'
mr.target_branch = 'master' mr.target_branch = @project.default_branch
mr.source = @source mr.source = @source
mr.target = 'master' mr.target = @project.default_branch
mr.target_new_branch = false mr.target_new_branch = false
end end
......
...@@ -45,9 +45,9 @@ module QA ...@@ -45,9 +45,9 @@ module QA
@merge_request = Resource::MergeRequest.fabricate_via_api! do |mr| @merge_request = Resource::MergeRequest.fabricate_via_api! do |mr|
mr.project = @project mr.project = @project
mr.source_branch = 'secure-mr' mr.source_branch = 'secure-mr'
mr.target_branch = 'master' mr.target_branch = @project.default_branch
mr.source = @source mr.source = @source
mr.target = 'master' mr.target = @project.default_branch
mr.target_new_branch = false mr.target_new_branch = false
end end
......
...@@ -95,20 +95,20 @@ module QA ...@@ -95,20 +95,20 @@ module QA
def create_many_merge_requests def create_many_merge_requests
30.times do |i| 30.times do |i|
create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "branch#{i}", "master", "MR#{i}") create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "branch#{i}", Runtime::Env.default_branch, "MR#{i}")
end end
@urls[:mr_list_page] = @urls[:project_page] + "/merge_requests" @urls[:mr_list_page] = @urls[:project_page] + "/merge_requests"
STDOUT.puts "Created many MRs: #{@urls[:mr_list_page]}" STDOUT.puts "Created many MRs: #{@urls[:mr_list_page]}"
end end
def create_many_new_files def create_many_new_files
create_a_new_file_api_req("hello.txt", "master", "#{@group_name}%2F#{@project_name}", "hello", "my new content") create_a_new_file_api_req("hello.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "hello", "my new content")
30.times do |i| 30.times do |i|
create_a_new_file_api_req("hello#{i}.txt", "master", "#{@group_name}%2F#{@project_name}", "hello", "my new content") create_a_new_file_api_req("hello#{i}.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "hello", "my new content")
create_a_new_file_api_req("hello#{i}.txt", "branch#{i}", "#{@group_name}%2F#{@project_name}", "hello", "my new content") create_a_new_file_api_req("hello#{i}.txt", "branch#{i}", "#{@group_name}%2F#{@project_name}", "hello", "my new content")
end end
@urls[:files_page] = @urls[:project_page] + "/tree/master" @urls[:files_page] = @urls[:project_page] + "/tree/#{Runtime::Env.default_branch}"
STDOUT.puts "Added many new files: #{@urls[:files_page]}" STDOUT.puts "Added many new files: #{@urls[:files_page]}"
end end
...@@ -138,7 +138,7 @@ module QA ...@@ -138,7 +138,7 @@ module QA
16.times do |i| 16.times do |i|
faker_line_arr = Faker::Lorem.sentences(1500) faker_line_arr = Faker::Lorem.sentences(1500)
content = faker_line_arr.join("\n\r") content = faker_line_arr.join("\n\r")
create_a_new_file_api_req("hello#{i + 100}.txt", "master", "#{@group_name}%2F#{@project_name}", "Add hello#{i + 100}.txt", content) create_a_new_file_api_req("hello#{i + 100}.txt", Runtime::Env.default_branch, "#{@group_name}%2F#{@project_name}", "Add hello#{i + 100}.txt", content)
content_arr[i] = faker_line_arr content_arr[i] = faker_line_arr
end end
...@@ -151,7 +151,7 @@ module QA ...@@ -151,7 +151,7 @@ module QA
update_file_api_req("hello#{i + 100}.txt", "performance", "#{@group_name}%2F#{@project_name}", "Update hello#{i + 100}.txt", content) update_file_api_req("hello#{i + 100}.txt", "performance", "#{@group_name}%2F#{@project_name}", "Update hello#{i + 100}.txt", content)
end end
create_mr_response = create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "performance", "master", "Large_MR") create_mr_response = create_a_merge_request_api_req("#{@group_name}%2F#{@project_name}", "performance", Runtime::Env.default_branch, "Large_MR")
iid = JSON.parse(create_mr_response.body)["iid"] iid = JSON.parse(create_mr_response.body)["iid"]
diff_refs = JSON.parse(create_mr_response.body)["diff_refs"] diff_refs = JSON.parse(create_mr_response.body)["diff_refs"]
...@@ -200,7 +200,7 @@ module QA ...@@ -200,7 +200,7 @@ module QA
create_a_branch_api_req(branch_name, project_path) create_a_branch_api_req(branch_name, project_path)
create_a_new_file_api_req(file_name, branch_name, project_path, "Initial commit for new file", "Initial file content") create_a_new_file_api_req(file_name, branch_name, project_path, "Initial commit for new file", "Initial file content")
create_mr_response = create_a_merge_request_api_req(project_path, branch_name, "master", "MR with many commits-#{SecureRandom.hex(8)}") create_mr_response = create_a_merge_request_api_req(project_path, branch_name, Runtime::Env.default_branch, "MR with many commits-#{SecureRandom.hex(8)}")
@urls[:mr_with_many_commits] = JSON.parse(create_mr_response.body)["web_url"] @urls[:mr_with_many_commits] = JSON.parse(create_mr_response.body)["web_url"]
100.times do |i| 100.times do |i|
update_file_api_req(file_name, branch_name, project_path, Faker::Lorem.sentences(5).join(" "), Faker::Lorem.sentences(500).join("\n")) update_file_api_req(file_name, branch_name, project_path, Faker::Lorem.sentences(5).join(" "), Faker::Lorem.sentences(500).join("\n"))
...@@ -268,7 +268,7 @@ module QA ...@@ -268,7 +268,7 @@ module QA
def create_a_branch_api_req(branch_name, project_path_or_id) def create_a_branch_api_req(branch_name, project_path_or_id)
call_api(expected_response_code: 201) do call_api(expected_response_code: 201) do
post Runtime::API::Request.new(@api_client, "/projects/#{project_path_or_id}/repository/branches").url, "branch=#{branch_name}&ref=master" post Runtime::API::Request.new(@api_client, "/projects/#{project_path_or_id}/repository/branches").url, "branch=#{branch_name}&ref=#{Runtime::Env.default_branch}"
end end
end end
......
...@@ -110,7 +110,7 @@ RSpec.describe QA::Git::Repository do ...@@ -110,7 +110,7 @@ RSpec.describe QA::Git::Repository do
end end
describe '#push_changes' do describe '#push_changes' do
let(:branch) { 'master' } let(:branch) { QA::Runtime::Env.default_branch }
let(:call_method) { repository.push_changes } let(:call_method) { repository.push_changes }
let(:command) { "git push #{repo_uri_with_credentials} #{branch}" } let(:command) { "git push #{repo_uri_with_credentials} #{branch}" }
......
...@@ -6,6 +6,10 @@ RSpec.describe QA::Resource::Events::Project do ...@@ -6,6 +6,10 @@ RSpec.describe QA::Resource::Events::Project do
def api_get_path def api_get_path
'/foo' '/foo'
end end
def default_branch
'master'
end
end end
end end
...@@ -53,7 +57,7 @@ RSpec.describe QA::Resource::Events::Project do ...@@ -53,7 +57,7 @@ RSpec.describe QA::Resource::Events::Project do
end end
describe "#wait_for_push_new_branch" do describe "#wait_for_push_new_branch" do
it 'waits for a push to master if no branch is given' do it 'waits for a push to the default branch if no branch is given' do
expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed') expect(subject).to receive(:api_get_from).with('/foo/events?action=pushed')
expect { subject.wait_for_push_new_branch }.not_to raise_error expect { subject.wait_for_push_new_branch }.not_to raise_error
end end
......
...@@ -423,17 +423,17 @@ RSpec.describe QA::Specs::Helpers::Quarantine do ...@@ -423,17 +423,17 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
end end
end end
context 'when a pipeline triggered from master runs in gitlab-qa' do context 'when a pipeline triggered from the default branch runs in gitlab-qa' do
before do before do
stub_env('CI_PROJECT_NAME', 'gitlab-qa') stub_env('CI_PROJECT_NAME', 'gitlab-qa')
described_class.configure_rspec described_class.configure_rspec
end end
it 'runs on master pipelines' do it 'runs on default branch pipelines' do
group = describe_successfully do group = describe_successfully do
it('runs on master pipeline given a single pipeline', only: { pipeline: :master } ) {} it('runs on master pipeline given a single pipeline', only: { pipeline: :master } ) {}
it('runs in master given an array of pipelines', only: { pipeline: [:canary, :master] }) {} it('runs in master given an array of pipelines', only: { pipeline: [:canary, :master] }) {}
it('does not run in non-master pipelines', only: { pipeline: [:nightly, :not_nightly, :not_master] } ) {} it('does not run in non-default pipelines', only: { pipeline: [:nightly, :not_nightly, :not_master] } ) {}
end end
aggregate_failures do aggregate_failures do
......
...@@ -30,17 +30,17 @@ module QA ...@@ -30,17 +30,17 @@ module QA
) )
end end
# Require approval from code owners on master # Require approval from code owners on the default branch
# The default branch is already protected, and we can't update a protected branch via the API (yet) # The default branch is already protected, and we can't update a protected branch via the API (yet)
# so we unprotect it first and then protect it again with the desired parameters # so we unprotect it first and then protect it again with the desired parameters
Resource::ProtectedBranch.unprotect_via_api! do |protected_branch| Resource::ProtectedBranch.unprotect_via_api! do |protected_branch|
protected_branch.project = project protected_branch.project = project
protected_branch.branch_name = 'master' protected_branch.branch_name = project.default_branch
end end
Resource::ProtectedBranch.fabricate_via_api! do |protected_branch| Resource::ProtectedBranch.fabricate_via_api! do |protected_branch|
protected_branch.project = project protected_branch.project = project
protected_branch.branch_name = 'master' protected_branch.branch_name = project.default_branch
protected_branch.new_branch = false protected_branch.new_branch = false
protected_branch.require_code_owner_approval = true protected_branch.require_code_owner_approval = true
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