gitlab-branch-rename 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d02aa63f9aa10433d20701e09795bc748f4b642ffe628c9ea5bfbc962939e85f
4
- data.tar.gz: 5c5b106cd879f3a7f676b6013e6be7dfa2c8005951b75e34f6d09ba52e64462e
3
+ metadata.gz: 4c1e3af9e6a7bf863499c1cc50580df59ebd274a60a856c8b321515275fcf513
4
+ data.tar.gz: 3ab5d0012f1451416392fddd789b176009de4541296dc20ce655747361078c53
5
5
  SHA512:
6
- metadata.gz: 626949e870d91827b5901ff5e62ffbe1a93e7972a00918425feba2960b61893ce6b15d0861da45db2e1ba61d7f30b821d51b97b4d908aaf2e703732d07b99a0c
7
- data.tar.gz: dea4861e80089beb216cf3295d16d61ca3e5e8e5f5f380f4d28ca22514d052d1d3d2b07afbfefe7411fbcd16a8845ea3e04f348c62db5733ae300084f9e99578
6
+ metadata.gz: 18a3bc1ece6198c4a11c25c2b4ad6983eb84eadebb468a3d36d07aa11ab144e22ad88edcde2512eda268dbc09c77bd5c7ad93956e6e62fde58314f0c2e06fcb4
7
+ data.tar.gz: 218ebf0040a5790781d93b0be5489424804a84125d4767ab9cbe17f4771fcc59595923d4ff6fe4e9194d4dfc09782463fbb2a5a31375135a3a1b58a75a2369fd
data/Gemfile CHANGED
@@ -2,3 +2,4 @@ source "https://rubygems.org"
2
2
  ruby "~> 2.6"
3
3
 
4
4
  gemspec
5
+ gem "colorize", "~> 0.8.1"
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gitlab-branch-rename (0.3.0)
4
+ gitlab-branch-rename (0.4.0)
5
5
  gitlab (~> 4.16)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
+ colorize (0.8.1)
10
11
  gitlab (4.16.1)
11
12
  httparty (~> 0.14, >= 0.14.0)
12
13
  terminal-table (~> 1.5, >= 1.5.1)
@@ -25,10 +26,11 @@ PLATFORMS
25
26
  ruby
26
27
 
27
28
  DEPENDENCIES
29
+ colorize (~> 0.8.1)
28
30
  gitlab-branch-rename!
29
31
 
30
32
  RUBY VERSION
31
- ruby 2.7.0p0
33
+ ruby 2.6.5p114
32
34
 
33
35
  BUNDLED WITH
34
- 2.1.4
36
+ 1.17.3
data/Makefile CHANGED
@@ -2,7 +2,7 @@ build:
2
2
  gem build ./gitlab-branch-rename.gemspec
3
3
 
4
4
  clean:
5
- rm gitlab-branch-rename-*.gem
5
+ -rm gitlab-branch-rename-*.gem
6
6
 
7
7
  install: build
8
8
  gem install ./gitlab-branch-rename-*.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Gitlab Branch Rename
2
2
 
3
- This is a simple tool to rename your Gitlab project branches en-mass.
3
+ This is a simple tool to rename your Gitlab project branches en masse.
4
4
 
5
5
  ## Motivation
6
6
 
@@ -1,18 +1,18 @@
1
1
  require_relative 'lib/gitlab_branch_rename/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "gitlab-branch-rename"
5
- spec.version = GitlabBranchRename::VERSION
6
- spec.authors = ["AP Fritts"]
7
- spec.email = ["ap@apfritts.com"]
4
+ spec.name = "gitlab-branch-rename"
5
+ spec.version = GitlabBranchRename::VERSION
6
+ spec.authors = ["AP Fritts"]
7
+ spec.email = ["ap@apfritts.com"]
8
8
 
9
- spec.summary = "Tool to rename your Gitlab project branches en-mass"
10
- spec.description = "To support Black Lives Matter and try to create safer spaces, I wanted to rename " +
11
- "all of my own default branches in Gitlab. I wasn't able to find any tools to do that, so I wrote " +
12
- "this one. If you're unsure why this is important or want to better understand my personal understanding " +
13
- "of why I wanted to make these changes, see this Twitter thread: https://twitter.com/mislav/status/1270388510684598272"
14
- spec.homepage = "https://gitlab.com/apfritts/gitlab-branch-rename"
15
- spec.license = "MIT"
9
+ spec.summary = "Tool to rename your Gitlab project branches en masse"
10
+ spec.description = "To support Black Lives Matter and create safer spaces, I wanted to rename all of the default " +
11
+ "branches in my Gitlab account. I wasn't able to find any tools to do that, so I wrote this one. If you're " +
12
+ "unsure why this is important or want to better understand why I wanted to make these changes, see this " +
13
+ "great {Twitter thread}[https://twitter.com/mislav/status/1270388510684598272]."
14
+ spec.homepage = "https://gitlab.com/apfritts/gitlab-branch-rename"
15
+ spec.license = "MIT"
16
16
  spec.required_ruby_version = Gem::Requirement.new(">= 2.6.0")
17
17
 
18
18
  spec.metadata["homepage_uri"] = spec.homepage
@@ -22,10 +22,10 @@ Gem::Specification.new do |spec|
22
22
 
23
23
  # Specify which files should be added to the gem when it is released.
24
24
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
25
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
25
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
26
26
  `git ls-files -z`.split("\x0")
27
27
  end
28
- spec.bindir = "exe"
29
- spec.executables = "gitlab-branch-rename"
28
+ spec.bindir = "exe"
29
+ spec.executables = "gitlab-branch-rename"
30
30
  spec.require_paths = ["lib"]
31
31
  end
@@ -5,7 +5,7 @@ module GitlabBranchRename
5
5
  class Configuration
6
6
  attr_accessor :token, :branch_to_rename, :new_branch_name,
7
7
  :endpoint, :is_default_branch, :has_visibility, :minimum_access_level,
8
- :skip_confirm, :pretend, :logfile
8
+ :skip_confirm, :pretend, :disable_color, :logfile
9
9
 
10
10
  def initialize
11
11
  # Required parameters
@@ -22,6 +22,7 @@ module GitlabBranchRename
22
22
  # Optional parameters
23
23
  self.skip_confirm = false
24
24
  self.pretend = false
25
+ self.disable_color = false
25
26
  self.logfile = STDOUT
26
27
  end
27
28
 
@@ -31,30 +32,33 @@ module GitlabBranchRename
31
32
  opts.banner = "Usage: gitlab-branch-rename --from <branch to rename> --to <new branch name> [options]"
32
33
  opts.separator ""
33
34
  opts.separator "Specific options:"
34
- opts.on("--from OLD_BRANCH", "Branch to rename") do |from|
35
+ opts.on("--from OLD_BRANCH", "Branch to rename (required)") do |from|
35
36
  configuration.branch_to_rename = from
36
37
  end
37
- opts.on("--to NEW_BRANCH", "New branch name") do |to|
38
+ opts.on("--to NEW_BRANCH", "New branch name (required)") do |to|
38
39
  configuration.new_branch_name = to
39
40
  end
40
- opts.on("--endpoint ENDPOINT", "Gitlab server endpoint. default: Gitlab cloud") do |endpoint|
41
+ opts.on("--endpoint ENDPOINT", "Gitlab server endpoint, default: https://gitlab.com/api/v4") do |endpoint|
41
42
  configuration.endpoint = endpoint
42
43
  end
43
- opts.on("--token-env-var ENV_VAR_NAME", "Environment variable to pull token out of") do |token_env_var|
44
+ opts.on("--token-env-var ENV_VAR_NAME", "Environment variable to use for Gitlab API token, default: GITLAB_ACCESS_TOKEN") do |token_env_var|
44
45
  configuration.token = ENV[token_env_var]
45
46
  end
46
- opts.on("--only-if-default", "Rename only if it is the default branch") do
47
+ opts.on("--only-if-default", "Rename only if the old branch is currently the default project branch") do
47
48
  configuration.is_default_branch = true
48
49
  end
49
- opts.on("--visibility VISIBILITIES", "Comma-separated list of project visibilities default: public,internal,private") do |visibility|
50
+ opts.on("--visibility VISIBILITIES", "Comma-separated list of project visibilities, default: public,internal,private") do |visibility|
50
51
  configuration.has_visibility = visibility.split ","
51
52
  end
52
53
  opts.on("--skip-confirm", "Skip confirmation before executing rename") do
53
54
  configuration.skip_confirm = true
54
55
  end
55
- opts.on("--pretend", "Pretend to perform actions. Overrides confirm option") do
56
+ opts.on("--pretend", "Pretend to perform actions. Overrides --skip-confirm option") do
56
57
  configuration.pretend = true
57
58
  end
59
+ opts.on("--disable-color", "Disable output colors") do
60
+ configuration.disable_color = true
61
+ end
58
62
  opts.on("--logfile LOGFILE", "Logfile destination. Use - for STDOUT") do |logfile|
59
63
  if logfile == "-"
60
64
  configuration.logfile = STDOUT
@@ -72,8 +76,8 @@ module GitlabBranchRename
72
76
 
73
77
  begin
74
78
  optparse.parse!
75
- raise OptionParser::MissingArgument.new('old branch name') if configuration.branch_to_rename.nil?
76
- raise OptionParser::MissingArgument.new('new branch name') if configuration.new_branch_name.nil?
79
+ raise OptionParser::MissingArgument.new("old branch name") if configuration.branch_to_rename.nil?
80
+ raise OptionParser::MissingArgument.new("new branch name") if configuration.new_branch_name.nil?
77
81
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument
78
82
  puts $!.to_s
79
83
  puts optparse
@@ -1,13 +1,33 @@
1
+ require "colorize"
2
+
1
3
  module GitlabBranchRename
2
4
  class LoggerConfigure
3
5
  def self.configure(configuration)
4
6
  logger = Logger.new(STDOUT)
5
7
  logger.formatter = proc do |severity, datetime, progname, msg|
6
8
  date_format = datetime.to_datetime.strftime("%Q")
7
- if severity == "INFO" or severity == "WARN"
8
- "#{severity} #{date_format} #{msg}\n"
9
+ output = nil
10
+ color = :black
11
+ case severity
12
+ when "DEBUG"
13
+ output = "D #{date_format} #{msg}\n"
14
+ color = :light_black
15
+ when "INFO"
16
+ output = "I #{date_format} #{msg}\n"
17
+ color = :black
18
+ when "WARN"
19
+ output = "W #{date_format} #{msg}\n"
20
+ color = :yellow
21
+ when "ERROR"
22
+ output = "E #{date_format} #{msg}\n"
23
+ color = :red
9
24
  else
10
- "#{severity} #{date_format} #{msg}\n"
25
+ output = "? #{date_format} #{msg}\n"
26
+ end
27
+ if configuration.disable_color
28
+ output
29
+ else
30
+ output.colorize(color)
11
31
  end
12
32
  end
13
33
  logger
@@ -27,6 +27,9 @@ module GitlabBranchRename
27
27
  logger.info(" git checkout #{c.new_branch_name}")
28
28
  logger.info(" git remote set-head `git remote` #{c.new_branch_name}")
29
29
  logger.info(" git branch -d #{c.branch_to_rename}")
30
+ logger.info("")
31
+ logger.info("Or all as one line:")
32
+ logger.info(" git fetch `git remote` --prune && git checkout trunk && git remote set-head `git remote` trunk && git branch -d master")
30
33
  logger.close
31
34
  end
32
35
  end
@@ -62,7 +62,7 @@ module GitlabBranchRename
62
62
 
63
63
  # Confirm or pretend
64
64
  msg = "Rename #{project.path_with_namespace} branch #{@configuration.branch_to_rename} to #{@configuration.new_branch_name} " +
65
- (branch_protection_parameters ? "with" : "without") + " protection"
65
+ (branch_protection_parameters.nil? ? "without" : "with") + " protection"
66
66
  if @configuration.pretend
67
67
  puts(msg)
68
68
  @logger.info(msg)
@@ -86,17 +86,17 @@ module GitlabBranchRename
86
86
  Gitlab.create_branch(project.id, @configuration.new_branch_name, old_branch.name)
87
87
  @logger.debug("Created new branch with name #{@configuration.new_branch_name}")
88
88
  rescue StandardError => e
89
- @logger.error(e)
89
+ @logger.error("Error creating new branch: #{e}")
90
90
  next
91
91
  end
92
92
 
93
93
  # Protect branch
94
- unless branch_protection_parameters
94
+ unless branch_protection_parameters.nil?
95
95
  begin
96
96
  Gitlab.protect_branch(project.id, @configuration.new_branch_name, branch_protection_parameters)
97
97
  @logger.debug("Protected branch with parameters #{branch_protection_parameters}")
98
98
  rescue StandardError => e
99
- @logger.error(e)
99
+ @logger.error("Error protecting new branch: #{e} with #{branch_protection_parameters}")
100
100
  end
101
101
  end
102
102
 
@@ -107,16 +107,16 @@ module GitlabBranchRename
107
107
  Gitlab.edit_project(project.id, {default_branch: @configuration.new_branch_name})
108
108
  @logger.debug("Changed default branch")
109
109
  rescue StandardError => e
110
- @logger.error(e)
110
+ @logger.error("Error changing default branch: #{e}")
111
111
  end
112
112
 
113
113
  # Unprotect protected branches
114
- unless branch_protection_parameters
114
+ if branch_protection_parameters
115
115
  begin
116
116
  Gitlab.unprotect_branch(project.id, old_branch.name)
117
117
  @logger.debug("Unprotected old branch")
118
118
  rescue StandardError => e
119
- @logger.error(e)
119
+ @logger.error("Error unprotecting old branch: #{e}")
120
120
  end
121
121
  end
122
122
 
@@ -125,7 +125,7 @@ module GitlabBranchRename
125
125
  Gitlab.delete_branch(project.id, old_branch.name)
126
126
  @logger.debug("Deleted old branch")
127
127
  rescue StandardError => e
128
- @logger.error(e)
128
+ @logger.error("Error deleting old branch: #{e}")
129
129
  end
130
130
  end
131
131
  end
@@ -1,3 +1,3 @@
1
1
  module GitlabBranchRename
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gitlab-branch-rename
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - AP Fritts
@@ -24,11 +24,11 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '4.16'
27
- description: 'To support Black Lives Matter and try to create safer spaces, I wanted
28
- to rename all of my own default branches in Gitlab. I wasn''t able to find any tools
29
- to do that, so I wrote this one. If you''re unsure why this is important or want
30
- to better understand my personal understanding of why I wanted to make these changes,
31
- see this Twitter thread: https://twitter.com/mislav/status/1270388510684598272'
27
+ description: To support Black Lives Matter and create safer spaces, I wanted to rename
28
+ all of the default branches in my Gitlab account. I wasn't able to find any tools
29
+ to do that, so I wrote this one. If you're unsure why this is important or want
30
+ to better understand why I wanted to make these changes, see this great {Twitter
31
+ thread}[https://twitter.com/mislav/status/1270388510684598272].
32
32
  email:
33
33
  - ap@apfritts.com
34
34
  executables:
@@ -44,7 +44,6 @@ files:
44
44
  - LICENSE.txt
45
45
  - Makefile
46
46
  - README.md
47
- - bin/console
48
47
  - exe/gitlab-branch-rename
49
48
  - gitlab-branch-rename.gemspec
50
49
  - gitlab-branch-rename.gemspec.lock
@@ -78,5 +77,5 @@ requirements: []
78
77
  rubygems_version: 3.0.8
79
78
  signing_key:
80
79
  specification_version: 4
81
- summary: Tool to rename your Gitlab project branches en-mass
80
+ summary: Tool to rename your Gitlab project branches en masse
82
81
  test_files: []
@@ -1,14 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require "bundler/setup"
4
- require "main"
5
-
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
14
- IRB.start(__FILE__)