From bd5d5791c552da3446db979fd2f576e91a1c1b37 Mon Sep 17 00:00:00 2001 From: GitLab Bot Date: Thu, 23 Apr 2020 09:09:46 +0000 Subject: [PATCH] Add latest changes from gitlab-org/gitlab@master --- .../199843-fix-viewing-nil-blobs.yml | 5 +++ .../214283-add-updated-at-to-todos-api.yml | 5 +++ doc/api/todos.md | 9 +++-- doc/development/documentation/styleguide.md | 12 ++++--- .../merge_requests/accessibility_testing.md | 5 ++- lib/api/entities/todo.rb | 1 + lib/declarative_policy.rb | 17 +++++---- lib/gitlab/blob_helper.rb | 16 +++++++-- qa/Gemfile.lock | 2 +- spec/lib/declarative_policy_spec.rb | 36 +++++++++++++++++++ spec/lib/gitlab/git/blob_spec.rb | 12 +++++++ spec/requests/api/todos_spec.rb | 1 + spec/support/helpers/fake_blob_helpers.rb | 6 +++- 13 files changed, 105 insertions(+), 22 deletions(-) create mode 100644 changelogs/unreleased/199843-fix-viewing-nil-blobs.yml create mode 100644 changelogs/unreleased/214283-add-updated-at-to-todos-api.yml create mode 100644 spec/lib/declarative_policy_spec.rb diff --git a/changelogs/unreleased/199843-fix-viewing-nil-blobs.yml b/changelogs/unreleased/199843-fix-viewing-nil-blobs.yml new file mode 100644 index 00000000000..61cedbf5ab2 --- /dev/null +++ b/changelogs/unreleased/199843-fix-viewing-nil-blobs.yml @@ -0,0 +1,5 @@ +--- +title: Fix display of some overflowing merge request diffs +merge_request: 29267 +author: +type: fixed diff --git a/changelogs/unreleased/214283-add-updated-at-to-todos-api.yml b/changelogs/unreleased/214283-add-updated-at-to-todos-api.yml new file mode 100644 index 00000000000..42f2d3a6615 --- /dev/null +++ b/changelogs/unreleased/214283-add-updated-at-to-todos-api.yml @@ -0,0 +1,5 @@ +--- +title: Expose the updated_at attribute in the todos API +merge_request: 30035 +author: +type: changed diff --git a/doc/api/todos.md b/doc/api/todos.md index 2711766c634..cd6f2468cc6 100644 --- a/doc/api/todos.md +++ b/doc/api/todos.md @@ -101,7 +101,8 @@ Example Response: "target_url": "https://gitlab.example.com/gitlab-org/gitlab-foss/-/merge_requests/7", "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", "state": "pending", - "created_at": "2016-06-17T07:52:35.225Z" + "created_at": "2016-06-17T07:52:35.225Z", + "updated_at": "2016-06-17T07:52:35.225Z" }, { "id": 98, @@ -174,7 +175,8 @@ Example Response: "target_url": "https://gitlab.example.com/gitlab-org/gitlab-foss/-/merge_requests/7", "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", "state": "pending", - "created_at": "2016-06-17T07:49:24.624Z" + "created_at": "2016-06-17T07:49:24.624Z", + "updated_at": "2016-06-17T07:49:24.624Z" } ] ``` @@ -272,7 +274,8 @@ Example Response: "target_url": "https://gitlab.example.com/gitlab-org/gitlab-foss/-/merge_requests/7", "body": "Dolores in voluptatem tenetur praesentium omnis repellendus voluptatem quaerat.", "state": "done", - "created_at": "2016-06-17T07:52:35.225Z" + "created_at": "2016-06-17T07:52:35.225Z", + "updated_at": "2016-06-17T07:52:35.225Z" } ``` diff --git a/doc/development/documentation/styleguide.md b/doc/development/documentation/styleguide.md index d6f4289e4b5..0c6028971d9 100644 --- a/doc/development/documentation/styleguide.md +++ b/doc/development/documentation/styleguide.md @@ -19,7 +19,7 @@ that apply to all GitLab content, not just documentation. The documentation of GitLab products and features is the SSOT for all information related to implementation, usage, and troubleshooting. It evolves continually, in keeping with new products and features, and with improvements for clarity, accuracy, and completeness. -This policy prevents information silos, ensuring that it remains easy to find information about GitLab products. +This policy prevents information silos, making it easier to find information about GitLab products. It also informs decisions about the kinds of content we include in our documentation. @@ -61,7 +61,7 @@ Instead, link to the SSOT and explain why it is important to consume the informa ### Organize by topic, not by type -Beyond top-level audience-type folders (for example, `administration`), we organize content by topic, not by type, so that it can be located as easily as possible within the single-source-of-truth (SSOT) section for the subject matter. +Beyond top-level audience-type folders (for example, `administration`), we organize content by topic, not by type, so it can be located as easily as possible within the single-source-of-truth (SSOT) section for the subject matter. For example, do not create groupings of similar media types. For example: @@ -76,7 +76,7 @@ and cross-link between any related content. ### Docs-first methodology -We employ a **docs-first methodology** to help ensure that the docs remain a complete and trusted resource, and to make communicating about the use of GitLab more efficient. +We employ a **docs-first methodology** to help ensure the docs remain a complete and trusted resource, and to make communicating about the use of GitLab more efficient. - If the answer to a question exists in documentation, share the link to the docs instead of rephrasing the information. - When you encounter new information not available in GitLab’s documentation (for example, when working on a support case or testing a feature), your first step should be to create a merge request (MR) to add this information to the docs. You can then share the MR in order to communicate this information. @@ -129,13 +129,13 @@ correctly, but is not the current standard for GitLab documentation). A rule that could cause confusion is `MD044/proper-names`, as it might not be immediately clear what caused markdownlint to fail, or how to correct the failure. This rule checks a list of known words, listed in the `.markdownlint.json` file in each project, -to verify that proper capitalization and backticks are used. Words in backticks will +to verify proper use of capitalization and backticks. Words in backticks will be ignored by markdownlint. In general, product names should follow the exact capitalization of the official names of the products, protocols, and so on. -Some examples that will fail if incorrect capitalization is used: +Some examples fail if incorrect capitalization is used: - MinIO (needs capital `IO`) - NGINX (needs all capitals) @@ -252,6 +252,8 @@ GitLab documentation should be clear and easy to understand. - Avoid uncommon words. - Don't write in the first person singular. - Instead of "I" or "me," use "we," "you," "us," or "one." + - When possible, stay user focused by writing in the second person ("you" or the imperative). +- Don't overuse "that". In many cases, you can remove "that" from a sentence and improve readability. ### Point of view diff --git a/doc/user/project/merge_requests/accessibility_testing.md b/doc/user/project/merge_requests/accessibility_testing.md index 755bf0447e3..24c073e762c 100644 --- a/doc/user/project/merge_requests/accessibility_testing.md +++ b/doc/user/project/merge_requests/accessibility_testing.md @@ -46,9 +46,12 @@ Pa11y against the webpages defined in `a11y_urls`, and builds an HTML report for The report for each URL is saved as an artifact that can be [viewed directly in your browser](../../../ci/pipelines/job_artifacts.md#browsing-artifacts). -A single `accessibility.json` artifact is created and saved along with the individual HTML reports. +A single `gl-accessibility.json` artifact is created and saved along with the individual HTML reports. It includes report data for all URLs scanned. +NOTE: **Note:** +For GitLab 12.10 and earlier, the [artifact generated is named `accessibility.json`](https://gitlab.com/gitlab-org/ci-cd/accessibility/-/merge_requests/9). + NOTE: **Note:** For GitLab versions earlier than 12.9, you can use `include:remote` and use a link to the [current template in `master`](https://gitlab.com/gitlab-org/gitlab/-/raw/master/lib/gitlab/ci/templates/Verify/Accessibility.gitlab-ci.yml) diff --git a/lib/api/entities/todo.rb b/lib/api/entities/todo.rb index abfdde89bf1..8261a0b488e 100644 --- a/lib/api/entities/todo.rb +++ b/lib/api/entities/todo.rb @@ -22,6 +22,7 @@ module API expose :body expose :state expose :created_at + expose :updated_at def todo_target_class(target_type) # false as second argument prevents looking up in module hierarchy diff --git a/lib/declarative_policy.rb b/lib/declarative_policy.rb index e51f30af581..bd1c121fe79 100644 --- a/lib/declarative_policy.rb +++ b/lib/declarative_policy.rb @@ -72,18 +72,17 @@ module DeclarativePolicy end def compute_class_for_class(subject_class) + if subject_class.respond_to?(:declarative_policy_class) + return subject_class.declarative_policy_class.constantize + end + subject_class.ancestors.each do |klass| - next unless klass.name + name = klass.name + + next unless name begin - klass_name = - if subject_class.respond_to?(:declarative_policy_class) - subject_class.declarative_policy_class - else - "#{klass.name}Policy" - end - - policy_class = klass_name.constantize + policy_class = "#{name}Policy".constantize # NOTE: the < operator here tests whether policy_class # inherits from Base. We can't use #is_a? because that diff --git a/lib/gitlab/blob_helper.rb b/lib/gitlab/blob_helper.rb index fc579ad8d2a..57d632afd74 100644 --- a/lib/gitlab/blob_helper.rb +++ b/lib/gitlab/blob_helper.rb @@ -3,6 +3,8 @@ # This has been extracted from https://github.com/github/linguist/blob/master/lib/linguist/blob_helper.rb module Gitlab module BlobHelper + include Gitlab::Utils::StrongMemoize + def extname File.extname(name.to_s) end @@ -120,8 +122,18 @@ module Gitlab end def encoded_newlines_re - @encoded_newlines_re ||= - Regexp.union(["\r\n", "\r", "\n"].map { |nl| nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data.encoding) }) + strong_memoize(:encoded_newlines_re) do + newlines = ["\r\n", "\r", "\n"] + data_encoding = data&.encoding + + if ruby_encoding && data_encoding + newlines.map! do |nl| + nl.encode(ruby_encoding, "ASCII-8BIT").force_encoding(data_encoding) + end + end + + Regexp.union(newlines) + end end def ruby_encoding diff --git a/qa/Gemfile.lock b/qa/Gemfile.lock index 75531573a50..5046ab654e5 100644 --- a/qa/Gemfile.lock +++ b/qa/Gemfile.lock @@ -93,7 +93,7 @@ GEM rspec-support (3.7.0) rspec_junit_formatter (0.4.1) rspec-core (>= 2, < 4, != 2.12.0) - ruby-debug-ide (0.7.0) + ruby-debug-ide (0.7.2) rake (>= 0.8.1) rubyzip (1.3.0) selenium-webdriver (3.142.6) diff --git a/spec/lib/declarative_policy_spec.rb b/spec/lib/declarative_policy_spec.rb new file mode 100644 index 00000000000..0904b084c57 --- /dev/null +++ b/spec/lib/declarative_policy_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe DeclarativePolicy do + describe '.class_for' do + it 'uses declarative_policy_class if present' do + instance = Gitlab::ErrorTracking::ErrorEvent.new + + expect(described_class.class_for(instance)).to eq(ErrorTracking::BasePolicy) + end + + it 'infers policy class from name' do + instance = PersonalSnippet.new + + expect(described_class.class_for(instance)).to eq(PersonalSnippetPolicy) + end + + it 'raises error if not found' do + instance = Object.new + + expect { described_class.class_for(instance) }.to raise_error('no policy for Object') + end + + context 'when found policy class does not inherit base' do + class Foo; end + class FooPolicy; end + + it 'raises error if inferred class does not inherit Base' do + instance = Foo.new + + expect { described_class.class_for(instance) }.to raise_error('no policy for Foo') + end + end + end +end diff --git a/spec/lib/gitlab/git/blob_spec.rb b/spec/lib/gitlab/git/blob_spec.rb index 06f9767d58b..46d9b78c14b 100644 --- a/spec/lib/gitlab/git/blob_spec.rb +++ b/spec/lib/gitlab/git/blob_spec.rb @@ -652,4 +652,16 @@ describe Gitlab::Git::Blob, :seed_helper do expect(described_class).to respond_to(:gitlab_blob_size) end end + + describe '#lines' do + context 'when the encoding cannot be detected' do + it 'successfully splits the data' do + data = "test\nblob" + blob = Gitlab::Git::Blob.new(name: 'test', size: data.bytesize, data: data) + expect(blob).to receive(:ruby_encoding) { nil } + + expect(blob.lines).to eq(data.split("\n")) + end + end + end end diff --git a/spec/requests/api/todos_spec.rb b/spec/requests/api/todos_spec.rb index 1aa5e21dddb..1c380d51813 100644 --- a/spec/requests/api/todos_spec.rb +++ b/spec/requests/api/todos_spec.rb @@ -235,6 +235,7 @@ describe API::Todos do expect(json_response['state']).to eq('pending') expect(json_response['action_name']).to eq('marked') expect(json_response['created_at']).to be_present + expect(json_response['updated_at']).to be_present end it 'returns 304 there already exist a todo on that issuable' do diff --git a/spec/support/helpers/fake_blob_helpers.rb b/spec/support/helpers/fake_blob_helpers.rb index a7eafb0fd23..6c8866deac4 100644 --- a/spec/support/helpers/fake_blob_helpers.rb +++ b/spec/support/helpers/fake_blob_helpers.rb @@ -22,7 +22,11 @@ module FakeBlobHelpers alias_method :name, :path def id - 0 + "00000000" + end + + def commit_id + "11111111" end def binary_in_repo?