Skip to content

Commit f210187

Browse files
Copilotrobaiken
andcommitted
Add support for *.MODULE.bazel files in file_fetcher
Co-authored-by: robaiken <6567647+robaiken@users.noreply.github.com>
1 parent 2bbd198 commit f210187

File tree

4 files changed

+95
-1
lines changed

4 files changed

+95
-1
lines changed

bazel/lib/dependabot/bazel/file_fetcher.rb

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ def self.required_files_message
2121

2222
sig { override.params(filenames: T::Array[String]).returns(T::Boolean) }
2323
def self.required_files_in?(filenames)
24-
filenames.any? { |name| WORKSPACE_FILES.include?(name) || MODULE_FILES.include?(name) }
24+
filenames.any? do |name|
25+
WORKSPACE_FILES.include?(name) || MODULE_FILES.include?(name) || name.end_with?(".MODULE.bazel")
26+
end
2527
end
2628

2729
sig { override.returns(T::Array[DependencyFile]) }
@@ -74,11 +76,22 @@ def workspace_files
7476
def module_files
7577
files = T.let([], T::Array[DependencyFile])
7678

79+
# Fetch explicit MODULE.bazel files
7780
MODULE_FILES.each do |filename|
7881
file = fetch_file_if_present(filename)
7982
files << file if file
8083
end
8184

85+
# Fetch all *.MODULE.bazel files
86+
repo_contents(raise_errors: false).each do |item|
87+
next unless item.type == "file"
88+
next unless item.name.end_with?(".MODULE.bazel")
89+
next if MODULE_FILES.include?(item.name) # Skip if already fetched
90+
91+
file = fetch_file_if_present(item.name)
92+
files << file if file
93+
end
94+
8295
files
8396
end
8497

bazel/spec/dependabot/bazel/file_fetcher_spec.rb

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@
5959
it { is_expected.to be(true) }
6060
end
6161

62+
context "with a *.MODULE.bazel file" do
63+
let(:filenames) { %w(deps.MODULE.bazel README.md) }
64+
65+
it { is_expected.to be(true) }
66+
end
67+
6268
context "without any Bazel files" do
6369
let(:filenames) { %w(README.md package.json) }
6470

@@ -115,6 +121,33 @@
115121
end
116122
end
117123

124+
context "with MODULE.bazel and *.MODULE.bazel files" do
125+
before do
126+
stub_request(:get, url + "?ref=sha")
127+
.to_return(
128+
status: 200,
129+
body: fixture("github", "contents_bazel_with_additional_module.json"),
130+
headers: { "content-type" => "application/json" }
131+
)
132+
stub_request(:get, url + "MODULE.bazel?ref=sha")
133+
.to_return(
134+
status: 200,
135+
body: fixture("github", "contents_bazel_module_file.json"),
136+
headers: { "content-type" => "application/json" }
137+
)
138+
stub_request(:get, url + "deps.MODULE.bazel?ref=sha")
139+
.to_return(
140+
status: 200,
141+
body: fixture("github", "contents_bazel_deps_module_file.json"),
142+
headers: { "content-type" => "application/json" }
143+
)
144+
end
145+
146+
it "fetches all MODULE.bazel files including *.MODULE.bazel files" do
147+
expect(fetched_files.map(&:name)).to include("MODULE.bazel", "deps.MODULE.bazel")
148+
end
149+
end
150+
118151
context "when beta ecosystems are not allowed" do
119152
before do
120153
allow(file_fetcher_instance).to receive(:allow_beta_ecosystems?).and_return(false)
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "deps.MODULE.bazel",
3+
"path": "deps.MODULE.bazel",
4+
"sha": "def456",
5+
"size": 567,
6+
"url": "https://api.github.com/repos/example/repo/contents/deps.MODULE.bazel?ref=sha",
7+
"html_url": "https://github.com/example/repo/blob/sha/deps.MODULE.bazel",
8+
"git_url": "https://api.github.com/repos/example/repo/git/blobs/def456",
9+
"download_url": "https://raw.githubusercontent.com/example/repo/sha/deps.MODULE.bazel",
10+
"type": "file",
11+
"content": "YmF6ZWxfZGVwKG5hbWUgPSAiZGVwcyIsIHZlcnNpb24gPSAiMS4wLjAiKQ==\n",
12+
"encoding": "base64"
13+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
[
2+
{
3+
"name": "MODULE.bazel",
4+
"path": "MODULE.bazel",
5+
"sha": "abc123",
6+
"size": 1234,
7+
"url": "https://api.github.com/repos/example/repo/contents/MODULE.bazel?ref=sha",
8+
"html_url": "https://github.com/example/repo/blob/sha/MODULE.bazel",
9+
"git_url": "https://api.github.com/repos/example/repo/git/blobs/abc123",
10+
"download_url": "https://raw.githubusercontent.com/example/repo/sha/MODULE.bazel",
11+
"type": "file"
12+
},
13+
{
14+
"name": "deps.MODULE.bazel",
15+
"path": "deps.MODULE.bazel",
16+
"sha": "def456",
17+
"size": 567,
18+
"url": "https://api.github.com/repos/example/repo/contents/deps.MODULE.bazel?ref=sha",
19+
"html_url": "https://github.com/example/repo/blob/sha/deps.MODULE.bazel",
20+
"git_url": "https://api.github.com/repos/example/repo/git/blobs/def456",
21+
"download_url": "https://raw.githubusercontent.com/example/repo/sha/deps.MODULE.bazel",
22+
"type": "file"
23+
},
24+
{
25+
"name": "README.md",
26+
"path": "README.md",
27+
"sha": "ghi789",
28+
"size": 890,
29+
"url": "https://api.github.com/repos/example/repo/contents/README.md?ref=sha",
30+
"html_url": "https://github.com/example/repo/blob/sha/README.md",
31+
"git_url": "https://api.github.com/repos/example/repo/git/blobs/ghi789",
32+
"download_url": "https://raw.githubusercontent.com/example/repo/sha/README.md",
33+
"type": "file"
34+
}
35+
]

0 commit comments

Comments
 (0)