-
Notifications
You must be signed in to change notification settings - Fork 1
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
Asana log message #6
Changes from 7 commits
7c24cea
91ae0b6
e28812f
5820c36
5942f55
ed36636
889e719
bf42f3f
7cfaca6
26a7cf6
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
require "fastlane/action" | ||
require "fastlane_core/configuration/config_item" | ||
require "asana" | ||
require_relative "../helper/ddg_apple_automation_helper" | ||
require_relative "asana_add_comment_action" | ||
require_relative "asana_get_release_automation_subtask_id_action" | ||
require_relative "asana_get_user_id_for_github_handle_action" | ||
require_relative "asana_extract_task_id_action" | ||
require_relative "asana_extract_task_assignee_action" | ||
|
||
module Fastlane | ||
module Actions | ||
class AsanaLogMessageAction < Action | ||
def self.run(params) | ||
token = params[:asana_access_token] | ||
task_url = params[:task_url] | ||
template_name = params[:template_name] | ||
comment = params[:comment] | ||
is_scheduled_release = params[:is_scheduled_release] || false | ||
github_handle = params[:github_handle] | ||
|
||
automation_subtask_id = AsanaGetReleaseAutomationSubtaskIdAction.run(task_url: task_url, asana_access_token: token) | ||
|
||
if is_scheduled_release | ||
task_id = AsanaExtractTaskIdAction.run(task_url: task_url) | ||
assignee_id = AsanaExtractTaskAssigneeAction.run(task_id: task_id, asana_access_token: token) | ||
else | ||
if github_handle.to_s.empty? | ||
UI.user_error!("Github handle cannot be empty for manual release") | ||
return | ||
end | ||
assignee_id = AsanaGetUserIdForGithubHandleAction.run(github_handle: github_handle, asana_access_token: token) | ||
end | ||
|
||
asana_client = Asana::Client.new do |c| | ||
c.authentication(:access_token, token) | ||
end | ||
|
||
begin | ||
asana_client.tasks.add_followers_for_task(task_gid: automation_subtask_id, followers: [assignee_id]) | ||
rescue StandardError => e | ||
UI.user_error!("Failed to add a collaborator to the release task: #{e}") | ||
end | ||
|
||
AsanaAddCommentAction.run(task_id: automation_subtask_id, comment: comment, template_name: template_name, asana_access_token: token) | ||
end | ||
|
||
def self.description | ||
"Add a Message to Asana Release Automation Task" | ||
end | ||
|
||
def self.authors | ||
["DuckDuckGo"] | ||
end | ||
|
||
def self.return_value | ||
"" | ||
end | ||
|
||
def self.details | ||
"Adds a comment about release progress to the Asana release task's 'Automation' subtask" | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.asana_access_token, | ||
FastlaneCore::ConfigItem.new(key: :task_url, | ||
description: "Asana release task URL", | ||
optional: false, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :comment, | ||
description: "Comment to add to the Asana task", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :template_name, | ||
description: "Name of a template file (without extension) for the comment. Templates can be found in assets/asana_add_comment/templates subdirectory. | ||
The file is processed before being sent to Asana", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :github_handle, | ||
description: "Github user handle", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :is_scheduled_release, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
description: "Indicates whether the release was scheduled or started manually", | ||
optional: true, | ||
type: Boolean) | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
true | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,12 @@ def self.asana_task_url(task_id) | |
def self.path_for_asset_file(file) | ||
File.expand_path("../assets/#{file}", __dir__) | ||
end | ||
|
||
def self.load_template_file(template_file) | ||
File.read(template_file) | ||
rescue StandardError | ||
UI.user_error!("Error: The file '#{template_file}' does not exist.") | ||
end | ||
Comment on lines
+26
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious if we's ever need to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. makes perfect sense, but let me do it in another PR today! |
||
end | ||
end | ||
end | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
describe Fastlane::Actions::AsanaLogMessageAction do | ||
describe "#run" do | ||
let(:task_url) { "https://example.com" } | ||
let(:task_id) { "1" } | ||
let(:automation_subtask_id) { "2" } | ||
let(:assignee_id) { "11" } | ||
let(:comment) { "comment" } | ||
let(:github_handle) { "user" } | ||
|
||
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(Fastlane::Actions::AsanaGetReleaseAutomationSubtaskIdAction).to receive(:run).and_return(automation_subtask_id) | ||
allow(Fastlane::Actions::AsanaExtractTaskIdAction).to receive(:run).and_return(task_id) | ||
allow(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run).and_return(assignee_id) | ||
allow(Fastlane::Actions::AsanaGetUserIdForGithubHandleAction).to receive(:run).and_return(assignee_id) | ||
allow(@asana_client_tasks).to receive(:add_followers_for_task) | ||
allow(Fastlane::Actions::AsanaAddCommentAction).to receive(:run) | ||
end | ||
|
||
it "does extract assignee id from release task when is scheduled release" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. extracts in place of does extract, maybe? |
||
expect(Fastlane::Actions::AsanaExtractTaskIdAction).to receive(:run).with(task_url: task_url) | ||
expect(Fastlane::Actions::AsanaExtractTaskAssigneeAction).to receive(:run).with( | ||
task_id: task_id, | ||
asana_access_token: anything | ||
) | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: true) | ||
end | ||
|
||
it "does takes assignee id from github handle when is manual release" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. s/does takes/takes/ |
||
expect(Fastlane::Actions::AsanaGetUserIdForGithubHandleAction).to receive(:run).with( | ||
github_handle: github_handle, | ||
asana_access_token: anything | ||
) | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: false, github_handle: github_handle) | ||
end | ||
|
||
it "raises an error when github handle is empty and is manual release" do | ||
expect(Fastlane::UI).to receive(:user_error!).with("Github handle cannot be empty for manual release") | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: false, github_handle: "") | ||
end | ||
|
||
it "adds a assignee as a follower to the automation task" do | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. adds an assignee as follower 😇 |
||
expect(@asana_client_tasks).to receive(:add_followers_for_task).with(task_gid: automation_subtask_id, followers: [assignee_id]) | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: false, github_handle: github_handle) | ||
end | ||
|
||
it "raises an error if adding a collaborator fails" do | ||
allow(Fastlane::UI).to receive(:user_error!) | ||
allow(@asana_client_tasks).to receive(:add_followers_for_task).and_raise(StandardError, 'some error') | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: false, github_handle: github_handle) | ||
expect(Fastlane::UI).to have_received(:user_error!).with("Failed to add a collaborator to the release task: some error") | ||
end | ||
|
||
it "adds a comment to the automation subtask" do | ||
expect(Fastlane::Actions::AsanaAddCommentAction).to receive(:run).with( | ||
task_id: automation_subtask_id, | ||
comment: comment, | ||
template_name: nil, | ||
asana_access_token: anything | ||
) | ||
test_action(task_url: task_url, comment: comment, is_scheduled_release: false, github_handle: github_handle) | ||
end | ||
end | ||
|
||
def test_action(task_url:, github_handle: nil, comment: nil, template_name: nil, is_scheduled_release: false) | ||
Fastlane::Actions::AsanaLogMessageAction.run(task_url: task_url, | ||
comment: comment, | ||
template_name: template_name, | ||
is_scheduled_release: is_scheduled_release, | ||
github_handle: github_handle) | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it's not the release task that the user is added to, but the 'Automation' subtask of a release task. How about the following? To allow easier debugging, perhaps.