dependabot-common 0.315.0 → 0.316.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: 68238b0440934d660fcb680bd94b21397bf3396c0e4467fbd88fd21a23453a6f
4
- data.tar.gz: d263bcc8392bbad1168f031af2bdbf243190ab91ab1f019a7206c1af76f95652
3
+ metadata.gz: 96bdb5c59d32f26540da409a5dc9052431575832324c353ecb5b6f385962ff8c
4
+ data.tar.gz: 17ee865c4fe6825bb6e01b3f42e7255e1a283b35bf495a55d570977f529970c8
5
5
  SHA512:
6
- metadata.gz: 3165f873c2ff8492dc8f7ee6cfe0a136d664cf35653f9856ebc80f6c5c0fce35e287950be698263f62152affc82859d8808edb0bd2355d12f481193e9c463cb2
7
- data.tar.gz: 5692d5ad262572fc9cc91095010ed4b2381335d98d1064ee078c845cb9b17a060be52dd48d0ff72dc82526fd9bd1ed8c5dcd1551822be4c1e5c7f763df46c69e
6
+ metadata.gz: 326849c6620a3a1c87c6f32005010ccfb4bb8dad03bce1edc5c1944f19630a5c2c10119d965055f5c94327dcfec3fab22a09968675c9c4889c38a1f67857c960
7
+ data.tar.gz: 445ea4329399825e8637a325f2e41e7515732a480a80dd4961c4571ef22469bc361c29c0720a9907a24d661da507eef24f0e515c511290e49386f8b144893dcb
@@ -5,7 +5,7 @@ require "excon"
5
5
  require "open3"
6
6
  require "ostruct"
7
7
  require "sorbet-runtime"
8
-
8
+ require "tmpdir"
9
9
  require "dependabot/errors"
10
10
  require "dependabot/git_ref"
11
11
  require "dependabot/git_tag_with_detail"
@@ -118,6 +118,32 @@ module Dependabot
118
118
  result_lines
119
119
  end
120
120
 
121
+ sig { params(uri: String).returns(String) }
122
+ def fetch_tags_with_detail(uri)
123
+ response_with_git = fetch_tags_with_detail_from_git_for(uri)
124
+ return response_with_git.body if response_with_git.status == 200
125
+
126
+ raise Dependabot::GitDependenciesNotReachable, [uri] unless uri.match?(KNOWN_HOSTS)
127
+
128
+ if response_with_git.status < 400
129
+ raise "Unexpected response: #{response_with_git.status} - #{response_with_git.body}"
130
+ end
131
+
132
+ if uri.match?(/github\.com/i)
133
+ response = response_with_git.data
134
+ response[:response_headers] = response[:headers] unless response.nil?
135
+ raise Octokit::Error.from_response(response)
136
+ end
137
+
138
+ raise "Server error at #{uri}: #{response_with_git.body}" if response_with_git.status >= 500
139
+
140
+ raise Dependabot::GitDependenciesNotReachable, [uri]
141
+ rescue Excon::Error::Socket, Excon::Error::Timeout
142
+ raise if uri.match?(KNOWN_HOSTS)
143
+
144
+ raise Dependabot::GitDependenciesNotReachable, [uri]
145
+ end
146
+
121
147
  private
122
148
 
123
149
  sig { returns(String) }
@@ -293,54 +319,44 @@ module Dependabot
293
319
  raise Dependabot::GitDependenciesNotReachable, [url]
294
320
  end
295
321
 
296
- sig { params(uri: String).returns(String) }
297
- def fetch_tags_with_detail(uri)
298
- response = fetch_raw_upload_pack_for(uri)
299
- return response.body if response.status == 200
300
-
301
- response_with_git = fetch_tags_with_detail_from_git_for(uri)
302
- return response_with_git.body if response_with_git.status == 200
303
-
304
- raise Dependabot::GitDependenciesNotReachable, [uri] unless uri.match?(KNOWN_HOSTS)
305
-
306
- raise "Unexpected response: #{response.status} - #{response.body}" if response.status < 400
307
-
308
- if uri.match?(/github\.com/i)
309
- response = response.data
310
- response[:response_headers] = response[:headers]
311
- raise Octokit::Error.from_response(response)
312
- end
313
-
314
- raise "Server error at #{uri}: #{response.body}" if response.status >= 500
315
-
316
- raise Dependabot::GitDependenciesNotReachable, [uri]
317
- rescue Excon::Error::Socket, Excon::Error::Timeout
318
- raise if uri.match?(KNOWN_HOSTS)
319
-
320
- raise Dependabot::GitDependenciesNotReachable, [uri]
321
- end
322
-
322
+ # Added method to fetch tags with their creation dates from a git repository. In case
323
+ # private registry is used, it will clone the repository and fetch tags with their creation dates.
323
324
  sig { params(uri: String).returns(T.untyped) }
324
325
  def fetch_tags_with_detail_from_git_for(uri)
325
- complete_uri = uri
326
- complete_uri += ".git" unless complete_uri.end_with?(".git") || skip_git_suffix(uri)
327
-
328
- env = { "PATH" => ENV.fetch("PATH", nil), "GIT_TERMINAL_PROMPT" => "0" }
329
- command = "git for-each-ref --format=\"%(refname:short) %(creatordate:short)\" refs/tags #{complete_uri}"
330
- command = SharedHelpers.escape_command(command)
331
-
332
- begin
333
- stdout, stderr, process = Open3.capture3(env, command)
334
- # package the command response like a HTTP response so error handling remains unchanged
335
- rescue Errno::ENOENT => e # thrown when `git` isn't installed...
336
- OpenStruct.new(body: e.message, status: 500)
337
- else
338
- if process.success?
339
- OpenStruct.new(body: stdout, status: 200)
340
- else
341
- OpenStruct.new(body: stderr, status: 500)
326
+ uri_ending_with_git = uri
327
+ uri_ending_with_git += ".git" unless uri_ending_with_git.end_with?(".git") || skip_git_suffix(uri)
328
+
329
+ Dir.mktmpdir do |dir|
330
+ # Clone the repository into a temporary directory
331
+ clone_command = "git clone --bare #{uri_ending_with_git} #{dir}"
332
+ env = { "PATH" => ENV.fetch("PATH", nil), "GIT_TERMINAL_PROMPT" => "0" }
333
+ clone_command = SharedHelpers.escape_command(clone_command)
334
+
335
+ _stdout, stderr, process = Open3.capture3(env, clone_command)
336
+ return OpenStruct.new(body: stderr, status: 500) unless process.success?
337
+
338
+ # Change to the cloned repository directory
339
+ Dir.chdir(dir) do
340
+ # Fetch tags and their creation dates
341
+ tags_command = 'git for-each-ref --format="%(refname:short) %(creatordate:short)" refs/tags'
342
+ tags_stdout, stderr, process = Open3.capture3(env, tags_command)
343
+
344
+ return OpenStruct.new(body: stderr, status: 500) unless process.success?
345
+
346
+ # Parse and sort tags by creation date
347
+ tags = tags_stdout.lines.map do |line|
348
+ tag, date = line.strip.split(" ", 2)
349
+ { tag: tag, date: date }
350
+ end
351
+ sorted_tags = tags.sort_by { |tag| tag[:date] }
352
+
353
+ # Format the output as a string
354
+ formatted_output = sorted_tags.map { |tag| "#{tag[:tag]} #{tag[:date]}" }.join("\n")
355
+ return OpenStruct.new(body: formatted_output, status: 200)
342
356
  end
343
357
  end
358
+ rescue Errno::ENOENT => e # Thrown when `git` isn't installed
359
+ OpenStruct.new(body: e.message, status: 500)
344
360
  end
345
361
  end
346
362
  end
@@ -23,6 +23,7 @@ module Dependabot
23
23
  url: T.nilable(String),
24
24
  package_type: T.nilable(String),
25
25
  language: T.nilable(Dependabot::Package::PackageLanguage),
26
+ tag: T.nilable(String),
26
27
  details: T::Hash[String, T.untyped]
27
28
  ).void
28
29
  end
@@ -36,6 +37,7 @@ module Dependabot
36
37
  url: nil,
37
38
  package_type: nil,
38
39
  language: nil,
40
+ tag: nil,
39
41
  details: {}
40
42
  )
41
43
  @version = T.let(version, Dependabot::Version)
@@ -47,6 +49,7 @@ module Dependabot
47
49
  @url = T.let(url, T.nilable(String))
48
50
  @package_type = T.let(package_type, T.nilable(String))
49
51
  @language = T.let(language, T.nilable(Dependabot::Package::PackageLanguage))
52
+ @tag = T.let(tag, T.nilable(String))
50
53
  @details = T.let(details, T::Hash[String, T.untyped])
51
54
  end
52
55
 
@@ -77,6 +80,9 @@ module Dependabot
77
80
  sig { returns(T.nilable(Dependabot::Package::PackageLanguage)) }
78
81
  attr_reader :language
79
82
 
83
+ sig { returns(T.nilable(String)) }
84
+ attr_reader :tag
85
+
80
86
  sig { returns(T::Hash[String, T.untyped]) }
81
87
  attr_reader :details
82
88
 
data/lib/dependabot.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Dependabot
5
- VERSION = "0.315.0"
5
+ VERSION = "0.316.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.315.0
4
+ version: 0.316.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
@@ -625,7 +625,7 @@ licenses:
625
625
  - MIT
626
626
  metadata:
627
627
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
628
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.315.0
628
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.316.0
629
629
  rdoc_options: []
630
630
  require_paths:
631
631
  - lib