File: helpers.rb

package info (click to toggle)
gitlab 17.6.5-19
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 629,368 kB
  • sloc: ruby: 1,915,304; javascript: 557,307; sql: 60,639; xml: 6,509; sh: 4,567; makefile: 1,239; python: 406
file content (82 lines) | stat: -rw-r--r-- 2,615 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# frozen_string_literal: true

module SystemCheck
  # Helpers used inside a SystemCheck instance to standardize output responses
  module Helpers
    include ::Gitlab::TaskHelpers

    # Display a message telling to fix and rerun the checks
    def fix_and_rerun
      $stdout.puts Rainbow('  Please fix the error above and rerun the checks.').red
    end

    # Display a formatted list of references (documentation or links) where to find more information
    #
    # @param [Array<String>] sources one or more references (documentation or links)
    def for_more_information(*sources)
      $stdout.puts Rainbow('  For more information see:').blue
      sources.each do |source|
        $stdout.puts "  #{source}"
      end
    end

    # Construct a help page based on the instance's external_url
    #
    # @param <String> path of the documentation page
    # @param <String> anchor to the specific docs heading
    #
    # @return <String> URL of the help page
    def construct_help_page_url(path, anchor = nil)
      Rails.application.routes.url_helpers.help_page_url(path, anchor)
    end

    def see_installation_guide_section(section)
      "doc/install/installation.md in section \"#{section}\""
    end

    # @deprecated This will no longer be used when all checks were executed using SystemCheck
    def finished_checking(component)
      $stdout.puts ''
      $stdout.puts "Checking #{Rainbow(component).yellow} ... #{Rainbow('Finished').green}"
      $stdout.puts ''
    end

    # @deprecated This will no longer be used when all checks were executed using SystemCheck
    def start_checking(component)
      $stdout.puts "Checking #{Rainbow(component).yellow} ..."
      $stdout.puts ''
    end

    # Display a formatted list of instructions on how to fix the issue identified by the #check?
    #
    # @param [Array<String>] steps one or short sentences with help how to fix the issue
    def try_fixing_it(*steps)
      steps = steps.shift if steps.first.is_a?(Array)

      $stdout.puts Rainbow('  Try fixing it:').blue
      steps.each do |step|
        $stdout.puts "  #{step}"
      end
    end

    def sanitized_message(project)
      if should_sanitize?
        "#{Rainbow(project.namespace_id.to_s).yellow}/#{Rainbow(project.id.to_s).yellow} ... "
      else
        "#{Rainbow(project.full_name).yellow} ... "
      end
    end

    def should_sanitize?
      ENV['SANITIZE'] == 'true'
    end

    def omnibus_gitlab?
      Dir.pwd == '/opt/gitlab/embedded/service/gitlab-rails'
    end

    def sudo_gitlab(command)
      "sudo -u #{gitlab_user} -H #{command}"
    end
  end
end