From ae6edf18fcf207a63a7130ec8d49966acd83de67 Mon Sep 17 00:00:00 2001 From: "Z.J. van de Weg" Date: Wed, 29 Jun 2016 18:00:22 +0200 Subject: Update rubocop to 0.41.2 https://github.com/bbatsov/rubocop/blob/v0.41.2/CHANGELOG.md --- .rubocop.yml | 6 ++--- .rubocop_todo.yml | 65 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ Gemfile | 2 +- Gemfile.lock | 12 +++++----- 4 files changed, 74 insertions(+), 11 deletions(-) create mode 100644 .rubocop_todo.yml diff --git a/.rubocop.yml b/.rubocop.yml index 3aac8401848..17802fbb307 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -2,6 +2,8 @@ require: - rubocop-rspec - ./rubocop/rubocop +inherit_from: .rubocop_todo.yml + AllCops: TargetRubyVersion: 2.1 # Cop names are not displayed in offense messages by default. Change behavior @@ -159,10 +161,6 @@ Style/ConstantName: Style/DefWithParentheses: Enabled: true -# Checks for use of deprecated Hash methods. -Style/DeprecatedHashMethods: - Enabled: false - # Document classes and non-namespace modules. Style/Documentation: Enabled: false diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml new file mode 100644 index 00000000000..9a791d74c15 --- /dev/null +++ b/.rubocop_todo.yml @@ -0,0 +1,65 @@ +# This configuration was generated by +# `rubocop --auto-gen-config` +# on 2016-06-29 18:24:55 +0200 using RuboCop version 0.41.1. +# The point is for the user to remove these configuration records +# one by one as the offenses are removed from the code base. +# Note that changes in the inspected code, or installation of new +# versions of RuboCop, may require this file to be generated again. + +# Offense count: 1 +Lint/ShadowedException: + Exclude: + - 'app/models/u2f_registration.rb' + +# Offense count: 12 +# Cop supports --auto-correct. +Performance/PushSplat: + Exclude: + - 'app/controllers/projects/refs_controller.rb' + - 'app/helpers/page_layout_helper.rb' + - 'app/models/ability.rb' + - 'app/models/network/graph.rb' + - 'app/models/project_team.rb' + - 'app/models/user.rb' + - 'config/application.rb' + +# Offense count: 59 +Rails/OutputSafety: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles. +# SupportedOctalStyles: zero_with_o, zero_only +Style/NumericLiteralPrefix: + Exclude: + - 'config/initializers/1_settings.rb' + - 'config/initializers/secret_token.rb' + - 'lib/gitlab/backend/shell.rb' + - 'spec/support/test_env.rb' + - 'spec/tasks/gitlab/backup_rake_spec.rb' + +# Offense count: 28 +# Cop supports --auto-correct. +Style/PreferredHashMethods: + Exclude: + - 'app/helpers/dropdowns_helper.rb' + - 'app/models/application_setting.rb' + - 'app/models/members/project_member.rb' + - 'app/services/git_push_service.rb' + - 'lib/api/helpers.rb' + - 'lib/ci/api/builds.rb' + - 'lib/ci/gitlab_ci_yaml_processor.rb' + - 'lib/gitlab/ci/config/node/configurable.rb' + - 'lib/gitlab/ci/config/node/factory.rb' + - 'lib/gitlab/google_code_import/client.rb' + - 'lib/gitlab/google_code_import/importer.rb' + - 'lib/gitlab/visibility_level.rb' + - 'spec/requests/api/projects_spec.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Style/SpaceInsidePercentLiteralDelimiters: + Exclude: + - 'lib/event_filter.rb' + - 'lib/gitlab/git_access.rb' diff --git a/Gemfile b/Gemfile index 5c43015e52c..0769214a071 100644 --- a/Gemfile +++ b/Gemfile @@ -299,7 +299,7 @@ group :development, :test do gem 'spring-commands-spinach', '~> 1.1.0' gem 'spring-commands-teaspoon', '~> 0.0.2' - gem 'rubocop', '~> 0.40.0', require: false + gem 'rubocop', '~> 0.41.1', require: false gem 'rubocop-rspec', '~> 1.5.0', require: false gem 'scss_lint', '~> 0.47.0', require: false gem 'simplecov', '~> 0.11.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index f8018e58a5e..6f93a534359 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -58,7 +58,7 @@ GEM faraday_middleware-multi_json (~> 0.0) oauth2 (~> 1.0) asciidoctor (1.5.3) - ast (2.2.0) + ast (2.3.0) attr_encrypted (3.0.1) encryptor (~> 3.0.0) attr_required (1.0.0) @@ -473,7 +473,7 @@ GEM orm_adapter (0.5.0) paranoia (2.1.4) activerecord (~> 4.0) - parser (2.3.1.0) + parser (2.3.1.2) ast (~> 2.2) pg (0.18.4) pkg-config (1.1.7) @@ -606,8 +606,8 @@ GEM rspec-retry (0.4.5) rspec-core rspec-support (3.5.0) - rubocop (0.40.0) - parser (>= 2.3.1.0, < 3.0) + rubocop (0.41.2) + parser (>= 2.3.1.1, < 3.0) powerpack (~> 0.1) rainbow (>= 1.99.1, < 3.0) ruby-progressbar (~> 1.7) @@ -758,7 +758,7 @@ GEM unf (0.1.4) unf_ext unf_ext (0.0.7.2) - unicode-display_width (1.0.5) + unicode-display_width (1.1.0) unicorn (4.9.0) kgio (~> 2.6) rack @@ -937,7 +937,7 @@ DEPENDENCIES rqrcode-rails3 (~> 0.1.7) rspec-rails (~> 3.5.0) rspec-retry (~> 0.4.5) - rubocop (~> 0.40.0) + rubocop (~> 0.41.1) rubocop-rspec (~> 1.5.0) ruby-fogbugz (~> 0.2.1) sanitize (~> 2.0) -- cgit v1.2.1 From fb4f3a473b633ebd165d351e7101898c2b87ad72 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Sun, 3 Jul 2016 14:18:39 -0600 Subject: Remove some disabled cops. --- .rubocop.yml | 363 +--------------------------------- .rubocop_todo.yml | 567 ++++++++++++++++++++++++++++++++++++++++++++++++++++-- 2 files changed, 552 insertions(+), 378 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index 17802fbb307..ce4287a2796 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,10 +37,6 @@ AllCops: Style/AccessModifierIndentation: Enabled: true -# Check the naming of accessor methods for get_/set_. -Style/AccessorMethodName: - Enabled: false - # Use alias_method instead of alias. Style/Alias: EnforcedStyle: prefer_alias_method @@ -54,14 +50,6 @@ Style/AlignArray: Style/AlignHash: Enabled: true -# Align the parameters of a method call if they span more than one line. -Style/AlignParameters: - Enabled: false - -# Use &&/|| instead of and/or. -Style/AndOr: - Enabled: false - # Use `Array#join` instead of `Array#*`. Style/ArrayJoin: Enabled: true @@ -82,10 +70,6 @@ Style/Attr: Style/BeginBlock: Enabled: true -# Checks if usage of %() or %Q() matches configuration. -Style/BarePercentLiterals: - Enabled: false - # Do not use block comments. Style/BlockComments: Enabled: true @@ -99,14 +83,6 @@ Style/BlockEndNewline: Style/BlockDelimiters: Enabled: true -# Enforce braces style around hash parameters. -Style/BracesAroundHashParameters: - Enabled: false - -# Avoid explicit use of the case equality operator(===). -Style/CaseEquality: - Enabled: false - # Indentation of when in a case/when/[else/]end. Style/CaseIndentation: Enabled: true @@ -135,24 +111,10 @@ Style/ClassMethods: Style/ClassVars: Enabled: true -# Do not use :: for method call. -Style/ColonMethodCall: - Enabled: false - -# Checks formatting of special comments (TODO, FIXME, OPTIMIZE, HACK, REVIEW). -Style/CommentAnnotation: - Enabled: false - # Indentation of comments. Style/CommentIndentation: Enabled: true -# Use the return value of `if` and `case` statements for assignment to a -# variable and variable comparison instead of assigning that variable -# inside of each branch. -Style/ConditionalAssignment: - Enabled: false - # Constants should use SCREAMING_SNAKE_CASE. Style/ConstantName: Enabled: true @@ -165,26 +127,10 @@ Style/DefWithParentheses: Style/Documentation: Enabled: false -# Checks the position of the dot in multi-line method calls. -Style/DotPosition: - Enabled: false - -# Checks for uses of double negation (!!). -Style/DoubleNegation: - Enabled: false - -# Prefer `each_with_object` over `inject` or `reduce`. -Style/EachWithObject: - Enabled: false - # Align elses and elsifs correctly. Style/ElseAlignment: Enabled: true -# Avoid empty else-clauses. -Style/EmptyElse: - Enabled: false - # Use empty lines between defs. Style/EmptyLineBetweenDefs: Enabled: false @@ -213,10 +159,6 @@ Style/EmptyLinesAroundModuleBody: Style/EmptyLinesAroundMethodBody: Enabled: false -# Prefer literals to Array.new/Hash.new/String.new. -Style/EmptyLiteral: - Enabled: false - # Avoid the use of END blocks. Style/EndBlock: Enabled: true @@ -229,10 +171,6 @@ Style/EndOfLine: Style/EvenOdd: Enabled: true -# Do not use unnecessary spacing. -Style/ExtraSpacing: - Enabled: false - # Use snake_case for source file names. Style/FileName: Enabled: true @@ -250,31 +188,15 @@ Style/FlipFlop: Style/For: Enabled: true -# Enforce the use of Kernel#sprintf, Kernel#format or String#%. -Style/FormatString: - Enabled: false - # Do not introduce global variables. Style/GlobalVars: Enabled: true -# Check for conditionals that can be replaced with guard clauses. -Style/GuardClause: - Enabled: false - # Prefer Ruby 1.9 hash syntax `{ a: 1, b: 2 }` # over 1.8 syntax `{ :a => 1, :b => 2 }`. Style/HashSyntax: Enabled: true -# Finds if nodes inside else, which can be converted to elsif. -Style/IfInsideElse: - Enabled: false - -# Favor modifier if/unless usage when you have a single-line body. -Style/IfUnlessModifier: - Enabled: false - # Do not use if x; .... Use the ternary operator instead. Style/IfWithSemicolon: Enabled: true @@ -297,22 +219,10 @@ Style/IndentationConsistency: Style/IndentationWidth: Enabled: true -# Checks the indentation of the first element in an array literal. -Style/IndentArray: - Enabled: false - -# Checks the indentation of the first key in a hash literal. -Style/IndentHash: - Enabled: false - # Use Kernel#loop for infinite loops. Style/InfiniteLoop: Enabled: true -# Use the new lambda literal syntax for single-line blocks. -Style/Lambda: - Enabled: false - # Use lambda.call(...) instead of lambda.(...). Style/LambdaCall: Enabled: true @@ -321,14 +231,6 @@ Style/LambdaCall: Style/LeadingCommentSpace: Enabled: true -# Use \ instead of + or << to concatenate two string literals at line end. -Style/LineEndConcatenation: - Enabled: false - -# Do not use parentheses for method calls with no arguments. -Style/MethodCallParentheses: - Enabled: false - # Checks if the method definitions have or don't have parentheses. Style/MethodDefParentheses: Enabled: true @@ -337,10 +239,6 @@ Style/MethodDefParentheses: Style/MethodName: Enabled: true -# Checks for usage of `extend self` in modules. -Style/ModuleFunction: - Enabled: false - # Checks that the closing brace in an array literal is either on the same line # as the last array element, or a new line. Style/MultilineArrayBraceLayout: @@ -385,39 +283,18 @@ Style/MultilineMethodDefinitionBraceLayout: Style/MultilineOperationIndentation: Enabled: false -# Avoid multi-line `? :` (the ternary operator), use if/unless instead. -Style/MultilineTernaryOperator: - Enabled: false - -# Do not assign mutable objects to constants. -Style/MutableConstant: - Enabled: false - # Favor unless over if for negative conditions (or control flow or). Style/NegatedIf: Enabled: true -# Favor until over while for negative conditions. -Style/NegatedWhile: - Enabled: false - # Avoid using nested modifiers. Style/NestedModifier: Enabled: true -# Parenthesize method calls which are nested inside the argument list of -# another parenthesized method call. -Style/NestedParenthesizedCalls: - Enabled: false - # Use one expression per branch in a ternary operator. Style/NestedTernaryOperator: Enabled: true -# Use `next` to skip iteration instead of a condition at the end. -Style/Next: - Enabled: false - # Prefer x.nil? to x == nil. Style/NilComparison: Enabled: true @@ -442,51 +319,10 @@ Style/OneLineConditional: Style/OpMethod: Enabled: true -# Check for simple usages of parallel assignment. It will only warn when -# the number of variables matches on both sides of the assignment. -Style/ParallelAssignment: - Enabled: false - # Don't use parentheses around the condition of an if/unless/while. Style/ParenthesesAroundCondition: Enabled: true -# Use `%`-literal delimiters consistently. -Style/PercentLiteralDelimiters: - Enabled: false - -# Checks if uses of %Q/%q match the configured preference. -Style/PercentQLiterals: - Enabled: false - -# Avoid Perl-style regex back references. -Style/PerlBackrefs: - Enabled: false - -# Check the names of predicate methods. -Style/PredicateName: - Enabled: false - -# Use proc instead of Proc.new. -Style/Proc: - Enabled: false - -# Checks the arguments passed to raise/fail. -Style/RaiseArgs: - Enabled: false - -# Don't use begin blocks when they are not needed. -Style/RedundantBegin: - Enabled: false - -# Checks for an obsolete RuntimeException argument in raise/fail. -Style/RedundantException: - Enabled: false - -# Checks usages of Object#freeze on immutable objects. -Style/RedundantFreeze: - Enabled: false - # Checks for parentheses that seem not to serve any purpose. Style/RedundantParentheses: Enabled: true @@ -495,24 +331,6 @@ Style/RedundantParentheses: Style/RedundantReturn: Enabled: true -# Don't use self where it's not needed. -Style/RedundantSelf: - Enabled: false - -# Use %r for regular expressions matching more than `MaxSlashes` '/' -# characters. Use %r only for regular expressions matching more -# than `MaxSlashes` '/' character. -Style/RegexpLiteral: - Enabled: false - -# Avoid using rescue in its modifier form. -Style/RescueModifier: - Enabled: false - -# Checks for places where self-assignment shorthand should have been used. -Style/SelfAssignment: - Enabled: false - # Don't use semicolons to terminate expressions. Style/Semicolon: Enabled: true @@ -522,14 +340,6 @@ Style/SignalException: EnforcedStyle: only_raise Enabled: true -# Enforces the names of some block params. -Style/SingleLineBlockParams: - Enabled: false - -# Avoid single-line methods. -Style/SingleLineMethods: - Enabled: false - # Use spaces after colons. Style/SpaceAfterColon: Enabled: true @@ -551,11 +361,6 @@ Style/SpaceAfterNot: Style/SpaceAfterSemicolon: Enabled: true -# Checks that the equals signs in parameter default assignments have or don't -# have surrounding space depending on configuration. -Style/SpaceAroundEqualsInParameterDefault: - Enabled: false - # Use a space around keywords if appropriate. Style/SpaceAroundKeyword: Enabled: true @@ -564,10 +369,6 @@ Style/SpaceAroundKeyword: Style/SpaceAroundOperators: Enabled: true -# Checks that the left block brace has or doesn't have space before it. -Style/SpaceBeforeBlockBraces: - Enabled: false - # No spaces before commas. Style/SpaceBeforeComma: Enabled: true @@ -576,33 +377,14 @@ Style/SpaceBeforeComma: Style/SpaceBeforeComment: Enabled: true -# Checks that exactly one space is used between a method name and the first -# argument for method calls without parentheses. -Style/SpaceBeforeFirstArg: - Enabled: false - # No spaces before semicolons. Style/SpaceBeforeSemicolon: Enabled: true -# Checks that block braces have or don't have surrounding space. -# For blocks taking parameters, checks that the left brace has or doesn't -# have trailing space. -Style/SpaceInsideBlockBraces: - Enabled: false - -# No spaces after [ or before ]. -Style/SpaceInsideBrackets: - Enabled: false - # Use spaces inside hash literal braces - or don't. Style/SpaceInsideHashLiteralBraces: Enabled: true -# No spaces after ( or before ). -Style/SpaceInsideParens: - Enabled: false - # No spaces inside range literals. Style/SpaceInsideRangeLiteral: Enabled: true @@ -612,10 +394,6 @@ Style/SpaceInsideStringInterpolation: EnforcedStyle: no_space Enabled: true -# Avoid Perl-style global variables. -Style/SpecialGlobalVars: - Enabled: false - # Check for the usage of parentheses around stabby lambda arguments. Style/StabbyLambdaParentheses: EnforcedStyle: require_parentheses @@ -625,25 +403,12 @@ Style/StabbyLambdaParentheses: Style/StringLiterals: Enabled: false -# Checks if uses of quotes inside expressions in interpolated strings match the -# configured preference. -Style/StringLiteralsInInterpolation: - Enabled: false - # Checks if configured preferred methods are used over non-preferred. Style/StringMethods: PreferredMethods: intern: to_sym Enabled: true -# Use %i or %I for arrays of symbols. -Style/SymbolArray: - Enabled: false - -# Use symbols as procs instead of blocks when possible. -Style/SymbolProc: - Enabled: false - # No hard tabs. Style/Tab: Enabled: true @@ -652,40 +417,10 @@ Style/Tab: Style/TrailingBlankLines: Enabled: true -# Checks for trailing comma in array and hash literals. -Style/TrailingCommaInLiteral: - Enabled: false - -# Checks for trailing comma in argument lists. -Style/TrailingCommaInArguments: - Enabled: false - -# Avoid trailing whitespace. -Style/TrailingWhitespace: - Enabled: false - -# Checks for the usage of unneeded trailing underscores at the end of -# parallel variable assignment. -Style/TrailingUnderscoreVariable: - Enabled: false - -# Prefer attr_* methods to trivial readers/writers. -Style/TrivialAccessors: - Enabled: false - -# Do not use unless with else. Rewrite these with the positive case first. -Style/UnlessElse: - Enabled: false - # Checks for %W when interpolation is not needed. Style/UnneededCapitalW: Enabled: true -# TODO: Enable UnneededInterpolation Cop. -# Checks for strings that are just an interpolated expression. -Style/UnneededInterpolation: - Enabled: false - # Checks for %q/%Q when single quotes or double quotes would do. Style/UnneededPercentQ: Enabled: false @@ -715,12 +450,6 @@ Style/WhileUntilModifier: Style/WordArray: Enabled: false -# TODO: Enable ZeroLengthPredicate Cop. -# Use #empty? when testing for objects of length 0. -Style/ZeroLengthPredicate: - Enabled: false - - #################### Metrics ################################ # A calculated magnitude based on number of assignments, @@ -774,15 +503,6 @@ Metrics/PerceivedComplexity: Lint/AmbiguousOperator: Enabled: true -# Checks for ambiguous regexp literals in the first argument of a method -# invocation without parentheses. -Lint/AmbiguousRegexpLiteral: - Enabled: false - -# Don't use assignment in conditions. -Lint/AssignmentInCondition: - Enabled: false - # Align block ends correctly. Lint/BlockAlignment: Enabled: true @@ -808,14 +528,6 @@ Lint/DefEndAlignment: Lint/DeprecatedClassMethods: Enabled: true -# Check for duplicate method definitions. -Lint/DuplicateMethods: - Enabled: false - -# Check for duplicate keys in hash literals. -Lint/DuplicatedKey: - Enabled: false - # Check for immutable argument given to each_with_object. Lint/EachWithObjectArgument: Enabled: true @@ -828,10 +540,6 @@ Lint/ElseLayout: Lint/EmptyEnsure: Enabled: true -# Checks for empty string interpolation. -Lint/EmptyInterpolation: - Enabled: false - # Align ends correctly. Lint/EndAlignment: Enabled: true @@ -856,21 +564,11 @@ Lint/FloatOutOfRange: Lint/FormatParameterMismatch: Enabled: true -# Don't suppress exception. -Lint/HandleExceptions: - Enabled: false - # Checks for adjacent string literals on the same line, which could better be # represented as a single string literal. Lint/ImplicitStringConcatenation: Enabled: true -# TODO: Enable IneffectiveAccessModifier Cop. -# Checks for attempts to use `private` or `protected` to set the visibility -# of a class method, which does not work. -Lint/IneffectiveAccessModifier: - Enabled: false - # Checks for invalid character literals with a non-escaped whitespace # character. Lint/InvalidCharacterLiteral: @@ -884,11 +582,6 @@ Lint/LiteralInCondition: Lint/LiteralInInterpolation: Enabled: true -# Use Kernel#loop with break rather than begin/end/until or begin/end/while -# for post-loop tests. -Lint/Loop: - Enabled: false - # Do not use nested method definitions. Lint/NestedMethodDefinition: Enabled: true @@ -914,13 +607,8 @@ Lint/RequireParentheses: Lint/RescueException: Enabled: true -# Do not use the same name as outer local variable for block arguments -# or block local variables. -Lint/ShadowingOuterLocalVariable: - Enabled: false - -# 'Checks for Object#to_s usage in string interpolation. -Lint/StringConversionInInterpolation: +# Checks for the order which exceptions are rescued to avoid rescueing a less specific exception before a more specific exception. +Lint/ShadowedException: Enabled: false # Do not use prefix `_` for a variable that is used. @@ -933,22 +621,10 @@ Lint/UnderscorePrefixedVariableName: Lint/UnneededDisable: Enabled: false -# Checks for unused block arguments. -Lint/UnusedBlockArgument: - Enabled: false - -# Checks for unused method arguments. -Lint/UnusedMethodArgument: - Enabled: false - # Unreachable code. Lint/UnreachableCode: Enabled: true -# Checks for useless access modifiers. -Lint/UselessAccessModifier: - Enabled: false - # Checks for useless assignment to a local variable. Lint/UselessAssignment: Enabled: true @@ -981,11 +657,6 @@ Performance/Casecmp: Performance/DoubleStartEndWith: Enabled: true -# TODO: Enable EndWith Cop. -# Use `end_with?` instead of a regex match anchored to the end of a string. -Performance/EndWith: - Enabled: false - # Use `strip` instead of `lstrip.rstrip`. Performance/LstripRstrip: Enabled: true @@ -994,24 +665,6 @@ Performance/LstripRstrip: Performance/RangeInclude: Enabled: true -# TODO: Enable RedundantBlockCall Cop. -# Use `yield` instead of `block.call`. -Performance/RedundantBlockCall: - Enabled: false - -# TODO: Enable RedundantMatch Cop. -# Use `=~` instead of `String#match` or `Regexp#match` in a context where the -# returned `MatchData` is not needed. -Performance/RedundantMatch: - Enabled: false - -# TODO: Enable RedundantMerge Cop. -# Use `Hash#[]=`, rather than `Hash#merge!` with a single key-value pair. -Performance/RedundantMerge: - # Max number of key-value pairs to consider an offense - MaxKeyValuePairs: 2 - Enabled: false - # Use `sort` instead of `sort_by { |x| x }`. Performance/RedundantSortBy: Enabled: true @@ -1080,18 +733,6 @@ Rails/ReadWriteAttribute: Rails/ScopeArgs: Enabled: true -# Checks the correct usage of time zone aware methods. -# http://danilenko.org/2012/7/6/rails_timezones -Rails/TimeZone: - Enabled: false - -# Use validates :attribute, hash of validations. -Rails/Validation: - Enabled: false - -Rails/UniqBeforePluck: - Enabled: false - ##################### RSpec ################################## # Check that instances are not being stubbed globally. diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 9a791d74c15..cb6df9d88c2 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,15 +1,66 @@ # This configuration was generated by -# `rubocop --auto-gen-config` -# on 2016-06-29 18:24:55 +0200 using RuboCop version 0.41.1. +# `rubocop --auto-gen-config --exclude-limit 8` +# on 2016-07-03 15:32:25 -0600 using RuboCop version 0.41.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +# Offense count: 152 +Lint/AmbiguousRegexpLiteral: + Enabled: false + +# Offense count: 42 +# Configuration parameters: AllowSafeAssignment. +Lint/AssignmentInCondition: + Enabled: false + # Offense count: 1 -Lint/ShadowedException: +Lint/DuplicateMethods: + Exclude: + - 'lib/gitlab/github_import/branch_formatter.rb' + +# Offense count: 14 +Lint/HandleExceptions: + Enabled: false + +# Offense count: 20 +Lint/IneffectiveAccessModifier: + Enabled: false + +# Offense count: 2 +Lint/Loop: + Exclude: + - 'app/mailers/notify.rb' + - 'lib/gitlab/bitbucket_import/client.rb' + +# Offense count: 12 +Lint/ShadowingOuterLocalVariable: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Lint/StringConversionInInterpolation: Exclude: - - 'app/models/u2f_registration.rb' + - 'app/models/commit_range.rb' + - 'app/services/system_hooks_service.rb' + - 'app/services/system_note_service.rb' + +# Offense count: 42 +# Cop supports --auto-correct. +# Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. +Lint/UnusedBlockArgument: + Enabled: false + +# Offense count: 125 +# Cop supports --auto-correct. +# Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. +Lint/UnusedMethodArgument: + Enabled: false + +# Offense count: 11 +Lint/UselessAccessModifier: + Enabled: false # Offense count: 12 # Cop supports --auto-correct. @@ -23,10 +74,263 @@ Performance/PushSplat: - 'app/models/user.rb' - 'config/application.rb' +# Offense count: 2 +# Cop supports --auto-correct. +Performance/RedundantBlockCall: + Exclude: + - 'app/controllers/application_controller.rb' + - 'lib/gitlab/backend/shell.rb' + +# Offense count: 5 +# Cop supports --auto-correct. +Performance/RedundantMatch: + Exclude: + - 'app/models/external_issue.rb' + - 'lib/extracts_path.rb' + - 'lib/gitlab/diff/highlight.rb' + - 'lib/gitlab/diff/inline_diff.rb' + - 'lib/gitlab/diff/parser.rb' + +# Offense count: 24 +# Cop supports --auto-correct. +# Configuration parameters: MaxKeyValuePairs. +Performance/RedundantMerge: + Enabled: false + # Offense count: 59 Rails/OutputSafety: Enabled: false +# Offense count: 125 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: strict, flexible +Rails/TimeZone: + Enabled: false + +# Offense count: 12 +# Cop supports --auto-correct. +# Configuration parameters: Include. +# Include: app/models/**/*.rb +Rails/Validation: + Enabled: false + +# Offense count: 18 +Style/AccessorMethodName: + Enabled: false + +# Offense count: 208 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: with_first_parameter, with_fixed_indentation +Style/AlignParameters: + Enabled: false + +# Offense count: 32 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: always, conditionals +Style/AndOr: + Enabled: false + +# Offense count: 47 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: percent_q, bare_percent +Style/BarePercentLiterals: + Enabled: false + +# Offense count: 255 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: braces, no_braces, context_dependent +Style/BracesAroundHashParameters: + Enabled: false + +# Offense count: 4 +Style/CaseEquality: + Exclude: + - 'app/helpers/auth_helper.rb' + - 'app/models/commit.rb' + - 'app/services/projects/download_service.rb' + - 'config/initializers/trusted_proxies.rb' + +# Offense count: 19 +# Cop supports --auto-correct. +Style/ColonMethodCall: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +# Configuration parameters: Keywords. +# Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW +Style/CommentAnnotation: + Exclude: + - 'app/models/project.rb' + - 'lib/api/entities.rb' + - 'spec/requests/api/project_snippets_spec.rb' + +# Offense count: 35 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. +# SupportedStyles: assign_to_condition, assign_inside_condition +Style/ConditionalAssignment: + Enabled: false + +# Offense count: 762 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: leading, trailing +Style/DotPosition: + Enabled: false + +# Offense count: 14 +Style/DoubleNegation: + Enabled: false + +# Offense count: 3 +Style/EachWithObject: + Exclude: + - 'app/models/commit_status.rb' + - 'lib/ci/ansi2html.rb' + - 'lib/gitlab/import_export/members_mapper.rb' + +# Offense count: 29 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: empty, nil, both +Style/EmptyElse: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Style/EmptyLiteral: + Exclude: + - 'features/steps/project/commits/commits.rb' + - 'lib/gitlab/fogbugz_import/importer.rb' + - 'spec/lib/gitlab/workhorse_spec.rb' + +# Offense count: 119 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. +Style/ExtraSpacing: + Enabled: false + +# Offense count: 7 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: format, sprintf, percent +Style/FormatString: + Exclude: + - 'app/models/ci/pipeline.rb' + - 'app/services/gravatar_service.rb' + - 'config/initializers/rack_lineprof.rb' + - 'lib/ci/version_info.rb' + - 'lib/gitlab/version_info.rb' + - 'spec/requests/api/issues_spec.rb' + +# Offense count: 50 +# Configuration parameters: MinBodyLength. +Style/GuardClause: + Enabled: false + +# Offense count: 9 +Style/IdenticalConditionalBranches: + Exclude: + - 'app/controllers/projects_controller.rb' + - 'app/models/project_services/irker_service.rb' + - 'app/services/merge_requests/refresh_service.rb' + - 'lib/rouge/formatters/html_gitlab.rb' + +# Offense count: 10 +Style/IfInsideElse: + Enabled: false + +# Offense count: 178 +# Cop supports --auto-correct. +# Configuration parameters: MaxLineLength. +Style/IfUnlessModifier: + Enabled: false + +# Offense count: 48 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_brackets +Style/IndentArray: + Enabled: false + +# Offense count: 85 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. +# SupportedStyles: special_inside_parentheses, consistent, align_braces +Style/IndentHash: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: line_count_dependent, lambda, literal +Style/Lambda: + Exclude: + - 'app/models/ci/runner.rb' + - 'app/models/event.rb' + - 'app/models/note.rb' + - 'config/routes.rb' + - 'lib/api/entities.rb' + - 'spec/models/concerns/participable_spec.rb' + +# Offense count: 6 +# Cop supports --auto-correct. +Style/LineEndConcatenation: + Exclude: + - 'app/helpers/preferences_helper.rb' + - 'app/helpers/tree_helper.rb' + - 'app/models/merge_request.rb' + - 'app/models/user.rb' + - 'spec/lib/gitlab/gfm/reference_rewriter_spec.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +Style/MethodCallParentheses: + Exclude: + - 'lib/api/helpers.rb' + - 'lib/ci/ansi2html.rb' + - 'spec/features/dashboard/datetime_on_tooltips_spec.rb' + - 'spec/helpers/submodule_helper_spec.rb' + - 'spec/workers/post_receive_spec.rb' + +# Offense count: 9 +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: module_function, extend_self +Style/ModuleFunction: + Enabled: false + +# Offense count: 3 +Style/MultilineTernaryOperator: + Exclude: + - 'lib/banzai/filter/relative_link_filter.rb' + - 'spec/support/api_helpers.rb' + +# Offense count: 62 +# Cop supports --auto-correct. +Style/MutableConstant: + Enabled: false + +# Offense count: 10 +# Cop supports --auto-correct. +Style/NestedParenthesizedCalls: + Exclude: + - 'app/helpers/commits_helper.rb' + - 'app/workers/irker_worker.rb' + - 'spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb' + - 'spec/lib/gitlab/email/message/repository_push_spec.rb' + - 'spec/services/ci/create_builds_service_spec.rb' + +# Offense count: 13 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. +# SupportedStyles: skip_modifier_ifs, always +Style/Next: + Enabled: false + # Offense count: 6 # Cop supports --auto-correct. # Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles. @@ -39,23 +343,166 @@ Style/NumericLiteralPrefix: - 'spec/support/test_env.rb' - 'spec/tasks/gitlab/backup_rake_spec.rb' +# Offense count: 29 +# Cop supports --auto-correct. +Style/ParallelAssignment: + Enabled: false + +# Offense count: 201 +# Cop supports --auto-correct. +# Configuration parameters: PreferredDelimiters. +Style/PercentLiteralDelimiters: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: lower_case_q, upper_case_q +Style/PercentQLiterals: + Exclude: + - 'spec/helpers/gitlab_markdown_helper_spec.rb' + - 'spec/lib/gitlab/diff/highlight_spec.rb' + - 'spec/models/project_services/bamboo_service_spec.rb' + - 'spec/models/project_services/teamcity_service_spec.rb' + - 'spec/workers/repository_import_worker_spec.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +Style/PerlBackrefs: + Enabled: false + +# Offense count: 30 +# Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. +# NamePrefix: is_, has_, have_ +# NamePrefixBlacklist: is_, has_, have_ +# NameWhitelist: is_a? +Style/PredicateName: + Enabled: false + # Offense count: 28 # Cop supports --auto-correct. Style/PreferredHashMethods: + Enabled: false + +# Offense count: 6 +# Cop supports --auto-correct. +Style/Proc: Exclude: - - 'app/helpers/dropdowns_helper.rb' - - 'app/models/application_setting.rb' - - 'app/models/members/project_member.rb' - - 'app/services/git_push_service.rb' - - 'lib/api/helpers.rb' - - 'lib/ci/api/builds.rb' - - 'lib/ci/gitlab_ci_yaml_processor.rb' - - 'lib/gitlab/ci/config/node/configurable.rb' - - 'lib/gitlab/ci/config/node/factory.rb' - - 'lib/gitlab/google_code_import/client.rb' - - 'lib/gitlab/google_code_import/importer.rb' - - 'lib/gitlab/visibility_level.rb' - - 'spec/requests/api/projects_spec.rb' + - 'app/mailers/base_mailer.rb' + - 'app/models/label.rb' + - 'app/models/service.rb' + - 'lib/api/api_guard.rb' + - 'spec/initializers/trusted_proxies_spec.rb' + +# Offense count: 21 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: compact, exploded +Style/RaiseArgs: + Enabled: false + +# Offense count: 3 +# Cop supports --auto-correct. +Style/RedundantBegin: + Exclude: + - 'app/models/ci/build.rb' + - 'app/models/merge_request.rb' + - 'app/services/projects/import_service.rb' + +# Offense count: 1 +# Cop supports --auto-correct. +Style/RedundantException: + Exclude: + - 'app/helpers/preferences_helper.rb' + +# Offense count: 21 +# Cop supports --auto-correct. +Style/RedundantFreeze: + Enabled: false + +# Offense count: 312 +# Cop supports --auto-correct. +Style/RedundantSelf: + Enabled: false + +# Offense count: 92 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. +# SupportedStyles: slashes, percent_r, mixed +Style/RegexpLiteral: + Enabled: false + +# Offense count: 14 +# Cop supports --auto-correct. +Style/RescueModifier: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +Style/SelfAssignment: + Exclude: + - 'app/services/notification_service.rb' + - 'lib/api/runners.rb' + +# Offense count: 2 +# Configuration parameters: Methods. +# Methods: {"reduce"=>["a", "e"]}, {"inject"=>["a", "e"]} +Style/SingleLineBlockParams: + Exclude: + - 'app/models/commit.rb' + - 'spec/support/services_shared_context.rb' + +# Offense count: 50 +# Cop supports --auto-correct. +# Configuration parameters: AllowIfMethodIsEmpty. +Style/SingleLineMethods: + Exclude: + - 'lib/ci/ansi2html.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: space, no_space +Style/SpaceAroundEqualsInParameterDefault: + Enabled: false + +# Offense count: 118 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: space, no_space +Style/SpaceBeforeBlockBraces: + Enabled: false + +# Offense count: 11 +# Cop supports --auto-correct. +# Configuration parameters: AllowForAlignment. +Style/SpaceBeforeFirstArg: + Exclude: + - 'config/initializers/doorkeeper.rb' + - 'config/routes.rb' + - 'features/steps/project/source/browse_files.rb' + - 'features/steps/project/source/markdown_render.rb' + - 'spec/routing/project_routing_spec.rb' + - 'spec/services/delete_user_service_spec.rb' + - 'spec/services/projects/fork_service_spec.rb' + - 'spec/services/system_note_service_spec.rb' + +# Offense count: 129 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. +# SupportedStyles: space, no_space +Style/SpaceInsideBlockBraces: + Enabled: false + +# Offense count: 92 +# Cop supports --auto-correct. +Style/SpaceInsideBrackets: + Enabled: false + +# Offense count: 60 +# Cop supports --auto-correct. +Style/SpaceInsideParens: + Enabled: false # Offense count: 5 # Cop supports --auto-correct. @@ -63,3 +510,89 @@ Style/SpaceInsidePercentLiteralDelimiters: Exclude: - 'lib/event_filter.rb' - 'lib/gitlab/git_access.rb' + +# Offense count: 33 +# Cop supports --auto-correct. +# Configuration parameters: SupportedStyles. +# SupportedStyles: use_perl_names, use_english_names +Style/SpecialGlobalVars: + EnforcedStyle: use_perl_names + +# Offense count: 30 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyle, SupportedStyles. +# SupportedStyles: single_quotes, double_quotes +Style/StringLiteralsInInterpolation: + Enabled: false + +# Offense count: 24 +# Cop supports --auto-correct. +# Configuration parameters: IgnoredMethods. +# IgnoredMethods: respond_to, define_method +Style/SymbolProc: + Enabled: false + +# Offense count: 23 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +# SupportedStyles: comma, consistent_comma, no_comma +Style/TrailingCommaInArguments: + Enabled: false + +# Offense count: 117 +# Cop supports --auto-correct. +# Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. +# SupportedStyles: comma, consistent_comma, no_comma +Style/TrailingCommaInLiteral: + Enabled: false + +# Offense count: 7 +# Cop supports --auto-correct. +# Configuration parameters: AllowNamedUnderscoreVariables. +Style/TrailingUnderscoreVariable: + Exclude: + - 'app/controllers/admin/background_jobs_controller.rb' + - 'app/controllers/invites_controller.rb' + - 'app/controllers/projects/git_http_controller.rb' + - 'app/helpers/tab_helper.rb' + - 'lib/gitlab/force_push_check.rb' + - 'lib/gitlab/logger.rb' + +# Offense count: 89 +# Cop supports --auto-correct. +Style/TrailingWhitespace: + Enabled: false + +# Offense count: 2 +# Cop supports --auto-correct. +# Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. +# Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym +Style/TrivialAccessors: + Exclude: + - 'app/models/external_issue.rb' + - 'lib/gitlab/ldap/person.rb' + +# Offense count: 3 +# Cop supports --auto-correct. +Style/UnlessElse: + Exclude: + - 'lib/api/projects.rb' + - 'lib/gitlab/backend/grack_auth.rb' + - 'lib/gitlab/project_search_results.rb' + +# Offense count: 14 +# Cop supports --auto-correct. +Style/UnneededInterpolation: + Enabled: false + +# Offense count: 8 +# Cop supports --auto-correct. +Style/ZeroLengthPredicate: + Exclude: + - 'app/models/deploy_key.rb' + - 'app/models/network/commit.rb' + - 'app/models/network/graph.rb' + - 'app/models/project_services/asana_service.rb' + - 'app/models/repository.rb' + - 'lib/extracts_path.rb' + - 'lib/gitlab/force_push_check.rb' -- cgit v1.2.1 From c4cbf3effa2c19ebcdcd3943b46ed9296c6e609e Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Tue, 5 Jul 2016 10:33:50 -0600 Subject: Disable two cops as recommended. --- .rubocop.yml | 8 ++++++++ .rubocop_todo.yml | 42 ++++++++++++++++-------------------------- 2 files changed, 24 insertions(+), 26 deletions(-) diff --git a/.rubocop.yml b/.rubocop.yml index ce4287a2796..db0bcfadcf4 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -37,6 +37,10 @@ AllCops: Style/AccessModifierIndentation: Enabled: true +# Check the naming of accessor methods for get_/set_. +Style/AccessorMethodName: + Enabled: false + # Use alias_method instead of alias. Style/Alias: EnforcedStyle: prefer_alias_method @@ -239,6 +243,10 @@ Style/MethodDefParentheses: Style/MethodName: Enabled: true +# Checks for usage of `extend self` in modules. +Style/ModuleFunction: + Enabled: false + # Checks that the closing brace in an array literal is either on the same line # as the last array element, or a new line. Style/MultilineArrayBraceLayout: diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cb6df9d88c2..8204fd82a63 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,12 +1,12 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 8` -# on 2016-07-03 15:32:25 -0600 using RuboCop version 0.41.1. +# on 2016-07-05 10:30:07 -0600 using RuboCop version 0.41.1. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. -# Offense count: 152 +# Offense count: 154 Lint/AmbiguousRegexpLiteral: Enabled: false @@ -52,7 +52,7 @@ Lint/StringConversionInInterpolation: Lint/UnusedBlockArgument: Enabled: false -# Offense count: 125 +# Offense count: 129 # Cop supports --auto-correct. # Configuration parameters: AllowUnusedKeywordArguments, IgnoreEmptyMethods. Lint/UnusedMethodArgument: @@ -114,11 +114,7 @@ Rails/TimeZone: Rails/Validation: Enabled: false -# Offense count: 18 -Style/AccessorMethodName: - Enabled: false - -# Offense count: 208 +# Offense count: 218 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation @@ -139,7 +135,7 @@ Style/AndOr: Style/BarePercentLiterals: Enabled: false -# Offense count: 255 +# Offense count: 256 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: braces, no_braces, context_dependent @@ -176,7 +172,7 @@ Style/CommentAnnotation: Style/ConditionalAssignment: Enabled: false -# Offense count: 762 +# Offense count: 773 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: leading, trailing @@ -194,7 +190,7 @@ Style/EachWithObject: - 'lib/ci/ansi2html.rb' - 'lib/gitlab/import_export/members_mapper.rb' -# Offense count: 29 +# Offense count: 30 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: empty, nil, both @@ -244,7 +240,7 @@ Style/IdenticalConditionalBranches: Style/IfInsideElse: Enabled: false -# Offense count: 178 +# Offense count: 179 # Cop supports --auto-correct. # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: @@ -297,19 +293,13 @@ Style/MethodCallParentheses: - 'spec/helpers/submodule_helper_spec.rb' - 'spec/workers/post_receive_spec.rb' -# Offense count: 9 -# Configuration parameters: EnforcedStyle, SupportedStyles. -# SupportedStyles: module_function, extend_self -Style/ModuleFunction: - Enabled: false - # Offense count: 3 Style/MultilineTernaryOperator: Exclude: - 'lib/banzai/filter/relative_link_filter.rb' - 'spec/support/api_helpers.rb' -# Offense count: 62 +# Offense count: 61 # Cop supports --auto-correct. Style/MutableConstant: Enabled: false @@ -348,7 +338,7 @@ Style/NumericLiteralPrefix: Style/ParallelAssignment: Enabled: false -# Offense count: 201 +# Offense count: 206 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -379,7 +369,7 @@ Style/PerlBackrefs: Style/PredicateName: Enabled: false -# Offense count: 28 +# Offense count: 27 # Cop supports --auto-correct. Style/PreferredHashMethods: Enabled: false @@ -394,7 +384,7 @@ Style/Proc: - 'lib/api/api_guard.rb' - 'spec/initializers/trusted_proxies_spec.rb' -# Offense count: 21 +# Offense count: 20 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: compact, exploded @@ -420,7 +410,7 @@ Style/RedundantException: Style/RedundantFreeze: Enabled: false -# Offense count: 312 +# Offense count: 321 # Cop supports --auto-correct. Style/RedundantSelf: Enabled: false @@ -466,7 +456,7 @@ Style/SingleLineMethods: Style/SpaceAroundEqualsInParameterDefault: Enabled: false -# Offense count: 118 +# Offense count: 119 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: space, no_space @@ -494,7 +484,7 @@ Style/SpaceBeforeFirstArg: Style/SpaceInsideBlockBraces: Enabled: false -# Offense count: 92 +# Offense count: 98 # Cop supports --auto-correct. Style/SpaceInsideBrackets: Enabled: false @@ -558,7 +548,7 @@ Style/TrailingUnderscoreVariable: - 'lib/gitlab/force_push_check.rb' - 'lib/gitlab/logger.rb' -# Offense count: 89 +# Offense count: 88 # Cop supports --auto-correct. Style/TrailingWhitespace: Enabled: false -- cgit v1.2.1 From 9468b07925a1ab47fc485bf6baddaf4e89252b08 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Wed, 13 Jul 2016 12:08:45 -0600 Subject: Resolve feedback. --- .rubocop_todo.yml | 95 ++++++++++++++++++++++++------------------------------- Gemfile | 2 +- Gemfile.lock | 2 +- 3 files changed, 44 insertions(+), 55 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 8204fd82a63..3478d86f1fa 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by # `rubocop --auto-gen-config --exclude-limit 8` -# on 2016-07-05 10:30:07 -0600 using RuboCop version 0.41.1. +# on 2016-07-13 12:03:44 -0600 using RuboCop version 0.41.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -10,21 +10,16 @@ Lint/AmbiguousRegexpLiteral: Enabled: false -# Offense count: 42 +# Offense count: 43 # Configuration parameters: AllowSafeAssignment. Lint/AssignmentInCondition: Enabled: false -# Offense count: 1 -Lint/DuplicateMethods: - Exclude: - - 'lib/gitlab/github_import/branch_formatter.rb' - # Offense count: 14 Lint/HandleExceptions: Enabled: false -# Offense count: 20 +# Offense count: 21 Lint/IneffectiveAccessModifier: Enabled: false @@ -34,7 +29,7 @@ Lint/Loop: - 'app/mailers/notify.rb' - 'lib/gitlab/bitbucket_import/client.rb' -# Offense count: 12 +# Offense count: 15 Lint/ShadowingOuterLocalVariable: Enabled: false @@ -46,7 +41,7 @@ Lint/StringConversionInInterpolation: - 'app/services/system_hooks_service.rb' - 'app/services/system_note_service.rb' -# Offense count: 42 +# Offense count: 44 # Cop supports --auto-correct. # Configuration parameters: IgnoreEmptyBlocks, AllowUnusedKeywordArguments. Lint/UnusedBlockArgument: @@ -81,14 +76,13 @@ Performance/RedundantBlockCall: - 'app/controllers/application_controller.rb' - 'lib/gitlab/backend/shell.rb' -# Offense count: 5 +# Offense count: 4 # Cop supports --auto-correct. Performance/RedundantMatch: Exclude: - 'app/models/external_issue.rb' - 'lib/extracts_path.rb' - 'lib/gitlab/diff/highlight.rb' - - 'lib/gitlab/diff/inline_diff.rb' - 'lib/gitlab/diff/parser.rb' # Offense count: 24 @@ -97,11 +91,11 @@ Performance/RedundantMatch: Performance/RedundantMerge: Enabled: false -# Offense count: 59 +# Offense count: 60 Rails/OutputSafety: Enabled: false -# Offense count: 125 +# Offense count: 128 # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: strict, flexible Rails/TimeZone: @@ -114,7 +108,7 @@ Rails/TimeZone: Rails/Validation: Enabled: false -# Offense count: 218 +# Offense count: 217 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: with_first_parameter, with_fixed_indentation @@ -135,18 +129,19 @@ Style/AndOr: Style/BarePercentLiterals: Enabled: false -# Offense count: 256 +# Offense count: 258 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: braces, no_braces, context_dependent Style/BracesAroundHashParameters: Enabled: false -# Offense count: 4 +# Offense count: 5 Style/CaseEquality: Exclude: - 'app/helpers/auth_helper.rb' - 'app/models/commit.rb' + - 'app/models/protected_branch.rb' - 'app/services/projects/download_service.rb' - 'config/initializers/trusted_proxies.rb' @@ -165,21 +160,21 @@ Style/CommentAnnotation: - 'lib/api/entities.rb' - 'spec/requests/api/project_snippets_spec.rb' -# Offense count: 35 +# Offense count: 34 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, SingleLineConditionsOnly. # SupportedStyles: assign_to_condition, assign_inside_condition Style/ConditionalAssignment: Enabled: false -# Offense count: 773 +# Offense count: 788 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: leading, trailing Style/DotPosition: Enabled: false -# Offense count: 14 +# Offense count: 13 Style/DoubleNegation: Enabled: false @@ -205,7 +200,7 @@ Style/EmptyLiteral: - 'lib/gitlab/fogbugz_import/importer.rb' - 'spec/lib/gitlab/workhorse_spec.rb' -# Offense count: 119 +# Offense count: 123 # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment, ForceEqualSignAlignment. Style/ExtraSpacing: @@ -223,44 +218,36 @@ Style/FormatString: - 'lib/gitlab/version_info.rb' - 'spec/requests/api/issues_spec.rb' -# Offense count: 50 +# Offense count: 48 # Configuration parameters: MinBodyLength. Style/GuardClause: Enabled: false -# Offense count: 9 -Style/IdenticalConditionalBranches: - Exclude: - - 'app/controllers/projects_controller.rb' - - 'app/models/project_services/irker_service.rb' - - 'app/services/merge_requests/refresh_service.rb' - - 'lib/rouge/formatters/html_gitlab.rb' - -# Offense count: 10 +# Offense count: 11 Style/IfInsideElse: Enabled: false -# Offense count: 179 +# Offense count: 177 # Cop supports --auto-correct. # Configuration parameters: MaxLineLength. Style/IfUnlessModifier: Enabled: false -# Offense count: 48 +# Offense count: 50 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_brackets Style/IndentArray: Enabled: false -# Offense count: 85 +# Offense count: 89 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_braces Style/IndentHash: Enabled: false -# Offense count: 11 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: line_count_dependent, lambda, literal @@ -269,6 +256,7 @@ Style/Lambda: - 'app/models/ci/runner.rb' - 'app/models/event.rb' - 'app/models/note.rb' + - 'app/models/notification_setting.rb' - 'config/routes.rb' - 'lib/api/entities.rb' - 'spec/models/concerns/participable_spec.rb' @@ -299,7 +287,7 @@ Style/MultilineTernaryOperator: - 'lib/banzai/filter/relative_link_filter.rb' - 'spec/support/api_helpers.rb' -# Offense count: 61 +# Offense count: 62 # Cop supports --auto-correct. Style/MutableConstant: Enabled: false @@ -314,14 +302,14 @@ Style/NestedParenthesizedCalls: - 'spec/lib/gitlab/email/message/repository_push_spec.rb' - 'spec/services/ci/create_builds_service_spec.rb' -# Offense count: 13 +# Offense count: 12 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles. # SupportedStyles: skip_modifier_ifs, always Style/Next: Enabled: false -# Offense count: 6 +# Offense count: 8 # Cop supports --auto-correct. # Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles. # SupportedOctalStyles: zero_with_o, zero_only @@ -330,6 +318,7 @@ Style/NumericLiteralPrefix: - 'config/initializers/1_settings.rb' - 'config/initializers/secret_token.rb' - 'lib/gitlab/backend/shell.rb' + - 'spec/lib/gitlab/git/hook_spec.rb' - 'spec/support/test_env.rb' - 'spec/tasks/gitlab/backup_rake_spec.rb' @@ -338,7 +327,7 @@ Style/NumericLiteralPrefix: Style/ParallelAssignment: Enabled: false -# Offense count: 206 +# Offense count: 208 # Cop supports --auto-correct. # Configuration parameters: PreferredDelimiters. Style/PercentLiteralDelimiters: @@ -356,12 +345,12 @@ Style/PercentQLiterals: - 'spec/models/project_services/teamcity_service_spec.rb' - 'spec/workers/repository_import_worker_spec.rb' -# Offense count: 14 +# Offense count: 13 # Cop supports --auto-correct. Style/PerlBackrefs: Enabled: false -# Offense count: 30 +# Offense count: 32 # Configuration parameters: NamePrefix, NamePrefixBlacklist, NameWhitelist. # NamePrefix: is_, has_, have_ # NamePrefixBlacklist: is_, has_, have_ @@ -369,7 +358,7 @@ Style/PerlBackrefs: Style/PredicateName: Enabled: false -# Offense count: 27 +# Offense count: 28 # Cop supports --auto-correct. Style/PreferredHashMethods: Enabled: false @@ -405,24 +394,24 @@ Style/RedundantException: Exclude: - 'app/helpers/preferences_helper.rb' -# Offense count: 21 +# Offense count: 23 # Cop supports --auto-correct. Style/RedundantFreeze: Enabled: false -# Offense count: 321 +# Offense count: 377 # Cop supports --auto-correct. Style/RedundantSelf: Enabled: false -# Offense count: 92 +# Offense count: 94 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes. # SupportedStyles: slashes, percent_r, mixed Style/RegexpLiteral: Enabled: false -# Offense count: 14 +# Offense count: 17 # Cop supports --auto-correct. Style/RescueModifier: Enabled: false @@ -477,7 +466,7 @@ Style/SpaceBeforeFirstArg: - 'spec/services/projects/fork_service_spec.rb' - 'spec/services/system_note_service_spec.rb' -# Offense count: 129 +# Offense count: 130 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters. # SupportedStyles: space, no_space @@ -501,7 +490,7 @@ Style/SpaceInsidePercentLiteralDelimiters: - 'lib/event_filter.rb' - 'lib/gitlab/git_access.rb' -# Offense count: 33 +# Offense count: 36 # Cop supports --auto-correct. # Configuration parameters: SupportedStyles. # SupportedStyles: use_perl_names, use_english_names @@ -529,7 +518,7 @@ Style/SymbolProc: Style/TrailingCommaInArguments: Enabled: false -# Offense count: 117 +# Offense count: 114 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. # SupportedStyles: comma, consistent_comma, no_comma @@ -545,10 +534,10 @@ Style/TrailingUnderscoreVariable: - 'app/controllers/invites_controller.rb' - 'app/controllers/projects/git_http_controller.rb' - 'app/helpers/tab_helper.rb' - - 'lib/gitlab/force_push_check.rb' + - 'lib/gitlab/checks/force_push.rb' - 'lib/gitlab/logger.rb' -# Offense count: 88 +# Offense count: 90 # Cop supports --auto-correct. Style/TrailingWhitespace: Enabled: false @@ -570,7 +559,7 @@ Style/UnlessElse: - 'lib/gitlab/backend/grack_auth.rb' - 'lib/gitlab/project_search_results.rb' -# Offense count: 14 +# Offense count: 13 # Cop supports --auto-correct. Style/UnneededInterpolation: Enabled: false @@ -585,4 +574,4 @@ Style/ZeroLengthPredicate: - 'app/models/project_services/asana_service.rb' - 'app/models/repository.rb' - 'lib/extracts_path.rb' - - 'lib/gitlab/force_push_check.rb' + - 'lib/gitlab/checks/force_push.rb' diff --git a/Gemfile b/Gemfile index 0769214a071..7f16e0bd18c 100644 --- a/Gemfile +++ b/Gemfile @@ -299,7 +299,7 @@ group :development, :test do gem 'spring-commands-spinach', '~> 1.1.0' gem 'spring-commands-teaspoon', '~> 0.0.2' - gem 'rubocop', '~> 0.41.1', require: false + gem 'rubocop', '~> 0.41.2', require: false gem 'rubocop-rspec', '~> 1.5.0', require: false gem 'scss_lint', '~> 0.47.0', require: false gem 'simplecov', '~> 0.11.0', require: false diff --git a/Gemfile.lock b/Gemfile.lock index 6f93a534359..cb3a3af47cd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -937,7 +937,7 @@ DEPENDENCIES rqrcode-rails3 (~> 0.1.7) rspec-rails (~> 3.5.0) rspec-retry (~> 0.4.5) - rubocop (~> 0.41.1) + rubocop (~> 0.41.2) rubocop-rspec (~> 1.5.0) ruby-fogbugz (~> 0.2.1) sanitize (~> 2.0) -- cgit v1.2.1 From 82c500a2b69e985cb12ce89964c6ebdd289a0d23 Mon Sep 17 00:00:00 2001 From: Connor Shea Date: Wed, 13 Jul 2016 12:39:14 -0600 Subject: Disable all cops with offenses. --- .rubocop_todo.yml | 183 ++++++++++-------------------------------------------- 1 file changed, 34 insertions(+), 149 deletions(-) diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index 3478d86f1fa..9310e711889 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -1,6 +1,6 @@ # This configuration was generated by -# `rubocop --auto-gen-config --exclude-limit 8` -# on 2016-07-13 12:03:44 -0600 using RuboCop version 0.41.2. +# `rubocop --auto-gen-config --exclude-limit 0` +# on 2016-07-13 12:36:08 -0600 using RuboCop version 0.41.2. # The point is for the user to remove these configuration records # one by one as the offenses are removed from the code base. # Note that changes in the inspected code, or installation of new @@ -25,9 +25,7 @@ Lint/IneffectiveAccessModifier: # Offense count: 2 Lint/Loop: - Exclude: - - 'app/mailers/notify.rb' - - 'lib/gitlab/bitbucket_import/client.rb' + Enabled: false # Offense count: 15 Lint/ShadowingOuterLocalVariable: @@ -36,10 +34,7 @@ Lint/ShadowingOuterLocalVariable: # Offense count: 3 # Cop supports --auto-correct. Lint/StringConversionInInterpolation: - Exclude: - - 'app/models/commit_range.rb' - - 'app/services/system_hooks_service.rb' - - 'app/services/system_note_service.rb' + Enabled: false # Offense count: 44 # Cop supports --auto-correct. @@ -60,30 +55,17 @@ Lint/UselessAccessModifier: # Offense count: 12 # Cop supports --auto-correct. Performance/PushSplat: - Exclude: - - 'app/controllers/projects/refs_controller.rb' - - 'app/helpers/page_layout_helper.rb' - - 'app/models/ability.rb' - - 'app/models/network/graph.rb' - - 'app/models/project_team.rb' - - 'app/models/user.rb' - - 'config/application.rb' + Enabled: false # Offense count: 2 # Cop supports --auto-correct. Performance/RedundantBlockCall: - Exclude: - - 'app/controllers/application_controller.rb' - - 'lib/gitlab/backend/shell.rb' + Enabled: false # Offense count: 4 # Cop supports --auto-correct. Performance/RedundantMatch: - Exclude: - - 'app/models/external_issue.rb' - - 'lib/extracts_path.rb' - - 'lib/gitlab/diff/highlight.rb' - - 'lib/gitlab/diff/parser.rb' + Enabled: false # Offense count: 24 # Cop supports --auto-correct. @@ -138,12 +120,7 @@ Style/BracesAroundHashParameters: # Offense count: 5 Style/CaseEquality: - Exclude: - - 'app/helpers/auth_helper.rb' - - 'app/models/commit.rb' - - 'app/models/protected_branch.rb' - - 'app/services/projects/download_service.rb' - - 'config/initializers/trusted_proxies.rb' + Enabled: false # Offense count: 19 # Cop supports --auto-correct. @@ -155,10 +132,7 @@ Style/ColonMethodCall: # Configuration parameters: Keywords. # Keywords: TODO, FIXME, OPTIMIZE, HACK, REVIEW Style/CommentAnnotation: - Exclude: - - 'app/models/project.rb' - - 'lib/api/entities.rb' - - 'spec/requests/api/project_snippets_spec.rb' + Enabled: false # Offense count: 34 # Cop supports --auto-correct. @@ -167,7 +141,7 @@ Style/CommentAnnotation: Style/ConditionalAssignment: Enabled: false -# Offense count: 788 +# Offense count: 789 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: leading, trailing @@ -180,10 +154,7 @@ Style/DoubleNegation: # Offense count: 3 Style/EachWithObject: - Exclude: - - 'app/models/commit_status.rb' - - 'lib/ci/ansi2html.rb' - - 'lib/gitlab/import_export/members_mapper.rb' + Enabled: false # Offense count: 30 # Cop supports --auto-correct. @@ -195,10 +166,7 @@ Style/EmptyElse: # Offense count: 3 # Cop supports --auto-correct. Style/EmptyLiteral: - Exclude: - - 'features/steps/project/commits/commits.rb' - - 'lib/gitlab/fogbugz_import/importer.rb' - - 'spec/lib/gitlab/workhorse_spec.rb' + Enabled: false # Offense count: 123 # Cop supports --auto-correct. @@ -210,13 +178,7 @@ Style/ExtraSpacing: # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: format, sprintf, percent Style/FormatString: - Exclude: - - 'app/models/ci/pipeline.rb' - - 'app/services/gravatar_service.rb' - - 'config/initializers/rack_lineprof.rb' - - 'lib/ci/version_info.rb' - - 'lib/gitlab/version_info.rb' - - 'spec/requests/api/issues_spec.rb' + Enabled: false # Offense count: 48 # Configuration parameters: MinBodyLength. @@ -233,7 +195,7 @@ Style/IfInsideElse: Style/IfUnlessModifier: Enabled: false -# Offense count: 50 +# Offense count: 52 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyle, SupportedStyles, IndentationWidth. # SupportedStyles: special_inside_parentheses, consistent, align_brackets @@ -252,40 +214,21 @@ Style/IndentHash: # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: line_count_dependent, lambda, literal Style/Lambda: - Exclude: - - 'app/models/ci/runner.rb' - - 'app/models/event.rb' - - 'app/models/note.rb' - - 'app/models/notification_setting.rb' - - 'config/routes.rb' - - 'lib/api/entities.rb' - - 'spec/models/concerns/participable_spec.rb' + Enabled: false # Offense count: 6 # Cop supports --auto-correct. Style/LineEndConcatenation: - Exclude: - - 'app/helpers/preferences_helper.rb' - - 'app/helpers/tree_helper.rb' - - 'app/models/merge_request.rb' - - 'app/models/user.rb' - - 'spec/lib/gitlab/gfm/reference_rewriter_spec.rb' + Enabled: false # Offense count: 13 # Cop supports --auto-correct. Style/MethodCallParentheses: - Exclude: - - 'lib/api/helpers.rb' - - 'lib/ci/ansi2html.rb' - - 'spec/features/dashboard/datetime_on_tooltips_spec.rb' - - 'spec/helpers/submodule_helper_spec.rb' - - 'spec/workers/post_receive_spec.rb' + Enabled: false # Offense count: 3 Style/MultilineTernaryOperator: - Exclude: - - 'lib/banzai/filter/relative_link_filter.rb' - - 'spec/support/api_helpers.rb' + Enabled: false # Offense count: 62 # Cop supports --auto-correct. @@ -295,12 +238,7 @@ Style/MutableConstant: # Offense count: 10 # Cop supports --auto-correct. Style/NestedParenthesizedCalls: - Exclude: - - 'app/helpers/commits_helper.rb' - - 'app/workers/irker_worker.rb' - - 'spec/lib/gitlab/ci/build/artifacts/metadata/entry_spec.rb' - - 'spec/lib/gitlab/email/message/repository_push_spec.rb' - - 'spec/services/ci/create_builds_service_spec.rb' + Enabled: false # Offense count: 12 # Cop supports --auto-correct. @@ -314,13 +252,7 @@ Style/Next: # Configuration parameters: EnforcedOctalStyle, SupportedOctalStyles. # SupportedOctalStyles: zero_with_o, zero_only Style/NumericLiteralPrefix: - Exclude: - - 'config/initializers/1_settings.rb' - - 'config/initializers/secret_token.rb' - - 'lib/gitlab/backend/shell.rb' - - 'spec/lib/gitlab/git/hook_spec.rb' - - 'spec/support/test_env.rb' - - 'spec/tasks/gitlab/backup_rake_spec.rb' + Enabled: false # Offense count: 29 # Cop supports --auto-correct. @@ -338,12 +270,7 @@ Style/PercentLiteralDelimiters: # Configuration parameters: EnforcedStyle, SupportedStyles. # SupportedStyles: lower_case_q, upper_case_q Style/PercentQLiterals: - Exclude: - - 'spec/helpers/gitlab_markdown_helper_spec.rb' - - 'spec/lib/gitlab/diff/highlight_spec.rb' - - 'spec/models/project_services/bamboo_service_spec.rb' - - 'spec/models/project_services/teamcity_service_spec.rb' - - 'spec/workers/repository_import_worker_spec.rb' + Enabled: false # Offense count: 13 # Cop supports --auto-correct. @@ -366,12 +293,7 @@ Style/PreferredHashMethods: # Offense count: 6 # Cop supports --auto-correct. Style/Proc: - Exclude: - - 'app/mailers/base_mailer.rb' - - 'app/models/label.rb' - - 'app/models/service.rb' - - 'lib/api/api_guard.rb' - - 'spec/initializers/trusted_proxies_spec.rb' + Enabled: false # Offense count: 20 # Cop supports --auto-correct. @@ -383,16 +305,12 @@ Style/RaiseArgs: # Offense count: 3 # Cop supports --auto-correct. Style/RedundantBegin: - Exclude: - - 'app/models/ci/build.rb' - - 'app/models/merge_request.rb' - - 'app/services/projects/import_service.rb' + Enabled: false # Offense count: 1 # Cop supports --auto-correct. Style/RedundantException: - Exclude: - - 'app/helpers/preferences_helper.rb' + Enabled: false # Offense count: 23 # Cop supports --auto-correct. @@ -419,24 +337,19 @@ Style/RescueModifier: # Offense count: 2 # Cop supports --auto-correct. Style/SelfAssignment: - Exclude: - - 'app/services/notification_service.rb' - - 'lib/api/runners.rb' + Enabled: false # Offense count: 2 # Configuration parameters: Methods. # Methods: {"reduce"=>["a", "e"]}, {"inject"=>["a", "e"]} Style/SingleLineBlockParams: - Exclude: - - 'app/models/commit.rb' - - 'spec/support/services_shared_context.rb' + Enabled: false # Offense count: 50 # Cop supports --auto-correct. # Configuration parameters: AllowIfMethodIsEmpty. Style/SingleLineMethods: - Exclude: - - 'lib/ci/ansi2html.rb' + Enabled: false # Offense count: 14 # Cop supports --auto-correct. @@ -456,15 +369,7 @@ Style/SpaceBeforeBlockBraces: # Cop supports --auto-correct. # Configuration parameters: AllowForAlignment. Style/SpaceBeforeFirstArg: - Exclude: - - 'config/initializers/doorkeeper.rb' - - 'config/routes.rb' - - 'features/steps/project/source/browse_files.rb' - - 'features/steps/project/source/markdown_render.rb' - - 'spec/routing/project_routing_spec.rb' - - 'spec/services/delete_user_service_spec.rb' - - 'spec/services/projects/fork_service_spec.rb' - - 'spec/services/system_note_service_spec.rb' + Enabled: false # Offense count: 130 # Cop supports --auto-correct. @@ -486,9 +391,7 @@ Style/SpaceInsideParens: # Offense count: 5 # Cop supports --auto-correct. Style/SpaceInsidePercentLiteralDelimiters: - Exclude: - - 'lib/event_filter.rb' - - 'lib/gitlab/git_access.rb' + Enabled: false # Offense count: 36 # Cop supports --auto-correct. @@ -518,7 +421,7 @@ Style/SymbolProc: Style/TrailingCommaInArguments: Enabled: false -# Offense count: 114 +# Offense count: 113 # Cop supports --auto-correct. # Configuration parameters: EnforcedStyleForMultiline, SupportedStyles. # SupportedStyles: comma, consistent_comma, no_comma @@ -529,13 +432,7 @@ Style/TrailingCommaInLiteral: # Cop supports --auto-correct. # Configuration parameters: AllowNamedUnderscoreVariables. Style/TrailingUnderscoreVariable: - Exclude: - - 'app/controllers/admin/background_jobs_controller.rb' - - 'app/controllers/invites_controller.rb' - - 'app/controllers/projects/git_http_controller.rb' - - 'app/helpers/tab_helper.rb' - - 'lib/gitlab/checks/force_push.rb' - - 'lib/gitlab/logger.rb' + Enabled: false # Offense count: 90 # Cop supports --auto-correct. @@ -547,17 +444,12 @@ Style/TrailingWhitespace: # Configuration parameters: ExactNameMatch, AllowPredicates, AllowDSLWriters, IgnoreClassMethods, Whitelist. # Whitelist: to_ary, to_a, to_c, to_enum, to_h, to_hash, to_i, to_int, to_io, to_open, to_path, to_proc, to_r, to_regexp, to_str, to_s, to_sym Style/TrivialAccessors: - Exclude: - - 'app/models/external_issue.rb' - - 'lib/gitlab/ldap/person.rb' + Enabled: false # Offense count: 3 # Cop supports --auto-correct. Style/UnlessElse: - Exclude: - - 'lib/api/projects.rb' - - 'lib/gitlab/backend/grack_auth.rb' - - 'lib/gitlab/project_search_results.rb' + Enabled: false # Offense count: 13 # Cop supports --auto-correct. @@ -567,11 +459,4 @@ Style/UnneededInterpolation: # Offense count: 8 # Cop supports --auto-correct. Style/ZeroLengthPredicate: - Exclude: - - 'app/models/deploy_key.rb' - - 'app/models/network/commit.rb' - - 'app/models/network/graph.rb' - - 'app/models/project_services/asana_service.rb' - - 'app/models/repository.rb' - - 'lib/extracts_path.rb' - - 'lib/gitlab/checks/force_push.rb' + Enabled: false -- cgit v1.2.1 From d7c591915893c8c572e9135db4ec27dc174823fd Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Wed, 13 Jul 2016 19:17:17 -0700 Subject: Revert "Optimistic locking for Issue and Merge Requests" This reverts commit c39356998b1850f3dc26fe0b987cb419c1d1afb4. --- app/controllers/projects/issues_controller.rb | 6 +----- .../projects/merge_requests_controller.rb | 5 +---- app/models/concerns/issuable.rb | 6 ------ app/views/shared/issuable/_form.html.haml | 9 --------- db/migrate/20160707104333_add_lock_to_issuables.rb | 17 ----------------- db/schema.rb | 22 ++++++++++------------ features/project/merge_requests.feature | 2 +- spec/features/issues_spec.rb | 11 ----------- spec/features/merge_requests/edit_mr_spec.rb | 11 ----------- 9 files changed, 13 insertions(+), 76 deletions(-) delete mode 100644 db/migrate/20160707104333_add_lock_to_issuables.rb diff --git a/app/controllers/projects/issues_controller.rb b/app/controllers/projects/issues_controller.rb index f7ada5cfee4..b6e80762e3c 100644 --- a/app/controllers/projects/issues_controller.rb +++ b/app/controllers/projects/issues_controller.rb @@ -119,10 +119,6 @@ class Projects::IssuesController < Projects::ApplicationController render json: @issue.to_json(include: { milestone: {}, assignee: { methods: :avatar_url }, labels: { methods: :text_color } }) end end - - rescue ActiveRecord::StaleObjectError - @conflict = true - render :edit end def referenced_merge_requests @@ -220,7 +216,7 @@ class Projects::IssuesController < Projects::ApplicationController def issue_params params.require(:issue).permit( :title, :assignee_id, :position, :description, :confidential, - :milestone_id, :due_date, :state_event, :task_num, :lock_version, label_ids: [] + :milestone_id, :due_date, :state_event, :task_num, label_ids: [] ) end diff --git a/app/controllers/projects/merge_requests_controller.rb b/app/controllers/projects/merge_requests_controller.rb index 2deb7959700..df659bb8c3b 100644 --- a/app/controllers/projects/merge_requests_controller.rb +++ b/app/controllers/projects/merge_requests_controller.rb @@ -196,9 +196,6 @@ class Projects::MergeRequestsController < Projects::ApplicationController else render "edit" end - rescue ActiveRecord::StaleObjectError - @conflict = true - render :edit end def remove_wip @@ -427,7 +424,7 @@ class Projects::MergeRequestsController < Projects::ApplicationController :title, :assignee_id, :source_project_id, :source_branch, :target_project_id, :target_branch, :milestone_id, :state_event, :description, :task_num, :force_remove_source_branch, - :lock_version, label_ids: [] + label_ids: [] ) end diff --git a/app/models/concerns/issuable.rb b/app/models/concerns/issuable.rb index fb49bd7dd64..acb6f5a2998 100644 --- a/app/models/concerns/issuable.rb +++ b/app/models/concerns/issuable.rb @@ -87,12 +87,6 @@ module Issuable User.find(assignee_id_was).update_cache_counts if assignee_id_was assignee.update_cache_counts if assignee end - - # We want to use optimistic lock for cases when only title or description are involved - # http://api.rubyonrails.org/classes/ActiveRecord/Locking/Optimistic.html - def locking_enabled? - title_changed? || description_changed? - end end module ClassMethods diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index 98bbb12eaec..c30bdb0ae91 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -1,12 +1,5 @@ = form_errors(issuable) -- if @conflict - .alert.alert-danger - Someone edited the #{issuable.class.model_name.human.downcase} the same time you did. - Please check out - = link_to "the #{issuable.class.model_name.human.downcase}", polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), target: "_blank" - and make sure your changes will not unintentionally remove theirs - .form-group = f.label :title, class: 'control-label' .col-sm-10 @@ -156,5 +149,3 @@ = link_to 'Delete', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), data: { confirm: "#{issuable.class.name.titleize} will be removed! Are you sure?" }, method: :delete, class: 'btn btn-danger btn-grouped' = link_to 'Cancel', polymorphic_path([@project.namespace.becomes(Namespace), @project, issuable]), class: 'btn btn-grouped btn-cancel' - -= f.hidden_field :lock_version diff --git a/db/migrate/20160707104333_add_lock_to_issuables.rb b/db/migrate/20160707104333_add_lock_to_issuables.rb deleted file mode 100644 index cb516672800..00000000000 --- a/db/migrate/20160707104333_add_lock_to_issuables.rb +++ /dev/null @@ -1,17 +0,0 @@ -# See http://doc.gitlab.com/ce/development/migration_style_guide.html -# for more information on how to write migrations for GitLab. - -class AddLockToIssuables < ActiveRecord::Migration - include Gitlab::Database::MigrationHelpers - disable_ddl_transaction! - - def up - add_column_with_default :issues, :lock_version, :integer, default: 0 - add_column_with_default :merge_requests, :lock_version, :integer, default: 0 - end - - def down - remove_column :issues, :lock_version - remove_column :merge_requests, :lock_version - end -end diff --git a/db/schema.rb b/db/schema.rb index f24e47b85b2..8c12898eec9 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -70,11 +70,11 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.string "recaptcha_site_key" t.string "recaptcha_private_key" t.integer "metrics_port", default: 8089 + t.boolean "akismet_enabled", default: false + t.string "akismet_api_key" t.integer "metrics_sample_interval", default: 15 t.boolean "sentry_enabled", default: false t.string "sentry_dsn" - t.boolean "akismet_enabled", default: false - t.string "akismet_api_key" t.boolean "email_author_in_body", default: false t.integer "default_group_visibility" t.boolean "repository_checks_enabled", default: false @@ -84,10 +84,10 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.string "health_check_access_token" t.boolean "send_user_confirmation_email", default: false t.integer "container_registry_token_expire_delay", default: 5 + t.boolean "user_default_external", default: false, null: false t.text "after_sign_up_text" t.string "repository_storage", default: "default" t.string "enabled_git_access_protocol" - t.boolean "user_default_external", default: false, null: false end create_table "audit_events", force: :cascade do |t| @@ -165,8 +165,8 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.text "artifacts_metadata" t.integer "erased_by_id" t.datetime "erased_at" - t.datetime "artifacts_expire_at" t.string "environment" + t.datetime "artifacts_expire_at" t.integer "artifacts_size" end @@ -481,11 +481,10 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.string "state" t.integer "iid" t.integer "updated_by_id" - t.integer "moved_to_id" t.boolean "confidential", default: false t.datetime "deleted_at" t.date "due_date" - t.integer "lock_version", default: 0, null: false + t.integer "moved_to_id" end add_index "issues", ["assignee_id"], name: "index_issues_on_assignee_id", using: :btree @@ -625,7 +624,6 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.integer "merge_user_id" t.string "merge_commit_sha" t.datetime "deleted_at" - t.integer "lock_version", default: 0, null: false end add_index "merge_requests", ["assignee_id"], name: "index_merge_requests_on_assignee_id", using: :btree @@ -775,10 +773,10 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.integer "user_id", null: false t.string "token", null: false t.string "name", null: false - t.boolean "revoked", default: false - t.datetime "expires_at" t.datetime "created_at", null: false t.datetime "updated_at", null: false + t.boolean "revoked", default: false + t.datetime "expires_at" end add_index "personal_access_tokens", ["token"], name: "index_personal_access_tokens_on_token", unique: true, using: :btree @@ -898,9 +896,9 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.string "type" t.string "title" t.integer "project_id" - t.datetime "created_at", null: false - t.datetime "updated_at", null: false - t.boolean "active", null: false + t.datetime "created_at" + t.datetime "updated_at" + t.boolean "active", default: false, null: false t.text "properties" t.boolean "template", default: false t.boolean "push_events", default: true diff --git a/features/project/merge_requests.feature b/features/project/merge_requests.feature index 8176ec5ab45..21768c15c17 100644 --- a/features/project/merge_requests.feature +++ b/features/project/merge_requests.feature @@ -89,7 +89,7 @@ Feature: Project Merge Requests Then The list should be sorted by "Oldest updated" @javascript - Scenario: Visiting Merge Requests from a different Project after sorting + Scenario: Visiting Merge Requests from a differente Project after sorting Given I visit project "Shop" merge requests page And I sort the list by "Oldest updated" And I visit dashboard merge requests page diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index cfe6349a1a1..d51c9abea19 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -121,17 +121,6 @@ describe 'Issues', feature: true do expect(page).to have_content date.to_s(:medium) end end - - it 'warns about version conflict' do - issue.update(title: "New title") - - fill_in 'issue_title', with: 'bug 345' - fill_in 'issue_description', with: 'bug description' - - click_button 'Save changes' - - expect(page).to have_content 'Someone edited the issue the same time you did' - end end end diff --git a/spec/features/merge_requests/edit_mr_spec.rb b/spec/features/merge_requests/edit_mr_spec.rb index 8ad884492d1..9e007ab7635 100644 --- a/spec/features/merge_requests/edit_mr_spec.rb +++ b/spec/features/merge_requests/edit_mr_spec.rb @@ -17,16 +17,5 @@ feature 'Edit Merge Request', feature: true do it 'form should have class js-quick-submit' do expect(page).to have_selector('.js-quick-submit') end - - it 'warns about version conflict' do - merge_request.update(title: "New title") - - fill_in 'merge_request_title', with: 'bug 345' - fill_in 'merge_request_description', with: 'bug description' - - click_button 'Save changes' - - expect(page).to have_content 'Someone edited the merge request the same time you did' - end end end -- cgit v1.2.1 From 4b33c4c6d1aa529ec22606995123cfa3a151ccee Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Mon, 11 Jul 2016 13:00:22 +0530 Subject: Load Javascript U2F library selectively. 1. Only on supported Chrome versions 2. Mainly, this lets us simplify the javascript-based U2F check to `window.u2f`, where `window.u2f` can either be loaded from the GitLab server (for Chrome) or from the Firefox extension. 3. This is a better way to provide browser detection for U2F. --- CHANGELOG | 1 + app/assets/javascripts/application.js.coffee | 1 - app/assets/javascripts/u2f/util.js.coffee.erb | 14 +------------- app/controllers/application_controller.rb | 4 ---- app/controllers/concerns/authenticates_with_two_factor.rb | 3 +-- app/controllers/profiles/two_factor_auths_controller.rb | 3 +-- app/helpers/u2f_helper.rb | 5 +++++ app/views/devise/sessions/two_factor.html.haml | 4 ++++ app/views/profiles/two_factor_auths/show.html.haml | 4 ++++ config/application.rb | 1 + 10 files changed, 18 insertions(+), 22 deletions(-) create mode 100644 app/helpers/u2f_helper.rb diff --git a/CHANGELOG b/CHANGELOG index 0eb7595fbfa..cd66281fddc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -16,6 +16,7 @@ v 8.10.0 (unreleased) - Make images fit to the size of the viewport !4810 - Fix check for New Branch button on Issue page !4630 (winniehell) - Fix MR-auto-close text added to description. !4836 + - Support U2F devices in Firefox. !5177 - Fix issue, preventing users w/o push access to sort tags !5105 (redetection) - Add Spring EmojiOne updates. - Add syntax for multiline blockquote using `>>>` fence !3954 diff --git a/app/assets/javascripts/application.js.coffee b/app/assets/javascripts/application.js.coffee index 64da503c35f..4393fece329 100644 --- a/app/assets/javascripts/application.js.coffee +++ b/app/assets/javascripts/application.js.coffee @@ -54,7 +54,6 @@ #= require_directory ./u2f #= require_directory . #= require fuzzaldrin-plus -#= require u2f window.slugify = (text) -> text.replace(/[^-a-zA-Z0-9]+/g, '_').toLowerCase() diff --git a/app/assets/javascripts/u2f/util.js.coffee.erb b/app/assets/javascripts/u2f/util.js.coffee.erb index d59341c38b9..be1d3286b01 100644 --- a/app/assets/javascripts/u2f/util.js.coffee.erb +++ b/app/assets/javascripts/u2f/util.js.coffee.erb @@ -1,15 +1,3 @@ -# Helper class for U2F (universal 2nd factor) device registration and authentication. - class @U2FUtil @isU2FSupported: -> - if @testMode - true - else - gon.u2f.browser_supports_u2f - - @enableTestMode: -> - @testMode = true - -<% if Rails.env.test? %> -U2FUtil.enableTestMode(); -<% end %> + window.u2f diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 9cc31620d9f..a1004d9bcea 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -344,10 +344,6 @@ class ApplicationController < ActionController::Base session[:skip_tfa] && session[:skip_tfa] > Time.current end - def browser_supports_u2f? - browser.chrome? && browser.version.to_i >= 41 && !browser.device.mobile? - end - def redirect_to_home_page_url? # If user is not signed-in and tries to access root_path - redirect him to landing page # Don't redirect to the default URL to prevent endless redirections diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index 998b8adc411..0c755894790 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -80,8 +80,7 @@ module AuthenticatesWithTwoFactor challenges = sign_requests.map(&:challenge) session[:challenges] = challenges gon.push(u2f: { challenges: challenges, app_id: u2f_app_id, - sign_requests: sign_requests, - browser_supports_u2f: browser_supports_u2f? }) + sign_requests: sign_requests }) end end end diff --git a/app/controllers/profiles/two_factor_auths_controller.rb b/app/controllers/profiles/two_factor_auths_controller.rb index 6a358fdcc05..e37e9e136db 100644 --- a/app/controllers/profiles/two_factor_auths_controller.rb +++ b/app/controllers/profiles/two_factor_auths_controller.rb @@ -100,7 +100,6 @@ class Profiles::TwoFactorAuthsController < Profiles::ApplicationController gon.push(u2f: { challenges: session[:challenges], app_id: u2f_app_id, register_requests: registration_requests, - sign_requests: sign_requests, - browser_supports_u2f: browser_supports_u2f? }) + sign_requests: sign_requests }) end end diff --git a/app/helpers/u2f_helper.rb b/app/helpers/u2f_helper.rb new file mode 100644 index 00000000000..143b4ca6b51 --- /dev/null +++ b/app/helpers/u2f_helper.rb @@ -0,0 +1,5 @@ +module U2fHelper + def inject_u2f_api? + browser.chrome? && browser.version.to_i >= 41 && !browser.device.mobile? + end +end diff --git a/app/views/devise/sessions/two_factor.html.haml b/app/views/devise/sessions/two_factor.html.haml index a373f61bd3c..dbf4d699d01 100644 --- a/app/views/devise/sessions/two_factor.html.haml +++ b/app/views/devise/sessions/two_factor.html.haml @@ -1,3 +1,7 @@ +- content_for :page_specific_javascripts do + - if inject_u2f_api? + = page_specific_javascript_tag('u2f.js') + %div .login-box .login-heading diff --git a/app/views/profiles/two_factor_auths/show.html.haml b/app/views/profiles/two_factor_auths/show.html.haml index 5890456bee2..0e9a80a6267 100644 --- a/app/views/profiles/two_factor_auths/show.html.haml +++ b/app/views/profiles/two_factor_auths/show.html.haml @@ -2,6 +2,10 @@ - header_title "Two-Factor Authentication", profile_two_factor_auth_path = render 'profiles/head' +- content_for :page_specific_javascripts do + - if inject_u2f_api? + = page_specific_javascript_tag('u2f.js') + .row.prepend-top-default .col-lg-3 %h4.prepend-top-0 diff --git a/config/application.rb b/config/application.rb index 21e7cc7b6e8..5f7b6a3c049 100644 --- a/config/application.rb +++ b/config/application.rb @@ -87,6 +87,7 @@ module Gitlab config.assets.precompile << "profile/application.js" config.assets.precompile << "lib/utils/*.js" config.assets.precompile << "lib/*.js" + config.assets.precompile << "u2f.js" # Version of your assets, change this if you want to expire all your assets config.assets.version = '1.0' -- cgit v1.2.1 From 3572582dd2568cd473676563077ab3985b9803f7 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Mon, 11 Jul 2016 13:02:24 +0530 Subject: Use a single challenge for U2F authentication. 1. According to the spec, either we have a single challenge with a number of `signRequests`, or a number of `signRequests`, each with it's own challenge. 2. Previously, we had both these - per-request challenges, as well as a single extra challenge. 3. This commit changes this so that the per-request challenges are removed, leaving only a single challenge, as per the v1.1 U2F API. 4. The existing implementation didn't work in Firefox, because the Firefox (extension) implementation is less flexible with regard to the inputs. 5. Fix teaspoon specs. 6. References: https://fidoalliance.org/specs/fido-u2f-v1.0-nfc-bt-amendment-20150514/fido-u2f-javascript-api.html#h2_background --- app/assets/javascripts/u2f/authenticate.js.coffee | 15 ++++++++++++--- app/controllers/concerns/authenticates_with_two_factor.rb | 7 +++---- spec/javascripts/u2f/authenticate_spec.coffee | 3 +-- spec/javascripts/u2f/register_spec.js.coffee | 1 - spec/support/fake_u2f_device.rb | 4 ++-- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/app/assets/javascripts/u2f/authenticate.js.coffee b/app/assets/javascripts/u2f/authenticate.js.coffee index 6deb902c8de..be10e911c83 100644 --- a/app/assets/javascripts/u2f/authenticate.js.coffee +++ b/app/assets/javascripts/u2f/authenticate.js.coffee @@ -6,8 +6,17 @@ class @U2FAuthenticate constructor: (@container, u2fParams) -> @appId = u2fParams.app_id - @challenges = u2fParams.challenges - @signRequests = u2fParams.sign_requests + @challenge = u2fParams.challenge + + # The U2F Javascript API v1.1 requires a single challenge, with _no + # challenges per-request_. + # + # The U2F Javascript API v1.0 requires a challenge per-request, which + # is done by copying the single challenge into every request. + # + # In either case, we don't need the per-request challenges that the server + # has generated, so we can remove them. + @signRequests = u2fParams.sign_requests.map (request) -> _(request).omit('challenge') start: () => if U2FUtil.isU2FSupported() @@ -16,7 +25,7 @@ class @U2FAuthenticate @renderNotSupported() authenticate: () => - u2f.sign(@appId, @challenges, @signRequests, (response) => + u2f.sign(@appId, @challenge, @signRequests, (response) => if response.errorCode error = new U2FError(response.errorCode) @renderError(error); diff --git a/app/controllers/concerns/authenticates_with_two_factor.rb b/app/controllers/concerns/authenticates_with_two_factor.rb index 0c755894790..ba07cea569c 100644 --- a/app/controllers/concerns/authenticates_with_two_factor.rb +++ b/app/controllers/concerns/authenticates_with_two_factor.rb @@ -57,7 +57,7 @@ module AuthenticatesWithTwoFactor # Authenticate using the response from a U2F (universal 2nd factor) device def authenticate_with_two_factor_via_u2f(user) - if U2fRegistration.authenticate(user, u2f_app_id, user_params[:device_response], session[:challenges]) + if U2fRegistration.authenticate(user, u2f_app_id, user_params[:device_response], session[:challenge]) # Remove any lingering user data from login session.delete(:otp_user_id) session.delete(:challenges) @@ -77,9 +77,8 @@ module AuthenticatesWithTwoFactor if key_handles.present? sign_requests = u2f.authentication_requests(key_handles) - challenges = sign_requests.map(&:challenge) - session[:challenges] = challenges - gon.push(u2f: { challenges: challenges, app_id: u2f_app_id, + session[:challenge] ||= u2f.challenge + gon.push(u2f: { challenge: session[:challenge], app_id: u2f_app_id, sign_requests: sign_requests }) end end diff --git a/spec/javascripts/u2f/authenticate_spec.coffee b/spec/javascripts/u2f/authenticate_spec.coffee index e8a2892d678..8ffeda11704 100644 --- a/spec/javascripts/u2f/authenticate_spec.coffee +++ b/spec/javascripts/u2f/authenticate_spec.coffee @@ -5,13 +5,12 @@ #= require ./mock_u2f_device describe 'U2FAuthenticate', -> - U2FUtil.enableTestMode() fixture.load('u2f/authenticate') beforeEach -> @u2fDevice = new MockU2FDevice @container = $("#js-authenticate-u2f") - @component = new U2FAuthenticate(@container, {}, "token") + @component = new U2FAuthenticate(@container, {sign_requests: []}, "token") @component.start() it 'allows authenticating via a U2F device', -> diff --git a/spec/javascripts/u2f/register_spec.js.coffee b/spec/javascripts/u2f/register_spec.js.coffee index 0858abeca1a..87dc769792b 100644 --- a/spec/javascripts/u2f/register_spec.js.coffee +++ b/spec/javascripts/u2f/register_spec.js.coffee @@ -5,7 +5,6 @@ #= require ./mock_u2f_device describe 'U2FRegister', -> - U2FUtil.enableTestMode() fixture.load('u2f/register') beforeEach -> diff --git a/spec/support/fake_u2f_device.rb b/spec/support/fake_u2f_device.rb index 553fe9f1fbc..f550e9a0160 100644 --- a/spec/support/fake_u2f_device.rb +++ b/spec/support/fake_u2f_device.rb @@ -18,8 +18,8 @@ class FakeU2fDevice def respond_to_u2f_authentication app_id = @page.evaluate_script('gon.u2f.app_id') - challenges = @page.evaluate_script('gon.u2f.challenges') - json_response = u2f_device(app_id).sign_response(challenges[0]) + challenge = @page.evaluate_script('gon.u2f.challenge') + json_response = u2f_device(app_id).sign_response(challenge) @page.execute_script(" u2f.sign = function(appId, challenges, signRequests, callback) { -- cgit v1.2.1 From 341d8bc3f7fbe3763250af1e89020b81dad34bb8 Mon Sep 17 00:00:00 2001 From: Timothy Andrew Date: Mon, 11 Jul 2016 13:23:02 +0530 Subject: Add a U2F feature spec for multiple devices owned by the same user. 1. This scenario was previously tested for the registration flow, but not authentication. --- app/assets/javascripts/u2f/authenticate.js.coffee | 13 +++-- app/assets/javascripts/u2f/util.js.coffee | 3 ++ app/assets/javascripts/u2f/util.js.coffee.erb | 3 -- app/views/devise/sessions/two_factor.html.haml | 4 +- app/views/profiles/two_factor_auths/show.html.haml | 4 +- spec/features/u2f_spec.rb | 55 +++++++++++++++++----- 6 files changed, 59 insertions(+), 23 deletions(-) create mode 100644 app/assets/javascripts/u2f/util.js.coffee delete mode 100644 app/assets/javascripts/u2f/util.js.coffee.erb diff --git a/app/assets/javascripts/u2f/authenticate.js.coffee b/app/assets/javascripts/u2f/authenticate.js.coffee index be10e911c83..918c0a560fd 100644 --- a/app/assets/javascripts/u2f/authenticate.js.coffee +++ b/app/assets/javascripts/u2f/authenticate.js.coffee @@ -8,14 +8,17 @@ class @U2FAuthenticate @appId = u2fParams.app_id @challenge = u2fParams.challenge - # The U2F Javascript API v1.1 requires a single challenge, with _no - # challenges per-request_. - # - # The U2F Javascript API v1.0 requires a challenge per-request, which - # is done by copying the single challenge into every request. + # The U2F Javascript API v1.1 requires a single challenge, with + # _no challenges per-request_. The U2F Javascript API v1.0 requires a + # challenge per-request, which is done by copying the single challenge + # into every request. # # In either case, we don't need the per-request challenges that the server # has generated, so we can remove them. + # + # Note: The server library fixes this behaviour in (unreleased) version 1.0.0. + # This can be removed once we upgrade. + # https://github.com/castle/ruby-u2f/commit/103f428071a81cd3d5f80c2e77d522d5029946a4 @signRequests = u2fParams.sign_requests.map (request) -> _(request).omit('challenge') start: () => diff --git a/app/assets/javascripts/u2f/util.js.coffee b/app/assets/javascripts/u2f/util.js.coffee new file mode 100644 index 00000000000..5ef324f609d --- /dev/null +++ b/app/assets/javascripts/u2f/util.js.coffee @@ -0,0 +1,3 @@ +class @U2FUtil + @isU2FSupported: -> + window.u2f diff --git a/app/assets/javascripts/u2f/util.js.coffee.erb b/app/assets/javascripts/u2f/util.js.coffee.erb deleted file mode 100644 index be1d3286b01..00000000000 --- a/app/assets/javascripts/u2f/util.js.coffee.erb +++ /dev/null @@ -1,3 +0,0 @@ -class @U2FUtil - @isU2FSupported: -> - window.u2f diff --git a/app/views/devise/sessions/two_factor.html.haml b/app/views/devise/sessions/two_factor.html.haml index dbf4d699d01..4debd3d608f 100644 --- a/app/views/devise/sessions/two_factor.html.haml +++ b/app/views/devise/sessions/two_factor.html.haml @@ -1,5 +1,5 @@ -- content_for :page_specific_javascripts do - - if inject_u2f_api? +- if inject_u2f_api? + - content_for :page_specific_javascripts do = page_specific_javascript_tag('u2f.js') %div diff --git a/app/views/profiles/two_factor_auths/show.html.haml b/app/views/profiles/two_factor_auths/show.html.haml index 0e9a80a6267..355bfcf1d62 100644 --- a/app/views/profiles/two_factor_auths/show.html.haml +++ b/app/views/profiles/two_factor_auths/show.html.haml @@ -2,8 +2,8 @@ - header_title "Two-Factor Authentication", profile_two_factor_auth_path = render 'profiles/head' -- content_for :page_specific_javascripts do - - if inject_u2f_api? +- if inject_u2f_api? + - content_for :page_specific_javascripts do = page_specific_javascript_tag('u2f.js') .row.prepend-top-default diff --git a/spec/features/u2f_spec.rb b/spec/features/u2f_spec.rb index 14613754f74..9335f5bf120 100644 --- a/spec/features/u2f_spec.rb +++ b/spec/features/u2f_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: true, js: true do + before { allow_any_instance_of(U2fHelper).to receive(:inject_u2f_api?).and_return(true) } + def register_u2f_device(u2f_device = nil) u2f_device ||= FakeU2fDevice.new(page) u2f_device.respond_to_u2f_registration @@ -208,21 +210,52 @@ feature 'Using U2F (Universal 2nd Factor) Devices for Authentication', feature: expect(page.body).to match('Authentication via U2F device failed') end end - end - describe "when two-factor authentication is disabled" do - let(:user) { create(:user) } + describe "when more than one device has been registered by the same user" do + it "allows logging in with either device" do + # Register first device + user = login_as(:user) + user.update_attribute(:otp_required_for_login, true) + visit profile_two_factor_auth_path + expect(page).to have_content("Your U2F device needs to be set up.") + first_device = register_u2f_device + + # Register second device + visit profile_two_factor_auth_path + expect(page).to have_content("Your U2F device needs to be set up.") + second_device = register_u2f_device + logout + + # Authenticate as both devices + [first_device, second_device].each do |device| + login_as(user) + device.respond_to_u2f_authentication + click_on "Login Via U2F Device" + expect(page.body).to match('We heard back from your U2F device') + click_on "Authenticate via U2F Device" - before do - login_as(user) - user.update_attribute(:otp_required_for_login, true) - visit profile_account_path - click_on 'Manage Two-Factor Authentication' - register_u2f_device + expect(page.body).to match('Signed in successfully') + + logout + end + end end - it "deletes u2f registrations" do - expect { click_on "Disable" }.to change { U2fRegistration.count }.from(1).to(0) + describe "when two-factor authentication is disabled" do + let(:user) { create(:user) } + + before do + user = login_as(:user) + user.update_attribute(:otp_required_for_login, true) + visit profile_account_path + click_on 'Manage Two-Factor Authentication' + expect(page).to have_content("Your U2F device needs to be set up.") + register_u2f_device + end + + it "deletes u2f registrations" do + expect { click_on "Disable" }.to change { U2fRegistration.count }.by(-1) + end end end end -- cgit v1.2.1 From e21492b810bf9cd30f0e60836c056a72e830f427 Mon Sep 17 00:00:00 2001 From: dixpac Date: Sun, 3 Jul 2016 16:04:22 +0200 Subject: Fix not normalized emoji paths * There where path where +1 was stored as +1 not as thumbsup that was causing problems such as showing thumbsup icon 2 time. I fixed this to always normalize and store +1 as tumbsup --- CHANGELOG | 1 + app/models/concerns/awardable.rb | 9 +++++++-- app/models/note.rb | 3 +-- app/services/notes/create_service.rb | 1 - lib/api/award_emoji.rb | 4 ++-- spec/requests/api/award_emoji_spec.rb | 32 ++++++++++++++++++++++++++++++++ 6 files changed, 43 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19286abd74f..139444ef70e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -74,6 +74,7 @@ v 8.10.0 (unreleased) - Add basic system information like memory and disk usage to the admin panel - Don't garbage collect commits that have related DB records like comments - More descriptive message for git hooks and file locks + - Aliases of award emoji should be stored as original name. !5060 (dixpac) - Handle custom Git hook result in GitLab UI - Allow '?', or '&' for label names - Fix importer for GitHub Pull Requests when a branch was reused across Pull Requests diff --git a/app/models/concerns/awardable.rb b/app/models/concerns/awardable.rb index 06beff177b1..800a16ab246 100644 --- a/app/models/concerns/awardable.rb +++ b/app/models/concerns/awardable.rb @@ -65,8 +65,7 @@ module Awardable def create_award_emoji(name, current_user) return unless emoji_awardable? - - award_emoji.create(name: name, user: current_user) + award_emoji.create(name: normalize_name(name), user: current_user) end def remove_award_emoji(name, current_user) @@ -80,4 +79,10 @@ module Awardable create_award_emoji(emoji_name, current_user) end end + + private + + def normalize_name(name) + Gitlab::AwardEmoji.normalize_emoji_name(name) + end end diff --git a/app/models/note.rb b/app/models/note.rb index 8dca2ef09a8..0ce10c77de9 100644 --- a/app/models/note.rb +++ b/app/models/note.rb @@ -229,8 +229,7 @@ class Note < ActiveRecord::Base end def award_emoji_name - original_name = note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] - Gitlab::AwardEmoji.normalize_emoji_name(original_name) + note.match(Banzai::Filter::EmojiFilter.emoji_pattern)[1] end private diff --git a/app/services/notes/create_service.rb b/app/services/notes/create_service.rb index 02fca5c0ea3..18971bd0be3 100644 --- a/app/services/notes/create_service.rb +++ b/app/services/notes/create_service.rb @@ -8,7 +8,6 @@ module Notes if note.award_emoji? noteable = note.noteable todo_service.new_award_emoji(noteable, current_user) - return noteable.create_award_emoji(note.award_emoji_name, current_user) end diff --git a/lib/api/award_emoji.rb b/lib/api/award_emoji.rb index c4fa1838b5a..2efe7e3adf3 100644 --- a/lib/api/award_emoji.rb +++ b/lib/api/award_emoji.rb @@ -56,9 +56,9 @@ module API not_found!('Award Emoji') unless can_read_awardable? - award = awardable.award_emoji.new(name: params[:name], user: current_user) + award = awardable.create_award_emoji(params[:name], current_user) - if award.save + if award.persisted? present award, with: Entities::AwardEmoji else not_found!("Award Emoji #{award.errors.messages}") diff --git a/spec/requests/api/award_emoji_spec.rb b/spec/requests/api/award_emoji_spec.rb index 72a6d45f47d..2b74dd4bbb0 100644 --- a/spec/requests/api/award_emoji_spec.rb +++ b/spec/requests/api/award_emoji_spec.rb @@ -135,6 +135,22 @@ describe API::API, api: true do expect(response).to have_http_status(401) end + + it "normalizes +1 as thumbsup award" do + post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: '+1' + + expect(issue.award_emoji.last.name).to eq("thumbsup") + end + + context 'when the emoji already has been awarded' do + it 'returns a 404 status code' do + post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: 'thumbsup' + post api("/projects/#{project.id}/issues/#{issue.id}/award_emoji", user), name: 'thumbsup' + + expect(response).to have_http_status(404) + expect(json_response["message"]).to match("has already been taken") + end + end end end @@ -147,6 +163,22 @@ describe API::API, api: true do expect(response).to have_http_status(201) expect(json_response['user']['username']).to eq(user.username) end + + it "normalizes +1 as thumbsup award" do + post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: '+1' + + expect(note.award_emoji.last.name).to eq("thumbsup") + end + + context 'when the emoji already has been awarded' do + it 'returns a 404 status code' do + post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket' + post api("/projects/#{project.id}/issues/#{issue.id}/notes/#{note.id}/award_emoji", user), name: 'rocket' + + expect(response).to have_http_status(404) + expect(json_response["message"]).to match("has already been taken") + end + end end describe 'DELETE /projects/:id/awardable/:awardable_id/award_emoji/:award_id' do -- cgit v1.2.1 From ef892bc2bfa29046dd58441d8d9afe8b3cde0007 Mon Sep 17 00:00:00 2001 From: Katarzyna Kobierska Date: Thu, 14 Jul 2016 10:53:56 +0200 Subject: When Issue author assign or mention himself Todos are created --- CHANGELOG | 1 + app/services/todo_service.rb | 3 +-- spec/services/todo_service_spec.rb | 35 ++++++++++++++++++++--------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 19286abd74f..aaab3551ea8 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,6 +91,7 @@ v 8.10.0 (unreleased) - Redesign Builds and Pipelines pages - Change status color and icon for running builds - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` + - Create Todos for Issue author when assign or mention himself (Katarzyna Kobierska) v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 diff --git a/app/services/todo_service.rb b/app/services/todo_service.rb index 6bb0a72d30e..6b48d68cccb 100644 --- a/app/services/todo_service.rb +++ b/app/services/todo_service.rb @@ -194,7 +194,7 @@ class TodoService end def create_assignment_todo(issuable, author) - if issuable.assignee && issuable.assignee != author + if issuable.assignee attributes = attributes_for_todo(issuable.project, issuable, author, Todo::ASSIGNED) create_todos(issuable.assignee, attributes) end @@ -239,7 +239,6 @@ class TodoService def filter_mentioned_users(project, target, author) mentioned_users = target.mentioned_users(author) mentioned_users = reject_users_without_access(mentioned_users, project, target) - mentioned_users.delete(author) mentioned_users.uniq end diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb index b4522536724..b8c62e3d1dc 100644 --- a/spec/services/todo_service_spec.rb +++ b/spec/services/todo_service_spec.rb @@ -35,8 +35,11 @@ describe TodoService, services: true do should_not_create_any_todo { service.new_issue(unassigned_issue, author) } end - it 'does not create a todo if assignee is the current user' do - should_not_create_any_todo { service.new_issue(unassigned_issue, john_doe) } + it 'creates a todo if assignee is the current user' do + unassigned_issue.update_attribute(:assignee, john_doe) + service.new_issue(unassigned_issue, john_doe) + + should_create_todo(user: john_doe, target: unassigned_issue, author: john_doe, action: Todo::ASSIGNED) end it 'creates a todo for each valid mentioned user' do @@ -44,7 +47,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: issue, action: Todo::MENTIONED) should_create_todo(user: guest, target: issue, action: Todo::MENTIONED) - should_not_create_todo(user: author, target: issue, action: Todo::MENTIONED) + should_create_todo(user: author, target: issue, action: Todo::MENTIONED) should_not_create_todo(user: john_doe, target: issue, action: Todo::MENTIONED) should_not_create_todo(user: non_member, target: issue, action: Todo::MENTIONED) end @@ -57,7 +60,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) should_create_todo(user: admin, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) should_not_create_todo(user: guest, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) - should_not_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) + should_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) end context 'when a private group is mentioned' do @@ -87,7 +90,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: issue, action: Todo::MENTIONED) should_create_todo(user: guest, target: issue, action: Todo::MENTIONED) should_create_todo(user: john_doe, target: issue, action: Todo::MENTIONED) - should_not_create_todo(user: author, target: issue, action: Todo::MENTIONED) + should_create_todo(user: author, target: issue, action: Todo::MENTIONED) should_not_create_todo(user: non_member, target: issue, action: Todo::MENTIONED) end @@ -105,7 +108,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) should_create_todo(user: admin, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) should_not_create_todo(user: guest, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) - should_not_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) + should_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED) end context 'issues with a task list' do @@ -156,10 +159,11 @@ describe TodoService, services: true do should_not_create_any_todo { service.reassigned_issue(issue, author) } end - it 'does not create a todo if new assignee is the current user' do + it 'creates a todo if new assignee is the current user' do unassigned_issue.update_attribute(:assignee, john_doe) + service.reassigned_issue(unassigned_issue, john_doe) - should_not_create_any_todo { service.reassigned_issue(unassigned_issue, john_doe) } + should_create_todo(user: john_doe, target: unassigned_issue, author: john_doe, action: Todo::ASSIGNED) end end @@ -250,7 +254,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) should_create_todo(user: guest, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) should_create_todo(user: author, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) - should_not_create_todo(user: john_doe, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) + should_create_todo(user: john_doe, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) should_not_create_todo(user: non_member, target: issue, author: john_doe, action: Todo::MENTIONED, note: note) end @@ -262,7 +266,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: confidential_issue, author: john_doe, action: Todo::MENTIONED, note: note_on_confidential_issue) should_create_todo(user: admin, target: confidential_issue, author: john_doe, action: Todo::MENTIONED, note: note_on_confidential_issue) should_not_create_todo(user: guest, target: confidential_issue, author: john_doe, action: Todo::MENTIONED, note: note_on_confidential_issue) - should_not_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED, note: note_on_confidential_issue) + should_create_todo(user: john_doe, target: confidential_issue, author: john_doe, action: Todo::MENTIONED, note: note_on_confidential_issue) end it 'creates a todo for each valid mentioned user when leaving a note on commit' do @@ -270,7 +274,7 @@ describe TodoService, services: true do should_create_todo(user: member, target_id: nil, target_type: 'Commit', commit_id: note_on_commit.commit_id, author: john_doe, action: Todo::MENTIONED, note: note_on_commit) should_create_todo(user: author, target_id: nil, target_type: 'Commit', commit_id: note_on_commit.commit_id, author: john_doe, action: Todo::MENTIONED, note: note_on_commit) - should_not_create_todo(user: john_doe, target_id: nil, target_type: 'Commit', commit_id: note_on_commit.commit_id, author: john_doe, action: Todo::MENTIONED, note: note_on_commit) + should_create_todo(user: john_doe, target_id: nil, target_type: 'Commit', commit_id: note_on_commit.commit_id, author: john_doe, action: Todo::MENTIONED, note: note_on_commit) should_not_create_todo(user: non_member, target_id: nil, target_type: 'Commit', commit_id: note_on_commit.commit_id, author: john_doe, action: Todo::MENTIONED, note: note_on_commit) end @@ -312,7 +316,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: mr_assigned, action: Todo::MENTIONED) should_create_todo(user: guest, target: mr_assigned, action: Todo::MENTIONED) - should_not_create_todo(user: author, target: mr_assigned, action: Todo::MENTIONED) + should_create_todo(user: author, target: mr_assigned, action: Todo::MENTIONED) should_not_create_todo(user: john_doe, target: mr_assigned, action: Todo::MENTIONED) should_not_create_todo(user: non_member, target: mr_assigned, action: Todo::MENTIONED) end @@ -325,7 +329,7 @@ describe TodoService, services: true do should_create_todo(user: member, target: mr_assigned, action: Todo::MENTIONED) should_create_todo(user: guest, target: mr_assigned, action: Todo::MENTIONED) should_create_todo(user: john_doe, target: mr_assigned, action: Todo::MENTIONED) - should_not_create_todo(user: author, target: mr_assigned, action: Todo::MENTIONED) + should_create_todo(user: author, target: mr_assigned, action: Todo::MENTIONED) should_not_create_todo(user: non_member, target: mr_assigned, action: Todo::MENTIONED) end @@ -382,10 +386,11 @@ describe TodoService, services: true do should_not_create_any_todo { service.reassigned_merge_request(mr_assigned, author) } end - it 'does not create a todo if new assignee is the current user' do + it 'creates a todo if new assignee is the current user' do mr_assigned.update_attribute(:assignee, john_doe) + service.reassigned_merge_request(mr_assigned, john_doe) - should_not_create_any_todo { service.reassigned_merge_request(mr_assigned, john_doe) } + should_create_todo(user: john_doe, target: mr_assigned, author: john_doe, action: Todo::ASSIGNED) end end -- cgit v1.2.1 From 097706b4588ca8ace9dfaab44f03d62ac6b3a2be Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 14 Jul 2016 12:07:54 +0200 Subject: fix EE => CE project import, and updated JSON spec --- lib/gitlab/import_export/relation_factory.rb | 8 ++++++-- spec/lib/gitlab/import_export/project.json | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/import_export/relation_factory.rb b/lib/gitlab/import_export/relation_factory.rb index 9824df3f274..6ba25a31641 100644 --- a/lib/gitlab/import_export/relation_factory.rb +++ b/lib/gitlab/import_export/relation_factory.rb @@ -87,7 +87,7 @@ module Gitlab project_id = @relation_hash.delete('project_id') # project_id may not be part of the export, but we always need to populate it if required. - @relation_hash['project_id'] = project_id if relation_class.column_names.include?('project_id') + @relation_hash['project_id'] = project_id @relation_hash['gl_project_id'] = project_id if @relation_hash['gl_project_id'] @relation_hash['target_project_id'] = project_id if @relation_hash['target_project_id'] @relation_hash['source_project_id'] = -1 if @relation_hash['source_project_id'] @@ -111,7 +111,7 @@ module Gitlab end def imported_object - imported_object = relation_class.new(@relation_hash) + imported_object = relation_class.new(parsed_relation_hash) yield(imported_object) if block_given? imported_object.importing = true if imported_object.respond_to?(:importing) imported_object @@ -125,6 +125,10 @@ module Gitlab def admin_user? @user.is_admin? end + + def parsed_relation_hash + @relation_hash.reject { |k, _v| !relation_class.attribute_method?(k) } + end end end end diff --git a/spec/lib/gitlab/import_export/project.json b/spec/lib/gitlab/import_export/project.json index 7286b0c39c0..4113d829c3c 100644 --- a/spec/lib/gitlab/import_export/project.json +++ b/spec/lib/gitlab/import_export/project.json @@ -26,6 +26,7 @@ "deleted_at": null, "due_date": null, "moved_to_id": null, + "test_ee_field": "test", "notes": [ { "id": 351, -- cgit v1.2.1 From 37d1e65a2deb64d95183e69c3680a6eeb1770fdb Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 14 Jul 2016 12:18:16 +0200 Subject: added changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 19286abd74f..6acecf94420 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,6 +91,7 @@ v 8.10.0 (unreleased) - Redesign Builds and Pipelines pages - Change status color and icon for running builds - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` + - Fix issues importing projects from EE to CE v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 -- cgit v1.2.1 From b1ab079fae3fbebd0277e16682872632463cd0e2 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 14 Jul 2016 16:03:00 +0200 Subject: fix updated_at not preserved after import - for GitLab projects --- lib/gitlab/import_export/project_tree_restorer.rb | 5 ++++- spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/import_export/project_tree_restorer.rb b/lib/gitlab/import_export/project_tree_restorer.rb index 025ecc12f9f..051110c23cf 100644 --- a/lib/gitlab/import_export/project_tree_restorer.rb +++ b/lib/gitlab/import_export/project_tree_restorer.rb @@ -12,7 +12,10 @@ module Gitlab json = IO.read(@path) @tree_hash = ActiveSupport::JSON.decode(json) @project_members = @tree_hash.delete('project_members') - create_relations + + ActiveRecord::Base.no_touching do + create_relations + end rescue => e @shared.error(e) false diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index 05ffec8ea0a..877be300262 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -30,6 +30,14 @@ describe Gitlab::ImportExport::ProjectTreeRestorer, services: true do expect(Event.where.not(data: nil).first.data[:ref]).not_to be_empty end + it 'preserves updated_at on issues' do + restored_project_json + + issue = Issue.where(description: 'Aliquam enim illo et possimus.').first + + expect(issue.reload.updated_at.to_s).to eq('2016-06-14 15:02:47 UTC') + end + context 'event at forth level of the tree' do let(:event) { Event.where(title: 'test levels').first } -- cgit v1.2.1 From 37e363c9cff8a0dd0dac7eff42316c3ba589bf55 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 14 Jul 2016 17:06:48 +0200 Subject: fixed similar issue with gitlab.com importer because why not! --- lib/gitlab/gitlab_import/importer.rb | 53 +++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/lib/gitlab/gitlab_import/importer.rb b/lib/gitlab/gitlab_import/importer.rb index e6d31ea04c0..46d40f75be6 100644 --- a/lib/gitlab/gitlab_import/importer.rb +++ b/lib/gitlab/gitlab_import/importer.rb @@ -15,32 +15,35 @@ module Gitlab end def execute - project_identifier = CGI.escape(project.import_source) - - # Issues && Comments - issues = client.issues(project_identifier) - - issues.each do |issue| - body = @formatter.author_line(issue["author"]["name"]) - body += issue["description"] - - comments = client.issue_comments(project_identifier, issue["id"]) - - if comments.any? - body += @formatter.comments_header + ActiveRecord::Base.no_touching do + project_identifier = CGI.escape(project.import_source) + + # Issues && Comments + issues = client.issues(project_identifier) + + issues.each do |issue| + body = @formatter.author_line(issue["author"]["name"]) + body += issue["description"] + + comments = client.issue_comments(project_identifier, issue["id"]) + + if comments.any? + body += @formatter.comments_header + end + + comments.each do |comment| + body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"]) + end + + project.issues.create!( + iid: issue["iid"], + description: body, + title: issue["title"], + state: issue["state"], + updated_at: issue["updated_at"], + author_id: gl_user_id(project, issue["author"]["id"]) + ) end - - comments.each do |comment| - body += @formatter.comment(comment["author"]["name"], comment["created_at"], comment["body"]) - end - - project.issues.create!( - iid: issue["iid"], - description: body, - title: issue["title"], - state: issue["state"], - author_id: gl_user_id(project, issue["author"]["id"]) - ) end true -- cgit v1.2.1 From cc6d3a83c2c50be88110938e11e872b7c29f4696 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Thu, 14 Jul 2016 17:13:00 +0200 Subject: updated changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 19286abd74f..fdad63bf323 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,6 +91,7 @@ v 8.10.0 (unreleased) - Redesign Builds and Pipelines pages - Change status color and icon for running builds - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` + - Fix last update timestamp on issues not preserved on gitlab.com and project imports v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 -- cgit v1.2.1 From 7d456ad436c95a6b081da59cd61cc9672e1e3f5a Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 10:27:39 -0700 Subject: update rouge, gollum-lib, and github-markup --- Gemfile | 6 +++--- Gemfile.lock | 18 +++++++++--------- 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Gemfile b/Gemfile index ee23f712f05..3c0b8edabc6 100644 --- a/Gemfile +++ b/Gemfile @@ -61,7 +61,7 @@ gem 'gitlab_omniauth-ldap', '~> 1.2.1', require: 'omniauth-ldap' # Git Wiki # Required manually in config/initializers/gollum.rb to control load order -gem 'gollum-lib', '~> 4.1.0', require: false +gem 'gollum-lib', '~> 4.2', require: false gem 'gollum-rugged_adapter', '~> 0.4.2', require: false # Language detection @@ -105,7 +105,7 @@ gem 'seed-fu', '~> 2.3.5' # Markdown and HTML processing gem 'html-pipeline', '~> 1.11.0' gem 'task_list', '~> 1.0.2', require: 'task_list/railtie' -gem 'github-markup', '~> 1.3.1' +gem 'github-markup', '~> 1.4' gem 'redcarpet', '~> 3.3.3' gem 'RedCloth', '~> 4.3.2' gem 'rdoc', '~>3.6' @@ -113,7 +113,7 @@ gem 'org-ruby', '~> 0.9.12' gem 'creole', '~> 0.5.0' gem 'wikicloth', '0.8.1' gem 'asciidoctor', '~> 1.5.2' -gem 'rouge', '~> 1.11' +gem 'rouge', '~> 2.0' # See https://groups.google.com/forum/#!topic/ruby-security-ann/aSbgDiwb24s # and https://groups.google.com/forum/#!topic/ruby-security-ann/Dy7YiKb_pMM diff --git a/Gemfile.lock b/Gemfile.lock index 67c0645c3d9..1514bde61ab 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -264,7 +264,7 @@ GEM escape_utils (~> 1.1.0) mime-types (>= 1.19) rugged (>= 0.23.0b) - github-markup (1.3.3) + github-markup (1.4.0) gitlab-flowdock-git-hook (1.0.1) flowdock (~> 0.7) gitlab-grit (>= 2.4.1) @@ -287,13 +287,13 @@ GEM rubyntlm (~> 0.3) globalid (0.3.6) activesupport (>= 4.1.0) - gollum-grit_adapter (1.0.0) + gollum-grit_adapter (1.0.1) gitlab-grit (~> 2.7, >= 2.7.1) - gollum-lib (4.1.0) - github-markup (~> 1.3.3) + gollum-lib (4.2.1) + github-markup (~> 1.4.0) gollum-grit_adapter (~> 1.0) nokogiri (~> 1.6.4) - rouge (~> 1.9) + rouge (~> 2.0) sanitize (~> 2.1.0) stringex (~> 2.5.1) gollum-rugged_adapter (0.4.2) @@ -578,7 +578,7 @@ GEM railties (>= 4.2.0, < 5.1) rinku (2.0.0) rotp (2.1.2) - rouge (1.11.0) + rouge (2.0.1) rqrcode (0.7.0) chunky_png rqrcode-rails3 (0.1.7) @@ -859,12 +859,12 @@ DEPENDENCIES gemnasium-gitlab-service (~> 0.2) gemojione (~> 2.6) github-linguist (~> 4.7.0) - github-markup (~> 1.3.1) + github-markup (~> 1.4) gitlab-flowdock-git-hook (~> 1.0.1) gitlab_git (~> 10.2) gitlab_meta (= 7.0) gitlab_omniauth-ldap (~> 1.2.1) - gollum-lib (~> 4.1.0) + gollum-lib (~> 4.2) gollum-rugged_adapter (~> 0.4.2) gon (~> 6.0.1) grape (~> 0.13.0) @@ -933,7 +933,7 @@ DEPENDENCIES request_store (~> 1.3.0) rerun (~> 0.11.0) responders (~> 2.0) - rouge (~> 1.11) + rouge (~> 2.0) rqrcode-rails3 (~> 0.1.7) rspec-rails (~> 3.5.0) rspec-retry (~> 0.4.5) -- cgit v1.2.1 From 96c68c503340bf650a545872cb4e8767a1b00f5b Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 11:29:19 -0700 Subject: deprecate @anchorlinenos --- lib/rouge/formatters/html_gitlab.rb | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 3358ed6773e..2833dbddcf3 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -26,9 +26,6 @@ module Rouge # [+lineanchorsid+] If lineanchors is true the name of the anchors can # be changed with lineanchorsid to e.g. foo-linenumber # (default: 'L'). - # [+anchorlinenos+] If set to true, will wrap line numbers in - # tags. Used in combination with linenos and lineanchors - # (default: false). # [+inline_theme+] Inline CSS styles for the
 tag (default: false).
       def initialize(
           nowrap: false,
@@ -37,7 +34,6 @@ module Rouge
           linenostart: 1,
           lineanchors: false,
           lineanchorsid: 'L',
-          anchorlinenos: false,
           inline_theme: nil
       )
         @nowrap = nowrap
