master_to_main 0.0.1 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 71e3451ce977f600d84510976915b39c28d18a68596b2a9118731fde10d9d4d9
4
- data.tar.gz: 9b73f2ec8d863bf86fa4b763f07fddd662676a351f17c5d845767c61bca05a6c
3
+ metadata.gz: 3e178c01d989407574bbc17949910dca148aad2afaca28205abb785c7aed3263
4
+ data.tar.gz: eeab0dd082a7808a332a66cb164a67e213f391392cd54ede20a3ba400e9b6c3f
5
5
  SHA512:
6
- metadata.gz: 34ef7eab028716de82af81e41154ea9e4a0cc963c720c84d9aae6e2118391357e411e6c796d12c8fbce514ada5d145f18575fe0f79c5b76c108a12e60c98453a
7
- data.tar.gz: bffc48a13f395255bc403bb8c0270007bd997edd2afd2dede41668bf86387fe7166edd29021785789526b6ba43ff4ed7d5bba1c60fc9ea4b1493900bb3a95e78
6
+ metadata.gz: 6156ba5854ec68934d55aca6b955b096bfc97def37394669536b4492419ce8b8cf35b45d159f331f3cf22175de5261d71d10dee4302f5fb6058ed24280586872
7
+ data.tar.gz: d5f7d35aeadee3496122606e6d6f6c613f177526e2780120e249bffcbcab98a80f6449c8b36d88ba0aed4dd557e6dd19ec5450f83574353ce0d9326c2719c857
@@ -1,3 +1,30 @@
1
+ # 0.0.6 - 2020-06-23
2
+
3
+ - Include `find_references` in `update_docs`
4
+ - README Updates
5
+
6
+ # 0.0.5 - 2020-06-19
7
+
8
+ - Add `find_references` for finding non doc references
9
+ - Provide better explanation that you are updating docs only
10
+ - Rescue from branch protection errors like in personal private repos
11
+
12
+ # 0.0.4 - 2020-06-18
13
+
14
+ - Change `github` to `update`
15
+ - Add `update_docs` command
16
+
17
+ # 0.0.3 - 2020-06-17
18
+
19
+ - Only set api endpoint if not using "github.com"
20
+ - Bump rake version
21
+ - Typos
22
+ - Fetch before checking out main
23
+
24
+ # 0.0.2 - 2020-06-17
25
+
26
+ Fix checkout of local branch, add local master branch deletion
27
+
1
28
  # 0.0.1 - 2020-06-17
2
29
 
3
- Initiale release for testing
30
+ Initial release for testing
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- master_to_main (0.1.0)
4
+ master_to_main (0.0.6)
5
5
  octokit (~> 4.0)
6
6
  thor (~> 1.0.1)
7
7
 
@@ -18,7 +18,7 @@ GEM
18
18
  faraday (>= 0.9)
19
19
  sawyer (~> 0.8.0, >= 0.5.3)
20
20
  public_suffix (4.0.5)
21
- rake (10.5.0)
21
+ rake (13.0.1)
22
22
  rspec (3.9.0)
23
23
  rspec-core (~> 3.9.0)
24
24
  rspec-expectations (~> 3.9.0)
@@ -41,7 +41,10 @@ PLATFORMS
41
41
  ruby
42
42
 
43
43
  DEPENDENCIES
44
- bundler (~> 1.17)
44
+ bundler (~> 2.0)
45
45
  master_to_main!
46
- rake (~> 10.0)
46
+ rake (~> 13.0)
47
47
  rspec (~> 3.0)
48
+
49
+ BUNDLED WITH
50
+ 2.1.4
data/README.md CHANGED
@@ -4,29 +4,49 @@
4
4
  enterprise to a new branch. For example, if you wanted to change `master` to
5
5
  `main`.
6
6
 
7
+ While `master` does have meanings that connote expertise or original record, it also
8
+ has meanings that have much more oppressive and violent histories. Whether or not the
9
+ original meaning of `master` branch was in reference to original record or the opposite
10
+ of slave matters less than what it may mean to a reader who doesn't want to bother with
11
+ the history of git.
12
+
13
+ Per the twitter thread below, maybe we can just think of it as:
14
+
15
+ > Agreed. All it does is make the world a tiny bit more welcoming.
16
+
7
17
  Thanks to [@shanselman](https://github.com/shanselman) for [the
8
18
  suggestion](https://twitter.com/shanselman/status/1269838158650195968).
9
19
 
20
+ ## Installation
21
+
22
+ You need ruby and [rubygems](https://rubygems.org/pages/download) to use `master_to_main`.
23
+ With ruby gems installed you can simply run
24
+
25
+ ```
26
+ $ gem install master_to_main
27
+ ```
28
+
10
29
  ## Functionality
11
30
 
12
- `MasterToMain` has 2 actions for now:
31
+ `MasterToMain` has 3 actions:
13
32
 
14
- 1. `github`
15
- 2. `update_local`
33
+ 1. `update` - Update github, pull requests, branch protections, local origin
34
+ 1. `update_local` - For people to use after `update` to update the local clone
35
+ 1. `update_docs` - If you just want to search docs for github urls.
16
36
 
17
- ## Github
37
+ ## `update`
18
38
 
19
39
  ### Usage
20
40
 
21
41
  ```
22
- master_to_main github
42
+ master_to_main update
23
43
  ```
24
44
 
25
45
  After filling out the relevant prompts you will be able to:
26
46
 
27
47
  1. Create a new branch (e.g. `main`) if it does not exist.
28
48
  1. Clone all branch protections from an old branch.
29
- - Caveat: This does not include the signed commit requirement
49
+ - Caveat: This does not include the signed commit requirement
30
50
  1. Change the default branch of your repository
31
51
  1. Rebase all pull requests based on your old branch to your new branch
32
52
  1. Change the local `origin` remote value in github.
@@ -40,8 +60,11 @@ on Fetch URL of `origin` or "github.com")
40
60
  or `pwd`)
41
61
  1. The current default branch (default is `master`)
42
62
  1. The desired default branch (default is `main`)
