manageiq-cross_repo 0.1.0 → 0.2.0

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: bf9a2849a682e80a6099be954de0a7f2a1e3f019b3b04018a5a18aeeec68f905
4
- data.tar.gz: 6308f46b490d5af9a923929bd706f9a41e057cd5cbefef8214db7b44f1d8978c
3
+ metadata.gz: 239fd403cb0702b0dc46c14a2091f60f6c3026eb9e2a4ba8177e2673111db23f
4
+ data.tar.gz: 65e594c923e080920fba7a24aa0ce75e31affa600e2f95238ff896c817dd597a
5
5
  SHA512:
6
- metadata.gz: 1bf15c4fe299adab8a79a0bc37afd619032c2a868adf328db72a9eec4d918f435496872f182349d675347d14220248bdc99399059f8a62af4113433117c4118b
7
- data.tar.gz: a910789c67868604ddc3fe304c7268952d474e36d81f120b39553c8dce2d23540984f319dd87f28cdd5dd4d80cdcd7fe01b4d44a97e9887b95b2ea00b4c9cf32
6
+ metadata.gz: 0a19241876f9e0d0911dd4ee6b5912ead8349b0c4acd648db93dca59d8f992f89130eb08e54efefb1472269c8f240ccefc29b94d2c469b5c85c6aaa1f37330cb
7
+ data.tar.gz: 120fbc5e638502dd731e3b37571595ff68f6125f54e37fed218a563d03c8e6e53a4e5291b33d1d8f2b40772a8221b43837cacdc0a47abc46855c637fd58224cf
data/README.md CHANGED
@@ -29,6 +29,9 @@ Repo Formats:
29
29
  @ref: Optional, defaults to master if #pr not set. Can be a branch, tag, or SHA. Mutually exclusive with #pr.
30
30
  #pr: Optional, references a pull-request number. Mutually exclusive with @ref.
31
31
 
32
+ URL: https://github.com/org/repository, https://github.com/org/repository/tree/branch,
33
+ https://github.com/org/repository/commit/sha, https://github.com/org/repository/pull/pr
34
+
32
35
  Local: Either a fully qualified path or a relative path (e.g. /path/to/repo, ~/relative/to/home, ../relative/to/current/dir)
33
36
 
34
37
  Examples:
@@ -49,6 +49,9 @@ opts = Optimist.options do
49
49
  @ref: Optional, defaults to master if #pr not set. Can be a branch, tag, or SHA. Mutually exclusive with #pr.
50
50
  #pr: Optional, references a pull-request number. Mutually exclusive with @ref.
51
51
 
52
+ URL: https://github.com/org/repository, https://github.com/org/repository/tree/branch,
53
+ https://github.com/org/repository/commit/sha, https://github.com/org/repository/pull/pr
54
+
52
55
  Local: Either a fully qualified path or a relative path (e.g. /path/to/repo, ~/relative/to/home, ../relative/to/current/dir)
53
56
  EOS
54
57
 
@@ -86,6 +89,11 @@ end
86
89
 
87
90
  opts[:gem_repos] = opts[:gem_repos].flatten.flat_map { |repo| repo.split(",").map(&:strip) }
88
91
 
92
+ if ENV["CI"] && opts[:test_repo] == "ManageIQ/manageiq@master" && opts[:core_repo].blank? && opts[:gem_repos].blank?
93
+ puts "Nothing to do!"
94
+ exit
95
+ end
96
+
89
97
  begin
90
98
  ManageIQ::CrossRepo.run(opts[:test_repo], opts[:core_repo], opts[:gem_repos])
91
99
  rescue ArgumentError => e
@@ -1,6 +1,7 @@
1
1
  module ManageIQ::CrossRepo
2
2
  class Repository
3
- attr_accessor :org, :repo, :ref, :sha, :url, :path
3
+ attr_reader :identifier, :server
4
+ attr_reader :org, :repo, :ref, :sha, :url, :path
4
5
 
5
6
  # ManageIQ::CrossRepo::Repository
6
7
  #
@@ -9,7 +10,9 @@ module ManageIQ::CrossRepo
9
10
  # @example
10
11
  # Repostory.new("ManageIQ/manageiq@master", server: "https://github.com")
11
12
  def initialize(identifier, server: "https://github.com")
12
- @org, @repo, @ref, @sha, @url, @path = parse_identifier(identifier, server)
13
+ @identifier = identifier
14
+ @server = server
15
+ @org, @repo, @ref, @sha, @url, @path = parse_identifier
13
16
  end
14
17
 
15
18
  def core?
@@ -37,34 +40,91 @@ module ManageIQ::CrossRepo
37
40
 
38
41
  private
39
42
 
40
- def parse_identifier(identifier, server)
41
- if ["/", "~", "."].include?(identifier[0])
42
- path = Pathname.new(identifier).expand_path
43
- raise ArgumentError, "Path #{path} does not exist" unless path.exist?
43
+ def parse_identifier
44
+ if local_identifier?
45
+ parse_local_identifier
46
+ elsif url_identifier?
47
+ parse_url_identifier
48
+ else
49
+ parse_repo_identifier
50
+ end
51
+ end
52
+
53
+ def local_identifier?
54
+ ["/", "~", "."].include?(identifier[0])
55
+ end
56
+
57
+ def parse_local_identifier
58
+ path = Pathname.new(identifier).expand_path
59
+ raise ArgumentError, "Path #{path} does not exist" unless path.exist?
60
+
61
+ org = nil
62
+ repo = path.basename.to_s
63
+ ref = Dir.chdir(path) { `git rev-parse HEAD`.chomp }
64
+ sha = ref
65
+ url = nil
66
+
67
+ return org, repo, ref, sha, url, path
68
+ end
69
+
70
+ def url_identifier?
71
+ identifier.start_with?(server)
72
+ end
73
+
74
+ def parse_url_identifier
75
+ url_path = URI.parse(identifier).path
76
+ _, org, repo, type, commit_branch_or_pr = url_path.split("/")
77
+
78
+ case type
79
+ when "tree"
80
+ branch = commit_branch_or_pr
81
+ when "commit"
82
+ commit = commit_branch_or_pr
83
+ when "pull"
84
+ pr = commit_branch_or_pr
85
+ else
86
+ branch = "master"
87
+ end
88
+
89
+ url = File.join(server, org, repo)
90
+ sha =
91
+ if pr
92
+ git_pr_to_sha(url, pr)
93
+ elsif branch
94
+ git_branch_to_sha(url, branch)
95
+ else
96
+ commit
97
+ end
44
98
 
45
- repo = path.basename.to_s
46
- ref = Dir.chdir(path) { `git rev-parse HEAD`.chomp }
47
- sha = ref
99
+ raise ArgumentError, "#{identifier} does not exist" if sha.nil?
100
+
101
+ ref = nil
102
+ path = REPOS_DIR.join("#{org}/#{repo}@#{sha}")
103
+
104
+ return org, repo, ref, sha, url, path
105
+ end
106
+
107
+ def parse_repo_identifier
108
+ if identifier.include?("#")
109
+ name, pr = identifier.split("#")
48
110
  else
49
- if identifier.include?("#")
50
- name, pr = identifier.split("#")
111
+ name, ref_or_branch = identifier.split("@")
112
+ if ref_or_branch.nil?
113
+ branch = "master"
114
+ elsif ref_or_branch.match?(/^\h+$/)
115
+ ref = ref_or_branch
51
116
  else
52
- name, ref_or_branch = identifier.split("@")
53
- if ref_or_branch.nil?
54
- branch = "master"
55
- elsif ref_or_branch.match?(/^\h+$/)
56
- ref = ref_or_branch
57
- else
58
- branch = ref_or_branch
59
- end
117
+ branch = ref_or_branch
60
118
  end
119
+ end
61
120
 
62
- org, repo = name.split("/")
63
- repo, org = org, "ManageIQ" if repo.nil?
121
+ org, repo = name.split("/")
122
+ repo, org = org, "ManageIQ" if repo.nil?
64
123
 
65
- url = File.join(server, org, repo)
124
+ url = File.join(server, org, repo)
66
125
 
67
- sha = if pr
126
+ sha =
127
+ if pr
68
128
  git_pr_to_sha(url, pr)
69
129
  elsif branch
70
130
  git_branch_to_sha(url, branch)
@@ -72,10 +132,9 @@ module ManageIQ::CrossRepo
72
132
  ref
73
133
  end
74
134
 
75
- raise ArgumentError, "#{identifier} does not exist" if sha.nil?
135
+ raise ArgumentError, "#{identifier} does not exist" if sha.nil?
76
136
 
77
- path = REPOS_DIR.join("#{org}/#{repo}@#{sha}")
78
- end
137
+ path = REPOS_DIR.join("#{org}/#{repo}@#{sha}")
79
138
 
80
139
  return org, repo, ref, sha, url, path
81
140
  end
@@ -89,7 +148,7 @@ module ManageIQ::CrossRepo
89
148
  end
90
149
 
91
150
  def git_pr_to_sha(url, pr)
92
- `git ls-remote #{url} refs/pull/#{pr}/head`.split("\t").first
151
+ git_branch_to_sha(url, "refs/pull/#{pr}/head")
93
152
  end
94
153
  end
95
154
  end
@@ -58,7 +58,7 @@ module ManageIQ::CrossRepo
58
58
  end
59
59
 
60
60
  def system!(*args)
61
- exit($CHILD_STATUS.exitstatus) unless system(*args)
61
+ exit($?.exitstatus) unless system(*args)
62
62
  end
63
63
 
64
64
  def generate_bundler_d
@@ -68,7 +68,7 @@ module ManageIQ::CrossRepo
68
68
  if gem_repos.empty?
69
69
  FileUtils.rm_f override_path
70
70
  else
71
- content = gem_repos.map { |gem| "override_gem \"#{gem.repo}\", :path => \"#{gem.path}\"" }.join("\n")
71
+ content = gem_repos.map { |gem| "ensure_gem \"#{gem.repo}\", :path => \"#{gem.path}\"" }.join("\n")
72
72
  FileUtils.mkdir_p(bundler_d_path)
73
73
 
74
74
  File.write(override_path, content)
@@ -1,5 +1,5 @@
1
1
  module ManageIQ
2
2
  module CrossRepo
3
- VERSION = "0.1.0"
3
+ VERSION = "0.2.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: manageiq-cross_repo
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - ManageIQ Authors
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-10-22 00:00:00.000000000 Z
11
+ date: 2019-10-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake