Skip to content

Commit

Permalink
Add asana_extract_task_assignee action
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Aug 4, 2024
1 parent 6519224 commit ccea3f4
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 2 deletions.
2 changes: 2 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ gem 'rubocop-require_tools'
# SimpleCov is a code coverage analysis tool for Ruby.
gem 'simplecov'

gem 'httparty'

gemspec

plugins_path = File.join(File.dirname(__FILE__), 'fastlane', 'Pluginfile')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require "httparty"
require "json"
require_relative "../helper/ddg_release_automation_helper"
require_relative "../helper/github_actions_helper"

module Fastlane
module Actions
class AsanaExtractTaskAssigneeAction < Action
def self.run(params)
task_id = params[:task_id]
token = Helper::DdgReleaseAutomationHelper.fetch_asana_token
url = Helper::DdgReleaseAutomationHelper::ASANA_API_URL + "/tasks/#{task_id}?opt_fields=assignee"

response = HTTParty.get(url, headers: { 'Authorization' => "Bearer #{token}" })

if response.success?
assignee_id = response.parsed_response.dig('data', 'assignee', 'gid')
else
UI.user_error!("Failed to fetch task assignee: (#{response.code} #{response.message})")
end

if Helper.is_ci?
Helper::GitHubActionsHelper.set_output("asana_assignee_id", assignee_id)
end

assignee_id
end

def self.description
"This action checks Asana task assignee ID for a provided task ID"
end

def self.authors
["DuckDuckGo"]
end

def self.return_value
"The assignee ID extracted from the Asana task"
end

def self.details
# Optional:
""
end

def self.available_options
[
FastlaneCore::ConfigItem.new(key: :task_id,
description: "Asana task ID",
optional: false,
type: String)
]
end

def self.is_supported?(platform)
true
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def self.run(params)
task_id = match[1]

if Helper.is_ci?
Helper::GitHubActionsHelper.set_output("ASANA_TASK_ID", task_id)
Helper::GitHubActionsHelper.set_output("asana_task_id", task_id)
end

task_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,18 @@ class DdgReleaseAutomationHelper
# class methods that you define here become available in your action
# as `Helper::DdgReleaseAutomationHelper.your_method`
#

ASANA_API_URL = "https://app.asana.com/api/1.0"

def self.show_message
UI.message("Hello from the ddg_release_automation plugin helper!")
end

def self.fetch_asana_token
ENV.fetch("ASANA_ACCESS_TOKEN")
rescue KeyError
UI.user_error!("ASANA_ACCESS_TOKEN is not set")
end
end
end
end
2 changes: 1 addition & 1 deletion spec/asana_extract_task_id_action_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
allow(Fastlane::Helper::GitHubActionsHelper).to receive(:set_output)

expect(test_action("https://app.asana.com/0/12837864576817392/3465387322")).to eq("3465387322")
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("ASANA_TASK_ID", "3465387322")
expect(Fastlane::Helper::GitHubActionsHelper).to have_received(:set_output).with("asana_task_id", "3465387322")
end

it "fails when garbage is passed" do
Expand Down

0 comments on commit ccea3f4

Please sign in to comment.