diff --git a/updater/lib/dependabot/api_client.rb b/updater/lib/dependabot/api_client.rb index 10624f2dcbd..a458086a456 100644 --- a/updater/lib/dependabot/api_client.rb +++ b/updater/lib/dependabot/api_client.rb @@ -3,18 +3,31 @@ require "http" require "dependabot/job" +# Provides a client to access the internal Dependabot Service's API +# +# The Service acts as a relay to Core's GitHub API adapters while providing +# some co-ordination and enrichment functionality that is only relevant to +# the integrated service. +# +# This API is only available to Dependabot jobs being executed within our +# hosted infrastructure and is not open to integrators at this time. +# module Dependabot class ApiError < StandardError; end class ApiClient - # TODO: instantiate client with job_id? - def initialize(base_url, token) + def initialize(base_url, job_id, job_token) @base_url = base_url - @token = token + @job_id = job_id + @job_token = job_token end - def get_job(job_id) - response = fetch_job_details_from_backend(job_id) + # TODO: Remove + # + # We don't seem to use this anymore and always read the job description + # from the file system. + def fetch_job + response = fetch_job_details_from_backend # If the job has already been accessed then we can safely return quietly. # This happens when the backend isn't sure if the updater has enqueued a @@ -36,10 +49,10 @@ def get_job(job_id) :vendor_dependencies, :security_updates_only ) - Job.new(job_data.merge(token: token)) + Job.new(job_data.merge(token: job_token)) end - def create_pull_request(job_id, dependencies, updated_dependency_files, + def create_pull_request(dependencies, updated_dependency_files, base_commit_sha, pr_message) api_url = "#{base_url}/update_jobs/#{job_id}/create_pull_request" data = create_pull_request_data(dependencies, updated_dependency_files, base_commit_sha, pr_message) @@ -53,8 +66,8 @@ def create_pull_request(job_id, dependencies, updated_dependency_files, sleep(rand(3.0..10.0)) && retry end - def update_pull_request(job_id, dependencies, updated_dependency_files, - base_commit_sha) + # TODO: Determine if we should regenerate the PR message within core for updates + def update_pull_request(dependencies, updated_dependency_files, base_commit_sha) api_url = "#{base_url}/update_jobs/#{job_id}/update_pull_request" body = { data: { @@ -73,7 +86,7 @@ def update_pull_request(job_id, dependencies, updated_dependency_files, sleep(rand(3.0..10.0)) && retry end - def close_pull_request(job_id, dependency_name, reason) + def close_pull_request(dependency_name, reason) api_url = "#{base_url}/update_jobs/#{job_id}/close_pull_request" body = { data: { "dependency-names": dependency_name, reason: reason } } response = http_client.post(api_url, json: body) @@ -86,7 +99,7 @@ def close_pull_request(job_id, dependency_name, reason) sleep(rand(3.0..10.0)) && retry end - def record_update_job_error(job_id, error_type:, error_details:) + def record_update_job_error(error_type:, error_details:) api_url = "#{base_url}/update_jobs/#{job_id}/record_update_job_error" body = { data: { @@ -104,7 +117,7 @@ def record_update_job_error(job_id, error_type:, error_details:) sleep(rand(3.0..10.0)) && retry end - def mark_job_as_processed(job_id, base_commit_sha) + def mark_job_as_processed(base_commit_sha) api_url = "#{base_url}/update_jobs/#{job_id}/mark_as_processed" body = { data: { "base-commit-sha": base_commit_sha } } response = http_client.patch(api_url, json: body) @@ -117,7 +130,7 @@ def mark_job_as_processed(job_id, base_commit_sha) sleep(rand(3.0..10.0)) && retry end - def update_dependency_list(job_id, dependencies, dependency_files) + def update_dependency_list(dependencies, dependency_files) api_url = "#{base_url}/update_jobs/#{job_id}/update_dependency_list" body = { data: { @@ -135,7 +148,7 @@ def update_dependency_list(job_id, dependencies, dependency_files) sleep(rand(3.0..10.0)) && retry end - def record_package_manager_version(job_id, ecosystem, package_managers) + def record_package_manager_version(ecosystem, package_managers) api_url = "#{base_url}/update_jobs/#{job_id}/record_package_manager_version" body = { data: { @@ -155,10 +168,10 @@ def record_package_manager_version(job_id, ecosystem, package_managers) private - attr_reader :token, :base_url + attr_reader :base_url, :job_id, :job_token def http_client - client = HTTP.auth(token) + client = HTTP.auth(job_token) proxy = URI(base_url).find_proxy unless proxy.nil? args = [proxy.host, proxy.port, proxy.user, proxy.password].compact @@ -167,7 +180,7 @@ def http_client client end - def fetch_job_details_from_backend(job_id) + def fetch_job_details_from_backend api_url = "#{base_url}/update_jobs/#{job_id}" http_client.get(api_url) rescue HTTP::ConnectionError, OpenSSL::SSL::SSLError diff --git a/updater/lib/dependabot/base_command.rb b/updater/lib/dependabot/base_command.rb index cc40672cf41..42defb845a2 100644 --- a/updater/lib/dependabot/base_command.rb +++ b/updater/lib/dependabot/base_command.rb @@ -51,7 +51,7 @@ def run logger_info("Finished job processing") rescue StandardError => e handle_exception(e) - service.mark_job_as_processed(job_id, base_commit_sha) + service.mark_job_as_processed(base_commit_sha) ensure Dependabot.logger.info(service.summary) unless service.noop? raise Dependabot::RunFailure if Dependabot::Environment.github_actions? && service.failure? @@ -63,27 +63,23 @@ def handle_exception(err) Raven.capture_exception(err, raven_context) - service.record_update_job_error( - job_id, - error_type: "unknown_error", - error_details: { message: err.message } - ) - end - - def job_id - Environment.job_id + service.record_update_job_error(error_type: "unknown_error", error_details: { message: err.message }) end def api_url Environment.api_url end - def token - Environment.token + def job_id + Environment.job_id + end + + def job_token + Environment.job_token end def api_client - @api_client ||= Dependabot::ApiClient.new(api_url, token) + @api_client ||= Dependabot::ApiClient.new(api_url, job_id, job_token) end def service diff --git a/updater/lib/dependabot/environment.rb b/updater/lib/dependabot/environment.rb index 1f39759860e..9c7029839d2 100644 --- a/updater/lib/dependabot/environment.rb +++ b/updater/lib/dependabot/environment.rb @@ -6,8 +6,8 @@ def self.job_id @job_id ||= environment_variable("DEPENDABOT_JOB_ID") end - def self.token - @token ||= environment_variable("DEPENDABOT_JOB_TOKEN") + def self.job_token + @job_token ||= environment_variable("DEPENDABOT_JOB_TOKEN") end def self.api_url diff --git a/updater/lib/dependabot/file_fetcher_command.rb b/updater/lib/dependabot/file_fetcher_command.rb index 9712cf7a4f7..47e49e427b4 100644 --- a/updater/lib/dependabot/file_fetcher_command.rb +++ b/updater/lib/dependabot/file_fetcher_command.rb @@ -22,11 +22,7 @@ def perform_job raise "base commit SHA not found" unless @base_commit_sha version = file_fetcher.package_manager_version - unless version.nil? - api_client.record_package_manager_version( - Dependabot::Environment.job_id, version[:ecosystem], version[:package_managers] - ) - end + api_client.record_package_manager_version(version[:ecosystem], version[:package_managers]) unless version.nil? dependency_files rescue StandardError => e @@ -39,7 +35,7 @@ def perform_job logger_error("Error during file fetching; aborting") end handle_file_fetcher_error(e) - service.mark_job_as_processed(job_id, @base_commit_sha) + service.mark_job_as_processed(@base_commit_sha) return end @@ -191,7 +187,6 @@ def rate_limit_error_remaining(error) def record_error(error_details) service.record_update_job_error( - job_id, error_type: error_details.fetch(:"error-type"), error_details: error_details[:"error-detail"] ) diff --git a/updater/lib/dependabot/job.rb b/updater/lib/dependabot/job.rb index c5347d64acf..85dd0bba7dd 100644 --- a/updater/lib/dependabot/job.rb +++ b/updater/lib/dependabot/job.rb @@ -4,6 +4,16 @@ require "dependabot/source" require "wildcard_matcher" +# Describes a single Dependabot workload within the GitHub-integrated Service +# +# This primarily acts as a value class to hold inputs for various Core objects +# and is an approximate data structure for the 'job description file' used by +# the CLI tool. +# +# See: https://github.com/dependabot/cli#job-description-file +# +# This class should evenually be promoted to common/lib and augmented to +# validate job description files. module Dependabot class Job TOP_LEVEL_DEPENDENCY_TYPES = %w(direct production development).freeze diff --git a/updater/lib/dependabot/service.rb b/updater/lib/dependabot/service.rb index d79f977f075..d4c28eec3bb 100644 --- a/updater/lib/dependabot/service.rb +++ b/updater/lib/dependabot/service.rb @@ -17,26 +17,26 @@ def initialize(client:) @errors = [] end - def_delegators :client, :get_job, :mark_job_as_processed, :update_dependency_list, :record_package_manager_version + def_delegators :client, :fetch_job, :mark_job_as_processed, :update_dependency_list, :record_package_manager_version - def create_pull_request(job_id, dependencies, updated_dependency_files, base_commit_sha, pr_message) - client.create_pull_request(job_id, dependencies, updated_dependency_files, base_commit_sha, pr_message) + def create_pull_request(dependencies, updated_dependency_files, base_commit_sha, pr_message) + client.create_pull_request(dependencies, updated_dependency_files, base_commit_sha, pr_message) @pull_requests << [humanize(dependencies), :created] end - def update_pull_request(job_id, dependencies, updated_dependency_files, base_commit_sha) - client.update_pull_request(job_id, dependencies, updated_dependency_files, base_commit_sha) + def update_pull_request(dependencies, updated_dependency_files, base_commit_sha) + client.update_pull_request(dependencies, updated_dependency_files, base_commit_sha) @pull_requests << [humanize(dependencies), :updated] end - def close_pull_request(job_id, dependency_name, reason) - client.close_pull_request(job_id, dependency_name, reason) + def close_pull_request(dependency_name, reason) + client.close_pull_request(dependency_name, reason) @pull_requests << [dependency_name, "closed: #{reason}"] end - def record_update_job_error(job_id, error_type:, error_details:, dependency: nil) + def record_update_job_error(error_type:, error_details:, dependency: nil) @errors << [error_type.to_s, dependency] - client.record_update_job_error(job_id, error_type: error_type, error_details: error_details) + client.record_update_job_error(error_type: error_type, error_details: error_details) end def noop? diff --git a/updater/lib/dependabot/update_files_command.rb b/updater/lib/dependabot/update_files_command.rb index 72d7447c8c2..952b3b95191 100644 --- a/updater/lib/dependabot/update_files_command.rb +++ b/updater/lib/dependabot/update_files_command.rb @@ -16,7 +16,7 @@ def perform_job base_commit_sha: base_commit_sha ).run - service.mark_job_as_processed(job_id, base_commit_sha) + service.mark_job_as_processed(base_commit_sha) end def job diff --git a/updater/lib/dependabot/updater.rb b/updater/lib/dependabot/updater.rb index 4795464a2ed..cff941aef9b 100644 --- a/updater/lib/dependabot/updater.rb +++ b/updater/lib/dependabot/updater.rb @@ -746,7 +746,6 @@ def create_pull_request(dependencies, updated_dependency_files, pr_message) "pull request for creation") service.create_pull_request( - job_id, dependencies, updated_dependency_files.map(&:to_h), base_commit_sha, @@ -767,7 +766,6 @@ def update_pull_request(dependencies, updated_dependency_files) "pull request for update") service.update_pull_request( - job_id, dependencies, updated_dependency_files.map(&:to_h), base_commit_sha @@ -778,7 +776,7 @@ def close_pull_request(reason:) reason_string = reason.to_s.tr("_", " ") logger_info("Telling backend to close pull request for " \ "#{job.dependencies.join(', ')} - #{reason_string}") - service.close_pull_request(job_id, job.dependencies, reason) + service.close_pull_request(job.dependencies, reason) end # rubocop:disable Metrics/MethodLength @@ -978,7 +976,6 @@ def pr_message(dependencies, files) def update_dependency_list(dependencies) service.update_dependency_list( - job_id, dependencies.map do |dep| { name: dep.name, @@ -1016,7 +1013,6 @@ def log_prefix def record_error(error_details, dependency: nil) service.record_update_job_error( - job_id, error_type: error_details.fetch(:"error-type"), error_details: error_details[:"error-detail"], dependency: dependency diff --git a/updater/spec/dependabot/api_client_spec.rb b/updater/spec/dependabot/api_client_spec.rb index b8409a8112a..5db62b1c743 100644 --- a/updater/spec/dependabot/api_client_spec.rb +++ b/updater/spec/dependabot/api_client_spec.rb @@ -5,17 +5,17 @@ require "dependabot/api_client" RSpec.describe Dependabot::ApiClient do - subject(:client) { Dependabot::ApiClient.new("http://example.com", "token") } + subject(:client) { Dependabot::ApiClient.new("http://example.com", 1, "token") } let(:headers) { { "Content-Type" => "application/json" } } - describe "get_job" do + describe "fetch_job" do before do stub_request(:get, "http://example.com/update_jobs/1"). - to_return(body: fixture("get_job.json"), headers: headers) + to_return(body: fixture("fetch_job.json"), headers: headers) end it "hits the correct endpoint" do - client.get_job(1) + client.fetch_job expect(WebMock). to have_requested(:get, "http://example.com/update_jobs/1"). @@ -23,7 +23,7 @@ end it "returns a job" do - job = client.get_job(1) + job = client.fetch_job expect(job).to be_a(Dependabot::Job) end end @@ -61,7 +61,7 @@ end it "hits the correct endpoint" do - client.create_pull_request(1, [dependency], dependency_files, base_commit, message) + client.create_pull_request([dependency], dependency_files, base_commit, message) expect(WebMock). to have_requested(:post, create_pull_request_url). @@ -69,7 +69,7 @@ end it "does not send pull request message" do - client.create_pull_request(1, [dependency], dependency_files, base_commit, message) + client.create_pull_request([dependency], dependency_files, base_commit, message) expect(WebMock). to(have_requested(:post, create_pull_request_url). @@ -88,7 +88,7 @@ end it "encodes fields" do - client.create_pull_request(1, [dependency], dependency_files, base_commit, message) + client.create_pull_request([dependency], dependency_files, base_commit, message) expect(WebMock). to(have_requested(:post, create_pull_request_url). with(headers: { "Authorization" => "token" }). @@ -115,7 +115,7 @@ end it "encodes fields" do - client.create_pull_request(1, [removed_dependency, dependency], dependency_files, base_commit, message) + client.create_pull_request([removed_dependency, dependency], dependency_files, base_commit, message) expect(WebMock). to(have_requested(:post, create_pull_request_url). with(headers: { "Authorization" => "token" }). @@ -163,7 +163,7 @@ end it "hits the correct endpoint" do - client.update_pull_request(1, [dependency], dependency_files, base_commit) + client.update_pull_request([dependency], dependency_files, base_commit) expect(WebMock). to have_requested(:post, update_pull_request_url). @@ -183,7 +183,7 @@ end it "hits the correct endpoint" do - client.close_pull_request(1, dependency_name, :dependency_removed) + client.close_pull_request(dependency_name, :dependency_removed) expect(WebMock). to have_requested(:post, close_pull_request_url). @@ -199,7 +199,6 @@ it "hits the correct endpoint" do client.record_update_job_error( - 1, error_type: error_type, error_details: error_detail ) @@ -216,7 +215,7 @@ before { stub_request(:patch, url).to_return(status: 204) } it "hits the correct endpoint" do - client.mark_job_as_processed(1, base_commit) + client.mark_job_as_processed(base_commit) expect(WebMock). to have_requested(:patch, url). @@ -239,7 +238,7 @@ before { stub_request(:post, url).to_return(status: 204) } it "hits the correct endpoint" do - client.update_dependency_list(1, [dependency], ["Gemfile"]) + client.update_dependency_list([dependency], ["Gemfile"]) expect(WebMock). to have_requested(:post, url). @@ -253,7 +252,7 @@ it "hits the correct endpoint" do client.record_package_manager_version( - 1, "bundler", { "bundler" => "2" } + "bundler", { "bundler" => "2" } ) expect(WebMock). diff --git a/updater/spec/dependabot/file_fetcher_command_spec.rb b/updater/spec/dependabot/file_fetcher_command_spec.rb index 5f454614b30..00ecae53118 100644 --- a/updater/spec/dependabot/file_fetcher_command_spec.rb +++ b/updater/spec/dependabot/file_fetcher_command_spec.rb @@ -12,7 +12,7 @@ before do allow(job).to receive(:job_id).and_return(job_id) - allow(job).to receive(:token).and_return("job_token") + allow(job).to receive(:job_token).and_return("job_token") allow(job).to receive(:api_client).and_return(api_client) allow(api_client).to receive(:mark_job_as_processed) @@ -64,7 +64,6 @@ expect(api_client). to receive(:record_update_job_error). with( - job_id, error_details: { "branch-name": "my_branch" }, error_type: "branch_not_found" ) @@ -89,7 +88,6 @@ expect(api_client). to receive(:record_update_job_error). with( - job_id, error_details: {}, error_type: "job_repo_not_found" ) @@ -121,7 +119,6 @@ expect(api_client). to receive(:record_update_job_error). with( - job_id, error_details: { "rate-limit-reset": reset_at }, error_type: "octokit_rate_limited" ) @@ -185,7 +182,6 @@ expect(api_client). to receive(:record_update_job_error). with( - job_id, error_details: { "branch-name": "my_branch" }, error_type: "branch_not_found" ) @@ -206,7 +202,6 @@ expect(api_client). to receive(:record_update_job_error). with( - job_id, error_details: {}, error_type: "out_of_disk" ) diff --git a/updater/spec/dependabot/integration_spec.rb b/updater/spec/dependabot/integration_spec.rb index 8b01cd6bd4f..f181728af7a 100644 --- a/updater/spec/dependabot/integration_spec.rb +++ b/updater/spec/dependabot/integration_spec.rb @@ -74,7 +74,7 @@ File.join(Dir.mktmpdir("fetch"), "output.json"), File.join(Dir.mktmpdir("update"), "output.json") ) - allow(Dependabot::Environment).to receive(:token).and_return("token") + allow(Dependabot::Environment).to receive(:job_token).and_return("token") # Stub Dependabot object with instance doubles allow(Dependabot::ApiClient).to receive(:new).and_return(api_client) @@ -145,8 +145,7 @@ it "updates dependencies correctly" do expect(api_client). - to receive(:create_pull_request) do |id, deps, files, commit_sha| - expect(id).to eq(1) + to receive(:create_pull_request) do |deps, files, commit_sha| dep = Dependabot::Dependency.new( name: "dummy-pkg-b", package_manager: "bundler", @@ -212,7 +211,7 @@ it "notifies Dependabot API of the problem" do expect(api_client).to receive(:record_update_job_error). - with(job_id, { error_type: "unknown_error", error_details: nil }) + with({ error_type: "unknown_error", error_details: nil }) expect { run_job }.to output(/oh no!/).to_stdout_from_any_process end @@ -244,7 +243,6 @@ before do # Pre-populate an updater error update_files.service.record_update_job_error( - job_id, error_type: :epoch_error, error_details: { message: "What is fortran doing here?!" @@ -336,8 +334,7 @@ it "updates dependencies correctly" do expect(api_client). - to receive(:create_pull_request) do |id, deps, files, commit_sha| - expect(id).to eq(1) + to receive(:create_pull_request) do |deps, files, commit_sha| dep = Dependabot::Dependency.new( name: "dummy-git-dependency", package_manager: "bundler", diff --git a/updater/spec/dependabot/service_spec.rb b/updater/spec/dependabot/service_spec.rb index 907aa4dc561..a6c81c95f7f 100644 --- a/updater/spec/dependabot/service_spec.rb +++ b/updater/spec/dependabot/service_spec.rb @@ -5,11 +5,11 @@ require "dependabot/service" RSpec.describe Dependabot::Service do - let(:job_id) { 42 } let(:base_sha) { "mock-sha" } let(:mock_client) do instance_double(Dependabot::ApiClient, { + fetch_job: nil, create_pull_request: nil, update_pull_request: nil, close_pull_request: nil, @@ -56,7 +56,7 @@ end before do - service.create_pull_request(job_id, dependencies, dependency_files, base_sha, pr_message) + service.create_pull_request(dependencies, dependency_files, base_sha, pr_message) end end @@ -85,7 +85,7 @@ end before do - service.update_pull_request(job_id, dependencies, dependency_files, base_sha) + service.update_pull_request(dependencies, dependency_files, base_sha) end end @@ -94,14 +94,13 @@ let(:reason) { :dependency_removed } before do - service.close_pull_request(job_id, dependency_name, reason) + service.close_pull_request(dependency_name, reason) end end shared_context :an_error_was_reported do before do service.record_update_job_error( - job_id, error_type: :epoch_error, error_details: { message: "What is fortran doing here?!" @@ -128,7 +127,6 @@ before do service.record_update_job_error( - job_id, error_type: :unknown_error, error_details: { message: "0001 Undefined error. Inform Technical Support" @@ -140,10 +138,9 @@ describe "Instance methods delegated to @client" do { - get_job: "mock_job_id", - mark_job_as_processed: %w(mock_job_id mock_sha), - update_dependency_list: %w(mock_job_id mock_dependencies mock_dependency_file), - record_package_manager_version: %w(mock_job_id mock_ecosystem mock_package_managers) + mark_job_as_processed: %w(mock_sha), + update_dependency_list: %w(mock_dependencies mock_dependency_file), + record_package_manager_version: %w(mock_ecosystem mock_package_managers) }.each do |method, arguments| before { allow(mock_client).to receive(method) } @@ -153,6 +150,12 @@ expect(mock_client).to have_received(method).with(*arguments) end end + + it "delegates fetch_job" do + service.fetch_job + + expect(mock_client).to have_received(:fetch_job) + end end describe "#create_pull_request" do @@ -160,7 +163,7 @@ it "delegates to @client" do expect(mock_client). - to have_received(:create_pull_request).with(job_id, dependencies, dependency_files, base_sha, pr_message) + to have_received(:create_pull_request).with(dependencies, dependency_files, base_sha, pr_message) end it "memoizes a shorthand summary of the PR" do @@ -173,7 +176,7 @@ include_context :a_pr_was_updated it "delegates to @client" do - expect(mock_client).to have_received(:update_pull_request).with(job_id, dependencies, dependency_files, base_sha) + expect(mock_client).to have_received(:update_pull_request).with(dependencies, dependency_files, base_sha) end it "memoizes a shorthand summary of the PR" do @@ -185,7 +188,7 @@ include_context :a_pr_was_closed it "delegates to @client" do - expect(mock_client).to have_received(:close_pull_request).with(job_id, dependency_name, reason) + expect(mock_client).to have_received(:close_pull_request).with(dependency_name, reason) end it "memoizes a shorthand summary of the reason for closing PRs for a dependency" do @@ -198,7 +201,6 @@ it "delegates to @client" do expect(mock_client).to have_received(:record_update_job_error).with( - job_id, { error_type: :epoch_error, error_details: { @@ -220,7 +222,6 @@ it "is false if there has been an event" do service.record_update_job_error( - job_id, error_type: :epoch_error, error_details: { message: "What is fortran doing here?!" @@ -231,7 +232,7 @@ end it "is false if there has been a pull request change" do - service.close_pull_request(job_id, "dependabot-cobol", "legacy code removed") + service.close_pull_request("dependabot-cobol", "legacy code removed") expect(service).not_to be_failure end @@ -244,7 +245,6 @@ it "is true if there has been an error" do service.record_update_job_error( - job_id, error_type: :epoch_error, error_details: { message: "What is fortran doing here?!" diff --git a/updater/spec/dependabot/update_files_command_spec.rb b/updater/spec/dependabot/update_files_command_spec.rb index f8f4cfba495..5b26c1a7802 100644 --- a/updater/spec/dependabot/update_files_command_spec.rb +++ b/updater/spec/dependabot/update_files_command_spec.rb @@ -42,7 +42,7 @@ and_return(dummy_runner) expect(dummy_runner).to receive(:run) expect(service).to receive(:mark_job_as_processed). - with(job_id, base_commit_sha) + with(base_commit_sha) perform_job end @@ -68,7 +68,7 @@ and_return(dummy_runner) expect(dummy_runner).to receive(:run) expect(service).to receive(:mark_job_as_processed). - with(job_id, base_commit_sha) + with(base_commit_sha) perform_job end diff --git a/updater/spec/dependabot/updater_spec.rb b/updater/spec/dependabot/updater_spec.rb index 9b1f9ee8743..ed625ffaf9a 100644 --- a/updater/spec/dependabot/updater_spec.rb +++ b/updater/spec/dependabot/updater_spec.rb @@ -32,7 +32,6 @@ service = build_service(job: job) updater = build_updater(service: service, job: job) - job_id = 1 dependencies = [have_attributes(name: "dummy-pkg-b")] updated_dependency_files = [ { @@ -63,7 +62,7 @@ expect(service). to receive(:create_pull_request). - with(job_id, dependencies, updated_dependency_files, base_commit_sha, pr_message) + with(dependencies, updated_dependency_files, base_commit_sha, pr_message) updater.run end @@ -73,7 +72,6 @@ service = build_service(job: job) updater = build_updater(service: service, job: job) - job_id = 1 dependencies = [ { name: "dummy-pkg-a", @@ -103,7 +101,7 @@ dependency_files = ["/Gemfile", "/Gemfile.lock"] expect(service). - to receive(:update_dependency_list).with(job_id, dependencies, dependency_files) + to receive(:update_dependency_list).with(dependencies, dependency_files) updater.run end @@ -191,7 +189,7 @@ updater.run expect(service).to have_received(:record_update_job_error). - with(anything, { error_type: "out_of_disk", error_details: nil, dependency: nil }) + with({ error_type: "out_of_disk", error_details: nil, dependency: nil }) end end @@ -221,7 +219,6 @@ expect(service).to have_received(:record_update_job_error). with( - anything, { error_type: "octokit_rate_limited", error_details: { "rate-limit-reset": 42 }, @@ -337,7 +334,6 @@ expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error).with( - 1, { error_type: "dependency_file_not_supported", error_details: { @@ -412,7 +408,6 @@ expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error).with( - 1, { error_type: "security_update_not_possible", error_details: { @@ -466,7 +461,6 @@ expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error).with( - 1, { error_type: "security_update_not_possible", error_details: { @@ -509,7 +503,6 @@ expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error). with( - 1, error_type: "security_update_not_found", error_details: { "dependency-name": "dummy-pkg-b", @@ -1061,7 +1054,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error). with( - 1, error_type: "pull_request_exists_for_security_update", error_details: { "updated-dependencies": [ @@ -1108,7 +1100,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error). with( - 1, error_type: "pull_request_exists_for_latest_version", error_details: { "dependency-name": "dummy-pkg-b", @@ -1209,7 +1200,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error). with( - 1, error_type: "pull_request_exists_for_security_update", error_details: { "updated-dependencies": [ @@ -1602,7 +1592,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service).not_to receive(:create_pull_request) expect(service).to receive(:record_update_job_error).with( - 1, { error_type: "all_versions_ignored", error_details: { @@ -1641,7 +1630,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service).to_not receive(:create_pull_request) expect(service).to receive(:record_update_job_error).with( - 1, { error_type: "security_update_not_needed", error_details: { @@ -1698,7 +1686,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "unknown_error", error_details: nil, dependency: nil @@ -1741,7 +1728,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "dependency_file_not_found", error_details: { "file-path": "path/to/file" }, dependency: nil @@ -1784,7 +1770,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "branch_not_found", error_details: { "branch-name": "my_branch" }, dependency: nil @@ -1827,7 +1812,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "dependency_file_not_parseable", error_details: { "file-path": "path/to/file", message: "a" }, dependency: nil @@ -1870,7 +1854,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "path_dependencies_not_reachable", error_details: { dependencies: ["bad_gem"] }, dependency: nil @@ -1910,7 +1893,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "dependency_file_not_resolvable", error_details: { message: "message" }, dependency: an_instance_of(Dependabot::Dependency) @@ -1949,7 +1931,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "dependency_file_not_evaluatable", error_details: { message: "message" }, dependency: an_instance_of(Dependabot::Dependency) @@ -2020,7 +2001,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "git_dependencies_not_reachable", error_details: { "dependency-urls": ["https://example.com"] }, dependency: an_instance_of(Dependabot::Dependency) @@ -2059,7 +2039,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "git_dependency_reference_not_found", error_details: { dependency: "some_dep" }, dependency: an_instance_of(Dependabot::Dependency) @@ -2098,7 +2077,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "go_module_path_mismatch", error_details: { "declared-path": "foo", @@ -2141,7 +2119,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "private_source_authentication_failure", error_details: { source: "some.example.com" }, dependency: an_instance_of(Dependabot::Dependency) @@ -2169,7 +2146,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "unknown_error", error_details: nil, dependency: an_instance_of(Dependabot::Dependency) @@ -2227,7 +2203,6 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:record_update_job_error). with( - 1, error_type: "unknown_error", error_details: nil, dependency: an_instance_of(Dependabot::Dependency) @@ -2401,7 +2376,6 @@ def expect_update_checker_with_ignored_versions(versions) ] updater = build_updater(service: service, job: job, dependency_files: dependency_files) - job_id = 1 dependencies = [have_attributes(name: "dummy-pkg-b")] updated_dependency_files = [ { @@ -2432,7 +2406,7 @@ def expect_update_checker_with_ignored_versions(versions) expect(service). to receive(:create_pull_request). - with(job_id, dependencies, updated_dependency_files, base_commit_sha, pr_message) + with(dependencies, updated_dependency_files, base_commit_sha, pr_message) updater.run end @@ -2596,7 +2570,7 @@ def default_dependency_files def build_service(job: build_job) instance_double( Dependabot::Service, - get_job: job, + fetch_job: job, create_pull_request: nil, update_pull_request: nil, close_pull_request: nil, diff --git a/updater/spec/fixtures/get_job.json b/updater/spec/fixtures/fetch_job.json similarity index 100% rename from updater/spec/fixtures/get_job.json rename to updater/spec/fixtures/fetch_job.json