Skip to content

Commit

Permalink
Refactor get release automation subtask id to use asana client
Browse files Browse the repository at this point in the history
  • Loading branch information
jaceklyp committed Sep 6, 2024
1 parent 188dfa6 commit 3a16944
Showing 1 changed file with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,20 @@ def self.run(params)
# TODO: To be reworked for local execution.
AsanaExtractTaskAssigneeAction.run(task_id: task_id, asana_access_token: token)

url = Helper::DdgAppleAutomationHelper::ASANA_API_URL + "/tasks/#{task_id}/subtasks?opt_fields=name,created_at"
response = HTTParty.get(url, headers: { 'Authorization' => "Bearer #{token}" })
asana_client = Asana::Client.new do |c|
c.authentication(:access_token, token)
end

if response.success?
automation_subtask_id = find_oldest_automation_subtask(response)
Helper::GitHubActionsHelper.set_output("asana_automation_task_id", automation_subtask_id)
automation_subtask_id
else
UI.user_error!("Failed to fetch 'Automation' subtask: (#{response.code} #{response.message})")
begin
subtasks = asana_client.tasks.get_subtasks_for_task(task_gid: task_id, opt_fields: ["name", "created_at"])
rescue StandardError => e
UI.user_error!("Failed to fetch 'Automation' subtasks for task #{task_id}: #{e}")
return
end

automation_subtask_id = find_oldest_automation_subtask(subtasks).gid
Helper::GitHubActionsHelper.set_output("asana_automation_task_id", automation_subtask_id)
automation_subtask_id
end

def self.description
Expand Down Expand Up @@ -65,11 +69,15 @@ def self.is_supported?(platform)
true
end

def self.find_oldest_automation_subtask(response)
response.parsed_response['data']
&.find_all { |hash| hash['name'] == 'Automation' }
&.min_by { |x| Time.parse(x['created_at']) } # Get the oldest 'Automation' subtask
&.dig('gid')
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
end
end
end
Expand Down

0 comments on commit 3a16944

Please sign in to comment.