From a7f1e2ebd6c023d1e5aff8627715d8dcc8d54707 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Mon, 14 Sep 2020 06:09:28 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- app/assets/javascripts/gpg_badges.js | 3 +- ...r-app-assets-javascripts-gpg_badges-js.yml | 5 ++ lib/gitlab/ci/features.rb | 2 - qa/qa/git/repository.rb | 4 ++ qa/qa/resource/project.rb | 1 + qa/qa/runtime/application_settings.rb | 56 ++++++++--------- .../default_branch_name_setting_spec.rb | 62 +++++++++++++++++++ qa/spec/runtime/application_settings_spec.rb | 6 +- spec/frontend/gpg_badges_spec.js | 2 +- 9 files changed, 105 insertions(+), 36 deletions(-) create mode 100644 changelogs/unreleased/202273-migrate-spinner-for-app-assets-javascripts-gpg_badges-js.yml create mode 100644 qa/qa/specs/features/api/3_create/repository/default_branch_name_setting_spec.rb diff --git a/app/assets/javascripts/gpg_badges.js b/app/assets/javascripts/gpg_badges.js index 099c46f4b8d..e0f64c8e843 100644 --- a/app/assets/javascripts/gpg_badges.js +++ b/app/assets/javascripts/gpg_badges.js @@ -13,7 +13,8 @@ export default class GpgBadges { const badges = $('.js-loading-gpg-badge'); - badges.html(''); + badges.html(''); + badges.children().attr('aria-label', __('Loading')); const displayError = () => createFlash(__('An error occurred while loading commit signatures')); diff --git a/changelogs/unreleased/202273-migrate-spinner-for-app-assets-javascripts-gpg_badges-js.yml b/changelogs/unreleased/202273-migrate-spinner-for-app-assets-javascripts-gpg_badges-js.yml new file mode 100644 index 00000000000..6b9a2974846 --- /dev/null +++ b/changelogs/unreleased/202273-migrate-spinner-for-app-assets-javascripts-gpg_badges-js.yml @@ -0,0 +1,5 @@ +--- +title: Migrate '.fa-spinner' to '.spinner' for 'app/assets/javascripts/gpg_badges.js' +merge_request: 41136 +author: Gilang Gumilar +type: changed diff --git a/lib/gitlab/ci/features.rb b/lib/gitlab/ci/features.rb index f50014a9ae3..c792b985381 100644 --- a/lib/gitlab/ci/features.rb +++ b/lib/gitlab/ci/features.rb @@ -77,5 +77,3 @@ module Gitlab end end end - -::Gitlab::Ci::Features.prepend_if_ee('::EE::Gitlab::Ci::Features') diff --git a/qa/qa/git/repository.rb b/qa/qa/git/repository.rb index e0fcb9b0599..035946b8471 100644 --- a/qa/qa/git/repository.rb +++ b/qa/qa/git/repository.rb @@ -118,6 +118,10 @@ module QA run(%Q{git config user.signingkey #{@gpg_key_id} && git config gpg.program $(command -v gpg) && git commit -S -m "#{message}"}).to_s end + def current_branch + run("git rev-parse --abbrev-ref HEAD").to_s + end + def push_changes(branch = 'master') run("git push #{uri} #{branch}", max_attempts: 3).to_s end diff --git a/qa/qa/resource/project.rb b/qa/qa/resource/project.rb index eba8ada50ab..a6bc24fdd04 100644 --- a/qa/qa/resource/project.rb +++ b/qa/qa/resource/project.rb @@ -13,6 +13,7 @@ module QA attr_writer :initialize_with_readme attr_writer :auto_devops_enabled + attribute :default_branch attribute :id attribute :name attribute :add_name_uuid diff --git a/qa/qa/runtime/application_settings.rb b/qa/qa/runtime/application_settings.rb index df6323f9a48..c78f4258721 100644 --- a/qa/qa/runtime/application_settings.rb +++ b/qa/qa/runtime/application_settings.rb @@ -2,43 +2,39 @@ module QA module Runtime - module ApplicationSettings - extend self - extend Support::Api + class ApplicationSettings + class << self + include Support::Api - APPLICATION_SETTINGS_PATH = '/application/settings' + APPLICATION_SETTINGS_PATH = '/application/settings' - # Set a GitLab application setting - # Example: - # #set({ allow_local_requests_from_web_hooks_and_services: true }) - # #set(allow_local_requests_from_web_hooks_and_services: true) - # https://docs.gitlab.com/ee/api/settings.html - def set_application_settings(**application_settings) - QA::Runtime::Logger.info("Setting application settings: #{application_settings}") - r = put(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url, **application_settings) - raise "Couldn't set application settings #{application_settings.inspect}" unless r.code == QA::Support::Api::HTTP_STATUS_OK - end + # Set a GitLab application setting + # Example: + # #set({ allow_local_requests_from_web_hooks_and_services: true }) + # #set(allow_local_requests_from_web_hooks_and_services: true) + # https://docs.gitlab.com/ee/api/settings.html + def set_application_settings(**application_settings) + @original_application_settings = get_application_settings - def get_application_settings - parse_body(get(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url)) - end + QA::Runtime::Logger.info("Setting application settings: #{application_settings}") + r = put(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url, **application_settings) + raise "Couldn't set application settings #{application_settings.inspect}" unless r.code == QA::Support::Api::HTTP_STATUS_OK + end - private + def get_application_settings + parse_body(get(Runtime::API::Request.new(api_client, APPLICATION_SETTINGS_PATH).url)) + end - def api_client - @api_client ||= begin - return Runtime::API::Client.new(:gitlab, personal_access_token: Runtime::Env.admin_personal_access_token) if Runtime::Env.admin_personal_access_token + def restore_application_settings(*application_settings_keys) + set_application_settings(@original_application_settings.slice(*application_settings_keys)) + end - user = Resource::User.fabricate_via_api! do |user| - user.username = Runtime::User.admin_username - user.password = Runtime::User.admin_password - end + private - unless user.admin? - raise "Administrator access is required to set application settings. User '#{user.username}' is not an administrator." - end - - Runtime::API::Client.new(:gitlab, user: user) + def api_client + @api_client ||= Runtime::API::Client.as_admin + rescue AuthorizationError => e + raise "Administrator access is required to set application settings. #{e.message}" end end end diff --git a/qa/qa/specs/features/api/3_create/repository/default_branch_name_setting_spec.rb b/qa/qa/specs/features/api/3_create/repository/default_branch_name_setting_spec.rb new file mode 100644 index 00000000000..af155b22618 --- /dev/null +++ b/qa/qa/specs/features/api/3_create/repository/default_branch_name_setting_spec.rb @@ -0,0 +1,62 @@ +# frozen_string_literal: true + +require 'securerandom' + +module QA + RSpec.describe 'Create' do + describe 'Default branch name instance setting', :requires_admin, :skip_live_env do + before(:context) do + Runtime::ApplicationSettings.set_application_settings(default_branch_name: 'main') + end + + after(:context) do + Runtime::ApplicationSettings.restore_application_settings(:default_branch_name) + end + + it 'sets the default branch name for a new project' do + project = Resource::Project.fabricate_via_api! do |project| + project.name = "default-branch-name" + project.initialize_with_readme = true + end + + # It takes a moment to create the project. We wait until we + # know it exists before we try to clone it + Support::Waiter.wait_until { project.has_file?('README.md') } + + Git::Repository.perform do |repository| + repository.uri = project.repository_http_location.uri + repository.use_default_credentials + repository.clone + + expect(repository.current_branch).to eq('main') + end + end + + it 'allows a project to be created via the CLI with a different default branch name' do + project_name = "default-branch-name-via-cli-#{SecureRandom.hex(8)}" + group = Resource::Group.fabricate_via_api! + + Git::Repository.perform do |repository| + repository.init_repository + repository.uri = "#{Runtime::Scenario.gitlab_address}/#{group.full_path}/#{project_name}" + repository.use_default_credentials + repository.configure_identity('GitLab QA', 'root@gitlab.com') + repository.checkout('trunk', new_branch: true) + repository.commit_file('README.md', 'Created via the CLI', 'initial commit via CLI') + repository.push_changes('trunk') + end + + project = Resource::Project.fabricate_via_api! do |project| + project.add_name_uuid = false + project.name = project_name + project.group = group + end + + expect(project.default_branch).to eq('trunk') + expect(project).to have_file('README.md') + expect(project.commits.map { |commit| commit[:message].chomp }) + .to include('initial commit via CLI') + end + end + end +end diff --git a/qa/spec/runtime/application_settings_spec.rb b/qa/spec/runtime/application_settings_spec.rb index fce0361aee0..e48214b22e6 100644 --- a/qa/spec/runtime/application_settings_spec.rb +++ b/qa/spec/runtime/application_settings_spec.rb @@ -16,12 +16,14 @@ describe QA::Runtime::ApplicationSettings do .with(api_client, '/application/settings') .and_return(request) + expect(described_class).to receive(:get_application_settings) + expect(described_class) .to receive(:put) .with(request.url, { allow_local_requests_from_web_hooks_and_services: true }) .and_return(Struct.new(:code).new(200)) - subject.set_application_settings(allow_local_requests_from_web_hooks_and_services: true) + described_class.set_application_settings(allow_local_requests_from_web_hooks_and_services: true) end end @@ -37,7 +39,7 @@ describe QA::Runtime::ApplicationSettings do .with(request.url) .and_return(get_response) - subject.get_application_settings + described_class.get_application_settings end end end diff --git a/spec/frontend/gpg_badges_spec.js b/spec/frontend/gpg_badges_spec.js index 809cc5c88e2..644b687aa19 100644 --- a/spec/frontend/gpg_badges_spec.js +++ b/spec/frontend/gpg_badges_spec.js @@ -68,7 +68,7 @@ describe('GpgBadges', () => { GpgBadges.fetch() .then(() => { expect(document.querySelector('.js-loading-gpg-badge:empty')).toBe(null); - const spinners = document.querySelectorAll('.js-loading-gpg-badge i.fa.fa-spinner.fa-spin'); + const spinners = document.querySelectorAll('.js-loading-gpg-badge span.gl-spinner'); expect(spinners.length).toBe(1); done();