dependabot-common 0.162.2 → 0.165.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: c5598558127057abb7ac51f18576548e5589c52c07f6974029f07b0927c90940
4
- data.tar.gz: 05b6b1140a37903e10356ff60c0162ede9781a3ae7edbe32ab267ff46fe19542
3
+ metadata.gz: fded763414c9d5eec2fcdcbde94cc2f6feb6cc28218b4505ebd3a05250a02140
4
+ data.tar.gz: 405ae147644579eb70e84cb0dbf9a3bb9b27cfc5ed144597a08ad5286eb1925f
5
5
  SHA512:
6
- metadata.gz: a6aceab2e96e3cfb0ea5a7ca04cd55078935d5e23fb5490b3d0d777c354e3729484d105ffe2991438b3a9a76611cd843eaa38897e725575f6c8706bed84c62a1
7
- data.tar.gz: eb0e81e76203686073468c105bb67844f16a502814c12ff632e08c186b7a91b92f37247ed75e38e856492cb798fd9148af27eb6fcf975638548eca0470c07100
6
+ metadata.gz: 01aea5b71061b178a252555fa59f828d9f86a89d41d7d58e2a7d58c15cfae40a752eaf6f0858bb3b6e8dc5c224fc8b83c935e1dc3e7d264fab069d24244f6b64
7
+ data.tar.gz: 918375276fbc3ef7e735df189f1dfd9821f0473651959a0aad38a7932214f0fc02e0348139ae321c4944ea2ba6f0b7d013cb9ef7a054eb8373c0ab6a8f84cb9b
@@ -82,7 +82,7 @@ module Dependabot
82
82
  branch_name,
83
83
  source.branch || default_branch,
84
84
  pr_description,
85
- labeler&.labels_for_pr,
85
+ nil,
86
86
  work_item
87
87
  )
88
88
  end
@@ -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)[/:]
@@ -40,7 +49,7 @@ module Dependabot
40
49
  :hostname, :api_endpoint
41
50
 
42
51
  def self.from_url(url_string)
43
- return unless url_string&.match?(SOURCE_REGEX)
52
+ return github_enterprise_from_url(url_string) unless url_string&.match?(SOURCE_REGEX)
44
53
 
45
54
  captures = url_string.match(SOURCE_REGEX).named_captures
46
55
 
@@ -52,6 +61,33 @@ module Dependabot
52
61
  )
53
62
  end
54
63
 
64
+ def self.github_enterprise_from_url(url_string)
65
+ captures = url_string&.match(GITHUB_ENTERPRISE_SOURCE)&.named_captures
66
+ return unless captures
67
+
68
+ base_url = "https://#{captures.fetch('host')}"
69
+
70
+ return unless github_enterprise?(base_url)
71
+
72
+ new(
73
+ provider: "github",
74
+ repo: captures.fetch("repo"),
75
+ directory: captures.fetch("directory"),
76
+ branch: captures.fetch("branch"),
77
+ hostname: captures.fetch("host"),
78
+ api_endpoint: File.join(base_url, "api", "v3")
79
+ )
80
+ end
81
+
82
+ def self.github_enterprise?(base_url)
83
+ resp = Excon.get(File.join(base_url, "status"))
84
+ resp.status == 200 &&
85
+ # Alternatively: resp.headers["Server"] == "GitHub.com", but this
86
+ # currently doesn't work with development environments
87
+ resp.headers["X-GitHub-Request-Id"] &&
88
+ !resp.headers["X-GitHub-Request-Id"].empty?
89
+ end
90
+
55
91
  def initialize(provider:, repo:, directory: nil, branch: nil, commit: nil,
56
92
  hostname: nil, api_endpoint: nil)
57
93
  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.162.2"
4
+ VERSION = "0.165.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.162.2
4
+ version: 0.165.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-09-29 00:00:00.000000000 Z
11
+ date: 2021-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport