vanagon 0.39.0 → 0.39.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: 4ac97aec522601e6c06e6b246356b9fd2eef1a94d1548b501424224d4d51522c
4
- data.tar.gz: 557d3080596d55cc84819bd59b5d30d566c66d3620cc3687ea8bb889c8f50118
3
+ metadata.gz: 4fe169a867215743c1234c1dc7611f6747040505867c94f05379e2e789e1ef22
4
+ data.tar.gz: d663402a3ff359291b83a970e59ea8e9ce3b3101ba1a5d443e38b2372018ffa4
5
5
  SHA512:
6
- metadata.gz: 007b36851f55746bd042d54f1b4aa6ab2557b18f81f0d759730554080153b7cdbda44d8a16476f36f63556f906631eaca1bfa8de066c9c7b0bf4cc8da543e4e4
7
- data.tar.gz: fe4fa81aeb5246f3892cee17cea50b9545fce5f8dda33f491f7b92ad6f58c624e09540d3476353b2eeef58518fd730e310288140bdf03181b8d7c3137e8d6f3b
6
+ metadata.gz: 1c58c68372fb374b8ea3d3d016473e32bc41d76632f42dd76bcdef99a375b8758198fd1b193231932746d8c219cce8131817a43bc4c2597f8be2477c52f02d3f
7
+ data.tar.gz: 18e74e97521b6db5596d746ff6628f932bdfd0b69670987588063a8f6b688a4ce3e0bfcd9d2f6159af68f5f9c3a47a2336267a928e10e0adf35d3e7b4cdd9f29
@@ -60,6 +60,7 @@ class Vanagon
60
60
  # VANAGON-227 We need to be careful when guessing whether a https://github.com/...
61
61
  # URL is actually a true git repo. Make some rules around it based on the github API.
62
62
  # Decide that anything with a documented media_type is just an http url.
63
+ # We do this instead of talking to GitHub directly to avoid rate limiting.
63
64
  # See:
64
65
  # https://docs.github.com/en/repositories/working-with-files/using-files/downloading-source-code-archives
65
66
  # https://docs.github.com/en/rest/repos/contents?apiVersion=2022-11-28#download-a-repository-archive-tar
@@ -68,17 +69,13 @@ class Vanagon
68
69
  url_directory = url.to_s.delete_prefix(github_url_prefix)
69
70
  url_components = url_directory.split('/')
70
71
 
71
- return :github_remote if url_directory.end_with?('.git')
72
-
73
72
  # Find cases of supported github media types.
74
73
  # [ owner, repo, media_type, ref ]
75
- case url_components[2]
76
- when 'archive'
77
- :github_archive
78
- when 'tarball'
79
- :github_tarball
80
- when 'zipball'
81
- :github_zipball
74
+ path_types = ['archive', 'releases', 'tarball', 'zipball']
75
+ if path_types.include?(url_components[2]) ||
76
+ url_components[-1].end_with?('.tar.gz') ||
77
+ url_components[-1].end_with?('.zip')
78
+ :github_media
82
79
  else
83
80
  :github_remote
84
81
  end
@@ -22,20 +22,19 @@ class Vanagon
22
22
  return false unless ['http', 'https'].include? uri.scheme
23
23
 
24
24
  Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') do |http|
25
- http.request(Net::HTTP::Head.new(uri)) do |response|
26
- case response
27
- when Net::HTTPRedirection
28
- # By parsing the location header, we get either an absolute
29
- # URI or a URI with a relative `path`. Adding it to `uri`
30
- # should correctly update the relative `path` or overwrite
31
- # the entire URI if it's absolute.
32
- location = URI.parse(response.header['location'])
33
- valid_url?(uri + location)
34
- when Net::HTTPSuccess
35
- return true
36
- else
37
- false
38
- end
25
+ response = http.request(Net::HTTP::Head.new(uri))
26
+ case response
27
+ when Net::HTTPRedirection
28
+ # By parsing the location header, we get either an absolute
29
+ # URI or a URI with a relative `path`. Adding it to `uri`
30
+ # should correctly update the relative `path` or overwrite
31
+ # the entire URI if it's absolute.
32
+ location = URI.parse(response.header['location'])
33
+ valid_url?(uri + location)
34
+ when Net::HTTPSuccess
35
+ true
36
+ else
37
+ false
39
38
  end
