Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add AsanaCreateActionItemAction #8

Merged
merged 22 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Update specs
  • Loading branch information
jaceklyp committed Sep 6, 2024
commit 8b724567388659f7ec02574f7dcd297bafcd2ebc
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "httparty"
require "json"
require "time"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/github_actions_helper"
Expand Down Expand Up @@ -33,7 +31,7 @@ def self.run(params)
return
end

automation_subtask_id = find_oldest_automation_subtask(subtasks).gid
automation_subtask_id = find_oldest_automation_subtask(subtasks)&.gid
Helper::GitHubActionsHelper.set_output("asana_automation_task_id", automation_subtask_id)
automation_subtask_id
end
Expand Down Expand Up @@ -70,14 +68,9 @@ def self.is_supported?(platform)
end

def self.find_oldest_automation_subtask(subtasks)
automation_subtask = subtasks
.find_all { |task| task.name == 'Automation' }
&.min_by { |task| Time.parse(task.created_at) }
if automation_subtask.nil?
UI.user_error!("There is no 'Automation' subtask in task: #{task_id}")
return
end
automation_subtask
subtasks
.find_all { |task| task.name == 'Automation' }
&.min_by { |task| Time.parse(task.created_at) }
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/asana_extract_task_assignee_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
describe "#run" do
before do
@asana_client_tasks = double
asana_client = double("Asana::Client")
asana_client = double("asana_client")
allow(Asana::Client).to receive(:new).and_return(asana_client)
allow(asana_client).to receive(:tasks).and_return(@asana_client_tasks)
allow(@asana_client_tasks).to receive(:get_task)
Expand All @@ -14,7 +14,7 @@
double(assignee: double(gid: "67890"))
)

expect(test_action("12345")).to eq("67890")

Check failure on line 17 in spec/asana_extract_task_assignee_action_spec.rb

View workflow job for this annotation

GitHub Actions / Test Report

./spec/asana_extract_task_assignee_action_spec.rb.Fastlane::Actions::AsanaExtractTaskAssigneeAction#run returns the assignee ID and sets GHA output when Asana task is assigned

#<Double (anonymous)> received unexpected message :[] with ("gid")
Raw output
Failure/Error: assignee_id = task.assignee["gid"]
  #<Double (anonymous)> received unexpected message :[] with ("gid")
./lib/fastlane/plugin/ddg_apple_automation/actions/asana_extract_task_assignee_action.rb:25:in `run'
./spec/asana_extract_task_assignee_action_spec.rb:38:in `test_action'
./spec/asana_extract_task_assignee_action_spec.rb:17:in `block (3 levels) in <top (required)>'
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("asana_assignee_id", "67890")
end

Expand All @@ -23,7 +23,7 @@
double(assignee: double(gid: nil))
)

expect(test_action("12345")).to eq(nil)

Check failure on line 26 in spec/asana_extract_task_assignee_action_spec.rb

View workflow job for this annotation

GitHub Actions / Test Report

./spec/asana_extract_task_assignee_action_spec.rb.Fastlane::Actions::AsanaExtractTaskAssigneeAction#run returns nil when Asana task is not assigned

#<Double (anonymous)> received unexpected message :[] with ("gid")
Raw output
Failure/Error: assignee_id = task.assignee["gid"]
  #<Double (anonymous)> received unexpected message :[] with ("gid")
./lib/fastlane/plugin/ddg_apple_automation/actions/asana_extract_task_assignee_action.rb:25:in `run'
./spec/asana_extract_task_assignee_action_spec.rb:38:in `test_action'
./spec/asana_extract_task_assignee_action_spec.rb:26:in `block (3 levels) in <top (required)>'
end

it "shows error when failed to fetch task assignee" do
Expand Down
2 changes: 1 addition & 1 deletion spec/asana_find_release_task_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,9 +141,9 @@ def validate_semver(version)
end

it "shows error" do
allow(Fastlane::UI).to receive(:user_error!)
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).not_to receive(:find_hotfix_task_in_response)
expect(Fastlane::Actions::AsanaFindReleaseTaskAction).not_to receive(:find_release_task_in_response)
allow(Fastlane::UI).to receive(:user_error!)

find_release_task("1.0.0")

Expand Down
85 changes: 19 additions & 66 deletions spec/asana_get_release_automation_subtask_id_action_spec.rb
Original file line number Diff line number Diff line change
@@ -1,88 +1,41 @@
describe Fastlane::Actions::AsanaGetReleaseAutomationSubtaskIdAction do
describe "#run" do
it "returns the 'Automation' subtask ID when it exists in the Asana task" do
before do
@asana_client_tasks = double
asana_client = double("asana_client")
allow(Asana::Client).to receive(:new).and_return(asana_client)
allow(asana_client).to receive(:tasks).and_return(@asana_client_tasks)
allow(@asana_client_tasks).to receive(:get_subtasks_for_task)
end
it "returns the 'Automation' subtask ID and sets GHA output when the subtask exists in the Asana task" do
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: true,
parsed_response: { 'data' => [
{ 'gid' => '12345', 'name' => 'Automation', 'created_at' => '2020-01-01T00:00:00.000Z' }
] }
)
expect(@asana_client_tasks).to receive(:get_subtasks_for_task).and_return(
[double(gid: "12345", name: "Automation", created_at: "2020-01-01T00:00:00.000Z")]
)

expect(test_action("https://app.asana.com/0/0/0")).to eq("12345")
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("asana_automation_task_id", "12345")
end

it "returns the oldest 'Automation' subtask when there are multiple subtasks with that name" do
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: true,
parsed_response: { 'data' => [
{ 'gid' => '12345', 'name' => 'Automation', 'created_at' => '2020-01-01T00:00:00.000Z' },
{ 'gid' => '431', 'name' => 'Automation', 'created_at' => '2019-01-01T00:00:00.000Z' },
{ 'gid' => '12460', 'name' => 'Automation', 'created_at' => '2020-01-05T00:00:00.000Z' }
] }
)
expect(@asana_client_tasks).to receive(:get_subtasks_for_task).and_return(
[double(gid: "12345", name: "Automation", created_at: "2020-01-01T00:00:00.000Z"),
double(gid: "431", name: "Automation", created_at: "2019-01-01T00:00:00.000Z"),
double(gid: "12460", name: "Automation", created_at: "2020-01-05T00:00:00.000Z")]
)

expect(test_action("https://app.asana.com/0/0/0")).to eq("431")
end

it "returns nil when 'Automation' subtask does not exist in the Asana task" do
allow(Fastlane::UI).to receive(:user_error!)
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: true,
parsed_response: { 'data' => [] }
)
)

expect(test_action("https://app.asana.com/0/0/0")).to eq(nil)
end

it "returns nil when response is empty" do
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: true,
parsed_response: {}
)
)

expect(test_action("https://app.asana.com/0/0/0")).to eq(nil)
end

it "shows error when failed to fetch task subtasks" do
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: false,
code: 401,
message: "Unauthorized"
)
)

expect(Fastlane::UI).to receive(:user_error!).with("Failed to fetch 'Automation' subtask: (401 Unauthorized)")
expect(@asana_client_tasks).to receive(:get_subtasks_for_task).and_raise(StandardError, "API error")

test_action("https://app.asana.com/0/0/0")
end

it "sets GHA output" do
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run)
expect(HTTParty).to receive(:get).and_return(
double(
success?: true,
parsed_response: { 'data' => [
{ 'gid' => '12345', 'name' => 'Automation', 'created_at' => '2020-01-01T00:00:00.000Z' }
] }
)
)

expect(test_action("https://app.asana.com/0/0/0")).to eq("12345")
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("asana_automation_task_id", "12345")
expect(Fastlane::UI).to have_received(:user_error!).with("Failed to fetch 'Automation' subtasks for task 0: API error")
end
end

Expand Down
Loading