git_rid 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/bin/git_rid +49 -0
- data/lib/git_rid.rb +42 -0
- metadata +89 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 2b9dcf887879784c7d12c7be5b416ca07ef33d898a34f8c688cd35646fd7b3fa
|
4
|
+
data.tar.gz: a00d51d67619cc09b0f8c001dce06428159d815920388b05ded9ae0099ae8f03
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 63d57f99bca1ab1a6a4923d3be8f4eda212691db9a7b0b466ef6d0c9b96e7b9fee85b9eaf9c718531ad18f30110dbc84cbfd432f97030dcb802d22cd03a9198d
|
7
|
+
data.tar.gz: dfbb8b34cae104d84bf2b2569969066733bfdbbf2ec411f1f2a876bbb3c36a86ba0ff114634fecffadc9765752577ae1718c71b22003864755ebd869b49845bb
|
data/bin/git_rid
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'git_rid'
|
5
|
+
require 'highline/import'
|
6
|
+
require 'dotenv/load'
|
7
|
+
|
8
|
+
options = {
|
9
|
+
updated: 'main',
|
10
|
+
outdated: 'master',
|
11
|
+
url: ENV['GITLAB_API_ENDPOINT'] || 'https://gitlab.com/api/v4',
|
12
|
+
token: ENV['GITLAB_API_PRIVATE_TOKEN']
|
13
|
+
}
|
14
|
+
OptionParser.new do |opts|
|
15
|
+
opts.banner = 'Usage: git_rid'
|
16
|
+
|
17
|
+
opts.on('-b', '--branch-name=main', 'Set the new branch name you want') do |name|
|
18
|
+
options[:updated] = name
|
19
|
+
end
|
20
|
+
|
21
|
+
opts.on('-o', '--outdated-branch=master', 'Specify what the outdated branch name was') do |name|
|
22
|
+
options[:outdated] = name
|
23
|
+
end
|
24
|
+
|
25
|
+
opts.on('-u', '--url=https://gitlab.com/api/v4', 'Specify the url for the gitlab server') do |url|
|
26
|
+
options[:url] = url
|
27
|
+
end
|
28
|
+
|
29
|
+
opts.on('-t', '--token=???', 'Specify the token for the gitlab user (must be maintainer or above)') do |url|
|
30
|
+
options[:url] = url
|
31
|
+
end
|
32
|
+
|
33
|
+
opts.on('-h', '--help', 'Show usage help text') do
|
34
|
+
puts opts
|
35
|
+
exit 0
|
36
|
+
end
|
37
|
+
end.parse!
|
38
|
+
|
39
|
+
if options[:token].nil?
|
40
|
+
puts 'please specify a gitlab token or supply GITLAB_API_PRIVATE_TOKEN in your environment'
|
41
|
+
exit 1
|
42
|
+
end
|
43
|
+
|
44
|
+
puts "Keep in mind that while you should definitely 100% do this, it will rename the #{options[:outdated]} branch to #{options[:updated]} and that could confuse people."
|
45
|
+
confirm = ask("Do it? [Y/N] ") { |yn| yn.limit = 1, yn.validate = /[yn]/i }
|
46
|
+
exit unless confirm.downcase == 'y'
|
47
|
+
|
48
|
+
puts 'OKAY LETS DO THIS!'
|
49
|
+
GitRid.perform!(options)
|
data/lib/git_rid.rb
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
require 'gitlab'
|
2
|
+
|
3
|
+
class GitRid
|
4
|
+
def self.perform!(options)
|
5
|
+
updated_name = options[:updated]
|
6
|
+
outdated_name = options[:outdated]
|
7
|
+
|
8
|
+
Gitlab.configure do |config|
|
9
|
+
config.endpoint = options[:url] || ENV['GITLAB_API_ENDPOINT']
|
10
|
+
config.private_token = options[:token] || ENV['GITLAB_API_PRIVATE_TOKEN']
|
11
|
+
end
|
12
|
+
|
13
|
+
projects = Gitlab.projects(min_access_level: 40)
|
14
|
+
|
15
|
+
if projects.empty?
|
16
|
+
puts "Looks like you aren't a maintainer on any projects :("
|
17
|
+
exit 1
|
18
|
+
end
|
19
|
+
|
20
|
+
projects.auto_paginate do |project|
|
21
|
+
mb = Gitlab.branch(project.id, outdated_name)
|
22
|
+
|
23
|
+
Gitlab.create_branch(project.id, updated_name, mb.commit.id)
|
24
|
+
|
25
|
+
if mb.protected
|
26
|
+
Gitlab.protect_branch(project.id, updated_name)
|
27
|
+
Gitlab.unprotect_branch(project.id, outdated_name)
|
28
|
+
end
|
29
|
+
|
30
|
+
if project.default_branch == outdated_name
|
31
|
+
Gitlab.edit_project(project.id, {default_branch: updated_name})
|
32
|
+
end
|
33
|
+
|
34
|
+
Gitlab.delete_branch(project.id, outdated_name)
|
35
|
+
puts "Updated #{project.name} and replaced #{outdated_name} with #{updated_name}"
|
36
|
+
rescue Gitlab::Error::NotFound => e
|
37
|
+
puts "Skipping #{project.name}, it doesn't have a #{outdated_name} branch!"
|
38
|
+
rescue Gitlab::Error::BadRequest
|
39
|
+
puts "Skipping #{project.name} because it already had a branch called #{updated_name}... you'll have to sort that out yourself."
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: git_rid
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex Ives
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: gitlab
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 4.15.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 4.15.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: dotenv
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 2.7.5
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 2.7.5
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: highline
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 2.0.3
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 2.0.3
|
55
|
+
description: Change every main branch to the name of your choice instead of master
|
56
|
+
(default is main)
|
57
|
+
email: alex@ives.dev
|
58
|
+
executables:
|
59
|
+
- git_rid
|
60
|
+
extensions: []
|
61
|
+
extra_rdoc_files: []
|
62
|
+
files:
|
63
|
+
- bin/git_rid
|
64
|
+
- lib/git_rid.rb
|
65
|
+
homepage: https://gitlab.com/alexives/git_rid
|
66
|
+
licenses:
|
67
|
+
- MIT
|
68
|
+
metadata:
|
69
|
+
source_code_uri: https://gitlab.com/alexives/git_rid
|
70
|
+
post_install_message:
|
71
|
+
rdoc_options: []
|
72
|
+
require_paths:
|
73
|
+
- lib
|
74
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
version: '0'
|
79
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
requirements: []
|
85
|
+
rubygems_version: 3.0.3
|
86
|
+
signing_key:
|
87
|
+
specification_version: 4
|
88
|
+
summary: Change all instances of master branches in gitlab (where you have access)
|
89
|
+
test_files: []
|