File tree Expand file tree Collapse file tree
spec/dependabot/file_fetchers Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33module Dependabot
44 class DependabotError < StandardError ; end
55
6+ #####################
7+ # Repo leval errors #
8+ #####################
9+
10+ class BranchNotFound < DependabotError
11+ attr_reader :branch_name
12+
13+ def initialize ( branch_name , msg = nil )
14+ @branch_name = branch_name
15+ super ( msg )
16+ end
17+
18+ def file_name
19+ branch_name . split ( "/" ) . last
20+ end
21+
22+ def directory
23+ # Directory should always start with a `/`
24+ branch_name . split ( "/" ) [ 0 ..-2 ] . join ( "/" ) . sub ( %r{^/*} , "/" )
25+ end
26+ end
27+
628 #####################
729 # File level errors #
830 #####################
Original file line number Diff line number Diff line change @@ -48,6 +48,8 @@ def commit
4848 gitlab_client . branch ( repo , branch ) . commit . id
4949 else raise "Unsupported host '#{ host } '."
5050 end
51+ rescue Octokit ::NotFound
52+ raise Dependabot ::BranchNotFound , branch
5153 end
5254
5355 private
Original file line number Diff line number Diff line change @@ -77,6 +77,22 @@ def fetch_files
7777 end
7878
7979 it { is_expected . to eq ( "bb218f56b14c9653891f9e74264a383fa43fefbd" ) }
80+
81+ context "that can't be found" do
82+ before do
83+ stub_request ( :get , url + "/git/refs/heads/my_branch" ) .
84+ with ( headers : { "Authorization" => "token token" } ) .
85+ to_return ( status : 404 ,
86+ headers : { "content-type" => "application/json" } )
87+ end
88+
89+ it "raises a custom error" do
90+ expect { file_fetcher_instance . files } .
91+ to raise_error ( Dependabot ::BranchNotFound ) do |error |
92+ expect ( error . branch_name ) . to eq ( "my_branch" )
93+ end
94+ end
95+ end
8096 end
8197 end
8298
You can’t perform that action at this time.
0 commit comments