summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.rubocop.yml4
-rw-r--r--.rubocop_todo.yml5
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock4
-rw-r--r--app/assets/javascripts/blob/file_template_mediator.js241
-rw-r--r--app/assets/javascripts/blob/file_template_selector.js60
-rw-r--r--app/assets/javascripts/blob/template_selector.js (renamed from app/assets/javascripts/blob/template_selectors/template_selector.js)0
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selector.js9
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selectors.js23
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_dockerfile_selector.js9
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_dockerfile_selectors.js23
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_gitignore_selector.js9
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_gitignore_selectors.js23
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_license_selector.js13
-rw-r--r--app/assets/javascripts/blob/template_selectors/blob_license_selectors.js24
-rw-r--r--app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js32
-rw-r--r--app/assets/javascripts/blob/template_selectors/dockerfile_selector.js32
-rw-r--r--app/assets/javascripts/blob/template_selectors/gitignore_selector.js31
-rw-r--r--app/assets/javascripts/blob/template_selectors/license_selector.js38
-rw-r--r--app/assets/javascripts/blob/template_selectors/type_selector.js25
-rw-r--r--app/assets/javascripts/blob_edit/blob_bundle.js3
-rw-r--r--app/assets/javascripts/blob_edit/edit_blob.js38
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js27
-rw-r--r--app/assets/javascripts/templates/issuable_template_selector.js2
-rw-r--r--app/assets/stylesheets/pages/editor.scss142
-rw-r--r--app/controllers/admin/abuse_reports_controller.rb1
-rw-r--r--app/controllers/admin/application_settings_controller.rb1
-rw-r--r--app/controllers/groups/group_members_controller.rb1
-rw-r--r--app/controllers/projects/git_http_controller.rb2
-rwxr-xr-xapp/controllers/projects/merge_requests_controller.rb1
-rw-r--r--app/controllers/projects/milestones_controller.rb2
-rw-r--r--app/controllers/registrations_controller.rb4
-rw-r--r--app/controllers/sessions_controller.rb2
-rw-r--r--app/mailers/base_mailer.rb4
-rw-r--r--app/models/application_setting.rb7
-rw-r--r--app/models/ci/pipeline.rb2
-rw-r--r--app/models/milestone.rb2
-rw-r--r--app/models/repository.rb8
-rw-r--r--app/models/service.rb2
-rw-r--r--app/services/todo_service.rb2
-rw-r--r--app/services/users/destroy_service.rb4
-rw-r--r--app/views/admin/application_settings/_form.html.haml14
-rw-r--r--app/views/projects/blob/_editor.html.haml20
-rw-r--r--app/views/projects/blob/_template_selectors.html.haml17
-rw-r--r--app/views/projects/blob/edit.html.haml7
-rw-r--r--app/views/projects/blob/new.html.haml8
-rw-r--r--changelogs/unreleased/22303-symbolic-in-tree.yml4
-rw-r--r--changelogs/unreleased/25332-make-file-templates-easy-to-use-and-discover.yml4
-rw-r--r--changelogs/unreleased/29541-fix-github-importer-deleted-fork.yml4
-rw-r--r--changelogs/unreleased/29669-redirect-referer-params.yml4
-rw-r--r--changelogs/unreleased/30264-fix-vue-pagination.yml5
-rw-r--r--changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml4
-rw-r--r--changelogs/unreleased/introduce-polling-interval-multiplier.yml4
-rw-r--r--changelogs/unreleased/namespace-race-condition.yml4
-rw-r--r--changelogs/unreleased/sh-fix-destroy-user-race.yml5
-rw-r--r--changelogs/unreleased/sh-relax-wiki-slug-constraint.yml4
-rw-r--r--changelogs/unreleased/style-proc-cop.yml4
-rw-r--r--changelogs/unreleased/todo-update-order.yml4
-rw-r--r--config/gitlab.yml.example2
-rw-r--r--config/initializers/8_gitaly.rb2
-rw-r--r--config/routes/wiki.rb4
-rw-r--r--db/migrate/20170329124448_add_polling_interval_multiplier_to_application_settings.rb33
-rw-r--r--db/schema.rb3
-rw-r--r--doc/api/settings.md7
-rw-r--r--doc/ci/variables/README.md2
-rw-r--r--features/steps/dashboard/todos.rb3
-rw-r--r--lib/api/api_guard.rb2
-rw-r--r--lib/api/entities.rb3
-rw-r--r--lib/api/settings.rb3
-rw-r--r--lib/api/users.rb2
-rw-r--r--lib/gitlab/etag_caching/middleware.rb11
-rw-r--r--lib/gitlab/git/repository.rb5
-rw-r--r--lib/gitlab/git/tree.rb2
-rw-r--r--lib/gitlab/gitaly_client.rb4
-rw-r--r--lib/gitlab/gitaly_client/commit.rb14
-rw-r--r--lib/gitlab/github_import/branch_formatter.rb8
-rw-r--r--lib/gitlab/github_import/pull_request_formatter.rb33
-rw-r--r--lib/gitlab/ldap/config.rb4
-rw-r--r--lib/gitlab/polling_interval.rb22
-rw-r--r--lib/gitlab/shell.rb5
-rw-r--r--lib/gitlab/workhorse.rb28
-rw-r--r--spec/controllers/registrations_controller_spec.rb16
-rw-r--r--spec/controllers/sessions_controller_spec.rb16
-rw-r--r--spec/features/auto_deploy_spec.rb4
-rw-r--r--spec/features/projects/blobs/user_create_spec.rb2
-rw-r--r--spec/features/projects/files/project_owner_creates_license_file_spec.rb4
-rw-r--r--spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb4
-rw-r--r--spec/features/projects/files/template_type_dropdown_spec.rb135
-rw-r--r--spec/features/projects/files/undo_template_spec.rb67
-rw-r--r--spec/finders/issues_finder_spec.rb2
-rw-r--r--spec/initializers/trusted_proxies_spec.rb2
-rw-r--r--spec/javascripts/environments/environment_spec.js4
-rw-r--r--spec/javascripts/lib/utils/common_utils_spec.js49
-rw-r--r--spec/javascripts/vue_shared/components/table_pagination_spec.js4
-rw-r--r--spec/lib/gitlab/etag_caching/middleware_spec.rb13
-rw-r--r--spec/lib/gitlab/git/tree_spec.rb1
-rw-r--r--spec/lib/gitlab/gitaly_client_spec.rb26
-rw-r--r--spec/lib/gitlab/github_import/importer_spec.rb4
-rw-r--r--spec/lib/gitlab/github_import/pull_request_formatter_spec.rb47
-rw-r--r--spec/lib/gitlab/polling_interval_spec.rb34
-rw-r--r--spec/lib/gitlab/workhorse_spec.rb60
-rw-r--r--spec/models/repository_spec.rb13
-rw-r--r--spec/requests/api/users_spec.rb10
-rw-r--r--spec/services/users/destroy_spec.rb19
-rw-r--r--spec/support/test_env.rb6
105 files changed, 1411 insertions, 313 deletions
diff --git a/.rubocop.yml b/.rubocop.yml
index fa1370ea1f3..ac6b141cea3 100644
--- a/.rubocop.yml
+++ b/.rubocop.yml
@@ -533,6 +533,10 @@ Style/WhileUntilModifier:
Style/WordArray:
Enabled: true
+# Use `proc` instead of `Proc.new`.
+Style/Proc:
+ Enabled: true
+
# Metrics #####################################################################
# A calculated magnitude based on number of assignments,
diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml
index c24142c0a11..8588988dc87 100644
--- a/.rubocop_todo.yml
+++ b/.rubocop_todo.yml
@@ -226,11 +226,6 @@ Style/PredicateName:
Style/PreferredHashMethods:
Enabled: false
-# Offense count: 8
-# Cop supports --auto-correct.
-Style/Proc:
- Enabled: false
-
# Offense count: 62
# Cop supports --auto-correct.
# Configuration parameters: EnforcedStyle, SupportedStyles.
diff --git a/Gemfile b/Gemfile
index 562ee2d1b9e..0c6bb805b98 100644
--- a/Gemfile
+++ b/Gemfile
@@ -352,4 +352,4 @@ gem 'vmstat', '~> 2.3.0'
gem 'sys-filesystem', '~> 1.1.6'
# Gitaly GRPC client
-gem 'gitaly', '~> 0.3.0'
+gem 'gitaly', '~> 0.5.0'
diff --git a/Gemfile.lock b/Gemfile.lock
index 8382de2b7a0..304fc9f2bb3 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -253,7 +253,7 @@ GEM
json
get_process_mem (0.2.0)
gherkin-ruby (0.3.2)
- gitaly (0.3.0)
+ gitaly (0.5.0)
google-protobuf (~> 3.1)
grpc (~> 1.0)
github-linguist (4.7.6)
@@ -899,7 +899,7 @@ DEPENDENCIES
fuubar (~> 2.0.0)
gemnasium-gitlab-service (~> 0.2)
gemojione (~> 3.0)
- gitaly (~> 0.3.0)
+ gitaly (~> 0.5.0)
github-linguist (~> 4.7.0)
gitlab-flowdock-git-hook (~> 1.0.1)
gitlab-markup (~> 1.5.1)
diff --git a/app/assets/javascripts/blob/file_template_mediator.js b/app/assets/javascripts/blob/file_template_mediator.js
new file mode 100644
index 00000000000..3062cd51ee3
--- /dev/null
+++ b/app/assets/javascripts/blob/file_template_mediator.js
@@ -0,0 +1,241 @@
+/* eslint-disable class-methods-use-this */
+/* global Flash */
+
+import FileTemplateTypeSelector from './template_selectors/type_selector';
+import BlobCiYamlSelector from './template_selectors/ci_yaml_selector';
+import DockerfileSelector from './template_selectors/dockerfile_selector';
+import GitignoreSelector from './template_selectors/gitignore_selector';
+import LicenseSelector from './template_selectors/license_selector';
+
+export default class FileTemplateMediator {
+ constructor({ editor, currentAction }) {
+ this.editor = editor;
+ this.currentAction = currentAction;
+
+ this.initTemplateSelectors();
+ this.initTemplateTypeSelector();
+ this.initDomElements();
+ this.initDropdowns();
+ this.initPageEvents();
+ }
+
+ initTemplateSelectors() {
+ // Order dictates template type dropdown item order
+ this.templateSelectors = [
+ GitignoreSelector,
+ BlobCiYamlSelector,
+ DockerfileSelector,
+ LicenseSelector,
+ ].map(TemplateSelectorClass => new TemplateSelectorClass({ mediator: this }));
+ }
+
+ initTemplateTypeSelector() {
+ this.typeSelector = new FileTemplateTypeSelector({
+ mediator: this,
+ dropdownData: this.templateSelectors
+ .map((templateSelector) => {
+ const cfg = templateSelector.config;
+
+ return {
+ name: cfg.name,
+ key: cfg.key,
+ };
+ }),
+ });
+ }
+
+ initDomElements() {
+ const $templatesMenu = $('.template-selectors-menu');
+ const $undoMenu = $templatesMenu.find('.template-selectors-undo-menu');
+ const $fileEditor = $('.file-editor');
+
+ this.$templatesMenu = $templatesMenu;
+ this.$undoMenu = $undoMenu;
+ this.$undoBtn = $undoMenu.find('button');
+ this.$templateSelectors = $templatesMenu.find('.template-selector-dropdowns-wrap');
+ this.$filenameInput = $fileEditor.find('.js-file-path-name-input');
+ this.$fileContent = $fileEditor.find('#file-content');
+ this.$commitForm = $fileEditor.find('form');
+ this.$navLinks = $fileEditor.find('.nav-links');
+ }
+
+ initDropdowns() {
+ if (this.currentAction === 'create') {
+ this.typeSelector.show();
+ } else {
+ this.hideTemplateSelectorMenu();
+ }
+
+ this.displayMatchedTemplateSelector();
+ }
+
+ initPageEvents() {
+ this.listenForFilenameInput();
+ this.prepFileContentForSubmit();
+ this.listenForPreviewMode();
+ }
+
+ listenForFilenameInput() {
+ this.$filenameInput.on('keyup blur', () => {
+ this.displayMatchedTemplateSelector();
+ });
+ }
+
+ prepFileContentForSubmit() {
+ this.$commitForm.submit(() => {
+ this.$fileContent.val(this.editor.getValue());
+ });
+ }
+
+ listenForPreviewMode() {
+ this.$navLinks.on('click', 'a', (e) => {
+ const urlPieces = e.target.href.split('#');
+ const hash = urlPieces[1];
+ if (hash === 'preview') {
+ this.hideTemplateSelectorMenu();
+ } else if (hash === 'editor') {
+ this.showTemplateSelectorMenu();
+ }
+ });
+ }
+
+ selectTemplateType(item, el, e) {
+ if (e) {
+ e.preventDefault();
+ }
+
+ this.templateSelectors.forEach((selector) => {
+ if (selector.config.key === item.key) {
+ selector.show();
+ } else {
+ selector.hide();
+ }
+ });
+
+ this.typeSelector.setToggleText(item.name);
+
+ this.cacheToggleText();
+ }
+
+ selectTemplateFile(selector, query, data) {
+ selector.renderLoading();
+ // in case undo menu is already already there
+ this.destroyUndoMenu();
+ this.fetchFileTemplate(selector.config.endpoint, query, data)
+ .then((file) => {
+ this.showUndoMenu();
+ this.setEditorContent(file);
+ this.setFilename(selector.config.name);
+ selector.renderLoaded();
+ })
+ .catch(err => new Flash(`An error occurred while fetching the template: ${err}`));
+ }
+
+ displayMatchedTemplateSelector() {
+ const currentInput = this.getFilename();
+ this.templateSelectors.forEach((selector) => {
+ const match = selector.config.pattern.test(currentInput);
+
+ if (match) {
+ this.typeSelector.show();
+ this.selectTemplateType(selector.config);
+ this.showTemplateSelectorMenu();
+ }
+ });
+ }
+
+ fetchFileTemplate(apiCall, query, data) {
+ return new Promise((resolve) => {
+ const resolveFile = file => resolve(file);
+
+ if (!data) {
+ apiCall(query, resolveFile);
+ } else {
+ apiCall(query, data, resolveFile);
+ }
+ });
+ }
+
+ setEditorContent(file) {
+ if (!file && file !== '') return;
+
+ const newValue = file.content || file;
+
+ this.editor.setValue(newValue, 1);
+
+ this.editor.focus();
+
+ this.editor.navigateFileStart();
+ }
+
+ findTemplateSelectorByKey(key) {
+ return this.templateSelectors.find(selector => selector.config.key === key);
+ }
+
+ showUndoMenu() {
+ this.$undoMenu.removeClass('hidden');
+
+ this.$undoBtn.on('click', () => {
+ this.restoreFromCache();
+ this.destroyUndoMenu();
+ });
+ }
+
+ destroyUndoMenu() {
+ this.cacheFileContents();
+ this.cacheToggleText();
+ this.$undoMenu.addClass('hidden');
+ this.$undoBtn.off('click');
+ }
+
+ hideTemplateSelectorMenu() {
+ this.$templatesMenu.hide();
+ }
+
+ showTemplateSelectorMenu() {
+ this.$templatesMenu.show();
+ }
+
+ cacheToggleText() {
+ this.cachedToggleText = this.getTemplateSelectorToggleText();
+ }
+
+ cacheFileContents() {
+ this.cachedContent = this.editor.getValue();
+ this.cachedFilename = this.getFilename();
+ }
+
+ restoreFromCache() {
+ this.setEditorContent(this.cachedContent);
+ this.setFilename(this.cachedFilename);
+ this.setTemplateSelectorToggleText();
+ }
+
+ getTemplateSelectorToggleText() {
+ return this.$templateSelectors
+ .find('.js-template-selector-wrap:visible .dropdown-toggle-text')
+ .text();
+ }
+
+ setTemplateSelectorToggleText() {
+ return this.$templateSelectors
+ .find('.js-template-selector-wrap:visible .dropdown-toggle-text')
+ .text(this.cachedToggleText);
+ }
+
+ getTypeSelectorToggleText() {
+ return this.typeSelector.getToggleText();
+ }
+
+ getFilename() {
+ return this.$filenameInput.val();
+ }
+
+ setFilename(name) {
+ this.$filenameInput.val(name);
+ }
+
+ getSelected() {
+ return this.templateSelectors.find(selector => selector.selected);
+ }
+}
diff --git a/app/assets/javascripts/blob/file_template_selector.js b/app/assets/javascripts/blob/file_template_selector.js
new file mode 100644
index 00000000000..31dd45fac89
--- /dev/null
+++ b/app/assets/javascripts/blob/file_template_selector.js
@@ -0,0 +1,60 @@
+/* global Api */
+
+export default class FileTemplateSelector {
+ constructor(mediator) {
+ this.mediator = mediator;
+ this.$dropdown = null;
+ this.$wrapper = null;
+ }
+
+ init() {
+ const cfg = this.config;
+
+ this.$dropdown = $(cfg.dropdown);
+ this.$wrapper = $(cfg.wrapper);
+ this.$loadingIcon = this.$wrapper.find('.fa-chevron-down');
+ this.$dropdownToggleText = this.$wrapper.find('.dropdown-toggle-text');
+
+ this.initDropdown();
+ }
+
+ show() {
+ if (this.$dropdown === null) {
+ this.init();
+ }
+
+ this.$wrapper.removeClass('hidden');
+ }
+
+ hide() {
+ if (this.$dropdown !== null) {
+ this.$wrapper.addClass('hidden');
+ }
+ }
+
+ getToggleText() {
+ return this.$dropdownToggleText.text();
+ }
+
+ setToggleText(text) {
+ this.$dropdownToggleText.text(text);
+ }
+
+ renderLoading() {
+ this.$loadingIcon
+ .addClass('fa-spinner fa-spin')
+ .removeClass('fa-chevron-down');
+ }
+
+ renderLoaded() {
+ this.$loadingIcon
+ .addClass('fa-chevron-down')
+ .removeClass('fa-spinner fa-spin');
+ }
+
+ reportSelection(query, el, e, data) {
+ e.preventDefault();
+ return this.mediator.selectTemplateFile(this, query, data);
+ }
+}
+
diff --git a/app/assets/javascripts/blob/template_selectors/template_selector.js b/app/assets/javascripts/blob/template_selector.js
index d7c1c32efbd..d7c1c32efbd 100644
--- a/app/assets/javascripts/blob/template_selectors/template_selector.js
+++ b/app/assets/javascripts/blob/template_selector.js
diff --git a/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selector.js b/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selector.js
deleted file mode 100644
index 5a5954e7751..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selector.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/* global Api */
-
-import TemplateSelector from './template_selector';
-
-export default class BlobCiYamlSelector extends TemplateSelector {
- requestFile(query) {
- return Api.gitlabCiYml(query.name, (file, config) => this.setEditorContent(file, config));
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selectors.js b/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selectors.js
deleted file mode 100644
index 7a4d6a42a03..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_ci_yaml_selectors.js
+++ /dev/null
@@ -1,23 +0,0 @@
-/* global Api */
-
-import BlobCiYamlSelector from './blob_ci_yaml_selector';
-
-export default class BlobCiYamlSelectors {
- constructor({ editor, $dropdowns }) {
- this.$dropdowns = $dropdowns || $('.js-gitlab-ci-yml-selector');
- this.initSelectors(editor);
- }
-
- initSelectors(editor) {
- this.$dropdowns.each((i, dropdown) => {
- const $dropdown = $(dropdown);
- return new BlobCiYamlSelector({
- editor,
- pattern: /(.gitlab-ci.yml)/,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-gitlab-ci-yml-selector-wrap'),
- dropdown: $dropdown,
- });
- });
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selector.js b/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selector.js
deleted file mode 100644
index 19f8820a0cb..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selector.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/* global Api */
-
-import TemplateSelector from './template_selector';
-
-export default class BlobDockerfileSelector extends TemplateSelector {
- requestFile(query) {
- return Api.dockerfileYml(query.name, (file, config) => this.setEditorContent(file, config));
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selectors.js b/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selectors.js
deleted file mode 100644
index da067035b43..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_dockerfile_selectors.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import BlobDockerfileSelector from './blob_dockerfile_selector';
-
-export default class BlobDockerfileSelectors {
- constructor({ editor, $dropdowns }) {
- this.editor = editor;
- this.$dropdowns = $dropdowns || $('.js-dockerfile-selector');
- this.initSelectors();
- }
-
- initSelectors() {
- const editor = this.editor;
- this.$dropdowns.each((i, dropdown) => {
- const $dropdown = $(dropdown);
- return new BlobDockerfileSelector({
- editor,
- pattern: /(Dockerfile)/,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-dockerfile-selector-wrap'),
- dropdown: $dropdown,
- });
- });
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_gitignore_selector.js b/app/assets/javascripts/blob/template_selectors/blob_gitignore_selector.js
deleted file mode 100644
index 0b6b02fc2b3..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_gitignore_selector.js
+++ /dev/null
@@ -1,9 +0,0 @@
-/* global Api */
-
-import TemplateSelector from './template_selector';
-
-export default class BlobGitignoreSelector extends TemplateSelector {
- requestFile(query) {
- return Api.gitignoreText(query.name, (file, config) => this.setEditorContent(file, config));
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_gitignore_selectors.js b/app/assets/javascripts/blob/template_selectors/blob_gitignore_selectors.js
deleted file mode 100644
index dc485d97677..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_gitignore_selectors.js
+++ /dev/null
@@ -1,23 +0,0 @@
-import BlobGitignoreSelector from './blob_gitignore_selector';
-
-export default class BlobGitignoreSelectors {
- constructor({ editor, $dropdowns }) {
- this.$dropdowns = $dropdowns || $('.js-gitignore-selector');
- this.editor = editor;
- this.initSelectors();
- }
-
- initSelectors() {
- this.$dropdowns.each((i, dropdown) => {
- const $dropdown = $(dropdown);
-
- return new BlobGitignoreSelector({
- pattern: /(.gitignore)/,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-gitignore-selector-wrap'),
- dropdown: $dropdown,
- editor: this.editor,
- });
- });
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_license_selector.js b/app/assets/javascripts/blob/template_selectors/blob_license_selector.js
deleted file mode 100644
index e9cb31cc2dc..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_license_selector.js
+++ /dev/null
@@ -1,13 +0,0 @@
-/* global Api */
-
-import TemplateSelector from './template_selector';
-
-export default class BlobLicenseSelector extends TemplateSelector {
- requestFile(query) {
- const data = {
- project: this.dropdown.data('project'),
- fullname: this.dropdown.data('fullname'),
- };
- return Api.licenseText(query.id, data, (file, config) => this.setEditorContent(file, config));
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/blob_license_selectors.js b/app/assets/javascripts/blob/template_selectors/blob_license_selectors.js
deleted file mode 100644
index a44f4f78b2d..00000000000
--- a/app/assets/javascripts/blob/template_selectors/blob_license_selectors.js
+++ /dev/null
@@ -1,24 +0,0 @@
-/* eslint-disable no-unused-vars, no-param-reassign */
-
-import BlobLicenseSelector from './blob_license_selector';
-
-export default class BlobLicenseSelectors {
- constructor({ $dropdowns, editor }) {
- this.$dropdowns = $dropdowns || $('.js-license-selector');
- this.initSelectors(editor);
- }
-
- initSelectors(editor) {
- this.$dropdowns.each((i, dropdown) => {
- const $dropdown = $(dropdown);
-
- return new BlobLicenseSelector({
- editor,
- pattern: /^(.+\/)?(licen[sc]e|copying)($|\.)/i,
- data: $dropdown.data('data'),
- wrapper: $dropdown.closest('.js-license-selector-wrap'),
- dropdown: $dropdown,
- });
- });
- }
-}
diff --git a/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js b/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
new file mode 100644
index 00000000000..935df07677c
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selectors/ci_yaml_selector.js
@@ -0,0 +1,32 @@
+/* global Api */
+
+import FileTemplateSelector from '../file_template_selector';
+
+export default class BlobCiYamlSelector extends FileTemplateSelector {
+ constructor({ mediator }) {
+ super(mediator);
+ this.config = {
+ key: 'gitlab-ci-yaml',
+ name: '.gitlab-ci.yml',
+ pattern: /(.gitlab-ci.yml)/,
+ endpoint: Api.gitlabCiYml,
+ dropdown: '.js-gitlab-ci-yml-selector',
+ wrapper: '.js-gitlab-ci-yml-selector-wrap',
+ };
+ }
+
+ initDropdown() {
+ // maybe move to super class as well
+ this.$dropdown.glDropdown({
+ data: this.$dropdown.data('data'),
+ filterable: true,
+ selectable: true,
+ toggleLabel: item => item.name,
+ search: {
+ fields: ['name'],
+ },
+ clicked: (query, el, e) => this.reportSelection(query.name, el, e),
+ text: item => item.name,
+ });
+ }
+}
diff --git a/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js b/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
new file mode 100644
index 00000000000..b4b4d09c315
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selectors/dockerfile_selector.js
@@ -0,0 +1,32 @@
+/* global Api */
+
+import FileTemplateSelector from '../file_template_selector';
+
+export default class DockerfileSelector extends FileTemplateSelector {
+ constructor({ mediator }) {
+ super(mediator);
+ this.config = {
+ key: 'dockerfile',
+ name: 'Dockerfile',
+ pattern: /(Dockerfile)/,
+ endpoint: Api.dockerfileYml,
+ dropdown: '.js-dockerfile-selector',
+ wrapper: '.js-dockerfile-selector-wrap',
+ };
+ }
+
+ initDropdown() {
+ // maybe move to super class as well
+ this.$dropdown.glDropdown({
+ data: this.$dropdown.data('data'),
+ filterable: true,
+ selectable: true,
+ toggleLabel: item => item.name,
+ search: {
+ fields: ['name'],
+ },
+ clicked: (query, el, e) => this.reportSelection(query.name, el, e),
+ text: item => item.name,
+ });
+ }
+}
diff --git a/app/assets/javascripts/blob/template_selectors/gitignore_selector.js b/app/assets/javascripts/blob/template_selectors/gitignore_selector.js
new file mode 100644
index 00000000000..aefae54ae71
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selectors/gitignore_selector.js
@@ -0,0 +1,31 @@
+/* global Api */
+
+import FileTemplateSelector from '../file_template_selector';
+
+export default class BlobGitignoreSelector extends FileTemplateSelector {
+ constructor({ mediator }) {
+ super(mediator);
+ this.config = {
+ key: 'gitignore',
+ name: '.gitignore',
+ pattern: /(.gitignore)/,
+ endpoint: Api.gitignoreText,
+ dropdown: '.js-gitignore-selector',
+ wrapper: '.js-gitignore-selector-wrap',
+ };
+ }
+
+ initDropdown() {
+ this.$dropdown.glDropdown({
+ data: this.$dropdown.data('data'),
+ filterable: true,
+ selectable: true,
+ toggleLabel: item => item.name,
+ search: {
+ fields: ['name'],
+ },
+ clicked: (query, el, e) => this.reportSelection(query.name, el, e),
+ text: item => item.name,
+ });
+ }
+}
diff --git a/app/assets/javascripts/blob/template_selectors/license_selector.js b/app/assets/javascripts/blob/template_selectors/license_selector.js
new file mode 100644
index 00000000000..c8abd689ab4
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selectors/license_selector.js
@@ -0,0 +1,38 @@
+/* global Api */
+
+import FileTemplateSelector from '../file_template_selector';
+
+export default class BlobLicenseSelector extends FileTemplateSelector {
+ constructor({ mediator }) {
+ super(mediator);
+ this.config = {
+ key: 'license',
+ name: 'LICENSE',
+ pattern: /^(.+\/)?(licen[sc]e|copying)($|\.)/i,
+ endpoint: Api.licenseText,
+ dropdown: '.js-license-selector',
+ wrapper: '.js-license-selector-wrap',
+ };
+ }
+
+ initDropdown() {
+ this.$dropdown.glDropdown({
+ data: this.$dropdown.data('data'),
+ filterable: true,
+ selectable: true,
+ toggleLabel: item => item.name,
+ search: {
+ fields: ['name'],
+ },
+ clicked: (query, el, e) => {
+ const data = {
+ project: this.$dropdown.data('project'),
+ fullname: this.$dropdown.data('fullname'),
+ };
+
+ this.reportSelection(query.id, el, e, data);
+ },
+ text: item => item.name,
+ });
+ }
+}
diff --git a/app/assets/javascripts/blob/template_selectors/type_selector.js b/app/assets/javascripts/blob/template_selectors/type_selector.js
new file mode 100644
index 00000000000..56f23ef0568
--- /dev/null
+++ b/app/assets/javascripts/blob/template_selectors/type_selector.js
@@ -0,0 +1,25 @@
+import FileTemplateSelector from '../file_template_selector';
+
+export default class FileTemplateTypeSelector extends FileTemplateSelector {
+ constructor({ mediator, dropdownData }) {
+ super(mediator);
+ this.mediator = mediator;
+ this.config = {
+ dropdown: '.js-template-type-selector',
+ wrapper: '.js-template-type-selector-wrap',
+ dropdownData,
+ };
+ }
+
+ initDropdown() {
+ this.$dropdown.glDropdown({
+ data: this.config.dropdownData,
+ filterable: false,
+ selectable: true,
+ toggleLabel: item => item.name,
+ clicked: (item, el, e) => this.mediator.selectTemplateType(item, el, e),
+ text: item => item.name,
+ });
+ }
+
+}
diff --git a/app/assets/javascripts/blob_edit/blob_bundle.js b/app/assets/javascripts/blob_edit/blob_bundle.js
index c5deccf631e..1c64ccf536f 100644
--- a/app/assets/javascripts/blob_edit/blob_bundle.js
+++ b/app/assets/javascripts/blob_edit/blob_bundle.js
@@ -13,8 +13,9 @@ $(() => {
const urlRoot = editBlobForm.data('relative-url-root');
const assetsPath = editBlobForm.data('assets-prefix');
const blobLanguage = editBlobForm.data('blob-language');
+ const currentAction = $('.js-file-title').data('current-action');
- new EditBlob(`${urlRoot}${assetsPath}`, blobLanguage);
+ new EditBlob(`${urlRoot}${assetsPath}`, blobLanguage, currentAction);
new NewCommitForm(editBlobForm);
}
diff --git a/app/assets/javascripts/blob_edit/edit_blob.js b/app/assets/javascripts/blob_edit/edit_blob.js
index d3560d5df3b..b37988a674d 100644
--- a/app/assets/javascripts/blob_edit/edit_blob.js
+++ b/app/assets/javascripts/blob_edit/edit_blob.js
@@ -1,17 +1,13 @@
/* global ace */
-import BlobLicenseSelectors from '../blob/template_selectors/blob_license_selectors';
-import BlobGitignoreSelectors from '../blob/template_selectors/blob_gitignore_selectors';
-import BlobCiYamlSelectors from '../blob/template_selectors/blob_ci_yaml_selectors';
-import BlobDockerfileSelectors from '../blob/template_selectors/blob_dockerfile_selectors';
+import TemplateSelectorMediator from '../blob/file_template_mediator';
export default class EditBlob {
- constructor(assetsPath, aceMode) {
+ constructor(assetsPath, aceMode, currentAction) {
this.configureAceEditor(aceMode, assetsPath);
- this.prepFileContentForSubmit();
this.initModePanesAndLinks();
this.initSoftWrap();
- this.initFileSelectors();
+ this.initFileSelectors(currentAction);
}
configureAceEditor(aceMode, assetsPath) {
@@ -19,6 +15,10 @@ export default class EditBlob {
ace.config.loadModule('ace/ext/searchbox');
this.editor = ace.edit('editor');
+
+ // This prevents warnings re: automatic scrolling being logged
+ this.editor.$blockScrolling = Infinity;
+
this.editor.focus();
if (aceMode) {
@@ -26,29 +26,13 @@ export default class EditBlob {
}
}
- prepFileContentForSubmit() {
- $('form').submit(() => {
- $('#file-content').val(this.editor.getValue());
+ initFileSelectors(currentAction) {
+ this.fileTemplateMediator = new TemplateSelectorMediator({
+ currentAction,
+ editor: this.editor,
});
}
- initFileSelectors() {
- this.blobTemplateSelectors = [
- new BlobLicenseSelectors({
- editor: this.editor,
- }),
- new BlobGitignoreSelectors({
- editor: this.editor,
- }),
- new BlobCiYamlSelectors({
- editor: this.editor,
- }),
- new BlobDockerfileSelectors({
- editor: this.editor,
- }),
- ];
- }
-
initModePanesAndLinks() {
this.$editModePanes = $('.js-edit-mode-pane');
this.$editModeLinks = $('.js-edit-mode a');
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 4aad0128aef..46b80c04e20 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -263,7 +263,7 @@
});
/**
- * Updates the search parameter of a URL given the parameter and values provided.
+ * Updates the search parameter of a URL given the parameter and value provided.
*
* If no search params are present we'll add it.
* If param for page is already present, we'll update it
@@ -278,17 +278,24 @@
let search;
const locationSearch = window.location.search;
- if (locationSearch.length === 0) {
- search = `?${param}=${value}`;
- }
+ if (locationSearch.length) {
+ const parameters = locationSearch.substring(1, locationSearch.length)
+ .split('&')
+ .reduce((acc, element) => {
+ const val = element.split('=');
+ acc[val[0]] = decodeURIComponent(val[1]);
+ return acc;
+ }, {});
- if (locationSearch.indexOf(param) !== -1) {
- const regex = new RegExp(param + '=\\d');
- search = locationSearch.replace(regex, `${param}=${value}`);
- }
+ parameters[param] = value;
- if (locationSearch.length && locationSearch.indexOf(param) === -1) {
- search = `${locationSearch}&${param}=${value}`;
+ const toString = Object.keys(parameters)
+ .map(val => `${val}=${encodeURIComponent(parameters[val])}`)
+ .join('&');
+
+ search = `?${toString}`;
+ } else {
+ search = `?${param}=${value}`;
}
return search;
diff --git a/app/assets/javascripts/templates/issuable_template_selector.js b/app/assets/javascripts/templates/issuable_template_selector.js
index 32067ed1fee..e62f429f1ae 100644
--- a/app/assets/javascripts/templates/issuable_template_selector.js
+++ b/app/assets/javascripts/templates/issuable_template_selector.js
@@ -1,7 +1,7 @@
/* eslint-disable comma-dangle, max-len, no-useless-return, no-param-reassign, max-len */
/* global Api */
-import TemplateSelector from '../blob/template_selectors/template_selector';
+import TemplateSelector from '../blob/template_selector';
((global) => {
class IssuableTemplateSelector extends TemplateSelector {
diff --git a/app/assets/stylesheets/pages/editor.scss b/app/assets/stylesheets/pages/editor.scss
index 4af267403d8..f6b8c8ee2bc 100644
--- a/app/assets/stylesheets/pages/editor.scss
+++ b/app/assets/stylesheets/pages/editor.scss
@@ -1,4 +1,13 @@
.file-editor {
+ .nav-links {
+ border-top: 1px solid $border-color;
+ border-right: 1px solid $border-color;
+ border-left: 1px solid $border-color;
+ border-bottom: none;
+ border-radius: 2px;
+ background: $gray-normal;
+ }
+
#editor {
border: none;
border-radius: 0;
@@ -72,11 +81,7 @@
}
.encoding-selector,
- .soft-wrap-toggle,
- .license-selector,
- .gitignore-selector,
- .gitlab-ci-yml-selector,
- .dockerfile-selector {
+ .soft-wrap-toggle {
display: inline-block;
vertical-align: top;
font-family: $regular_font;
@@ -103,28 +108,9 @@
}
}
}
-
- .gitignore-selector,
- .license-selector,
- .gitlab-ci-yml-selector,
- .dockerfile-selector {
- .dropdown {
- line-height: 21px;
- }
-
- .dropdown-menu-toggle {
- vertical-align: top;
- width: 220px;
- }
- }
-
- .gitlab-ci-yml-selector {
- .dropdown-menu-toggle {
- width: 250px;
- }
- }
}
+
@media(max-width: $screen-xs-max){
.file-editor {
.file-title {
@@ -149,10 +135,7 @@
margin: 3px 0;
}
- .encoding-selector,
- .license-selector,
- .gitignore-selector,
- .gitlab-ci-yml-selector {
+ .encoding-selector {
display: block;
margin: 3px 0;
@@ -163,3 +146,104 @@
}
}
}
+
+.blob-new-page-title,
+.blob-edit-page-title {
+ margin: 19px 0 21px;
+ vertical-align: top;
+ display: inline-block;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ margin: 19px 0 12px;
+ }
+}
+
+.template-selectors-menu {
+ display: inline-block;
+ vertical-align: top;
+ margin: 14px 0 0 16px;
+ padding: 0 0 0 14px;
+ border-left: 1px solid $border-color;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ width: 100%;
+ margin: 5px 0;
+ padding: 0;
+ border-left: none;
+ }
+}
+
+.templates-selectors-label {
+ display: inline-block;
+ vertical-align: top;
+ margin-top: 6px;
+ line-height: 21px;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ margin: 5px 0;
+ }
+}
+
+.template-selector-dropdowns-wrap {
+ display: inline-block;
+ margin-left: 8px;
+ vertical-align: top;
+ margin: 5px 0 0 8px;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ width: 100%;
+ margin: 0 0 16px;
+ }
+
+ .license-selector,
+ .gitignore-selector,
+ .gitlab-ci-yml-selector,
+ .dockerfile-selector,
+ .template-type-selector {
+ display: inline-block;
+ vertical-align: top;
+ font-family: $regular_font;
+ margin-top: -5px;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ width: 100%;
+ margin: 5px 0;
+ }
+
+ .dropdown {
+ line-height: 21px;
+ }
+
+ .dropdown-menu-toggle {
+ width: 250px;
+ vertical-align: top;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ width: 100%;
+ margin: 5px 0;
+ }
+ }
+
+ }
+}
+
+.template-selectors-undo-menu {
+ display: inline-block;
+ margin: 7px 0 0 10px;
+
+ @media(max-width: $screen-sm-max) {
+ display: block;
+ width: 100%;
+ margin: 20px 0;
+ }
+
+ button {
+ margin: -4px 0 0 15px;
+ }
+}
diff --git a/app/controllers/admin/abuse_reports_controller.rb b/app/controllers/admin/abuse_reports_controller.rb
index 5055c318a5f..dc9a6df5f75 100644
--- a/app/controllers/admin/abuse_reports_controller.rb
+++ b/app/controllers/admin/abuse_reports_controller.rb
@@ -1,6 +1,7 @@
class Admin::AbuseReportsController < Admin::ApplicationController
def index
@abuse_reports = AbuseReport.order(id: :desc).page(params[:page])
+ @abuse_reports.includes(:reporter, :user)
end
def destroy
diff --git a/app/controllers/admin/application_settings_controller.rb b/app/controllers/admin/application_settings_controller.rb
index 0bfbe47eb4f..515d8e1523b 100644
--- a/app/controllers/admin/application_settings_controller.rb
+++ b/app/controllers/admin/application_settings_controller.rb
@@ -134,6 +134,7 @@ class Admin::ApplicationSettingsController < Admin::ApplicationController
:unique_ips_limit_enabled,
:version_check_enabled,
:terminal_max_session_time,
+ :polling_interval_multiplier,
disabled_oauth_sign_in_sources: [],
import_sources: [],
diff --git a/app/controllers/groups/group_members_controller.rb b/app/controllers/groups/group_members_controller.rb
index 0cbf3eb58a3..00c50f9d0ad 100644
--- a/app/controllers/groups/group_members_controller.rb
+++ b/app/controllers/groups/group_members_controller.rb
@@ -14,6 +14,7 @@ class Groups::GroupMembersController < Groups::ApplicationController
@members = @members.search(params[:search]) if params[:search].present?
@members = @members.sort(@sort)
@members = @members.page(params[:page]).per(50)
+ @members.includes(:user)
@requesters = AccessRequestsFinder.new(@group).execute(current_user)
diff --git a/app/controllers/projects/git_http_controller.rb b/app/controllers/projects/git_http_controller.rb
index 278098fcc58..37f6f637ff0 100644
--- a/app/controllers/projects/git_http_controller.rb
+++ b/app/controllers/projects/git_http_controller.rb
@@ -57,7 +57,7 @@ class Projects::GitHttpController < Projects::GitHttpClientController
def render_ok
set_workhorse_internal_api_content_type
- render json: Gitlab::Workhorse.git_http_ok(repository, user)
+ render json: Gitlab::Workhorse.git_http_ok(repository, user, action_name)
end
def render_http_not_allowed
diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb
index 9621b30b251..37e3ac05916 100755
--- a/app/controllers/projects/merge_requests_controller.rb
+++ b/app/controllers/projects/merge_requests_controller.rb
@@ -39,6 +39,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController
@collection_type = "MergeRequest"
@merge_requests = merge_requests_collection
@merge_requests = @merge_requests.page(params[:page])
+ @merge_requests = @merge_requests.includes(merge_request_diff: :merge_request)
@issuable_meta_data = issuable_meta_data(@merge_requests, @collection_type)
if @merge_requests.out_of_range? && @merge_requests.total_pages != 0
diff --git a/app/controllers/projects/milestones_controller.rb b/app/controllers/projects/milestones_controller.rb
index 5922e686cd0..408c0c60cb0 100644
--- a/app/controllers/projects/milestones_controller.rb
+++ b/app/controllers/projects/milestones_controller.rb
@@ -21,9 +21,9 @@ class Projects::MilestonesController < Projects::ApplicationController
@sort = params[:sort] || 'due_date_asc'
@milestones = @milestones.sort(@sort)
- @milestones = @milestones.includes(:project)
respond_to do |format|
format.html do
+ @milestones = @milestones.includes(:project)
@milestones = @milestones.page(params[:page])
end
format.json do
diff --git a/app/controllers/registrations_controller.rb b/app/controllers/registrations_controller.rb
index a49a1f50a81..8109427a45f 100644
--- a/app/controllers/registrations_controller.rb
+++ b/app/controllers/registrations_controller.rb
@@ -25,12 +25,12 @@ class RegistrationsController < Devise::RegistrationsController
end
def destroy
- Users::DestroyService.new(current_user).execute(current_user)
+ DeleteUserWorker.perform_async(current_user.id, current_user.id)
respond_to do |format|
format.html do
session.try(:destroy)
- redirect_to new_user_session_path, notice: "Account successfully removed."
+ redirect_to new_user_session_path, notice: "Account scheduled for removal."
end
end
end
diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb
index 7d81c96262f..d8561871098 100644
--- a/app/controllers/sessions_controller.rb
+++ b/app/controllers/sessions_controller.rb
@@ -79,7 +79,7 @@ class SessionsController < Devise::SessionsController
if request.referer.present? && (params['redirect_to_referer'] == 'yes')
referer_uri = URI(request.referer)
if referer_uri.host == Gitlab.config.gitlab.host
- referer_uri.path
+ referer_uri.request_uri
else
request.fullpath
end
diff --git a/app/mailers/base_mailer.rb b/app/mailers/base_mailer.rb
index 79c3c2e62c5..a9b6b33eb5c 100644
--- a/app/mailers/base_mailer.rb
+++ b/app/mailers/base_mailer.rb
@@ -5,8 +5,8 @@ class BaseMailer < ActionMailer::Base
attr_accessor :current_user
helper_method :current_user, :can?
- default from: Proc.new { default_sender_address.format }
- default reply_to: Proc.new { default_reply_to_address.format }
+ default from: proc { default_sender_address.format }
+ default reply_to: proc { default_reply_to_address.format }
def can?
Ability.allowed?(current_user, action, subject)
diff --git a/app/models/application_setting.rb b/app/models/application_setting.rb
index 671a0fe98cc..2961e16f5e0 100644
--- a/app/models/application_setting.rb
+++ b/app/models/application_setting.rb
@@ -131,6 +131,10 @@ class ApplicationSetting < ActiveRecord::Base
presence: true,
numericality: { only_integer: true, greater_than_or_equal_to: 0 }
+ validates :polling_interval_multiplier,
+ presence: true,
+ numericality: { greater_than_or_equal_to: 0 }
+
validates_each :restricted_visibility_levels do |record, attr, value|
value&.each do |level|
unless Gitlab::VisibilityLevel.options.has_value?(level)
@@ -233,7 +237,8 @@ class ApplicationSetting < ActiveRecord::Base
signup_enabled: Settings.gitlab['signup_enabled'],
terminal_max_session_time: 0,
two_factor_grace_period: 48,
- user_default_external: false
+ user_default_external: false,
+ polling_interval_multiplier: 1
}
end
diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb
index f12be98c80c..ad7e0b23ff4 100644
--- a/app/models/ci/pipeline.rb
+++ b/app/models/ci/pipeline.rb
@@ -210,7 +210,7 @@ module Ci
end
def stuck?
- builds.pending.any?(&:stuck?)
+ builds.pending.includes(:project).any?(&:stuck?)
end
def retryable?
diff --git a/app/models/milestone.rb b/app/models/milestone.rb
index e85d5709624..ac205b9b738 100644
--- a/app/models/milestone.rb
+++ b/app/models/milestone.rb
@@ -30,7 +30,7 @@ class Milestone < ActiveRecord::Base
validates :title, presence: true, uniqueness: { scope: :project_id }
validates :project, presence: true
- validate :start_date_should_be_less_than_due_date, if: Proc.new { |m| m.start_date.present? && m.due_date.present? }
+ validate :start_date_should_be_less_than_due_date, if: proc { |m| m.start_date.present? && m.due_date.present? }
strip_attributes :title
diff --git a/app/models/repository.rb b/app/models/repository.rb
index 6ab04440ca8..596650353fc 100644
--- a/app/models/repository.rb
+++ b/app/models/repository.rb
@@ -981,7 +981,13 @@ class Repository
end
def is_ancestor?(ancestor_id, descendant_id)
- merge_base(ancestor_id, descendant_id) == ancestor_id
+ Gitlab::GitalyClient.migrate(:is_ancestor) do |is_enabled|
+ if is_enabled
+ raw_repository.is_ancestor?(ancestor_id, descendant_id)
+ else
+ merge_base_commit(ancestor_id, descendant_id) == ancestor_id
+ end
+ end
end
def empty_repo?
diff --git a/app/models/service.rb b/app/models/service.rb
index e73f7e5d1a3..54550177744 100644
--- a/app/models/service.rb
+++ b/app/models/service.rb
@@ -25,7 +25,7 @@ class Service < ActiveRecord::Base
belongs_to :project, inverse_of: :services
has_one :service_hook
- validates :project_id, presence: true, unless: Proc.new { |service| service.template? }
+ validates :project_id, presence: true, unless: proc { |service| service.template? }
scope :visible, -> { where.not(type: 'GitlabIssueTrackerService') }
scope :issue_trackers, -> { where(category: 'issue_tracker') }
diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb
index 2c56cb4c680..b6e88b0280f 100644
--- a/app/services/todo_service.rb
+++ b/app/services/todo_service.rb
@@ -204,7 +204,7 @@ class TodoService
# Only update those that are not really on that state
todos = todos.where.not(state: state)
todos_ids = todos.pluck(:id)
- todos.update_all(state: state)
+ todos.unscope(:order).update_all(state: state)
current_user.update_todos_count_cache
todos_ids
end
diff --git a/app/services/users/destroy_service.rb b/app/services/users/destroy_service.rb
index 833da5bc5d1..a3b32a71a64 100644
--- a/app/services/users/destroy_service.rb
+++ b/app/services/users/destroy_service.rb
@@ -20,10 +20,10 @@ module Users
Groups::DestroyService.new(group, current_user).execute
end
- user.personal_projects.each do |project|
+ user.personal_projects.with_deleted.each do |project|
# Skip repository removal because we remove directory with namespace
# that contain all this repositories
- ::Projects::DestroyService.new(project, current_user, skip_repo: true).async_execute
+ ::Projects::DestroyService.new(project, current_user, skip_repo: true).execute
end
move_issues_to_ghost_user(user)
diff --git a/app/views/admin/application_settings/_form.html.haml b/app/views/admin/application_settings/_form.html.haml
index 3eab065bb9f..5d51a2b5cbc 100644
--- a/app/views/admin/application_settings/_form.html.haml
+++ b/app/views/admin/application_settings/_form.html.haml
@@ -558,5 +558,19 @@
Maximum time for web terminal websocket connection (in seconds).
0 for unlimited.
+ %fieldset
+ %legend Real-time features
+ .form-group
+ = f.label :polling_interval_multiplier, 'Polling interval multiplier', class: 'control-label col-sm-2'
+ .col-sm-10
+ = f.text_field :polling_interval_multiplier, class: 'form-control'
+ .help-block
+ Change this value to influence how frequently the GitLab UI polls for updates.
+ If you set the value to 2 all polling intervals are multiplied
+ by 2, which means that polling happens half as frequently.
+ The multiplier can also have a decimal value.
+ The default value (1) is a reasonable choice for the majority of GitLab
+ installations. Set to 0 to completely disable polling.
+
.form-actions
= f.submit 'Save', class: 'btn btn-save'
diff --git a/app/views/projects/blob/_editor.html.haml b/app/views/projects/blob/_editor.html.haml
index e7adef5558a..4b344b2edb9 100644
--- a/app/views/projects/blob/_editor.html.haml
+++ b/app/views/projects/blob/_editor.html.haml
@@ -1,29 +1,23 @@
+- action = current_action?(:edit) || current_action?(:update) ? 'edit' : 'create'
+
.file-holder.file.append-bottom-default
- .js-file-title.file-title.clearfix
+ .js-file-title.file-title.clearfix{ data: { current_action: action } }
.editor-ref
= icon('code-fork')
= ref
%span.editor-file-name
- if current_action?(:edit) || current_action?(:update)
= text_field_tag 'file_path', (params[:file_path] || @path),
- class: 'form-control new-file-path'
+ class: 'form-control new-file-path js-file-path-name-input'
- if current_action?(:new) || current_action?(:create)
%span.editor-file-name
\/
= text_field_tag 'file_name', params[:file_name], placeholder: "File name",
- required: true, class: 'form-control new-file-name'
+ required: true, class: 'form-control new-file-name js-file-path-name-input'
.pull-right.file-buttons
- .license-selector.js-license-selector-wrap.hidden
- = dropdown_tag("Choose a License template", options: { toggle_class: 'btn js-license-selector', title: "Choose a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select, project: @project.name, fullname: @project.namespace.human_name } } )
- .gitignore-selector.js-gitignore-selector-wrap.hidden
- = dropdown_tag("Choose a .gitignore template", options: { toggle_class: 'btn js-gitignore-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } )
- .gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.hidden
- = dropdown_tag("Choose a GitLab CI Yaml template", options: { toggle_class: 'btn js-gitlab-ci-yml-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } )
- .dockerfile-selector.js-dockerfile-selector-wrap.hidden
- = dropdown_tag("Choose a Dockerfile template", options: { toggle_class: 'btn js-dockerfile-selector', title: "Choose a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } )
- = button_tag class: 'soft-wrap-toggle btn', type: 'button' do
+ = button_tag class: 'soft-wrap-toggle btn', type: 'button', tabindex: '-1' do
%span.no-wrap
= custom_icon('icon_no_wrap')
No wrap
@@ -31,7 +25,7 @@
= custom_icon('icon_soft_wrap')
Soft wrap
.encoding-selector
- = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'select2'
+ = select_tag :encoding, options_for_select([ "base64", "text" ], "text"), class: 'select2', tabindex: '-1'
.file-editor.code
%pre.js-edit-mode-pane#editor= params[:content] || local_assigns[:blob_data]
diff --git a/app/views/projects/blob/_template_selectors.html.haml b/app/views/projects/blob/_template_selectors.html.haml
new file mode 100644
index 00000000000..d52733d2bd6
--- /dev/null
+++ b/app/views/projects/blob/_template_selectors.html.haml
@@ -0,0 +1,17 @@
+.template-selectors-menu
+ .templates-selectors-label
+ Template
+ .template-selector-dropdowns-wrap
+ .template-type-selector.js-template-type-selector-wrap.hidden
+ = dropdown_tag("Choose type", options: { toggle_class: 'btn js-template-type-selector', title: "Choose a template type" } )
+ .license-selector.js-license-selector-wrap.js-template-selector-wrap.hidden
+ = dropdown_tag("Apply a License template", options: { toggle_class: 'btn js-license-selector', title: "Apply a license", filter: true, placeholder: "Filter", data: { data: licenses_for_select, project: @project.name, fullname: @project.namespace.human_name } } )
+ .gitignore-selector.js-gitignore-selector-wrap.js-template-selector-wrap.hidden
+ = dropdown_tag("Apply a .gitignore template", options: { toggle_class: 'btn js-gitignore-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitignore_names } } )
+ .gitlab-ci-yml-selector.js-gitlab-ci-yml-selector-wrap.js-template-selector-wrap.hidden
+ = dropdown_tag("Apply a GitLab CI Yaml template", options: { toggle_class: 'btn js-gitlab-ci-yml-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: gitlab_ci_ymls } } )
+ .dockerfile-selector.js-dockerfile-selector-wrap.js-template-selector-wrap.hidden
+ = dropdown_tag("Apply a Dockerfile template", options: { toggle_class: 'btn js-dockerfile-selector', title: "Apply a template", filter: true, placeholder: "Filter", data: { data: dockerfile_names } } )
+ .template-selectors-undo-menu.hidden
+ %span.text-info Template applied
+ %button.btn.btn-sm.btn-info Undo
diff --git a/app/views/projects/blob/edit.html.haml b/app/views/projects/blob/edit.html.haml
index afe0b5dba45..4b26f944733 100644
--- a/app/views/projects/blob/edit.html.haml
+++ b/app/views/projects/blob/edit.html.haml
@@ -11,12 +11,15 @@
Someone edited the file the same time you did. Please check out
= link_to "the file", namespace_project_blob_path(@project.namespace, @project, tree_join(@target_branch, @file_path)), target: "_blank", rel: 'noopener noreferrer'
and make sure your changes will not unintentionally remove theirs.
-
+ .editor-title-row
+ %h3.page-title.blob-edit-page-title
+ Edit file
+ = render 'template_selectors'
.file-editor
%ul.nav-links.no-bottom.js-edit-mode
%li.active
= link_to '#editor' do
- Edit File
+ Write
%li
= link_to '#preview', 'data-preview-url' => namespace_project_preview_blob_path(@project.namespace, @project, @id) do
diff --git a/app/views/projects/blob/new.html.haml b/app/views/projects/blob/new.html.haml
index 4c449e040ee..2afb909572a 100644
--- a/app/views/projects/blob/new.html.haml
+++ b/app/views/projects/blob/new.html.haml
@@ -2,10 +2,10 @@
- content_for :page_specific_javascripts do
= page_specific_javascript_tag('lib/ace.js')
= page_specific_javascript_bundle_tag('blob')
-
-%h3.page-title
- New File
-
+.editor-title-row
+ %h3.page-title.blob-new-page-title
+ New file
+ = render 'template_selectors'
.file-editor
= form_tag(namespace_project_create_blob_path(@project.namespace, @project, @id), method: :post, class: 'form-horizontal js-edit-blob-form js-new-blob-form js-quick-submit js-requires-input', data: blob_editor_paths) do
= render 'projects/blob/editor', ref: @ref
diff --git a/changelogs/unreleased/22303-symbolic-in-tree.yml b/changelogs/unreleased/22303-symbolic-in-tree.yml
new file mode 100644
index 00000000000..02444f571d0
--- /dev/null
+++ b/changelogs/unreleased/22303-symbolic-in-tree.yml
@@ -0,0 +1,4 @@
+---
+title: Fix symlink icon in project tree
+merge_request: 9780
+author: mhasbini
diff --git a/changelogs/unreleased/25332-make-file-templates-easy-to-use-and-discover.yml b/changelogs/unreleased/25332-make-file-templates-easy-to-use-and-discover.yml
new file mode 100644
index 00000000000..fc95858f783
--- /dev/null
+++ b/changelogs/unreleased/25332-make-file-templates-easy-to-use-and-discover.yml
@@ -0,0 +1,4 @@
+---
+title: Remove no-new annotation from file_template_mediator.js.
+merge_request: !9782
+author:
diff --git a/changelogs/unreleased/29541-fix-github-importer-deleted-fork.yml b/changelogs/unreleased/29541-fix-github-importer-deleted-fork.yml
new file mode 100644
index 00000000000..fcb5798a619
--- /dev/null
+++ b/changelogs/unreleased/29541-fix-github-importer-deleted-fork.yml
@@ -0,0 +1,4 @@
+---
+title: Fix GitHub Importer for PRs of deleted forked repositories
+merge_request: 9992
+author:
diff --git a/changelogs/unreleased/29669-redirect-referer-params.yml b/changelogs/unreleased/29669-redirect-referer-params.yml
new file mode 100644
index 00000000000..d8fc7f33049
--- /dev/null
+++ b/changelogs/unreleased/29669-redirect-referer-params.yml
@@ -0,0 +1,4 @@
+---
+title: Fix redirection after login when the referer have params
+merge_request:
+author: mhasbini
diff --git a/changelogs/unreleased/30264-fix-vue-pagination.yml b/changelogs/unreleased/30264-fix-vue-pagination.yml
new file mode 100644
index 00000000000..d5846e52bcf
--- /dev/null
+++ b/changelogs/unreleased/30264-fix-vue-pagination.yml
@@ -0,0 +1,5 @@
+---
+title: Fixes method not replacing URL parameters correctly and breaking pipelines
+ pagination
+merge_request:
+author:
diff --git a/changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml b/changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml
new file mode 100644
index 00000000000..733e3643ce5
--- /dev/null
+++ b/changelogs/unreleased/feature-use-gitaly-for-commit-is-ancestor.yml
@@ -0,0 +1,4 @@
+---
+title: Use Gitaly for Repository#is_ancestor
+merge_request: 9864
+author:
diff --git a/changelogs/unreleased/introduce-polling-interval-multiplier.yml b/changelogs/unreleased/introduce-polling-interval-multiplier.yml
new file mode 100644
index 00000000000..3ccae8e327f
--- /dev/null
+++ b/changelogs/unreleased/introduce-polling-interval-multiplier.yml
@@ -0,0 +1,4 @@
+---
+title: Introduce "polling_interval_multiplier" as application setting
+merge_request: 10280
+author:
diff --git a/changelogs/unreleased/namespace-race-condition.yml b/changelogs/unreleased/namespace-race-condition.yml
new file mode 100644
index 00000000000..2a76b6c74e8
--- /dev/null
+++ b/changelogs/unreleased/namespace-race-condition.yml
@@ -0,0 +1,4 @@
+---
+title: Fix project creation failure due to race condition in namespace directory creation
+merge_request: 10268
+author: Robin Bobbitt
diff --git a/changelogs/unreleased/sh-fix-destroy-user-race.yml b/changelogs/unreleased/sh-fix-destroy-user-race.yml
new file mode 100644
index 00000000000..4d650b51ada
--- /dev/null
+++ b/changelogs/unreleased/sh-fix-destroy-user-race.yml
@@ -0,0 +1,5 @@
+---
+title: Fix race condition where a namespace would be deleted before a project was
+ deleted
+merge_request:
+author:
diff --git a/changelogs/unreleased/sh-relax-wiki-slug-constraint.yml b/changelogs/unreleased/sh-relax-wiki-slug-constraint.yml
new file mode 100644
index 00000000000..08395b0d28c
--- /dev/null
+++ b/changelogs/unreleased/sh-relax-wiki-slug-constraint.yml
@@ -0,0 +1,4 @@
+---
+title: Relax constraint on Wiki IDs, since subdirectories can contain spaces
+merge_request:
+author:
diff --git a/changelogs/unreleased/style-proc-cop.yml b/changelogs/unreleased/style-proc-cop.yml
new file mode 100644
index 00000000000..25acab740bd
--- /dev/null
+++ b/changelogs/unreleased/style-proc-cop.yml
@@ -0,0 +1,4 @@
+---
+title: Enable Style/Proc cop for rubocop
+merge_request:
+author: mhasbini
diff --git a/changelogs/unreleased/todo-update-order.yml b/changelogs/unreleased/todo-update-order.yml
new file mode 100644
index 00000000000..2046b6df11e
--- /dev/null
+++ b/changelogs/unreleased/todo-update-order.yml
@@ -0,0 +1,4 @@
+---
+title: Remove unnecessary ORDER BY clause when updating todos
+merge_request:
+author: mhasbini
diff --git a/config/gitlab.yml.example b/config/gitlab.yml.example
index bd27f01c872..4314e902564 100644
--- a/config/gitlab.yml.example
+++ b/config/gitlab.yml.example
@@ -461,7 +461,7 @@ production: &base
storages: # You must have at least a `default` storage path.
default:
path: /home/git/repositories/
- gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket
+ gitaly_address: unix:/home/git/gitlab/tmp/sockets/private/gitaly.socket # TCP connections are supported too (e.g. tcp://host:port)
## Backup settings
backup:
diff --git a/config/initializers/8_gitaly.rb b/config/initializers/8_gitaly.rb
index 69c0a91d6f0..c7f27c78535 100644
--- a/config/initializers/8_gitaly.rb
+++ b/config/initializers/8_gitaly.rb
@@ -9,7 +9,7 @@ if Gitlab.config.gitaly.enabled || Rails.env.test?
raise "storage #{name.inspect} is missing a gitaly_address"
end
- unless URI(address).scheme == 'unix'
+ unless URI(address).scheme.in?(%w(tcp unix))
raise "Unsupported Gitaly address: #{address.inspect}"
end
diff --git a/config/routes/wiki.rb b/config/routes/wiki.rb
index a6b3f5d4693..c2da84ff6f2 100644
--- a/config/routes/wiki.rb
+++ b/config/routes/wiki.rb
@@ -1,5 +1,3 @@
-WIKI_SLUG_ID = { id: /\S+/ }.freeze unless defined? WIKI_SLUG_ID
-
scope(controller: :wikis) do
scope(path: 'wikis', as: :wikis) do
get :git_access
@@ -8,7 +6,7 @@ scope(controller: :wikis) do
post '/', to: 'wikis#create'
end
- scope(path: 'wikis/*id', as: :wiki, constraints: WIKI_SLUG_ID, format: false) do
+ scope(path: 'wikis/*id', as: :wiki, format: false) do
get :edit
get :history
post :preview_markdown
diff --git a/db/migrate/20170329124448_add_polling_interval_multiplier_to_application_settings.rb b/db/migrate/20170329124448_add_polling_interval_multiplier_to_application_settings.rb
new file mode 100644
index 00000000000..a8affd19a0b
--- /dev/null
+++ b/db/migrate/20170329124448_add_polling_interval_multiplier_to_application_settings.rb
@@ -0,0 +1,33 @@
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddPollingIntervalMultiplierToApplicationSettings < ActiveRecord::Migration
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ # When a migration requires downtime you **must** uncomment the following
+ # constant and define a short and easy to understand explanation as to why the
+ # migration requires downtime.
+ # DOWNTIME_REASON = ''
+
+ # When using the methods "add_concurrent_index" or "add_column_with_default"
+ # you must disable the use of transactions as these methods can not run in an
+ # existing transaction. When using "add_concurrent_index" make sure that this
+ # method is the _only_ method called in the migration, any other changes
+ # should go in a separate migration. This ensures that upon failure _only_ the
+ # index creation fails and can be retried or reverted easily.
+ #
+ # To disable transactions uncomment the following line and remove these
+ # comments:
+ disable_ddl_transaction!
+
+ def up
+ add_column_with_default :application_settings, :polling_interval_multiplier, :decimal, default: 1, allow_null: false
+ end
+
+ def down
+ remove_column :application_settings, :polling_interval_multiplier
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index dba242548c1..19aca4b941e 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
-ActiveRecord::Schema.define(version: 20170317203554) do
+ActiveRecord::Schema.define(version: 20170329124448) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -115,6 +115,7 @@ ActiveRecord::Schema.define(version: 20170317203554) do
t.integer "unique_ips_limit_per_user"
t.integer "unique_ips_limit_time_window"
t.boolean "unique_ips_limit_enabled", default: false, null: false
+ t.decimal "polling_interval_multiplier", default: 1.0, null: false
end
create_table "audit_events", force: :cascade do |t|
diff --git a/doc/api/settings.md b/doc/api/settings.md
index ad975e2e325..d99695ca986 100644
--- a/doc/api/settings.md
+++ b/doc/api/settings.md
@@ -48,7 +48,8 @@ Example response:
"koding_url": null,
"plantuml_enabled": false,
"plantuml_url": null,
- "terminal_max_session_time": 0
+ "terminal_max_session_time": 0,
+ "polling_interval_multiplier": 1.0
}
```
@@ -88,6 +89,7 @@ PUT /application/settings
| `plantuml_enabled` | boolean | no | Enable PlantUML integration. Default is `false`. |
| `plantuml_url` | string | yes (if `plantuml_enabled` is `true`) | The PlantUML instance URL for integration. |
| `terminal_max_session_time` | integer | no | Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time. |
+| `polling_interval_multiplier` | decimal | no | Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling. |
```bash
curl --request PUT --header "PRIVATE-TOKEN: 9koXpg98eAheJpvBs5tK" https://gitlab.example.com/api/v4/application/settings?signup_enabled=false&default_project_visibility=internal
@@ -124,6 +126,7 @@ Example response:
"koding_url": null,
"plantuml_enabled": false,
"plantuml_url": null,
- "terminal_max_session_time": 0
+ "terminal_max_session_time": 0,
+ "polling_interval_multiplier": 1.0
}
```
diff --git a/doc/ci/variables/README.md b/doc/ci/variables/README.md
index b35caf672a8..53c29a4fd98 100644
--- a/doc/ci/variables/README.md
+++ b/doc/ci/variables/README.md
@@ -352,7 +352,7 @@ Example values:
export CI_JOB_ID="50"
export CI_COMMIT_SHA="1ecfd275763eff1d6b4844ea3168962458c9f27a"
export CI_COMMIT_REF_NAME="master"
-export CI_REPOSITORY_URL="https://gitab-ci-token:abcde-1234ABCD5678ef@example.com/gitlab-org/gitlab-ce.git"
+export CI_REPOSITORY_URL="https://gitlab-ci-token:abcde-1234ABCD5678ef@example.com/gitlab-org/gitlab-ce.git"
export CI_COMMIT_TAG="1.0.0"
export CI_JOB_NAME="spec:other"
export CI_JOB_STAGE="test"
diff --git a/features/steps/dashboard/todos.rb b/features/steps/dashboard/todos.rb
index 7bd3c7ee653..3225e19995b 100644
--- a/features/steps/dashboard/todos.rb
+++ b/features/steps/dashboard/todos.rb
@@ -3,6 +3,7 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
include SharedPaths
include SharedProject
include SharedUser
+ include WaitForAjax
step '"John Doe" is a developer of project "Shop"' do
project.team << [john_doe, :developer]
@@ -138,6 +139,8 @@ class Spinach::Features::DashboardTodos < Spinach::FeatureSteps
step 'I should be directed to the corresponding page' do
page.should have_css('.identifier', text: 'Merge Request !1')
+ # Merge request page loads and issues a number of Ajax requests
+ wait_for_ajax
end
def should_see_todo(position, title, body, state: :pending)
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb
index 409cb5b924f..9fcf04efa38 100644
--- a/lib/api/api_guard.rb
+++ b/lib/api/api_guard.rb
@@ -121,7 +121,7 @@ module API
end
def oauth2_bearer_token_error_handler
- Proc.new do |e|
+ proc do |e|
response =
case e
when MissingTokenError
diff --git a/lib/api/entities.rb b/lib/api/entities.rb
index 5954aea8041..00d44821e3f 100644
--- a/lib/api/entities.rb
+++ b/lib/api/entities.rb
@@ -204,7 +204,7 @@ module API
expose :id, :name, :type, :path
expose :mode do |obj, options|
- filemode = obj.mode.to_s(8)
+ filemode = obj.mode
filemode = "0" + filemode if filemode.length < 6
filemode
end
@@ -581,6 +581,7 @@ module API
expose :plantuml_enabled
expose :plantuml_url
expose :terminal_max_session_time
+ expose :polling_interval_multiplier
end
class Release < Grape::Entity
diff --git a/lib/api/settings.rb b/lib/api/settings.rb
index d4d3229f0d1..c7f97ad2aab 100644
--- a/lib/api/settings.rb
+++ b/lib/api/settings.rb
@@ -110,6 +110,7 @@ module API
requires :housekeeping_gc_period, type: Integer, desc: "Number of Git pushes after which 'git gc' is run."
end
optional :terminal_max_session_time, type: Integer, desc: 'Maximum time for web terminal websocket connection (in seconds). Set to 0 for unlimited time.'
+ optional :polling_interval_multiplier, type: BigDecimal, desc: 'Interval multiplier used by endpoints that perform polling. Set to 0 to disable polling.'
at_least_one_of :default_branch_protection, :default_project_visibility, :default_snippet_visibility,
:default_group_visibility, :restricted_visibility_levels, :import_sources,
:enabled_git_access_protocol, :gravatar_enabled, :default_projects_limit,
@@ -125,7 +126,7 @@ module API
:akismet_enabled, :admin_notification_email, :sentry_enabled,
:repository_storage, :repository_checks_enabled, :koding_enabled, :plantuml_enabled,
:version_check_enabled, :email_author_in_body, :html_emails_enabled,
- :housekeeping_enabled, :terminal_max_session_time
+ :housekeeping_enabled, :terminal_max_session_time, :polling_interval_multiplier
end
put "application/settings" do
attrs = declared_params(include_missing: false)
diff --git a/lib/api/users.rb b/lib/api/users.rb
index a4201fe6fed..530ca0b5235 100644
--- a/lib/api/users.rb
+++ b/lib/api/users.rb
@@ -293,7 +293,7 @@ module API
user = User.find_by(id: params[:id])
not_found!('User') unless user
- ::Users::DestroyService.new(current_user).execute(user)
+ DeleteUserWorker.perform_async(current_user.id, user.id)
end
desc 'Block a user. Available only for admins.'
diff --git a/lib/gitlab/etag_caching/middleware.rb b/lib/gitlab/etag_caching/middleware.rb
index ffbc6e17dc5..9c98f0d1a30 100644
--- a/lib/gitlab/etag_caching/middleware.rb
+++ b/lib/gitlab/etag_caching/middleware.rb
@@ -18,8 +18,7 @@ module Gitlab
if_none_match = env['HTTP_IF_NONE_MATCH']
if if_none_match == etag
- Gitlab::Metrics.add_event(:etag_caching_cache_hit)
- [304, { 'ETag' => etag }, ['']]
+ handle_cache_hit(etag)
else
track_cache_miss(if_none_match, cached_value_present)
@@ -52,6 +51,14 @@ module Gitlab
%Q{W/"#{value}"}
end
+ def handle_cache_hit(etag)
+ Gitlab::Metrics.add_event(:etag_caching_cache_hit)
+
+ status_code = Gitlab::PollingInterval.polling_enabled? ? 304 : 429
+
+ [status_code, { 'ETag' => etag }, ['']]
+ end
+
def track_cache_miss(if_none_match, cached_value_present)
if if_none_match.blank?
Gitlab::Metrics.add_event(:etag_caching_header_missing)
diff --git a/lib/gitlab/git/repository.rb b/lib/gitlab/git/repository.rb
index 4e72519c81d..32aebb6f6f0 100644
--- a/lib/gitlab/git/repository.rb
+++ b/lib/gitlab/git/repository.rb
@@ -411,6 +411,11 @@ module Gitlab
rugged.merge_base(from, to)
end
+ # Returns true is +from+ is direct ancestor to +to+, otherwise false
+ def is_ancestor?(from, to)
+ Gitlab::GitalyClient::Commit.is_ancestor(self, from, to)
+ end
+
# Return an array of Diff objects that represent the diff
# between +from+ and +to+. See Diff::filter_diff_options for the allowed
# diff options. The +options+ hash can also include :break_rewrites to
diff --git a/lib/gitlab/git/tree.rb b/lib/gitlab/git/tree.rb
index f7450e8b58f..b722d8a9f56 100644
--- a/lib/gitlab/git/tree.rb
+++ b/lib/gitlab/git/tree.rb
@@ -33,7 +33,7 @@ module Gitlab
root_id: root_tree.oid,
name: entry[:name],
type: entry[:type],
- mode: entry[:filemode],
+ mode: entry[:filemode].to_s(8),
path: path ? File.join(path, entry[:name]) : entry[:name],
commit_id: sha,
)
diff --git a/lib/gitlab/gitaly_client.rb b/lib/gitlab/gitaly_client.rb
index a0dbe0a8c11..fe15fb12adb 100644
--- a/lib/gitlab/gitaly_client.rb
+++ b/lib/gitlab/gitaly_client.rb
@@ -12,9 +12,11 @@ module Gitlab
end
def self.new_channel(address)
- # NOTE: Gitaly currently runs on a Unix socket, so permissions are
+ address = address.sub(%r{^tcp://}, '') if URI(address).scheme == 'tcp'
+ # NOTE: When Gitaly runs on a Unix socket, permissions are
# handled using the file system and no additional authentication is
# required (therefore the :this_channel_is_insecure flag)
+ # TODO: Add authentication support when Gitaly is running on a TCP socket.
GRPC::Core::Channel.new(address, {}, :this_channel_is_insecure)
end
diff --git a/lib/gitlab/gitaly_client/commit.rb b/lib/gitlab/gitaly_client/commit.rb
index 9c714a3ee45..f15faebe27e 100644
--- a/lib/gitlab/gitaly_client/commit.rb
+++ b/lib/gitlab/gitaly_client/commit.rb
@@ -21,6 +21,20 @@ module Gitlab
Gitlab::Git::DiffCollection.new(stub.commit_diff(request), options)
end
+
+ def is_ancestor(repository, ancestor_id, child_id)
+ project = Project.find_by_path(repository.path)
+ channel = GitalyClient.get_channel(project.repository_storage)
+ stub = Gitaly::Commit::Stub.new(nil, nil, channel_override: channel)
+ repo = Gitaly::Repository.new(path: repository.path_to_repo)
+ request = Gitaly::CommitIsAncestorRequest.new(
+ repository: repo,
+ ancestor_id: ancestor_id,
+ child_id: child_id
+ )
+
+ stub.commit_is_ancestor(request).value
+ end
end
end
end
diff --git a/lib/gitlab/github_import/branch_formatter.rb b/lib/gitlab/github_import/branch_formatter.rb
index 5d29e698b27..8aa885fb811 100644
--- a/lib/gitlab/github_import/branch_formatter.rb
+++ b/lib/gitlab/github_import/branch_formatter.rb
@@ -11,6 +11,14 @@ module Gitlab
sha.present? && ref.present?
end
+ def user
+ raw_data.user&.login || 'unknown'
+ end
+
+ def short_sha
+ Commit.truncate_sha(sha)
+ end
+
private
def branch_exists?
diff --git a/lib/gitlab/github_import/pull_request_formatter.rb b/lib/gitlab/github_import/pull_request_formatter.rb
index add7236e339..38660a7ccca 100644
--- a/lib/gitlab/github_import/pull_request_formatter.rb
+++ b/lib/gitlab/github_import/pull_request_formatter.rb
@@ -1,8 +1,8 @@
module Gitlab
module GithubImport
class PullRequestFormatter < IssuableFormatter
- delegate :exists?, :project, :ref, :repo, :sha, to: :source_branch, prefix: true
- delegate :exists?, :project, :ref, :repo, :sha, to: :target_branch, prefix: true
+ delegate :user, :project, :ref, :repo, :sha, to: :source_branch, prefix: true
+ delegate :user, :exists?, :project, :ref, :repo, :sha, :short_sha, to: :target_branch, prefix: true
def attributes
{
@@ -37,13 +37,20 @@ module Gitlab
end
def source_branch_name
- @source_branch_name ||= begin
- if cross_project?
- "pull/#{number}/#{source_branch_repo.full_name}/#{source_branch_ref}"
+ @source_branch_name ||=
+ if cross_project? || !source_branch_exists?
+ source_branch_name_prefixed
else
- source_branch_exists? ? source_branch_ref : "pull/#{number}/#{source_branch_ref}"
+ source_branch_ref
end
- end
+ end
+
+ def source_branch_name_prefixed
+ "gh-#{target_branch_short_sha}/#{number}/#{source_branch_user}/#{source_branch_ref}"
+ end
+
+ def source_branch_exists?
+ !cross_project? && source_branch.exists?
end
def target_branch
@@ -51,13 +58,17 @@ module Gitlab
end
def target_branch_name
- @target_branch_name ||= begin
- target_branch_exists? ? target_branch_ref : "pull/#{number}/#{target_branch_ref}"
- end
+ @target_branch_name ||= target_branch_exists? ? target_branch_ref : target_branch_name_prefixed
+ end
+
+ def target_branch_name_prefixed
+ "gl-#{target_branch_short_sha}/#{number}/#{target_branch_user}/#{target_branch_ref}"
end
def cross_project?
- source_branch.repo.id != target_branch.repo.id
+ return true if source_branch_repo.nil?
+
+ source_branch_repo.id != target_branch_repo.id
end
def opened?
diff --git a/lib/gitlab/ldap/config.rb b/lib/gitlab/ldap/config.rb
index 28129198438..46deea3cc9f 100644
--- a/lib/gitlab/ldap/config.rb
+++ b/lib/gitlab/ldap/config.rb
@@ -124,9 +124,9 @@ module Gitlab
def name_proc
if allow_username_or_email_login
- Proc.new { |name| name.gsub(/@.*\z/, '') }
+ proc { |name| name.gsub(/@.*\z/, '') }
else
- Proc.new { |name| name }
+ proc { |name| name }
end
end
diff --git a/lib/gitlab/polling_interval.rb b/lib/gitlab/polling_interval.rb
new file mode 100644
index 00000000000..c44bb1cd14d
--- /dev/null
+++ b/lib/gitlab/polling_interval.rb
@@ -0,0 +1,22 @@
+module Gitlab
+ class PollingInterval
+ include Gitlab::CurrentSettings
+
+ HEADER_NAME = 'Poll-Interval'.freeze
+
+ def self.set_header(response, interval:)
+ if polling_enabled?
+ multiplier = current_application_settings.polling_interval_multiplier
+ value = (interval * multiplier).to_i
+ else
+ value = -1
+ end
+
+ response.headers[HEADER_NAME] = value
+ end
+
+ def self.polling_enabled?
+ !current_application_settings.polling_interval_multiplier.zero?
+ end
+ end
+end
diff --git a/lib/gitlab/shell.rb b/lib/gitlab/shell.rb
index da8d8ddb8ed..9864a9c7f1a 100644
--- a/lib/gitlab/shell.rb
+++ b/lib/gitlab/shell.rb
@@ -174,7 +174,10 @@ module Gitlab
# add_namespace("/path/to/storage", "gitlab")
#
def add_namespace(storage, name)
- FileUtils.mkdir_p(full_path(storage, name), mode: 0770) unless exists?(storage, name)
+ path = full_path(storage, name)
+ FileUtils.mkdir_p(path, mode: 0770) unless exists?(storage, name)
+ rescue Errno::EEXIST => e
+ Rails.logger.warn("Directory exists as a file: #{e} at: #{path}")
end
# Remove directory from repositories storage
diff --git a/lib/gitlab/workhorse.rb b/lib/gitlab/workhorse.rb
index 6fe85af3c30..d0637f8b394 100644
--- a/lib/gitlab/workhorse.rb
+++ b/lib/gitlab/workhorse.rb
@@ -16,15 +16,35 @@ module Gitlab
SECRET_LENGTH = 32
class << self
- def git_http_ok(repository, user)
+ def git_http_ok(repository, user, action)
+ repo_path = repository.path_to_repo
params = {
GL_ID: Gitlab::GlId.gl_id(user),
- RepoPath: repository.path_to_repo,
+ RepoPath: repo_path,
}
if Gitlab.config.gitaly.enabled
- address = Gitlab::GitalyClient.get_address(repository.project.repository_storage)
- params[:GitalySocketPath] = URI(address).path
+ storage = repository.project.repository_storage
+ address = Gitlab::GitalyClient.get_address(storage)
+ # TODO: use GitalyClient code to assemble the Repository message
+ params[:Repository] = Gitaly::Repository.new(
+ path: repo_path,
+ storage_name: storage,
+ relative_path: Gitlab::RepoPath.strip_storage_path(repo_path),
+ ).to_h
+
+ feature_enabled = case action.to_s
+ when 'git_receive_pack'
+ Gitlab::GitalyClient.feature_enabled?(:post_receive_pack)
+ when 'git_upload_pack'
+ Gitlab::GitalyClient.feature_enabled?(:post_upload_pack)
+ when 'info_refs'
+ true
+ else
+ raise "Unsupported action: #{action}"
+ end
+
+ params[:GitalySocketPath] = URI(address).path if feature_enabled
end
params
diff --git a/spec/controllers/registrations_controller_spec.rb b/spec/controllers/registrations_controller_spec.rb
index 902911071c4..71dd9ef3eb4 100644
--- a/spec/controllers/registrations_controller_spec.rb
+++ b/spec/controllers/registrations_controller_spec.rb
@@ -68,4 +68,20 @@ describe RegistrationsController do
end
end
end
+
+ describe '#destroy' do
+ let(:user) { create(:user) }
+
+ before do
+ sign_in(user)
+ end
+
+ it 'schedules the user for destruction' do
+ expect(DeleteUserWorker).to receive(:perform_async).with(user.id, user.id)
+
+ post(:destroy)
+
+ expect(response.status).to eq(302)
+ end
+ end
end
diff --git a/spec/controllers/sessions_controller_spec.rb b/spec/controllers/sessions_controller_spec.rb
index a06c29dd91a..9c16a7bc08b 100644
--- a/spec/controllers/sessions_controller_spec.rb
+++ b/spec/controllers/sessions_controller_spec.rb
@@ -211,4 +211,20 @@ describe SessionsController do
end
end
end
+
+ describe '#new' do
+ before do
+ @request.env['devise.mapping'] = Devise.mappings[:user]
+ end
+
+ it 'redirects correctly for referer on same host with params' do
+ search_path = '/search?search=seed_project'
+ allow(controller.request).to receive(:referer).
+ and_return('http://%{host}%{path}' % { host: Gitlab.config.gitlab.host, path: search_path })
+
+ get(:new, redirect_to_referer: :yes)
+
+ expect(controller.stored_location_for(:redirect)).to eq(search_path)
+ end
+ end
end
diff --git a/spec/features/auto_deploy_spec.rb b/spec/features/auto_deploy_spec.rb
index ea7a97d1d4f..009e9c6b04c 100644
--- a/spec/features/auto_deploy_spec.rb
+++ b/spec/features/auto_deploy_spec.rb
@@ -42,7 +42,7 @@ describe 'Auto deploy' do
it 'includes OpenShift as an available template', js: true do
click_link 'Set up auto deploy'
- click_button 'Choose a GitLab CI Yaml template'
+ click_button 'Apply a GitLab CI Yaml template'
within '.gitlab-ci-yml-selector' do
expect(page).to have_content('OpenShift')
@@ -51,7 +51,7 @@ describe 'Auto deploy' do
it 'creates a merge request using "auto-deploy" branch', js: true do
click_link 'Set up auto deploy'
- click_button 'Choose a GitLab CI Yaml template'
+ click_button 'Apply a GitLab CI Yaml template'
within '.gitlab-ci-yml-selector' do
click_on 'OpenShift'
end
diff --git a/spec/features/projects/blobs/user_create_spec.rb b/spec/features/projects/blobs/user_create_spec.rb
index 5686868a0c4..d214a531138 100644
--- a/spec/features/projects/blobs/user_create_spec.rb
+++ b/spec/features/projects/blobs/user_create_spec.rb
@@ -88,7 +88,7 @@ feature 'New blob creation', feature: true, js: true do
scenario 'shows error message' do
expect(page).to have_content('Your changes could not be committed because a file with the same name already exists')
- expect(page).to have_content('New File')
+ expect(page).to have_content('New file')
expect(page).to have_content('NextFeature')
end
end
diff --git a/spec/features/projects/files/project_owner_creates_license_file_spec.rb b/spec/features/projects/files/project_owner_creates_license_file_spec.rb
index ccadc936567..6b281e6d21d 100644
--- a/spec/features/projects/files/project_owner_creates_license_file_spec.rb
+++ b/spec/features/projects/files/project_owner_creates_license_file_spec.rb
@@ -40,7 +40,7 @@ feature 'project owner creates a license file', feature: true, js: true do
scenario 'project master creates a license file from the "Add license" link' do
click_link 'Add License'
- expect(page).to have_content('New File')
+ expect(page).to have_content('New file')
expect(current_path).to eq(
namespace_project_new_blob_path(project.namespace, project, 'master'))
expect(find('#file_name').value).to eq('LICENSE')
@@ -63,7 +63,7 @@ feature 'project owner creates a license file', feature: true, js: true do
def select_template(template)
page.within('.js-license-selector-wrap') do
- click_button 'Choose a License template'
+ click_button 'Apply a License template'
click_link template
wait_for_ajax
end
diff --git a/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb b/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
index 420db962318..87322ac2584 100644
--- a/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
+++ b/spec/features/projects/files/project_owner_sees_link_to_create_license_file_in_empty_project_spec.rb
@@ -14,7 +14,7 @@ feature 'project owner sees a link to create a license file in empty project', f
visit namespace_project_path(project.namespace, project)
click_link 'Create empty bare repository'
click_on 'LICENSE'
- expect(page).to have_content('New File')
+ expect(page).to have_content('New file')
expect(current_path).to eq(
namespace_project_new_blob_path(project.namespace, project, 'master'))
@@ -40,7 +40,7 @@ feature 'project owner sees a link to create a license file in empty project', f
def select_template(template)
page.within('.js-license-selector-wrap') do
- click_button 'Choose a License template'
+ click_button 'Apply a License template'
click_link template
wait_for_ajax
end
diff --git a/spec/features/projects/files/template_type_dropdown_spec.rb b/spec/features/projects/files/template_type_dropdown_spec.rb
new file mode 100644
index 00000000000..5ee5e5b4c4e
--- /dev/null
+++ b/spec/features/projects/files/template_type_dropdown_spec.rb
@@ -0,0 +1,135 @@
+require 'spec_helper'
+
+feature 'Template type dropdown selector', js: true do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ before do
+ project.team << [user, :master]
+ login_as user
+ end
+
+ context 'editing a non-matching file' do
+ before do
+ create_and_edit_file('.random-file.js')
+ end
+
+ scenario 'not displayed' do
+ check_type_selector_display(false)
+ end
+
+ scenario 'selects every template type correctly' do
+ fill_in 'file_path', with: '.gitignore'
+ try_selecting_all_types
+ end
+
+ scenario 'updates toggle value when input matches' do
+ fill_in 'file_path', with: '.gitignore'
+ check_type_selector_toggle_text('.gitignore')
+ end
+ end
+
+ context 'editing a matching file' do
+ before do
+ visit namespace_project_edit_blob_path(project.namespace, project, File.join(project.default_branch, 'LICENSE'))
+ end
+
+ scenario 'displayed' do
+ check_type_selector_display(true)
+ end
+
+ scenario 'is displayed when input matches' do
+ check_type_selector_display(true)
+ end
+
+ scenario 'selects every template type correctly' do
+ try_selecting_all_types
+ end
+
+ context 'user previews changes' do
+ before do
+ click_link 'Preview Changes'
+ end
+
+ scenario 'type selector is hidden and shown correctly' do
+ check_type_selector_display(false)
+ click_link 'Write'
+ check_type_selector_display(true)
+ end
+ end
+ end
+
+ context 'creating a matching file' do
+ before do
+ visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: '.gitignore')
+ end
+
+ scenario 'is displayed' do
+ check_type_selector_display(true)
+ end
+
+ scenario 'toggle is set to the correct value' do
+ check_type_selector_toggle_text('.gitignore')
+ end
+
+ scenario 'selects every template type correctly' do
+ try_selecting_all_types
+ end
+ end
+
+ context 'creating a file' do
+ before do
+ visit namespace_project_new_blob_path(project.namespace, project, project.default_branch)
+ end
+
+ scenario 'type selector is shown' do
+ check_type_selector_display(true)
+ end
+
+ scenario 'toggle is set to the proper value' do
+ check_type_selector_toggle_text('Choose type')
+ end
+
+ scenario 'selects every template type correctly' do
+ try_selecting_all_types
+ end
+ end
+end
+
+def check_type_selector_display(is_visible)
+ count = is_visible ? 1 : 0
+ expect(page).to have_css('.js-template-type-selector', count: count)
+end
+
+def try_selecting_all_types
+ try_selecting_template_type('LICENSE', 'Apply a License template')
+ try_selecting_template_type('Dockerfile', 'Apply a Dockerfile template')
+ try_selecting_template_type('.gitlab-ci.yml', 'Apply a GitLab CI Yaml template')
+ try_selecting_template_type('.gitignore', 'Apply a .gitignore template')
+end
+
+def try_selecting_template_type(template_type, selector_label)
+ select_template_type(template_type)
+ check_template_selector_display(selector_label)
+ check_type_selector_toggle_text(template_type)
+end
+
+def select_template_type(template_type)
+ find('.js-template-type-selector').click
+ find('.dropdown-content li', text: template_type).click
+end
+
+def check_template_selector_display(content)
+ expect(page).to have_content(content)
+end
+
+def check_type_selector_toggle_text(template_type)
+ dropdown_toggle_button = find('.template-type-selector .dropdown-toggle-text')
+ expect(dropdown_toggle_button).to have_content(template_type)
+end
+
+def create_and_edit_file(file_name)
+ visit namespace_project_new_blob_path(project.namespace, project, 'master', file_name: file_name)
+ click_button "Commit Changes"
+ visit namespace_project_edit_blob_path(project.namespace, project, File.join(project.default_branch, file_name))
+end
diff --git a/spec/features/projects/files/undo_template_spec.rb b/spec/features/projects/files/undo_template_spec.rb
new file mode 100644
index 00000000000..5479ea34610
--- /dev/null
+++ b/spec/features/projects/files/undo_template_spec.rb
@@ -0,0 +1,67 @@
+require 'spec_helper'
+include WaitForAjax
+
+feature 'Template Undo Button', js: true do
+ let(:project) { create(:project) }
+ let(:user) { create(:user) }
+
+ before do
+ project.team << [user, :master]
+ login_as user
+ end
+
+ context 'editing a matching file and applying a template' do
+ before do
+ visit namespace_project_edit_blob_path(project.namespace, project, File.join(project.default_branch, "LICENSE"))
+ select_file_template('.js-license-selector', 'Apache License 2.0')
+ end
+
+ scenario 'reverts template application' do
+ try_template_undo('http://www.apache.org/licenses/', 'Apply a License template')
+ end
+ end
+
+ context 'creating a non-matching file' do
+ before do
+ visit namespace_project_new_blob_path(project.namespace, project, 'master')
+ select_file_template_type('LICENSE')
+ select_file_template('.js-license-selector', 'Apache License 2.0')
+ end
+
+ scenario 'reverts template application' do
+ try_template_undo('http://www.apache.org/licenses/', 'Apply a License template')
+ end
+ end
+end
+
+def try_template_undo(template_content, toggle_text)
+ check_undo_button_display
+ check_content_reverted(template_content)
+ check_toggle_text_set(toggle_text)
+end
+
+def check_toggle_text_set(neutral_toggle_text)
+ expect(page).to have_content(neutral_toggle_text)
+end
+
+def check_undo_button_display
+ expect(page).to have_content('Template applied')
+ expect(page).to have_css('.template-selectors-undo-menu .btn-info')
+end
+
+def check_content_reverted(template_content)
+ find('.template-selectors-undo-menu .btn-info').click
+ expect(page).not_to have_content(template_content)
+ expect(find('.template-type-selector .dropdown-toggle-text')).to have_content()
+end
+
+def select_file_template(template_selector_selector, template_name)
+ find(template_selector_selector).click
+ find('.dropdown-content li', text: template_name).click
+ wait_for_ajax
+end
+
+def select_file_template_type(template_type)
+ find('.js-template-type-selector').click
+ find('.dropdown-content li', text: template_type).click
+end
diff --git a/spec/finders/issues_finder_spec.rb b/spec/finders/issues_finder_spec.rb
index ee52dc65175..231fd85c464 100644
--- a/spec/finders/issues_finder_spec.rb
+++ b/spec/finders/issues_finder_spec.rb
@@ -9,7 +9,7 @@ describe IssuesFinder do
let(:label) { create(:label, project: project2) }
let(:issue1) { create(:issue, author: user, assignee: user, project: project1, milestone: milestone, title: 'gitlab') }
let(:issue2) { create(:issue, author: user, assignee: user, project: project2, description: 'gitlab') }
- let(:issue3) { create(:issue, author: user2, assignee: user2, project: project2) }
+ let(:issue3) { create(:issue, author: user2, assignee: user2, project: project2, title: 'tanuki', description: 'tanuki') }
describe '#execute' do
let(:closed_issue) { create(:issue, author: user2, assignee: user2, project: project2, state: 'closed') }
diff --git a/spec/initializers/trusted_proxies_spec.rb b/spec/initializers/trusted_proxies_spec.rb
index ff8b8daa347..70a18f31744 100644
--- a/spec/initializers/trusted_proxies_spec.rb
+++ b/spec/initializers/trusted_proxies_spec.rb
@@ -56,7 +56,7 @@ describe 'trusted_proxies', lib: true do
end
def stub_request(headers = {})
- ActionDispatch::RemoteIp.new(Proc.new { }, false, Rails.application.config.action_dispatch.trusted_proxies).call(headers)
+ ActionDispatch::RemoteIp.new(proc { }, false, Rails.application.config.action_dispatch.trusted_proxies).call(headers)
ActionDispatch::Request.new(headers)
end
diff --git a/spec/javascripts/environments/environment_spec.js b/spec/javascripts/environments/environment_spec.js
index 9601575577e..9bcf617fcd8 100644
--- a/spec/javascripts/environments/environment_spec.js
+++ b/spec/javascripts/environments/environment_spec.js
@@ -91,6 +91,10 @@ describe('Environment', () => {
});
describe('pagination', () => {
+ afterEach(() => {
+ window.history.pushState({}, null, '');
+ });
+
it('should render pagination', (done) => {
setTimeout(() => {
expect(
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js
index 7cf39d37181..5a93d479c1f 100644
--- a/spec/javascripts/lib/utils/common_utils_spec.js
+++ b/spec/javascripts/lib/utils/common_utils_spec.js
@@ -46,6 +46,10 @@ require('~/lib/utils/common_utils');
spyOn(window.document, 'getElementById').and.callThrough();
});
+ afterEach(() => {
+ window.history.pushState({}, null, '');
+ });
+
function expectGetElementIdToHaveBeenCalledWith(elementId) {
expect(window.document.getElementById).toHaveBeenCalledWith(elementId);
}
@@ -75,11 +79,56 @@ require('~/lib/utils/common_utils');
});
});
+ describe('gl.utils.setParamInURL', () => {
+ afterEach(() => {
+ window.history.pushState({}, null, '');
+ });
+
+ it('should return the parameter', () => {
+ window.history.replaceState({}, null, '');
+
+ expect(gl.utils.setParamInURL('page', 156)).toBe('?page=156');
+ expect(gl.utils.setParamInURL('page', '156')).toBe('?page=156');
+ });
+
+ it('should update the existing parameter when its a number', () => {
+ window.history.pushState({}, null, '?page=15');
+
+ expect(gl.utils.setParamInURL('page', 16)).toBe('?page=16');
+ expect(gl.utils.setParamInURL('page', '16')).toBe('?page=16');
+ expect(gl.utils.setParamInURL('page', true)).toBe('?page=true');
+ });
+
+ it('should update the existing parameter when its a string', () => {
+ window.history.pushState({}, null, '?scope=all');
+
+ expect(gl.utils.setParamInURL('scope', 'finished')).toBe('?scope=finished');
+ });
+
+ it('should update the existing parameter when more than one parameter exists', () => {
+ window.history.pushState({}, null, '?scope=all&page=15');
+
+ expect(gl.utils.setParamInURL('scope', 'finished')).toBe('?scope=finished&page=15');
+ });
+
+ it('should add a new parameter to the end of the existing ones', () => {
+ window.history.pushState({}, null, '?scope=all');
+
+ expect(gl.utils.setParamInURL('page', 16)).toBe('?scope=all&page=16');
+ expect(gl.utils.setParamInURL('page', '16')).toBe('?scope=all&page=16');
+ expect(gl.utils.setParamInURL('page', true)).toBe('?scope=all&page=true');
+ });
+ });
+
describe('gl.utils.getParameterByName', () => {
beforeEach(() => {
window.history.pushState({}, null, '?scope=all&p=2');
});
+ afterEach(() => {
+ window.history.replaceState({}, null, null);
+ });
+
it('should return valid parameter', () => {
const value = gl.utils.getParameterByName('scope');
expect(value).toBe('all');
diff --git a/spec/javascripts/vue_shared/components/table_pagination_spec.js b/spec/javascripts/vue_shared/components/table_pagination_spec.js
index d1640ffed99..96038718191 100644
--- a/spec/javascripts/vue_shared/components/table_pagination_spec.js
+++ b/spec/javascripts/vue_shared/components/table_pagination_spec.js
@@ -124,6 +124,10 @@ describe('Pagination component', () => {
});
describe('paramHelper', () => {
+ afterEach(() => {
+ window.history.pushState({}, null, '');
+ });
+
it('can parse url parameters correctly', () => {
window.history.pushState({}, null, '?scope=all&p=2');
diff --git a/spec/lib/gitlab/etag_caching/middleware_spec.rb b/spec/lib/gitlab/etag_caching/middleware_spec.rb
index 8b5bfc4dbb0..6ec4360adc2 100644
--- a/spec/lib/gitlab/etag_caching/middleware_spec.rb
+++ b/spec/lib/gitlab/etag_caching/middleware_spec.rb
@@ -99,6 +99,19 @@ describe Gitlab::EtagCaching::Middleware do
middleware.call(build_env(path, if_none_match))
end
+
+ context 'when polling is disabled' do
+ before do
+ allow(Gitlab::PollingInterval).to receive(:polling_enabled?).
+ and_return(false)
+ end
+
+ it 'returns status code 429' do
+ status, _, _ = middleware.call(build_env(path, if_none_match))
+
+ expect(status).to eq 429
+ end
+ end
end
context 'when If-None-Match header does not match ETag in store' do
diff --git a/spec/lib/gitlab/git/tree_spec.rb b/spec/lib/gitlab/git/tree_spec.rb
index 83d2ff8f9b3..82685712b5b 100644
--- a/spec/lib/gitlab/git/tree_spec.rb
+++ b/spec/lib/gitlab/git/tree_spec.rb
@@ -19,6 +19,7 @@ describe Gitlab::Git::Tree, seed_helper: true do
it { expect(dir.commit_id).to eq(SeedRepo::Commit::ID) }
it { expect(dir.name).to eq('encoding') }
it { expect(dir.path).to eq('encoding') }
+ it { expect(dir.mode).to eq('40000') }
context :subdir do
let(:subdir) { Gitlab::Git::Tree.where(repository, SeedRepo::Commit::ID, 'files').first }
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb
new file mode 100644
index 00000000000..55fcf91fb6e
--- /dev/null
+++ b/spec/lib/gitlab/gitaly_client_spec.rb
@@ -0,0 +1,26 @@
+require 'spec_helper'
+
+describe Gitlab::GitalyClient, lib: true do
+ describe '.new_channel' do
+ context 'when passed a UNIX socket address' do
+ it 'passes the address as-is to GRPC::Core::Channel initializer' do
+ address = 'unix:/tmp/gitaly.sock'
+
+ expect(GRPC::Core::Channel).to receive(:new).with(address, any_args)
+
+ described_class.new_channel(address)
+ end
+ end
+
+ context 'when passed a TCP address' do
+ it 'strips tcp:// prefix before passing it to GRPC::Core::Channel initializer' do
+ address = 'localhost:9876'
+ prefixed_address = "tcp://#{address}"
+
+ expect(GRPC::Core::Channel).to receive(:new).with(address, any_args)
+
+ described_class.new_channel(prefixed_address)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/github_import/importer_spec.rb b/spec/lib/gitlab/github_import/importer_spec.rb
index 8b867fbe322..9d5e20841b5 100644
--- a/spec/lib/gitlab/github_import/importer_spec.rb
+++ b/spec/lib/gitlab/github_import/importer_spec.rb
@@ -215,9 +215,9 @@ describe Gitlab::GithubImport::Importer, lib: true do
let(:updated_at) { DateTime.strptime('2011-01-27T19:01:12Z') }
let(:repository) { double(id: 1, fork: false) }
let(:source_sha) { create(:commit, project: project).id }
- let(:source_branch) { double(ref: 'branch-merged', repo: repository, sha: source_sha) }
+ let(:source_branch) { double(ref: 'branch-merged', repo: repository, sha: source_sha, user: octocat) }
let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id }
- let(:target_branch) { double(ref: 'master', repo: repository, sha: target_sha) }
+ let(:target_branch) { double(ref: 'master', repo: repository, sha: target_sha, user: octocat) }
let(:pull_request) do
double(
number: 1347,
diff --git a/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb b/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
index 44423917944..9b9f7e4d34e 100644
--- a/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
+++ b/spec/lib/gitlab/github_import/pull_request_formatter_spec.rb
@@ -4,15 +4,18 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
let(:client) { double }
let(:project) { create(:project, :repository) }
let(:source_sha) { create(:commit, project: project).id }
- let(:target_sha) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit).id }
+ let(:target_commit) { create(:commit, project: project, git_commit: RepoHelpers.another_sample_commit) }
+ let(:target_sha) { target_commit.id }
+ let(:target_short_sha) { target_commit.id.to_s[0..7] }
let(:repository) { double(id: 1, fork: false) }
let(:source_repo) { repository }
let(:source_branch) { double(ref: 'branch-merged', repo: source_repo, sha: source_sha) }
let(:forked_source_repo) { double(id: 2, fork: true, name: 'otherproject', full_name: 'company/otherproject') }
let(:target_repo) { repository }
- let(:target_branch) { double(ref: 'master', repo: target_repo, sha: target_sha) }
- let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b') }
- let(:forked_branch) { double(ref: 'master', repo: forked_source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b') }
+ let(:target_branch) { double(ref: 'master', repo: target_repo, sha: target_sha, user: octocat) }
+ let(:removed_branch) { double(ref: 'removed-branch', repo: source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) }
+ let(:forked_branch) { double(ref: 'master', repo: forked_source_repo, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) }
+ let(:branch_deleted_repo) { double(ref: 'master', repo: nil, sha: '2e5d3239642f9161dcbbc4b70a211a68e5e45e2b', user: octocat) }
let(:octocat) { double(id: 123456, login: 'octocat', email: 'octocat@example.com') }
let(:created_at) { DateTime.strptime('2011-01-26T19:01:12Z') }
let(:updated_at) { DateTime.strptime('2011-01-27T19:01:12Z') }
@@ -203,16 +206,24 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context 'when source branch does not exist' do
let(:raw_data) { double(base_data.merge(head: removed_branch)) }
- it 'prefixes branch name with pull request number' do
- expect(pull_request.source_branch_name).to eq 'pull/1347/removed-branch'
+ it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do
+ expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/removed-branch"
end
end
context 'when source branch is from a fork' do
let(:raw_data) { double(base_data.merge(head: forked_branch)) }
- it 'prefixes branch name with pull request number and project with namespace to avoid collision' do
- expect(pull_request.source_branch_name).to eq 'pull/1347/company/otherproject/master'
+ it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do
+ expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/master"
+ end
+ end
+
+ context 'when source branch is from a deleted fork' do
+ let(:raw_data) { double(base_data.merge(head: branch_deleted_repo)) }
+
+ it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do
+ expect(pull_request.source_branch_name).to eq "gh-#{target_short_sha}/1347/octocat/master"
end
end
end
@@ -229,8 +240,8 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
context 'when target branch does not exist' do
let(:raw_data) { double(base_data.merge(base: removed_branch)) }
- it 'prefixes branch name with pull request number' do
- expect(pull_request.target_branch_name).to eq 'pull/1347/removed-branch'
+ it 'prefixes branch name with gh-:short_sha/:number/:user pattern to avoid collision' do
+ expect(pull_request.target_branch_name).to eq 'gl-2e5d3239/1347/octocat/removed-branch'
end
end
end
@@ -290,6 +301,14 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
+ context 'when source repository does not exist anymore' do
+ let(:raw_data) { double(base_data.merge(head: branch_deleted_repo)) }
+
+ it 'returns true' do
+ expect(pull_request.cross_project?).to eq true
+ end
+ end
+
context 'when source and target repositories are the same' do
let(:raw_data) { double(base_data.merge(head: source_branch)) }
@@ -299,6 +318,14 @@ describe Gitlab::GithubImport::PullRequestFormatter, lib: true do
end
end
+ describe '#source_branch_exists?' do
+ let(:raw_data) { double(base_data.merge(head: forked_branch)) }
+
+ it 'returns false when is a cross_project' do
+ expect(pull_request.source_branch_exists?).to eq false
+ end
+ end
+
describe '#url' do
let(:raw_data) { double(base_data) }
diff --git a/spec/lib/gitlab/polling_interval_spec.rb b/spec/lib/gitlab/polling_interval_spec.rb
new file mode 100644
index 00000000000..56c2847e26a
--- /dev/null
+++ b/spec/lib/gitlab/polling_interval_spec.rb
@@ -0,0 +1,34 @@
+require 'spec_helper'
+
+describe Gitlab::PollingInterval, lib: true do
+ let(:polling_interval) { described_class }
+
+ describe '.set_header' do
+ let(:headers) { {} }
+ let(:response) { double(headers: headers) }
+
+ context 'when polling is disabled' do
+ before do
+ stub_application_setting(polling_interval_multiplier: 0)
+ end
+
+ it 'sets value to -1' do
+ polling_interval.set_header(response, interval: 10_000)
+
+ expect(headers['Poll-Interval']).to eq(-1)
+ end
+ end
+
+ context 'when polling is enabled' do
+ before do
+ stub_application_setting(polling_interval_multiplier: 0.33333)
+ end
+
+ it 'applies modifier to base interval' do
+ polling_interval.set_header(response, interval: 10_000)
+
+ expect(headers['Poll-Interval']).to eq(3333)
+ end
+ end
+ end
+end
diff --git a/spec/lib/gitlab/workhorse_spec.rb b/spec/lib/gitlab/workhorse_spec.rb
index 535c96eeee9..3bd2a3238fe 100644
--- a/spec/lib/gitlab/workhorse_spec.rb
+++ b/spec/lib/gitlab/workhorse_spec.rb
@@ -179,19 +179,69 @@ describe Gitlab::Workhorse, lib: true do
describe '.git_http_ok' do
let(:user) { create(:user) }
+ let(:repo_path) { repository.path_to_repo }
+ let(:action) { 'info_refs' }
- subject { described_class.git_http_ok(repository, user) }
+ subject { described_class.git_http_ok(repository, user, action) }
- it { expect(subject).to eq({ GL_ID: "user-#{user.id}", RepoPath: repository.path_to_repo }) }
+ it { expect(subject).to include({ GL_ID: "user-#{user.id}", RepoPath: repo_path }) }
context 'when Gitaly is enabled' do
+ let(:gitaly_params) do
+ {
+ GitalySocketPath: URI(Gitlab::GitalyClient.get_address('default')).path,
+ }
+ end
+
before do
allow(Gitlab.config.gitaly).to receive(:enabled).and_return(true)
end
- it 'includes Gitaly params in the returned value' do
- gitaly_socket_path = URI(Gitlab::GitalyClient.get_address('default')).path
- expect(subject).to include({ GitalySocketPath: gitaly_socket_path })
+ it 'includes a Repository param' do
+ repo_param = { Repository: {
+ path: repo_path,
+ storage_name: 'default',
+ relative_path: project.full_path + '.git',
+ } }
+
+ expect(subject).to include(repo_param)
+ end
+
+ {
+ git_receive_pack: :post_receive_pack,
+ git_upload_pack: :post_upload_pack
+ }.each do |action_name, feature_flag|
+ context "when #{action_name} action is passed" do
+ let(:action) { action_name }
+
+ context 'when action is enabled by feature flag' do
+ it 'includes Gitaly params in the returned value' do
+ allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(feature_flag).and_return(true)
+
+ expect(subject).to include(gitaly_params)
+ end
+ end
+
+ context 'when action is not enabled by feature flag' do
+ it 'does not include Gitaly params in the returned value' do
+ allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(feature_flag).and_return(false)
+
+ expect(subject).not_to include(gitaly_params)
+ end
+ end
+ end
+ end
+
+ context "when info_refs action is passed" do
+ let(:action) { 'info_refs' }
+
+ it { expect(subject).to include(gitaly_params) }
+ end
+
+ context 'when action passed is not supported by Gitaly' do
+ let(:action) { 'download' }
+
+ it { expect { subject }.to raise_exception('Unsupported action: download') }
end
end
end
diff --git a/spec/models/repository_spec.rb b/spec/models/repository_spec.rb
index 585b87b828d..df742ee8084 100644
--- a/spec/models/repository_spec.rb
+++ b/spec/models/repository_spec.rb
@@ -1851,4 +1851,17 @@ describe Repository, models: true do
end
end
end
+
+ describe '#is_ancestor?' do
+ context 'Gitaly is_ancestor feature enabled' do
+ it 'asks Gitaly server if it\'s an ancestor' do
+ commit = repository.commit
+ allow(Gitlab::GitalyClient).to receive(:feature_enabled?).with(:is_ancestor).and_return(true)
+ expect(Gitlab::GitalyClient::Commit).to receive(:is_ancestor).
+ with(repository.raw_repository, commit.id, commit.id).and_return(true)
+
+ expect(repository.is_ancestor?(commit.id, commit.id)).to be true
+ end
+ end
+ end
end
diff --git a/spec/requests/api/users_spec.rb b/spec/requests/api/users_spec.rb
index 04e7837fd7a..f793c0db2f3 100644
--- a/spec/requests/api/users_spec.rb
+++ b/spec/requests/api/users_spec.rb
@@ -676,7 +676,7 @@ describe API::Users, api: true do
before { admin }
it "deletes user" do
- delete api("/users/#{user.id}", admin)
+ Sidekiq::Testing.inline! { delete api("/users/#{user.id}", admin) }
expect(response).to have_http_status(204)
expect { User.find(user.id) }.to raise_error ActiveRecord::RecordNotFound
@@ -684,23 +684,23 @@ describe API::Users, api: true do
end
it "does not delete for unauthenticated user" do
- delete api("/users/#{user.id}")
+ Sidekiq::Testing.inline! { delete api("/users/#{user.id}") }
expect(response).to have_http_status(401)
end
it "is not available for non admin users" do
- delete api("/users/#{user.id}", user)
+ Sidekiq::Testing.inline! { delete api("/users/#{user.id}", user) }
expect(response).to have_http_status(403)
end
it "returns 404 for non-existing user" do
- delete api("/users/999999", admin)
+ Sidekiq::Testing.inline! { delete api("/users/999999", admin) }
expect(response).to have_http_status(404)
expect(json_response['message']).to eq('404 User Not Found')
end
it "returns a 404 for invalid ID" do
- delete api("/users/ASDF", admin)
+ Sidekiq::Testing.inline! { delete api("/users/ASDF", admin) }
expect(response).to have_http_status(404)
end
diff --git a/spec/services/users/destroy_spec.rb b/spec/services/users/destroy_spec.rb
index 9a28c03d968..66c61b7f8ff 100644
--- a/spec/services/users/destroy_spec.rb
+++ b/spec/services/users/destroy_spec.rb
@@ -17,13 +17,28 @@ describe Users::DestroyService, services: true do
expect { Namespace.with_deleted.find(user.namespace.id) }.to raise_error(ActiveRecord::RecordNotFound)
end
- it 'will delete the project in the near future' do
- expect_any_instance_of(Projects::DestroyService).to receive(:async_execute).once
+ it 'will delete the project' do
+ expect_any_instance_of(Projects::DestroyService).to receive(:execute).once
service.execute(user)
end
end
+ context 'projects in pending_delete' do
+ before do
+ project.pending_delete = true
+ project.save
+ end
+
+ it 'destroys a project in pending_delete' do
+ expect_any_instance_of(Projects::DestroyService).to receive(:execute).once
+
+ service.execute(user)
+
+ expect { Project.find(project.id) }.to raise_error(ActiveRecord::RecordNotFound)
+ end
+ end
+
context "a deleted user's issues" do
let(:project) { create(:project) }
diff --git a/spec/support/test_env.rb b/spec/support/test_env.rb
index a19a35c2c0d..1b5cb71a6b0 100644
--- a/spec/support/test_env.rb
+++ b/spec/support/test_env.rb
@@ -131,8 +131,10 @@ module TestEnv
set_repo_refs(repo_path, branch_sha)
- # We must copy bare repositories because we will push to them.
- system(git_env, *%W(#{Gitlab.config.git.bin_path} clone -q --bare #{repo_path} #{repo_path_bare}))
+ unless File.directory?(repo_path_bare)
+ # We must copy bare repositories because we will push to them.
+ system(git_env, *%W(#{Gitlab.config.git.bin_path} clone -q --bare #{repo_path} #{repo_path_bare}))
+ end
end
def copy_repo(project)