summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Gemfile1
-rw-r--r--Gemfile.lock3
-rw-r--r--app/assets/javascripts/contextual_sidebar.js2
-rw-r--r--app/assets/javascripts/filtered_search/available_dropdown_mappings.js16
-rw-r--r--app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js6
-rw-r--r--app/assets/javascripts/filtered_search/filtered_search_manager.js2
-rw-r--r--app/assets/javascripts/filtered_search/visual_token_value.js8
-rw-r--r--app/assets/javascripts/monitoring/components/dashboard.vue14
-rw-r--r--app/assets/javascripts/monitoring/stores/actions.js4
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/comment.js132
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/constants.js37
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/index.js23
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/login.js52
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/note.js27
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/utils.js42
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/wrapper.js82
-rw-r--r--app/assets/javascripts/visual_review_toolbar/components/wrapper_icons.js15
-rw-r--r--app/assets/javascripts/visual_review_toolbar/index.js37
-rw-r--r--app/assets/javascripts/visual_review_toolbar/store/events.js36
-rw-r--r--app/assets/javascripts/visual_review_toolbar/store/index.js5
-rw-r--r--app/assets/javascripts/visual_review_toolbar/store/state.js77
-rw-r--r--app/assets/javascripts/visual_review_toolbar/store/utils.js15
-rw-r--r--app/assets/stylesheets/framework/variables.scss2
-rw-r--r--app/helpers/dropdowns_helper.rb2
-rw-r--r--app/helpers/environments_helper.rb2
-rw-r--r--app/helpers/markup_helper.rb5
-rw-r--r--app/helpers/search_helper.rb6
-rw-r--r--app/mailers/repository_check_mailer.rb2
-rw-r--r--app/models/commit.rb2
-rw-r--r--app/models/group.rb2
-rw-r--r--app/views/layouts/nav/sidebar/_project.html.haml2
-rw-r--r--app/views/shared/_sidebar_toggle_button.html.haml2
-rw-r--r--app/views/shared/issuable/_sidebar.html.haml4
-rw-r--r--changelogs/unreleased/62684-add-index-public-email-on-users.yml5
-rw-r--r--changelogs/unreleased/asciidoc-include-directive.yml5
-rw-r--r--changelogs/unreleased/dhiraj-fix-missing-deployment-rockets-in-monitoring-dashboard.yml5
-rw-r--r--changelogs/unreleased/ensure_namespace.yml5
-rw-r--r--changelogs/unreleased/feature-require-2fa-for-all-entities-in-group.yml4
-rw-r--r--changelogs/unreleased/fix-flyout-navs.yml5
-rw-r--r--changelogs/unreleased/sh-omit-blocked-admins-from-notification.yml5
-rw-r--r--changelogs/unreleased/sh-speed-up-commit-loading.yml5
-rw-r--r--config/initializers/7_prometheus_metrics.rb6
-rw-r--r--db/migrate/20190607190856_add_index_to_users_public_emails.rb23
-rw-r--r--db/schema.rb1
-rw-r--r--doc/development/contributing/issue_workflow.md4
-rw-r--r--doc/development/testing_guide/end_to_end/quick_start_guide.md8
-rw-r--r--doc/security/two_factor_authentication.md22
-rw-r--r--doc/ssh/README.md11
-rw-r--r--doc/user/asciidoc.md372
-rw-r--r--doc/user/project/deploy_boards.md6
-rw-r--r--doc/user/project/repository/index.md2
-rw-r--r--lib/gitlab/asciidoc.rb54
-rw-r--r--lib/gitlab/asciidoc/html5_converter.rb32
-rw-r--r--lib/gitlab/asciidoc/include_processor.rb126
-rw-r--r--lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml2
-rw-r--r--lib/gitlab/legacy_github_import/importer.rb7
-rw-r--r--qa/qa/page/base.rb4
-rw-r--r--qa/qa/page/project/issue/show.rb46
-rw-r--r--qa/qa/resource/issue.rb17
-rw-r--r--qa/qa/resource/label.rb21
-rw-r--r--qa/qa/specs/features/browser_ui/2_plan/issue/collapse_comments_in_discussions_spec.rb2
-rw-r--r--qa/qa/specs/features/browser_ui/2_plan/issue/create_issue_spec.rb2
-rw-r--r--qa/qa/specs/features/browser_ui/2_plan/issue/filter_issue_comments_spec.rb2
-rw-r--r--qa/qa/specs/features/browser_ui/3_create/merge_request/create_merge_request_spec.rb6
-rw-r--r--qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb2
-rw-r--r--qa/qa/support/page/logging.rb2
-rw-r--r--qa/spec/page/logging_spec.rb4
-rw-r--r--spec/features/contextual_sidebar_spec.rb37
-rw-r--r--spec/helpers/environments_helper_spec.rb2
-rw-r--r--spec/helpers/search_helper_spec.rb12
-rw-r--r--spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js4
-rw-r--r--spec/javascripts/filtered_search/visual_token_value_spec.js4
-rw-r--r--spec/javascripts/monitoring/dashboard_spec.js2
-rw-r--r--spec/javascripts/monitoring/store/actions_spec.js8
-rw-r--r--spec/javascripts/vue_shared/components/sidebar/labels_select/mock_data.js4
-rw-r--r--spec/lib/gitlab/asciidoc_spec.rb188
-rw-r--r--spec/lib/gitlab/legacy_github_import/importer_spec.rb19
-rw-r--r--spec/mailers/repository_check_mailer_spec.rb10
-rw-r--r--spec/models/commit_spec.rb8
-rw-r--r--spec/models/group_spec.rb100
-rw-r--r--spec/models/user_spec.rb25
-rw-r--r--vendor/assets/javascripts/visual_review_toolbar.js377
82 files changed, 1759 insertions, 531 deletions
diff --git a/Gemfile b/Gemfile
index 375fcaf76ce..a5dccd2ef24 100644
--- a/Gemfile
+++ b/Gemfile
@@ -130,6 +130,7 @@ gem 'org-ruby', '~> 0.9.12'
gem 'creole', '~> 0.5.0'
gem 'wikicloth', '0.8.1'
gem 'asciidoctor', '~> 1.5.8'
+gem 'asciidoctor-include-ext', '~> 0.3.1', require: false
gem 'asciidoctor-plantuml', '0.0.8'
gem 'rouge', '~> 3.1'
gem 'truncato', '~> 0.7.11'
diff --git a/Gemfile.lock b/Gemfile.lock
index c403f45109c..0159d1f96e8 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -67,6 +67,8 @@ GEM
faraday_middleware-multi_json (~> 0.0)
oauth2 (~> 1.0)
asciidoctor (1.5.8)
+ asciidoctor-include-ext (0.3.1)
+ asciidoctor (>= 1.5.6, < 3.0.0)
asciidoctor-plantuml (0.0.8)
asciidoctor (~> 1.5)
ast (2.4.0)
@@ -1024,6 +1026,7 @@ DEPENDENCIES
apollo_upload_server (~> 2.0.0.beta3)
asana (~> 0.8.1)
asciidoctor (~> 1.5.8)
+ asciidoctor-include-ext (~> 0.3.1)
asciidoctor-plantuml (= 0.0.8)
attr_encrypted (~> 3.1.0)
awesome_print
diff --git a/app/assets/javascripts/contextual_sidebar.js b/app/assets/javascripts/contextual_sidebar.js
index b62ec8a651b..9263e9b27e4 100644
--- a/app/assets/javascripts/contextual_sidebar.js
+++ b/app/assets/javascripts/contextual_sidebar.js
@@ -78,7 +78,7 @@ export default class ContextualSidebar {
const dbp = ContextualSidebar.isDesktopBreakpoint();
if (this.$sidebar.length) {
- this.$sidebar.toggleClass('sidebar-collapsed-desktop', collapsed);
+ this.$sidebar.toggleClass(`sidebar-collapsed-desktop ${SIDEBAR_COLLAPSED_CLASS}`, collapsed);
this.$sidebar.toggleClass('sidebar-expanded-mobile', !dbp ? !collapsed : false);
this.$page.toggleClass(
'page-with-icon-sidebar',
diff --git a/app/assets/javascripts/filtered_search/available_dropdown_mappings.js b/app/assets/javascripts/filtered_search/available_dropdown_mappings.js
index be867a3838d..891086b4142 100644
--- a/app/assets/javascripts/filtered_search/available_dropdown_mappings.js
+++ b/app/assets/javascripts/filtered_search/available_dropdown_mappings.js
@@ -8,9 +8,19 @@ import DropdownUtils from './dropdown_utils';
import { mergeUrlParams } from '../lib/utils/url_utility';
export default class AvailableDropdownMappings {
- constructor(container, baseEndpoint, groupsOnly, includeAncestorGroups, includeDescendantGroups) {
+ constructor(
+ container,
+ baseEndpoint,
+ labelsEndpoint,
+ milestonesEndpoint,
+ groupsOnly,
+ includeAncestorGroups,
+ includeDescendantGroups,
+ ) {
this.container = container;
this.baseEndpoint = baseEndpoint;
+ this.labelsEndpoint = labelsEndpoint;
+ this.milestonesEndpoint = milestonesEndpoint;
this.groupsOnly = groupsOnly;
this.includeAncestorGroups = includeAncestorGroups;
this.includeDescendantGroups = includeDescendantGroups;
@@ -117,11 +127,11 @@ export default class AvailableDropdownMappings {
}
getMilestoneEndpoint() {
- return `${this.baseEndpoint}/milestones.json`;
+ return `${this.milestonesEndpoint}.json`;
}
getLabelsEndpoint() {
- let endpoint = `${this.baseEndpoint}/labels.json?`;
+ let endpoint = `${this.labelsEndpoint}.json?`;
if (this.groupsOnly) {
endpoint = `${endpoint}only_group_labels=true&`;
diff --git a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js
index cb0a84b490b..1cbfd7f9bb9 100644
--- a/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js
+++ b/app/assets/javascripts/filtered_search/filtered_search_dropdown_manager.js
@@ -9,6 +9,8 @@ import FilteredSearchVisualTokens from './filtered_search_visual_tokens';
export default class FilteredSearchDropdownManager {
constructor({
baseEndpoint = '',
+ labelsEndpoint = '',
+ milestonesEndpoint = '',
tokenizer,
page,
isGroup,
@@ -18,6 +20,8 @@ export default class FilteredSearchDropdownManager {
}) {
this.container = FilteredSearchContainer.container;
this.baseEndpoint = baseEndpoint.replace(/\/$/, '');
+ this.labelsEndpoint = labelsEndpoint.replace(/\/$/, '');
+ this.milestonesEndpoint = milestonesEndpoint.replace(/\/$/, '');
this.tokenizer = tokenizer;
this.filteredSearchTokenKeys = filteredSearchTokenKeys || FilteredSearchTokenKeys;
this.filteredSearchInput = this.container.querySelector('.filtered-search');
@@ -48,6 +52,8 @@ export default class FilteredSearchDropdownManager {
const availableMappings = new AvailableDropdownMappings(
this.container,
this.baseEndpoint,
+ this.labelsEndpoint,
+ this.milestonesEndpoint,
this.groupsOnly,
this.includeAncestorGroups,
this.includeDescendantGroups,
diff --git a/app/assets/javascripts/filtered_search/filtered_search_manager.js b/app/assets/javascripts/filtered_search/filtered_search_manager.js
index 78fbb3696cc..450e0725f2e 100644
--- a/app/assets/javascripts/filtered_search/filtered_search_manager.js
+++ b/app/assets/javascripts/filtered_search/filtered_search_manager.js
@@ -86,6 +86,8 @@ export default class FilteredSearchManager {
this.tokenizer = FilteredSearchTokenizer;
this.dropdownManager = new FilteredSearchDropdownManager({
baseEndpoint: this.filteredSearchInput.getAttribute('data-base-endpoint') || '',
+ labelsEndpoint: this.filteredSearchInput.getAttribute('data-labels-endpoint') || '',
+ milestonesEndpoint: this.filteredSearchInput.getAttribute('data-milestones-endpoint') || '',
tokenizer: this.tokenizer,
page: this.page,
isGroup: this.isGroup,
diff --git a/app/assets/javascripts/filtered_search/visual_token_value.js b/app/assets/javascripts/filtered_search/visual_token_value.js
index 38327472cb3..a54b445fb0a 100644
--- a/app/assets/javascripts/filtered_search/visual_token_value.js
+++ b/app/assets/javascripts/filtered_search/visual_token_value.js
@@ -56,13 +56,13 @@ export default class VisualTokenValue {
updateLabelTokenColor(tokenValueContainer) {
const { tokenValue } = this;
const filteredSearchInput = FilteredSearchContainer.container.querySelector('.filtered-search');
- const { baseEndpoint } = filteredSearchInput.dataset;
- const labelsEndpoint = FilteredSearchVisualTokens.getEndpointWithQueryParams(
- `${baseEndpoint}/labels.json`,
+ const { labelsEndpoint } = filteredSearchInput.dataset;
+ const labelsEndpointWithParams = FilteredSearchVisualTokens.getEndpointWithQueryParams(
+ `${labelsEndpoint}.json`,
filteredSearchInput.dataset.endpointQueryParams,
);
- return AjaxCache.retrieve(labelsEndpoint)
+ return AjaxCache.retrieve(labelsEndpointWithParams)
.then(labels => {
const matchingLabel = (labels || []).find(
label => `~${DropdownUtils.getEscapedText(label.title)}` === tokenValue,
diff --git a/app/assets/javascripts/monitoring/components/dashboard.vue b/app/assets/javascripts/monitoring/components/dashboard.vue
index d716fc211ca..0a652329dfe 100644
--- a/app/assets/javascripts/monitoring/components/dashboard.vue
+++ b/app/assets/javascripts/monitoring/components/dashboard.vue
@@ -70,7 +70,7 @@ export default {
type: String,
required: true,
},
- deploymentEndpoint: {
+ deploymentsEndpoint: {
type: String,
required: false,
default: null,
@@ -148,7 +148,7 @@ export default {
this.setEndpoints({
metricsEndpoint: this.metricsEndpoint,
environmentsEndpoint: this.environmentsEndpoint,
- deploymentsEndpoint: this.deploymentEndpoint,
+ deploymentsEndpoint: this.deploymentsEndpoint,
dashboardEndpoint: this.dashboardEndpoint,
});
@@ -280,9 +280,8 @@ export default {
<gl-button
v-gl-modal-directive="$options.addMetric.modalId"
class="js-add-metric-button text-success border-success"
+ >{{ $options.addMetric.title }}</gl-button
>
- {{ $options.addMetric.title }}
- </gl-button>
<gl-modal
ref="addMetricModal"
:modal-id="$options.addMetric.modalId"
@@ -296,16 +295,13 @@ export default {
/>
</form>
<div slot="modal-footer">
- <gl-button @click="hideAddMetricModal">
- {{ __('Cancel') }}
- </gl-button>
+ <gl-button @click="hideAddMetricModal">{{ __('Cancel') }}</gl-button>
<gl-button
:disabled="!formIsValid"
variant="success"
@click="submitCustomMetricsForm"
+ >{{ __('Save changes') }}</gl-button
>
- {{ __('Save changes') }}
- </gl-button>
</div>
</gl-modal>
</div>
diff --git a/app/assets/javascripts/monitoring/stores/actions.js b/app/assets/javascripts/monitoring/stores/actions.js
index 49ce722b838..f41e215cb5d 100644
--- a/app/assets/javascripts/monitoring/stores/actions.js
+++ b/app/assets/javascripts/monitoring/stores/actions.js
@@ -164,10 +164,10 @@ export const fetchPrometheusMetrics = ({ state, commit, dispatch }, params) => {
};
export const fetchDeploymentsData = ({ state, dispatch }) => {
- if (!state.deploymentEndpoint) {
+ if (!state.deploymentsEndpoint) {
return Promise.resolve([]);
}
- return backOffRequest(() => axios.get(state.deploymentEndpoint))
+ return backOffRequest(() => axios.get(state.deploymentsEndpoint))
.then(resp => resp.data)
.then(response => {
if (!response || !response.deployments) {
diff --git a/app/assets/javascripts/visual_review_toolbar/components/comment.js b/app/assets/javascripts/visual_review_toolbar/components/comment.js
new file mode 100644
index 00000000000..2fec96d1435
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/comment.js
@@ -0,0 +1,132 @@
+import { BLACK, COMMENT_BOX, MUTED, LOGOUT } from './constants';
+import { clearNote, note, postError } from './note';
+import { buttonClearStyles, selectCommentBox, selectCommentButton, selectNote } from './utils';
+
+const comment = `
+ <div>
+ <textarea id="${COMMENT_BOX}" name="${COMMENT_BOX}" rows="3" placeholder="Enter your feedback or idea" class="gitlab-input" aria-required="true"></textarea>
+ ${note}
+ <p class="gitlab-metadata-note">Additional metadata will be included: browser, OS, current page, user agent, and viewport dimensions.</p>
+ </div>
+ <div class="gitlab-button-wrapper">
+ <button class="gitlab-button gitlab-button-secondary" style="${buttonClearStyles}" type="button" id="${LOGOUT}"> Logout </button>
+ <button class="gitlab-button gitlab-button-success" style="${buttonClearStyles}" type="button" id="gitlab-comment-button"> Send feedback </button>
+ </div>
+`;
+
+const resetCommentBox = () => {
+ const commentBox = selectCommentBox();
+ const commentButton = selectCommentButton();
+
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ commentButton.innerText = 'Send feedback';
+ commentButton.classList.replace('gitlab-button-secondary', 'gitlab-button-success');
+ commentButton.style.opacity = 1;
+
+ commentBox.style.pointerEvents = 'auto';
+ commentBox.style.color = BLACK;
+};
+
+const resetCommentButton = () => {
+ const commentBox = selectCommentBox();
+ const currentNote = selectNote();
+
+ commentBox.value = '';
+ currentNote.innerText = '';
+};
+
+const resetComment = () => {
+ resetCommentBox();
+ resetCommentButton();
+};
+
+const confirmAndClear = mergeRequestId => {
+ const commentButton = selectCommentButton();
+ const currentNote = selectNote();
+
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ commentButton.innerText = 'Feedback sent';
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ currentNote.innerText = `Your comment was successfully posted to merge request #${mergeRequestId}`;
+ setTimeout(resetComment, 2000);
+};
+
+const setInProgressState = () => {
+ const commentButton = selectCommentButton();
+ const commentBox = selectCommentBox();
+
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ commentButton.innerText = 'Sending feedback';
+ commentButton.classList.replace('gitlab-button-success', 'gitlab-button-secondary');
+ commentButton.style.opacity = 0.5;
+ commentBox.style.color = MUTED;
+ commentBox.style.pointerEvents = 'none';
+};
+
+const postComment = ({
+ href,
+ platform,
+ browser,
+ userAgent,
+ innerWidth,
+ innerHeight,
+ projectId,
+ mergeRequestId,
+ mrUrl,
+ token,
+}) => {
+ // Clear any old errors
+ clearNote(COMMENT_BOX);
+
+ setInProgressState();
+
+ const commentText = selectCommentBox().value.trim();
+
+ if (!commentText) {
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ postError('Your comment appears to be empty.', COMMENT_BOX);
+ resetCommentBox();
+ return;
+ }
+
+ const detailText = `
+ \n
+<details>
+ <summary>Metadata</summary>
+ Posted from ${href} | ${platform} | ${browser} | ${innerWidth} x ${innerHeight}.
+ <br /><br />
+ <em>User agent: ${userAgent}</em>
+</details>
+ `;
+
+ const url = `
+ ${mrUrl}/api/v4/projects/${projectId}/merge_requests/${mergeRequestId}/discussions`;
+
+ const body = `${commentText} ${detailText}`;
+
+ fetch(url, {
+ method: 'POST',
+ headers: {
+ 'PRIVATE-TOKEN': token,
+ 'Content-Type': 'application/json',
+ },
+ body: JSON.stringify({ body }),
+ })
+ .then(response => {
+ if (response.ok) {
+ confirmAndClear(mergeRequestId);
+ return;
+ }
+
+ throw new Error(`${response.status}: ${response.statusText}`);
+ })
+ .catch(err => {
+ postError(
+ `Your comment could not be sent. Please try again. Error: ${err.message}`,
+ COMMENT_BOX,
+ );
+ resetCommentBox();
+ });
+};
+
+export { comment, postComment };
diff --git a/app/assets/javascripts/visual_review_toolbar/components/constants.js b/app/assets/javascripts/visual_review_toolbar/components/constants.js
new file mode 100644
index 00000000000..32ed1153515
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/constants.js
@@ -0,0 +1,37 @@
+// component selectors
+const COLLAPSE_BUTTON = 'gitlab-collapse';
+const COMMENT_BOX = 'gitlab-comment';
+const COMMENT_BUTTON = 'gitlab-comment-button';
+const FORM = 'gitlab-form-wrapper';
+const LOGIN = 'gitlab-login';
+const LOGOUT = 'gitlab-logout-button';
+const NOTE = 'gitlab-validation-note';
+const REMEMBER_TOKEN = 'gitlab-remember_token';
+const REVIEW_CONTAINER = 'gitlab-review-container';
+const TOKEN_BOX = 'gitlab-token';
+
+// colors — these are applied programmatically
+// rest of styles belong in ./styles
+const BLACK = 'rgba(46, 46, 46, 1)';
+const CLEAR = 'rgba(255, 255, 255, 0)';
+const MUTED = 'rgba(223, 223, 223, 0.5)';
+const RED = 'rgba(219, 59, 33, 1)';
+const WHITE = 'rgba(255, 255, 255, 1)';
+
+export {
+ COLLAPSE_BUTTON,
+ COMMENT_BOX,
+ COMMENT_BUTTON,
+ FORM,
+ LOGIN,
+ LOGOUT,
+ NOTE,
+ REMEMBER_TOKEN,
+ REVIEW_CONTAINER,
+ TOKEN_BOX,
+ BLACK,
+ CLEAR,
+ MUTED,
+ RED,
+ WHITE,
+};
diff --git a/app/assets/javascripts/visual_review_toolbar/components/index.js b/app/assets/javascripts/visual_review_toolbar/components/index.js
new file mode 100644
index 00000000000..43581818152
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/index.js
@@ -0,0 +1,23 @@
+import { comment, postComment } from './comment';
+import { COLLAPSE_BUTTON, COMMENT_BUTTON, LOGIN, LOGOUT, REVIEW_CONTAINER } from './constants';
+import { authorizeUser, login } from './login';
+import { selectContainer } from './utils';
+import { form, logoutUser, toggleForm } from './wrapper';
+import { collapseButton } from './wrapper_icons';
+
+export {
+ authorizeUser,
+ collapseButton,
+ comment,
+ form,
+ login,
+ logoutUser,
+ postComment,
+ selectContainer,
+ toggleForm,
+ COLLAPSE_BUTTON,
+ COMMENT_BUTTON,
+ LOGIN,
+ LOGOUT,
+ REVIEW_CONTAINER,
+};
diff --git a/app/assets/javascripts/visual_review_toolbar/components/login.js b/app/assets/javascripts/visual_review_toolbar/components/login.js
new file mode 100644
index 00000000000..ce713cdc520
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/login.js
@@ -0,0 +1,52 @@
+import { LOGIN, REMEMBER_TOKEN, TOKEN_BOX } from './constants';
+import { clearNote, note, postError } from './note';
+import { buttonClearStyles, selectRemember, selectToken } from './utils';
+import { addCommentForm } from './wrapper';
+
+const login = `
+ <div>
+ <label for="${TOKEN_BOX}" class="gitlab-label">Enter your <a class="gitlab-link" href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html">personal access token</a></label>
+ <input class="gitlab-input" type="password" id="${TOKEN_BOX}" name="${TOKEN_BOX}" aria-required="true" autocomplete="current-password">
+ ${note}
+ </div>
+ <div class="gitlab-checkbox-wrapper">
+ <input type="checkbox" id="${REMEMBER_TOKEN}" name="${REMEMBER_TOKEN}" value="remember">
+ <label for="${REMEMBER_TOKEN}" class="gitlab-checkbox-label">Remember me</label>
+ </div>
+ <div class="gitlab-button-wrapper">
+ <button class="gitlab-button-wide gitlab-button gitlab-button-success" style="${buttonClearStyles}" type="button" id="${LOGIN}"> Submit </button>
+ </div>
+`;
+
+const storeToken = (token, state) => {
+ const { localStorage } = window;
+ const rememberMe = selectRemember().checked;
+
+ // All the browsers we support have localStorage, so let's silently fail
+ // and go on with the rest of the functionality.
+ try {
+ if (rememberMe) {
+ localStorage.setItem('token', token);
+ }
+ } finally {
+ state.token = token;
+ }
+};
+
+const authorizeUser = state => {
+ // Clear any old errors
+ clearNote(TOKEN_BOX);
+
+ const token = selectToken().value;
+
+ if (!token) {
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ postError('Please enter your token.', TOKEN_BOX);
+ return;
+ }
+
+ storeToken(token, state);
+ addCommentForm();
+};
+
+export { authorizeUser, login };
diff --git a/app/assets/javascripts/visual_review_toolbar/components/note.js b/app/assets/javascripts/visual_review_toolbar/components/note.js
new file mode 100644
index 00000000000..dfebf58fd95
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/note.js
@@ -0,0 +1,27 @@
+import { NOTE, RED } from './constants';
+import { selectById, selectNote } from './utils';
+
+const note = `
+ <p id=${NOTE} class='gitlab-message'></p>
+`;
+
+const clearNote = inputId => {
+ const currentNote = selectNote();
+ currentNote.innerText = '';
+ currentNote.style.color = '';
+
+ if (inputId) {
+ const field = document.getElementById(inputId);
+ field.style.borderColor = '';
+ }
+};
+
+const postError = (message, inputId) => {
+ const currentNote = selectNote();
+ const field = selectById(inputId);
+ field.style.borderColor = RED;
+ currentNote.style.color = RED;
+ currentNote.innerText = message;
+};
+
+export { clearNote, note, postError };
diff --git a/app/assets/javascripts/visual_review_toolbar/components/utils.js b/app/assets/javascripts/visual_review_toolbar/components/utils.js
new file mode 100644
index 00000000000..7bc2e5a905b
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/utils.js
@@ -0,0 +1,42 @@
+/* global document */
+
+import {
+ COLLAPSE_BUTTON,
+ COMMENT_BOX,
+ COMMENT_BUTTON,
+ FORM,
+ NOTE,
+ REMEMBER_TOKEN,
+ REVIEW_CONTAINER,
+ TOKEN_BOX,
+} from './constants';
+
+// this style must be applied inline in a handful of components
+/* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+const buttonClearStyles = `
+ -webkit-appearance: none;
+`;
+
+// selector functions to abstract out a little
+const selectById = id => document.getElementById(id);
+const selectCollapseButton = () => document.getElementById(COLLAPSE_BUTTON);
+const selectCommentBox = () => document.getElementById(COMMENT_BOX);
+const selectCommentButton = () => document.getElementById(COMMENT_BUTTON);
+const selectContainer = () => document.getElementById(REVIEW_CONTAINER);
+const selectForm = () => document.getElementById(FORM);
+const selectNote = () => document.getElementById(NOTE);
+const selectRemember = () => document.getElementById(REMEMBER_TOKEN);
+const selectToken = () => document.getElementById(TOKEN_BOX);
+
+export {
+ buttonClearStyles,
+ selectById,
+ selectCollapseButton,
+ selectContainer,
+ selectCommentBox,
+ selectCommentButton,
+ selectForm,
+ selectNote,
+ selectRemember,
+ selectToken,
+};
diff --git a/app/assets/javascripts/visual_review_toolbar/components/wrapper.js b/app/assets/javascripts/visual_review_toolbar/components/wrapper.js
new file mode 100644
index 00000000000..233b7ec496c
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/wrapper.js
@@ -0,0 +1,82 @@
+import { comment } from './comment';
+import { CLEAR, FORM, WHITE } from './constants';
+import { login } from './login';
+import { selectCollapseButton, selectContainer, selectForm } from './utils';
+import { commentIcon, compressIcon } from './wrapper_icons';
+
+const form = content => `
+ <form id=${FORM}>
+ ${content}
+ </form>
+`;
+
+const addCommentForm = () => {
+ const formWrapper = selectForm();
+ formWrapper.innerHTML = comment;
+};
+
+const addLoginForm = () => {
+ const formWrapper = selectForm();
+ formWrapper.innerHTML = login;
+};
+
+function logoutUser() {
+ const { localStorage } = window;
+
+ // All the browsers we support have localStorage, so let's silently fail
+ // and go on with the rest of the functionality.
+ try {
+ localStorage.removeItem('token');
+ } catch (err) {
+ return;
+ }
+
+ addLoginForm();
+}
+
+function toggleForm() {
+ const container = selectContainer();
+ const collapseButton = selectCollapseButton();
+ const currentForm = selectForm();
+ const OPEN = 'open';
+ const CLOSED = 'closed';
+
+ /*
+ You may wonder why we spread the arrays before we reverse them.
+ In the immortal words of MDN,
+ Careful: reverse is destructive. It also changes the original array
+ */
+
+ const openButtonClasses = ['gitlab-collapse-closed', 'gitlab-collapse-open'];
+ const closedButtonClasses = [...openButtonClasses].reverse();
+ const openContainerClasses = ['gitlab-closed-wrapper', 'gitlab-open-wrapper'];
+ const closedContainerClasses = [...openContainerClasses].reverse();
+
+ const stateVals = {
+ [OPEN]: {
+ buttonClasses: openButtonClasses,
+ containerClasses: openContainerClasses,
+ icon: compressIcon,
+ display: 'flex',
+ backgroundColor: WHITE,
+ },
+ [CLOSED]: {
+ buttonClasses: closedButtonClasses,
+ containerClasses: closedContainerClasses,
+ icon: commentIcon,
+ display: 'none',
+ backgroundColor: CLEAR,
+ },
+ };
+
+ const nextState = collapseButton.classList.contains('gitlab-collapse-open') ? CLOSED : OPEN;
+ const currentVals = stateVals[nextState];
+
+ container.classList.replace(...currentVals.containerClasses);
+ container.style.backgroundColor = currentVals.backgroundColor;
+ currentForm.style.display = currentVals.display;
+ collapseButton.classList.replace(...currentVals.buttonClasses);
+ collapseButton.innerHTML = currentVals.icon;
+}
+
+export { addCommentForm, addLoginForm, form, logoutUser, toggleForm };
diff --git a/app/assets/javascripts/visual_review_toolbar/components/wrapper_icons.js b/app/assets/javascripts/visual_review_toolbar/components/wrapper_icons.js
new file mode 100644
index 00000000000..b686fd4f5c2
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/components/wrapper_icons.js
@@ -0,0 +1,15 @@
+import { buttonClearStyles } from './utils';
+
+const commentIcon = `
+ <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>icn/comment</title><path d="M4 11.132l1.446-.964A1 1 0 0 1 6 10h5a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v6.132zM6.303 12l-2.748 1.832A1 1 0 0 1 2 13V5a3 3 0 0 1 3-3h6a3 3 0 0 1 3 3v4a3 3 0 0 1-3 3H6.303z" id="gitlab-comment-icon"/></svg>
+`;
+
+const compressIcon = `
+ <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>icn/compress</title><path d="M5.27 12.182l-1.562 1.561a1 1 0 0 1-1.414 0h-.001a1 1 0 0 1 0-1.415l1.56-1.56L2.44 9.353a.5.5 0 0 1 .353-.854H7.09a.5.5 0 0 1 .5.5v4.294a.5.5 0 0 1-.853.353l-1.467-1.465zm6.911-6.914l1.464 1.464a.5.5 0 0 1-.353.854H8.999a.5.5 0 0 1-.5-.5V2.793a.5.5 0 0 1 .854-.354l1.414 1.415 1.56-1.561a1 1 0 1 1 1.415 1.414l-1.561 1.56z" id="gitlab-compress-icon"/></svg>
+`;
+
+const collapseButton = `
+ <button id='gitlab-collapse' style='${buttonClearStyles}' class='gitlab-button gitlab-button-secondary gitlab-collapse gitlab-collapse-open'>${compressIcon}</button>
+`;
+
+export { commentIcon, compressIcon, collapseButton };
diff --git a/app/assets/javascripts/visual_review_toolbar/index.js b/app/assets/javascripts/visual_review_toolbar/index.js
index 91d0382feac..941d77e25b4 100644
--- a/app/assets/javascripts/visual_review_toolbar/index.js
+++ b/app/assets/javascripts/visual_review_toolbar/index.js
@@ -1,2 +1,37 @@
import './styles/toolbar.css';
-import 'vendor/visual_review_toolbar';
+
+import { form, selectContainer, REVIEW_CONTAINER } from './components';
+import { debounce, eventLookup, getInitialView, initializeState, updateWindowSize } from './store';
+
+/*
+
+ Welcome to the visual review toolbar files. A few useful notes:
+
+ - These files build a static script that is served from our webpack
+ assets folder. (https://gitlab.com/assets/webpack/visual_review_toolbar.js)
+
+ - To compile this file, run `yarn webpack-vrt`.
+
+ - Vue is not used in these files because we do not want to ask users to
+ install another library at this time. It's all pure vanilla javascript.
+
+*/
+
+window.addEventListener('load', () => {
+ initializeState(window, document);
+
+ const { content, toggleButton } = getInitialView(window);
+ const container = document.createElement('div');
+
+ container.setAttribute('id', REVIEW_CONTAINER);
+ container.insertAdjacentHTML('beforeend', toggleButton);
+ container.insertAdjacentHTML('beforeend', form(content));
+
+ document.body.insertBefore(container, document.body.firstChild);
+
+ selectContainer().addEventListener('click', event => {
+ eventLookup(event)();
+ });
+
+ window.addEventListener('resize', debounce(updateWindowSize.bind(null, window), 200));
+});
diff --git a/app/assets/javascripts/visual_review_toolbar/store/events.js b/app/assets/javascripts/visual_review_toolbar/store/events.js
new file mode 100644
index 00000000000..93996be8473
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/store/events.js
@@ -0,0 +1,36 @@
+import {
+ authorizeUser,
+ logoutUser,
+ postComment,
+ toggleForm,
+ COLLAPSE_BUTTON,
+ COMMENT_BUTTON,
+ LOGIN,
+ LOGOUT,
+} from '../components';
+
+import { state } from './state';
+
+const noop = () => {};
+
+const eventLookup = ({ target: { id } }) => {
+ switch (id) {
+ case COLLAPSE_BUTTON:
+ return toggleForm;
+ case COMMENT_BUTTON:
+ return postComment.bind(null, state);
+ case LOGIN:
+ return authorizeUser.bind(null, state);
+ case LOGOUT:
+ return logoutUser;
+ default:
+ return noop;
+ }
+};
+
+const updateWindowSize = wind => {
+ state.innerWidth = wind.innerWidth;
+ state.innerHeight = wind.innerHeight;
+};
+
+export { eventLookup, updateWindowSize };
diff --git a/app/assets/javascripts/visual_review_toolbar/store/index.js b/app/assets/javascripts/visual_review_toolbar/store/index.js
new file mode 100644
index 00000000000..7143588c0bf
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/store/index.js
@@ -0,0 +1,5 @@
+import { eventLookup, updateWindowSize } from './events';
+import { getInitialView, initializeState } from './state';
+import debounce from './utils';
+
+export { debounce, eventLookup, getInitialView, initializeState, updateWindowSize };
diff --git a/app/assets/javascripts/visual_review_toolbar/store/state.js b/app/assets/javascripts/visual_review_toolbar/store/state.js
new file mode 100644
index 00000000000..f5ede6e85b2
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/store/state.js
@@ -0,0 +1,77 @@
+import { comment, login, collapseButton } from '../components';
+
+const state = {
+ browser: '',
+ href: '',
+ innerWidth: '',
+ innerHeight: '',
+ mergeRequestId: '',
+ mrUrl: '',
+ platform: '',
+ projectId: '',
+ userAgent: '',
+ token: '',
+};
+
+// adapted from https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator#Example_2_Browser_detect_and_return_an_index
+const getBrowserId = sUsrAg => {
+ /* eslint-disable-next-line @gitlab/i18n/no-non-i18n-strings */
+ const aKeys = ['MSIE', 'Edge', 'Firefox', 'Safari', 'Chrome', 'Opera'];
+ let nIdx = aKeys.length - 1;
+
+ for (nIdx; nIdx > -1 && sUsrAg.indexOf(aKeys[nIdx]) === -1; nIdx -= 1);
+ return aKeys[nIdx];
+};
+
+const initializeState = (wind, doc) => {
+ const {
+ innerWidth,
+ innerHeight,
+ location: { href },
+ navigator: { platform, userAgent },
+ } = wind;
+
+ const browser = getBrowserId(userAgent);
+
+ const scriptEl = doc.getElementById('review-app-toolbar-script');
+ const { projectId, mergeRequestId, mrUrl } = scriptEl.dataset;
+
+ // This mutates our default state object above. It's weird but it makes the linter happy.
+ Object.assign(state, {
+ browser,
+ href,
+ innerWidth,
+ innerHeight,
+ mergeRequestId,
+ mrUrl,
+ platform,
+ projectId,
+ userAgent,
+ });
+};
+
+function getInitialView({ localStorage }) {
+ const loginView = {
+ content: login,
+ toggleButton: collapseButton,
+ };
+
+ const commentView = {
+ content: comment,
+ toggleButton: collapseButton,
+ };
+
+ try {
+ const token = localStorage.getItem('token');
+
+ if (token) {
+ state.token = token;
+ return commentView;
+ }
+ return loginView;
+ } catch (err) {
+ return loginView;
+ }
+}
+
+export { initializeState, getInitialView, state };
diff --git a/app/assets/javascripts/visual_review_toolbar/store/utils.js b/app/assets/javascripts/visual_review_toolbar/store/utils.js
new file mode 100644
index 00000000000..5cf145351b3
--- /dev/null
+++ b/app/assets/javascripts/visual_review_toolbar/store/utils.js
@@ -0,0 +1,15 @@
+const debounce = (fn, time) => {
+ let current;
+
+ const debounced = () => {
+ if (current) {
+ clearTimeout(current);
+ }
+
+ current = setTimeout(fn, time);
+ };
+
+ return debounced;
+};
+
+export default debounce;
diff --git a/app/assets/stylesheets/framework/variables.scss b/app/assets/stylesheets/framework/variables.scss
index 07fc655307e..b6a24247d40 100644
--- a/app/assets/stylesheets/framework/variables.scss
+++ b/app/assets/stylesheets/framework/variables.scss
@@ -823,7 +823,7 @@ $issues-analytics-popover-boarder-color: rgba(0, 0, 0, 0.15);
/*
Merge Requests
*/
-$mr-tabs-height: 51px;
+$mr-tabs-height: 48px;
$mr-version-controls-height: 56px;
/*
diff --git a/app/helpers/dropdowns_helper.rb b/app/helpers/dropdowns_helper.rb
index 8d8c62f1291..64c5fae7d96 100644
--- a/app/helpers/dropdowns_helper.rb
+++ b/app/helpers/dropdowns_helper.rb
@@ -91,7 +91,7 @@ module DropdownsHelper
def dropdown_filter(placeholder, search_id: nil)
content_tag :div, class: "dropdown-input" do
- filter_output = search_field_tag search_id, nil, class: "dropdown-input-field", placeholder: placeholder, autocomplete: 'off'
+ filter_output = search_field_tag search_id, nil, class: "dropdown-input-field qa-dropdown-input-field", placeholder: placeholder, autocomplete: 'off'
filter_output << icon('search', class: "dropdown-input-search")
filter_output << icon('times', class: "dropdown-input-clear js-dropdown-input-clear", role: "button")
diff --git a/app/helpers/environments_helper.rb b/app/helpers/environments_helper.rb
index 855b243cc8a..0f118c235d8 100644
--- a/app/helpers/environments_helper.rb
+++ b/app/helpers/environments_helper.rb
@@ -27,7 +27,7 @@ module EnvironmentsHelper
"empty-unable-to-connect-svg-path" => image_path('illustrations/monitoring/unable_to_connect.svg'),
"metrics-endpoint" => additional_metrics_project_environment_path(project, environment, format: :json),
"dashboard-endpoint" => metrics_dashboard_project_environment_path(project, environment, format: :json),
- "deployment-endpoint" => project_environment_deployments_path(project, environment, format: :json),
+ "deployments-endpoint" => project_environment_deployments_path(project, environment, format: :json),
"environments-endpoint": project_environments_path(project, format: :json),
"project-path" => project_path(project),
"tags-path" => project_tags_path(project),
diff --git a/app/helpers/markup_helper.rb b/app/helpers/markup_helper.rb
index dce4168ad7b..bf894360a2e 100644
--- a/app/helpers/markup_helper.rb
+++ b/app/helpers/markup_helper.rb
@@ -263,6 +263,11 @@ module MarkupHelper
end
def asciidoc_unsafe(text, context = {})
+ context.merge!(
+ commit: @commit,
+ ref: @ref,
+ requested_path: @path
+ )
Gitlab::Asciidoc.render(text, context)
end
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index 4594f5a31b9..dfa34ad7020 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -172,11 +172,17 @@ module SearchHelper
if @project.present?
opts[:data]['project-id'] = @project.id
opts[:data]['base-endpoint'] = project_path(@project)
+ opts[:data]['labels-endpoint'] = project_labels_path(@project)
+ opts[:data]['milestones-endpoint'] = project_milestones_path(@project)
elsif @group.present?
opts[:data]['group-id'] = @group.id
opts[:data]['base-endpoint'] = group_canonical_path(@group)
+ opts[:data]['labels-endpoint'] = group_labels_path(@group)
+ opts[:data]['milestones-endpoint'] = group_milestones_path(@group)
else
opts[:data]['base-endpoint'] = root_dashboard_path
+ opts[:data]['labels-endpoint'] = dashboard_labels_path
+ opts[:data]['milestones-endpoint'] = dashboard_milestones_path
end
opts
diff --git a/app/mailers/repository_check_mailer.rb b/app/mailers/repository_check_mailer.rb
index a24d3476d0e..aa56ba1828b 100644
--- a/app/mailers/repository_check_mailer.rb
+++ b/app/mailers/repository_check_mailer.rb
@@ -15,7 +15,7 @@ class RepositoryCheckMailer < BaseMailer
end
mail(
- to: User.admins.pluck(:email),
+ to: User.admins.active.pluck(:email),
subject: "GitLab Admin | #{@message}"
)
end
diff --git a/app/models/commit.rb b/app/models/commit.rb
index fa0bf36ba49..be37fa2e76f 100644
--- a/app/models/commit.rb
+++ b/app/models/commit.rb
@@ -94,7 +94,7 @@ class Commit
end
def lazy(project, oid)
- BatchLoader.for({ project: project, oid: oid }).batch do |items, loader|
+ BatchLoader.for({ project: project, oid: oid }).batch(replace_methods: false) do |items, loader|
items_by_project = items.group_by { |i| i[:project] }
items_by_project.each do |project, commit_ids|
diff --git a/app/models/group.rb b/app/models/group.rb
index cdb4e6e87f6..dbec211935d 100644
--- a/app/models/group.rb
+++ b/app/models/group.rb
@@ -423,7 +423,7 @@ class Group < Namespace
def update_two_factor_requirement
return unless saved_change_to_require_two_factor_authentication? || saved_change_to_two_factor_grace_period?
- users.find_each(&:update_two_factor_requirement)
+ members_with_descendants.find_each(&:update_two_factor_requirement)
end
def path_changed_hook
diff --git a/app/views/layouts/nav/sidebar/_project.html.haml b/app/views/layouts/nav/sidebar/_project.html.haml
index 9b6551552c7..49ff976f8e8 100644
--- a/app/views/layouts/nav/sidebar/_project.html.haml
+++ b/app/views/layouts/nav/sidebar/_project.html.haml
@@ -9,7 +9,7 @@
= @project.name
%ul.sidebar-top-level-items
= nav_link(path: sidebar_projects_paths, html_options: { class: 'home' }) do
- = link_to project_path(@project), class: 'shortcuts-project' do
+ = link_to project_path(@project), class: 'shortcuts-project qa-link-project' do
.nav-icon-container
= sprite_icon('home')
%span.nav-item-name
diff --git a/app/views/shared/_sidebar_toggle_button.html.haml b/app/views/shared/_sidebar_toggle_button.html.haml
index d90a6d43761..d499bc0a253 100644
--- a/app/views/shared/_sidebar_toggle_button.html.haml
+++ b/app/views/shared/_sidebar_toggle_button.html.haml
@@ -1,4 +1,4 @@
-%a.toggle-sidebar-button.js-toggle-sidebar{ role: "button", type: "button", title: "Toggle sidebar" }
+%a.toggle-sidebar-button.js-toggle-sidebar.qa-toggle-sidebar{ role: "button", type: "button", title: "Toggle sidebar" }
= sprite_icon('angle-double-left', css_class: 'icon-angle-double-left')
= sprite_icon('angle-double-right', css_class: 'icon-angle-double-right')
%span.collapse-text= _("Collapse sidebar")
diff --git a/app/views/shared/issuable/_sidebar.html.haml b/app/views/shared/issuable/_sidebar.html.haml
index 3a5adb34ad1..e87e560266f 100644
--- a/app/views/shared/issuable/_sidebar.html.haml
+++ b/app/views/shared/issuable/_sidebar.html.haml
@@ -102,7 +102,7 @@
= _('Labels')
= icon('spinner spin', class: 'hidden block-loading', 'aria-hidden': 'true')
- if can_edit_issuable
- = link_to _('Edit'), '#', class: 'js-sidebar-dropdown-toggle edit-link float-right'
+ = link_to _('Edit'), '#', class: 'js-sidebar-dropdown-toggle edit-link qa-edit-link-labels float-right'
.value.issuable-show-labels.dont-hide.hide-collapsed.qa-labels-block{ class: ("has-labels" if selected_labels.any?) }
- if selected_labels.any?
- selected_labels.each do |label_hash|
@@ -118,7 +118,7 @@
%span.dropdown-toggle-text{ class: ("is-default" if selected_labels.empty?) }
= multi_label_name(selected_labels, "Labels")
= icon('chevron-down', 'aria-hidden': 'true')
- .dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable.dropdown-extended-height
+ .dropdown-menu.dropdown-select.dropdown-menu-paging.qa-dropdown-menu-labels.dropdown-menu-labels.dropdown-menu-selectable.dropdown-extended-height
= render partial: "shared/issuable/label_page_default"
- if issuable_sidebar.dig(:current_user, :can_admin_label)
= render partial: "shared/issuable/label_page_create"
diff --git a/changelogs/unreleased/62684-add-index-public-email-on-users.yml b/changelogs/unreleased/62684-add-index-public-email-on-users.yml
new file mode 100644
index 00000000000..56b5f91da21
--- /dev/null
+++ b/changelogs/unreleased/62684-add-index-public-email-on-users.yml
@@ -0,0 +1,5 @@
+---
+title: Add index on public_email for users
+merge_request: 29430
+author:
+type: performance
diff --git a/changelogs/unreleased/asciidoc-include-directive.yml b/changelogs/unreleased/asciidoc-include-directive.yml
new file mode 100644
index 00000000000..58fe3666727
--- /dev/null
+++ b/changelogs/unreleased/asciidoc-include-directive.yml
@@ -0,0 +1,5 @@
+---
+title: Add support for AsciiDoc include directive
+merge_request: 28417
+author: "Jakub Jirutka & Guillaume Grossetie"
+type: added
diff --git a/changelogs/unreleased/dhiraj-fix-missing-deployment-rockets-in-monitoring-dashboard.yml b/changelogs/unreleased/dhiraj-fix-missing-deployment-rockets-in-monitoring-dashboard.yml
new file mode 100644
index 00000000000..12a21e818b4
--- /dev/null
+++ b/changelogs/unreleased/dhiraj-fix-missing-deployment-rockets-in-monitoring-dashboard.yml
@@ -0,0 +1,5 @@
+---
+title: Fix missing deployment rockets in monitor dashboard
+merge_request: 29574
+author:
+type: fixed
diff --git a/changelogs/unreleased/ensure_namespace.yml b/changelogs/unreleased/ensure_namespace.yml
new file mode 100644
index 00000000000..ce2a615af1f
--- /dev/null
+++ b/changelogs/unreleased/ensure_namespace.yml
@@ -0,0 +1,5 @@
+---
+title: AutoDevops function ensure_namespace() now explicitly tests the namespace
+merge_request: 29567
+author: Jack Lei
+type: fixed
diff --git a/changelogs/unreleased/feature-require-2fa-for-all-entities-in-group.yml b/changelogs/unreleased/feature-require-2fa-for-all-entities-in-group.yml
new file mode 100644
index 00000000000..0abe777fb69
--- /dev/null
+++ b/changelogs/unreleased/feature-require-2fa-for-all-entities-in-group.yml
@@ -0,0 +1,4 @@
+title: Apply the group setting "require 2FA" across all subgroup members as well when changing the group setting
+merge_request: 24965
+author: rroger
+type: changed
diff --git a/changelogs/unreleased/fix-flyout-navs.yml b/changelogs/unreleased/fix-flyout-navs.yml
new file mode 100644
index 00000000000..c21f1037f09
--- /dev/null
+++ b/changelogs/unreleased/fix-flyout-navs.yml
@@ -0,0 +1,5 @@
+---
+title: Fix sidebar flyout navigation
+merge_request: 29571
+author:
+type: fixed
diff --git a/changelogs/unreleased/sh-omit-blocked-admins-from-notification.yml b/changelogs/unreleased/sh-omit-blocked-admins-from-notification.yml
new file mode 100644
index 00000000000..82c5505892f
--- /dev/null
+++ b/changelogs/unreleased/sh-omit-blocked-admins-from-notification.yml
@@ -0,0 +1,5 @@
+---
+title: Omit blocked admins from repository check e-mails
+merge_request: 29507
+author:
+type: fixed
diff --git a/changelogs/unreleased/sh-speed-up-commit-loading.yml b/changelogs/unreleased/sh-speed-up-commit-loading.yml
new file mode 100644
index 00000000000..db408708385
--- /dev/null
+++ b/changelogs/unreleased/sh-speed-up-commit-loading.yml
@@ -0,0 +1,5 @@
+---
+title: Speed up commit loads by disabling BatchLoader replace_methods
+merge_request: 29633
+author:
+type: performance
diff --git a/config/initializers/7_prometheus_metrics.rb b/config/initializers/7_prometheus_metrics.rb
index 4da683014d4..68f8487d377 100644
--- a/config/initializers/7_prometheus_metrics.rb
+++ b/config/initializers/7_prometheus_metrics.rb
@@ -19,6 +19,12 @@ Gitlab::Application.configure do |config|
config.middleware.insert(1, Gitlab::Metrics::RequestsRackMiddleware)
end
+Sidekiq.configure_server do |config|
+ config.on(:startup) do
+ Gitlab::Metrics::SidekiqMetricsExporter.instance.start
+ end
+end
+
if !Rails.env.test? && Gitlab::Metrics.prometheus_metrics_enabled?
Gitlab::Cluster::LifecycleEvents.on_worker_start do
defined?(::Prometheus::Client.reinitialize_on_pid_change) && Prometheus::Client.reinitialize_on_pid_change
diff --git a/db/migrate/20190607190856_add_index_to_users_public_emails.rb b/db/migrate/20190607190856_add_index_to_users_public_emails.rb
new file mode 100644
index 00000000000..81ec38b8b32
--- /dev/null
+++ b/db/migrate/20190607190856_add_index_to_users_public_emails.rb
@@ -0,0 +1,23 @@
+# frozen_string_literal: true
+
+# See http://doc.gitlab.com/ce/development/migration_style_guide.html
+# for more information on how to write migrations for GitLab.
+
+class AddIndexToUsersPublicEmails < ActiveRecord::Migration[5.1]
+ include Gitlab::Database::MigrationHelpers
+
+ # Set this constant to true if this migration requires downtime.
+ DOWNTIME = false
+
+ disable_ddl_transaction!
+
+ def up
+ add_concurrent_index :users, [:public_email],
+ where: "public_email != ''"
+ end
+
+ def down
+ remove_concurrent_index :users, [:public_email],
+ where: "public_email != ''"
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 392edf89430..86a099d28b2 100644
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -2388,6 +2388,7 @@ ActiveRecord::Schema.define(version: 20190611161641) do
t.index ["incoming_email_token"], name: "index_users_on_incoming_email_token", using: :btree
t.index ["name"], name: "index_users_on_name", using: :btree
t.index ["name"], name: "index_users_on_name_trigram", using: :gin, opclasses: {"name"=>"gin_trgm_ops"}
+ t.index ["public_email"], name: "index_users_on_public_email", where: "((public_email)::text <> ''::text)", using: :btree
t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true, using: :btree
t.index ["state"], name: "index_users_on_state", using: :btree
t.index ["username"], name: "index_users_on_username", using: :btree
diff --git a/doc/development/contributing/issue_workflow.md b/doc/development/contributing/issue_workflow.md
index e3a1dc711fd..0396f7ebc45 100644
--- a/doc/development/contributing/issue_workflow.md
+++ b/doc/development/contributing/issue_workflow.md
@@ -163,9 +163,9 @@ or ~"Stretch". Any open issue for a previous milestone should be labeled
Priority labels help us define the time a ~bug fix should be completed. Priority determines how quickly the defect turnaround time must be.
If there are multiple defects, the priority decides which defect has to be fixed immediately versus later.
-This label documents the planned timeline & urgency which is used to measure against our actual SLA on delivering ~bug fixes.
+This label documents the planned timeline & urgency which is used to measure against our target SLO on delivering ~bug fixes.
-| Label | Meaning | Defect SLA (applies only to ~bug and ~security defects) |
+| Label | Meaning | Target SLO (applies only to ~bug and ~security defects) |
|-------|-----------------|----------------------------------------------------------------------------|
| ~P1 | Urgent Priority | The current release + potentially immediate hotfix to GitLab.com (30 days) |
| ~P2 | High Priority | The next release (60 days) |
diff --git a/doc/development/testing_guide/end_to_end/quick_start_guide.md b/doc/development/testing_guide/end_to_end/quick_start_guide.md
index 521e3e56e7a..1802f4792e0 100644
--- a/doc/development/testing_guide/end_to_end/quick_start_guide.md
+++ b/doc/development/testing_guide/end_to_end/quick_start_guide.md
@@ -357,13 +357,13 @@ In the following we describe the changes needed in each of the resource files me
Now, let's make it possible to create an issue resource through the API.
-First, in the [issue resource](https://gitlab.com/gitlab-org/gitlab-ee/blob/d3584e80b4236acdf393d815d604801573af72cc/qa/qa/resource/issue.rb), let's expose its labels attribute.
+First, in the [issue resource](https://gitlab.com/gitlab-org/gitlab-ee/blob/d3584e80b4236acdf393d815d604801573af72cc/qa/qa/resource/issue.rb), let's expose its id and labels attributes.
-Add the following `attribute :labels` right above the [`attribute :title`](https://gitlab.com/gitlab-org/gitlab-ee/blob/d3584e80b4236acdf393d815d604801573af72cc/qa/qa/resource/issue.rb#L15).
+Add the following `attribute :id` and `attribute :labels` right above the [`attribute :title`](https://gitlab.com/gitlab-org/gitlab-ee/blob/d3584e80b4236acdf393d815d604801573af72cc/qa/qa/resource/issue.rb#L15).
-> This line is needed to allow for labels to be automatically added to an issue when fabricating it via API.
+> This line is needed to allow for the issue fabrication, and for labels to be automatically added to the issue when fabricating it via API.
-> We add the new line above the existing attribute to keep them alphabetically organized.
+> We add the attributes above the existing attribute to keep them alphabetically organized.
Next, add the following code right below the [`fabricate!`](https://gitlab.com/gitlab-org/gitlab-ee/blob/d3584e80b4236acdf393d815d604801573af72cc/qa/qa/resource/issue.rb#L27) method.
diff --git a/doc/security/two_factor_authentication.md b/doc/security/two_factor_authentication.md
index ad5daef805a..49dadd5abc2 100644
--- a/doc/security/two_factor_authentication.md
+++ b/doc/security/two_factor_authentication.md
@@ -39,8 +39,26 @@ If you want to enforce 2FA only for certain groups, you can:
To change this setting, you need to be administrator or owner of the group.
-If there are multiple 2FA requirements (i.e. group + all users, or multiple
-groups) the shortest grace period will be used.
+> [From](https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/24965) GitLab 12.0, 2FA settings for a group are also applied to subgroups.
+
+If you want to enforce 2FA only for certain groups, you can enable it in the
+group settings and specify a grace period as above. To change this setting you
+need to be administrator or owner of the group.
+
+The following are important notes about 2FA:
+
+- Projects belonging to a 2FA-enabled group that
+ [is shared](../user/project/members/share_project_with_groups.md)
+ with a 2FA-disabled group will *not* require members of the 2FA-disabled group to use
+ 2FA for the project. For example, if project *P* belongs to 2FA-enabled group *A* and
+ is shared with 2FA-disabled group *B*, members of group *B* can access project *P*
+ without 2FA. To ensure this scenario doesn't occur,
+ [prevent sharing of projects](../user/group/index.md#share-with-group-lock)
+ for the 2FA-enabled group.
+- If you add additional members to a project within a group or subgroup that has
+ 2FA enabled, 2FA is **not** required for those individually added members.
+- If there are multiple 2FA requirements (for example, group + all users, or multiple
+ groups) the shortest grace period will be used.
## Disabling 2FA for everyone
diff --git a/doc/ssh/README.md b/doc/ssh/README.md
index 09b5fbd9260..dbd9bcee935 100644
--- a/doc/ssh/README.md
+++ b/doc/ssh/README.md
@@ -64,9 +64,14 @@ Following [best practices](https://linux-audit.com/using-ed25519-openssh-keys-in
you should always favor [ED25519](https://ed25519.cr.yp.to/) SSH keys, since they
are more secure and have better performance over the other types.
-They were introduced in OpenSSH 6.5, so any modern OS should include the
-option to create them. If for any reason your OS or the GitLab instance you
-interact with doesn't support this, you can fallback to RSA.
+ED25519 SSH keys were introduced in OpenSSH 6.5,
+so any modern OS should include the option to create them.
+If for any reason your OS or the GitLab instance you interact with doesn't
+support ED25519, you can fallback to RSA.
+
+NOTE: **Note:**
+Omnibus does not ship with OpenSSH, so it uses the version on your GitLab server. If using
+Omnibus, ensure the version of OpenSSH installed is version 6.5 or newer if you want to use ED25519 SSH keys.
### RSA SSH keys
diff --git a/doc/user/asciidoc.md b/doc/user/asciidoc.md
new file mode 100644
index 00000000000..a22b285b114
--- /dev/null
+++ b/doc/user/asciidoc.md
@@ -0,0 +1,372 @@
+# AsciiDoc
+
+GitLab uses the [Asciidoctor](https://asciidoctor.org) gem to convert AsciiDoc content to HTML5.
+Consult the [Asciidoctor User Manual](https://asciidoctor.org/docs/user-manual) for a complete Asciidoctor reference.
+
+## Syntax
+
+Here's a brief reference of the most commonly used AsciiDoc syntax.
+You can find the full documentation for the AsciiDoc syntax at https://asciidoctor.org/docs.
+
+### Paragraphs
+
+```asciidoc
+A normal paragraph.
+Line breaks are not preserved.
+```
+
+Line comments, which are lines that start with `//`, are skipped:
+
+```
+// this is a comment
+```
+
+A blank line separates paragraphs.
+
+A paragraph with the `[%hardbreaks]` option will preserve line breaks:
+
+```asciidoc
+[%hardbreaks]
+This paragraph carries the `hardbreaks` option.
+Notice how line breaks are now preserved.
+```
+
+An indented (literal) paragraph disables text formatting,
+preserves spaces and line breaks, and is displayed in a
+monospaced font:
+
+```asciidoc
+ This literal paragraph is indented with one space.
+ As a consequence, *text formatting*, spaces,
+ and lines breaks will be preserved.
+```
+
+An admonition paragraph grabs the reader's attention:
+
+```asciidoc
+NOTE: This is a brief reference, please read the full documentation at https://asciidoctor.org/docs.
+
+TIP: Lists can be indented. Leading whitespace is not significant.
+```
+
+### Text Formatting
+
+**Constrained (applied at word boundaries)**
+
+```asciidoc
+*strong importance* (aka bold)
+_stress emphasis_ (aka italic)
+`monospaced` (aka typewriter text)
+"`double`" and '`single`' typographic quotes
++passthrough text+ (substitutions disabled)
+`+literal text+` (monospaced with substitutions disabled)
+```
+
+**Unconstrained (applied anywhere)**
+
+```asciidoc
+**C**reate+**R**ead+**U**pdate+**D**elete
+fan__freakin__tastic
+``mono``culture
+```
+
+**Replacements**
+
+```asciidoc
+A long time ago in a galaxy far, far away...
+(C) 1976 Arty Artisan
+I believe I shall--no, actually I won't.
+```
+
+**Macros**
+
+```asciidoc
+// where c=specialchars, q=quotes, a=attributes, r=replacements, m=macros, p=post_replacements, etc.
+The European icon:flag[role=blue] is blue & contains pass:[************] arranged in a icon:circle-o[role=yellow].
+The pass:c[->] operator is often referred to as the stabby lambda.
+Since `pass:[++]` has strong priority in AsciiDoc, you can rewrite pass:c,a,r[C++ => C{pp}].
+// activate stem support by adding `:stem:` to the document header
+stem:[sqrt(4) = 2]
+```
+
+### Attributes
+
+```asciidoc
+// define attributes in the document header
+:name: value
+```
+
+```asciidoc
+:url-gem: https://rubygems.org/gems/asciidoctor
+
+You can download and install Asciidoctor {asciidoctor-version} from {url-gem}.
+C{pp} is not required, only Ruby.
+Use a leading backslash to output a word enclosed in curly braces, like \{name}.
+```
+
+### Links
+
+```asciidoc
+https://example.org/page[A webpage]
+link:../path/to/file.txt[A local file]
+xref:document.adoc[A sibling document]
+mailto:hello@example.org[Email to say hello!]
+```
+
+### Anchors
+
+```asciidoc
+[[idname,reference text]]
+// or written using normal block attributes as `[#idname,reftext=reference text]`
+A paragraph (or any block) with an anchor (aka ID) and reftext.
+
+See <<idname>> or <<idname,optional text of internal link>>.
+
+xref:document.adoc#idname[Jumps to anchor in another document].
+
+This paragraph has a footnote.footnote:[This is the text of the footnote.]
+```
+
+### Lists
+
+#### Unordered
+
+```asciidoc
+* level 1
+** level 2
+*** level 3
+**** level 4
+***** etc.
+* back at level 1
++
+Attach a block or paragraph to a list item using a list continuation (which you can enclose in an open block).
+
+.Some Authors
+[circle]
+- Edgar Allen Poe
+- Sheri S. Tepper
+- Bill Bryson
+```
+
+#### Ordered
+
+```asciidoc
+. Step 1
+. Step 2
+.. Step 2a
+.. Step 2b
+. Step 3
+
+.Remember your Roman numerals?
+[upperroman]
+. is one
+. is two
+. is three
+```
+
+#### Checklist
+
+```asciidoc
+* [x] checked
+* [ ] not checked
+```
+#### Callout
+
+```asciidoc
+// enable callout bubbles by adding `:icons: font` to the document header
+[,ruby]
+----
+puts 'Hello, World!' # <1>
+----
+<1> Prints `Hello, World!` to the console.
+```
+
+#### Description
+
+```asciidoc
+first term:: description of first term
+second term::
+description of second term
+```
+### Document Structure
+
+#### Header
+
+```asciidoc
+= Document Title
+Author Name <author@example.org>
+v1.0, 2019-01-01
+```
+#### Sections
+
+```asciidoc
+= Document Title (Level 0)
+== Level 1
+=== Level 2
+==== Level 3
+===== Level 4
+====== Level 5
+== Back at Level 1
+```
+
+#### Includes
+
+```asciidoc
+include::basics.adoc[]
+
+// define -a allow-uri-read to allow content to be read from URI
+include::https://example.org/installation.adoc[]
+```
+### Blocks
+
+```asciidoc
+--
+open - a general-purpose content wrapper; useful for enclosing content to attach to a list item
+--
+```
+
+```asciidoc
+// recognized types include CAUTION, IMPORTANT, NOTE, TIP, and WARNING
+// enable admonition icons by setting `:icons: font` in the document header
+[NOTE]
+====
+admonition - a notice for the reader, ranging in severity from a tip to an alert
+====
+```
+
+```asciidoc
+====
+example - a demonstration of the concept being documented
+====
+```
+
+```asciidoc
+.Toggle Me
+[%collapsible]
+====
+collapsible - these details are revealed by clicking the title
+====
+```
+
+```asciidoc
+****
+sidebar - auxiliary content that can be read independently of the main content
+****
+```
+
+```asciidoc
+....
+literal - an exhibit that features program output
+....
+```
+
+```asciidoc
+----
+listing - an exhibit that features program input, source code, or the contents of a file
+----
+```
+
+```asciidoc
+[,language]
+----
+source - a listing that is embellished with (colorized) syntax highlighting
+----
+```
+
+```asciidoc
+\```language
+fenced code - a shorthand syntax for the source block
+\```
+```
+
+```asciidoc
+[,attribution,citetitle]
+____
+quote - a quotation or excerpt; attribution with title of source are optional
+____
+```
+
+```asciidoc
+[verse,attribution,citetitle]
+____
+verse - a literary excerpt, often a poem; attribution with title of source are optional
+____
+```
+
+```asciidoc
+++++
+pass - content passed directly to the output document; often raw HTML
+++++
+```
+
+```asciidoc
+// activate stem support by adding `:stem:` to the document header
+[stem]
+++++
+x = y^2
+++++
+```
+
+```asciidoc
+////
+comment - content which is not included in the output document
+////
+```
+
+### Tables
+
+```asciidoc
+.Table Attributes
+[cols=>1h;2d,width=50%,frame=topbot]
+|===
+| Attribute Name | Values
+
+| options
+| header,footer,autowidth
+
+| cols
+| colspec[;colspec;...]
+
+| grid
+| all \| cols \| rows \| none
+
+| frame
+| all \| sides \| topbot \| none
+
+| stripes
+| all \| even \| odd \| none
+
+| width
+| (0%..100%)
+
+| format
+| psv {vbar} csv {vbar} dsv
+|===
+```
+
+### Multimedia
+
+```asciidoc
+image::screenshot.png[block image,800,450]
+
+Press image:reload.svg[reload,16,opts=interactive] to reload the page.
+
+video::movie.mp4[width=640,start=60,end=140,options=autoplay]
+
+video::aHjpOzsQ9YI[youtube]
+
+video::300817511[vimeo]
+```
+
+### Breaks
+
+```asciidoc
+// thematic break (aka horizontal rule)
+---
+```
+
+```asciidoc
+// page break
+<<<
+```
+
diff --git a/doc/user/project/deploy_boards.md b/doc/user/project/deploy_boards.md
index 2f2a9c5eec3..0994c51abb2 100644
--- a/doc/user/project/deploy_boards.md
+++ b/doc/user/project/deploy_boards.md
@@ -96,12 +96,6 @@ navigate to the environments page under **Operations > Environments**.
Deploy Boards are visible by default. You can explicitly click
the triangle next to their respective environment name in order to hide them.
-GitLab will then query Kubernetes for the state of each pod (e.g., waiting,
-deploying, finished, unknown), and the Deploy Board status will finally appear.
-
-GitLab will only display a Deploy Board for top-level environments. Foldered
-environments like `review/*` (usually used for [Review Apps]) won't have a
-Deploy Board attached to them.
## Canary Deployments
diff --git a/doc/user/project/repository/index.md b/doc/user/project/repository/index.md
index 6fccfd40987..165f4c15165 100644
--- a/doc/user/project/repository/index.md
+++ b/doc/user/project/repository/index.md
@@ -68,7 +68,7 @@ according to the markup language.
| Plain text | `txt` |
| [Markdown](../../markdown.md) | `mdown`, `mkd`, `mkdn`, `md`, `markdown` |
| [reStructuredText](http://docutils.sourceforge.net/rst.html) | `rst` |
-| [Asciidoc](https://asciidoctor.org/docs/what-is-asciidoc/) | `adoc`, `ad`, `asciidoc` |
+| [AsciiDoc](../../asciidoc.md) | `adoc`, `ad`, `asciidoc` |
| [Textile](https://txstyle.org/) | `textile` |
| [rdoc](http://rdoc.sourceforge.net/doc/index.html) | `rdoc` |
| [Orgmode](https://orgmode.org/) | `org` |
diff --git a/lib/gitlab/asciidoc.rb b/lib/gitlab/asciidoc.rb
index df8f0470063..7f8300a0c2f 100644
--- a/lib/gitlab/asciidoc.rb
+++ b/lib/gitlab/asciidoc.rb
@@ -1,27 +1,41 @@
# frozen_string_literal: true
require 'asciidoctor'
-require 'asciidoctor/converter/html5'
-require "asciidoctor-plantuml"
+require 'asciidoctor-plantuml'
+require 'asciidoctor/extensions'
+require 'gitlab/asciidoc/html5_converter'
module Gitlab
# Parser/renderer for the AsciiDoc format that uses Asciidoctor and filters
# the resulting HTML through HTML pipeline filters.
module Asciidoc
- DEFAULT_ADOC_ATTRS = [
- 'showtitle', 'idprefix=user-content-', 'idseparator=-', 'env=gitlab',
- 'env-gitlab', 'source-highlighter=html-pipeline', 'icons=font',
- 'outfilesuffix=.adoc'
- ].freeze
+ MAX_INCLUDE_DEPTH = 5
+ DEFAULT_ADOC_ATTRS = {
+ 'showtitle' => true,
+ 'idprefix' => 'user-content-',
+ 'idseparator' => '-',
+ 'env' => 'gitlab',
+ 'env-gitlab' => '',
+ 'source-highlighter' => 'html-pipeline',
+ 'icons' => 'font',
+ 'outfilesuffix' => '.adoc',
+ 'max-include-depth' => MAX_INCLUDE_DEPTH
+ }.freeze
# Public: Converts the provided Asciidoc markup into HTML.
#
# input - the source text in Asciidoc format
+ # context - :commit, :project, :ref, :requested_path
#
def self.render(input, context)
+ extensions = proc do
+ include_processor ::Gitlab::Asciidoc::IncludeProcessor.new(context)
+ end
+
asciidoc_opts = { safe: :secure,
backend: :gitlab_html5,
- attributes: DEFAULT_ADOC_ATTRS }
+ attributes: DEFAULT_ADOC_ATTRS,
+ extensions: extensions }
context[:pipeline] = :ascii_doc
@@ -40,29 +54,5 @@ module Gitlab
conf.txt_enable = false
end
end
-
- class Html5Converter < Asciidoctor::Converter::Html5Converter
- extend Asciidoctor::Converter::Config
-
- register_for 'gitlab_html5'
-
- def stem(node)
- return super unless node.style.to_sym == :latexmath
-
- %(<pre#{id_attribute(node)} data-math-style="display"><code>#{node.content}</code></pre>)
- end
-
- def inline_quoted(node)
- return super unless node.type.to_sym == :latexmath
-
- %(<code#{id_attribute(node)} data-math-style="inline">#{node.text}</code>)
- end
-
- private
-
- def id_attribute(node)
- node.id ? %( id="#{node.id}") : nil
- end
- end
end
end
diff --git a/lib/gitlab/asciidoc/html5_converter.rb b/lib/gitlab/asciidoc/html5_converter.rb
new file mode 100644
index 00000000000..2c5c74e4789
--- /dev/null
+++ b/lib/gitlab/asciidoc/html5_converter.rb
@@ -0,0 +1,32 @@
+# frozen_string_literal: true
+
+require 'asciidoctor'
+require 'asciidoctor/converter/html5'
+
+module Gitlab
+ module Asciidoc
+ class Html5Converter < Asciidoctor::Converter::Html5Converter
+ extend Asciidoctor::Converter::Config
+
+ register_for 'gitlab_html5'
+
+ def stem(node)
+ return super unless node.style.to_sym == :latexmath
+
+ %(<pre#{id_attribute(node)} data-math-style="display"><code>#{node.content}</code></pre>)
+ end
+
+ def inline_quoted(node)
+ return super unless node.type.to_sym == :latexmath
+
+ %(<code#{id_attribute(node)} data-math-style="inline">#{node.text}</code>)
+ end
+
+ private
+
+ def id_attribute(node)
+ node.id ? %( id="#{node.id}") : nil
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/asciidoc/include_processor.rb b/lib/gitlab/asciidoc/include_processor.rb
new file mode 100644
index 00000000000..c6fbf540e9c
--- /dev/null
+++ b/lib/gitlab/asciidoc/include_processor.rb
@@ -0,0 +1,126 @@
+# frozen_string_literal: true
+
+require 'asciidoctor/include_ext/include_processor'
+
+module Gitlab
+ module Asciidoc
+ # Asciidoctor extension for processing includes (macro include::[]) within
+ # documents inside the same repository.
+ class IncludeProcessor < Asciidoctor::IncludeExt::IncludeProcessor
+ extend ::Gitlab::Utils::Override
+
+ def initialize(context)
+ super(logger: Gitlab::AppLogger)
+
+ @context = context
+ @repository = context[:project].try(:repository)
+
+ # Note: Asciidoctor calls #freeze on extensions, so we can't set new
+ # instance variables after initialization.
+ @cache = {
+ uri_types: {}
+ }
+ end
+
+ protected
+
+ override :include_allowed?
+ def include_allowed?(target, reader)
+ doc = reader.document
+
+ return false if doc.attributes.fetch('max-include-depth').to_i < 1
+ return false if target_uri?(target)
+
+ true
+ end
+
+ override :resolve_target_path
+ def resolve_target_path(target, reader)
+ return unless repository.try(:exists?)
+
+ base_path = reader.include_stack.empty? ? requested_path : reader.file
+ path = resolve_relative_path(target, base_path)
+
+ path if Gitlab::Git::Blob.find(repository, ref, path)
+ end
+
+ override :read_lines
+ def read_lines(filename, selector)
+ blob = read_blob(ref, filename)
+
+ if selector
+ blob.data.each_line.select.with_index(1, &selector)
+ else
+ blob.data
+ end
+ end
+
+ override :unresolved_include!
+ def unresolved_include!(target, reader)
+ reader.unshift_line("*[ERROR: include::#{target}[] - unresolved directive]*")
+ end
+
+ private
+
+ attr_accessor :context, :repository, :cache
+
+ # Gets a Blob at a path for a specific revision.
+ # This method will check that the Blob exists and contains readable text.
+ #
+ # revision - The String SHA1.
+ # path - The String file path.
+ #
+ # Returns a Blob
+ def read_blob(ref, filename)
+ blob = repository&.blob_at(ref, filename)
+
+ raise 'Blob not found' unless blob
+ raise 'File is not readable' unless blob.readable_text?
+
+ blob
+ end
+
+ # Resolves the given relative path of file in repository into canonical
+ # path based on the specified base_path.
+ #
+ # Examples:
+ #
+ # # File in the same directory as the current path
+ # resolve_relative_path("users.adoc", "doc/api/README.adoc")
+ # # => "doc/api/users.adoc"
+ #
+ # # File in the same directory, which is also the current path
+ # resolve_relative_path("users.adoc", "doc/api")
+ # # => "doc/api/users.adoc"
+ #
+ # # Going up one level to a different directory
+ # resolve_relative_path("../update/7.14-to-8.0.adoc", "doc/api/README.adoc")
+ # # => "doc/update/7.14-to-8.0.adoc"
+ #
+ # Returns a String
+ def resolve_relative_path(path, base_path)
+ p = Pathname(base_path)
+ p = p.dirname unless p.extname.empty?
+ p += path
+
+ p.cleanpath.to_s
+ end
+
+ def current_commit
+ cache[:current_commit] ||= context[:commit] || repository&.commit(ref)
+ end
+
+ def ref
+ context[:ref] || context[:project].default_branch
+ end
+
+ def requested_path
+ cache[:requested_path] ||= Addressable::URI.unescape(context[:requested_path])
+ end
+
+ def uri_type(path)
+ cache[:uri_types][path] ||= current_commit&.uri_type(path)
+ end
+ end
+ end
+end
diff --git a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml
index 1d55c64ec56..dcf8254ef94 100644
--- a/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml
+++ b/lib/gitlab/ci/templates/Jobs/Deploy.gitlab-ci.yml
@@ -505,7 +505,7 @@ rollout 100%:
}
function ensure_namespace() {
- kubectl describe namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
+ kubectl get namespace "$KUBE_NAMESPACE" || kubectl create namespace "$KUBE_NAMESPACE"
}
function check_kube_domain() {
diff --git a/lib/gitlab/legacy_github_import/importer.rb b/lib/gitlab/legacy_github_import/importer.rb
index 70b18221a66..751726d4810 100644
--- a/lib/gitlab/legacy_github_import/importer.rb
+++ b/lib/gitlab/legacy_github_import/importer.rb
@@ -55,7 +55,12 @@ module Gitlab
import_pull_requests
import_issues
import_comments(:issues)
- import_comments(:pull_requests)
+
+ # Gitea doesn't have an API endpoint for pull requests comments
+ unless project.gitea_import?
+ import_comments(:pull_requests)
+ end
+
import_wiki
# Gitea doesn't have a Release API yet
diff --git a/qa/qa/page/base.rb b/qa/qa/page/base.rb
index d247a273637..d0fe2987b0a 100644
--- a/qa/qa/page/base.rb
+++ b/qa/qa/page/base.rb
@@ -197,6 +197,10 @@ module QA
views.map(&:elements).flatten
end
+ def send_keys_to_element(name, keys)
+ find_element(name).send_keys(keys)
+ end
+
class DSL
attr_reader :views
diff --git a/qa/qa/page/project/issue/show.rb b/qa/qa/page/project/issue/show.rb
index 77bad7481d8..b59540d0377 100644
--- a/qa/qa/page/project/issue/show.rb
+++ b/qa/qa/page/project/issue/show.rb
@@ -8,11 +8,6 @@ module QA
include Page::Component::Issuable::Common
include Page::Component::Note
- view 'app/views/shared/notes/_form.html.haml' do
- element :new_note_form, 'new-note' # rubocop:disable QA/ElementWithPattern
- element :new_note_form, 'attr: :note' # rubocop:disable QA/ElementWithPattern
- end
-
view 'app/assets/javascripts/notes/components/comment_form.vue' do
element :comment_button
element :comment_input
@@ -27,6 +22,21 @@ module QA
element :noteable_note_item
end
+ view 'app/helpers/dropdowns_helper.rb' do
+ element :dropdown_input_field
+ end
+
+ view 'app/views/shared/notes/_form.html.haml' do
+ element :new_note_form, 'new-note' # rubocop:disable QA/ElementWithPattern
+ element :new_note_form, 'attr: :note' # rubocop:disable QA/ElementWithPattern
+ end
+
+ view 'app/views/shared/issuable/_sidebar.html.haml' do
+ element :labels_block
+ element :edit_link_labels
+ element :dropdown_menu_labels
+ end
+
# Adds a comment to an issue
# attachment option should be an absolute path
def comment(text, attachment: nil, filter: :all_activities)
@@ -47,6 +57,10 @@ module QA
end
end
+ def select_all_activities_filter
+ select_filter_with_text('Show all activity')
+ end
+
def select_comments_only_filter
select_filter_with_text('Show comments only')
end
@@ -55,8 +69,26 @@ module QA
select_filter_with_text('Show history only')
end
- def select_all_activities_filter
- select_filter_with_text('Show all activity')
+ def select_labels_and_refresh(labels)
+ click_element(:edit_link_labels)
+
+ labels.each do |label|
+ within_element(:dropdown_menu_labels, text: label) do
+ send_keys_to_element(:dropdown_input_field, [label, :enter])
+ end
+ end
+
+ click_body
+
+ labels.each do |label|
+ has_element?(:labels_block, text: label)
+ end
+
+ refresh
+ end
+
+ def text_of_labels_block
+ find_element(:labels_block)
end
private
diff --git a/qa/qa/resource/issue.rb b/qa/qa/resource/issue.rb
index 2c2f27fe231..9c57a0f5afb 100644
--- a/qa/qa/resource/issue.rb
+++ b/qa/qa/resource/issue.rb
@@ -12,6 +12,8 @@ module QA
end
end
+ attribute :id
+ attribute :labels
attribute :title
def fabricate!
@@ -25,6 +27,21 @@ module QA
page.create_new_issue
end
end
+
+ def api_get_path
+ "/projects/#{project.id}/issues/#{id}"
+ end
+
+ def api_post_path
+ "/projects/#{project.id}/issues"
+ end
+
+ def api_post_body
+ {
+ labels: [labels],
+ title: title
+ }
+ end
end
end
end
diff --git a/qa/qa/resource/label.rb b/qa/qa/resource/label.rb
index 7c899db31f3..5a681a5fe9f 100644
--- a/qa/qa/resource/label.rb
+++ b/qa/qa/resource/label.rb
@@ -34,6 +34,27 @@ module QA
page.click_label_create_button
end
end
+
+ def resource_web_url(resource)
+ super
+ rescue ResourceURLMissingError
+ # this particular resource does not expose a web_url property
+ end
+
+ def api_get_path
+ raise NotImplementedError, "The Labels API doesn't expose a single-resource endpoint so this method cannot be properly implemented."
+ end
+
+ def api_post_path
+ "/projects/#{project}/labels"
+ end
+
+ def api_post_body
+ {
+ color: @color,
+ name: @title
+ }
+ end
end
end
end
diff --git a/qa/qa/specs/features/browser_ui/2_plan/issue/collapse_comments_in_discussions_spec.rb b/qa/qa/specs/features/browser_ui/2_plan/issue/collapse_comments_in_discussions_spec.rb
index fa779bd1f4e..4478ea41662 100644
--- a/qa/qa/specs/features/browser_ui/2_plan/issue/collapse_comments_in_discussions_spec.rb
+++ b/qa/qa/specs/features/browser_ui/2_plan/issue/collapse_comments_in_discussions_spec.rb
@@ -9,7 +9,7 @@ module QA
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.perform(&:sign_in_using_credentials)
- Resource::Issue.fabricate! do |issue|
+ Resource::Issue.fabricate_via_browser_ui! do |issue|
issue.title = issue_title
end
diff --git a/qa/qa/specs/features/browser_ui/2_plan/issue/create_issue_spec.rb b/qa/qa/specs/features/browser_ui/2_plan/issue/create_issue_spec.rb
index 00094161f61..1eea3efec7f 100644
--- a/qa/qa/specs/features/browser_ui/2_plan/issue/create_issue_spec.rb
+++ b/qa/qa/specs/features/browser_ui/2_plan/issue/create_issue_spec.rb
@@ -42,7 +42,7 @@ module QA
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
- Resource::Issue.fabricate! do |issue|
+ Resource::Issue.fabricate_via_browser_ui! do |issue|
issue.title = issue_title
end
end
diff --git a/qa/qa/specs/features/browser_ui/2_plan/issue/filter_issue_comments_spec.rb b/qa/qa/specs/features/browser_ui/2_plan/issue/filter_issue_comments_spec.rb
index b2164bb5fab..ad2773b41ac 100644
--- a/qa/qa/specs/features/browser_ui/2_plan/issue/filter_issue_comments_spec.rb
+++ b/qa/qa/specs/features/browser_ui/2_plan/issue/filter_issue_comments_spec.rb
@@ -9,7 +9,7 @@ module QA
Runtime::Browser.visit(:gitlab, Page::Main::Login)
Page::Main::Login.act { sign_in_using_credentials }
- Resource::Issue.fabricate! do |issue|
+ Resource::Issue.fabricate_via_browser_ui! do |issue|
issue.title = issue_title
end
diff --git a/qa/qa/specs/features/browser_ui/3_create/merge_request/create_merge_request_spec.rb b/qa/qa/specs/features/browser_ui/3_create/merge_request/create_merge_request_spec.rb
index 0ff71baed90..cd1c7545944 100644
--- a/qa/qa/specs/features/browser_ui/3_create/merge_request/create_merge_request_spec.rb
+++ b/qa/qa/specs/features/browser_ui/3_create/merge_request/create_merge_request_spec.rb
@@ -23,7 +23,7 @@ module QA
expect(page).to have_content(merge_request_title)
expect(page).to have_content(merge_request_description)
- expect(page).to have_content(/Opened [\w\s]+ ago/)
+ expect(page).to have_content('Opened just now')
end
it 'user creates a new merge request with a milestone and label' do
@@ -41,7 +41,7 @@ module QA
milestone.project = current_project
end
- new_label = Resource::Label.fabricate! do |label|
+ new_label = Resource::Label.fabricate_via_browser_ui! do |label|
label.project = current_project
label.title = 'qa-mr-test-label'
label.description = 'Merge Request label'
@@ -62,7 +62,7 @@ module QA
Page::MergeRequest::Show.perform do |merge_request|
expect(merge_request).to have_content(merge_request_title)
expect(merge_request).to have_content(merge_request_description)
- expect(merge_request).to have_content(/Opened [\w\s]+ ago/)
+ expect(merge_request).to have_content('Opened just now')
expect(merge_request).to have_assignee(gitlab_account_username)
expect(merge_request).to have_label(new_label.title)
end
diff --git a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb
index fc4ff364fd4..a04efb94def 100644
--- a/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb
+++ b/qa/qa/specs/features/browser_ui/non_devops/performance_bar_spec.rb
@@ -19,7 +19,7 @@ module QA
it 'shows results for the original request and AJAX requests' do
# Issue pages always make AJAX requests
- Resource::Issue.fabricate! do |issue|
+ Resource::Issue.fabricate_via_browser_ui! do |issue|
issue.title = 'Performance bar test'
end
diff --git a/qa/qa/support/page/logging.rb b/qa/qa/support/page/logging.rb
index 02ebd96ad49..93d8fa99c0a 100644
--- a/qa/qa/support/page/logging.rb
+++ b/qa/qa/support/page/logging.rb
@@ -125,7 +125,7 @@ module QA
super
end
- def within_element(name)
+ def within_element(name, text: nil)
log("within element :#{name}")
element = super
diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb
index 092c6a17c9c..0f1ed039149 100644
--- a/qa/spec/page/logging_spec.rb
+++ b/qa/spec/page/logging_spec.rb
@@ -135,9 +135,9 @@ describe QA::Support::Page::Logging do
end
it 'logs within_element' do
- expect { subject.within_element(:element) }
+ expect { subject.within_element(:element, text: nil) }
.to output(/within element :element/).to_stdout_from_any_process
- expect { subject.within_element(:element) }
+ expect { subject.within_element(:element, text: nil) }
.to output(/end within element :element/).to_stdout_from_any_process
end
diff --git a/spec/features/contextual_sidebar_spec.rb b/spec/features/contextual_sidebar_spec.rb
new file mode 100644
index 00000000000..88da1b7966b
--- /dev/null
+++ b/spec/features/contextual_sidebar_spec.rb
@@ -0,0 +1,37 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+
+describe 'Contextual sidebar', :js do
+ let(:user) { create(:user) }
+ let(:project) { create(:project) }
+
+ before do
+ project.add_maintainer(user)
+ sign_in(user)
+
+ visit project_path(project)
+ end
+
+ it 'shows flyout navs when collapsed or expanded apart from on the active item when expanded' do
+ expect(page).not_to have_selector('.js-sidebar-collapsed')
+
+ find('.qa-link-pipelines').hover
+
+ expect(page).to have_selector('.is-showing-fly-out')
+
+ find('.qa-link-project').hover
+
+ expect(page).not_to have_selector('.is-showing-fly-out')
+
+ find('.qa-toggle-sidebar').click
+
+ find('.qa-link-pipelines').hover
+
+ expect(page).to have_selector('.is-showing-fly-out')
+
+ find('.qa-link-project').hover
+
+ expect(page).to have_selector('.is-showing-fly-out')
+ end
+end
diff --git a/spec/helpers/environments_helper_spec.rb b/spec/helpers/environments_helper_spec.rb
index 0c8a8d2f032..2b8bf9319fc 100644
--- a/spec/helpers/environments_helper_spec.rb
+++ b/spec/helpers/environments_helper_spec.rb
@@ -27,7 +27,7 @@ describe EnvironmentsHelper do
'empty-no-data-svg-path' => match_asset_path('/assets/illustrations/monitoring/no_data.svg'),
'empty-unable-to-connect-svg-path' => match_asset_path('/assets/illustrations/monitoring/unable_to_connect.svg'),
'metrics-endpoint' => additional_metrics_project_environment_path(project, environment, format: :json),
- 'deployment-endpoint' => project_environment_deployments_path(project, environment, format: :json),
+ 'deployments-endpoint' => project_environment_deployments_path(project, environment, format: :json),
'environments-endpoint': project_environments_path(project, format: :json),
'project-path' => project_path(project),
'tags-path' => project_tags_path(project),
diff --git a/spec/helpers/search_helper_spec.rb b/spec/helpers/search_helper_spec.rb
index 2f59cfda0a0..da14f7f16fb 100644
--- a/spec/helpers/search_helper_spec.rb
+++ b/spec/helpers/search_helper_spec.rb
@@ -113,8 +113,10 @@ describe SearchHelper do
expect(search_filter_input_options('')[:data]['project-id']).to eq(@project.id)
end
- it 'includes project base-endpoint' do
+ it 'includes project endpoints' do
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq(project_path(@project))
+ expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(project_labels_path(@project))
+ expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(project_milestones_path(@project))
end
it 'includes autocomplete=off flag' do
@@ -131,8 +133,10 @@ describe SearchHelper do
expect(search_filter_input_options('')[:data]['project-id']).to eq(nil)
end
- it 'includes group base-endpoint' do
+ it 'includes group endpoints' do
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/groups#{group_path(@group)}")
+ expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(group_labels_path(@group))
+ expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(group_milestones_path(@group))
end
end
@@ -142,8 +146,10 @@ describe SearchHelper do
expect(search_filter_input_options('')[:data]['group-id']).to eq(nil)
end
- it 'includes dashboard base-endpoint' do
+ it 'includes dashboard endpoints' do
expect(search_filter_input_options('')[:data]['base-endpoint']).to eq("/dashboard")
+ expect(search_filter_input_options('')[:data]['labels-endpoint']).to eq(dashboard_labels_path)
+ expect(search_filter_input_options('')[:data]['milestones-endpoint']).to eq(dashboard_milestones_path)
end
end
end
diff --git a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js
index a72ea6ab547..0ee13faf841 100644
--- a/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js
+++ b/spec/javascripts/filtered_search/filtered_search_visual_tokens_spec.js
@@ -118,7 +118,7 @@ describe('Filtered Search Visual Tokens', () => {
describe('getEndpointWithQueryParams', () => {
it('returns `endpoint` string as is when second param `endpointQueryParams` is undefined, null or empty string', () => {
- const endpoint = 'foo/bar/labels.json';
+ const endpoint = 'foo/bar/-/labels.json';
expect(subject.getEndpointWithQueryParams(endpoint)).toBe(endpoint);
expect(subject.getEndpointWithQueryParams(endpoint, null)).toBe(endpoint);
@@ -126,7 +126,7 @@ describe('Filtered Search Visual Tokens', () => {
});
it('returns `endpoint` string with values of `endpointQueryParams`', () => {
- const endpoint = 'foo/bar/labels.json';
+ const endpoint = 'foo/bar/-/labels.json';
const singleQueryParams = '{"foo":"true"}';
const multipleQueryParams = '{"foo":"true","bar":"true"}';
diff --git a/spec/javascripts/filtered_search/visual_token_value_spec.js b/spec/javascripts/filtered_search/visual_token_value_spec.js
index 14217d460cc..d1d16afc977 100644
--- a/spec/javascripts/filtered_search/visual_token_value_spec.js
+++ b/spec/javascripts/filtered_search/visual_token_value_spec.js
@@ -156,9 +156,11 @@ describe('Filtered Search Visual Tokens', () => {
const filteredSearchInput = document.querySelector('.filtered-search');
filteredSearchInput.dataset.baseEndpoint = dummyEndpoint;
+ filteredSearchInput.dataset.labelsEndpoint = `${dummyEndpoint}/-/labels`;
+ filteredSearchInput.dataset.milestonesEndpoint = `${dummyEndpoint}/-/milestones`;
AjaxCache.internalStorage = {};
- AjaxCache.internalStorage[`${dummyEndpoint}/labels.json`] = labelData;
+ AjaxCache.internalStorage[`${filteredSearchInput.dataset.labelsEndpoint}.json`] = labelData;
});
const parseColor = color => {
diff --git a/spec/javascripts/monitoring/dashboard_spec.js b/spec/javascripts/monitoring/dashboard_spec.js
index f1d578648b8..f4166987aed 100644
--- a/spec/javascripts/monitoring/dashboard_spec.js
+++ b/spec/javascripts/monitoring/dashboard_spec.js
@@ -20,7 +20,7 @@ const propsData = {
tagsPath: '/path/to/tags',
projectPath: '/path/to/project',
metricsEndpoint: mockApiEndpoint,
- deploymentEndpoint: null,
+ deploymentsEndpoint: null,
emptyGettingStartedSvgPath: '/path/to/getting-started.svg',
emptyLoadingSvgPath: '/path/to/loading.svg',
emptyNoDataSvgPath: '/path/to/no-data.svg',
diff --git a/spec/javascripts/monitoring/store/actions_spec.js b/spec/javascripts/monitoring/store/actions_spec.js
index 8c02e21eda2..083a01c4d74 100644
--- a/spec/javascripts/monitoring/store/actions_spec.js
+++ b/spec/javascripts/monitoring/store/actions_spec.js
@@ -51,9 +51,9 @@ describe('Monitoring store actions', () => {
it('commits RECEIVE_DEPLOYMENTS_DATA_SUCCESS on error', done => {
const dispatch = jasmine.createSpy();
const { state } = store;
- state.deploymentEndpoint = '/success';
+ state.deploymentsEndpoint = '/success';
- mock.onGet(state.deploymentEndpoint).reply(200, {
+ mock.onGet(state.deploymentsEndpoint).reply(200, {
deployments: deploymentData,
});
@@ -68,9 +68,9 @@ describe('Monitoring store actions', () => {
it('commits RECEIVE_DEPLOYMENTS_DATA_FAILURE on error', done => {
const dispatch = jasmine.createSpy();
const { state } = store;
- state.deploymentEndpoint = '/error';
+ state.deploymentsEndpoint = '/error';
- mock.onGet(state.deploymentEndpoint).reply(500);
+ mock.onGet(state.deploymentsEndpoint).reply(500);
fetchDeploymentsData({ state, dispatch })
.then(() => {
diff --git a/spec/javascripts/vue_shared/components/sidebar/labels_select/mock_data.js b/spec/javascripts/vue_shared/components/sidebar/labels_select/mock_data.js
index 70025f041a7..6564c012e67 100644
--- a/spec/javascripts/vue_shared/components/sidebar/labels_select/mock_data.js
+++ b/spec/javascripts/vue_shared/components/sidebar/labels_select/mock_data.js
@@ -48,8 +48,8 @@ export const mockConfig = {
},
namespace: 'gitlab-org',
updatePath: '/gitlab-org/my-project/issue/1',
- labelsPath: '/gitlab-org/my-project/labels.json',
- labelsWebUrl: '/gitlab-org/my-project/labels',
+ labelsPath: '/gitlab-org/my-project/-/labels.json',
+ labelsWebUrl: '/gitlab-org/my-project/-/labels',
labelFilterBasePath: '/gitlab-org/my-project/issues',
canEdit: true,
suggestedColors: mockSuggestedColors,
diff --git a/spec/lib/gitlab/asciidoc_spec.rb b/spec/lib/gitlab/asciidoc_spec.rb
index e1782cff81a..0f933ac5464 100644
--- a/spec/lib/gitlab/asciidoc_spec.rb
+++ b/spec/lib/gitlab/asciidoc_spec.rb
@@ -3,20 +3,23 @@ require 'nokogiri'
module Gitlab
describe Asciidoc do
- let(:input) { '<b>ascii</b>' }
- let(:context) { {} }
- let(:html) { 'H<sub>2</sub>O' }
+ include FakeBlobHelpers
+
+ before do
+ allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
+ end
context "without project" do
- before do
- allow_any_instance_of(ApplicationSetting).to receive(:current).and_return(::ApplicationSetting.create_from_defaults)
- end
+ let(:input) { '<b>ascii</b>' }
+ let(:context) { {} }
+ let(:html) { 'H<sub>2</sub>O' }
it "converts the input using Asciidoctor and default options" do
expected_asciidoc_opts = {
safe: :secure,
backend: :gitlab_html5,
- attributes: described_class::DEFAULT_ADOC_ATTRS
+ attributes: described_class::DEFAULT_ADOC_ATTRS,
+ extensions: be_a(Proc)
}
expect(Asciidoctor).to receive(:convert)
@@ -30,7 +33,8 @@ module Gitlab
expected_asciidoc_opts = {
safe: :secure,
backend: :gitlab_html5,
- attributes: described_class::DEFAULT_ADOC_ATTRS
+ attributes: described_class::DEFAULT_ADOC_ATTRS,
+ extensions: be_a(Proc)
}
expect(Asciidoctor).to receive(:convert)
@@ -105,6 +109,174 @@ module Gitlab
end
end
+ context 'with project' do
+ let(:context) do
+ {
+ commit: commit,
+ project: project,
+ ref: ref,
+ requested_path: requested_path
+ }
+ end
+ let(:commit) { project.commit(ref) }
+ let(:project) { create(:project, :repository) }
+ let(:ref) { 'asciidoc' }
+ let(:requested_path) { '/' }
+
+ context 'include directive' do
+ subject(:output) { render(input, context) }
+
+ let(:input) { "Include this:\n\ninclude::#{include_path}[]" }
+
+ before do
+ current_file = requested_path
+ current_file += 'README.adoc' if requested_path.end_with? '/'
+
+ create_file(current_file, "= AsciiDoc\n")
+ end
+
+ context 'with path to non-existing file' do
+ let(:include_path) { 'not-exists.adoc' }
+
+ it 'renders Unresolved directive placeholder' do
+ is_expected.to include("<strong>[ERROR: include::#{include_path}[] - unresolved directive]</strong>")
+ end
+ end
+
+ shared_examples :invalid_include do
+ let(:include_path) { 'dk.png' }
+
+ before do
+ allow(project.repository).to receive(:blob_at).and_return(blob)
+ end
+
+ it 'does not read the blob' do
+ expect(blob).not_to receive(:data)
+ end
+
+ it 'renders Unresolved directive placeholder' do
+ is_expected.to include("<strong>[ERROR: include::#{include_path}[] - unresolved directive]</strong>")
+ end
+ end
+
+ context 'with path to a binary file' do
+ let(:blob) { fake_blob(path: 'dk.png', binary: true) }
+ include_examples :invalid_include
+ end
+
+ context 'with path to file in external storage' do
+ let(:blob) { fake_blob(path: 'dk.png', lfs: true) }
+
+ before do
+ allow(Gitlab.config.lfs).to receive(:enabled).and_return(true)
+ project.update_attribute(:lfs_enabled, true)
+ end
+
+ include_examples :invalid_include
+ end
+
+ context 'with path to a textual file' do
+ let(:include_path) { 'sample.adoc' }
+
+ before do
+ create_file(file_path, "Content from #{include_path}")
+ end
+
+ shared_examples :valid_include do
+ [
+ ['/doc/sample.adoc', 'doc/sample.adoc', 'absolute path'],
+ ['sample.adoc', 'doc/api/sample.adoc', 'relative path'],
+ ['./sample.adoc', 'doc/api/sample.adoc', 'relative path with leading ./'],
+ ['../sample.adoc', 'doc/sample.adoc', 'relative path to a file up one directory'],
+ ['../../sample.adoc', 'sample.adoc', 'relative path for a file up multiple directories']
+ ].each do |include_path_, file_path_, desc|
+
+ context "the file is specified by #{desc}" do
+ let(:include_path) { include_path_ }
+ let(:file_path) { file_path_ }
+
+ it 'includes content of the file' do
+ is_expected.to include('<p>Include this:</p>')
+ is_expected.to include("<p>Content from #{include_path}</p>")
+ end
+ end
+ end
+ end
+
+ context 'when requested path is a file in the repo' do
+ let(:requested_path) { 'doc/api/README.adoc' }
+
+ include_examples :valid_include
+
+ context 'without a commit (only ref)' do
+ let(:commit) { nil }
+ include_examples :valid_include
+ end
+ end
+
+ context 'when requested path is a directory in the repo' do
+ let(:requested_path) { 'doc/api/' }
+
+ include_examples :valid_include
+
+ context 'without a commit (only ref)' do
+ let(:commit) { nil }
+ include_examples :valid_include
+ end
+ end
+ end
+
+ context 'recursive includes with relative paths' do
+ let(:input) do
+ <<~ADOC
+ Source: requested file
+
+ include::doc/README.adoc[]
+
+ include::license.adoc[]
+ ADOC
+ end
+
+ before do
+ create_file 'doc/README.adoc', <<~ADOC
+ Source: doc/README.adoc
+
+ include::../license.adoc[]
+
+ include::api/hello.adoc[]
+ ADOC
+ create_file 'license.adoc', <<~ADOC
+ Source: license.adoc
+ ADOC
+ create_file 'doc/api/hello.adoc', <<~ADOC
+ Source: doc/api/hello.adoc
+
+ include::./common.adoc[]
+ ADOC
+ create_file 'doc/api/common.adoc', <<~ADOC
+ Source: doc/api/common.adoc
+ ADOC
+ end
+
+ it 'includes content of the included files recursively' do
+ expect(output.gsub(/<[^>]+>/, '').gsub(/\n\s*/, "\n").strip).to eq <<~ADOC.strip
+ Source: requested file
+ Source: doc/README.adoc
+ Source: license.adoc
+ Source: doc/api/hello.adoc
+ Source: doc/api/common.adoc
+ Source: license.adoc
+ ADOC
+ end
+ end
+
+ def create_file(path, content)
+ project.repository.create_file(project.creator, path, content,
+ message: "Add #{path}", branch_name: 'asciidoc')
+ end
+ end
+ end
+
def render(*args)
described_class.render(*args)
end
diff --git a/spec/lib/gitlab/legacy_github_import/importer_spec.rb b/spec/lib/gitlab/legacy_github_import/importer_spec.rb
index 6bc3792eb22..a0c664da185 100644
--- a/spec/lib/gitlab/legacy_github_import/importer_spec.rb
+++ b/spec/lib/gitlab/legacy_github_import/importer_spec.rb
@@ -13,21 +13,22 @@ describe Gitlab::LegacyGithubImport::Importer do
expected_called = [
:import_labels, :import_milestones, :import_pull_requests, :import_issues,
- :import_wiki, :import_releases, :handle_errors
+ :import_wiki, :import_releases, :handle_errors,
+ [:import_comments, :issues],
+ [:import_comments, :pull_requests]
]
expected_called -= expected_not_called
aggregate_failures do
- expected_called.each do |method_name|
- expect(importer).to receive(method_name)
+ expected_called.each do |method_name, arg|
+ base_expectation = proc { expect(importer).to receive(method_name) }
+ arg ? base_expectation.call.with(arg) : base_expectation.call
end
- expect(importer).to receive(:import_comments).with(:issues)
- expect(importer).to receive(:import_comments).with(:pull_requests)
-
- expected_not_called.each do |method_name|
- expect(importer).not_to receive(method_name)
+ expected_not_called.each do |method_name, arg|
+ base_expectation = proc { expect(importer).not_to receive(method_name) }
+ arg ? base_expectation.call.with(arg) : base_expectation.call
end
end
@@ -289,7 +290,7 @@ describe Gitlab::LegacyGithubImport::Importer do
end
it_behaves_like 'Gitlab::LegacyGithubImport::Importer#execute' do
- let(:expected_not_called) { [:import_releases] }
+ let(:expected_not_called) { [:import_releases, [:import_comments, :pull_requests]] }
end
it_behaves_like 'Gitlab::LegacyGithubImport::Importer#execute an error occurs'
it_behaves_like 'Gitlab::LegacyGithubImport unit-testing'
diff --git a/spec/mailers/repository_check_mailer_spec.rb b/spec/mailers/repository_check_mailer_spec.rb
index 384660f7221..3dce89f5be2 100644
--- a/spec/mailers/repository_check_mailer_spec.rb
+++ b/spec/mailers/repository_check_mailer_spec.rb
@@ -12,6 +12,16 @@ describe RepositoryCheckMailer do
expect(mail).to deliver_to admins.map(&:email)
end
+ it 'omits blocked admins' do
+ blocked = create(:admin, :blocked)
+ admins = create_list(:admin, 3)
+
+ mail = described_class.notify(1)
+
+ expect(mail.to).not_to include(blocked.email)
+ expect(mail).to deliver_to admins.map(&:email)
+ end
+
it 'mentions the number of failed checks' do
mail = described_class.notify(3)
diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb
index 14f4b4d692f..e76186fb280 100644
--- a/spec/models/commit_spec.rb
+++ b/spec/models/commit_spec.rb
@@ -44,6 +44,14 @@ describe Commit do
expect(commit.id).to eq(oids[i])
end
end
+
+ it 'does not attempt to replace methods via BatchLoader' do
+ subject.each do |commit|
+ expect(commit).to receive(:method_missing).and_call_original
+
+ commit.id
+ end
+ end
end
context 'when not found' do
diff --git a/spec/models/group_spec.rb b/spec/models/group_spec.rb
index e6e7298a043..d7accbef6bd 100644
--- a/spec/models/group_spec.rb
+++ b/spec/models/group_spec.rb
@@ -603,40 +603,96 @@ describe Group do
describe '#update_two_factor_requirement' do
let(:user) { create(:user) }
- before do
- group.add_user(user, GroupMember::OWNER)
- end
+ context 'group membership' do
+ before do
+ group.add_user(user, GroupMember::OWNER)
+ end
- it 'is called when require_two_factor_authentication is changed' do
- expect_any_instance_of(User).to receive(:update_two_factor_requirement)
+ it 'is called when require_two_factor_authentication is changed' do
+ expect_any_instance_of(User).to receive(:update_two_factor_requirement)
- group.update!(require_two_factor_authentication: true)
- end
+ group.update!(require_two_factor_authentication: true)
+ end
- it 'is called when two_factor_grace_period is changed' do
- expect_any_instance_of(User).to receive(:update_two_factor_requirement)
+ it 'is called when two_factor_grace_period is changed' do
+ expect_any_instance_of(User).to receive(:update_two_factor_requirement)
- group.update!(two_factor_grace_period: 23)
- end
+ group.update!(two_factor_grace_period: 23)
+ end
- it 'is not called when other attributes are changed' do
- expect_any_instance_of(User).not_to receive(:update_two_factor_requirement)
+ it 'is not called when other attributes are changed' do
+ expect_any_instance_of(User).not_to receive(:update_two_factor_requirement)
- group.update!(description: 'foobar')
+ group.update!(description: 'foobar')
+ end
+
+ it 'calls #update_two_factor_requirement on each group member' do
+ other_user = create(:user)
+ group.add_user(other_user, GroupMember::OWNER)
+
+ calls = 0
+ allow_any_instance_of(User).to receive(:update_two_factor_requirement) do
+ calls += 1
+ end
+
+ group.update!(require_two_factor_authentication: true, two_factor_grace_period: 23)
+
+ expect(calls).to eq 2
+ end
end
- it 'calls #update_two_factor_requirement on each group member' do
- other_user = create(:user)
- group.add_user(other_user, GroupMember::OWNER)
+ context 'sub groups and projects', :nested_groups do
+ it 'enables two_factor_requirement for group member' do
+ group.add_user(user, GroupMember::OWNER)
- calls = 0
- allow_any_instance_of(User).to receive(:update_two_factor_requirement) do
- calls += 1
+ group.update!(require_two_factor_authentication: true)
+
+ expect(user.reload.require_two_factor_authentication_from_group).to be_truthy
end
- group.update!(require_two_factor_authentication: true, two_factor_grace_period: 23)
+ context 'expanded group members', :nested_groups do
+ let(:indirect_user) { create(:user) }
+
+ it 'enables two_factor_requirement for subgroup member' do
+ subgroup = create(:group, :nested, parent: group)
+ subgroup.add_user(indirect_user, GroupMember::OWNER)
- expect(calls).to eq 2
+ group.update!(require_two_factor_authentication: true)
+
+ expect(indirect_user.reload.require_two_factor_authentication_from_group).to be_truthy
+ end
+
+ it 'does not enable two_factor_requirement for ancestor group member' do
+ ancestor_group = create(:group)
+ ancestor_group.add_user(indirect_user, GroupMember::OWNER)
+ group.update!(parent: ancestor_group)
+
+ group.update!(require_two_factor_authentication: true)
+
+ expect(indirect_user.reload.require_two_factor_authentication_from_group).to be_falsey
+ end
+ end
+
+ context 'project members' do
+ it 'does not enable two_factor_requirement for child project member' do
+ project = create(:project, group: group)
+ project.add_maintainer(user)
+
+ group.update!(require_two_factor_authentication: true)
+
+ expect(user.reload.require_two_factor_authentication_from_group).to be_falsey
+ end
+
+ it 'does not enable two_factor_requirement for subgroup child project member', :nested_groups do
+ subgroup = create(:group, :nested, parent: group)
+ project = create(:project, group: subgroup)
+ project.add_maintainer(user)
+
+ group.update!(require_two_factor_authentication: true)
+
+ expect(user.reload.require_two_factor_authentication_from_group).to be_falsey
+ end
+ end
end
end
diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb
index d1338e34bb8..c95bbb0b3f5 100644
--- a/spec/models/user_spec.rb
+++ b/spec/models/user_spec.rb
@@ -2655,9 +2655,9 @@ describe User do
end
end
- context 'with 2FA requirement on nested parent group', :nested_groups do
+ context 'with 2FA requirement from expanded groups', :nested_groups do
let!(:group1) { create :group, require_two_factor_authentication: true }
- let!(:group1a) { create :group, require_two_factor_authentication: false, parent: group1 }
+ let!(:group1a) { create :group, parent: group1 }
before do
group1a.add_user(user, GroupMember::OWNER)
@@ -2685,6 +2685,27 @@ describe User do
end
end
+ context "with 2FA requirement from shared project's group" do
+ let!(:group1) { create :group, require_two_factor_authentication: true }
+ let!(:group2) { create :group }
+ let(:shared_project) { create(:project, namespace: group1) }
+
+ before do
+ shared_project.project_group_links.create!(
+ group: group2,
+ group_access: ProjectGroupLink.default_access
+ )
+
+ group2.add_user(user, GroupMember::OWNER)
+ end
+
+ it 'does not require 2FA' do
+ user.update_two_factor_requirement
+
+ expect(user.require_two_factor_authentication_from_group).to be false
+ end
+ end
+
context 'without 2FA requirement on groups' do
let(:group) { create :group }
diff --git a/vendor/assets/javascripts/visual_review_toolbar.js b/vendor/assets/javascripts/visual_review_toolbar.js
deleted file mode 100644
index 12a3a4c9672..00000000000
--- a/vendor/assets/javascripts/visual_review_toolbar.js
+++ /dev/null
@@ -1,377 +0,0 @@
-///////////////////////////////////////////////
-/////////////////// STYLES ////////////////////
-///////////////////////////////////////////////
-
-// this style must be applied inline
-const buttonClearStyles = `
- -webkit-appearance: none;
-`;
-
-///////////////////////////////////////////////
-/////////////////// STATE ////////////////////
-///////////////////////////////////////////////
-const data = {};
-
-///////////////////////////////////////////////
-///////////////// COMPONENTS //////////////////
-///////////////////////////////////////////////
-const note = `
- <p id='gitlab-validation-note' class='gitlab-message'></p>
-`;
-
-const comment = `
- <div>
- <textarea id='gitlab-comment' name='gitlab-comment' rows='3' placeholder='Enter your feedback or idea' class='gitlab-input'></textarea>
- ${note}
- <p class='gitlab-metadata-note'>Additional metadata will be included: browser, OS, current page, user agent, and viewport dimensions.</p>
- </div>
- <div class='gitlab-button-wrapper''>
- <button class='gitlab-button gitlab-button-secondary' style='${buttonClearStyles}' type='button' id='gitlab-logout-button'> Logout </button>
- <button class='gitlab-button gitlab-button-success' style='${buttonClearStyles}' type='button' id='gitlab-comment-button'> Send feedback </button>
- </div>
-`;
-
-const commentIcon = `
- <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>icn/comment</title><path d="M4 11.132l1.446-.964A1 1 0 0 1 6 10h5a1 1 0 0 0 1-1V5a1 1 0 0 0-1-1H5a1 1 0 0 0-1 1v6.132zM6.303 12l-2.748 1.832A1 1 0 0 1 2 13V5a3 3 0 0 1 3-3h6a3 3 0 0 1 3 3v4a3 3 0 0 1-3 3H6.303z" id="gitlab-comment-icon"/></svg>
-`;
-
-const compressIcon = `
- <svg width="16" height="16" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"><title>icn/compress</title><path d="M5.27 12.182l-1.562 1.561a1 1 0 0 1-1.414 0h-.001a1 1 0 0 1 0-1.415l1.56-1.56L2.44 9.353a.5.5 0 0 1 .353-.854H7.09a.5.5 0 0 1 .5.5v4.294a.5.5 0 0 1-.853.353l-1.467-1.465zm6.911-6.914l1.464 1.464a.5.5 0 0 1-.353.854H8.999a.5.5 0 0 1-.5-.5V2.793a.5.5 0 0 1 .854-.354l1.414 1.415 1.56-1.561a1 1 0 1 1 1.415 1.414l-1.561 1.56z" id="gitlab-compress-icon"/></svg>
-`;
-
-const collapseButton = `
- <button id='gitlab-collapse' style='${buttonClearStyles}' class='gitlab-button gitlab-button-secondary gitlab-collapse gitlab-collapse-open'>${compressIcon}</button>
-`;
-
-const form = content => `
- <div id='gitlab-form-wrapper'>
- ${content}
- </div>
-`;
-
-const login = `
- <div>
- <label for='gitlab-token' class='gitlab-label'>Enter your <a class='gitlab-link' href="https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html">personal access token</a></label>
- <input class='gitlab-input' type='password' id='gitlab-token' name='gitlab-token'>
- ${note}
- </div>
- <div class='gitlab-checkbox-wrapper'>
- <input type="checkbox" id="remember_token" name="remember_token" value="remember">
- <label for="remember_token" class='gitlab-checkbox-label'>Remember me</label>
- </div>
- <div class='gitlab-button-wrapper'>
- <button class='gitlab-button-wide gitlab-button gitlab-button-success' style='${buttonClearStyles}' type='button' id='gitlab-login'> Submit </button>
- </div>
-`;
-
-///////////////////////////////////////////////
-//////////////// INTERACTIONS /////////////////
-///////////////////////////////////////////////
-
-// from https://developer.mozilla.org/en-US/docs/Web/API/Window/navigator
-function getBrowserId(sUsrAg) {
- var aKeys = ['MSIE', 'Edge', 'Firefox', 'Safari', 'Chrome', 'Opera'],
- nIdx = aKeys.length - 1;
-
- for (nIdx; nIdx > -1 && sUsrAg.indexOf(aKeys[nIdx]) === -1; nIdx--);
- return aKeys[nIdx];
-}
-
-function addCommentForm() {
- const formWrapper = document.getElementById('gitlab-form-wrapper');
- formWrapper.innerHTML = comment;
-}
-
-function addLoginForm() {
- const formWrapper = document.getElementById('gitlab-form-wrapper');
- formWrapper.innerHTML = login;
-}
-
-function authorizeUser() {
- // Clear any old errors
- clearNote('gitlab-token');
-
- const token = document.getElementById('gitlab-token').value;
- const rememberMe = document.getElementById('remember_token').checked;
-
- if (!token) {
- postError('Please enter your token.', 'gitlab-token');
- return;
- }
-
- if (rememberMe) {
- storeToken(token);
- }
-
- authSuccess(token);
- return;
-}
-
-function authSuccess(token) {
- data.token = token;
- addCommentForm();
-}
-
-function clearNote(inputId) {
- const note = document.getElementById('gitlab-validation-note');
- note.innerText = '';
- note.style.color = '';
-
- if (inputId) {
- const field = document.getElementById(inputId);
- field.style.borderColor = '';
- }
-}
-
-function confirmAndClear(mergeRequestId) {
- const commentButton = document.getElementById('gitlab-comment-button');
- const note = document.getElementById('gitlab-validation-note');
-
- commentButton.innerText = 'Feedback sent';
- note.innerText = `Your comment was successfully posted to merge request #${mergeRequestId}`;
-
- setTimeout(resetCommentButton, 1000);
-}
-
-function getInitialState() {
- const { localStorage } = window;
-
- try {
- let token = localStorage.getItem('token');
-
- if (token) {
- data.token = token;
- return comment;
- }
-
- return login;
- } catch (err) {
- return login;
- }
-}
-
-function getProjectDetails() {
- const {
- innerWidth,
- innerHeight,
- location: { href },
- navigator: { platform, userAgent },
- } = window;
- const browser = getBrowserId(userAgent);
-
- const scriptEl = document.getElementById('review-app-toolbar-script');
- const { projectId, mergeRequestId, mrUrl } = scriptEl.dataset;
-
- return {
- href,
- platform,
- browser,
- userAgent,
- innerWidth,
- innerHeight,
- projectId,
- mergeRequestId,
- mrUrl,
- };
-}
-
-function logoutUser() {
- const { localStorage } = window;
-
- // All the browsers we support have localStorage, so let's silently fail
- // and go on with the rest of the functionality.
- try {
- localStorage.removeItem('token');
- } catch (err) {
- return;
- }
-
- addLoginForm();
-}
-
-function postComment({
- href,
- platform,
- browser,
- userAgent,
- innerWidth,
- innerHeight,
- projectId,
- mergeRequestId,
- mrUrl,
-}) {
- // Clear any old errors
- clearNote('gitlab-comment');
-
- setInProgressState();
-
- const commentText = document.getElementById('gitlab-comment').value.trim();
-
- if (!commentText) {
- postError('Your comment appears to be empty.', 'gitlab-comment');
- resetCommentBox();
- return;
- }
-
- const detailText = `
- \n
-<details>
- <summary>Metadata</summary>
- Posted from ${href} | ${platform} | ${browser} | ${innerWidth} x ${innerHeight}.
- <br /><br />
- <em>User agent: ${userAgent}</em>
-</details>
- `;
-
- const url = `
- ${mrUrl}/api/v4/projects/${projectId}/merge_requests/${mergeRequestId}/discussions`;
-
- const body = `${commentText} ${detailText}`;
-
- fetch(url, {
- method: 'POST',
- headers: {
- 'PRIVATE-TOKEN': data.token,
- 'Content-Type': 'application/json',
- },
- body: JSON.stringify({ body }),
- })
- .then(response => {
- if (response.ok) {
- confirmAndClear(mergeRequestId);
- return;
- }
-
- throw new Error(`${response.status}: ${response.statusText}`);
- })
- .catch(err => {
- postError(
- `The feedback was not sent successfully. Please try again. Error: ${err.message}`,
- 'gitlab-comment',
- );
- resetCommentBox();
- });
-}
-
-function postError(message, inputId) {
- const note = document.getElementById('gitlab-validation-note');
- const field = document.getElementById(inputId);
- field.style.borderColor = '#db3b21';
- note.style.color = '#db3b21';
- note.innerText = message;
-}
-
-function resetCommentBox() {
- const commentBox = document.getElementById('gitlab-comment');
- const commentButton = document.getElementById('gitlab-comment-button');
-
- commentButton.innerText = 'Send feedback';
- commentButton.classList.replace('gitlab-button-secondary', 'gitlab-button-success');
- commentButton.style.opacity = 1;
-
- commentBox.style.pointerEvents = 'auto';
- commentBox.style.color = 'rgba(0, 0, 0, 1)';
-}
-
-function resetCommentButton() {
- const commentBox = document.getElementById('gitlab-comment');
- const note = document.getElementById('gitlab-validation-note');
-
- commentBox.value = '';
- note.innerText = '';
- resetCommentBox();
-}
-
-function setInProgressState() {
- const commentButton = document.getElementById('gitlab-comment-button');
- const commentBox = document.getElementById('gitlab-comment');
-
- commentButton.innerText = 'Sending feedback';
- commentButton.classList.replace('gitlab-button-success', 'gitlab-button-secondary');
- commentButton.style.opacity = 0.5;
- commentBox.style.color = 'rgba(223, 223, 223, 0.5)';
- commentBox.style.pointerEvents = 'none';
-}
-
-function storeToken(token) {
- const { localStorage } = window;
-
- // All the browsers we support have localStorage, so let's silently fail
- // and go on with the rest of the functionality.
- try {
- localStorage.setItem('token', token);
- } catch (err) {
- return;
- }
-}
-
-function toggleForm() {
- const container = document.getElementById('gitlab-review-container');
- const collapseButton = document.getElementById('gitlab-collapse');
- const form = document.getElementById('gitlab-form-wrapper');
- const OPEN = 'open';
- const CLOSED = 'closed';
-
- const stateVals = {
- [OPEN]: {
- buttonClasses: ['gitlab-collapse-closed', 'gitlab-collapse-open'],
- containerClasses: ['gitlab-closed-wrapper', 'gitlab-open-wrapper'],
- icon: compressIcon,
- display: 'flex',
- backgroundColor: 'rgba(255, 255, 255, 1)',
- },
- [CLOSED]: {
- buttonClasses: ['gitlab-collapse-open', 'gitlab-collapse-closed'],
- containerClasses: ['gitlab-open-wrapper', 'gitlab-closed-wrapper'],
- icon: commentIcon,
- display: 'none',
- backgroundColor: 'rgba(255, 255, 255, 0)',
- },
- };
-
- const nextState = collapseButton.classList.contains('gitlab-collapse-open') ? CLOSED : OPEN;
-
- container.classList.replace(...stateVals[nextState].containerClasses);
- container.style.backgroundColor = stateVals[nextState].backgroundColor;
- form.style.display = stateVals[nextState].display;
- collapseButton.classList.replace(...stateVals[nextState].buttonClasses);
- collapseButton.innerHTML = stateVals[nextState].icon;
-}
-
-///////////////////////////////////////////////
-///////////////// INJECTION //////////////////
-///////////////////////////////////////////////
-
-function noop() {}
-
-const eventLookup = ({ target: { id } }) => {
- switch (id) {
- case 'gitlab-collapse':
- return toggleForm;
- case 'gitlab-comment-button':
- const projectDetails = getProjectDetails();
- return postComment.bind(null, projectDetails);
- case 'gitlab-login':
- return authorizeUser;
- case 'gitlab-logout-button':
- return logoutUser;
- default:
- return noop;
- }
-};
-
-window.addEventListener('load', () => {
- const content = getInitialState();
- const container = document.createElement('div');
-
- container.setAttribute('id', 'gitlab-review-container');
- container.insertAdjacentHTML('beforeend', collapseButton);
- container.insertAdjacentHTML('beforeend', form(content));
-
- document.body.insertBefore(container, document.body.firstChild);
-
- document.getElementById('gitlab-review-container').addEventListener('click', event => {
- eventLookup(event)();
- });
-
-});