multi_repo 0.3.0 → 0.3.1

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: 437c3e990a7e7feb750b0a2d65744d076bc496ce3de3560d25d25f4df8b335e9
4
- data.tar.gz: 695fca5f0b5ac72a1b91130381be208202a0bfbfcb11f866a6ce7f98b867e478
3
+ metadata.gz: 313d72f8febb801872f9f65ade31381a3104b32a21d1628e8c56ee3186b78164
4
+ data.tar.gz: 1850ed479241b145ba84295dcfe0a0cde15bce8d28f81c2fb11df90e69349d40
5
5
  SHA512:
6
- metadata.gz: fa5a942aabcf9a2ad1b04c594785992c9c553f58f7176d11d734707becbc09e02344dca9f0cba462e4a732e73b591e463f55f5dd9cd211bf5a6ed03bd9d6283b
7
- data.tar.gz: c89faaec5c8931c84fac5a4706316723a6eeaa16160b1770a2f9e4dc457bddc821cd401487e8f76f90cb967f2dcade5e785dfabd1c8ac45f3e00605d141fd468
6
+ metadata.gz: 9e5ce408edfeab47540e55241c6508cc6d0d84be9e31cc9531ecf7136d44c2b8be3797c7a909128fa22a0ba67f864e485eac32f121c68bd5afba674d983845be
7
+ data.tar.gz: c178885fe71a1f399d25f661081cb7560bdaba988d9b4a4ac1ec0c4b207858c798f18b751da988c7aa864a6a1854af96d6de361b55530b37ac8069699e9241e8
@@ -17,7 +17,7 @@ jobs:
17
17
  env:
18
18
  CC_TEST_REPORTER_ID: ${{ secrets.CC_TEST_REPORTER_ID }}
19
19
  steps:
20
- - uses: actions/checkout@v3
20
+ - uses: actions/checkout@v4
21
21
  - name: Set up Ruby
22
22
  uses: ruby/setup-ruby@v1
23
23
  with:
data/CHANGELOG.md ADDED
@@ -0,0 +1,14 @@
1
+ # Change Log
2
+ All notable changes to this project will be documented in this file.
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ ## [Unreleased]
6
+
7
+ ## [0.3.1] - 2024-01-31
8
+ ### Fixed
9
+ - [pull_request_blaster_outer] Various fixes and cleanup output [[#21](https://github.com/ManageIQ/multi_repo/pull/21)]
10
+ - [show_commit_history] Prevent missing ranges from failing the entire run [[#22](https://github.com/ManageIQ/multi_repo/pull/22)]
11
+ - [pull_request_merger] Fixing issue passing kwargs on Ruby 3 [[#23](https://github.com/ManageIQ/multi_repo/pull/23)]
12
+
13
+ [Unreleased]: https://github.com/ManageIQ/more_core_extensions/compare/v0.3.1...HEAD
14
+ [0.3.1]: https://github.com/ManageIQ/more_core_extensions/compare/v0.3.0...v0.3.1
@@ -9,8 +9,7 @@ module MultiRepo::Helpers
9
9
  @base = base
10
10
  @head = head
11
11
  @script = begin
12
- s = Pathname.new(script)
13
- s = Pathname.new(Dir.pwd).join(script) if s.relative?
12
+ s = Pathname.new(script).expand_path
14
13
  raise "File not found #{s}" unless s.exist?
15
14
  s.to_s
16
15
  end
@@ -20,12 +19,10 @@ module MultiRepo::Helpers
20
19
  end
21
20
 
22
21
  def blast
23
- puts "+++ blasting #{repo.name}..."
24
-
25
22
  repo.git.fetch
26
23
 
27
24
  unless repo.git.remote_branch?("origin", base)
28
- puts "!!! Skipping #{repo.name}: 'origin/#{base}' not found"
25
+ puts "!! Skipping #{repo.name}: 'origin/#{base}' not found".light_yellow
29
26
  return
30
27
  end
31
28
 
@@ -33,20 +30,31 @@ module MultiRepo::Helpers
33
30
  run_script
34
31
 
35
32
  result = false
36
- if !commit_changes
37
- puts "!!! Failed to commit changes. Perhaps the script is wrong or #{repo.name} is already updated."
38
- elsif dry_run
39
- result = "Committed but is dry run"
33
+ if !changes_found?
34
+ puts
35
+ puts "!! Skipping #{repo.name}: No changes found".light_yellow
36
+ result = "no changes".light_yellow
40
37
  else
41
- puts "Do you want to open a pull request on #{repo.name} with the above changes? (Y/N)"
42
- answer = $stdin.gets.chomp
43
- if answer.upcase.start_with?("Y")
44
- fork_repo unless forked?
45
- push_branch
46
- result = open_pull_request
38
+ commit_changes
39
+ show_commit
40
+ puts
41
+
42
+ if dry_run
43
+ puts "** dry-run: Skipping opening pull request".light_black
44
+ result = "dry run".light_black
45
+ else
46
+ print "Do you want to open a pull request on #{repo.name} with the above changes? (y/N): "
47
+ answer = $stdin.gets.chomp
48
+ if answer.upcase.start_with?("Y")
49
+ fork_repo unless forked?
50
+ push_branch
51
+ result = open_pull_request
52
+ else
53
+ puts "!! Skipping #{repo.name}: User ignored".light_yellow
54
+ result = "ignored".light_yellow
55
+ end
47
56
  end
48
57
  end
49
- puts "--- blasting #{repo.name} complete"
50
58
  result
51
59
  end
52
60
 
@@ -57,7 +65,9 @@ module MultiRepo::Helpers
57
65
  end
58
66
 
59
67
  def forked?
60
- github.client.repos(github.client.login).any? { |m| m.name == repo.name }
68
+ # NOTE: There is an assumption here that the fork's name will match the source's name.
69
+ # Ideally there would be a "forked from" field in the repo metadata, but there isn't.
70
+ github.client.repos(github.client.login, :type => "forks").any? { |m| m.name == repo.short_name }
61
71
  end
62
72
 
63
73
  def fork_repo
@@ -70,41 +80,41 @@ module MultiRepo::Helpers
70
80
 
71
81
  def run_script
72
82
  repo.chdir do
73
- parts = []
74
- parts << "GITHUB_REPO=#{repo.name}"
75
- parts << "DRY_RUN=true" if dry_run
76
- parts << script
77
- cmd = parts.join(" ")
78
-
79
- unless system(cmd)
80
- puts "!!! Script execution failed."
81
- exit $?.exitstatus
83
+ Bundler.with_unbundled_env do
84
+ parts = []
85
+ parts << "GITHUB_REPO=#{repo.name}"
86
+ parts << "DRY_RUN=true" if dry_run
87
+ parts << script
88
+ cmd = parts.join(" ")
89
+
90
+ unless system(cmd)
91
+ puts "!! Script execution failed.".light_red
92
+ exit $?.exitstatus
93
+ end
82
94
  end
83
95
  end
84
96
  end
85
97
 
98
+ def changes_found?
99
+ repo.git.client.capturing.status("--porcelain").chomp.present?
100
+ end
101
+
86
102
  def commit_changes
87
- repo.chdir do
88
- begin
89
- repo.git.client.add("-v", ".")
90
- repo.git.client.commit("-m", message)
91
- repo.git.client.show
92
- if dry_run
93
- puts "!!! --dry-run enabled: If the above commit in #{repo.path} looks good, run again without dry run to fork the repo, push the branch and open a pull request."
94
- end
95
- true
96
- rescue MiniGit::GitError => e
97
- e.status.exitstatus == 0
98
- end
99
- end
103
+ repo.git.client.add("-v", ".")
104
+ repo.git.client.commit("-m", message)
105
+ end
106
+
107
+ def show_commit
108
+ repo.git.client.show
100
109
  end
101
110
 
102
- def origin_remote
111
+ def blast_remote
103
112
  "pr_blaster_outer"
104
113
  end
105
114
 
106
- def origin_url
107
- "git@github.com:#{github.client.login}/#{repo.name}.git"
115
+ def blast_remote_url
116
+ # NOTE: Similar to `forked?`, there is an assumption here that the fork's name will match the source's name.
117
+ "git@github.com:#{github.client.login}/#{repo.short_name}.git"
108
118
  end
109
119
 
110
120
  def pr_head
@@ -112,10 +122,8 @@ module MultiRepo::Helpers
112
122
  end
113
123
 
114
124
  def push_branch
115
- repo.chdir do
116
- repo.git.client.remote("add", origin_remote, origin_url) unless repo.git.remote?(origin_remote)
117
- repo.git.client.push("-f", origin_remote, "#{head}:#{head}")
118
- end
125
+ repo.git.client.remote("add", blast_remote, blast_remote_url) unless repo.git.remote?(blast_remote)
126
+ repo.git.client.push("-f", blast_remote, "#{head}:#{head}")
119
127
  end
120
128
 
121
129
  def open_pull_request
@@ -123,7 +131,7 @@ module MultiRepo::Helpers
123
131
  pr.html_url
124
132
  rescue => err
125
133
  raise unless err.message.include?("A pull request already exists")
126
- puts "!!! Skipping. #{err.message}"
134
+ puts "!! Skipping #{repo.name}: #{err.message}".light_yellow
127
135
  end
128
136
  end
129
137
  end
@@ -1,3 +1,3 @@
1
1
  module MultiRepo
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
@@ -4,7 +4,9 @@ require "bundler/inline"
4
4
  gemfile do
5
5
  source "https://rubygems.org"
6
6
  gem "multi_repo", require: "multi_repo/cli", path: File.expand_path("..", __dir__)
7
+ gem "more_core_extensions"
7
8
  end
9
+ require "more_core_extensions/core_ext/array/tableize"
8
10
 
9
11
  opts = Optimist.options do
10
12
  synopsis "Create a pull request on all repos."
@@ -19,8 +21,11 @@ opts = Optimist.options do
19
21
  end
20
22
 
21
23
  results = {}
22
- MultiRepo::CLI.each_repo(**opts) do |repo|
23
- results[repo.name] = MultiRepo::Helpers::PullRequestBlasterOuter.new(repo, **opts).blast
24
+ begin
25
+ MultiRepo::CLI.each_repo(**opts) do |repo|
26
+ results[repo.name] = MultiRepo::Helpers::PullRequestBlasterOuter.new(repo, **opts).blast
27
+ end
28
+ ensure
29
+ puts "Summary:"
30
+ puts results.to_a.tableize(:header => false) unless results.empty?
24
31
  end
25
-
26
- pp results
@@ -57,9 +57,9 @@ opts[:prs].each do |pr|
57
57
 
58
58
  repo_name, pr_number = PR_REGEX.match(pr).captures
59
59
 
60
- merge_pull_request(repo_name, pr_number, opts)
61
- add_labels(repo_name, pr_number, opts) if opts[:labels].present?
62
- assign_user(repo_name, pr_number, opts)
60
+ merge_pull_request(repo_name, pr_number, **opts)
61
+ add_labels(repo_name, pr_number, **opts) if opts[:labels].present?
62
+ assign_user(repo_name, pr_number, **opts)
63
63
 
64
64
  puts
65
65
  end
@@ -48,7 +48,15 @@ MultiRepo::CLI.repos_for(**opts).each do |repo|
48
48
  end
49
49
  results["other"] = []
50
50
 
51
- log = repo.git.client.capturing.log({:oneline => true}, range)
51
+ log =
52
+ begin
53
+ repo.git.client.capturing.log({:oneline => true}, range)
54
+ rescue MiniGit::GitError
55
+ puts "ERROR: commit range not found.".light_red
56
+ puts
57
+ next
58
+ end
59
+
52
60
  log.lines.each do |line|
53
61
  next unless (match = line.match(/Merge pull request #(\d+)\b/))
54
62
 
@@ -71,7 +79,15 @@ MultiRepo::CLI.repos_for(**opts).each do |repo|
71
79
 
72
80
  repos_with_changes << repo if changes_found
73
81
  when "commit"
74
- output = repo.git.client.capturing.log({:oneline => true, :decorate => true, :graph => true}, range)
82
+ output =
83
+ begin
84
+ repo.git.client.capturing.log({:oneline => true, :decorate => true, :graph => true}, range)
85
+ rescue MiniGit::GitError
86
+ puts "ERROR: commit range not found.".light_red
87
+ puts
88
+ next
89
+ end
90
+
75
91
  puts output
76
92
  repos_with_changes << repo if output.present?
77
93
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: multi_repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-07 00:00:00.000000000 Z
11
+ date: 2024-01-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -279,6 +279,7 @@ files:
279
279
  - ".rubocop_cc.yml"
280
280
  - ".rubocop_local.yml"
281
281
  - ".whitesource"
282
+ - CHANGELOG.md
282
283
  - Gemfile
283
284
  - LICENSE.txt
284
285
  - README.md