dependabot-common 0.139.1 → 0.140.3

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: 14fda97b138d41cabecc3d42788bb0b4a327de69d04dc23f897daf83b9881df7
4
- data.tar.gz: 9f3ee6368d26b56394b10c3dc2c104c316ef56cb4cda642915f8a45da61af116
3
+ metadata.gz: 189215ae85298ad27a01437d5702c01c8ba2e68dd149f1b334118680888bbc51
4
+ data.tar.gz: df61584f2d45aaad32480af08209e911271feab1c1c378167a84cf272b46aa3c
5
5
  SHA512:
6
- metadata.gz: 5a09177d3c27a3c321980a9acf566543ce1ee657300854dc2e7a942de2e1124bea8189bcb54eb459d7e2820dc8745424c3479422ccf772b173db79027ac37567
7
- data.tar.gz: c17abdd1331d9ee815a44e77e5de2ea51050c153a00859e411dddc78915c641bb385f2d45e7dd034fd9ea1efd4d82b29cdde4192dfc2efb9c641911472161471
6
+ metadata.gz: 907e246bd29e3393be326e7fcfe285c4211d1851fbb58d55b67f5e3530d1b11b107816f142e3c86081f6457d745e91b25bfa8f5abfa9b020deb631dc96196e85
7
+ data.tar.gz: b52deaf257874776bcf38e7a4346ce07ade51e490ad8ef864c4048bf6451bc5c69231f20a273fc45184107de50b08afcac041e122f45e6477765961b0d956a18
@@ -5,23 +5,33 @@ require "pathname"
5
5
  module Dependabot
6
6
  class DependencyFile
7
7
  attr_accessor :name, :content, :directory, :type, :support_file,
8
- :symlink_target, :content_encoding, :deleted
8
+ :symlink_target, :content_encoding, :operation
9
9
 
10
10
  class ContentEncoding
11
11
  UTF_8 = "utf-8"
12
12
  BASE64 = "base64"
13
13
  end
14
14
 
15
+ class Operation
16
+ UPDATE = "update"
17
+ CREATE = "create"
18
+ DELETE = "delete"
19
+ end
20
+
15
21
  def initialize(name:, content:, directory: "/", type: "file",
16
22
  support_file: false, symlink_target: nil,
17
- content_encoding: ContentEncoding::UTF_8, deleted: false)
23
+ content_encoding: ContentEncoding::UTF_8, deleted: false, operation: Operation::UPDATE)
18
24
  @name = name
19
25
  @content = content
20
26
  @directory = clean_directory(directory)
21
27
  @symlink_target = symlink_target
22
28
  @support_file = support_file
23
29
  @content_encoding = content_encoding
24
- @deleted = deleted
30
+ @operation = operation
31
+
32
+ # Make deleted override the operation. Deleted is kept when operation
33
+ # was introduced to keep compatibility with downstream dependants.
34
+ @operation = Operation::DELETE if deleted
25
35
 
26
36
  # Type is used *very* sparingly. It lets the git_modules updater know that
27
37
  # a "file" is actually a submodule, and lets our Go updaters know which
@@ -44,7 +54,8 @@ module Dependabot
44
54
  "type" => type,
45
55
  "support_file" => support_file,
46
56
  "content_encoding" => content_encoding,
47
- "deleted" => deleted
57
+ "deleted" => deleted,
58
+ "operation" => operation
48
59
  }
49
60
 
50
61
  details["symlink_target"] = symlink_target if symlink_target
@@ -75,8 +86,16 @@ module Dependabot
75
86
  @support_file
76
87
  end
77
88
 
89
+ def deleted
90
+ @operation == Operation::DELETE
91
+ end
92
+
93
+ def deleted=(deleted)
94
+ @operation = deleted ? Operation::DELETE : Operation::UPDATE
95
+ end
96
+
78
97
  def deleted?
79
- @deleted
98
+ deleted
80
99
  end
81
100
 
82
101
  def binary?
@@ -27,12 +27,20 @@ module Dependabot
27
27
  )
28
28
  changed_paths = status.split("\n").map { |l| l.split(" ") }
29
29
  changed_paths.map do |type, path|
