diff --git a/github_actions/lib/dependabot/github_actions/file_parser.rb b/github_actions/lib/dependabot/github_actions/file_parser.rb index 8f7a5bd5c2d..ca3de292272 100644 --- a/github_actions/lib/dependabot/github_actions/file_parser.rb +++ b/github_actions/lib/dependabot/github_actions/file_parser.rb @@ -55,7 +55,7 @@ def workfile_file_dependencies(file) def build_github_dependency(file, string) details = string.match(GITHUB_REPO_REFERENCE).named_captures name = "#{details.fetch('owner')}/#{details.fetch('repo')}" - url = "https://github.com/#{name}" + url = "https://#{source.hostname}/#{name}" ref = details.fetch("ref") version = version_class.new(ref).to_s if version_class.correct?(ref) diff --git a/github_actions/spec/dependabot/github_actions/file_parser_spec.rb b/github_actions/spec/dependabot/github_actions/file_parser_spec.rb index 78784c146ea..1afa2b235c0 100644 --- a/github_actions/spec/dependabot/github_actions/file_parser_spec.rb +++ b/github_actions/spec/dependabot/github_actions/file_parser_spec.rb @@ -202,5 +202,59 @@ end end end + + context "with a non-github.com source" do + let(:workflow_file_fixture_name) { "non_github_source.yml" } + let(:service_pack_url) do + "https://ghes.other.com/inactions/checkout.git/info/refs"\ + "?service=git-upload-pack" + end + let(:source) do + Dependabot::Source.new( + provider: "github", + repo: "gocardless/bump", + directory: "/", + hostname: "ghes.other.com", + api_endpoint: "https://ghes.other.com/api/v3" + ) + end + before do + stub_request(:get, service_pack_url). + to_return( + status: 200, + body: fixture("git", "upload_packs", "checkout"), + headers: { + "content-type" => "application/x-git-upload-pack-advertisement" + } + ) + end + + its(:length) { is_expected.to eq(1) } + + describe "the first dependency" do + subject(:dependency) { dependencies.first } + let(:expected_requirements) do + [{ + requirement: nil, + groups: [], + file: ".github/workflows/workflow.yml", + source: { + type: "git", + url: "https://ghes.other.com/inactions/checkout", + ref: "01aecccf739ca6ff86c0539fbc67a7a5007bbc81", + branch: nil + }, + metadata: { declaration_string: "inactions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81" } + }] + end + + it "has the right details" do + expect(dependency).to be_a(Dependabot::Dependency) + expect(dependency.name).to eq("inactions/checkout") + expect(dependency.version).to eq("2.1.0") + expect(dependency.requirements).to eq(expected_requirements) + end + end + end end end diff --git a/github_actions/spec/fixtures/workflow_files/non_github_source.yml b/github_actions/spec/fixtures/workflow_files/non_github_source.yml new file mode 100644 index 00000000000..8923197ec50 --- /dev/null +++ b/github_actions/spec/fixtures/workflow_files/non_github_source.yml @@ -0,0 +1,7 @@ +on: [push] + +name: Integration +jobs: + chore: + steps: + - uses: inactions/checkout@01aecccf739ca6ff86c0539fbc67a7a5007bbc81