@@ -46,7 +42,6 @@ module Rouge
         @linenostart = linenostart
         @lineanchors = lineanchors
         @lineanchorsid = lineanchorsid
-        @anchorlinenos = anchorlinenos
         @inline_theme = Theme.find(inline_theme).new if inline_theme.is_a?(String)
       end
 
@@ -120,11 +115,6 @@ module Rouge
       end
 
       def wrap_linenos(numbers)
-        if @anchorlinenos
-          numbers.map! do |number|
-            "#{number}"
-          end
-        end
         numbers.join("\n")
       end
 
-- 
cgit v1.2.1


From 95d6174a0818230a9811d5d302c77760b49597b1 Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Wed, 15 Jun 2016 11:32:08 -0700
Subject: remove the unused inline_theme feature

---
 lib/rouge/formatters/html_gitlab.rb | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb
index 2833dbddcf3..50b1db88c0e 100644
--- a/lib/rouge/formatters/html_gitlab.rb
+++ b/lib/rouge/formatters/html_gitlab.rb
@@ -26,15 +26,13 @@ module Rouge
       # [+lineanchorsid+]   If lineanchors is true the name of the anchors can
       #                     be changed with lineanchorsid to e.g. foo-linenumber
       #                     (default: 'L').
-      # [+inline_theme+]    Inline CSS styles for the 
 tag (default: false).
       def initialize(
           nowrap: false,
           cssclass: 'highlight',
           linenos: nil,
           linenostart: 1,
           lineanchors: false,
-          lineanchorsid: 'L',
-          inline_theme: nil
+          lineanchorsid: 'L'
       )
         @nowrap = nowrap
         @cssclass = cssclass
@@ -42,7 +40,6 @@ module Rouge
         @linenostart = linenostart
         @lineanchors = lineanchors
         @lineanchorsid = lineanchorsid
-        @inline_theme = Theme.find(inline_theme).new if inline_theme.is_a?(String)
       end
 
       def render(tokens)
@@ -150,12 +147,7 @@ module Rouge
         if tok.shortname.empty?
           val
         else
-          if @inline_theme
-            rules = @inline_theme.style_for(tok).rendered_rules
-            ""
-          else
-            "#{val}"
-          end
+          "#{val}"
         end
       end
     end
-- 
cgit v1.2.1


From 681b5af586eb847651af075b325a8b6ef69f4ec6 Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Wed, 15 Jun 2016 11:32:27 -0700
Subject: do this thing in a clearer way

---
 lib/gitlab/highlight.rb | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb
index 41296415e35..adac216b337 100644
--- a/lib/gitlab/highlight.rb
+++ b/lib/gitlab/highlight.rb
@@ -28,11 +28,14 @@ module Gitlab
     end
 
     def highlight(text, continue: true, plain: false)
+      lexer = @lexer
+
       if plain
-        @formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe
-      else
-        @formatter.format(@lexer.lex(text, continue: continue)).html_safe
+        lexer = Rouge::Lexers::PlainText
+        continue = false
       end
+
+      @formatter.format(@lexer.lex(text, continue: continue)).html_safe
     rescue
       @formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe
     end
-- 
cgit v1.2.1


From 7e8a92fbd1cdaaf1011b301124c0d3f471c871fd Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Wed, 15 Jun 2016 11:44:12 -0700
Subject: the call site always specifies this option

---
 lib/gitlab/highlight.rb | 1 -
 1 file changed, 1 deletion(-)

diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb
index adac216b337..7230a85bc9f 100644
--- a/lib/gitlab/highlight.rb
+++ b/lib/gitlab/highlight.rb
@@ -52,7 +52,6 @@ module Gitlab
 
     def rouge_formatter(options = {})
       options = options.reverse_merge(
-        nowrap: true,
         cssclass: 'code highlight',
         lineanchors: true,
         lineanchorsid: 'LC'
-- 
cgit v1.2.1


From e2c9770e03681edafe14212d3db1035a675ba47d Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Wed, 15 Jun 2016 11:49:22 -0700
Subject: rm dead `highlighter` method

---
 app/helpers/blob_helper.rb | 4 ----
 1 file changed, 4 deletions(-)

diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index 428a42266d0..d639a56f487 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -1,8 +1,4 @@
 module BlobHelper
-  def highlighter(blob_name, blob_content, repository: nil, nowrap: false)
-    Gitlab::Highlight.new(blob_name, blob_content, nowrap: nowrap, repository: repository)
-  end
-
   def highlight(blob_name, blob_content, repository: nil, nowrap: false, plain: false)
     Gitlab::Highlight.highlight(blob_name, blob_content, nowrap: nowrap, plain: plain, repository: repository)
   end
-- 
cgit v1.2.1


From 7214a221e082c569b4804eb4729e097d4e4b069c Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Wed, 15 Jun 2016 11:52:23 -0700
Subject: kill the nowrap option

the 
 wrapping is *always* used by the helper, and *never* by
anywhere else, so pull the wrapping into the helper
---
 app/helpers/blob_helper.rb |  5 +++--
 lib/gitlab/highlight.rb    | 16 +++++-----------
 2 files changed, 8 insertions(+), 13 deletions(-)

diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb
index d639a56f487..39f9f935d31 100644
--- a/app/helpers/blob_helper.rb
+++ b/app/helpers/blob_helper.rb
@@ -1,6 +1,7 @@
 module BlobHelper
-  def highlight(blob_name, blob_content, repository: nil, nowrap: false, plain: false)
-    Gitlab::Highlight.highlight(blob_name, blob_content, nowrap: nowrap, plain: plain, repository: repository)
+  def highlight(blob_name, blob_content, repository: nil, plain: false)
+    highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository)
+    raw %<
#{highlighted}
> end def no_highlight_files diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 7230a85bc9f..ad928fec970 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -1,7 +1,7 @@ module Gitlab class Highlight - def self.highlight(blob_name, blob_content, repository: nil, nowrap: true, plain: false) - new(blob_name, blob_content, nowrap: nowrap, repository: repository). + def self.highlight(blob_name, blob_content, repository: nil, plain: false) + new(blob_name, blob_content, repository: repository). highlight(blob_content, continue: false, plain: plain) end @@ -13,13 +13,9 @@ module Gitlab highlight(file_name, blob.data, repository: repository).lines.map!(&:html_safe) end - attr_reader :lexer - def initialize(blob_name, blob_content, repository: nil, nowrap: true) - @blob_name = blob_name - @blob_content = blob_content + def initialize(blob_name, blob_content, repository: nil) + @formatter = rouge_formatter @repository = repository - @formatter = rouge_formatter(nowrap: nowrap) - @lexer = custom_language || begin Rouge::Lexer.guess(filename: blob_name, source: blob_content).new rescue Rouge::Lexer::AmbiguousGuess => e @@ -51,13 +47,11 @@ module Gitlab end def rouge_formatter(options = {}) - options = options.reverse_merge( + Rouge::Formatters::HTMLGitlab.new( cssclass: 'code highlight', lineanchors: true, lineanchorsid: 'LC' ) - - Rouge::Formatters::HTMLGitlab.new(options) end end end -- cgit v1.2.1 From 2ae837f9c9c62272efae4f6dbb1d33cbba325389 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 11:58:47 -0700 Subject: kill the nowrap option in HTMLGitlab itself --- lib/rouge/formatters/html_gitlab.rb | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 50b1db88c0e..04943c173bd 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -7,8 +7,6 @@ module Rouge # Creates a new Rouge::Formatter::HTMLGitlab instance. # - # [+nowrap+] If set to True, don't wrap the output at all, not - # even inside a
 tag (default: false).
       # [+cssclass+]        CSS class for the wrapping 
tag # (default: 'highlight'). # [+linenos+] If set to 'table', output line numbers as a table @@ -27,14 +25,12 @@ module Rouge # be changed with lineanchorsid to e.g. foo-linenumber # (default: 'L'). def initialize( - nowrap: false, cssclass: 'highlight', linenos: nil, linenostart: 1, lineanchors: false, lineanchorsid: 'L' ) - @nowrap = nowrap @cssclass = cssclass @linenos = linenos @linenostart = linenostart @@ -60,18 +56,13 @@ module Rouge def render_untableized(tokens) data = process_tokens(tokens) - html = '' - html << "
" unless @nowrap
-        html << wrap_lines(data[:code])
-        html << "
\n" unless @nowrap - html + wrap_lines(data[:code]) end def render_tableized(tokens) data = process_tokens(tokens) html = '' - html << "
" unless @nowrap html << '' html << "' html << '
"
         html << wrap_linenos(data[:numbers])
@@ -80,7 +71,6 @@ module Rouge
         html << wrap_lines(data[:code])
         html << '
' - html << '
' unless @nowrap html end -- cgit v1.2.1 From 96274c2765ad4daa23af667b27dc647a3406d7c0 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 12:04:25 -0700 Subject: add the wrapping back in for the banzai filter --- lib/banzai/filter/syntax_highlight_filter.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 536b478979f..c06de2e5b37 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -20,7 +20,7 @@ module Banzai code = node.text begin - highlighted = block_code(code, language) + highlighted = %<
#{block_code(code, language)}
> rescue # Gracefully handle syntax highlighter bugs/errors to ensure # users can still access an issue/comment/etc. @@ -31,6 +31,10 @@ module Banzai replace_parent_pre_element(node, highlighted) end + def css_classes + "code highlight js-syntax-highlight #{lexer.tag}" + end + private def replace_parent_pre_element(node, highlighted) -- cgit v1.2.1 From 504a048b0824aecb81faa3ca4a9503a05c93faac Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 12:08:04 -0700 Subject: remove the dead linenos and linenostart options and the methods that relied on them --- lib/rouge/formatters/html_gitlab.rb | 46 ++----------------------------------- 1 file changed, 2 insertions(+), 44 deletions(-) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 04943c173bd..b76021eef77 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -9,14 +9,6 @@ module Rouge # # [+cssclass+] CSS class for the wrapping
tag # (default: 'highlight'). - # [+linenos+] If set to 'table', output line numbers as a table - # with two cells, one containing the line numbers, - # the other the whole code. This is copy paste friendly, - # but may cause alignment problems with some browsers - # or fonts. If set to 'inline', the line numbers will - # be integrated in the
 tag that contains
-      #                     the code (default: nil).
-      # [+linenostart+]     The line number for the first line (default: 1).
       # [+lineanchors+]     If set to true the formatter will wrap each output
       #                     line in an anchor tag with a name of L-linenumber.
       #                     This allows easy linking to certain lines
@@ -26,53 +18,23 @@ module Rouge
       #                     (default: 'L').
       def initialize(
           cssclass: 'highlight',
-          linenos: nil,
-          linenostart: 1,
           lineanchors: false,
           lineanchorsid: 'L'
       )
         @cssclass = cssclass
-        @linenos = linenos
-        @linenostart = linenostart
         @lineanchors = lineanchors
         @lineanchorsid = lineanchorsid
       end
 
       def render(tokens)
-        case @linenos
-        when 'table'
-          render_tableized(tokens)
-        when 'inline'
-          render_untableized(tokens)
-        else
-          render_untableized(tokens)
-        end
-      end
-
-      alias_method :format, :render
-
-      private
-
-      def render_untableized(tokens)
         data = process_tokens(tokens)
 
         wrap_lines(data[:code])
       end
 
-      def render_tableized(tokens)
-        data = process_tokens(tokens)
+      alias_method :format, :render
 
-        html = ''
-        html << ''
-        html << "'
-        html << "'
-        html << '
"
-        html << wrap_linenos(data[:numbers])
-        html << '
"
-        html << wrap_lines(data[:code])
-        html << '
' - html - end + private def process_tokens(tokens) rendered = [] @@ -101,10 +63,6 @@ module Rouge { numbers: numbers, code: rendered } end - def wrap_linenos(numbers) - numbers.join("\n") - end - def wrap_lines(lines) if @lineanchors lines = lines.each_with_index.map do |line, index| -- cgit v1.2.1 From 55dc7d09b35c43679d0c298885c10aa59818bf66 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 12:12:48 -0700 Subject: trim more dead code --- lib/rouge/formatters/html_gitlab.rb | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index b76021eef77..791a9523884 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -57,10 +57,7 @@ module Rouge # Add leftover text rendered << current_line if current_line.present? - num_lines = rendered.size - numbers = (@linenostart..num_lines + @linenostart - 1).to_a - - { numbers: numbers, code: rendered } + { code: rendered } end def wrap_lines(lines) @@ -68,20 +65,8 @@ module Rouge lines = lines.each_with_index.map do |line, index| number = index + @linenostart - if @linenos == 'inline' - "" \ - "#{number}" \ - "#{line}" \ - '' - else - "#{line}" \ - '' - end - end - elsif @linenos == 'inline' - lines = lines.each_with_index.map do |line, index| - number = index + @linenostart - "#{number}#{line}" + "#{line}" \ + '' end end -- cgit v1.2.1 From 3bb65815b0cb7731b3262ff216506582951a6f6f Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 09:51:10 -0700 Subject: kill the :cssclass option --- lib/banzai/filter/syntax_highlight_filter.rb | 3 +-- lib/gitlab/highlight.rb | 1 - lib/rouge/formatters/html_gitlab.rb | 2 -- 3 files changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index c06de2e5b37..7f838ef4c08 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -44,8 +44,7 @@ module Banzai # Override Rouge::Plugins::Redcarpet#rouge_formatter def rouge_formatter(lexer) - Rouge::Formatters::HTMLGitlab.new( - cssclass: "code highlight js-syntax-highlight #{lexer.tag}") + Rouge::Formatters::HTMLGitlab.new end end end diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index ad928fec970..aaef569d870 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -48,7 +48,6 @@ module Gitlab def rouge_formatter(options = {}) Rouge::Formatters::HTMLGitlab.new( - cssclass: 'code highlight', lineanchors: true, lineanchorsid: 'LC' ) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 791a9523884..b9e3272e0b5 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -17,11 +17,9 @@ module Rouge # be changed with lineanchorsid to e.g. foo-linenumber # (default: 'L'). def initialize( - cssclass: 'highlight', lineanchors: false, lineanchorsid: 'L' ) - @cssclass = cssclass @lineanchors = lineanchors @lineanchorsid = lineanchorsid end -- cgit v1.2.1 From 34a3d2a340b5d235da3958176bca6e0de6679a0f Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 12:15:47 -0700 Subject: without line anchors, this is just the plain HTML formatter --- lib/banzai/filter/syntax_highlight_filter.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 7f838ef4c08..144d8c175dc 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -44,7 +44,7 @@ module Banzai # Override Rouge::Plugins::Redcarpet#rouge_formatter def rouge_formatter(lexer) - Rouge::Formatters::HTMLGitlab.new + Rouge::Formatters::HTML.new end end end -- cgit v1.2.1 From e1824aa101a2181fe7e5ce080582cfa188d19da8 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 12:32:55 -0700 Subject: use the new token_lines interface to format lines --- lib/gitlab/highlight.rb | 5 +-- lib/rouge/formatters/html_gitlab.rb | 81 +++++-------------------------------- 2 files changed, 12 insertions(+), 74 deletions(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index aaef569d870..ba157cc98cc 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -47,10 +47,7 @@ module Gitlab end def rouge_formatter(options = {}) - Rouge::Formatters::HTMLGitlab.new( - lineanchors: true, - lineanchorsid: 'LC' - ) + Rouge::Formatters::HTMLGitlab.new end end end diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index b9e3272e0b5..723bac574dd 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -2,83 +2,24 @@ require 'cgi' module Rouge module Formatters - class HTMLGitlab < Rouge::Formatter + class HTMLGitlab < Rouge::Formatters::HTML tag 'html_gitlab' # Creates a new Rouge::Formatter::HTMLGitlab instance. # - # [+cssclass+] CSS class for the wrapping
tag - # (default: 'highlight'). - # [+lineanchors+] If set to true the formatter will wrap each output - # line in an anchor tag with a name of L-linenumber. - # This allows easy linking to certain lines - # (default: false). - # [+lineanchorsid+] If lineanchors is true the name of the anchors can - # be changed with lineanchorsid to e.g. foo-linenumber - # (default: 'L'). - def initialize( - lineanchors: false, - lineanchorsid: 'L' - ) - @lineanchors = lineanchors - @lineanchorsid = lineanchorsid + # [+linenostart+] The line number for the first line (default: 1). + def initialize(linenostart: 1) + @linenostart = linenostart + @line_number = linenostart end - def render(tokens) - data = process_tokens(tokens) + def stream(tokens, &b) + token_lines(tokens) do |line| + yield %<> + line.each { |token, value| yield span(token, value) } + yield %<\n> - wrap_lines(data[:code]) - end - - alias_method :format, :render - - private - - def process_tokens(tokens) - rendered = [] - current_line = '' - - tokens.each do |tok, val| - # In the case of multi-line values (e.g. comments), we need to apply - # styling to each line since span elements are inline. - val.lines.each do |line| - stripped = line.chomp - current_line << span(tok, stripped) - - if line.end_with?("\n") - rendered << current_line - current_line = '' - end - end - end - - # Add leftover text - rendered << current_line if current_line.present? - - { code: rendered } - end - - def wrap_lines(lines) - if @lineanchors - lines = lines.each_with_index.map do |line, index| - number = index + @linenostart - - "#{line}" \ - '' - end - end - - lines.join("\n") - end - - def span(tok, val) - # http://stackoverflow.com/a/1600584/2587286 - val = CGI.escapeHTML(val) - - if tok.shortname.empty? - val - else - "#{val}" + @line_number += 1 end end end -- cgit v1.2.1 From 6107933ba30a2ac6e591971d4a7581a5611c42c0 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 14:01:47 -0700 Subject: inline #rouge_formatter --- lib/gitlab/highlight.rb | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index ba157cc98cc..84bd616d608 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -13,8 +13,8 @@ module Gitlab highlight(file_name, blob.data, repository: repository).lines.map!(&:html_safe) end - def initialize(blob_name, blob_content, repository: nil) - @formatter = rouge_formatter + def initialize(blob_name, blob_content) + @formatter = Rouge::Formatters::HTMLGitlab.new @repository = repository @lexer = custom_language || begin Rouge::Lexer.guess(filename: blob_name, source: blob_content).new @@ -45,9 +45,5 @@ module Gitlab Rouge::Lexer.find_fancy(language_name) end - - def rouge_formatter(options = {}) - Rouge::Formatters::HTMLGitlab.new - end end end -- cgit v1.2.1 From 4365144f5cfa1ab8ada3a75447e9d494f406980e Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 14:01:57 -0700 Subject: no longer need cgi --- lib/rouge/formatters/html_gitlab.rb | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index 723bac574dd..31533fc3b8c 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -1,5 +1,3 @@ -require 'cgi' - module Rouge module Formatters class HTMLGitlab < Rouge::Formatters::HTML -- cgit v1.2.1 From ff7e679bca6a0303dcb3cb07dbe26aa32f6fb649 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Wed, 15 Jun 2016 15:02:13 -0700 Subject: we no longer encode double-quotes --- spec/lib/gitlab/diff/highlight_spec.rb | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index fb5d50a5c68..4408d5bcdb4 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -28,13 +28,13 @@ describe Gitlab::Diff::Highlight, lib: true do end it 'highlights and marks removed lines' do - code = %Q{- raise "System commands must be given as an array of strings"\n} + code = %Q{- raise "System commands must be given as an array of strings"\n} expect(subject[4].text).to eq(code) end it 'highlights and marks added lines' do - code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"\n} + code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"\n} expect(subject[5].text).to eq(code) end @@ -67,7 +67,7 @@ describe Gitlab::Diff::Highlight, lib: true do end it 'marks added lines' do - code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"} + code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"} expect(subject[5].text).to eq(code) expect(subject[5].text).to be_html_safe -- cgit v1.2.1 From f82287e2cc3a57a21be74263be81716c5b3787b7 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 16 Jun 2016 15:15:18 -0700 Subject: use the local lexer variable to respect plain: ... --- lib/gitlab/highlight.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 84bd616d608..fbed65a055b 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -31,7 +31,7 @@ module Gitlab continue = false end - @formatter.format(@lexer.lex(text, continue: continue)).html_safe + @formatter.format(lexer.lex(text, continue: continue)).html_safe rescue @formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe end -- cgit v1.2.1 From e9f191907cb9c9d03b5ad0b67bd3e114f2111a18 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 16 Jun 2016 15:15:34 -0700 Subject: apparently this gets encoded now? --- spec/lib/gitlab/diff/highlight_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/gitlab/diff/highlight_spec.rb b/spec/lib/gitlab/diff/highlight_spec.rb index 4408d5bcdb4..88e4115c453 100644 --- a/spec/lib/gitlab/diff/highlight_spec.rb +++ b/spec/lib/gitlab/diff/highlight_spec.rb @@ -67,7 +67,7 @@ describe Gitlab::Diff::Highlight, lib: true do end it 'marks added lines' do - code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"} + code = %Q{+ raise RuntimeError, "System commands must be given as an array of strings"} expect(subject[5].text).to eq(code) expect(subject[5].text).to be_html_safe -- cgit v1.2.1 From 362d7fde084d0e9eeeeea0c78c2f455c6e86a35b Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 16 Jun 2016 16:05:53 -0700 Subject: bugfix: don't error in css_classes --- lib/banzai/filter/syntax_highlight_filter.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 144d8c175dc..17f9164bcb7 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -19,8 +19,15 @@ module Banzai language = node.attr('class') code = node.text + lexer = Rouge::Lexer.find_fancy(language) + formatter = Rouge::Formatters::HTML.new + css_classes = "code highlight js-syntax-highlight #{lexer.tag}" + begin - highlighted = %<
#{block_code(code, language)}
> + highlighted = '' + highlighted << %<
>
+          highlighted << formatter.format(lexer.lex(code))
+          highlighted << %<
> rescue # Gracefully handle syntax highlighter bugs/errors to ensure # users can still access an issue/comment/etc. @@ -31,10 +38,6 @@ module Banzai replace_parent_pre_element(node, highlighted) end - def css_classes - "code highlight js-syntax-highlight #{lexer.tag}" - end - private def replace_parent_pre_element(node, highlighted) -- cgit v1.2.1 From 001b1ff312df04e014a82fdb831a77cfaf66fd62 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 10:52:11 -0700 Subject: rm spec for a deleted method --- spec/helpers/blob_helper_spec.rb | 14 -------------- 1 file changed, 14 deletions(-) diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index 6d1c02db297..b6e18c6a753 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -54,20 +54,6 @@ describe BlobHelper do end end - describe "#highlighter" do - it 'should highlight continued blocks' do - # Both lines have LC1 as ID since formatter doesn't support continue at the moment - expected = [ - '(make-pathname :defaults name', - ':type "assem"))' - ] - - highlighter = helper.highlighter(blob_name, blob_content, nowrap: true) - result = split_content.map{ |content| highlighter.highlight(content) } - expect(result).to eq(expected) - end - end - describe "#sanitize_svg" do let(:input_svg_path) { File.join(Rails.root, 'spec', 'fixtures', 'unsanitized.svg') } let(:data) { open(input_svg_path).read } -- cgit v1.2.1 From d625f652916c7039797190351d1dc04c6152ce78 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 11:23:10 -0700 Subject: eliminate the final newline in
 blocks

---
 lib/rouge/formatters/html_gitlab.rb | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb
index 31533fc3b8c..b76cf14a536 100644
--- a/lib/rouge/formatters/html_gitlab.rb
+++ b/lib/rouge/formatters/html_gitlab.rb
@@ -12,10 +12,14 @@ module Rouge
       end
 
       def stream(tokens, &b)
+        is_first = true
         token_lines(tokens) do |line|
+          yield "\n" unless is_first
+          is_first = false
+
           yield %<>
           line.each { |token, value| yield span(token, value) }
-          yield %<\n>
+          yield %<>
 
           @line_number += 1
         end
-- 
cgit v1.2.1


From e0ee9dacd1bf6acab6774a2add992ae14fa0e2fc Mon Sep 17 00:00:00 2001
From: "http://jneen.net/" 
Date: Tue, 21 Jun 2016 11:24:12 -0700
Subject: remove uses of the nowrap: feature

---
 spec/helpers/blob_helper_spec.rb | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb
index b6e18c6a753..e5dfa61fa6a 100644
--- a/spec/helpers/blob_helper_spec.rb
+++ b/spec/helpers/blob_helper_spec.rb
@@ -16,19 +16,19 @@ describe BlobHelper do
 
   describe '#highlight' do
     it 'should return plaintext for unknown lexer context' do
-      result = helper.highlight(blob_name, no_context_content, nowrap: true)
-      expect(result).to eq(':type "assem"))')
+      result = helper.highlight(blob_name, no_context_content)
+      expect(result).to eq(%<
:type "assem"))
>) end it 'should highlight single block' do - expected = %Q[(make-pathname :defaults name -:type "assem"))] + expected = %Q[
(make-pathname :defaults name
+:type "assem"))
] - expect(helper.highlight(blob_name, blob_content, nowrap: true)).to eq(expected) + expect(helper.highlight(blob_name, blob_content)).to eq(expected) end it 'should highlight multi-line comments' do - result = helper.highlight(blob_name, multiline_content, nowrap: true) + result = helper.highlight(blob_name, multiline_content) html = Nokogiri::HTML(result) lines = html.search('.s') expect(lines.count).to eq(3) @@ -41,14 +41,14 @@ describe BlobHelper do let(:blob_name) { 'test.diff' } let(:blob_content) { "+aaa\n+bbb\n- ccc\n ddd\n"} let(:expected) do - %q(+aaa + %q(
+aaa
 +bbb
 - ccc
- ddd)
+ ddd
) end it 'should highlight each line properly' do - result = helper.highlight(blob_name, blob_content, nowrap: true) + result = helper.highlight(blob_name, blob_content) expect(result).to eq(expected) end end -- cgit v1.2.1 From 4e3db22fe0a469a8429f50b99a7edde8f5f28312 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 11:48:39 -0700 Subject: don't expect " encoding anymore --- spec/fixtures/parallel_diff_result.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/fixtures/parallel_diff_result.yml b/spec/fixtures/parallel_diff_result.yml index 333eda1191a..37066c8e930 100644 --- a/spec/fixtures/parallel_diff_result.yml +++ b/spec/fixtures/parallel_diff_result.yml @@ -121,7 +121,7 @@ :type: old :number: 9 :text: | - - raise "System commands must be given as an array of strings" + - raise "System commands must be given as an array of strings" :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_9_9 :position: !ruby/object:Gitlab::Diff::Position attributes: @@ -136,7 +136,7 @@ :type: new :number: 9 :text: | - + raise RuntimeError, "System commands must be given as an array of strings" + + raise RuntimeError, "System commands must be given as an array of strings" :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_10_9 :position: !ruby/object:Gitlab::Diff::Position attributes: @@ -241,7 +241,7 @@ :type: old :number: 13 :text: | - - vars = { "PWD" => path } + - vars = { "PWD" => path } :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_13_13 :position: !ruby/object:Gitlab::Diff::Position attributes: @@ -315,7 +315,7 @@ :type: new :number: 15 :text: | - + "PWD" => path + + "PWD" => path :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_15_15 :position: !ruby/object:Gitlab::Diff::Position attributes: @@ -623,7 +623,7 @@ :type: :number: 20 :text: |2 - @cmd_output = "" + @cmd_output = "" :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26 :position: !ruby/object:Gitlab::Diff::Position attributes: @@ -638,7 +638,7 @@ :type: :number: 26 :text: |2 - @cmd_output = "" + @cmd_output = "" :line_code: 2f6fcd96b88b36ce98c38da085c795a27d92a3dd_20_26 :position: !ruby/object:Gitlab::Diff::Position attributes: -- cgit v1.2.1 From ca32a542d7a36c1d27fc8851534a0c15048a79dd Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 11:51:29 -0700 Subject: don't expect a random newline at the end of the thing? --- spec/lib/banzai/filter/syntax_highlight_filter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index 407617f3307..50be175c1c3 100644 --- a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -5,7 +5,7 @@ describe Banzai::Filter::SyntaxHighlightFilter, lib: true do it 'highlights valid code blocks' do result = filter('
def fun end')
-    expect(result.to_html).to eq("
def fun end
\n") + expect(result.to_html).to eq("
def fun end
") end it 'passes through invalid code blocks' do -- cgit v1.2.1 From 2f0b29227d15bc30b2f13ee415ba83d052fd7f68 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 13:08:24 -0700 Subject: stub out errors from the formatter since we've eliminated #block_code --- spec/lib/banzai/filter/syntax_highlight_filter_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index 50be175c1c3..48ebc81cf82 100644 --- a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -9,7 +9,7 @@ describe Banzai::Filter::SyntaxHighlightFilter, lib: true do end it 'passes through invalid code blocks' do - allow_any_instance_of(described_class).to receive(:block_code).and_raise(StandardError) + allow_any_instance_of(Rouge::Formatter).to receive(:format).and_raise(StandardError) result = filter('
This is a test
') expect(result.to_html).to eq('
This is a test
') -- cgit v1.2.1 From 734ed9c59a486651820907051fbee149898f01e4 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Tue, 21 Jun 2016 13:12:21 -0700 Subject: expect final newlines from the banzai filter --- spec/helpers/events_helper_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/events_helper_spec.rb b/spec/helpers/events_helper_spec.rb index c0d2be98e85..6b5e3d93d48 100644 --- a/spec/helpers/events_helper_spec.rb +++ b/spec/helpers/events_helper_spec.rb @@ -57,7 +57,7 @@ describe EventsHelper do expected = '
' \
         "def test\n" \
         "  \'hello world\'\n" \
-        "end" \
+        "end\n" \
         '
' expect(helper.event_note(input)).to eq(expected) end -- cgit v1.2.1 From 7ceb9913aa87f1691411d725417e1fd1aadacb9b Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Mon, 27 Jun 2016 13:19:11 -0700 Subject: update to rouge 2.0.2 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 1514bde61ab..d87decc324e 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -578,7 +578,7 @@ GEM railties (>= 4.2.0, < 5.1) rinku (2.0.0) rotp (2.1.2) - rouge (2.0.1) + rouge (2.0.2) rqrcode (0.7.0) chunky_png rqrcode-rails3 (0.1.7) -- cgit v1.2.1 From d54a281e3d1c543f4cbd550c62f62d225f595bbb Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 12 Jul 2016 16:40:05 -0300 Subject: Fix creating group with space in group path --- app/views/layouts/_search.html.haml | 2 +- spec/features/groups_spec.rb | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/app/views/layouts/_search.html.haml b/app/views/layouts/_search.html.haml index 245b9c3b4d4..f7580f00159 100644 --- a/app/views/layouts/_search.html.haml +++ b/app/views/layouts/_search.html.haml @@ -44,7 +44,7 @@ name: "#{j(@project.name)}" }; - - if @group and @group.path + - if @group && @group.persisted? && @group.path :javascript gl.groupOptions = gl.groupOptions || {}; gl.groupOptions["#{j(@group.path)}"] = { diff --git a/spec/features/groups_spec.rb b/spec/features/groups_spec.rb index 891df65216d..2d8b59472e8 100644 --- a/spec/features/groups_spec.rb +++ b/spec/features/groups_spec.rb @@ -1,14 +1,26 @@ require 'spec_helper' feature 'Group', feature: true do + before do + login_as(:admin) + end + + describe 'creating a group with space in group path' do + it 'renders new group form with validation errors' do + visit new_group_path + fill_in 'Group path', with: 'space group' + + click_button 'Create group' + + expect(current_path).to eq(groups_path) + expect(page).to have_content("Path can contain only letters, digits, '_', '-' and '.'. Cannot start with '-' or end in '.'.") + end + end + describe 'description' do let(:group) { create(:group) } let(:path) { group_path(group) } - before do - login_as(:admin) - end - it 'parses Markdown' do group.update_attribute(:description, 'This is **my** group') visit path -- cgit v1.2.1 From e367bbff164cef36fcb4d5f819714347ed9a2ebd Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Tue, 12 Jul 2016 16:40:37 -0300 Subject: Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 6b24b2c5b32..7e784bd641d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -91,6 +91,7 @@ v 8.10.0 (unreleased) - Redesign Builds and Pipelines pages - Change status color and icon for running builds - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` + - Fix creating group with space in group path v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 -- cgit v1.2.1 From 822304b19f81386a36eb7175f7384e2a8c5fd5e1 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 11:40:55 -0700 Subject: fix Gitlab::Highlight#initializer bugs from rebase --- lib/gitlab/highlight.rb | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index fbed65a055b..57b7fc139f8 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -13,9 +13,10 @@ module Gitlab highlight(file_name, blob.data, repository: repository).lines.map!(&:html_safe) end - def initialize(blob_name, blob_content) + def initialize(blob_name, blob_content, repository: nil) @formatter = Rouge::Formatters::HTMLGitlab.new @repository = repository + @blob_name = blob_name @lexer = custom_language || begin Rouge::Lexer.guess(filename: blob_name, source: blob_content).new rescue Rouge::Lexer::AmbiguousGuess => e -- cgit v1.2.1 From b468672d7634b13b2a2bea5685a5e1cbc9d82c23 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 11:44:59 -0700 Subject: style: factor out `@lexer` into a method --- lib/gitlab/highlight.rb | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index 57b7fc139f8..a9e429a29f4 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -17,26 +17,30 @@ module Gitlab @formatter = Rouge::Formatters::HTMLGitlab.new @repository = repository @blob_name = blob_name - @lexer = custom_language || begin - Rouge::Lexer.guess(filename: blob_name, source: blob_content).new - rescue Rouge::Lexer::AmbiguousGuess => e - e.alternatives.sort_by(&:tag).first - end + @blob_content = blob_content end def highlight(text, continue: true, plain: false) - lexer = @lexer - if plain - lexer = Rouge::Lexers::PlainText + hl_lexer = Rouge::Lexers::PlainText continue = false + else + hl_lexer = self.lexer end - @formatter.format(lexer.lex(text, continue: continue)).html_safe + @formatter.format(hl_lexer.lex(text, continue: continue)).html_safe rescue @formatter.format(Rouge::Lexers::PlainText.lex(text)).html_safe end + def lexer + @lexer ||= custom_language || begin + Rouge::Lexer.guess(filename: blob_name, source: blob_content).new + rescue Rouge::Lexer::AmbiguousGuess => e + e.alternatives.sort_by(&:tag).first + end + end + private def custom_language -- cgit v1.2.1 From f7f082f46c919e5c8c730a2c2ab0a7baf086b01b Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 12:19:39 -0700 Subject: bump rouge to 2.0.3 --- Gemfile.lock | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index d87decc324e..eab04ec3a25 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -578,7 +578,7 @@ GEM railties (>= 4.2.0, < 5.1) rinku (2.0.0) rotp (2.1.2) - rouge (2.0.2) + rouge (2.0.3) rqrcode (0.7.0) chunky_png rqrcode-rails3 (0.1.7) -- cgit v1.2.1 From c763c7e402599a2789e260ecf61c11c68381aaa5 Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 12:21:22 -0700 Subject: use the proper variable names o_O --- lib/gitlab/highlight.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/gitlab/highlight.rb b/lib/gitlab/highlight.rb index a9e429a29f4..9360afedfcb 100644 --- a/lib/gitlab/highlight.rb +++ b/lib/gitlab/highlight.rb @@ -35,8 +35,8 @@ module Gitlab def lexer @lexer ||= custom_language || begin - Rouge::Lexer.guess(filename: blob_name, source: blob_content).new - rescue Rouge::Lexer::AmbiguousGuess => e + Rouge::Lexer.guess(filename: @blob_name, source: @blob_content).new + rescue Rouge::Guesser::Ambiguous => e e.alternatives.sort_by(&:tag).first end end -- cgit v1.2.1 From 01ff8ae5df7e00db16aa64f056098626b8ae795b Mon Sep 17 00:00:00 2001 From: winniehell Date: Thu, 14 Jul 2016 23:43:27 +0200 Subject: Display tooltip for mentioned users and groups (!5261) --- CHANGELOG | 1 + lib/banzai/filter/user_reference_filter.rb | 10 +++++----- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 6b24b2c5b32..eeb2d377bf6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -22,6 +22,7 @@ v 8.10.0 (unreleased) - Add Sidekiq queue duration to transaction metrics. - Add a new column `artifacts_size` to table `ci_builds` !4964 - Let Workhorse serve format-patch diffs + - Display tooltip for mentioned users and groups !5261 (winniehell) - Added day name to contribution calendar tooltips - Make images fit to the size of the viewport !4810 - Fix check for New Branch button on Issue page !4630 (winniehell) diff --git a/lib/banzai/filter/user_reference_filter.rb b/lib/banzai/filter/user_reference_filter.rb index 5b0a6d8541b..e1ca7f4d24b 100644 --- a/lib/banzai/filter/user_reference_filter.rb +++ b/lib/banzai/filter/user_reference_filter.rb @@ -112,7 +112,7 @@ module Banzai data = data_attribute(project: project.id, author: author.try(:id)) text = link_text || User.reference_prefix + 'all' - link_tag(url, data, text) + link_tag(url, data, text, 'All Project and Group Members') end def link_to_namespace(namespace, link_text: nil) @@ -128,7 +128,7 @@ module Banzai data = data_attribute(group: namespace.id) text = link_text || Group.reference_prefix + group - link_tag(url, data, text) + link_tag(url, data, text, namespace.name) end def link_to_user(user, namespace, link_text: nil) @@ -136,11 +136,11 @@ module Banzai data = data_attribute(user: namespace.owner_id) text = link_text || User.reference_prefix + user - link_tag(url, data, text) + link_tag(url, data, text, namespace.owner_name) end - def link_tag(url, data, text) - %(#{escape_once(text)}) + def link_tag(url, data, text, title) + %(#{escape_once(text)}) end end end -- cgit v1.2.1 From e5c7e11840871e3138ad32693d86de8d7cd7c670 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 14 Jul 2016 18:39:08 -0700 Subject: Disable PostgreSQL statement timeout during migrations Long-running migrations may take more than the timeout allowed by the database. Disable the session's statement timeout to ensure migrations don't get killed prematurely. --- CHANGELOG | 1 + lib/gitlab/database/migration_helpers.rb | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 19286abd74f..23f8bfa5d34 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,7 @@ Please view this file on the master branch, on stable branches it's out of date. v 8.10.0 (unreleased) - Expose {should,force}_remove_source_branch (Ben Boeckel) + - Disable PostgreSQL statement timeout during migrations - Fix projects dropdown loading performance with a simplified api cal. !5113 (tiagonbotelho) - Fix commit builds API, return all builds for all pipelines for given commit. !4849 - Replace Haml with Hamlit to make view rendering faster. !3666 diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index dec20d8659b..593ee5d9568 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -25,6 +25,13 @@ module Gitlab add_index(table_name, column_name, options) end + # Long-running migrations may take more than the timeout allowed by + # the database. Disable the session's statement timeout to ensure + # migrations don't get killed prematurely. (PostgreSQL only) + def disable_statement_timeout + ActiveRecord::Base.connection.execute('SET statement_timeout TO 0') if Database.postgresql? + end + # Updates the value of a column in batches. # # This method updates the table in batches of 5% of the total row count. @@ -134,6 +141,7 @@ module Gitlab end transaction do + disable_statement_timeout add_column(table, column, type, default: nil) # Changing the default before the update ensures any newly inserted -- cgit v1.2.1 From f700f3ec5d524afd1575a27da76b39b08947b7ea Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 14 Jul 2016 18:50:46 -0700 Subject: Disable statement timeout outside of transaction and during adding concurrent index --- lib/gitlab/database/migration_helpers.rb | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/lib/gitlab/database/migration_helpers.rb b/lib/gitlab/database/migration_helpers.rb index 593ee5d9568..927f9dad20b 100644 --- a/lib/gitlab/database/migration_helpers.rb +++ b/lib/gitlab/database/migration_helpers.rb @@ -20,6 +20,7 @@ module Gitlab if Database.postgresql? options = options.merge({ algorithm: :concurrently }) + disable_statement_timeout end add_index(table_name, column_name, options) @@ -140,8 +141,9 @@ module Gitlab 'in the body of your migration class' end + disable_statement_timeout + transaction do - disable_statement_timeout add_column(table, column, type, default: nil) # Changing the default before the update ensures any newly inserted -- cgit v1.2.1 From 3fd304c1a5063ad9fd53b851de79322f49c68997 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Thu, 14 Jul 2016 20:55:33 -0700 Subject: Fix spec Don't attempt to disable statement timeout on a MySQL DB --- spec/lib/gitlab/database/migration_helpers_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/lib/gitlab/database/migration_helpers_spec.rb b/spec/lib/gitlab/database/migration_helpers_spec.rb index 9096ad101b0..4ec3f19e03f 100644 --- a/spec/lib/gitlab/database/migration_helpers_spec.rb +++ b/spec/lib/gitlab/database/migration_helpers_spec.rb @@ -13,6 +13,10 @@ describe Gitlab::Database::MigrationHelpers, lib: true do context 'outside a transaction' do before do expect(model).to receive(:transaction_open?).and_return(false) + + unless Gitlab::Database.postgresql? + allow_any_instance_of(Gitlab::Database::MigrationHelpers).to receive(:disable_statement_timeout) + end end context 'using PostgreSQL' do -- cgit v1.2.1 From c4ea394736f98aebd6b370d75a5b3556206ce09d Mon Sep 17 00:00:00 2001 From: "http://jneen.net/" Date: Thu, 14 Jul 2016 22:43:49 -0700 Subject: use %(...) and %[...] in favor of %<...> --- app/helpers/blob_helper.rb | 2 +- lib/banzai/filter/syntax_highlight_filter.rb | 4 ++-- lib/rouge/formatters/html_gitlab.rb | 4 ++-- spec/helpers/blob_helper_spec.rb | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app/helpers/blob_helper.rb b/app/helpers/blob_helper.rb index 39f9f935d31..abe115d8c68 100644 --- a/app/helpers/blob_helper.rb +++ b/app/helpers/blob_helper.rb @@ -1,7 +1,7 @@ module BlobHelper def highlight(blob_name, blob_content, repository: nil, plain: false) highlighted = Gitlab::Highlight.highlight(blob_name, blob_content, plain: plain, repository: repository) - raw %<
#{highlighted}
> + raw %(
#{highlighted}
) end def no_highlight_files diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 17f9164bcb7..028edef704b 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -25,9 +25,9 @@ module Banzai begin highlighted = '' - highlighted << %<
>
+          highlighted << %(
)
           highlighted << formatter.format(lexer.lex(code))
-          highlighted << %<
> + highlighted << %(
) rescue # Gracefully handle syntax highlighter bugs/errors to ensure # users can still access an issue/comment/etc. diff --git a/lib/rouge/formatters/html_gitlab.rb b/lib/rouge/formatters/html_gitlab.rb index b76cf14a536..f818dc78d34 100644 --- a/lib/rouge/formatters/html_gitlab.rb +++ b/lib/rouge/formatters/html_gitlab.rb @@ -17,9 +17,9 @@ module Rouge yield "\n" unless is_first is_first = false - yield %<> + yield %() line.each { |token, value| yield span(token, value) } - yield %<> + yield %() @line_number += 1 end diff --git a/spec/helpers/blob_helper_spec.rb b/spec/helpers/blob_helper_spec.rb index e5dfa61fa6a..bd0108f9938 100644 --- a/spec/helpers/blob_helper_spec.rb +++ b/spec/helpers/blob_helper_spec.rb @@ -17,7 +17,7 @@ describe BlobHelper do describe '#highlight' do it 'should return plaintext for unknown lexer context' do result = helper.highlight(blob_name, no_context_content) - expect(result).to eq(%<
:type "assem"))
>) + expect(result).to eq(%[
:type "assem"))
]) end it 'should highlight single block' do -- cgit v1.2.1 From 65549a5866da6ceaf7ee4052736077879b5e641d Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 15 Jul 2016 12:47:06 +0200 Subject: add project name and namespace to filename on project export added changelog --- CHANGELOG | 1 + .../projects/import_export/export_service.rb | 2 +- lib/gitlab/import_export.rb | 7 +++++++ lib/gitlab/import_export/saver.rb | 5 +++-- spec/lib/gitlab/import_export/import_export_spec.rb | 21 +++++++++++++++++++++ 5 files changed, 33 insertions(+), 3 deletions(-) create mode 100644 spec/lib/gitlab/import_export/import_export_spec.rb diff --git a/CHANGELOG b/CHANGELOG index 51f1db07e8b..49792d2950f 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -93,6 +93,7 @@ v 8.10.0 (unreleased) - Redesign Builds and Pipelines pages - Change status color and icon for running builds - Fix markdown rendering for: consecutive labels references, label references that begin with a digit or contains `.` + - Project export filename now includes the project and namespace path v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 diff --git a/app/services/projects/import_export/export_service.rb b/app/services/projects/import_export/export_service.rb index 6afc048576d..998789d64d2 100644 --- a/app/services/projects/import_export/export_service.rb +++ b/app/services/projects/import_export/export_service.rb @@ -10,7 +10,7 @@ module Projects def save_all if [version_saver, project_tree_saver, uploads_saver, repo_saver, wiki_repo_saver].all?(&:save) - Gitlab::ImportExport::Saver.save(shared: @shared) + Gitlab::ImportExport::Saver.save(project: project, shared: @shared) notify_success else cleanup_and_notify diff --git a/lib/gitlab/import_export.rb b/lib/gitlab/import_export.rb index 588647e5adb..bab2ea73c4f 100644 --- a/lib/gitlab/import_export.rb +++ b/lib/gitlab/import_export.rb @@ -3,6 +3,7 @@ module Gitlab extend self VERSION = '0.1.1' + FILENAME_LIMIT = 50 def export_path(relative_path:) File.join(storage_path, relative_path) @@ -28,6 +29,12 @@ module Gitlab 'VERSION' end + def export_filename(project:) + basename = "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_#{project.namespace.path}_#{project.path}" + + "#{basename[0..FILENAME_LIMIT]}_export.tar.gz" + end + def version VERSION end diff --git a/lib/gitlab/import_export/saver.rb b/lib/gitlab/import_export/saver.rb index 6a60b65071f..6130c124dd1 100644 --- a/lib/gitlab/import_export/saver.rb +++ b/lib/gitlab/import_export/saver.rb @@ -7,7 +7,8 @@ module Gitlab new(*args).save end - def initialize(shared:) + def initialize(project:, shared:) + @project = project @shared = shared end @@ -36,7 +37,7 @@ module Gitlab end def archive_file - @archive_file ||= File.join(@shared.export_path, '..', "#{Time.now.strftime('%Y-%m-%d_%H-%M-%3N')}_project_export.tar.gz") + @archive_file ||= File.join(@shared.export_path, '..', Gitlab::ImportExport.export_filename(project: @project)) end end end diff --git a/spec/lib/gitlab/import_export/import_export_spec.rb b/spec/lib/gitlab/import_export/import_export_spec.rb new file mode 100644 index 00000000000..d6409a29550 --- /dev/null +++ b/spec/lib/gitlab/import_export/import_export_spec.rb @@ -0,0 +1,21 @@ +require 'spec_helper' + +describe Gitlab::ImportExport, services: true do + describe 'export filename' do + let(:project) { create(:project, :public, path: 'project-path') } + + it 'contains the project path' do + expect(described_class.export_filename(project: project)).to include(project.path) + end + + it 'contains the namespace path' do + expect(described_class.export_filename(project: project)).to include(project.namespace.path) + end + + it 'does not go over a certain length' do + project.path = 'a' * 100 + + expect(described_class.export_filename(project: project).length).to be < 70 + end + end +end -- cgit v1.2.1 From 86f39fece2273319e2c960d96b131924a9fbdc3c Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 14:01:34 +0200 Subject: Refactor LFS specs to use requests instead of LfsRouter --- spec/lib/gitlab/lfs/lfs_router_spec.rb | 730 ------------------------------- spec/requests/lfs_http_spec.rb | 763 +++++++++++++++++++++++++++++++++ 2 files changed, 763 insertions(+), 730 deletions(-) delete mode 100644 spec/lib/gitlab/lfs/lfs_router_spec.rb create mode 100644 spec/requests/lfs_http_spec.rb diff --git a/spec/lib/gitlab/lfs/lfs_router_spec.rb b/spec/lib/gitlab/lfs/lfs_router_spec.rb deleted file mode 100644 index 659facd6c19..00000000000 --- a/spec/lib/gitlab/lfs/lfs_router_spec.rb +++ /dev/null @@ -1,730 +0,0 @@ -require 'spec_helper' - -describe Gitlab::Lfs::Router, lib: true do - let(:project) { create(:project) } - let(:public_project) { create(:project, :public) } - let(:forked_project) { fork_project(public_project, user) } - - let(:user) { create(:user) } - let(:user_two) { create(:user) } - let!(:lfs_object) { create(:lfs_object, :with_file) } - - let(:request) { Rack::Request.new(env) } - let(:env) do - { - 'rack.input' => '', - 'REQUEST_METHOD' => 'GET', - } - end - - let(:lfs_router_auth) { new_lfs_router(project, user: user) } - let(:lfs_router_ci_auth) { new_lfs_router(project, ci: true) } - let(:lfs_router_noauth) { new_lfs_router(project) } - let(:lfs_router_public_auth) { new_lfs_router(public_project, user: user) } - let(:lfs_router_public_ci_auth) { new_lfs_router(public_project, ci: true) } - let(:lfs_router_public_noauth) { new_lfs_router(public_project) } - let(:lfs_router_forked_noauth) { new_lfs_router(forked_project) } - let(:lfs_router_forked_auth) { new_lfs_router(forked_project, user: user_two) } - let(:lfs_router_forked_ci_auth) { new_lfs_router(forked_project, ci: true) } - - let(:sample_oid) { "b68143e6463773b1b6c6fd009a76c32aeec041faff32ba2ed42fd7f708a17f80" } - let(:sample_size) { 499013 } - let(:respond_with_deprecated) {[ 501, { "Content-Type" => "application/json; charset=utf-8" }, ["{\"message\":\"Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.\",\"documentation_url\":\"#{Gitlab.config.gitlab.url}/help\"}"]]} - let(:respond_with_disabled) {[ 501, { "Content-Type" => "application/json; charset=utf-8" }, ["{\"message\":\"Git LFS is not enabled on this GitLab server, contact your admin.\",\"documentation_url\":\"#{Gitlab.config.gitlab.url}/help\"}"]]} - - describe 'when lfs is disabled' do - before do - allow(Gitlab.config.lfs).to receive(:enabled).and_return(false) - env['REQUEST_METHOD'] = 'POST' - body = { - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 - }, - { 'oid' => sample_oid, - 'size' => sample_size - } - ], - 'operation' => 'upload' - }.to_json - env['rack.input'] = StringIO.new(body) - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/info/lfs/objects/batch" - end - - it 'responds with 501' do - expect(lfs_router_auth.try_call).to match_array(respond_with_disabled) - end - end - - describe 'when fetching lfs object using deprecated API' do - before do - enable_lfs - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/info/lfs/objects/#{sample_oid}" - end - - it 'responds with 501' do - expect(lfs_router_auth.try_call).to match_array(respond_with_deprecated) - end - end - - describe 'when fetching lfs object' do - before do - enable_lfs - env['HTTP_ACCEPT'] = "application/vnd.git-lfs+json; charset=utf-8" - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/gitlab-lfs/objects/#{sample_oid}" - end - - describe 'and request comes from gitlab-workhorse' do - context 'without user being authorized' do - it "responds with status 401" do - expect(lfs_router_noauth.try_call.first).to eq(401) - end - end - - context 'with required headers' do - before do - project.lfs_objects << lfs_object - env['HTTP_X_SENDFILE_TYPE'] = "X-Sendfile" - end - - context 'when user does not have project access' do - it "responds with status 403" do - expect(lfs_router_auth.try_call.first).to eq(403) - end - end - - context 'when user has project access' do - before do - project.team << [user, :master] - end - - it "responds with status 200" do - expect(lfs_router_auth.try_call.first).to eq(200) - end - - it "responds with the file location" do - expect(lfs_router_auth.try_call[1]['Content-Type']).to eq("application/octet-stream") - expect(lfs_router_auth.try_call[1]['X-Sendfile']).to eq(lfs_object.file.path) - end - end - - context 'when CI is authorized' do - it "responds with status 200" do - expect(lfs_router_ci_auth.try_call.first).to eq(200) - end - - it "responds with the file location" do - expect(lfs_router_ci_auth.try_call[1]['Content-Type']).to eq("application/octet-stream") - expect(lfs_router_ci_auth.try_call[1]['X-Sendfile']).to eq(lfs_object.file.path) - end - end - end - - context 'without required headers' do - it "responds with status 403" do - expect(lfs_router_auth.try_call.first).to eq(403) - end - end - end - end - - describe 'when handling lfs request using deprecated API' do - before do - enable_lfs - env['REQUEST_METHOD'] = 'POST' - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/info/lfs/objects" - end - - it 'responds with 501' do - expect(lfs_router_auth.try_call).to match_array(respond_with_deprecated) - end - end - - describe 'when handling lfs batch request' do - before do - enable_lfs - env['REQUEST_METHOD'] = 'POST' - env['PATH_INFO'] = "#{project.repository.path_with_namespace}.git/info/lfs/objects/batch" - end - - describe 'download' do - before do - body = { 'operation' => 'download', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size - }] - }.to_json - env['rack.input'] = StringIO.new(body) - end - - shared_examples 'an authorized requests' do - context 'when downloading an lfs object that is assigned to our project' do - before do - project.lfs_objects << lfs_object - end - - it 'responds with status 200 and href to download' do - response = router.try_call - expect(response.first).to eq(200) - response_body = ActiveSupport::JSON.decode(response.last.first) - - expect(response_body).to eq('objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size, - 'actions' => { - 'download' => { - 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => { 'Authorization' => auth } - } - } - }]) - end - end - - context 'when downloading an lfs object that is assigned to other project' do - before do - public_project.lfs_objects << lfs_object - end - - it 'responds with status 200 and error message' do - response = router.try_call - expect(response.first).to eq(200) - response_body = ActiveSupport::JSON.decode(response.last.first) - - expect(response_body).to eq('objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it", - } - }]) - end - end - - context 'when downloading a lfs object that does not exist' do - before do - body = { 'operation' => 'download', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 - }] - }.to_json - env['rack.input'] = StringIO.new(body) - end - - it "responds with status 200 and error message" do - response = router.try_call - expect(response.first).to eq(200) - response_body = ActiveSupport::JSON.decode(response.last.first) - - expect(response_body).to eq('objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it", - } - }]) - end - end - - context 'when downloading one new and one existing lfs object' do - before do - body = { 'operation' => 'download', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 - }, - { 'oid' => sample_oid, - 'size' => sample_size - } - ] - }.to_json - env['rack.input'] = StringIO.new(body) - project.lfs_objects << lfs_object - end - - it "responds with status 200 with upload hypermedia link for the new object" do - response = router.try_call - expect(response.first).to eq(200) - response_body = ActiveSupport::JSON.decode(response.last.first) - - expect(response_body).to eq('objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078, - 'error' => { - 'code' => 404, - 'message' => "Object does not exist on the server or you don't have permissions to access it", - } - }, - { 'oid' => sample_oid, - 'size' => sample_size, - 'actions' => { - 'download' => { - 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => { 'Authorization' => auth } - } - } - }]) - end - end - end - - context 'when user is authenticated' do - let(:auth) { authorize(user) } - - before do - env["HTTP_AUTHORIZATION"] = auth - project.team << [user, role] - end - - it_behaves_like 'an authorized requests' do - let(:role) { :reporter } - let(:router) { lfs_router_auth } - end - - context 'when user does is not member of the project' do - let(:role) { :guest } - - it 'responds with 403' do - expect(lfs_router_auth.try_call.first).to eq(403) - end - end - - context 'when user does not have download access' do - let(:role) { :guest } - - it 'responds with 403' do - expect(lfs_router_auth.try_call.first).to eq(403) - end - end - end - - context 'when CI is authorized' do - let(:auth) { 'gitlab-ci-token:password' } - - before do - env["HTTP_AUTHORIZATION"] = auth - end - - it_behaves_like 'an authorized requests' do - let(:router) { lfs_router_ci_auth } - end - end - - context 'when user is not authenticated' do - describe 'is accessing public project' do - before do - public_project.lfs_objects << lfs_object - end - - it 'responds with status 200 and href to download' do - response = lfs_router_public_noauth.try_call - expect(response.first).to eq(200) - response_body = ActiveSupport::JSON.decode(response.last.first) - - expect(response_body).to eq('objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size, - 'actions' => { - 'download' => { - 'href' => "#{public_project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", - 'header' => {} - } - } - }]) - end - end - - describe 'is accessing non-public project' do - before do - project.lfs_objects << lfs_object - end - - it 'responds with authorization required' do - expect(lfs_router_noauth.try_call.first).to eq(401) - end - end - end - end - - describe 'upload' do - before do - body = { 'operation' => 'upload', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size - }] - }.to_json - env['rack.input'] = StringIO.new(body) - end - - describe 'when request is authenticated' do - describe 'when user has project push access' do - before do - @auth = authorize(user) - env["HTTP_AUTHORIZATION"] = @auth - project.team << [user, :developer] - end - - context 'when pushing an lfs object that already exists' do - before do - public_project.lfs_objects << lfs_object - end - - it "responds with status 200 and links the object to the project" do - response_body = lfs_router_auth.try_call.last - response = ActiveSupport::JSON.decode(response_body.first) - - expect(response['objects']).to be_kind_of(Array) - expect(response['objects'].first['oid']).to eq(sample_oid) - expect(response['objects'].first['size']).to eq(sample_size) - expect(lfs_object.projects.pluck(:id)).not_to include(project.id) - expect(lfs_object.projects.pluck(:id)).to include(public_project.id) - expect(response['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") - expect(response['objects'].first['actions']['upload']['header']).to eq('Authorization' => @auth) - end - end - - context 'when pushing a lfs object that does not exist' do - before do - body = { 'operation' => 'upload', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 - }] - }.to_json - env['rack.input'] = StringIO.new(body) - end - - it "responds with status 200 and upload hypermedia link" do - response = lfs_router_auth.try_call - expect(response.first).to eq(200) - - response_body = ActiveSupport::JSON.decode(response.last.first) - expect(response_body['objects']).to be_kind_of(Array) - expect(response_body['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") - expect(response_body['objects'].first['size']).to eq(1575078) - expect(lfs_object.projects.pluck(:id)).not_to include(project.id) - expect(response_body['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") - expect(response_body['objects'].first['actions']['upload']['header']).to eq('Authorization' => @auth) - end - end - - context 'when pushing one new and one existing lfs object' do - before do - body = { 'operation' => 'upload', - 'objects' => [ - { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', - 'size' => 1575078 - }, - { 'oid' => sample_oid, - 'size' => sample_size - } - ] - }.to_json - env['rack.input'] = StringIO.new(body) - project.lfs_objects << lfs_object - end - - it "responds with status 200 with upload hypermedia link for the new object" do - response = lfs_router_auth.try_call - expect(response.first).to eq(200) - - response_body = ActiveSupport::JSON.decode(response.last.first) - expect(response_body['objects']).to be_kind_of(Array) - - expect(response_body['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") - expect(response_body['objects'].first['size']).to eq(1575078) - expect(response_body['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") - expect(response_body['objects'].first['actions']['upload']['header']).to eq("Authorization" => @auth) - - expect(response_body['objects'].last['oid']).to eq(sample_oid) - expect(response_body['objects'].last['size']).to eq(sample_size) - expect(response_body['objects'].last).not_to have_key('actions') - end - end - end - - context 'when user does not have push access' do - it 'responds with 403' do - expect(lfs_router_auth.try_call.first).to eq(403) - end - end - - context 'when CI is authorized' do - it 'responds with 401' do - expect(lfs_router_ci_auth.try_call.first).to eq(401) - end - end - end - - context 'when user is not authenticated' do - context 'when user has push access' do - before do - project.team << [user, :master] - end - - it "responds with status 401" do - expect(lfs_router_public_noauth.try_call.first).to eq(401) - end - end - - context 'when user does not have push access' do - it "responds with status 401" do - expect(lfs_router_public_noauth.try_call.first).to eq(401) - end - end - end - - context 'when CI is authorized' do - let(:auth) { 'gitlab-ci-token:password' } - - before do - env["HTTP_AUTHORIZATION"] = auth - end - - it "responds with status 403" do - expect(lfs_router_public_ci_auth.try_call.first).to eq(401) - end - end - end - - describe 'unsupported' do - before do - body = { 'operation' => 'other', - 'objects' => [ - { 'oid' => sample_oid, - 'size' => sample_size - }] - }.to_json - env['rack.input'] = StringIO.new(body) - end - - it 'responds with status 404' do - expect(lfs_router_public_noauth.try_call.first).to eq(404) - end - end - end - - describe 'when pushing a lfs object' do - before do - enable_lfs - env['REQUEST_METHOD'] = 'PUT' - end - - shared_examples 'unauthorized' do - context 'and request is sent by gitlab-workhorse to authorize the request' do - before do - header_for_upload_authorize(router.project) - end - - it 'responds with status 401' do - expect(router.try_call.first).to eq(401) - end - end - - context 'and request is sent by gitlab-workhorse to finalize the upload' do - before do - headers_for_upload_finalize(router.project) - end - - it 'responds with status 401' do - expect(router.try_call.first).to eq(401) - end - end - - context 'and request is sent with a malformed headers' do - before do - env["PATH_INFO"] = "#{router.project.repository.path_with_namespace}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}" - env["HTTP_X_GITLAB_LFS_TMP"] = "cat /etc/passwd" - end - - it 'does not recognize it as a valid lfs command' do - expect(router.try_call).to eq(nil) - end - end - end - - shared_examples 'forbidden' do - context 'and request is sent by gitlab-workhorse to authorize the request' do - before do - header_for_upload_authorize(router.project) - end - - it 'responds with 403' do - expect(router.try_call.first).to eq(403) - end - end - - context 'and request is sent by gitlab-workhorse to finalize the upload' do - before do - headers_for_upload_finalize(router.project) - end - - it 'responds with 403' do - expect(router.try_call.first).to eq(403) - end - end - end - - describe 'to one project' do - describe 'when user is authenticated' do - describe 'when user has push access to the project' do - before do - project.team << [user, :developer] - end - - context 'and request is sent by gitlab-workhorse to authorize the request' do - before do - header_for_upload_authorize(project) - end - - it 'responds with status 200, location of lfs store and object details' do - json_response = ActiveSupport::JSON.decode(lfs_router_auth.try_call.last.first) - - expect(lfs_router_auth.try_call.first).to eq(200) - expect(json_response['StoreLFSPath']).to eq("#{Gitlab.config.shared.path}/lfs-objects/tmp/upload") - expect(json_response['LfsOid']).to eq(sample_oid) - expect(json_response['LfsSize']).to eq(sample_size) - end - end - - context 'and request is sent by gitlab-workhorse to finalize the upload' do - before do - headers_for_upload_finalize(project) - end - - it 'responds with status 200 and lfs object is linked to the project' do - expect(lfs_router_auth.try_call.first).to eq(200) - expect(lfs_object.projects.pluck(:id)).to include(project.id) - end - end - end - - describe 'and user does not have push access' do - let(:router) { lfs_router_auth } - - it_behaves_like 'forbidden' - end - end - - context 'when CI is authenticated' do - let(:router) { lfs_router_ci_auth } - - it_behaves_like 'unauthorized' - end - - context 'for unauthenticated' do - let(:router) { new_lfs_router(project) } - - it_behaves_like 'unauthorized' - end - end - - describe 'to a forked project' do - let(:forked_project) { fork_project(public_project, user) } - - describe 'when user is authenticated' do - describe 'when user has push access to the project' do - before do - forked_project.team << [user_two, :developer] - end - - context 'and request is sent by gitlab-workhorse to authorize the request' do - before do - header_for_upload_authorize(forked_project) - end - - it 'responds with status 200, location of lfs store and object details' do - json_response = ActiveSupport::JSON.decode(lfs_router_forked_auth.try_call.last.first) - - expect(lfs_router_forked_auth.try_call.first).to eq(200) - expect(json_response['StoreLFSPath']).to eq("#{Gitlab.config.shared.path}/lfs-objects/tmp/upload") - expect(json_response['LfsOid']).to eq(sample_oid) - expect(json_response['LfsSize']).to eq(sample_size) - end - end - - context 'and request is sent by gitlab-workhorse to finalize the upload' do - before do - headers_for_upload_finalize(forked_project) - end - - it 'responds with status 200 and lfs object is linked to the source project' do - expect(lfs_router_forked_auth.try_call.first).to eq(200) - expect(lfs_object.projects.pluck(:id)).to include(public_project.id) - end - end - end - - describe 'and user does not have push access' do - let(:router) { lfs_router_forked_auth } - - it_behaves_like 'forbidden' - end - end - - context 'when CI is authenticated' do - let(:router) { lfs_router_forked_ci_auth } - - it_behaves_like 'unauthorized' - end - - context 'for unauthenticated' do - let(:router) { lfs_router_forked_noauth } - - it_behaves_like 'unauthorized' - end - - describe 'and second project not related to fork or a source project' do - let(:second_project) { create(:project) } - let(:lfs_router_second_project) { new_lfs_router(second_project, user: user) } - - before do - public_project.lfs_objects << lfs_object - headers_for_upload_finalize(second_project) - end - - context 'when pushing the same lfs object to the second project' do - before do - second_project.team << [user, :master] - end - - it 'responds with 200 and links the lfs object to the project' do - expect(lfs_router_second_project.try_call.first).to eq(200) - expect(lfs_object.projects.pluck(:id)).to include(second_project.id, public_project.id) - end - end - end - end - end - - def enable_lfs - allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) - end - - def authorize(user) - ActionController::HttpAuthentication::Basic.encode_credentials(user.username, user.password) - end - - def new_lfs_router(project, user: nil, ci: false) - Gitlab::Lfs::Router.new(project, user, ci, request) - end - - def header_for_upload_authorize(project) - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}/authorize" - end - - def headers_for_upload_finalize(project) - env["PATH_INFO"] = "#{project.repository.path_with_namespace}.git/gitlab-lfs/objects/#{sample_oid}/#{sample_size}" - env["HTTP_X_GITLAB_LFS_TMP"] = "#{sample_oid}6e561c9d4" - end - - def fork_project(project, user, object = nil) - allow(RepositoryForkWorker).to receive(:perform_async).and_return(true) - Projects::ForkService.new(project, user, {}).execute - end -end diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb new file mode 100644 index 00000000000..d862cb5b0b4 --- /dev/null +++ b/spec/requests/lfs_http_spec.rb @@ -0,0 +1,763 @@ +require 'spec_helper' + +describe Gitlab::Lfs::Router do + let(:user) { create(:user) } + let!(:lfs_object) { create(:lfs_object, :with_file) } + + let(:headers) do + { + 'Authorization' => authorization, + 'X-Sendfile-Type' => sendfile + }.compact + end + let(:authorization) { } + let(:sendfile) { } + + let(:sample_oid) { lfs_object.oid } + let(:sample_size) { lfs_object.size } + + describe 'when lfs is disabled' do + let(:project) { create(:empty_project) } + let(:body) do + { + 'objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078 + }, + { 'oid' => sample_oid, + 'size' => sample_size + } + ], + 'operation' => 'upload' + } + end + + before do + allow(Gitlab.config.lfs).to receive(:enabled).and_return(false) + post_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers + end + + it 'responds with 501' do + expect(response).to have_http_status(501) + expect(json_response).to include('message' => 'Git LFS is not enabled on this GitLab server, contact your admin.') + end + end + + describe 'deprecated API' do + let(:project) { create(:empty_project) } + + before do + enable_lfs + end + + shared_examples 'a deprecated' do + it 'responds with 501' do + expect(response).to have_http_status(501) + end + + it 'returns deprecated message' do + expect(json_response).to include('message' => 'Server supports batch API only, please update your Git LFS client to version 1.0.1 and up.') + end + end + + context 'when fetching lfs object using deprecated API' do + let(:authorization) { authorize_user } + + before do + get "#{project.http_url_to_repo}/info/lfs/objects/#{sample_oid}", nil, headers + end + + it_behaves_like 'a deprecated' + end + + context 'when handling lfs request using deprecated API' do + before do + post_json "#{project.http_url_to_repo}/info/lfs/objects", nil, headers + end + + it_behaves_like 'a deprecated' + end + end + + describe 'when fetching lfs object' do + let(:project) { create(:empty_project) } + let(:update_permissions) { } + + before do + enable_lfs + update_permissions + get "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", nil, headers + end + + context 'and request comes from gitlab-workhorse' do + context 'without user being authorized' do + it 'responds with status 401' do + expect(response).to have_http_status(401) + end + end + + context 'with required headers' do + shared_examples 'responds with a file' do + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with the file location' do + expect(response.headers['Content-Type']).to eq('application/octet-stream') + expect(response.headers['X-Sendfile']).to eq(lfs_object.file.path) + end + end + + context 'with user is authorized' do + let(:authorization) { authorize_user } + let(:sendfile) { 'X-Sendfile' } + + context 'and does not have project access' do + let(:update_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with status 403' do + expect(response).to have_http_status(403) + end + end + + context 'and does have project access' do + let(:update_permissions) do + project.team << [user, :master] + project.lfs_objects << lfs_object + end + + it_behaves_like 'responds with a file' + end + end + + context 'when CI is authorized' do + let(:authorization) { authorize_ci_project } + + it_behaves_like 'responds with a file' + end + end + + context 'without required headers' do + let(:authorization) { authorize_user } + + it 'responds with status 403' do + expect(response).to have_http_status(403) + end + end + end + end + + describe 'when handling lfs batch request' do + let(:update_lfs_permissions) { } + let(:update_user_permissions) { } + + before do + enable_lfs + update_lfs_permissions + update_user_permissions + post_json "#{project.http_url_to_repo}/info/lfs/objects/batch", body, headers + end + + describe 'download' do + let(:project) { create(:empty_project) } + let(:body) do + { 'operation' => 'download', + 'objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size + }] + } + end + + shared_examples 'an authorized requests' do + context 'when downloading an lfs object that is assigned to our project' do + let(:update_lfs_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'with href to download' do + expect(json_response).to eq('objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size, + 'actions' => { + 'download' => { + 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + 'header' => { 'Authorization' => authorization } + } + } + }]) + end + end + + context 'when downloading an lfs object that is assigned to other project' do + let(:other_project) { create(:empty_project) } + let(:update_lfs_permissions) do + other_project.lfs_objects << lfs_object + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'with href to download' do + expect(json_response).to eq('objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size, + 'error' => { + 'code' => 404, + 'message' => "Object does not exist on the server or you don't have permissions to access it", + } + }]) + end + end + + context 'when downloading a lfs object that does not exist' do + let(:body) do + { 'operation' => 'download', + 'objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078 + }] + } + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'with an 404 for specific object' do + expect(json_response).to eq('objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078, + 'error' => { + 'code' => 404, + 'message' => "Object does not exist on the server or you don't have permissions to access it", + } + }]) + end + end + + context 'when downloading one new and one existing lfs object' do + let(:body) do + { 'operation' => 'download', + 'objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078 + }, + { 'oid' => sample_oid, + 'size' => sample_size + } + ] + } + end + + let(:update_lfs_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with upload hypermedia link for the new object' do + expect(json_response).to eq('objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078, + 'error' => { + 'code' => 404, + 'message' => "Object does not exist on the server or you don't have permissions to access it", + } + }, + { 'oid' => sample_oid, + 'size' => sample_size, + 'actions' => { + 'download' => { + 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + 'header' => { 'Authorization' => authorization } + } + } + }]) + end + end + end + + context 'when user is authenticated' do + let(:authorization) { authorize_user } + + let(:update_user_permissions) do + project.team << [user, role] + end + + it_behaves_like 'an authorized requests' do + let(:role) { :reporter } + end + + context 'when user does is not member of the project' do + let(:role) { :guest } + + it 'responds with 403' do + expect(response).to have_http_status(403) + end + end + + context 'when user does not have download access' do + let(:role) { :guest } + + it 'responds with 403' do + expect(response).to have_http_status(403) + end + end + end + + context 'when CI is authorized' do + let(:authorization) { authorize_ci_project } + + it_behaves_like 'an authorized requests' + end + + context 'when user is not authenticated' do + describe 'is accessing public project' do + let(:project) { create(:project, :public) } + + let(:update_lfs_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with status 200 and href to download' do + expect(response).to have_http_status(200) + end + + it 'responds with status 200 and href to download' do + expect(json_response).to eq('objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size, + 'actions' => { + 'download' => { + 'href' => "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}", + 'header' => {} + } + } + }]) + end + end + + describe 'is accessing non-public project' do + let(:update_lfs_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with authorization required' do + expect(response).to have_http_status(401) + end + end + end + end + + describe 'upload' do + let(:project) { create(:project, :public) } + let(:body) do + { 'operation' => 'upload', + 'objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size + }] + } + end + + describe 'when request is authenticated' do + describe 'when user has project push access' do + let(:authorization) { authorize_user } + + let(:update_user_permissions) do + project.team << [user, :developer] + end + + context 'when pushing an lfs object that already exists' do + let(:other_project) { create(:empty_project) } + let(:update_lfs_permissions) do + other_project.lfs_objects << lfs_object + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with links the object to the project' do + expect(json_response['objects']).to be_kind_of(Array) + expect(json_response['objects'].first['oid']).to eq(sample_oid) + expect(json_response['objects'].first['size']).to eq(sample_size) + expect(lfs_object.projects.pluck(:id)).not_to include(project.id) + expect(lfs_object.projects.pluck(:id)).to include(other_project.id) + expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}") + expect(json_response['objects'].first['actions']['upload']['header']).to eq('Authorization' => authorization) + end + end + + context 'when pushing a lfs object that does not exist' do + let(:body) do + { 'operation' => 'upload', + 'objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078 + }] + } + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with upload hypermedia link' do + expect(json_response['objects']).to be_kind_of(Array) + expect(json_response['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") + expect(json_response['objects'].first['size']).to eq(1575078) + expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{Gitlab.config.gitlab.url}/#{project.path_with_namespace}.git/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") + expect(json_response['objects'].first['actions']['upload']['header']).to eq('Authorization' => authorization) + end + end + + context 'when pushing one new and one existing lfs object' do + let(:body) do + { 'operation' => 'upload', + 'objects' => [ + { 'oid' => '91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897', + 'size' => 1575078 + }, + { 'oid' => sample_oid, + 'size' => sample_size + } + ] + } + end + + let(:update_lfs_permissions) do + project.lfs_objects << lfs_object + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with upload hypermedia link for the new object' do + expect(json_response['objects']).to be_kind_of(Array) + + expect(json_response['objects'].first['oid']).to eq("91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897") + expect(json_response['objects'].first['size']).to eq(1575078) + expect(json_response['objects'].first['actions']['upload']['href']).to eq("#{project.http_url_to_repo}/gitlab-lfs/objects/91eff75a492a3ed0dfcb544d7f31326bc4014c8551849c192fd1e48d4dd2c897/1575078") + expect(json_response['objects'].first['actions']['upload']['header']).to eq("Authorization" => authorization) + + expect(json_response['objects'].last['oid']).to eq(sample_oid) + expect(json_response['objects'].last['size']).to eq(sample_size) + expect(json_response['objects'].last).not_to have_key('actions') + end + end + end + + context 'when user does not have push access' do + let(:authorization) { authorize_user } + + it 'responds with 403' do + expect(response).to have_http_status(403) + end + end + + context 'when CI is authorized' do + let(:authorization) { authorize_ci_project } + + it 'responds with 401' do + expect(response).to have_http_status(401) + end + end + end + + context 'when user is not authenticated' do + context 'when user has push access' do + let(:update_user_permissions) do + project.team << [user, :master] + end + + it 'responds with status 401' do + expect(response).to have_http_status(401) + end + end + + context 'when user does not have push access' do + it 'responds with status 401' do + expect(response).to have_http_status(401) + end + end + end + + context 'when CI is authorized' do + let(:authorization) { authorize_ci_project } + + it 'responds with status 403' do + expect(response).to have_http_status(401) + end + end + end + + describe 'unsupported' do + let(:project) { create(:empty_project) } + let(:body) do + { 'operation' => 'other', + 'objects' => [ + { 'oid' => sample_oid, + 'size' => sample_size + }] + } + end + + it 'responds with status 404' do + expect(response).to have_http_status(404) + end + end + end + + describe 'when pushing a lfs object' do + before do + enable_lfs + end + + shared_examples 'unauthorized' do + context 'and request is sent by gitlab-workhorse to authorize the request' do + before do + put_authorize + end + + it 'responds with status 401' do + expect(response).to have_http_status(401) + end + end + + context 'and request is sent by gitlab-workhorse to finalize the upload' do + before do + put_finalize + end + + it 'responds with status 401' do + expect(response).to have_http_status(401) + end + end + + context 'and request is sent with a malformed headers' do + before do + put_finalize('cat /etc/passwd') + end + + it 'does not recognize it as a valid lfs command' do + expect(response).to have_http_status(401) + end + end + end + + shared_examples 'forbidden' do + context 'and request is sent by gitlab-workhorse to authorize the request' do + before do + put_authorize + end + + it 'responds with 403' do + expect(response).to have_http_status(403) + end + end + + context 'and request is sent by gitlab-workhorse to finalize the upload' do + before do + put_finalize + end + + it 'responds with 403' do + expect(response).to have_http_status(403) + end + end + end + + describe 'to one project' do + let(:project) { create(:empty_project) } + + describe 'when user is authenticated' do + let(:authorization) { authorize_user } + + describe 'when user has push access to the project' do + before do + project.team << [user, :developer] + end + + context 'and request is sent by gitlab-workhorse to authorize the request' do + before do + put_authorize + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'responds with status 200, location of lfs store and object details' do + expect(json_response['StoreLFSPath']).to eq("#{Gitlab.config.shared.path}/lfs-objects/tmp/upload") + expect(json_response['LfsOid']).to eq(sample_oid) + expect(json_response['LfsSize']).to eq(sample_size) + end + end + + context 'and request is sent by gitlab-workhorse to finalize the upload' do + before do + put_finalize + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'lfs object is linked to the project' do + expect(lfs_object.projects.pluck(:id)).to include(project.id) + end + end + end + + describe 'and user does not have push access' do + it_behaves_like 'forbidden' + end + end + + context 'when CI is authenticated' do + let(:authorization) { authorize_ci_project } + + it_behaves_like 'unauthorized' + end + + context 'for unauthenticated' do + it_behaves_like 'unauthorized' + end + end + + describe 'to a forked project' do + let(:upstream_project) { create(:project, :public) } + let(:project_owner) { create(:user) } + let(:project) { fork_project(upstream_project, project_owner) } + + describe 'when user is authenticated' do + let(:authorization) { authorize_user } + + describe 'when user has push access to the project' do + before do + project.team << [user, :developer] + end + + context 'and request is sent by gitlab-workhorse to authorize the request' do + before do + put_authorize + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'with location of lfs store and object details' do + expect(json_response['StoreLFSPath']).to eq("#{Gitlab.config.shared.path}/lfs-objects/tmp/upload") + expect(json_response['LfsOid']).to eq(sample_oid) + expect(json_response['LfsSize']).to eq(sample_size) + end + end + + context 'and request is sent by gitlab-workhorse to finalize the upload' do + before do + put_finalize + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'lfs object is linked to the source project' do + expect(lfs_object.projects.pluck(:id)).to include(upstream_project.id) + end + end + end + + describe 'and user does not have push access' do + it_behaves_like 'forbidden' + end + end + + context 'when CI is authenticated' do + let(:authorization) { authorize_ci_project } + + it_behaves_like 'unauthorized' + end + + context 'for unauthenticated' do + it_behaves_like 'unauthorized' + end + + describe 'and second project not related to fork or a source project' do + let(:second_project) { create(:empty_project) } + let(:authorization) { authorize_user } + + before do + second_project.team << [user, :master] + upstream_project.lfs_objects << lfs_object + end + + context 'when pushing the same lfs object to the second project' do + before do + put "#{second_project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}", nil, + headers.merge('X-Gitlab-Lfs-Tmp' => lfs_tmp_file).compact + end + + it 'responds with status 200' do + expect(response).to have_http_status(200) + end + + it 'links the lfs object to the project' do + expect(lfs_object.projects.pluck(:id)).to include(second_project.id, upstream_project.id) + end + end + end + end + + def put_authorize + put "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}/authorize", nil, headers + end + + def put_finalize(lfs_tmp = lfs_tmp_file) + put "#{project.http_url_to_repo}/gitlab-lfs/objects/#{sample_oid}/#{sample_size}", nil, + headers.merge('X-Gitlab-Lfs-Tmp' => lfs_tmp).compact + end + + def lfs_tmp_file + "#{sample_oid}012345678" + end + end + + def enable_lfs + allow(Gitlab.config.lfs).to receive(:enabled).and_return(true) + end + + def authorize_ci_project + ActionController::HttpAuthentication::Basic.encode_credentials('gitlab-ci-token', project.runners_token) + end + + def authorize_user + ActionController::HttpAuthentication::Basic.encode_credentials(user.username, user.password) + end + + def fork_project(project, user, object = nil) + allow(RepositoryForkWorker).to receive(:perform_async).and_return(true) + Projects::ForkService.new(project, user, {}).execute + end + + def post_json(url, body = nil, headers = nil) + post(url, body.try(:to_json), (headers || {}).merge('Content-Type' => 'application/json')) + end + + def json_response + @json_response ||= JSON.parse(response.body) + end +end -- cgit v1.2.1 From bb9f827ddc51eba73c78be83b977a07e10638936 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 14:23:26 +0200 Subject: Fix fetching LFS objects for private CI projects --- CHANGELOG | 1 + lib/gitlab/backend/grack_auth.rb | 2 +- spec/requests/lfs_http_spec.rb | 7 ++++++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index a977fc3fdbf..671a7c2e4a9 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -18,6 +18,7 @@ v 8.10.0 (unreleased) - Fix MR-auto-close text added to description. !4836 - Fix issue, preventing users w/o push access to sort tags !5105 (redetection) - Add Spring EmojiOne updates. + - Fix fetching LFS objects for private CI projects - Add syntax for multiline blockquote using `>>>` fence !3954 - Fix viewing notification settings when a project is pending deletion - Fix pagination when sorting by columns with lots of ties (like priority) diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb index 478f145bfed..ab94abeda77 100644 --- a/lib/gitlab/backend/grack_auth.rb +++ b/lib/gitlab/backend/grack_auth.rb @@ -63,7 +63,7 @@ module Grack def ci_request?(login, password) matched_login = /(?^[a-zA-Z]*-ci)-token$/.match(login) - if project && matched_login.present? && git_cmd == 'git-upload-pack' + if project && matched_login.present? underscored_service = matched_login['s'].underscore if underscored_service == 'gitlab_ci' diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index d862cb5b0b4..aaad1e3a6ec 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -98,6 +98,8 @@ describe Gitlab::Lfs::Router do context 'with required headers' do shared_examples 'responds with a file' do + let(:sendfile) { 'X-Sendfile' } + it 'responds with status 200' do expect(response).to have_http_status(200) end @@ -110,7 +112,6 @@ describe Gitlab::Lfs::Router do context 'with user is authorized' do let(:authorization) { authorize_user } - let(:sendfile) { 'X-Sendfile' } context 'and does not have project access' do let(:update_permissions) do @@ -135,6 +136,10 @@ describe Gitlab::Lfs::Router do context 'when CI is authorized' do let(:authorization) { authorize_ci_project } + let(:update_permissions) do + project.lfs_objects << lfs_object + end + it_behaves_like 'responds with a file' end end -- cgit v1.2.1 From e300dac29302015cbba5b917ad5ea3657de62f0d Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 15:06:19 +0200 Subject: Fix LFS specs --- lib/gitlab/lfs/response.rb | 2 ++ lib/gitlab/lfs/router.rb | 2 -- spec/requests/lfs_http_spec.rb | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/gitlab/lfs/response.rb b/lib/gitlab/lfs/response.rb index 811363405a8..a1ee1aa81ff 100644 --- a/lib/gitlab/lfs/response.rb +++ b/lib/gitlab/lfs/response.rb @@ -47,6 +47,8 @@ module Gitlab end def render_storage_upload_store_response(oid, size, tmp_file_name) + return render_forbidden unless tmp_file_name + render_response_to_push do render_lfs_upload_ok(oid, size, tmp_file_name) end diff --git a/lib/gitlab/lfs/router.rb b/lib/gitlab/lfs/router.rb index 69bd5e62305..f2a76a56b8f 100644 --- a/lib/gitlab/lfs/router.rb +++ b/lib/gitlab/lfs/router.rb @@ -74,8 +74,6 @@ module Gitlab lfs.render_storage_upload_authorize_response(oid, size) else tmp_file_name = sanitize_tmp_filename(@request.env['HTTP_X_GITLAB_LFS_TMP']) - return nil unless tmp_file_name - lfs.render_storage_upload_store_response(oid, size, tmp_file_name) end end diff --git a/spec/requests/lfs_http_spec.rb b/spec/requests/lfs_http_spec.rb index aaad1e3a6ec..93d2bc160cc 100644 --- a/spec/requests/lfs_http_spec.rb +++ b/spec/requests/lfs_http_spec.rb @@ -557,7 +557,7 @@ describe Gitlab::Lfs::Router do end it 'does not recognize it as a valid lfs command' do - expect(response).to have_http_status(401) + expect(response).to have_http_status(403) end end end -- cgit v1.2.1 From 3a3d999601ded922acca5a8f7a5f374f9690c1e0 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 16:35:48 +0200 Subject: Fix stage status shown for pipelines --- CHANGELOG | 1 + .../projects/ci/pipelines/_pipeline.html.haml | 2 +- spec/models/commit_status_spec.rb | 24 +++++++++++++++++----- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 040926d270d..67d7b43fef2 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -58,6 +58,7 @@ v 8.10.0 (unreleased) - Collapse large diffs by default (!4990) - Check for conflicts with existing Project's wiki path when creating a new project. - Show last push widget in upstream after push to fork + - Fix stage status shown for pipelines - Cache todos pending/done dashboard query counts. - Don't instantiate a git tree on Projects show default view - Bump Rinku to 2.0.0 diff --git a/app/views/projects/ci/pipelines/_pipeline.html.haml b/app/views/projects/ci/pipelines/_pipeline.html.haml index b53a8633937..0a103e58db3 100644 --- a/app/views/projects/ci/pipelines/_pipeline.html.haml +++ b/app/views/projects/ci/pipelines/_pipeline.html.haml @@ -32,7 +32,7 @@ Cant find HEAD commit for this branch - - stages_status = pipeline.statuses.stages_status + - stages_status = pipeline.statuses.latest.stages_status - stages.each do |stage| %td - status = stages_status[stage] diff --git a/spec/models/commit_status_spec.rb b/spec/models/commit_status_spec.rb index 05f22c7a9eb..ff6371ad685 100644 --- a/spec/models/commit_status_spec.rb +++ b/spec/models/commit_status_spec.rb @@ -177,10 +177,10 @@ describe CommitStatus, models: true do describe '#stages' do before do - FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'build', stage_idx: 0, status: 'success' - FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'build', stage_idx: 0, status: 'failed' - FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'deploy', stage_idx: 2, status: 'running' - FactoryGirl.create :commit_status, pipeline: pipeline, stage: 'test', stage_idx: 1, status: 'success' + create :commit_status, pipeline: pipeline, stage: 'build', name: 'linux', stage_idx: 0, status: 'success' + create :commit_status, pipeline: pipeline, stage: 'build', name: 'mac', stage_idx: 0, status: 'failed' + create :commit_status, pipeline: pipeline, stage: 'deploy', name: 'staging', stage_idx: 2, status: 'running' + create :commit_status, pipeline: pipeline, stage: 'test', name: 'rspec', stage_idx: 1, status: 'success' end context 'stages list' do @@ -192,7 +192,7 @@ describe CommitStatus, models: true do end context 'stages with statuses' do - subject { CommitStatus.where(pipeline: pipeline).stages_status } + subject { CommitStatus.where(pipeline: pipeline).latest.stages_status } it 'return list of stages with statuses' do is_expected.to eq({ @@ -201,6 +201,20 @@ describe CommitStatus, models: true do 'deploy' => 'running' }) end + + context 'when build is retried' do + before do + create :commit_status, pipeline: pipeline, stage: 'build', name: 'mac', stage_idx: 0, status: 'success' + end + + it 'ignores a previous state' do + is_expected.to eq({ + 'build' => 'success', + 'test' => 'success', + 'deploy' => 'running' + }) + end + end end end -- cgit v1.2.1 From 1744c742f28afb1a89432fa2854fad93e1557fd8 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 17:05:41 +0200 Subject: Allow to access Container Registry for Public and Internal projects --- CHANGELOG | 1 + app/models/ability.rb | 3 +- .../security/project/internal_access_spec.rb | 19 ++++ .../security/project/private_access_spec.rb | 19 ++++ .../security/project/public_access_spec.rb | 19 ++++ ...ntainer_registry_authentication_service_spec.rb | 104 ++++++++++++++++----- 6 files changed, 139 insertions(+), 26 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 040926d270d..bb58672f7bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -79,6 +79,7 @@ v 8.10.0 (unreleased) - Don't garbage collect commits that have related DB records like comments - More descriptive message for git hooks and file locks - Handle custom Git hook result in GitLab UI + - Allow to access Container Registry for Public and Internal projects - Allow '?', or '&' for label names - Fix importer for GitHub Pull Requests when a branch was reused across Pull Requests - Add date when user joined the team on the member page diff --git a/app/models/ability.rb b/app/models/ability.rb index eeb0ceba081..6fd18f2ee24 100644 --- a/app/models/ability.rb +++ b/app/models/ability.rb @@ -204,7 +204,8 @@ class Ability :download_code, :fork_project, :read_commit_status, - :read_pipeline + :read_pipeline, + :read_container_image ] end diff --git a/spec/features/security/project/internal_access_spec.rb b/spec/features/security/project/internal_access_spec.rb index 13d980a326f..b6acc509342 100644 --- a/spec/features/security/project/internal_access_spec.rb +++ b/spec/features/security/project/internal_access_spec.rb @@ -426,4 +426,23 @@ describe "Internal Project Access", feature: true do it { is_expected.to be_denied_for :external } it { is_expected.to be_denied_for :visitor } end + + describe "GET /:project_path/container_registry" do + before do + stub_container_registry_tags('latest') + stub_container_registry_config(enabled: true) + end + + subject { namespace_project_container_registry_index_path(project.namespace, project) } + + it { is_expected.to be_allowed_for :admin } + it { is_expected.to be_allowed_for owner } + it { is_expected.to be_allowed_for master } + it { is_expected.to be_allowed_for developer } + it { is_expected.to be_allowed_for reporter } + it { is_expected.to be_allowed_for guest } + it { is_expected.to be_allowed_for :user } + it { is_expected.to be_denied_for :external } + it { is_expected.to be_denied_for :visitor } + end end diff --git a/spec/features/security/project/private_access_spec.rb b/spec/features/security/project/private_access_spec.rb index ac9690cc127..ccb5c06dab0 100644 --- a/spec/features/security/project/private_access_spec.rb +++ b/spec/features/security/project/private_access_spec.rb @@ -362,4 +362,23 @@ describe "Private Project Access", feature: true do it { is_expected.to be_denied_for :external } it { is_expected.to be_denied_for :visitor } end + + describe "GET /:project_path/container_registry" do + before do + stub_container_registry_tags('latest') + stub_container_registry_config(enabled: true) + end + + subject { namespace_project_container_registry_index_path(project.namespace, project) } + + it { is_expected.to be_allowed_for :admin } + it { is_expected.to be_allowed_for owner } + it { is_expected.to be_allowed_for master } + it { is_expected.to be_allowed_for developer } + it { is_expected.to be_allowed_for reporter } + it { is_expected.to be_denied_for guest } + it { is_expected.to be_denied_for :user } + it { is_expected.to be_denied_for :external } + it { is_expected.to be_denied_for :visitor } + end end diff --git a/spec/features/security/project/public_access_spec.rb b/spec/features/security/project/public_access_spec.rb index 737897de52b..985663e7c98 100644 --- a/spec/features/security/project/public_access_spec.rb +++ b/spec/features/security/project/public_access_spec.rb @@ -426,4 +426,23 @@ describe "Public Project Access", feature: true do it { is_expected.to be_denied_for :external } it { is_expected.to be_denied_for :visitor } end + + describe "GET /:project_path/container_registry" do + before do + stub_container_registry_tags('latest') + stub_container_registry_config(enabled: true) + end + + subject { namespace_project_container_registry_index_path(project.namespace, project) } + + it { is_expected.to be_allowed_for :admin } + it { is_expected.to be_allowed_for owner } + it { is_expected.to be_allowed_for master } + it { is_expected.to be_allowed_for developer } + it { is_expected.to be_allowed_for reporter } + it { is_expected.to be_allowed_for guest } + it { is_expected.to be_allowed_for :user } + it { is_expected.to be_allowed_for :external } + it { is_expected.to be_allowed_for :visitor } + end end diff --git a/spec/services/auth/container_registry_authentication_service_spec.rb b/spec/services/auth/container_registry_authentication_service_spec.rb index 67777ad48bc..7cc71f706ce 100644 --- a/spec/services/auth/container_registry_authentication_service_spec.rb +++ b/spec/services/auth/container_registry_authentication_service_spec.rb @@ -87,51 +87,105 @@ describe Auth::ContainerRegistryAuthenticationService, services: true do end context 'user authorization' do - let(:project) { create(:project) } let(:current_user) { create(:user) } - context 'allow to use scope-less authentication' do - it_behaves_like 'a valid token' - end + context 'for private project' do + let(:project) { create(:empty_project) } - context 'allow developer to push images' do - before { project.team << [current_user, :developer] } + context 'allow to use scope-less authentication' do + it_behaves_like 'a valid token' + end - let(:current_params) do - { scope: "repository:#{project.path_with_namespace}:push" } + context 'allow developer to push images' do + before { project.team << [current_user, :developer] } + + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:push" } + end + + it_behaves_like 'a pushable' end - it_behaves_like 'a pushable' - end + context 'allow reporter to pull images' do + before { project.team << [current_user, :reporter] } + + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:pull" } + end - context 'allow reporter to pull images' do - before { project.team << [current_user, :reporter] } + it_behaves_like 'a pullable' + end - let(:current_params) do - { scope: "repository:#{project.path_with_namespace}:pull" } + context 'return a least of privileges' do + before { project.team << [current_user, :reporter] } + + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:push,pull" } + end + + it_behaves_like 'a pullable' end - it_behaves_like 'a pullable' + context 'disallow guest to pull or push images' do + before { project.team << [current_user, :guest] } + + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:pull,push" } + end + + it_behaves_like 'an inaccessible' + end end - context 'return a least of privileges' do - before { project.team << [current_user, :reporter] } + context 'for public project' do + let(:project) { create(:empty_project, :public) } - let(:current_params) do - { scope: "repository:#{project.path_with_namespace}:push,pull" } + context 'allow anyone to pull images' do + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:pull" } + end + + it_behaves_like 'a pullable' end - it_behaves_like 'a pullable' + context 'disallow anyone to push images' do + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:push" } + end + + it_behaves_like 'an inaccessible' + end end - context 'disallow guest to pull or push images' do - before { project.team << [current_user, :guest] } + context 'for internal project' do + let(:project) { create(:empty_project, :internal) } - let(:current_params) do - { scope: "repository:#{project.path_with_namespace}:pull,push" } + context 'for internal user' do + context 'allow anyone to pull images' do + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:pull" } + end + + it_behaves_like 'a pullable' + end + + context 'disallow anyone to push images' do + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:push" } + end + + it_behaves_like 'an inaccessible' + end end - it_behaves_like 'an inaccessible' + context 'for external user' do + let(:current_user) { create(:user, external: true) } + let(:current_params) do + { scope: "repository:#{project.path_with_namespace}:pull,push" } + end + + it_behaves_like 'an inaccessible' + end end end -- cgit v1.2.1 From 1556d4848d4753b7bddd8430cf223b91e6f47b0f Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 15:42:29 +0200 Subject: Track a user who created a pipeline --- CHANGELOG | 1 + app/models/ci/pipeline.rb | 2 ++ app/models/project.rb | 4 ++-- app/models/user.rb | 1 + app/services/ci/create_pipeline_service.rb | 1 + app/services/create_commit_builds_service.rb | 8 +++++++- db/migrate/20160715132507_add_user_id_to_pipeline.rb | 7 +++++++ db/schema.rb | 3 ++- lib/api/commit_statuses.rb | 2 +- spec/models/ci/pipeline_spec.rb | 3 +++ spec/models/user_spec.rb | 2 ++ spec/services/create_commit_builds_service_spec.rb | 3 ++- 12 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 db/migrate/20160715132507_add_user_id_to_pipeline.rb diff --git a/CHANGELOG b/CHANGELOG index 5ab16db31ce..044bdb476cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -53,6 +53,7 @@ v 8.10.0 (unreleased) - Fix user creation with stronger minimum password requirements !4054 (nathan-pmt) - Only show New Snippet button to users that can create snippets. - PipelinesFinder uses git cache data + - Track a user who created a pipeline - Actually render old and new sections of parallel diff next to each other - Throttle the update of `project.pushes_since_gc` to 1 minute. - Allow expanding and collapsing files in diff view (!4990) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index fa4071e2482..cb284ba1e1c 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -6,6 +6,8 @@ module Ci self.table_name = 'ci_commits' belongs_to :project, class_name: '::Project', foreign_key: :gl_project_id + belongs_to :user + has_many :statuses, class_name: 'CommitStatus', foreign_key: :commit_id has_many :builds, class_name: 'Ci::Build', foreign_key: :commit_id has_many :trigger_requests, dependent: :destroy, class_name: 'Ci::TriggerRequest', foreign_key: :commit_id diff --git a/app/models/project.rb b/app/models/project.rb index e7b9835692d..dba3b3413ef 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -1038,8 +1038,8 @@ class Project < ActiveRecord::Base pipelines.order(id: :desc).find_by(sha: sha, ref: ref) end - def ensure_pipeline(sha, ref) - pipeline(sha, ref) || pipelines.create(sha: sha, ref: ref) + def ensure_pipeline(sha, ref, current_user = nil) + pipeline(sha, ref) || pipelines.create(sha: sha, ref: ref, user: current_user) end def enable_ci diff --git a/app/models/user.rb b/app/models/user.rb index 7a72c202150..3d0a033785c 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -85,6 +85,7 @@ class User < ActiveRecord::Base has_one :abuse_report, dependent: :destroy has_many :spam_logs, dependent: :destroy has_many :builds, dependent: :nullify, class_name: 'Ci::Build' + has_many :pipelines, dependent: :nullify, class_name: 'Ci::Pipeline' has_many :todos, dependent: :destroy has_many :notification_settings, dependent: :destroy has_many :award_emoji, dependent: :destroy diff --git a/app/services/ci/create_pipeline_service.rb b/app/services/ci/create_pipeline_service.rb index b1ee6874190..be91bf0db85 100644 --- a/app/services/ci/create_pipeline_service.rb +++ b/app/services/ci/create_pipeline_service.rb @@ -2,6 +2,7 @@ module Ci class CreatePipelineService < BaseService def execute pipeline = project.pipelines.new(params) + pipeline.user = current_user unless ref_names.include?(params[:ref]) pipeline.errors.add(:base, 'Reference not found') diff --git a/app/services/create_commit_builds_service.rb b/app/services/create_commit_builds_service.rb index f947e8f452e..0b66b854dea 100644 --- a/app/services/create_commit_builds_service.rb +++ b/app/services/create_commit_builds_service.rb @@ -14,7 +14,13 @@ class CreateCommitBuildsService return false end - @pipeline = Ci::Pipeline.new(project: project, sha: sha, ref: ref, before_sha: before_sha, tag: tag) + @pipeline = Ci::Pipeline.new( + project: project, + sha: sha, + ref: ref, + before_sha: before_sha, + tag: tag, + user: user) ## # Skip creating pipeline if no gitlab-ci.yml is found diff --git a/db/migrate/20160715132507_add_user_id_to_pipeline.rb b/db/migrate/20160715132507_add_user_id_to_pipeline.rb new file mode 100644 index 00000000000..af0461c4daf --- /dev/null +++ b/db/migrate/20160715132507_add_user_id_to_pipeline.rb @@ -0,0 +1,7 @@ +class AddUserIdToPipeline < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + def change + add_column :ci_commits, :user_id, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index f24e47b85b2..6ab5a1eaded 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160712171823) do +ActiveRecord::Schema.define(version: 20160715132507) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -199,6 +199,7 @@ ActiveRecord::Schema.define(version: 20160712171823) do t.datetime "started_at" t.datetime "finished_at" t.integer "duration" + t.integer "user_id" end add_index "ci_commits", ["gl_project_id", "sha"], name: "index_ci_commits_on_gl_project_id_and_sha", using: :btree diff --git a/lib/api/commit_statuses.rb b/lib/api/commit_statuses.rb index 323a7086890..acb4812b5cf 100644 --- a/lib/api/commit_statuses.rb +++ b/lib/api/commit_statuses.rb @@ -64,7 +64,7 @@ module API ref = branches.first end - pipeline = @project.ensure_pipeline(commit.sha, ref) + pipeline = @project.ensure_pipeline(commit.sha, ref, current_user) name = params[:name] || params[:context] status = GenericCommitStatus.running_or_pending.find_by(pipeline: pipeline, name: name, ref: params[:ref]) diff --git a/spec/models/ci/pipeline_spec.rb b/spec/models/ci/pipeline_spec.rb index 4e5481f9154..10db79bd15f 100644 --- a/spec/models/ci/pipeline_spec.rb +++ b/spec/models/ci/pipeline_spec.rb @@ -5,9 +5,12 @@ describe Ci::Pipeline, models: true do let(:pipeline) { FactoryGirl.create :ci_pipeline, project: project } it { is_expected.to belong_to(:project) } + it { is_expected.to belong_to(:user) } + it { is_expected.to have_many(:statuses) } it { is_expected.to have_many(:trigger_requests) } it { is_expected.to have_many(:builds) } + it { is_expected.to validate_presence_of :sha } it { is_expected.to validate_presence_of :status } diff --git a/spec/models/user_spec.rb b/spec/models/user_spec.rb index ff39f187759..fc74488ac0e 100644 --- a/spec/models/user_spec.rb +++ b/spec/models/user_spec.rb @@ -31,6 +31,8 @@ describe User, models: true do it { is_expected.to have_many(:spam_logs).dependent(:destroy) } it { is_expected.to have_many(:todos).dependent(:destroy) } it { is_expected.to have_many(:award_emoji).dependent(:destroy) } + it { is_expected.to have_many(:builds).dependent(:nullify) } + it { is_expected.to have_many(:pipelines).dependent(:nullify) } describe '#group_members' do it 'does not include group memberships for which user is a requester' do diff --git a/spec/services/create_commit_builds_service_spec.rb b/spec/services/create_commit_builds_service_spec.rb index 4d09bc5fb12..7caf69bc870 100644 --- a/spec/services/create_commit_builds_service_spec.rb +++ b/spec/services/create_commit_builds_service_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' describe CreateCommitBuildsService, services: true do let(:service) { CreateCommitBuildsService.new } let(:project) { FactoryGirl.create(:empty_project) } - let(:user) { nil } + let(:user) { create(:user) } before do stub_ci_pipeline_to_return_yaml_file @@ -24,6 +24,7 @@ describe CreateCommitBuildsService, services: true do it { expect(pipeline).to be_valid } it { expect(pipeline).to be_persisted } it { expect(pipeline).to eq(project.pipelines.last) } + it { expect(pipeline).to have_attributes(:user => user) } it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) } end -- cgit v1.2.1 From 7993fc1b89f6a8903fea0aa9586b1ed1d8a3b29e Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 15:46:49 +0200 Subject: Add index for user_id of pipeline --- db/migrate/20160715134306_add_index_for_pipeline_user_id.rb | 7 +++++++ db/schema.rb | 3 ++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 db/migrate/20160715134306_add_index_for_pipeline_user_id.rb diff --git a/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb b/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb new file mode 100644 index 00000000000..ac5d2bec681 --- /dev/null +++ b/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb @@ -0,0 +1,7 @@ +class AddIndexForPipelineUserId < ActiveRecord::Migration + include Gitlab::Database::MigrationHelpers + + def change + add_index :ci_commits, :user_id + end +end diff --git a/db/schema.rb b/db/schema.rb index 6ab5a1eaded..c96baef6a8b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20160715132507) do +ActiveRecord::Schema.define(version: 20160715134306) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -211,6 +211,7 @@ ActiveRecord::Schema.define(version: 20160715132507) do add_index "ci_commits", ["project_id"], name: "index_ci_commits_on_project_id", using: :btree add_index "ci_commits", ["sha"], name: "index_ci_commits_on_sha", using: :btree add_index "ci_commits", ["status"], name: "index_ci_commits_on_status", using: :btree + add_index "ci_commits", ["user_id"], name: "index_ci_commits_on_user_id", using: :btree create_table "ci_events", force: :cascade do |t| t.integer "project_id" -- cgit v1.2.1 From 9d72d902cf21c786b871eced12609a793596cf29 Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 18:01:43 +0200 Subject: Make rubocop happy --- db/migrate/20160715134306_add_index_for_pipeline_user_id.rb | 2 +- spec/services/create_commit_builds_service_spec.rb | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb b/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb index ac5d2bec681..e09caa0e6d7 100644 --- a/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb +++ b/db/migrate/20160715134306_add_index_for_pipeline_user_id.rb @@ -2,6 +2,6 @@ class AddIndexForPipelineUserId < ActiveRecord::Migration include Gitlab::Database::MigrationHelpers def change - add_index :ci_commits, :user_id + add_concurrent_index :ci_commits, :user_id end end diff --git a/spec/services/create_commit_builds_service_spec.rb b/spec/services/create_commit_builds_service_spec.rb index 7caf69bc870..d4c5e584421 100644 --- a/spec/services/create_commit_builds_service_spec.rb +++ b/spec/services/create_commit_builds_service_spec.rb @@ -24,7 +24,7 @@ describe CreateCommitBuildsService, services: true do it { expect(pipeline).to be_valid } it { expect(pipeline).to be_persisted } it { expect(pipeline).to eq(project.pipelines.last) } - it { expect(pipeline).to have_attributes(:user => user) } + it { expect(pipeline).to have_attributes(user: user) } it { expect(pipeline.builds.first).to be_kind_of(Ci::Build) } end -- cgit v1.2.1 From 52af77d8f8e45caff9b7a496768fa47256e74c71 Mon Sep 17 00:00:00 2001 From: "Jacob Vosmaer (GitLab)" Date: Fri, 15 Jul 2016 16:04:45 +0000 Subject: Don't ask Heather to review documentation MR's --- doc/development/doc_styleguide.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/development/doc_styleguide.md b/doc/development/doc_styleguide.md index 975bb82c37d..fac35ec964d 100644 --- a/doc/development/doc_styleguide.md +++ b/doc/development/doc_styleguide.md @@ -44,7 +44,7 @@ it organized and easy to find. - When introducing a new document, be careful for the headings to be grammatically and syntactically correct. It is advised to mention one or all of the following GitLab members for a review: `@axil`, `@rspeicher`, - `@dblessing`, `@ashleys`, `@nearlythere`. This is to ensure that no document + `@dblessing`, `@ashleys`. This is to ensure that no document with wrong heading is going live without an audit, thus preventing dead links and redirection issues when corrected - Leave exactly one newline after a heading -- cgit v1.2.1 From 66c4ed6165d5e895ee802d9745205a05dfca9986 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 13 Jul 2016 21:00:46 -0300 Subject: Fix mentioned users list on diff notes --- app/models/concerns/note_on_diff.rb | 3 +++ spec/services/todo_service_spec.rb | 18 ++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb index 2785fbb21c9..7b6a28ccf3c 100644 --- a/app/models/concerns/note_on_diff.rb +++ b/app/models/concerns/note_on_diff.rb @@ -4,6 +4,9 @@ module NoteOnDiff NUMBER_OF_TRUNCATED_DIFF_LINES = 16 included do + attr_mentionable :note, pipeline: :note + participant :author + delegate :blob, :highlighted_diff_lines, to: :diff_file, allow_nil: true end diff --git a/spec/services/todo_service_spec.rb b/spec/services/todo_service_spec.rb index b4522536724..83c18a35472 100644 --- a/spec/services/todo_service_spec.rb +++ b/spec/services/todo_service_spec.rb @@ -435,6 +435,24 @@ describe TodoService, services: true do should_create_todo(user: author, target: mr_unassigned, action: Todo::MARKED) end end + + describe '#new_note' do + let(:mention) { john_doe.to_reference } + let(:diff_note_on_merge_request) { create(:diff_note_on_merge_request, project: project, noteable: mr_unassigned, author: author, note: "Hey #{mention}") } + let(:legacy_diff_note_on_merge_request) { create(:legacy_diff_note_on_merge_request, project: project, noteable: mr_unassigned, author: author, note: "Hey #{mention}") } + + it 'creates a todo for mentioned user on new diff note' do + service.new_note(diff_note_on_merge_request, author) + + should_create_todo(user: john_doe, target: mr_unassigned, author: author, action: Todo::MENTIONED, note: diff_note_on_merge_request) + end + + it 'creates a todo for mentioned user on legacy diff note' do + service.new_note(legacy_diff_note_on_merge_request, author) + + should_create_todo(user: john_doe, target: mr_unassigned, author: author, action: Todo::MENTIONED, note: legacy_diff_note_on_merge_request) + end + end end it 'updates cached counts when a todo is created' do -- cgit v1.2.1 From 16c9abf1ee95551d130e8b8eb454c440ca4c2eb2 Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Thu, 14 Jul 2016 00:28:58 -0300 Subject: Use cattr_accessor instead duplicating code on NoteOnDiff concern --- app/models/concerns/mentionable.rb | 8 ++++---- app/models/concerns/note_on_diff.rb | 3 --- app/models/concerns/participable.rb | 7 +++++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/models/concerns/mentionable.rb b/app/models/concerns/mentionable.rb index 8cac47246db..ec9e0f1b1d0 100644 --- a/app/models/concerns/mentionable.rb +++ b/app/models/concerns/mentionable.rb @@ -14,14 +14,14 @@ module Mentionable attr = attr.to_s mentionable_attrs << [attr, options] end + end + included do # Accessor for attributes marked mentionable. - def mentionable_attrs - @mentionable_attrs ||= [] + cattr_accessor :mentionable_attrs, instance_accessor: false do + [] end - end - included do if self < Participable participant -> (user, ext) { all_references(user, extractor: ext) } end diff --git a/app/models/concerns/note_on_diff.rb b/app/models/concerns/note_on_diff.rb index 7b6a28ccf3c..2785fbb21c9 100644 --- a/app/models/concerns/note_on_diff.rb +++ b/app/models/concerns/note_on_diff.rb @@ -4,9 +4,6 @@ module NoteOnDiff NUMBER_OF_TRUNCATED_DIFF_LINES = 16 included do - attr_mentionable :note, pipeline: :note - participant :author - delegate :blob, :highlighted_diff_lines, to: :diff_file, allow_nil: true end diff --git a/app/models/concerns/participable.rb b/app/models/concerns/participable.rb index 9822844357d..70740c76e43 100644 --- a/app/models/concerns/participable.rb +++ b/app/models/concerns/participable.rb @@ -41,9 +41,12 @@ module Participable def participant(attr) participant_attrs << attr end + end - def participant_attrs - @participant_attrs ||= [] + included do + # Accessor for participant attributes. + cattr_accessor :participant_attrs, instance_accessor: false do + [] end end -- cgit v1.2.1 From efe18f0507e08c7fd0f90a99e0c241c3c4ce107a Mon Sep 17 00:00:00 2001 From: Douglas Barbosa Alexandre Date: Wed, 13 Jul 2016 21:01:15 -0300 Subject: Update CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5ab16db31ce..424f8956a51 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -57,6 +57,7 @@ v 8.10.0 (unreleased) - Throttle the update of `project.pushes_since_gc` to 1 minute. - Allow expanding and collapsing files in diff view (!4990) - Collapse large diffs by default (!4990) + - Fix mentioned users list on diff notes - Check for conflicts with existing Project's wiki path when creating a new project. - Show last push widget in upstream after push to fork - Cache todos pending/done dashboard query counts. -- cgit v1.2.1 From c5555c8a84f10dd4a3f3f213bcf8b088e2a79718 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 15 Jul 2016 17:32:49 -0500 Subject: Don't fail when a LegacyDiffNote didn't store the right diff --- app/models/legacy_diff_note.rb | 4 ++-- app/views/notify/note_merge_request_email.html.haml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/app/models/legacy_diff_note.rb b/app/models/legacy_diff_note.rb index 790dfd4d480..04a651d50ab 100644 --- a/app/models/legacy_diff_note.rb +++ b/app/models/legacy_diff_note.rb @@ -38,7 +38,7 @@ class LegacyDiffNote < Note end def diff_line - @diff_line ||= diff_file.line_for_line_code(self.line_code) + @diff_line ||= diff_file.line_for_line_code(self.line_code) if diff_file end def for_line?(line) @@ -55,7 +55,7 @@ class LegacyDiffNote < Note def active? return @active if defined?(@active) return true if for_commit? - return true unless self.diff + return true unless diff_line return false unless noteable noteable_diff = find_noteable_diff diff --git a/app/views/notify/note_merge_request_email.html.haml b/app/views/notify/note_merge_request_email.html.haml index 35c4b862bb7..ea7e3d199fd 100644 --- a/app/views/notify/note_merge_request_email.html.haml +++ b/app/views/notify/note_merge_request_email.html.haml @@ -1,4 +1,4 @@ -- if @note.diff_note? +- if @note.diff_note? && @note.diff_file %p.details New comment on diff for = link_to @note.diff_file.file_path, @target_url -- cgit v1.2.1 From 979f1182ae7f036e5b647cdab6c80ca73ede968a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 15 Jul 2016 17:33:30 -0500 Subject: Don't fail when Ci::Pipeline doesn't have a project --- app/models/ci/pipeline.rb | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/models/ci/pipeline.rb b/app/models/ci/pipeline.rb index fa4071e2482..7d743ce99f0 100644 --- a/app/models/ci/pipeline.rb +++ b/app/models/ci/pipeline.rb @@ -215,6 +215,8 @@ module Ci end def keep_around_commits + return unless project + project.repository.keep_around(self.sha) project.repository.keep_around(self.before_sha) end -- cgit v1.2.1 From 34653c1e8be0be230943c39713da424a9e22d15b Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 15 Jul 2016 18:17:15 -0500 Subject: Update tests --- spec/models/legacy_diff_note_spec.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/spec/models/legacy_diff_note_spec.rb b/spec/models/legacy_diff_note_spec.rb index d64d89edbd3..d23fc06c3ad 100644 --- a/spec/models/legacy_diff_note_spec.rb +++ b/spec/models/legacy_diff_note_spec.rb @@ -16,10 +16,10 @@ describe LegacyDiffNote, models: true do end describe '#active?' do - it 'is always true when the note has no associated diff' do + it 'is always true when the note has no associated diff line' do note = build(:legacy_diff_note_on_merge_request) - expect(note).to receive(:diff).and_return(nil) + expect(note).to receive(:diff_line).and_return(nil) expect(note).to be_active end @@ -27,7 +27,7 @@ describe LegacyDiffNote, models: true do it 'is never true when the note has no noteable associated' do note = build(:legacy_diff_note_on_merge_request) - expect(note).to receive(:diff).and_return(double) + expect(note).to receive(:diff_line).and_return(double) expect(note).to receive(:noteable).and_return(nil) expect(note).not_to be_active @@ -47,7 +47,7 @@ describe LegacyDiffNote, models: true do merge = build_stubbed(:merge_request, :simple) note = build(:legacy_diff_note_on_merge_request, noteable: merge) - allow(note).to receive(:diff).and_return(double) + allow(note).to receive(:diff_line).and_return(double) expect(note).to receive(:find_noteable_diff).and_return(nil) expect(note).not_to be_active -- cgit v1.2.1 From 2735e5f1c2859ad496bc4f7bd820a7be33f97527 Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 15 Jul 2016 23:46:29 +0000 Subject: Revert "Merge branch 'gl-dropdown-issuable-form' into 'master'" This reverts merge request !4970 --- app/assets/javascripts/dispatcher.js.coffee | 2 -- app/assets/javascripts/labels_select.js.coffee | 31 ++++++------------- app/assets/javascripts/milestone_select.js.coffee | 2 +- app/assets/javascripts/users_select.js.coffee | 9 ++---- app/assets/stylesheets/framework/dropdowns.scss | 2 +- app/assets/stylesheets/pages/merge_requests.scss | 4 --- app/helpers/issuables_helper.rb | 2 +- app/views/shared/issuable/_filter.html.haml | 4 +-- app/views/shared/issuable/_form.html.haml | 36 +++++++++++++++------- .../shared/issuable/_label_dropdown.html.haml | 14 ++++----- .../shared/issuable/_milestone_dropdown.html.haml | 8 ++--- features/project/issues/issues.feature | 1 - features/steps/project/forked_merge_requests.rb | 12 +++++--- features/steps/project/issues/issues.rb | 3 +- spec/features/issues/move_spec.rb | 2 +- spec/features/issues_spec.rb | 5 +-- 16 files changed, 65 insertions(+), 72 deletions(-) diff --git a/app/assets/javascripts/dispatcher.js.coffee b/app/assets/javascripts/dispatcher.js.coffee index b5da15e9e49..afaa6407b05 100644 --- a/app/assets/javascripts/dispatcher.js.coffee +++ b/app/assets/javascripts/dispatcher.js.coffee @@ -39,8 +39,6 @@ class Dispatcher shortcut_handler = new ShortcutsNavigation() new GLForm($('.issue-form')) new IssuableForm($('.issue-form')) - new LabelsSelect() - new MilestoneSelect() when 'projects:merge_requests:new', 'projects:merge_requests:edit' new Diff() shortcut_handler = new ShortcutsNavigation() diff --git a/app/assets/javascripts/labels_select.js.coffee b/app/assets/javascripts/labels_select.js.coffee index 1a802b81452..7688609b301 100644 --- a/app/assets/javascripts/labels_select.js.coffee +++ b/app/assets/javascripts/labels_select.js.coffee @@ -184,22 +184,20 @@ class @LabelsSelect .value() if $dropdown.hasClass 'js-extra-options' - extraData = [] - if showAny - extraData.push( - isAny: true - title: 'Any Label' - ) - if showNo - extraData.push( + data.unshift( id: 0 title: 'No Label' ) - if extraData.length - extraData.push 'divider' - data = extraData.concat(data) + if showAny + data.unshift( + isAny: true + title: 'Any Label' + ) + + if data.length > 2 + data.splice 2, 0, 'divider' callback data @@ -289,12 +287,6 @@ class @LabelsSelect defaultLabel fieldName: $dropdown.data('field-name') id: (label) -> - if $dropdown.hasClass('js-issuable-form-dropdown') - if label.id is 0 - return - else - return label.id - if $dropdown.hasClass("js-filter-submit") and not label.isAny? label.title else @@ -308,9 +300,6 @@ class @LabelsSelect $selectbox.hide() # display:block overrides the hide-collapse rule $value.removeAttr('style') - - return if $dropdown.hasClass('js-issuable-form-dropdown') - if $dropdown.hasClass 'js-multiselect' if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) selectedLabels = $dropdown @@ -332,7 +321,7 @@ class @LabelsSelect clicked: (label) -> _this.enableBulkLabelDropdown() - if $dropdown.hasClass('js-filter-bulk-update') or $dropdown.hasClass('js-issuable-form-dropdown') + if $dropdown.hasClass('js-filter-bulk-update') return page = $('body').data 'page' diff --git a/app/assets/javascripts/milestone_select.js.coffee b/app/assets/javascripts/milestone_select.js.coffee index 3a036569317..8ab03ed93ee 100644 --- a/app/assets/javascripts/milestone_select.js.coffee +++ b/app/assets/javascripts/milestone_select.js.coffee @@ -62,7 +62,7 @@ class @MilestoneSelect title: 'Upcoming' ) - if extraOptions.length > 0 + if extraOptions.length > 2 extraOptions.push 'divider' callback(extraOptions.concat(data)) diff --git a/app/assets/javascripts/users_select.js.coffee b/app/assets/javascripts/users_select.js.coffee index e061f042ca9..344be811e0d 100644 --- a/app/assets/javascripts/users_select.js.coffee +++ b/app/assets/javascripts/users_select.js.coffee @@ -155,13 +155,11 @@ class @UsersSelect # display:block overrides the hide-collapse rule $value.css('display', '') - clicked: (user, $el, e) -> + clicked: (user) -> page = $('body').data 'page' isIssueIndex = page is 'projects:issues:index' isMRIndex = page is page is 'projects:merge_requests:index' - if $dropdown.hasClass('js-filter-bulk-update') or $dropdown.hasClass('js-issuable-form-dropdown') - e.preventDefault() - selectedId = user.id + if $dropdown.hasClass('js-filter-bulk-update') return if $dropdown.hasClass('js-filter-submit') and (isIssueIndex or isMRIndex) @@ -174,8 +172,7 @@ class @UsersSelect .closest('.selectbox') .find("input[name='#{$dropdown.data('field-name')}']").val() assignTo(selected) - id: (user) -> - user.id + renderRow: (user) -> username = if user.username then "@#{user.username}" else "" avatar = if user.avatar_url then user.avatar_url else false diff --git a/app/assets/stylesheets/framework/dropdowns.scss b/app/assets/stylesheets/framework/dropdowns.scss index 3fd0e12568d..d4e900f80ef 100644 --- a/app/assets/stylesheets/framework/dropdowns.scss +++ b/app/assets/stylesheets/framework/dropdowns.scss @@ -56,7 +56,7 @@ position: absolute; top: 50%; right: 6px; - margin-top: -6px; + margin-top: -4px; color: $dropdown-toggle-icon-color; font-size: 10px; } diff --git a/app/assets/stylesheets/pages/merge_requests.scss b/app/assets/stylesheets/pages/merge_requests.scss index dba9a7ab3ee..15c6c9f231a 100644 --- a/app/assets/stylesheets/pages/merge_requests.scss +++ b/app/assets/stylesheets/pages/merge_requests.scss @@ -324,10 +324,6 @@ .issuable-form-select-holder { display: inline-block; width: 250px; - - .dropdown-menu-toggle { - width: 100%; - } } .table-holder { diff --git a/app/helpers/issuables_helper.rb b/app/helpers/issuables_helper.rb index a3a8c7d5ff9..47d174361db 100644 --- a/app/helpers/issuables_helper.rb +++ b/app/helpers/issuables_helper.rb @@ -9,7 +9,7 @@ module IssuablesHelper def multi_label_name(current_labels, default_label) # current_labels may be a string from before - if current_labels.is_a?(Array) && current_labels.any? + if current_labels.is_a?(Array) if current_labels.count > 1 "#{current_labels[0]} +#{current_labels.count - 1} more" else diff --git a/app/views/shared/issuable/_filter.html.haml b/app/views/shared/issuable/_filter.html.haml index d5199bd86dd..094d6636c66 100644 --- a/app/views/shared/issuable/_filter.html.haml +++ b/app/views/shared/issuable/_filter.html.haml @@ -21,10 +21,10 @@ placeholder: "Search assignee", data: { any_user: "Any Assignee", first_user: (current_user.username if current_user), null_user: true, current_user: true, project_id: (@project.id if @project), selected: params[:assignee_id], field_name: "assignee_id", default_label: "Assignee" } }) .filter-item.inline.milestone-filter - = render "shared/issuable/milestone_dropdown", selected: params[:milestone_title], name: :milestone_title, show_any: true, show_upcoming: true + = render "shared/issuable/milestone_dropdown" .filter-item.inline.labels-filter - = render "shared/issuable/label_dropdown", selected: params[:label_name], data_options: { field_name: "label_name[]" } + = render "shared/issuable/label_dropdown" .pull-right = render 'shared/sort_dropdown' diff --git a/app/views/shared/issuable/_form.html.haml b/app/views/shared/issuable/_form.html.haml index a8a8426df52..c30bdb0ae91 100644 --- a/app/views/shared/issuable/_form.html.haml +++ b/app/views/shared/issuable/_form.html.haml @@ -52,24 +52,38 @@ = f.label :assignee_id, "Assignee", class: "control-label #{"col-lg-4" if has_due_date}" .col-sm-10{ class: ("col-lg-8" if has_due_date) } .issuable-form-select-holder - - project = @target_project || @project - - if issuable.assignee_id - = hidden_field_tag("#{issuable.class.model_name.param_key}[assignee_id]", issuable.assignee_id) - = dropdown_tag(user_dropdown_label(issuable.assignee_id, "Assignee"), options: { toggle_class: "js-user-search js-issuable-form-dropdown js-assignee-search", title: "Filter by assignee", filter: true, dropdown_class: "dropdown-menu-user dropdown-menu-selectable dropdown-menu-assignee js-filter-submit", - placeholder: "Search assignee", data: { first_user: (current_user.username if current_user), null_user: true, current_user: true, project_id: (project.id if project), selected: issuable.assignee_id, field_name: "#{issuable.class.model_name.param_key}[assignee_id]", default_label: "Assignee" } }) + = users_select_tag("#{issuable.class.model_name.param_key}[assignee_id]", + placeholder: 'Select assignee', class: 'custom-form-control', null_user: true, + selected: issuable.assignee_id, project: @target_project || @project, + first_user: true, current_user: true, include_blank: true) + %div + = link_to 'Assign to me', '#', class: 'assign-to-me-link prepend-top-5 inline' .form-group.issue-milestone = f.label :milestone_id, "Milestone", class: "control-label #{"col-lg-4" if has_due_date}" .col-sm-10{ class: ("col-lg-8" if has_due_date) } - .issuable-form-select-holder - = render "shared/issuable/milestone_dropdown", selected: issuable.milestone_id, name: "#{issuable.class.model_name.param_key}[milestone_id]", show_any: false, show_upcoming: false + - if milestone_options(issuable).present? + .issuable-form-select-holder + = f.select(:milestone_id, milestone_options(issuable), + { include_blank: true }, { class: 'select2', data: { placeholder: 'Select milestone' } }) + - else + .prepend-top-10 + %span.light No open milestones available. + - if can? current_user, :admin_milestone, issuable.project + %div + = link_to 'Create new milestone', new_namespace_project_milestone_path(issuable.project.namespace, issuable.project), target: :blank, class: "prepend-top-5 inline" .form-group - has_labels = issuable.project.labels.any? - - selected_labels = issuable.label_ids.any? ? issuable.label_ids : nil - - label_dropdown_toggle = issuable.labels.map { |label| label.title } = f.label :label_ids, "Labels", class: "control-label #{"col-lg-4" if has_due_date}" .col-sm-10{ class: "#{"col-lg-8" if has_due_date} #{'issuable-form-padding-top' if !has_labels}" } - .issuable-form-select-holder - = render "shared/issuable/label_dropdown", classes: ["js-issuable-form-dropdown"], selected: selected_labels, selected_toggle: label_dropdown_toggle, data_options: { field_name: "#{issuable.class.model_name.param_key}[label_ids][]", show_any: "false" } + - if has_labels + .issuable-form-select-holder + = f.collection_select :label_ids, issuable.project.labels.all, :id, :name, + { selected: issuable.label_ids }, multiple: true, class: 'select2', data: { placeholder: "Select labels" } + - else + %span.light No labels yet. + - if can? current_user, :admin_label, issuable.project + %div + = link_to 'Create new label', new_namespace_project_label_path(issuable.project.namespace, issuable.project), target: :blank, class: "prepend-top-5 inline" - if has_due_date .col-lg-6 .form-group diff --git a/app/views/shared/issuable/_label_dropdown.html.haml b/app/views/shared/issuable/_label_dropdown.html.haml index bcbe133ce62..d34d28f6736 100644 --- a/app/views/shared/issuable/_label_dropdown.html.haml +++ b/app/views/shared/issuable/_label_dropdown.html.haml @@ -4,21 +4,19 @@ - show_footer = local_assigns.fetch(:show_footer, true) - data_options = local_assigns.fetch(:data_options, {}) - classes = local_assigns.fetch(:classes, []) -- selected = local_assigns.fetch(:selected, nil) -- selected_toggle = local_assigns.fetch(:selected_toggle, nil) -- dropdown_data = {toggle: 'dropdown', field_name: "label_name[]", show_no: "true", show_any: "true", selected: selected, project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"} +- dropdown_data = {toggle: 'dropdown', field_name: 'label_name[]', show_no: "true", show_any: "true", selected: params[:label_name], project_id: @project.try(:id), labels: labels_filter_path, default_label: "Label"} - dropdown_data.merge!(data_options) - classes << 'js-extra-options' if extra_options - classes << 'js-filter-submit' if filter_submit -- if selected.present? - - if selected.respond_to?('any?') - - selected.each do |label| - = hidden_field_tag data_options[:field_name], label, id: nil +- if params[:label_name].present? + - if params[:label_name].respond_to?('any?') + - params[:label_name].each do |label| + = hidden_field_tag "label_name[]", label, id: nil .dropdown %button.dropdown-menu-toggle.js-label-select.js-multiselect{class: classes.join(' '), type: "button", data: dropdown_data} %span.dropdown-toggle-text - = h(multi_label_name(selected_toggle || selected, "Label")) + = h(multi_label_name(params[:label_name], "Label")) = icon('chevron-down') .dropdown-menu.dropdown-select.dropdown-menu-paging.dropdown-menu-labels.dropdown-menu-selectable = render partial: "shared/issuable/label_page_default", locals: { title: "Filter by label", show_footer: show_footer, show_create: show_create } diff --git a/app/views/shared/issuable/_milestone_dropdown.html.haml b/app/views/shared/issuable/_milestone_dropdown.html.haml index 9188ef72d52..2fcf40ece99 100644 --- a/app/views/shared/issuable/_milestone_dropdown.html.haml +++ b/app/views/shared/issuable/_milestone_dropdown.html.haml @@ -1,7 +1,7 @@ -- if selected.present? - = hidden_field_tag(name, selected) -= dropdown_tag(milestone_dropdown_label(selected), options: { title: "Filter by milestone", toggle_class: 'js-milestone-select js-filter-submit', filter: true, dropdown_class: "dropdown-menu-selectable", - placeholder: "Search milestones", footer_content: @project.present?, data: { show_no: true, show_any: show_any, show_upcoming: show_upcoming, field_name: name, selected: selected, project_id: @project.try(:id), milestones: milestones_filter_dropdown_path, default_label: "Milestone" } }) do +- if params[:milestone_title].present? + = hidden_field_tag(:milestone_title, params[:milestone_title]) += dropdown_tag(milestone_dropdown_label(params[:milestone_title]), options: { title: "Filter by milestone", toggle_class: 'js-milestone-select js-filter-submit', filter: true, dropdown_class: "dropdown-menu-selectable", + placeholder: "Search milestones", footer_content: @project.present?, data: { show_no: true, show_any: true, show_upcoming: true, field_name: "milestone_title", selected: params[:milestone_title], project_id: @project.try(:id), milestones: milestones_filter_dropdown_path, default_label: "Milestone" } }) do - if @project %ul.dropdown-footer-list - if can? current_user, :admin_milestone, @project diff --git a/features/project/issues/issues.feature b/features/project/issues/issues.feature index 80670063ea0..358e622b736 100644 --- a/features/project/issues/issues.feature +++ b/features/project/issues/issues.feature @@ -37,7 +37,6 @@ Feature: Project Issues And I submit new issue "500 error on profile" Then I should see issue "500 error on profile" - @javascript Scenario: I submit new unassigned issue with labels Given project "Shop" has labels: "bug", "feature", "enhancement" And I click link "New Issue" diff --git a/features/steps/project/forked_merge_requests.rb b/features/steps/project/forked_merge_requests.rb index 8f71dfdd899..6b56a77b832 100644 --- a/features/steps/project/forked_merge_requests.rb +++ b/features/steps/project/forked_merge_requests.rb @@ -135,17 +135,19 @@ class Spinach::Features::ProjectForkedMergeRequests < Spinach::FeatureSteps end step 'I click "Assign to" dropdown"' do - click_button 'Assignee' + first('.ajax-users-select').click end step 'I should see the target project ID in the input selector' do - expect(find('.js-assignee-search')["data-project-id"]).to eq "#{@project.id}" + expect(page).to have_selector("input[data-project-id=\"#{@project.id}\"]") end step 'I should see the users from the target project ID' do - expect(page).to have_content 'Unassigned' - expect(page).to have_content current_user.name - expect(page).to have_content @project.users.first.name + expect(page).to have_selector('.user-result', visible: true, count: 3) + users = page.all('.user-name') + expect(users[0].text).to eq 'Unassigned' + expect(users[1].text).to eq current_user.name + expect(users[2].text).to eq @project.users.first.name end # Verify a link is generated against the correct project diff --git a/features/steps/project/issues/issues.rb b/features/steps/project/issues/issues.rb index b785e15f70e..35f166c7c08 100644 --- a/features/steps/project/issues/issues.rb +++ b/features/steps/project/issues/issues.rb @@ -82,8 +82,7 @@ class Spinach::Features::ProjectIssues < Spinach::FeatureSteps step 'I submit new issue "500 error on profile" with label \'bug\'' do fill_in "issue_title", with: "500 error on profile" - click_button "Label" - click_link "bug" + select 'bug', from: "Labels" click_button "Submit issue" end diff --git a/spec/features/issues/move_spec.rb b/spec/features/issues/move_spec.rb index 055210399a7..7773c486b4e 100644 --- a/spec/features/issues/move_spec.rb +++ b/spec/features/issues/move_spec.rb @@ -55,7 +55,7 @@ feature 'issue move to another project' do first('.select2-choice').click end - fill_in('s2id_autogen1_search', with: new_project_search.name) + fill_in('s2id_autogen2_search', with: new_project_search.name) page.within '.select2-drop' do expect(page).to have_content(new_project_search.name) diff --git a/spec/features/issues_spec.rb b/spec/features/issues_spec.rb index d00cffa4e2b..d51c9abea19 100644 --- a/spec/features/issues_spec.rb +++ b/spec/features/issues_spec.rb @@ -50,8 +50,9 @@ describe 'Issues', feature: true do expect(page).to have_content "Assignee #{@user.name}" - first('.js-user-search').click - click_link 'Unassigned' + first('#s2id_issue_assignee_id').click + sleep 2 # wait for ajax stuff to complete + first('.user-result').click click_button 'Save changes' -- cgit v1.2.1 From 82959349dd97450a166d42547083f8dfd3d1491e Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Fri, 15 Jul 2016 20:22:35 -0500 Subject: Don't fail to highlight when Rouge doesn't have a lexer --- lib/banzai/filter/syntax_highlight_filter.rb | 15 +++++----- .../banzai/filter/syntax_highlight_filter_spec.rb | 34 +++++++++++++++++----- 2 files changed, 35 insertions(+), 14 deletions(-) diff --git a/lib/banzai/filter/syntax_highlight_filter.rb b/lib/banzai/filter/syntax_highlight_filter.rb index 028edef704b..91f0159f9a1 100644 --- a/lib/banzai/filter/syntax_highlight_filter.rb +++ b/lib/banzai/filter/syntax_highlight_filter.rb @@ -19,21 +19,22 @@ module Banzai language = node.attr('class') code = node.text - lexer = Rouge::Lexer.find_fancy(language) + css_classes = "code highlight" + + lexer = Rouge::Lexer.find_fancy(language) || Rouge::Lexers::PlainText formatter = Rouge::Formatters::HTML.new - css_classes = "code highlight js-syntax-highlight #{lexer.tag}" begin - highlighted = '' - highlighted << %(
)
-          highlighted << formatter.format(lexer.lex(code))
-          highlighted << %(
) + code = formatter.format(lexer.lex(code)) + + css_classes << " js-syntax-highlight #{lexer.tag}" rescue # Gracefully handle syntax highlighter bugs/errors to ensure # users can still access an issue/comment/etc. - highlighted = "
#{code}
" end + highlighted = %(
#{code}
) + # Extracted to a method to measure it replace_parent_pre_element(node, highlighted) end diff --git a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb index 48ebc81cf82..b1370bca833 100644 --- a/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb +++ b/spec/lib/banzai/filter/syntax_highlight_filter_spec.rb @@ -3,15 +3,35 @@ require 'spec_helper' describe Banzai::Filter::SyntaxHighlightFilter, lib: true do include FilterSpecHelper - it 'highlights valid code blocks' do - result = filter('
def fun end')
-    expect(result.to_html).to eq("
def fun end
") + context "when no language is specified" do + it "highlights as plaintext" do + result = filter('
def fun end
') + expect(result.to_html).to eq('
def fun end
') + end end - it 'passes through invalid code blocks' do - allow_any_instance_of(Rouge::Formatter).to receive(:format).and_raise(StandardError) + context "when a valid language is specified" do + it "highlights as that language" do + result = filter('
def fun end
') + expect(result.to_html).to eq('
def fun end
') + end + end + + context "when an invalid language is specified" do + it "highlights as plaintext" do + result = filter('
This is a test
') + expect(result.to_html).to eq('
This is a test
') + end + end + + context "when Rouge formatting fails" do + before do + allow_any_instance_of(Rouge::Formatter).to receive(:format).and_raise(StandardError) + end - result = filter('
This is a test
') - expect(result.to_html).to eq('
This is a test
') + it "highlights as plaintext" do + result = filter('
This is a test
') + expect(result.to_html).to eq('
This is a test
') + end end end -- cgit v1.2.1 From e94d3834c7d32f6e8a1d3d4c32d8be8cb1d7810c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alejandro=20Rodr=C3=ADguez?= Date: Fri, 15 Jul 2016 21:31:26 -0400 Subject: Fix a bug where the project's repository path was returned instead of the wiki path --- lib/api/internal.rb | 7 ++++++- spec/requests/api/internal_spec.rb | 14 +++++++++++--- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/api/internal.rb b/lib/api/internal.rb index d5dfba5e0cc..959b700de78 100644 --- a/lib/api/internal.rb +++ b/lib/api/internal.rb @@ -63,7 +63,12 @@ module API if access_status.status # Return the repository full path so that gitlab-shell has it when # handling ssh commands - response[:repository_path] = project.repository.path_to_repo + response[:repository_path] = + if wiki? + project.wiki.repository.path_to_repo + else + project.repository.path_to_repo + end end response diff --git a/spec/requests/api/internal_spec.rb b/spec/requests/api/internal_spec.rb index e567d36afa8..f6f85d6e95e 100644 --- a/spec/requests/api/internal_spec.rb +++ b/spec/requests/api/internal_spec.rb @@ -56,13 +56,21 @@ describe API::API, api: true do context "git push with project.wiki" do it 'responds with success' do - project_wiki = create(:project, name: 'my.wiki', path: 'my.wiki') - project_wiki.team << [user, :developer] + push(key, project.wiki) - push(key, project_wiki) + expect(response).to have_http_status(200) + expect(json_response["status"]).to be_truthy + expect(json_response["repository_path"]).to eq(project.wiki.repository.path_to_repo) + end + end + + context "git pull with project.wiki" do + it 'responds with success' do + pull(key, project.wiki) expect(response).to have_http_status(200) expect(json_response["status"]).to be_truthy + expect(json_response["repository_path"]).to eq(project.wiki.repository.path_to_repo) end end -- cgit v1.2.1 From 72818f2c1573b7664d4b41692dc51db1e5c28fbb Mon Sep 17 00:00:00 2001 From: Kamil Trzcinski Date: Fri, 15 Jul 2016 16:17:46 +0200 Subject: Fix creation of deployment on build that is retried, redeployed or rollback --- CHANGELOG | 1 + app/models/ci/build.rb | 1 + spec/services/create_deployment_service_spec.rb | 16 ++++++++++++++++ 3 files changed, 18 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5518429e1b5..0ab37eea3c6 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -60,6 +60,7 @@ v 8.10.0 (unreleased) - Allow expanding and collapsing files in diff view (!4990) - Collapse large diffs by default (!4990) - Fix mentioned users list on diff notes + - Fix creation of deployment on build that is retried, redeployed or rollback - Check for conflicts with existing Project's wiki path when creating a new project. - Show last push widget in upstream after push to fork - Cache todos pending/done dashboard query counts. diff --git a/app/models/ci/build.rb b/app/models/ci/build.rb index e189dbac285..b24527247e0 100644 --- a/app/models/ci/build.rb +++ b/app/models/ci/build.rb @@ -53,6 +53,7 @@ module Ci new_build.stage_idx = build.stage_idx new_build.trigger_request = build.trigger_request new_build.user = user + new_build.environment = build.environment new_build.save MergeRequests::AddTodoWhenBuildFailsService.new(build.project, nil).close(new_build) new_build diff --git a/spec/services/create_deployment_service_spec.rb b/spec/services/create_deployment_service_spec.rb index 654e441f3cd..8da2a2b3c1b 100644 --- a/spec/services/create_deployment_service_spec.rb +++ b/spec/services/create_deployment_service_spec.rb @@ -89,6 +89,12 @@ describe CreateDeploymentService, services: true do expect_any_instance_of(described_class).to receive(:execute) subject end + + it 'is set as deployable' do + subject + + expect(Deployment.last.deployable).to eq(deployable) + end end context 'without environment specified' do @@ -105,6 +111,8 @@ describe CreateDeploymentService, services: true do context 'when build succeeds' do it_behaves_like 'does create environment and deployment' do + let(:deployable) { build } + subject { build.success } end end @@ -114,6 +122,14 @@ describe CreateDeploymentService, services: true do subject { build.drop } end end + + context 'when build is retried' do + it_behaves_like 'does create environment and deployment' do + let(:deployable) { Ci::Build.retry(build) } + + subject { deployable.success } + end + end end end end -- cgit v1.2.1 From 1395edc06f0f06e4cfe8b37b49298c739b9eda2e Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Sat, 16 Jul 2016 17:47:05 -0500 Subject: Remove deploy to production button --- app/views/projects/ci/pipelines/_pipeline.html.haml | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/app/views/projects/ci/pipelines/_pipeline.html.haml b/app/views/projects/ci/pipelines/_pipeline.html.haml index b53a8633937..ebe4204788e 100644 --- a/app/views/projects/ci/pipelines/_pipeline.html.haml +++ b/app/views/projects/ci/pipelines/_pipeline.html.haml @@ -58,16 +58,7 @@ .controls.hidden-xs.pull-right - artifacts = pipeline.builds.latest.select { |b| b.artifacts? } - if artifacts.present? - .btn-group.inline - .btn-group - %a.dropdown-toggle.btn.btn-default{type: 'button', 'data-toggle' => 'dropdown'} - = icon("play") - %b.caret - %ul.dropdown-menu.dropdown-menu-align-right - %li - = link_to '#' do - = icon("play") - %span Deploy to production + .inline .btn-group %a.dropdown-toggle.btn.btn-default.build-artifacts{type: 'button', 'data-toggle' => 'dropdown'} = icon("download") -- cgit v1.2.1 From e72fe97e42c1a97bd6fd305a61e90dbb193c9f45 Mon Sep 17 00:00:00 2001 From: Annabel Dunstone Date: Sat, 16 Jul 2016 17:51:39 -0500 Subject: Align cancel and retry buttons --- app/assets/stylesheets/pages/pipelines.scss | 2 ++ app/views/projects/ci/pipelines/_pipeline.html.haml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/app/assets/stylesheets/pages/pipelines.scss b/app/assets/stylesheets/pages/pipelines.scss index 08da4e290dc..a0334207c68 100644 --- a/app/assets/stylesheets/pages/pipelines.scss +++ b/app/assets/stylesheets/pages/pipelines.scss @@ -129,6 +129,8 @@ } .cancel-retry-btns { + vertical-align: middle; + .btn:not(:first-child) { margin-left: 8px; } diff --git a/app/views/projects/ci/pipelines/_pipeline.html.haml b/app/views/projects/ci/pipelines/_pipeline.html.haml index ebe4204788e..631873fb0a3 100644 --- a/app/views/projects/ci/pipelines/_pipeline.html.haml +++ b/app/views/projects/ci/pipelines/_pipeline.html.haml @@ -71,7 +71,7 @@ %span Download '#{build.name}' artifacts - if can?(current_user, :update_pipeline, @project) - .cancel-retry-btns + .cancel-retry-btns.inline - if pipeline.retryable? = link_to retry_namespace_project_pipeline_path(@project.namespace, @project, pipeline.id), class: 'btn has-tooltip', title: "Retry", method: :post do = icon("repeat") -- cgit v1.2.1 From 63e951797102b37ef99a5651e18c45dc24e7f75c Mon Sep 17 00:00:00 2001 From: Achilleas Pipinellis Date: Sun, 17 Jul 2016 11:10:18 +0300 Subject: Fix CI yaml example --- doc/ci/yaml/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/ci/yaml/README.md b/doc/ci/yaml/README.md index 16a1461a7e4..50fa263f693 100644 --- a/doc/ci/yaml/README.md +++ b/doc/ci/yaml/README.md @@ -985,11 +985,11 @@ directive defined in `.postgres_services` and `.mysql_services` respectively: - ruby test:postgres: - << *job_definition + <<: *job_definition services: *postgres_definition test:mysql: - << *job_definition + <<: *job_definition services: *mysql_definition ``` -- cgit v1.2.1 From 565b3a183978a7952ef92d2e1e05b429f38322fa Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 17 Jul 2016 20:12:32 -0700 Subject: Allow a project import URL to be blank to prevent false positives preventing settings from being saved --- app/models/project.rb | 4 ++-- spec/models/project_spec.rb | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/app/models/project.rb b/app/models/project.rb index e7b9835692d..8d71e01103c 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -162,7 +162,7 @@ class Project < ActiveRecord::Base validates :namespace, presence: true validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id - validates :import_url, addressable_url: true, if: :import_url + validates :import_url, addressable_url: true, if: "import_url.present?" validates :star_count, numericality: { greater_than_or_equal_to: 0 } validate :check_limit, on: :create validate :avatar_type, @@ -482,7 +482,7 @@ class Project < ActiveRecord::Base end def create_or_update_import_data(data: nil, credentials: nil) - return unless valid_import_url? + return unless import_url.present? && valid_import_url? project_import_data = import_data || build_import_data if data diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index e842c58dd82..9dc34276f18 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -142,10 +142,10 @@ describe Project, models: true do expect(project2).to be_valid end - it 'does not allow to introduce an empty URI' do + it 'allows an empty URI' do project2 = build(:project, import_url: '') - expect(project2).not_to be_valid + expect(project2).to be_valid end it 'does not produce import data on an empty URI' do -- cgit v1.2.1 From 328da189d21673b7f8937d122363ef0c710f9ae9 Mon Sep 17 00:00:00 2001 From: Stan Hu Date: Sun, 17 Jul 2016 20:57:11 -0700 Subject: Fix spec to set import_url before attempting to create import_data --- spec/lib/gitlab/bitbucket_import/client_spec.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/lib/gitlab/bitbucket_import/client_spec.rb b/spec/lib/gitlab/bitbucket_import/client_spec.rb index 760d66a1488..7543c29bcc4 100644 --- a/spec/lib/gitlab/bitbucket_import/client_spec.rb +++ b/spec/lib/gitlab/bitbucket_import/client_spec.rb @@ -54,12 +54,12 @@ describe Gitlab::BitbucketImport::Client, lib: true do context 'project import' do it 'calls .from_project with no errors' do project = create(:empty_project) + project.import_url = "ssh://git@bitbucket.org/test/test.git" project.create_or_update_import_data(credentials: { user: "git", password: nil, bb_session: { bitbucket_access_token: "test", bitbucket_access_token_secret: "test" } }) - project.import_url = "ssh://git@bitbucket.org/test/test.git" expect { described_class.from_project(project) }.not_to raise_error end -- cgit v1.2.1 From 7a72c75a9cfeb2793e68e55ef091c1c298f27832 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 18 Jul 2016 08:54:25 +0200 Subject: use method in validates statement --- app/models/project.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/models/project.rb b/app/models/project.rb index 8d71e01103c..d3ae4a2dd0b 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -162,7 +162,7 @@ class Project < ActiveRecord::Base validates :namespace, presence: true validates_uniqueness_of :name, scope: :namespace_id validates_uniqueness_of :path, scope: :namespace_id - validates :import_url, addressable_url: true, if: "import_url.present?" + validates :import_url, addressable_url: true, if: :external_import? validates :star_count, numericality: { greater_than_or_equal_to: 0 } validate :check_limit, on: :create validate :avatar_type, -- cgit v1.2.1 From 785043841873f120e8e26da706060500b4a333a6 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 15 Jul 2016 11:34:23 +0200 Subject: limit project expor retry to only 3 --- app/workers/project_export_worker.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/workers/project_export_worker.rb b/app/workers/project_export_worker.rb index 39f6037e077..615311e63f5 100644 --- a/app/workers/project_export_worker.rb +++ b/app/workers/project_export_worker.rb @@ -1,7 +1,7 @@ class ProjectExportWorker include Sidekiq::Worker - sidekiq_options queue: :gitlab_shell, retry: true + sidekiq_options queue: :gitlab_shell, retry: 3 def perform(current_user_id, project_id) current_user = User.find(current_user_id) -- cgit v1.2.1 From 5ede1331d45199ff1b79d98c70bddda86837de48 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Fri, 15 Jul 2016 11:44:38 +0200 Subject: added changelog --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 5518429e1b5..8b70c6bf3df 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -103,6 +103,7 @@ v 8.10.0 (unreleased) - Fix issues importing projects from EE to CE - Fix creating group with space in group path - Create Todos for Issue author when assign or mention himself (Katarzyna Kobierska) + - Limit the number of retries on error to 3 for exporting projects v 8.9.6 - Fix importing of events under notes for GitLab projects. !5154 -- cgit v1.2.1