30
- deleted = type == "D"
30
+ # The following types are possible to be returned:
31
+ # M = Modified = Default for DependencyFile
32
+ # D = Deleted
33
+ # ?? = Untracked = Created
34
+ operation = Dependabot::DependencyFile::Operation::UPDATE
35
+ operation = Dependabot::DependencyFile::Operation::DELETE if type == "D"
36
+ operation = Dependabot::DependencyFile::Operation::CREATE if type == "??"
31
37
  encoding = ""
32
- encoded_content = File.read(path) unless deleted
38
+ encoded_content = File.read(path) unless operation == Dependabot::DependencyFile::Operation::DELETE
33
39
  if binary_file?(path)
34
40
  encoding = Dependabot::DependencyFile::ContentEncoding::BASE64
35
- encoded_content = Base64.encode64(encoded_content) unless deleted
41
+ if operation != Dependabot::DependencyFile::Operation::DELETE
42
+ encoded_content = Base64.encode64(encoded_content)
43
+ end
36
44
  end
37
45
 
38
46
  project_root =
@@ -44,7 +52,7 @@ module Dependabot
44
52
  name: file_path.to_s,
45
53
  content: encoded_content,
46
54
  directory: base_directory,
47
- deleted: deleted,
55
+ operation: operation,
48
56
  content_encoding: encoding
49
57
  )
50
58
  end
@@ -177,7 +177,7 @@ module Dependabot
177
177
  sha: file.content
178
178
  }
179
179
  else
180
- content = if file.deleted?
180
+ content = if file.operation == Dependabot::DependencyFile::Operation::DELETE
181
181
  { sha: nil }
182
182
  elsif file.binary?
183
183
  sha = github_client_for_source.create_blob(
@@ -91,23 +91,26 @@ module Dependabot
91
91
  )
92
92
  end
93
93
 
94
+ # @param [DependencyFile] file
95
+ def file_action(file)
96
+ if file.operation == Dependabot::DependencyFile::Operation::DELETE
97
+ "delete"
98
+ elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
99
+ "create"
100
+ else
101
+ "update"
102
+ end
103
+ end
104
+
94
105
  def create_commit
95
106
  return create_submodule_update_commit if files.count == 1 && files.first.type == "submodule"
96
107
 
97
108
  actions = files.map do |file|
98
- if file.type == "symlink"
99
- {
100
- action: "update",
101
- file_path: file.symlink_target,
102
- content: file.content
103
- }
104
- else
105
- {
106
- action: "update",
107
- file_path: file.path,
108
- content: file.content
109
- }
110
- end
109
+ {
110
+ action: file_action(file),
111
+ file_path: file.type == "symlink" ? file.symlink_target : file.path,
112
+ content: file.content
113
+ }
111
114
  end
112
115
 
113
116
  gitlab_client_for_source.create_commit(
@@ -132,7 +132,7 @@ module Dependabot
132
132
  sha: file.content
133
133
  }
134
134
  else
135
- content = if file.deleted?
135
+ content = if file.operation == Dependabot::DependencyFile::Operation::DELETE
136
136
  { sha: nil }
137
137
  elsif file.binary?
