diff options
-rw-r--r-- | .gitlab-ci.yml | 1 | ||||
-rw-r--r-- | app/assets/javascripts/lib/utils/ajax_cache.js | 18 | ||||
-rw-r--r-- | app/assets/javascripts/lib/utils/cache.js | 19 | ||||
-rw-r--r-- | app/assets/javascripts/lib/utils/users_cache.js | 28 | ||||
-rw-r--r-- | app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js | 5 | ||||
-rw-r--r-- | app/controllers/projects/environments_controller.rb | 1 | ||||
-rw-r--r-- | changelogs/unreleased/zj-sort-env-folders.yml | 4 | ||||
-rw-r--r-- | config/gitlab.yml.example | 2 | ||||
-rw-r--r-- | doc/install/kubernetes/gitlab_chart.md | 6 | ||||
-rw-r--r-- | doc/install/kubernetes/gitlab_runner_chart.md | 3 | ||||
-rw-r--r-- | doc/install/kubernetes/index.md | 3 | ||||
-rw-r--r-- | spec/controllers/projects/environments_controller_spec.rb | 19 | ||||
-rw-r--r-- | spec/javascripts/filtered_search/services/recent_searches_service_spec.js | 52 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/cache_spec.js | 65 | ||||
-rw-r--r-- | spec/javascripts/lib/utils/users_cache_spec.js | 136 | ||||
-rw-r--r-- | spec/lib/gitlab/database/migration_helpers_spec.rb | 8 | ||||
-rw-r--r-- | spec/services/projects/propagate_service_template_spec.rb | 12 |
17 files changed, 329 insertions, 53 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 3af2d4adc13..638553d7bf7 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -63,6 +63,7 @@ stages: .only-master-and-ee-or-mysql: &only-master-and-ee-or-mysql only: - /mysql/ + - /-stable$/ - master@gitlab-org/gitlab-ce - master@gitlab/gitlabhq - tags@gitlab-org/gitlab-ce diff --git a/app/assets/javascripts/lib/utils/ajax_cache.js b/app/assets/javascripts/lib/utils/ajax_cache.js index cf030d613df..f1fe95e12e8 100644 --- a/app/assets/javascripts/lib/utils/ajax_cache.js +++ b/app/assets/javascripts/lib/utils/ajax_cache.js @@ -1,21 +1,11 @@ -class AjaxCache { +import Cache from './cache'; + +class AjaxCache extends Cache { constructor() { - this.internalStorage = { }; + super(); this.pendingRequests = { }; } - get(endpoint) { - return this.internalStorage[endpoint]; - } - - hasData(endpoint) { - return Object.prototype.hasOwnProperty.call(this.internalStorage, endpoint); - } - - remove(endpoint) { - delete this.internalStorage[endpoint]; - } - retrieve(endpoint) { if (this.hasData(endpoint)) { return Promise.resolve(this.get(endpoint)); diff --git a/app/assets/javascripts/lib/utils/cache.js b/app/assets/javascripts/lib/utils/cache.js new file mode 100644 index 00000000000..3141f1eeafc --- /dev/null +++ b/app/assets/javascripts/lib/utils/cache.js @@ -0,0 +1,19 @@ +class Cache { + constructor() { + this.internalStorage = { }; + } + + get(key) { + return this.internalStorage[key]; + } + + hasData(key) { + return Object.prototype.hasOwnProperty.call(this.internalStorage, key); + } + + remove(key) { + delete this.internalStorage[key]; + } +} + +export default Cache; diff --git a/app/assets/javascripts/lib/utils/users_cache.js b/app/assets/javascripts/lib/utils/users_cache.js new file mode 100644 index 00000000000..88f8a622c00 --- /dev/null +++ b/app/assets/javascripts/lib/utils/users_cache.js @@ -0,0 +1,28 @@ +import Api from '../../api'; +import Cache from './cache'; + +class UsersCache extends Cache { + retrieve(username) { + if (this.hasData(username)) { + return Promise.resolve(this.get(username)); + } + + return Api.users('', { username }) + .then((users) => { + if (!users.length) { + throw new Error(`User "${username}" could not be found!`); + } + + if (users.length > 1) { + throw new Error(`Expected username "${username}" to be unique!`); + } + + const user = users[0]; + this.internalStorage[username] = user; + return user; + }); + // missing catch is intentional, error handling depends on use case + } +} + +export default new UsersCache(); diff --git a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js index 06661b930e3..c07bd25e6fd 100644 --- a/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js +++ b/app/assets/javascripts/vue_merge_request_widget/stores/mr_widget_store.js @@ -4,7 +4,7 @@ import { getStateKey } from '../dependencies'; export default class MergeRequestStore { constructor(data) { - this.startingSha = data.diff_head_sha; + this.sha = data.diff_head_sha; this.setData(data); } @@ -16,7 +16,6 @@ export default class MergeRequestStore { this.targetBranch = data.target_branch; this.sourceBranch = data.source_branch; this.mergeStatus = data.merge_status; - this.sha = data.diff_head_sha; this.commitMessage = data.merge_commit_message; this.commitMessageWithDescription = data.merge_commit_message_with_description; this.commitsCount = data.commits_count; @@ -69,7 +68,7 @@ export default class MergeRequestStore { this.canMerge = !!data.merge_path; this.canCreateIssue = currentUser.can_create_issue || false; this.canCancelAutomaticMerge = !!data.cancel_merge_when_pipeline_succeeds_path; - this.hasSHAChanged = this.sha !== this.startingSha; + this.hasSHAChanged = this.sha !== data.diff_head_sha; this.canBeMerged = data.can_be_merged || false; // Cherry-pick and Revert actions related diff --git a/app/controllers/projects/environments_controller.rb b/app/controllers/projects/environments_controller.rb index fd57afbd05f..efe83776834 100644 --- a/app/controllers/projects/environments_controller.rb +++ b/app/controllers/projects/environments_controller.rb @@ -31,6 +31,7 @@ class Projects::EnvironmentsController < Projects::ApplicationController def folder folder_environments = project.environments.where(environment_type: params[:id]) @environments = folder_environments.with_state(params[:scope] || :available) + .order(:name) respond_to do |format| format.html diff --git a/changelogs/unreleased/zj-sort-env-folders.yml b/changelogs/unreleased/zj-sort-env-folders.yml new file mode 100644 index 00000000000..b3ca97aef94 --- /dev/null +++ b/changelogs/unreleased/zj-sort-env-folders.yml @@ -0,0 +1,4 @@ +--- +title: Sort folder for environments +merge_request: +author: diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example index 14d99c243fc..a727f7e2fa3 100644 --- a/config/gitlab.yml.example +++ b/config/gitlab.yml.example @@ -182,7 +182,7 @@ production: &base cron: "0 * * * *" # Execute scheduled triggers pipeline_schedule_worker: - cron: "0 */12 * * *" + cron: "19 * * * *" # Remove expired build artifacts expire_build_artifacts_worker: cron: "50 * * * *" diff --git a/doc/install/kubernetes/gitlab_chart.md b/doc/install/kubernetes/gitlab_chart.md index 2d7edbe16e4..39ff4f8c1b8 100644 --- a/doc/install/kubernetes/gitlab_chart.md +++ b/doc/install/kubernetes/gitlab_chart.md @@ -1,4 +1,7 @@ # GitLab Helm Chart +> Officially supported cloud providers are Google Container Service and Azure Container Service. + +> Officially supported schedulers are Kubernetes and Terraform. The `gitlab` Helm chart deploys GitLab into your Kubernetes cluster. @@ -14,7 +17,7 @@ This chart includes the following: ## Prerequisites -- _At least_ 3 GB of RAM available on your cluster, in chunks of 1 GB +- _At least_ 3 GB of RAM available on your cluster, in chunks of 1 GB. 41GB of storage and 2 CPU are also required. - Kubernetes 1.4+ with Beta APIs enabled - [Persistent Volume](https://kubernetes.io/docs/concepts/storage/persistent-volumes/) provisioner support in the underlying infrastructure - The ability to point a DNS entry or URL at your GitLab install @@ -387,6 +390,7 @@ ingress: ``` ## Installing GitLab using the Helm Chart +> You may see a temporary error message `SchedulerPredicates failed due to PersistentVolumeClaim is not bound` while storage provisions. Once the storage provisions, the pods will automatically restart. This may take a couple minutes depending on your cloud provider. If the error persists, please review the [prerequisites](#prerequisites) to ensure you have enough RAM, CPU, and storage. Once you [have configured](#configuration) GitLab in your `values.yml` file, run the following: diff --git a/doc/install/kubernetes/gitlab_runner_chart.md b/doc/install/kubernetes/gitlab_runner_chart.md index dbd9ae3f70c..305b4593c73 100644 --- a/doc/install/kubernetes/gitlab_runner_chart.md +++ b/doc/install/kubernetes/gitlab_runner_chart.md @@ -1,4 +1,7 @@ # GitLab Runner Helm Chart +> Officially supported cloud providers are Google Container Service and Azure Container Service. + +> Officially supported schedulers are Kubernetes and Terraform. The `gitlab-runner` Helm chart deploys a GitLab Runner instance into your Kubernetes cluster. diff --git a/doc/install/kubernetes/index.md b/doc/install/kubernetes/index.md index cae5837a12b..88c56a1d17c 100644 --- a/doc/install/kubernetes/index.md +++ b/doc/install/kubernetes/index.md @@ -1,5 +1,6 @@ -# Installing GitLab in Kubernetes +# Installing GitLab on Kubernetes > Officially supported cloud providers are Google Container Service and Azure Container Service. + > Officially supported schedulers are Kubernetes and Terraform. The easiest method to deploy GitLab in [Kubernetes](https://kubernetes.io/) is diff --git a/spec/controllers/projects/environments_controller_spec.rb b/spec/controllers/projects/environments_controller_spec.rb index c0f8c36a018..20f99b209eb 100644 --- a/spec/controllers/projects/environments_controller_spec.rb +++ b/spec/controllers/projects/environments_controller_spec.rb @@ -1,25 +1,25 @@ require 'spec_helper' describe Projects::EnvironmentsController do - let(:user) { create(:user) } - let(:project) { create(:empty_project) } + set(:user) { create(:user) } + set(:project) { create(:empty_project) } - let(:environment) do + set(:environment) do create(:environment, name: 'production', project: project) end before do - project.team << [user, :master] + project.add_master(user) sign_in(user) end describe 'GET index' do - context 'when standardrequest has been made' do + context 'when a request for the HTML is made' do it 'responds with status code 200' do get :index, environment_params - expect(response).to be_ok + expect(response).to have_http_status(:ok) end end @@ -84,6 +84,9 @@ describe Projects::EnvironmentsController do create(:environment, project: project, name: 'staging-1.0/review', state: :available) + create(:environment, project: project, + name: 'staging-1.0/zzz', + state: :available) end context 'when using default format' do @@ -98,7 +101,7 @@ describe Projects::EnvironmentsController do end context 'when using JSON format' do - it 'responds with JSON' do + it 'sorts the subfolders lexicographically' do get :folder, namespace_id: project.namespace, project_id: project, id: 'staging-1.0', @@ -108,6 +111,8 @@ describe Projects::EnvironmentsController do expect(response).not_to render_template 'folder' expect(json_response['environments'][0]) .to include('name' => 'staging-1.0/review') + expect(json_response['environments'][1]) + .to include('name' => 'staging-1.0/zzz') end end end diff --git a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js b/spec/javascripts/filtered_search/services/recent_searches_service_spec.js index 31fa478804a..c293c0afa97 100644 --- a/spec/javascripts/filtered_search/services/recent_searches_service_spec.js +++ b/spec/javascripts/filtered_search/services/recent_searches_service_spec.js @@ -1,6 +1,5 @@ -/* eslint-disable promise/catch-or-return */ - import RecentSearchesService from '~/filtered_search/services/recent_searches_service'; +import RecentSearchesServiceError from '~/filtered_search/services/recent_searches_service_error'; import AccessorUtilities from '~/lib/utils/accessor'; describe('RecentSearchesService', () => { @@ -22,11 +21,9 @@ describe('RecentSearchesService', () => { fetchItemsPromise .then((items) => { expect(items).toEqual([]); - done(); }) - .catch((err) => { - done.fail('Shouldn\'t reject with empty localStorage key', err); - }); + .then(done) + .catch(done.fail); }); it('should reject when unable to parse', (done) => { @@ -34,19 +31,24 @@ describe('RecentSearchesService', () => { const fetchItemsPromise = service.fetch(); fetchItemsPromise + .then(done.fail) .catch((error) => { expect(error).toEqual(jasmine.any(SyntaxError)); - done(); - }); + }) + .then(done) + .catch(done.fail); }); it('should reject when service is unavailable', (done) => { RecentSearchesService.isAvailable.and.returnValue(false); - service.fetch().catch((error) => { - expect(error).toEqual(jasmine.any(Error)); - done(); - }); + service.fetch() + .then(done.fail) + .catch((error) => { + expect(error).toEqual(jasmine.any(Error)); + }) + .then(done) + .catch(done.fail); }); it('should return items from localStorage', (done) => { @@ -56,8 +58,9 @@ describe('RecentSearchesService', () => { fetchItemsPromise .then((items) => { expect(items).toEqual(['foo', 'bar']); - done(); - }); + }) + .then(done) + .catch(done.fail); }); describe('if .isAvailable returns `false`', () => { @@ -65,12 +68,17 @@ describe('RecentSearchesService', () => { RecentSearchesService.isAvailable.and.returnValue(false); spyOn(window.localStorage, 'getItem'); - - RecentSearchesService.prototype.fetch(); }); - it('should not call .getItem', () => { - expect(window.localStorage.getItem).not.toHaveBeenCalled(); + it('should not call .getItem', (done) => { + RecentSearchesService.prototype.fetch() + .then(done.fail) + .catch((err) => { + expect(err).toEqual(new RecentSearchesServiceError()); + expect(window.localStorage.getItem).not.toHaveBeenCalled(); + }) + .then(done) + .catch(done.fail); }); }); }); @@ -105,11 +113,11 @@ describe('RecentSearchesService', () => { RecentSearchesService.isAvailable.and.returnValue(true); spyOn(JSON, 'stringify').and.returnValue(searchesString); - - RecentSearchesService.prototype.save.call(recentSearchesService); }); it('should call .setItem', () => { + RecentSearchesService.prototype.save.call(recentSearchesService); + expect(window.localStorage.setItem).toHaveBeenCalledWith(localStorageKey, searchesString); }); }); @@ -117,11 +125,11 @@ describe('RecentSearchesService', () => { describe('if .isAvailable returns `false`', () => { beforeEach(() => { RecentSearchesService.isAvailable.and.returnValue(false); - - RecentSearchesService.prototype.save(); }); it('should not call .setItem', () => { + RecentSearchesService.prototype.save(); + expect(window.localStorage.setItem).not.toHaveBeenCalled(); }); }); diff --git a/spec/javascripts/lib/utils/cache_spec.js b/spec/javascripts/lib/utils/cache_spec.js new file mode 100644 index 00000000000..2fe02a7592c --- /dev/null +++ b/spec/javascripts/lib/utils/cache_spec.js @@ -0,0 +1,65 @@ +import Cache from '~/lib/utils/cache'; + +describe('Cache', () => { + const dummyKey = 'just some key'; + const dummyValue = 'more than a value'; + let cache; + + beforeEach(() => { + cache = new Cache(); + }); + + describe('get', () => { + it('return cached data', () => { + cache.internalStorage[dummyKey] = dummyValue; + + expect(cache.get(dummyKey)).toBe(dummyValue); + }); + + it('returns undefined for missing data', () => { + expect(cache.internalStorage[dummyKey]).toBe(undefined); + expect(cache.get(dummyKey)).toBe(undefined); + }); + }); + + describe('hasData', () => { + it('return true for cached data', () => { + cache.internalStorage[dummyKey] = dummyValue; + + expect(cache.hasData(dummyKey)).toBe(true); + }); + + it('returns false for missing data', () => { + expect(cache.internalStorage[dummyKey]).toBe(undefined); + expect(cache.hasData(dummyKey)).toBe(false); + }); + }); + + describe('remove', () => { + it('removes data from cache', () => { + cache.internalStorage[dummyKey] = dummyValue; + + cache.remove(dummyKey); + + expect(cache.internalStorage[dummyKey]).toBe(undefined); + }); + + it('does nothing for missing data', () => { + expect(cache.internalStorage[dummyKey]).toBe(undefined); + + cache.remove(dummyKey); + + expect(cache.internalStorage[dummyKey]).toBe(undefined); + }); + + it('does not remove wrong data', () => { + cache.internalStorage[dummyKey] = dummyValue; + cache.internalStorage[dummyKey + dummyKey] = dummyValue + dummyValue; + + cache.remove(dummyKey); + + expect(cache.internalStorage[dummyKey]).toBe(undefined); + expect(cache.internalStorage[dummyKey + dummyKey]).toBe(dummyValue + dummyValue); + }); + }); +}); diff --git a/spec/javascripts/lib/utils/users_cache_spec.js b/spec/javascripts/lib/utils/users_cache_spec.js new file mode 100644 index 00000000000..ec6ea35952b --- /dev/null +++ b/spec/javascripts/lib/utils/users_cache_spec.js @@ -0,0 +1,136 @@ +import Api from '~/api'; +import UsersCache from '~/lib/utils/users_cache'; + +describe('UsersCache', () => { + const dummyUsername = 'win'; + const dummyUser = 'has a farm'; + + beforeEach(() => { + UsersCache.internalStorage = { }; + }); + + describe('get', () => { + it('returns undefined for empty cache', () => { + expect(UsersCache.internalStorage).toEqual({ }); + + const user = UsersCache.get(dummyUsername); + + expect(user).toBe(undefined); + }); + + it('returns undefined for missing user', () => { + UsersCache.internalStorage['no body'] = 'no data'; + + const user = UsersCache.get(dummyUsername); + + expect(user).toBe(undefined); + }); + + it('returns matching user', () => { + UsersCache.internalStorage[dummyUsername] = dummyUser; + + const user = UsersCache.get(dummyUsername); + + expect(user).toBe(dummyUser); + }); + }); + + describe('hasData', () => { + it('returns false for empty cache', () => { + expect(UsersCache.internalStorage).toEqual({ }); + + expect(UsersCache.hasData(dummyUsername)).toBe(false); + }); + + it('returns false for missing user', () => { + UsersCache.internalStorage['no body'] = 'no data'; + + expect(UsersCache.hasData(dummyUsername)).toBe(false); + }); + + it('returns true for matching user', () => { + UsersCache.internalStorage[dummyUsername] = dummyUser; + + expect(UsersCache.hasData(dummyUsername)).toBe(true); + }); + }); + + describe('remove', () => { + it('does nothing if cache is empty', () => { + expect(UsersCache.internalStorage).toEqual({ }); + + UsersCache.remove(dummyUsername); + + expect(UsersCache.internalStorage).toEqual({ }); + }); + + it('does nothing if cache contains no matching data', () => { + UsersCache.internalStorage['no body'] = 'no data'; + + UsersCache.remove(dummyUsername); + + expect(UsersCache.internalStorage['no body']).toBe('no data'); + }); + + it('removes matching data', () => { + UsersCache.internalStorage[dummyUsername] = dummyUser; + + UsersCache.remove(dummyUsername); + + expect(UsersCache.internalStorage).toEqual({ }); + }); + }); + + describe('retrieve', () => { + let apiSpy; + + beforeEach(() => { + spyOn(Api, 'users').and.callFake((query, options) => apiSpy(query, options)); + }); + + it('stores and returns data from API call if cache is empty', (done) => { + apiSpy = (query, options) => { + expect(query).toBe(''); + expect(options).toEqual({ username: dummyUsername }); + return Promise.resolve([dummyUser]); + }; + + UsersCache.retrieve(dummyUsername) + .then((user) => { + expect(user).toBe(dummyUser); + expect(UsersCache.internalStorage[dummyUsername]).toBe(dummyUser); + }) + .then(done) + .catch(done.fail); + }); + + it('returns undefined if Ajax call fails and cache is empty', (done) => { + const dummyError = new Error('server exploded'); + apiSpy = (query, options) => { + expect(query).toBe(''); + expect(options).toEqual({ username: dummyUsername }); + return Promise.reject(dummyError); + }; + + UsersCache.retrieve(dummyUsername) + .then(user => fail(`Received unexpected user: ${JSON.stringify(user)}`)) + .catch((error) => { + expect(error).toBe(dummyError); + }) + .then(done) + .catch(done.fail); + }); + + it('makes no Ajax call if matching data exists', (done) => { + UsersCache.internalStorage[dummyUsername] = dummyUser; + apiSpy = () => fail(new Error('expected no Ajax call!')); + + UsersCache.retrieve(dummyUsername) + .then((user) => { + expect(user).toBe(dummyUser); + }) + .then(done) + .catch(done.fail); + }); + }); +}); diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index dfa3ae9142e..bd5ac6142be 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -247,6 +247,14 @@ describe Gitlab::Database::MigrationHelpers, lib: true do expect(Project.where(archived: true).count).to eq(1) end end + + context 'when the value is Arel.sql (Arel::Nodes::SqlLiteral)' do + it 'updates the value as a SQL expression' do + model.update_column_in_batches(:projects, :star_count, Arel.sql('1+1')) + + expect(Project.sum(:star_count)).to eq(2 * Project.count) + end + end end describe '#add_column_with_default' do diff --git a/spec/services/projects/propagate_service_template_spec.rb b/spec/services/projects/propagate_service_template_spec.rb index 90eff3bbc1e..8a6a9f09f74 100644 --- a/spec/services/projects/propagate_service_template_spec.rb +++ b/spec/services/projects/propagate_service_template_spec.rb @@ -71,14 +71,18 @@ describe Projects::PropagateServiceTemplate, services: true do end describe 'bulk update' do - it 'creates services for all projects' do - project_total = 5 + let(:project_total) { 5 } + + before do stub_const 'Projects::PropagateServiceTemplate::BATCH_SIZE', 3 project_total.times { create(:empty_project) } - expect { described_class.propagate(service_template) }. - to change { Service.count }.by(project_total + 1) + described_class.propagate(service_template) + end + + it 'creates services for all projects' do + expect(Service.all.reload.count).to eq(project_total + 2) end end |