@@ -640,12 +640,14 @@ def create_release(is_draft:, assets: [], name: nil)
640640
641641 before do
642642 allow ( Octokit ::Client ) . to receive ( :new ) . and_return ( client )
643+ allow ( client ) . to receive ( :release_for_tag ) . with ( test_repo , test_version ) . and_return ( release )
643644 allow ( client ) . to receive ( :releases ) . with ( test_repo ) . and_return ( [ release ] )
644645 allow ( client ) . to receive ( :release_assets ) . with ( release_url ) . and_return ( existing_assets )
645646 allow ( client ) . to receive_messages ( upload_asset : uploaded_asset , delete_release_asset : true )
646647 end
647648
648649 it 'fails clearly if the release does not exist' do
650+ allow ( client ) . to receive ( :release_for_tag ) . with ( test_repo , test_version ) . and_raise ( Octokit ::NotFound )
649651 allow ( client ) . to receive ( :releases ) . with ( test_repo ) . and_return ( [ ] )
650652
651653 with_tmp_file ( named : 'test-app.zip' ) do |file_path |
@@ -702,6 +704,7 @@ def create_release(is_draft:, assets: [], name: nil)
702704 draft_release = sawyer_resource_stub ( url : release_url , html_url : release_html_url , tag_name : test_version , draft : true )
703705 other_release = sawyer_resource_stub ( url : 'https://api.github.com/repos/repo-test/project-test/releases/456' , html_url : 'https://github.com/repo-test/project-test/releases/tag/0.9.0' , tag_name : '0.9.0' )
704706
707+ allow ( client ) . to receive ( :release_for_tag ) . with ( test_repo , test_version ) . and_raise ( Octokit ::NotFound )
705708 allow ( client ) . to receive ( :releases ) . with ( test_repo ) . and_return ( [ other_release , draft_release ] )
706709 allow ( client ) . to receive ( :release_assets ) . with ( release_url ) . and_return ( [ ] )
707710
@@ -714,6 +717,34 @@ def create_release(is_draft:, assets: [], name: nil)
714717 end
715718 end
716719
720+ it 'uses the release list without calling the direct release-by-tag lookup' do
721+ draft_release = sawyer_resource_stub ( url : 'draft-api-url' , html_url : 'draft-html-url' , tag_name : test_version , draft : true )
722+
723+ allow ( client ) . to receive ( :releases ) . with ( test_repo ) . and_return ( [ draft_release ] )
724+ expect ( client ) . not_to receive ( :release_for_tag )
725+ allow ( client ) . to receive ( :release_assets ) . with ( draft_release . url ) . and_return ( [ ] )
726+
727+ with_tmp_file ( named : 'test-app.zip' ) do |file_path |
728+ expect ( client ) . to receive ( :upload_asset ) . with ( draft_release . url , file_path , { content_type : 'application/octet-stream' } )
729+
730+ result = upload_release_assets ( assets : [ file_path ] )
731+
732+ expect ( result ) . to eq ( draft_release . html_url )
733+ end
734+ end
735+
736+ it 'falls back to the direct release-by-tag lookup when the release list misses' do
737+ with_tmp_file ( named : 'test-app.zip' ) do |file_path |
738+ allow ( client ) . to receive ( :releases ) . with ( test_repo ) . and_return ( [ ] )
739+ allow ( client ) . to receive ( :release_for_tag ) . with ( test_repo , test_version ) . and_return ( release )
740+ expect ( client ) . to receive ( :upload_asset ) . with ( release_url , file_path , { content_type : 'application/octet-stream' } )
741+
742+ result = upload_release_assets ( assets : [ file_path ] )
743+
744+ expect ( result ) . to eq ( release_html_url )
745+ end
746+ end
747+
717748 it 'uploads one asset to the existing release' do
718749 with_tmp_file ( named : 'test-app.zip' ) do |file_path |
719750 expect ( client ) . to receive ( :upload_asset ) . with ( release_url , file_path , { content_type : 'application/octet-stream' } )
0 commit comments