Skip to content

Commit 1a63e97

Browse files
committed
Filter out inaccessible tasks when constructing release notes
1 parent cbe1552 commit 1a63e97

3 files changed

Lines changed: 47 additions & 1 deletion

File tree

lib/fastlane/plugin/ddg_apple_automation/helper/asana_helper.rb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,7 @@ def self.update_asana_tasks_for_internal_release(params)
231231

232232
UI.message("Extracting task IDs from git log since #{latest_public_release.tag_name} release")
233233
task_ids = get_task_ids_from_git_log(latest_public_release.tag_name)
234+
.filter { |task_id| validate_task_accessible(task_id, params[:asana_access_token]) }
234235
UI.success("#{task_ids.count} task(s) found.")
235236

236237
UI.message("Fetching release notes from Asana release task (#{asana_task_url(params[:release_task_id])})")
@@ -428,6 +429,15 @@ def self.get_task_ids_from_git_log(from_ref, to_ref = "HEAD")
428429
.uniq
429430
end
430431

432+
def self.validate_task_accessible(task_id, asana_access_token)
433+
asana_client = make_asana_client(asana_access_token)
434+
asana_client.tasks.get_task(task_gid: task_id, options: { fields: ["gid"] })
435+
true
436+
rescue StandardError => e
437+
UI.important("Failed to fetch #{task_id}, ignoring. Error: #{e}")
438+
false
439+
end
440+
431441
def self.fetch_release_notes(release_task_id, asana_access_token, output_type: "asana")
432442
asana_client = make_asana_client(asana_access_token)
433443
release_task_body = asana_client.tasks.get_task(task_gid: release_task_id, options: { fields: ["notes"] }).notes
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Fastlane
22
module DdgAppleAutomation
3-
VERSION = "3.0.0"
3+
VERSION = "3.1.0"
44
end
55
end

spec/asana_helper_spec.rb

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,7 @@ def sanitize_asana_html_notes(content)
301301
expect(@client).to receive(:releases).with("iOS", { page: 1, per_page: 25 })
302302

303303
expect(Fastlane::Helper::AsanaHelper).to receive(:fetch_release_notes).with("1234567890", "secret-token")
304+
expect(Fastlane::Helper::AsanaHelper).to receive(:validate_task_accessible).with("1234567890", "secret-token").and_return(true)
304305
expect(Fastlane::Helper::ReleaseTaskHelper).to receive(:construct_release_task_description).with("Release notes content", ["1234567890"])
305306
expect(Fastlane::Helper::AsanaHelper).to receive(:move_tasks_to_section).with(["1234567890", "1234567890"], "987654321", "secret-token")
306307
expect(Fastlane::Helper::AsanaHelper).to receive(:tag_tasks).with("tag_id", ["1234567890", "1234567890"], "secret-token")
@@ -822,4 +823,39 @@ def sanitize_asana_html_notes(content)
822823
Fastlane::Helper::AsanaHelper.tag_tasks(tag_id, task_ids, asana_access_token)
823824
end
824825
end
826+
827+
describe ".validate_task_accessible" do
828+
subject { Fastlane::Helper::AsanaHelper.validate_task_accessible(task_id, asana_access_token) }
829+
830+
let(:task_id) { "1234567890" }
831+
let(:asana_access_token) { "secret-token" }
832+
833+
before do
834+
@asana_client = double("Asana::Client")
835+
allow(Fastlane::Helper::AsanaHelper).to receive(:make_asana_client).with(asana_access_token).and_return(@asana_client)
836+
allow(Fastlane::UI).to receive(:important)
837+
end
838+
839+
context "when the task is accessible" do
840+
before do
841+
allow(@asana_client).to receive_message_chain(:tasks, :get_task).and_return(double(gid: task_id))
842+
end
843+
844+
it "returns true" do
845+
expect(subject).to eq(true)
846+
expect(Fastlane::UI).not_to have_received(:important)
847+
end
848+
end
849+
850+
context "when the task is not accessible or fetching task data fails" do
851+
before do
852+
allow(@asana_client).to receive_message_chain(:tasks, :get_task).and_raise(StandardError, "API Error")
853+
end
854+
855+
it "returns false" do
856+
expect(subject).to be false
857+
expect(Fastlane::UI).to have_received(:important)
858+
end
859+
end
860+
end
825861
end

0 commit comments

Comments
 (0)