40
39
  end
41
40
  end
@@ -15,12 +15,27 @@ describe "Vanagon::Component::Source::Git" do
15
15
  let(:github_archive_uri) do
16
16
  'https://github.com/2ndQuadrant/pglogical/archive/a_file_name.tar.gz'
17
17
  end
18
+ let(:github_releases_uri) do
19
+ 'https://github.com/libffi/libffi/releases/download/v3.4.3/libffi-3.4.3.tar.gz'
20
+ end
18
21
  let(:github_tarball_uri) do
19
22
  'https://github.com/Baeldung/kotlin-tutorials/tarball/main'
20
23
  end
21
24
  let(:github_zipball_uri) do
22
25
  'https://github.com/Baeldung/kotlin-tutorials/zipball/master'
23
26
  end
27
+ let(:github_actual_tarball_uri) do
28
+ 'https://github.com/puppetlabs/puppet/archive/refs/tags/8.2.0.tar.gz'
29
+ end
30
+ let(:github_actual_tarball_with_unexpected_path_uri) do
31
+ 'https://github.com/puppetlabs/puppet/something/refs/tags/8.2.0.tar.gz'
32
+ end
33
+ let(:github_actual_zipball_uri) do
34
+ 'https://github.com/puppetlabs/puppet/archive/refs/tags/8.2.0.zip'
35
+ end
36
+ let(:github_actual_zipball_with_unexpected_path_uri) do
37
+ 'https://github.com/puppetlabs/puppet/something/refs/tags/8.2.0.zip'
38
+ end
24
39
  let(:github_repo_uri) do
25
40
  'https://github.com/cameronmcnz/rock-paper-scissors'
26
41
  end
@@ -32,14 +47,34 @@ describe "Vanagon::Component::Source::Git" do
32
47
  expect(Vanagon::Component::Source::Git.valid_remote?(github_archive_uri)).to be false
33
48
  end
34
49
 
50
+ it "flags github releases uris as not valid repos" do
51
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_releases_uri)).to be false
52
+ end
53
+
35
54
  it "flags github tarball uris as not valid repos" do
36
55
  expect(Vanagon::Component::Source::Git.valid_remote?(github_tarball_uri)).to be false
37
56
  end
38
57
 
58
+ it "flags github actual tarball uris as not valid repos" do
59
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_actual_tarball_uri)).to be false
60
+ end
61
+
62
+ it "flags github actual tarball uris with an unexpected path as not valid repos" do
63
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_actual_tarball_with_unexpected_path_uri)).to be false
64
+ end
65
+
39
66
  it "flags git zipball uris as not valid repos" do
40
67
  expect(Vanagon::Component::Source::Git.valid_remote?(github_zipball_uri)).to be false
41
68
  end
42
69
 
70
+ it "flags github actual tarball uris as not valid repos" do
71
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_actual_zipball_uri)).to be false
72
+ end
73
+
74
+ it "flags github actual tarball uris with an unexpected path as not valid repos" do
75
+ expect(Vanagon::Component::Source::Git.valid_remote?(github_actual_zipball_with_unexpected_path_uri)).to be false
76
+ end
77
+
43
78
  it "identifies git generic uris as valid repos" do
44
79
  expect(Vanagon::Component::Source::Git.valid_remote?(github_repo_uri)).to be true
45
80
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vanagon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.39.0
4
+ version: 0.39.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Puppet By Perforce
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-08 00:00:00.000000000 Z
11
+ date: 2023-08-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt