master_to_main 0.0.2 → 0.0.7

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: 6a64928607b005c31d0d4ad4e01994c12733d5744bd75d72fcf9e3d58279be81
4
- data.tar.gz: 2b72700b70c3d2f07ca291e3b18e0d147fbf1e4ae5636ba124af0d522bed8db1
3
+ metadata.gz: c946d54f9f02e3fd4b826f9293f2d46d5c5ea6bd92d375976e56f7b30539c09f
4
+ data.tar.gz: dfb3ee1e58e811d8d265bca117b1ac4ca468ad3ea610f422a90199c1e71e9d90
5
5
  SHA512:
6
- metadata.gz: 76c82db75d6c0157219f6700bebdf6b81d48e3a0954da7ebde4e31c051282e463935e4d3c377a37dc2424ffd909a5e7757c1e106256ec4bf8bce87da1e229a46
7
- data.tar.gz: 6af1841e036951b0f8a2f8ed37e4477d7f8d9ffda9b99a93b121de43e215a32567f36488256f2d6696ca183ffac142278e59e7842817724fecc7330c1e3c29fd
6
+ metadata.gz: 0c4472188bf291848ee7ccdade125d7b442cbb698617942ba3dff93b9d9a8e44ecfba597401fa0f561e1b785e1aded3b1157db9a821af25e4e54ab72b7d3bc23
7
+ data.tar.gz: cc81f28a699618888e1d8f0b79abfac319ad8fdf47ba815f4841030bbf5a495856caf9a2904bb457f9473eaaed34c41b78669b1cfa1532907f5ec1fad3a0c67e
@@ -1,4 +1,33 @@
1
- # 0.0.1 - 2020-06-17
1
+ # 0.0.7 - 2020-06-24
2
+
3
+ - Remove forgotten pry requirement
4
+ - Don't update md files in `vendor/` (thanks @woodbusy)
5
+ - Readme clarification (thanks @woodbusy)
6
+
7
+ # 0.0.6 - 2020-06-23
8
+
9
+ - Include `find_references` in `update_docs`
10
+ - README Updates
11
+
12
+ # 0.0.5 - 2020-06-19
13
+
14
+ - Add `find_references` for finding non doc references
15
+ - Provide better explanation that you are updating docs only
16
+ - Rescue from branch protection errors like in personal private repos
17
+
18
+ # 0.0.4 - 2020-06-18
19
+
20
+ - Change `github` to `update`
21
+ - Add `update_docs` command
22
+
23
+ # 0.0.3 - 2020-06-17
24
+
25
+ - Only set api endpoint if not using "github.com"
26
+ - Bump rake version
27
+ - Typos
28
+ - Fetch before checking out main
29
+
30
+ # 0.0.2 - 2020-06-17
2
31
 
3
32
  Fix checkout of local branch, add local master branch deletion
4
33
 
@@ -0,0 +1 @@
1
+ - [@woodbusy](https://github.com/woodbusy)
@@ -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.7)
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
 
@@ -3,13 +3,14 @@ require "octokit"
3
3
 
4
4
  module MasterToMain
5
5
  class CLI < Thor
6
+ include Thor::Actions
7
+
6
8
  def self.exit_on_failure?
7
9
  true
8
10
  end
9
11
 
10
- desc "github", "rebase PRs to the main branch"
11
- def github
12
-
12
+ desc "update", "rebase PRs to the main branch"
13
+ def update
13
14
  prompt_info
14
15
  create_client
15
16
 
@@ -20,6 +21,21 @@ module MasterToMain
20
21
  rebase_pull_requests
21
22
  change_origin
22
23
  delete_local_old_branch
24
+ ask_update_docs
25
+ ask_find_references
26
+ end
27
+
28
+ desc "update_docs", "update local docs to use MAIN"
29
+ def update_docs
30
+ prompt_info
31
+ _update_docs
32
+ ask_find_references
33
+ end
34
+
35
+ desc "find_references", "find references to github urls with MAIN"
36
+ def find_references
37
+ prompt_info
38
+ _find_references
23
39
  end
24
40
 
25
41
  desc "update_local", "point local clone to new branch"
@@ -32,12 +48,15 @@ module MasterToMain
32
48
  `git branch --unset-upstream`
33
49
  `git branch -u origin/#{@repo.new_branch}`
34
50
  `git symbolic-ref refs/remotes/origin/HEAD refs/remotes/origin/#{@repo.new_branch}`
51
+ `git pull`
35
52
  end
36
53
 
37
54
  no_commands do
38
55
  def create_client
39
- Octokit.configure do |c|
40
- c.api_endpoint = @repo.api_endpoint
56
+ if @repo.github != "github.com"
57
+ Octokit.configure do |c|
58
+ c.api_endpoint = @repo.api_endpoint
59
+ end
41
60
  end
42
61
  token = ask("What is your GitHub Personal Access Token?")
43
62
 
@@ -55,7 +74,7 @@ module MasterToMain
55
74
  {
56
75
  github: "github." + github_suffix,
57
76
  user: user,
58
- repo: repo.chomp,
77
+ repo: repo.gsub(/\.git/, "").chomp,
59
78
  }
60
79
  else
61
80
  {
@@ -69,8 +88,8 @@ module MasterToMain
69
88
  def prompt_info
70
89
  github_info = get_github_info
71
90
  github_url = ask("What is your github url?", default: github_info[:github]).gsub(/https:\/\//, "")
72
- user = ask("What is your github user?", default: github_info[:user])
73
- github_repo = ask("What is your github repo?", default: github_info[:repo])
91
+ user = ask("What is the repo's parent user/organization?", default: github_info[:user])
92
+ github_repo = ask("What is your github repo?", default: github_info[:repo]).gsub(/\.git/, "")
74
93
  old_branch = ask("What is your current primary branch?", default: "master")
75
94
  new_branch = ask("What is your desired primary branch?", default: "main")
76
95
 
@@ -80,7 +99,7 @@ module MasterToMain
80
99
  def ensure_old_branch_exists
81
100
  @client.branch(@repo.name, @repo.old_branch)
82
101
  rescue Octokit::NotFound
83
- say "The current primary branch does not exist, or do you not have access. Was there a typo?", :red
102
+ say "The current primary branch does not exist, or you do not have access. Was there a typo?", :red
84
103
  say "-----------------------"
85
104
  say "CURRENT PRIMARY BRANCH: #{@repo.old_branch}", :green
86
105
  exit 1
@@ -113,7 +132,12 @@ module MasterToMain
113
132
  end
114
133
 
115
134
  def clone_branch_protections
116
- options = @client.branch_protection(@repo.name, @repo.old_branch)
135
+ begin
136
+ repo = @client.repo(@repo.name)
137
+ options = @client.branch_protection(@repo.name, @repo.old_branch)
138
+ rescue Octokit::Forbidden
139
+ return
140
+ end
117
141
 
118
142
  if options && yes?("Would you like to clone branch protections from '#{@repo.old_branch}'?")
119
143
  updates = BranchProtectionParams.build(options.to_h)
@@ -123,7 +147,7 @@ module MasterToMain
123
147
  end
124
148
 
125
149
  def rebase_pull_requests
126
- if yes?("Would you like to rebase all requests based on #{@repo.old_branch} to #{@repo.new_branch}?")
150
+ if yes?("Would you like to rebase all pull requests based on #{@repo.old_branch} to #{@repo.new_branch}?")
127
151
  prs = @client.pull_requests(@repo.name)
128
152
  prs.each do |pr|
129
153
  if pr[:base][:ref] == @repo.old_branch
@@ -141,6 +165,7 @@ module MasterToMain
141
165
 
142
166
  def change_origin
143
167
  if yes?("Would you like to change origin to point to #{@repo.new_branch}?")
168
+ `git fetch`
144
169
  `git checkout #{@repo.new_branch}`
145
170
  `git push -u origin #{@repo.new_branch}`
146
171
  else
@@ -155,6 +180,36 @@ module MasterToMain
155
180
  say "In order to ensure no builds or deployments break, please delete your remote #{@repo.old_branch} on github", :green
156
181
  say "----------------"
157
182
  end
183
+
184
+ def ask_update_docs
185
+ say("We can update #{@repo.github} references in '.md' files that include master in your repo")
186
+ say("For example: https://#{@repo.github}/#{@repo.name}/(tree|blob)/master")
187
+ if yes?("Would you like to update these references?")
188
+ _update_docs
189
+ say("You should consider searching for other references not in markdown files.")
190
+ say("We don't want to automatically change those in case something breaks.")
191
+ say("But you can use `master_to_main find_references` to show you where they are")
192
+ end
193
+ end
194
+
195
+ def ask_find_references
196
+ _find_references if yes?("Would you like to display other URL references?")
197
+ end
198
+
199
+ def _update_docs
200
+ say "This will update all references of #{@repo.old_branch} to #{@repo.new_branch} in the following lines in this repo:"
201
+ say "https://#{@repo.github}/#{@repo.name}/<tree|blob>/#{@repo.old_branch}"
202
+ Dir.glob("**/*.md").each do |path|
203
+ next if path.start_with?("vendor/")
204
+ path = File.expand_path(path, Dir.pwd)
205
+ gsub_file path, /#{@repo.old_branch_regex}/, @repo.new_branch_replacement, verbose: false
206
+ end
207
+ end
208
+
209
+ def _find_references
210
+ say "Here are the references to urls with #{@repo.old_branch}:\n\n"
211
+ puts `git grep -E '#{@repo.old_branch_regex}'`
212
+ end
158
213
  end
159
214
  end
160
215
  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.2"
2
+ VERSION = "0.0.7"
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.2
4
+ version: 0.0.7
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-24 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
@@ -92,6 +92,7 @@ files:
92
92
  - ".rspec"
93
93
  - CHANGELOG.md
94
94
  - CODE_OF_CONDUCT.md
95
+ - CONTRIBUTORS.md
95
96
  - Gemfile
96
97
  - Gemfile.lock
97
98
  - LICENSE