dependabot-common 0.163.1 → 0.166.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: 0bd670e45c5c3fa9f949f99d323975f16c2f6d65750a4027de802d51caba995b
4
- data.tar.gz: f003a835d5f5e0875fbac29162dc3df96fd8fb963c691f5b3a9199e1dc25a246
3
+ metadata.gz: 8a3aea640c5c095314a2a681e4aa83144cfa3438f15ee84a7c6e71c551536b20
4
+ data.tar.gz: e7da1c50d04f2b84379b57e804702353e1d580718698e12a4ff9448a529dff8d
5
5
  SHA512:
6
- metadata.gz: 4da8363f3276ad3cedc91a9273f904e6b419ff012511290f49a3c5f64d34a82377f53a0b1abb90b7653fb1d323be249930b6986e8ba8fa1c104f4fa53082cc92
7
- data.tar.gz: 78e90b4e462daccab66e4374d5c27e0d4790332b199cd72732097bb08dcd8489a51cf6cddd89cff8458c8ea1416c6dde7104f7bc011e876ac23c5ecaf7471add
6
+ metadata.gz: 00ab9cb772d94a8f7d8ae82f0d0fff14d6167cbd8ef844fc698e5f81180b00f39cb3cd1dcd7dc4d74e9fb6f749def9a48ce5fdc797d0e93ab7891587735ca6c4
7
+ data.tar.gz: b847d1a4bbb1b8013caf86988a6e3e055df2294f773c3f2ef849b6a70b7f86ec90e62594e8d36195b01b13ff502206f20dbd730d7616e4b4d3f8eb20e903c642
@@ -10,25 +10,26 @@ module Dependabot
10
10
  attr_reader :source, :branch_name, :base_commit, :credentials,
11
11
  :files, :pr_description, :pr_name, :commit_message,
12
12
  :author_details, :labeler, :approvers, :assignees,
13
- :milestone
13
+ :milestone, :target_project_id
14
14
 
15
15
  def initialize(source:, branch_name:, base_commit:, credentials:,
16
16
  files:, commit_message:, pr_description:, pr_name:,
17
17
  author_details:, labeler:, approvers:, assignees:,
18
- milestone:)
19
- @source = source
20
- @branch_name = branch_name
21
- @base_commit = base_commit
22
- @credentials = credentials
23
- @files = files
24
- @commit_message = commit_message
25
- @pr_description = pr_description
26
- @pr_name = pr_name
27
- @author_details = author_details
28
- @labeler = labeler
29
- @approvers = approvers
30
- @assignees = assignees
31
- @milestone = milestone
18
+ milestone:, target_project_id:)
19
+ @source = source
20
+ @branch_name = branch_name
21
+ @base_commit = base_commit
22
+ @credentials = credentials
23
+ @files = files
24
+ @commit_message = commit_message
25
+ @pr_description = pr_description
26
+ @pr_name = pr_name
27
+ @author_details = author_details
28
+ @labeler = labeler
29
+ @approvers = approvers
30
+ @assignees = assignees
31
+ @milestone = milestone
32
+ @target_project_id = target_project_id
32
33
  end
33
34
 
34
35
  def create
@@ -76,7 +77,7 @@ module Dependabot
76
77
 
77
78
  def merge_request_exists?
78
79
  gitlab_client_for_source.merge_requests(
79
- source.repo,
80
+ target_project_id || source.repo,
80
81
  source_branch: branch_name,
81
82
  target_branch: source.branch || default_branch,
82
83
  state: "all"
@@ -143,7 +144,8 @@ module Dependabot
143
144
  remove_source_branch: true,
144
145
  assignee_ids: assignees,
145
146
  labels: labeler.labels_for_pr.join(","),
146
- milestone_id: milestone
147
+ milestone_id: milestone,
148
+ target_project_id: target_project_id
147
149
  )
148
150
  end
149
151
 
@@ -156,7 +158,7 @@ module Dependabot
156
158
  approvers.keys.map { |k| [k.to_sym, approvers[k]] }.to_h
157
159
 
158
160
  gitlab_client_for_source.edit_merge_request_approvers(
159
- source.repo,
161
+ target_project_id || source.repo,
160
162
  merge_request.iid,
161
163
  approver_ids: approvers_hash[:approvers],
162
164
  approver_group_ids: approvers_hash[:group_approvers]
@@ -157,7 +157,8 @@ module Dependabot
157
157
  labeler: labeler,
158
158
  approvers: reviewers,
159
159
  assignees: assignees,
160
- milestone: milestone
160
+ milestone: milestone,
161
+ target_project_id: provider_metadata[:target_project_id]
161
162
  )
162
163
  end
163
164
 
@@ -8,16 +8,17 @@ module Dependabot
8
8
  class PullRequestUpdater
9
9
  class Gitlab
10
10
  attr_reader :source, :files, :base_commit, :old_commit, :credentials,
11
- :pull_request_number
11
+ :pull_request_number, :target_project_id
12
12
 
13
13
  def initialize(source:, base_commit:, old_commit:, files:,
14
- credentials:, pull_request_number:)
14
+ credentials:, pull_request_number:, target_project_id:)
15
15
  @source = source
16
16
  @base_commit = base_commit
17
17
  @old_commit = old_commit
18
18
  @files = files
19
19
  @credentials = credentials
20
20
  @pull_request_number = pull_request_number
21
+ @target_project_id = target_project_id
21
22
  end
22
23
 
23
24
  def update
@@ -39,7 +40,7 @@ module Dependabot
39
40
 
40
41
  def merge_request
41
42
  @merge_request ||= gitlab_client_for_source.merge_request(
42
- source.repo,
43
+ target_project_id || source.repo,
43
44
  pull_request_number
44
45
  )
45
46
  end
@@ -9,11 +9,12 @@ module Dependabot
9
9
  class BranchProtected < StandardError; end
10
10
 
11
11
  attr_reader :source, :files, :base_commit, :old_commit, :credentials,
12
- :pull_request_number, :author_details, :signature_key
12
+ :pull_request_number, :author_details, :signature_key, :provider_metadata
13
13
 
14
14
  def initialize(source:, base_commit:, old_commit:, files:,
15
15
  credentials:, pull_request_number:,
16
- author_details: nil, signature_key: nil)
16
+ author_details: nil, signature_key: nil,
17
+ provider_metadata: {})
17
18
  @source = source
18
19
  @base_commit = base_commit
19
20
  @old_commit = old_commit
@@ -22,6 +23,7 @@ module Dependabot
22
23
  @pull_request_number = pull_request_number
23
24
  @author_details = author_details
24
25
  @signature_key = signature_key
26
+ @provider_metadata = provider_metadata
25
27
  end
26
28
 
27
29
  def update
@@ -55,7 +57,8 @@ module Dependabot
55
57
  old_commit: old_commit,
56
58
  files: files,
57
59
  credentials: credentials,
58
- pull_request_number: pull_request_number
60
+ pull_request_number: pull_request_number,
61
+ target_project_id: provider_metadata[:target_project_id]
59
62
  )
60
63
  end
61
64
 
@@ -40,10 +40,14 @@ module Dependabot
40
40
 
41
41
  def self.in_a_temporary_directory(directory = "/")
42
42
  Dir.mkdir(Utils::BUMP_TMP_DIR_PATH) unless Dir.exist?(Utils::BUMP_TMP_DIR_PATH)
43
- Dir.mktmpdir(Utils::BUMP_TMP_FILE_PREFIX, Utils::BUMP_TMP_DIR_PATH) do |dir|
44
- path = Pathname.new(File.join(dir, directory)).expand_path
43
+ tmp_dir = Dir.mktmpdir(Utils::BUMP_TMP_FILE_PREFIX, Utils::BUMP_TMP_DIR_PATH)
44
+
45
+ begin
46
+ path = Pathname.new(File.join(tmp_dir, directory)).expand_path
45
47
  FileUtils.mkpath(path)
46
48
  Dir.chdir(path) { yield(path) }
49
+ ensure
50
+ FileUtils.rm_rf(tmp_dir)
47
51
  end
48
52
  end
49
53
 
@@ -9,6 +9,15 @@ module Dependabot
9
9
  (?:(?:/tree|/blob)/(?<branch>[^/]+)/(?<directory>.*)[\#|/])?
10
10
  }x.freeze
11
11
 
12
+ GITHUB_ENTERPRISE_SOURCE = %r{
13
+ (?<protocol>(http://|https://|git://|ssh://))*
14
+ (?<username>[^@]+@)*
15
+ (?<host>[^/]+)
16
+ [/:]
17
+ (?<repo>[\w.-]+/(?:(?!\.git|\.\s)[\w.-])+)
18
+ (?:(?:/tree|/blob)/(?<branch>[^/]+)/(?<directory>.*)[\#|/])?
19
+ }x.freeze
20
+
12
21
  GITLAB_SOURCE = %r{
13
22
  (?<provider>gitlab)
14
23
  (?:\.com)[/:]
@@ -36,11 +45,13 @@ module Dependabot
36
45
  (?:#{AZURE_SOURCE})
37
46
  /x.freeze
38
47
 
48
+ IGNORED_PROVIDER_HOSTS = %w(gitbox.apache.org svn.apache.org).freeze
49
+
39
50
  attr_accessor :provider, :repo, :directory, :branch, :commit,
40
51
  :hostname, :api_endpoint
41
52
 
42
53
  def self.from_url(url_string)
43
- return unless url_string&.match?(SOURCE_REGEX)
54
+ return github_enterprise_from_url(url_string) unless url_string&.match?(SOURCE_REGEX)
44
55
 
45
56
  captures = url_string.match(SOURCE_REGEX).named_captures
46
57
 
@@ -52,6 +63,36 @@ module Dependabot
52
63
  )
53
64
  end
54
65
 
66
+ def self.github_enterprise_from_url(url_string)
67
+ captures = url_string&.match(GITHUB_ENTERPRISE_SOURCE)&.named_captures
68
+ return unless captures
69
+ return if IGNORED_PROVIDER_HOSTS.include?(captures.fetch("host"))
70
+
71
+ base_url = "https://#{captures.fetch('host')}"
72
+
73
+ return unless github_enterprise?(base_url)
74
+
75
+ new(
76
+ provider: "github",
77
+ repo: captures.fetch("repo"),
78
+ directory: captures.fetch("directory"),
79
+ branch: captures.fetch("branch"),
80
+ hostname: captures.fetch("host"),
81
+ api_endpoint: File.join(base_url, "api", "v3")
82
+ )
83
+ end
84
+
85
+ def self.github_enterprise?(base_url)
86
+ resp = Excon.get(File.join(base_url, "status"))
87
+ resp.status == 200 &&
88
+ # Alternatively: resp.headers["Server"] == "GitHub.com", but this
89
+ # currently doesn't work with development environments
90
+ resp.headers["X-GitHub-Request-Id"] &&
91
+ !resp.headers["X-GitHub-Request-Id"].empty?
92
+ rescue Excon::Error
93
+ false
94
+ end
95
+
55
96
  def initialize(provider:, repo:, directory: nil, branch: nil, commit: nil,
56
97
  hostname: nil, api_endpoint: nil)
57
98
  if (hostname.nil? ^ api_endpoint.nil?) && (provider != "codecommit")
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Dependabot
4
- VERSION = "0.163.1"
4
+ VERSION = "0.166.0"
5
5
  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.163.1
4
+ version: 0.166.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dependabot