dependabot-common 0.140.0 → 0.140.1

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: 9891079fbe9ee6f09274dd3f72dd0c5c12b40a8685e3c0747bd92b4cc0ed259b
4
- data.tar.gz: 7e52789d37118447e73082cce5263693194cc70b56637495f6985f3266d166f1
3
+ metadata.gz: b3d8d2c38530262cc825130faa28497e3ce5eed2a6b6e2e53b573ebebf8852e6
4
+ data.tar.gz: 0ba1270c2b0f274ab20184bb504c9e109e2586ee8a6e1e959d1c5f9c3c665f61
5
5
  SHA512:
6
- metadata.gz: 8fc90ba04b2b77974f90d7a1d1917e4458038ea263f4c14270fa719e11979947a33e97cff980d19ed05b3d5dbff321e856bfb9717b175b2021e15cdc2c3d0445
7
- data.tar.gz: d9aa3ee0b1b0d292de592309981c5e9309579a3ce4caf1e8a509a0f9dfc9fc10934b12944977e8bc655f38f81334203c6e280a27e4392915503c0bb4bd756144
6
+ metadata.gz: 363e147e1bc8240fba5fb50afbe0b5fa3af4d8b195a621ecaac6de52eacf7df0c9cf0d589ea422a91d1428c9e5841882814e2c37ddeb98e553323123a99b0b2b
7
+ data.tar.gz: 0ac8544ba1909dab8c0cc47ec3c301b0066af52a2a0519a0697b4556a7715ed7510086f4b9ec787d88160abec8f2b49bc8051985c7e52fe0fb9e94f00de6f820
@@ -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
  }
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.140.0"
4
+ VERSION = "0.140.1"
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.140.0
4
+ version: 0.140.1
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-07 00:00:00.000000000 Z
11
+ date: 2021-04-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport