1. 30 1月, 2019 1 次提交
  2. 16 1月, 2019 2 次提交
    • Y
      Refactor code for protecting default branches · 52eeb56b
      Yorick Peterse 提交于
      This refactors some of the logic used for protecting default branches,
      in particular Project#after_create_default_branch. The logic for this
      method is moved into a separate service class. Ideally we'd get rid of
      Project#after_create_default_branch entirely, but unfortunately
      Project#after_import depends on it. This means it has to stick around
      until we also refactor Project#after_import.
      
      For branch protection levels we introduce
      Gitlab::Access::BranchProtection, which provides a small wrapper around
      Integer based branch protection levels. Using this class removes the
      need for having to constantly refer to Gitlab::Access::PROTECTION_*
      constants.
      52eeb56b
    • Y
      Refactor checking personal project limits · 2d9a6f2b
      Yorick Peterse 提交于
      This refactors the code used for checking if a user has exceeded the
      personal projects limit. As part of this refactor the method has been
      renamed from Project#check_limit to "check_personal_projects_limit", as
      this name makes it much more clear what the purpose of the method is.
      Standalone unit tests have also been added, as before we only had a
      single generic validation test that did not cover all cases.
      
      The old implementation of the refactored method also included a `rescue`
      statement. This code would only run when a project creator was not set.
      The error that would be added wasn't super useful, especially since
      there would already be errors for the creator not being present. As none
      of the other code in the "check_personal_projects_limit" raises, it has
      been removed.
      2d9a6f2b
  3. 14 1月, 2019 2 次提交
  4. 11 1月, 2019 2 次提交
  5. 09 1月, 2019 1 次提交
    • S
      Remove get_build method for find_by_id · ab6b9a1c
      Steve Azzopardi 提交于
      The original intention of `get_build` was as a workaround not to violate
      `CodeReuse/ActiveRecord`. `find_by_id` does the exact same thing but
      does not violate the rubocop rule.
      ab6b9a1c
  6. 08 1月, 2019 5 次提交
    • G
      Only set as `read_only` when starting the per-project migration · ee4af0c6
      Gabriel Mazetto 提交于
      In the previous code, we locked the project during the migration
      scheduling step, which works fine for small setups, but can be
      problematic in really big installations.
      
      We now moved the logic to inside the worker, so we minimize the time a
      project will be read-only. We also make sure we only do that if
      reference counter is `0` (no current operation is in progress).
      ee4af0c6
    • P
      Implement error tracking configuration · 6710c874
      Peter Leitzen 提交于
      Re-use operations controller which already handles tracing settings.
      6710c874
    • R
      Add table and model for error tracking settings · f40b5860
      Reuben Pereira 提交于
      f40b5860
    • S
      Create `get_build` for project model · f9c8822a
      Steve Azzopardi 提交于
      Inside of `Projects::ArtifactsController` and
      `Projects::BuildArtifactsController` we fetching the build by id using
      active record directly which violates `CodeReuse/ActiveRecord` rubocop
      rule. Create `get_build` inside of `project` model which does the same
      thing.
      f9c8822a
    • S
      Refactor project.latest_successful_builds_for def · 7ac32ae2
      Steve Azzopardi 提交于
      `project.latest_successful_builds_for(ref)` is being used to find a
      single job all the time. This results into us having to call `find_by`
      inside of the controller which violates our CodeReuse/ActiveRecord
      rubocop rule.
      
      Refactor `project.latest_successful_builds_for(ref)` to
      `project.latest_successful_build_for(job_name, ref)` which will execute
      the `find_by` inside of the model.
      
      Also create `project.latest_successful_build_for!(job_name, ref)` which
      raises an exception instead of returning nil.
      7ac32ae2
  7. 04 1月, 2019 3 次提交
  8. 03 1月, 2019 2 次提交
  9. 02 1月, 2019 3 次提交
  10. 22 12月, 2018 1 次提交
  11. 19 12月, 2018 3 次提交
  12. 13 12月, 2018 1 次提交
  13. 12 12月, 2018 1 次提交
  14. 11 12月, 2018 1 次提交
    • Y
      Refactor Project#create_or_update_import_data · 26378511
      Yorick Peterse 提交于
      In https://gitlab.com/gitlab-org/release/framework/issues/28 we found
      that this method was changed a lot over the years: 43 times if our
      calculations were correct. Looking at the method, it had quite a few
      branches going on:
      
          def create_or_update_import_data(data: nil, credentials: nil)
            return if data.nil? && credentials.nil?
      
            project_import_data = import_data || build_import_data
      
            if data
              project_import_data.data ||= {}
              project_import_data.data = project_import_data.data.merge(data)
            end
      
            if credentials
              project_import_data.credentials ||= {}
              project_import_data.credentials =
                project_import_data.credentials.merge(credentials)
            end
      
            project_import_data
          end
      
      If we turn the || and ||= operators into regular if statements, we can
      see a bit more clearly that this method has quite a lot of branches in
      it:
      
          def create_or_update_import_data(data: nil, credentials: nil)
            if data.nil? && credentials.nil?
              return
            else
              project_import_data =
                if import_data
                  import_data
                else
                  build_import_data
                end
      
              if data
                if project_import_data.data
                  # nothing
                else
                  project_import_data.data = {}
                end
      
                project_import_data.data =
                  project_import_data.data.merge(data)
              end
      
              if credentials
                if project_import_data.credentials
                  # nothing
                else
                  project_import_data.credentials = {}
                end
      
                project_import_data.credentials =
                  project_import_data.credentials.merge(credentials)
              end
      
              project_import_data
            end
          end
      
      The number of if statements and branches here makes it easy to make
      mistakes. To resolve this, we refactor this code in such a way that we
      can get rid of all but the first `if data.nil? && credentials.nil?`
      statement. We can do this by simply sending `to_h` to `nil` in the right
      places, which removes the need for statements such as `if data`.
      
      Since this data gets written to a database, in ProjectImportData we do
      make sure to not write empty Hash values. This requires an `unless`
      (which is really a `if !`), but the resulting code is still very easy to
      read.
      26378511
  15. 09 12月, 2018 12 次提交