138
138
  sha = github_client_for_source.create_blob(
@@ -62,10 +62,21 @@ module Dependabot
62
62
  gitlab_client_for_source.commit(source.repo, old_commit)
63
63
  end
64
64
 
65
+ # @param [DependencyFile] file
66
+ def file_action(file)
67
+ if file.operation == Dependabot::DependencyFile::Operation::DELETE
68
+ "delete"
69
+ elsif file.operation == Dependabot::DependencyFile::Operation::CREATE
70
+ "create"
71
+ else
72
+ "update"
73
+ end
74
+ end
75
+
65
76
  def create_commit
66
77
  actions = files.map do |file|
67
78
  {
68
- action: "update",
79
+ action: file_action(file),
69
80
  file_path: file.type == "symlink" ? file.symlink_target : file.path,
70
81
  content: file.content
71
82
  }
@@ -161,47 +161,21 @@ module Dependabot
161
161
  reset_global_git_config(backup_git_config_path)
162
162
  end
163
163
 
164
+ def self.credential_helper_path
165
+ File.join(__dir__, "../../bin/git-credential-store-immutable")
166
+ end
167
+
168
+ # rubocop:disable Metrics/AbcSize
169
+ # rubocop:disable Metrics/PerceivedComplexity
164
170
  def self.configure_git_to_use_https_with_credentials(credentials)
165
171
  File.open(GIT_CONFIG_GLOBAL_PATH, "w") do |file|
166
172
  file << "# Generated by dependabot/dependabot-core"
167
173
  end
168
- configure_git_to_use_https
169
- configure_git_credentials(credentials)
170
- end
171
-
172
- def self.configure_git_to_use_https
173
- # NOTE: we use --global here (rather than --system) so that Dependabot
174
- # can be run without privileged access
175
- run_shell_command(
176
- "git config --global --replace-all url.https://github.com/."\
177
- "insteadOf ssh://git@github.com/"
178
- )
179
- run_shell_command(
180
- "git config --global --add url.https://github.com/."\
181
- "insteadOf ssh://git@github.com:"
182
- )
183
- run_shell_command(
184
- "git config --global --add url.https://github.com/."\
185
- "insteadOf git@github.com:"
186
- )
187
- run_shell_command(
188
- "git config --global --add url.https://github.com/."\
189
- "insteadOf git@github.com/"
190
- )
191
- run_shell_command(
192
- "git config --global --add url.https://github.com/."\
193
- "insteadOf git://github.com/"
194
- )
195
- end
196
174
 
197
- # rubocop:disable Metrics/PerceivedComplexity
198
- def self.configure_git_credentials(credentials)
199
175
  # Then add a file-based credential store that loads a file in this repo.
200
176
  # Under the hood this uses git credential-store, but it's invoked through
201
177
  # a wrapper binary that only allows non-mutating commands. Without this,
202
178
  # whenever the credentials are deemed to be invalid, they're erased.
203
- credential_helper_path =
204
- File.join(__dir__, "../../bin/git-credential-store-immutable")
205
179
  run_shell_command(
206
180
  "git config --global credential.helper "\
207
181
  "'!#{credential_helper_path} --file #{Dir.pwd}/git.store'",
@@ -219,6 +193,9 @@ module Dependabot
219
193
  github_credentials.find { |c| !c["password"]&.start_with?("v1.") } ||
220
194
  github_credentials.first
221
195
 
196
+ # Make sure we always have https alternatives for github.com.
197
+ configure_git_to_use_https("github.com") if github_credential.nil?
198
+
222
199
  deduped_credentials = credentials -
223
200
  github_credentials +
224
201
  [github_credential].compact
@@ -234,13 +211,40 @@ module Dependabot
234
211
  "@#{cred.fetch('host')}"
235
212
 
236
213
  git_store_content += authenticated_url + "\n"
214
+ configure_git_to_use_https(cred.fetch("host"))
237
215
  end
238
216
 
239
217
  # Save the file
240
218
  File.write("git.store", git_store_content)
241
219
  end
220
+ # rubocop:enable Metrics/AbcSize
242
221
  # rubocop:enable Metrics/PerceivedComplexity
243
222
 
223
+ def self.configure_git_to_use_https(host)
224
+ # NOTE: we use --global here (rather than --system) so that Dependabot
225
+ # can be run without privileged access
226
+ run_shell_command(
227
+ "git config --global --replace-all url.https://#{host}/."\
228
+ "insteadOf ssh://git@#{host}/"
229
+ )
230
+ run_shell_command(
231
+ "git config --global --add url.https://#{host}/."\
232
+ "insteadOf ssh://git@#{host}:"
233
+ )
234
+ run_shell_command(
235
+ "git config --global --add url.https://#{host}/."\
236
+ "insteadOf git@#{host}:"
237
+ )
238
+ run_shell_command(
239
+ "git config --global --add url.https://#{host}/."\
240
+ "insteadOf git@#{host}/"
241
+ )
242
+ run_shell_command(
243
+ "git config --global --add url.https://#{host}/."\
244
+ "insteadOf git://#{host}/"
245
+ )
246
+ end
247
+
244
248
  def self.reset_git_repo(path)
245
249
  Dir.chdir(path) do
246
250
  run_shell_command("git reset HEAD --hard")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.139.1"
4
+ VERSION = "0.140.3"
5
5
  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.139.1
4
+ version: 0.140.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-04-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport