dependabot-common 0.139.2 → 0.141.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: 70a8b637aa9cd5c38c93bcdca2f8e26283e0bbb5bebc70f54bc1ce0f80a93e75
4
- data.tar.gz: 1aebc5329c67b401cc630c815bf6abf5bf6a63748e326255ebf37e58db52d256
3
+ metadata.gz: 1ce8c540f85d77f29a05217fa942c30ceccc1105dec78812b1955f6d047d6a4a
4
+ data.tar.gz: 79ddaca31b26a954a5174f36c796083545f9c96f7fad03d4cfe7cab7651755f3
5
5
  SHA512:
6
- metadata.gz: 75e1080fcf2a30249c962597e7fd09916584f8e4488702050dd8bbd775d2a1447c07ac09e1502f832f7e463b7c760a25e348397072f1b5273faf0dea40a8a79f
7
- data.tar.gz: 4e14c9377f28242dc67767004e210e30f1f1c185a6e3e5180222a0a80f2227c7995abbcd8b3b6232edb4fea3345e5a55a995a626df6dd05fdee672ac18258f26
6
+ metadata.gz: a187fd0a04b6ff8a59434e1a6864f23795696c6b37ce132572cc15346fa23abf3600eb8d69242a691909573e3315dc3d5229e780cb0adf93c980b8af146d3e51
7
+ data.tar.gz: 919ba7bb0228d961e109583c3f769def71feb1dc8bfcb9fd5a767c5eab91f969873ba88441932cced9f9d8ebf0ac0cf5f7f861b1ac12b32780b542a117aad6e9
@@ -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
  }
@@ -157,6 +157,8 @@ module Dependabot
157
157
  backup_git_config_path = stash_global_git_config
158
158
  configure_git_to_use_https_with_credentials(credentials)
159
159
  yield
160
+ rescue Errno::ENOSPC => e
161
+ raise Dependabot::OutOfDisk, e.message
160
162
  ensure
161
163
  reset_global_git_config(backup_git_config_path)
162
164
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.139.2"
4
+ VERSION = "0.141.0"
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.2
4
+ version: 0.141.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-04-06 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