63
+ 1. Your personal access token (instructions for settings one can be found [here](https://help.github.com/en/github/authenticating-to-github/creating-a-personal-access-token-for-the-command-line))
64
+ - You should enable "repo" access
43
65
 
44
- ## Update Local Clone
66
+
67
+ ## `update_local`
45
68
 
46
69
  ### Usage
47
70
 
@@ -63,22 +86,16 @@ $ git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/main
63
86
  All credit for this goes to "Brad from XUnit.net!" per [Scott's
64
87
  Blog](https://www.hanselman.com/blog/EasilyRenameYourGitDefaultBranchFromMasterToMain.aspx).
65
88
 
89
+ ## `update_docs`
66
90
 
67
- ## Installation
68
-
69
- Add this line to your application's Gemfile:
91
+ ### Usage
70
92
 
71
- ```ruby
72
- gem 'master_to_main'
93
+ ```
94
+ master_to_main update_docs
73
95
  ```
74
96
 
75
- And then execute:
76
-
77
- $ bundle
78
-
79
- Or install it yourself as:
80
-
81
- $ gem install master_to_main
97
+ This will attempt to update all references to commits on the master branch with
98
+ commits on the main branch.
82
99
 
83
100
  ## TODO
84
101
 
@@ -86,7 +103,7 @@ Or install it yourself as:
86
103
 
87
104
  ## Contributing
88
105
 
89
- Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/master_to_main. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
106
+ Bug reports and pull requests are welcome on GitHub at https://github.com/dewyze/master_to_main. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
90
107
 
91
108
  ## Code of Conduct
92
109
 
@@ -1,24 +1,42 @@
1
1
  require "thor"
2
+ require "pry"
2
3
  require "octokit"
3
4
 
4
5
  module MasterToMain
5
6
  class CLI < Thor
7
+ include Thor::Actions
8
+
6
9
  def self.exit_on_failure?
7
10
  true
8
11
  end
9
12
 
10
- desc "github", "rebase PRs to the main branch"
11
- def github
12
-
13
+ desc "update", "rebase PRs to the main branch"
14
+ def update
13
15
  prompt_info
14
-
15
16
  create_client
17
+
16
18
  ensure_old_branch_exists
17
19
  ensure_new_branch_exists
18
20
  clone_branch_protections
19
21
  change_default_branch
20
22
  rebase_pull_requests
21
23
  change_origin
24
+ delete_local_old_branch
25
+ ask_update_docs
26
+ ask_find_references
27
+ end
28
+
29
+ desc "update_docs", "update local docs to use MAIN"
30
+ def update_docs
31
+ prompt_info
32
+ _update_docs
33
+ ask_find_references
34
+ end
35
+
36
+ desc "find_references", "find references to github urls with MAIN"
37
+ def find_references
38
+ prompt_info
39
+ _find_references
22
40
  end
23
41
 
24
42
  desc "update_local", "point local clone to new branch"
@@ -31,12 +49,15 @@ module MasterToMain
31
49
  `git branch --unset-upstream`
32
50
  `git branch -u origin/#{@repo.new_branch}`
33
51
  `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/#{@repo.new_branch}`
52
+ `git pull`
34
53
  end
35
54
 
36
55
  no_commands do
37
56
  def create_client
38
- Octokit.configure do |c|
39
- c.api_endpoint = @repo.api_endpoint
57
+ if @repo.github != "github.com"
58
+ Octokit.configure do |c|
59
+ c.api_endpoint = @repo.api_endpoint
60
+ end
40
61
  end
41
62
  token = ask("What is your GitHub Personal Access Token?")
42
63
 
@@ -54,7 +75,7 @@ module MasterToMain
54
75
  {
55
76
  github: "github." + github_suffix,
56
77
  user: user,
57
- repo: repo.chomp,
78
+ repo: repo.gsub(/\.git/, "").chomp,
58
79
  }
59
80
  else
60
81
  {
@@ -69,7 +90,7 @@ module MasterToMain
69
90
  github_info = get_github_info
70
91
  github_url = ask("What is your github url?", default: github_info[:github]).gsub(/https:\/\//, "")
71
92
  user = ask("What is your github user?", default: github_info[:user])
72
- github_repo = ask("What is your github repo?", default: github_info[:repo])
93
+ github_repo = ask("What is your github repo?", default: github_info[:repo]).gsub(/\.git/, "")
73
94
  old_branch = ask("What is your current primary branch?", default: "master")
74
95
  new_branch = ask("What is your desired primary branch?", default: "main")
75
96
 
@@ -112,7 +133,12 @@ module MasterToMain
112
133
  end
113
134
 
114
135
  def clone_branch_protections
115
- options = @client.branch_protection(@repo.name, @repo.old_branch)
136
+ begin
137
+ repo = @client.repo(@repo.name)
138
+ options = @client.branch_protection(@repo.name, @repo.old_branch)
139
+ rescue Octokit::Forbidden
140
+ return
141
+ end
116
142
 
117
143
  if options && yes?("Would you like to clone branch protections from '#{@repo.old_branch}'?")
118
144
  updates = BranchProtectionParams.build(options.to_h)
@@ -122,7 +148,7 @@ module MasterToMain
122
148
  end
123
149
 
124
150
  def rebase_pull_requests
125
- if yes?("Would you like to rebase all requests based on #{@repo.old_branch} to #{@repo.new_branch}?")
151
+ if yes?("Would you like to rebase all pull requests based on #{@repo.old_branch} to #{@repo.new_branch}?")
126
152
  prs = @client.pull_requests(@repo.name)
127
153
  prs.each do |pr|
128
154
  if pr[:base][:ref] == @repo.old_branch
@@ -140,11 +166,49 @@ module MasterToMain
140
166
 
141
167
  def change_origin
142
168
  if yes?("Would you like to change origin to point to #{@repo.new_branch}?")
143
- `git push -u origin master`
169
+ `git fetch`
170
+ `git checkout #{@repo.new_branch}`
171
+ `git push -u origin #{@repo.new_branch}`
144
172
  else
145
173
  say "Be sure to change your local `origin` setting"
146
174
  end
147
175
  end
176
+
177
+ def delete_local_old_branch
178
+ `git branch -D #{@repo.old_branch}` if yes?("Would you like to delete your local #{@repo.old_branch} branch?")
179
+
180
+ say "----------------"
181
+ say "In order to ensure no builds or deployments break, please delete your remote #{@repo.old_branch} on github", :green
182
+ say "----------------"
183
+ end
184
+
185
+ def ask_update_docs
186
+ say("We can update #{@repo.github} references in '.md' files that include master in your repo")
187
+ say("For example: https://#{@repo.github}/#{@repo.name}/(tree|blob)/master")
188
+ if yes?("Would you like to update these references?")
189
+ _update_docs
190
+ say("You should consider searching for other references not in markdown files.")
191
+ say("We don't want to automatically change those in case something breaks.")
192
+ say("But you can use `master_to_main find_references` to show you where they are")
193
+ end
194
+ end
195
+
196
+ def ask_find_references
197
+ _find_references if yes?("Would you like to display other URL references?")
198
+ end
199
+
200
+ def _update_docs
201
+ say "This will update all references of #{@repo.old_branch} to #{@repo.new_branch} in the following lines in this repo:"
202
+ say "https://#{@repo.github}/#{@repo.name}/<tree|blob>/#{@repo.old_branch}"
203
+ Dir.glob(File.expand_path("**/*.md", Dir.pwd)).each do |path|
204
+ gsub_file path, /#{@repo.old_branch_regex}/, @repo.new_branch_replacement, verbose: false
205
+ end
206
+ end
207
+
208
+ def _find_references
209
+ say "Here are the references to urls with #{@repo.old_branch}:\n\n"
210
+ puts `git grep -E '#{@repo.old_branch_regex}'`
211
+ end
148
212
  end
149
213
  end
150
214
  end
@@ -18,12 +18,20 @@ module MasterToMain
18
18
  "#{user}/#{repo_name}"
19
19
  end
20
20
 
21
- def old_branch_url
22
- "https://#{github}/tree/#{old_branch}"
21
+ def old_branch_regex
22
+ "(http[s]?:\/\/#{github}\/#{user}\/#{repo_name}\)/(tree|blob)\/#{old_branch}"
23
+ end
24
+
25
+ def new_branch_replacement
26
+ "\\1/\\2/#{new_branch}"
23
27
  end
24
28
 
25
29
  def new_branch_url
26
- "https://#{github}/tree/#{new_branch}"
30
+ "https://#{github}/#{name}/tree/#{new_branch}"
31
+ end
32
+
33
+ def public_github?
34
+ @github == "github.com"
27
35
  end
28
36
  end
29
37
  end
@@ -1,3 +1,3 @@
1
1
  module MasterToMain
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -35,8 +35,8 @@ Gem::Specification.new do |spec|
35
35
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
36
36
  spec.require_paths = ["lib"]
37
37
 
38
- spec.add_development_dependency "bundler", "~> 1.17"
39
- spec.add_development_dependency "rake", "~> 10.0"
38
+ spec.add_development_dependency "bundler", "~> 2.0"
39
+ spec.add_development_dependency "rake", "~> 13.0"
40
40
  spec.add_development_dependency "rspec", "~> 3.0"
41
41
 
42
42
  spec.add_dependency "thor", "~> 1.0.1"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: master_to_main
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - John DeWyze
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-06-17 00:00:00.000000000 Z
11
+ date: 2020-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -16,28 +16,28 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '2.0'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '2.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '10.0'
33
+ version: '13.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '10.0'
40
+ version: '13.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement