Class: GitlabBranchRename::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/gitlab_branch_rename/configuration.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gitlab_branch_rename/configuration.rb', line 10

def initialize
  # Required parameters
  self.branch_to_rename = nil
  self.new_branch_name = nil

  # Criteria parameters with defaults
  self.endpoint = "https://gitlab.com/api/v4"
  self.token = ENV["GITLAB_ACCESS_TOKEN"]
  self.is_default_branch = false
  self.has_visibility = %w[private internal public]
  self.minimum_access_level = 40

  # Optional parameters
  self.skip_confirm = false
  self.pretend = false
  self.disable_color = false
  self.logfile = STDOUT
end

Instance Attribute Details

#branch_to_renameObject

Returns the value of attribute branch_to_rename.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def branch_to_rename
  @branch_to_rename
end

#disable_colorObject

Returns the value of attribute disable_color.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def disable_color
  @disable_color
end

#endpointObject

Returns the value of attribute endpoint.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def endpoint
  @endpoint
end

#has_visibilityObject

Returns the value of attribute has_visibility.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def has_visibility
  @has_visibility
end

#is_default_branchObject

Returns the value of attribute is_default_branch.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def is_default_branch
  @is_default_branch
end

#logfileObject

Returns the value of attribute logfile.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def logfile
  @logfile
end

#minimum_access_levelObject

Returns the value of attribute minimum_access_level.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def minimum_access_level
  @minimum_access_level
end

#new_branch_nameObject

Returns the value of attribute new_branch_name.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def new_branch_name
  @new_branch_name
end

#pretendObject

Returns the value of attribute pretend.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def pretend
  @pretend
end

#skip_confirmObject

Returns the value of attribute skip_confirm.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def skip_confirm
  @skip_confirm
end

#tokenObject

Returns the value of attribute token.



6
7
8
# File 'lib/gitlab_branch_rename/configuration.rb', line 6

def token
  @token
end

Class Method Details

.configureObject



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
83
84
85
86
87
88
# File 'lib/gitlab_branch_rename/configuration.rb', line 29

def self.configure
  configuration = Configuration.new
  optparse = OptionParser.new do |opts|
    opts.banner = "Usage: gitlab-branch-rename --from <branch to rename> --to <new branch name> [options]"
    opts.separator ""
    opts.separator "Specific options:"
    opts.on("--from OLD_BRANCH", "Branch to rename (required)") do |from|
      configuration.branch_to_rename = from
    end
    opts.on("--to NEW_BRANCH", "New branch name (required)") do |to|
      configuration.new_branch_name = to
    end
    opts.on("--endpoint ENDPOINT", "Gitlab server endpoint, default: https://gitlab.com/api/v4") do |endpoint|
      configuration.endpoint = endpoint
    end
    opts.on("--token-env-var ENV_VAR_NAME", "Environment variable to use for Gitlab API token, default: GITLAB_ACCESS_TOKEN") do |token_env_var|
      configuration.token = ENV[token_env_var]
    end
    opts.on("--only-if-default", "Rename only if the old branch is currently the default project branch") do
      configuration.is_default_branch = true
    end
    opts.on("--visibility VISIBILITIES", "Comma-separated list of project visibilities, default: public,internal,private") do |visibility|
      configuration.has_visibility = visibility.split ","
    end
    opts.on("--skip-confirm", "Skip confirmation before executing rename") do
      configuration.skip_confirm = true
    end
    opts.on("--pretend", "Pretend to perform actions. Overrides --skip-confirm option") do
      configuration.pretend = true
    end
    opts.on("--disable-color", "Disable output colors") do
      configuration.disable_color = true
    end
    opts.on("--logfile LOGFILE", "Logfile destination. Use - for STDOUT") do |logfile|
      if logfile == "-"
        configuration.logfile = STDOUT
      else
        configuration.logfile = logfile
      end
    end
    opts.on("--version", "Print version and exit") do
      puts(GitlabBranchRename::VERSION)
      exit 0
    end
    opts.separator ""
    opts.separator "Visit https://gitlab.com/apfritts/gitlab-branch-rename for more details."
  end

  begin
    optparse.parse!
    raise OptionParser::MissingArgument.new("old branch name") if configuration.branch_to_rename.nil?
    raise OptionParser::MissingArgument.new("new branch name") if configuration.new_branch_name.nil?
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
    puts $!.to_s
    puts optparse
    exit 1
  end

  configuration
end