dependabot-common 0.272.0 → 0.273.0

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: 317e2fbaa5340fe4a995a419da5ace365912a1a47de42ebc79adf23cc704b98c
4
- data.tar.gz: 214d238bc3b6de57972e5676aac6e6b837187fb6fee5c050d673257ed751ef9c
3
+ metadata.gz: be0c28765d665424088cb737d933cf376c29d931e1d642f96562d362c406fcf0
4
+ data.tar.gz: de8f912ee099ed27b8d14811f7fb67f9b83119dc7db2483645947b2cd12b380d
5
5
  SHA512:
6
- metadata.gz: 64b49b8b1dec8d348b62090c5d67b5793f1ded64126b493fbc848aea8075ccaaa2c852cf14702bfd3bcea4c26b79a0e99cfe54f9d0a7f326af8a97aa2f53bd34
7
- data.tar.gz: e1020c4794c5ca79434d4c488d20f565fbc6b0694f03def3e948700803aa46fa6ecfa19bdf740b83b68764bd9624c46496e51fe8dddecebeda6b1d6afe9370ad
6
+ metadata.gz: e45c119606e121da9f919de9e40ff1ae63e22ad0167308bcb1e74b626296607fa8d05634ccb7ac922943d547c0f99820fab5c89fe105580146b5dc2224fbd97a
7
+ data.tar.gz: 2bc6a5d526316d9d81cbfb0e03d06699a28e03757ff36f07a46d870a1e55a89794ffd834f3c1c8e21c7ccf737ed325bc1af111a2e22234641c54e1bb9d8cd56b
@@ -6,32 +6,51 @@ require "dependabot/package_manager"
6
6
 
7
7
  module Dependabot
8
8
  class Notice
9
+ module NoticeMode
10
+ INFO = "INFO"
11
+ WARN = "WARN"
12
+ ERROR = "ERROR"
13
+ end
14
+
9
15
  extend T::Sig
10
16
 
11
17
  sig { returns(String) }
12
- attr_reader :mode, :type, :package_manager_name, :message, :markdown
18
+ attr_reader :mode, :type, :package_manager_name, :title, :description
19
+
20
+ sig { returns(T::Boolean) }
21
+ attr_reader :show_in_pr, :show_alert
13
22
 
14
23
  # Initializes a new Notice object.
15
24
  # @param mode [String] The mode of the notice (e.g., "WARN", "ERROR").
16
25
  # @param type [String] The type of the notice (e.g., "bundler_deprecated_warn").
17
26
  # @param package_manager_name [String] The name of the package manager (e.g., "bundler").
18
- # @param message [String] The main message of the notice.
19
- # @param markdown [String] The markdown formatted message.
27
+ # @param title [String] The title of the notice.
28
+ # @param description [String] The main description of the notice.
29
+ # @param show_in_pr [Boolean] Whether the notice should be shown in a pull request.
30
+ # @param show_alert [Boolean] Whether the notice should be shown in alerts.
20
31
  sig do
21
32
  params(
22
33
  mode: String,
23
34
  type: String,
24
35
  package_manager_name: String,
25
- message: String,
26
- markdown: String
36
+ title: String,
37
+ description: String,
38
+ show_in_pr: T::Boolean,
39
+ show_alert: T::Boolean
27
40
  ).void
28
41
  end
29
- def initialize(mode:, type:, package_manager_name:, message: "", markdown: "")
42
+ def initialize(
43
+ mode:, type:, package_manager_name:,
44
+ title: "", description: "",
45
+ show_in_pr: false, show_alert: false
46
+ )
30
47
  @mode = mode
31
48
  @type = type
32
49
  @package_manager_name = package_manager_name
33
- @message = message
34
- @markdown = markdown
50
+ @title = title
51
+ @description = description
52
+ @show_in_pr = show_in_pr
53
+ @show_alert = show_alert
35
54
  end
36
55
 
37
56
  # Converts the Notice object to a hash.
@@ -42,23 +61,25 @@ module Dependabot
42
61
  mode: @mode,
43
62
  type: @type,
44
63
  package_manager_name: @package_manager_name,
45
- message: @message,
46
- markdown: @markdown
64
+ title: @title,
65
+ description: @description,
66
+ show_in_pr: @show_in_pr,
67
+ show_alert: @show_alert
47
68
  }
48
69
  end
49
70
 
50
- # Generates a message for supported versions.
71
+ # Generates a description for supported versions.
51
72
  # @param supported_versions [Array<Dependabot::Version>, nil] The supported versions of the package manager.
52
73
  # @param support_later_versions [Boolean] Whether later versions are supported.
53
- # @return [String, nil] The generated message or nil if no supported versions are provided.
74
+ # @return [String, nil] The generated description or nil if no supported versions are provided.
54
75
  sig do
55
76
  params(
56
77
  supported_versions: T.nilable(T::Array[Dependabot::Version]),
57
78
  support_later_versions: T::Boolean
58
79
  ).returns(String)
59
80
  end
60
- def self.generate_supported_versions_message(supported_versions, support_later_versions)
61
- return "" unless supported_versions&.any?
81
+ def self.generate_supported_versions_description(supported_versions, support_later_versions)
82
+ return "Please upgrade your package manager version" unless supported_versions&.any?
62
83
 
63
84
  versions_string = supported_versions.map { |version| "`v#{version}`" }
64
85
 
@@ -66,11 +87,11 @@ module Dependabot
66
87
 
67
88
  versions_string = versions_string.join(", ")
68
89
 
69
- later_message = support_later_versions ? ", or later" : ""
90
+ later_description = support_later_versions ? ", or later" : ""
70
91
 
71
- return "Please upgrade to version #{versions_string}#{later_message}." if supported_versions.count == 1
92
+ return "Please upgrade to version #{versions_string}#{later_description}." if supported_versions.count == 1
72
93
 
73
- "Please upgrade to one of the following versions: #{versions_string}#{later_message}."
94
+ "Please upgrade to one of the following versions: #{versions_string}#{later_description}."
74
95
  end
75
96
 
76
97
  # Generates a support notice for the given package manager.
@@ -100,30 +121,26 @@ module Dependabot
100
121
  def self.generate_pm_deprecation_notice(package_manager)
101
122
  return nil unless package_manager.deprecated?
102
123
 
103
- mode = "WARN"
104
- supported_versions_message = generate_supported_versions_message(
124
+ mode = NoticeMode::WARN
125
+ supported_versions_description = generate_supported_versions_description(
105
126
  package_manager.supported_versions,
106
127
  package_manager.support_later_versions?
107
128
  )
108
- notice_type = "#{package_manager.name}_deprecated_#{mode.downcase}"
109
- message = "Dependabot will stop supporting `#{package_manager.name} v#{package_manager.version}`!"
110
- ## Create a warning markdown message
111
- markdown = "> [!WARNING]\n"
112
- ## Add the deprecation warning to the message
113
- markdown += "> #{message}\n>\n"
114
-
115
- ## Add the supported versions to the message
116
- unless supported_versions_message.empty?
117
- message += "\n#{supported_versions_message}\n"
118
- markdown += "> #{supported_versions_message}\n>\n"
119
- end
129
+ notice_type = "#{package_manager.name}_deprecated_warn"
130
+ title = "Package manager deprecation notice"
131
+ description = "Dependabot will stop supporting `#{package_manager.name} v#{package_manager.version}`!"
132
+
133
+ ## Add the supported versions to the description
134
+ description += "\n\n#{supported_versions_description}\n" unless supported_versions_description.empty?
120
135
 
121
136
  Notice.new(
122
137
  mode: mode,
123
138
  type: notice_type,
124
139
  package_manager_name: package_manager.name,
125
- message: message,
126
- markdown: markdown
140
+ title: title,
141
+ description: description,
142
+ show_in_pr: true,
143
+ show_alert: true
127
144
  )
128
145
  end
129
146
 
@@ -138,31 +155,56 @@ module Dependabot
138
155
  def self.generate_pm_unsupported_notice(package_manager)
139
156
  return nil unless package_manager.unsupported?
140
157
 
141
- mode = "ERROR"
142
- supported_versions_message = generate_supported_versions_message(
158
+ mode = NoticeMode::ERROR
159
+ supported_versions_description = generate_supported_versions_description(
143
160
  package_manager.supported_versions,
144
161
  package_manager.support_later_versions?
145
162
  )
146
- notice_type = "#{package_manager.name}_unsupported_#{mode.downcase}"
147
- message = "Dependabot no longer supports `#{package_manager.name} v#{package_manager.version}`!"
148
- ## Create an error markdown message
149
- markdown = "> [!IMPORTANT]\n"
150
- ## Add the error message to the message
151
- markdown += "> #{message}\n>\n"
152
-
153
- ## Add the supported versions to the message
154
- unless supported_versions_message.empty?
155
- message += "\n#{supported_versions_message}\n"
156
- markdown += "> #{supported_versions_message}\n>\n"
157
- end
163
+ notice_type = "#{package_manager.name}_unsupported_error"
164
+ title = "Package manager unsupported notice"
165
+ description = "Dependabot no longer supports `#{package_manager.name} v#{package_manager.version}`!"
166
+
167
+ ## Add the supported versions to the description
168
+ description += "\n\n#{supported_versions_description}\n" unless supported_versions_description.empty?
158
169
 
159
170
  Notice.new(
160
171
  mode: mode,
161
172
  type: notice_type,
162
173
  package_manager_name: package_manager.name,
163
- message: message,
164
- markdown: markdown
174
+ title: title,
175
+ description: description,
176
+ show_in_pr: true,
177
+ show_alert: true
165
178
  )
166
179
  end
180
+
181
+ sig { params(notice: Notice).returns(T.nilable(String)) }
182
+ def self.markdown_from_description(notice)
183
+ description = notice.description
184
+
185
+ return if description.empty?
186
+
187
+ markdown = "> [!#{markdown_mode(notice.mode)}]\n"
188
+ # Log each non-empty line of the deprecation notice description
189
+ description.each_line do |line|
190
+ line = line.strip
191
+ markdown += "> #{line}\n"
192
+ end
193
+ markdown
194
+ end
195
+
196
+ sig { params(mode: String).returns(String) }
197
+ def self.markdown_mode(mode)
198
+ case mode
199
+ when NoticeMode::INFO
200
+ "INFO"
201
+ when NoticeMode::WARN
202
+ "WARNING"
203
+ when NoticeMode::ERROR
204
+ "IMPORTANT"
205
+ else
206
+ "INFO"
207
+ end
208
+ end
167
209
  end
168
210
  end
@@ -143,8 +143,7 @@ module Dependabot
143
143
  def pr_notices
144
144
  notices = @notices || []
145
145
  unique_messages = notices.filter_map do |notice|
146
- markdown = notice.markdown if notice
147
- markdown unless markdown.empty?
146
+ Dependabot::Notice.markdown_from_description(notice) if notice.show_in_pr
148
147
  end.uniq
149
148
 
150
149
  message = unique_messages.join("\n\n")
data/lib/dependabot.rb CHANGED
@@ -2,5 +2,5 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  module Dependabot
5
- VERSION = "0.272.0"
5
+ VERSION = "0.273.0"
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dependabot-common
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.272.0
4
+ version: 0.273.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-08-22 00:00:00.000000000 Z
11
+ date: 2024-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aws-sdk-codecommit
@@ -600,7 +600,7 @@ licenses:
600
600
  - MIT
601
601
  metadata:
602
602
  bug_tracker_uri: https://github.com/dependabot/dependabot-core/issues
603
- changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.272.0
603
+ changelog_uri: https://github.com/dependabot/dependabot-core/releases/tag/v0.273.0
604
604
  post_install_message:
605
605
  rdoc_options: []
606
606
  require_paths: