|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +require 'spec_helper' |
| 4 | + |
| 5 | +describe Fastlane::Actions::CreateGithubReleaseAction do |
| 6 | + let(:test_token) { 'ghp_fake_token' } |
| 7 | + let(:test_repo) { 'repo-test/project-test' } |
| 8 | + let(:test_version) { '1.0.0' } |
| 9 | + let(:release_url) { 'https://github.com/repo-test/project-test/releases/tag/1.0.0' } |
| 10 | + let(:github_helper) { instance_double(Fastlane::Helper::GithubHelper) } |
| 11 | + |
| 12 | + before do |
| 13 | + allow(Fastlane::Helper::GithubHelper).to receive(:new).and_return(github_helper) |
| 14 | + end |
| 15 | + |
| 16 | + context 'when no release notes file is provided' do |
| 17 | + it 'creates the release with an empty description' do |
| 18 | + allow(github_helper).to receive(:create_release).with( |
| 19 | + repository: test_repo, |
| 20 | + version: test_version, |
| 21 | + name: nil, |
| 22 | + target: nil, |
| 23 | + description: '', |
| 24 | + assets: [], |
| 25 | + prerelease: false, |
| 26 | + is_draft: true |
| 27 | + ).and_return(release_url) |
| 28 | + |
| 29 | + result = run_described_fastlane_action( |
| 30 | + github_token: test_token, |
| 31 | + repository: test_repo, |
| 32 | + version: test_version, |
| 33 | + release_assets: [] |
| 34 | + ) |
| 35 | + |
| 36 | + expect(result).to eq(release_url) |
| 37 | + end |
| 38 | + end |
| 39 | + |
| 40 | + context 'when a release notes file is provided' do |
| 41 | + it 'rewrites bracketed GitHub PR and issue URLs to shorthand' do |
| 42 | + notes = <<~NOTES |
| 43 | + - Fix a thing [https://github.com/org-test/other-repo/pull/123] |
| 44 | + - Fix another thing [https://github.com/org-test/other-repo/issues/456] |
| 45 | + - Leave markdown links alone [as a link](https://github.com/org-test/other-repo/pull/789) |
| 46 | + NOTES |
| 47 | + |
| 48 | + expected_description = <<~NOTES |
| 49 | + - Fix a thing [org-test/other-repo#123] |
| 50 | + - Fix another thing [org-test/other-repo#456] |
| 51 | + - Leave markdown links alone [as a link](https://github.com/org-test/other-repo/pull/789) |
| 52 | + NOTES |
| 53 | + |
| 54 | + with_tmp_file(named: 'release-notes.txt', content: notes) do |notes_path| |
| 55 | + allow(github_helper).to receive(:create_release).with( |
| 56 | + repository: test_repo, |
| 57 | + version: test_version, |
| 58 | + name: nil, |
| 59 | + target: nil, |
| 60 | + description: expected_description, |
| 61 | + assets: [], |
| 62 | + prerelease: false, |
| 63 | + is_draft: true |
| 64 | + ).and_return(release_url) |
| 65 | + |
| 66 | + result = run_described_fastlane_action( |
| 67 | + github_token: test_token, |
| 68 | + repository: test_repo, |
| 69 | + version: test_version, |
| 70 | + release_assets: [], |
| 71 | + release_notes_file_path: notes_path |
| 72 | + ) |
| 73 | + |
| 74 | + expect(result).to eq(release_url) |
| 75 | + end |
| 76 | + end |
| 77 | + end |
| 78 | +end |
0 commit comments