Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove the native go helper #5521

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@ updates:
directory: "/"
schedule:
interval: "weekly"
- package-ecosystem: "gomod"
directory: "/go_modules/helpers"
schedule:
interval: "weekly"
- package-ecosystem: "mix"
directory: "/hex/helpers"
schedule:
Expand Down
3 changes: 0 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -303,9 +303,6 @@ COPY --chown=dependabot:dependabot bundler/helpers /opt/bundler/helpers
RUN bash /opt/bundler/helpers/v1/build \
&& bash /opt/bundler/helpers/v2/build

COPY --chown=dependabot:dependabot go_modules/helpers /opt/go_modules/helpers
RUN bash /opt/go_modules/helpers/build

COPY --chown=dependabot:dependabot hex/helpers /opt/hex/helpers
ENV MIX_HOME="/opt/hex/mix"
# https://github.com/hexpm/hex/releases
Expand Down
1 change: 0 additions & 1 deletion bin/docker-dev-shell
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,6 @@ docker run --rm -ti \
-v "$(pwd)/go_modules/.rubocop.yml:$CODE_DIR/go_modules/.rubocop.yml" \
-v "$(pwd)/go_modules/Gemfile:$CODE_DIR/go_modules/Gemfile" \
-v "$(pwd)/go_modules/dependabot-go_modules.gemspec:$CODE_DIR/go_modules/dependabot-go_modules.gemspec" \
-v "$(pwd)/go_modules/helpers:$CODE_DIR/go_modules/helpers" \
-v "$(pwd)/go_modules/lib:$CODE_DIR/go_modules/lib" \
-v "$(pwd)/go_modules/spec:$CODE_DIR/go_modules/spec" \
-v "$(pwd)/go_modules/script:$CODE_DIR/go_modules/script" \
Expand Down
9 changes: 0 additions & 9 deletions go_modules/helpers/Makefile

This file was deleted.

28 changes: 0 additions & 28 deletions go_modules/helpers/build

This file was deleted.

5 changes: 0 additions & 5 deletions go_modules/helpers/go.mod

This file was deleted.

2 changes: 0 additions & 2 deletions go_modules/helpers/go.sum

This file was deleted.

34 changes: 0 additions & 34 deletions go_modules/helpers/importresolver/main.go

This file was deleted.

67 changes: 0 additions & 67 deletions go_modules/helpers/main.go

This file was deleted.

3 changes: 1 addition & 2 deletions go_modules/lib/dependabot/go_modules/metadata_finder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,7 @@ def look_up_source
return look_up_git_dependency_source if git_dependency?

path_str = (specified_source_string || dependency.name)
url = Dependabot::GoModules::PathConverter.
git_url_for_path_without_go_helper(path_str)
url = Dependabot::GoModules::PathConverter.git_url_for_path(path_str)
Source.from_url(url) if url
end

Expand Down
20 changes: 3 additions & 17 deletions go_modules/lib/dependabot/go_modules/path_converter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,8 @@
module Dependabot
module GoModules
module PathConverter
def self.git_url_for_path(path)
# Save a query by manually converting golang.org/x names
import_path = path.gsub(%r{^golang\.org/x}, "github.com/golang")

SharedHelpers.run_helper_subprocess(
command: NativeHelpers.helper_path,
function: "getVcsRemoteForImport",
args: { import: import_path }
)
end

# rubocop:disable Metrics/PerceivedComplexity
# Used in dependabot-backend, which doesn't have access to any Go
# helpers.
# TODO: remove the need for this.
def self.git_url_for_path_without_go_helper(path)
def self.git_url_for_path(path)
# Save a query by manually converting golang.org/x names
tmp_path = path.gsub(%r{^golang\.org/x}, "github.com/golang")

Expand Down Expand Up @@ -56,8 +42,8 @@ def self.git_url_for_path_without_go_helper(path)
# rubocop:enable Metrics/PerceivedComplexity

def self.fetch_path_metadata(path)
# TODO: This is not robust! Instead, we should shell out to Go and
# use https://github.com/Masterminds/vcs.
# TODO: update this comment to explain why it's leveraging the `go-get=1` trick
# and why may not be robust
response = Dependabot::RegistryClient.get(url: "https://#{path}?go-get=1")

return unless response.status == 200
Expand Down
68 changes: 25 additions & 43 deletions go_modules/spec/dependabot/go_modules/path_converter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,31 @@
it { is_expected.to eq("https://github.com/kubernetes/apimachinery") }
end

# TODO: Below was test case for ruby helper, above is test case for native go helper
# notice the extra fixture stubbing required for Ruby, figure out how robust this is...
#
# context "with a vanity URL that needs to be fetched" do
# let(:path) { "k8s.io/apimachinery" }

# before do
# stub_request(:get, "https://k8s.io/apimachinery?go-get=1").
# to_return(status: 200, body: vanity_response)
# end
# let(:vanity_response) do
# fixture("repo_responses", "k8s_io_apimachinery.html")
# end

# it { is_expected.to eq("https://github.com/kubernetes/apimachinery") }

# context "and returns a git source hosted with an unknown provider" do
# let(:vanity_response) do
# fixture("go", "repo_responses", "unknown_git_source.html")

# it { is_expected.to eq("https://sf.com/kubernetes/apimachinery") }
# end
# end
# end

xcontext "with a vanity URL that redirects" do
let(:path) { "code.cloudfoundry.org/bytefmt" }
it { is_expected.to eq("https://github.com/cloudfoundry/bytefmt") }
Expand All @@ -44,47 +69,4 @@
it { is_expected.to eq("https://github.com/drewolson/testflight") }
end
end

describe ".git_url_for_path_without_go_helper" do
subject { described_class.git_url_for_path_without_go_helper(path) }

let(:path) { "gopkg.in/guregu/null.v3" }

context "with a path that is immediately recognisable as a git source" do
let(:path) { "github.com/drewolson/testflight" }
it { is_expected.to eq("https://github.com/drewolson/testflight") }
end

context "with a golang.org path" do
let(:path) { "golang.org/x/tools" }
it { is_expected.to eq("https://github.com/golang/tools") }
end

context "with a path that ends in .git" do
let(:path) { "git.fd.io/govpp.git" }
it { is_expected.to eq("https://git.fd.io/govpp.git") }
end

context "with a vanity URL that needs to be fetched" do
let(:path) { "k8s.io/apimachinery" }

before do
stub_request(:get, "https://k8s.io/apimachinery?go-get=1").
to_return(status: 200, body: vanity_response)
end
let(:vanity_response) do
fixture("repo_responses", "k8s_io_apimachinery.html")
end

it { is_expected.to eq("https://github.com/kubernetes/apimachinery") }

context "and returns a git source hosted with an unknown provider" do
let(:vanity_response) do
fixture("go", "repo_responses", "unknown_git_source.html")

it { is_expected.to eq("https://sf.com/kubernetes/apimachinery") }
end
end
end
end
end