Skip to content

Commit

Permalink
Remove the native go helper
Browse files Browse the repository at this point in the history
There are two functions that do the same thing, one in `ruby` and one in
`go`.

TODO explain why we had them both and why safe to remove the `go` one
once I finish researching it.

So I removed the one written in `go`.

It turns out this function was the only reason we had native `go`
helpers, so I was able to completely remove the helpers infra altogether.

Fix dependabot#4448
  • Loading branch information
jeffwidman committed Aug 12, 2022
1 parent 2cf754d commit 3f299d2
Show file tree
Hide file tree
Showing 12 changed files with 30 additions and 214 deletions.
4 changes: 0 additions & 4 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,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
2 changes: 0 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,6 @@ RUN DART_ARCH=${TARGETARCH} \
COPY --chown=dependabot:dependabot LICENSE /home/dependabot
COPY --chown=dependabot:dependabot composer/helpers /opt/composer/helpers
COPY --chown=dependabot:dependabot bundler/helpers /opt/bundler/helpers
COPY --chown=dependabot:dependabot go_modules/helpers /opt/go_modules/helpers
COPY --chown=dependabot:dependabot hex/helpers /opt/hex/helpers
COPY --chown=dependabot:dependabot pub/helpers /opt/pub/helpers
COPY --chown=dependabot:dependabot npm_and_yarn/helpers /opt/npm_and_yarn/helpers
Expand All @@ -282,7 +281,6 @@ RUN bash /opt/bundler/helpers/v1/build
RUN bash /opt/bundler/helpers/v2/build
RUN bash /opt/composer/helpers/v1/build
RUN bash /opt/composer/helpers/v2/build
RUN bash /opt/go_modules/helpers/build
RUN bash /opt/hex/helpers/build
RUN bash /opt/npm_and_yarn/helpers/build
RUN bash /opt/pub/helpers/build
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
69 changes: 26 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,32 @@
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 +70,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

0 comments on commit 3f299d2

Please sign in to comment.