-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement asana_add_comment action (#5)
- Loading branch information
Showing
27 changed files
with
408 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
132 changes: 132 additions & 0 deletions
132
lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,132 @@ | ||
require "fastlane/action" | ||
require "fastlane_core/configuration/config_item" | ||
require "asana" | ||
require_relative "../helper/ddg_apple_automation_helper" | ||
require_relative "asana_extract_task_id_action" | ||
|
||
module Fastlane | ||
module Actions | ||
class AsanaAddCommentAction < Action | ||
def self.run(params) | ||
asana_access_token = params[:asana_access_token] | ||
task_id = params[:task_id] | ||
task_url = params[:task_url] | ||
template_name = params[:template_name] | ||
comment = params[:comment] | ||
workflow_url = params[:workflow_url] | ||
|
||
begin | ||
validate_params(task_id, task_url, comment, template_name, workflow_url) | ||
rescue ArgumentError => e | ||
UI.user_error!(e.message) | ||
return | ||
end | ||
|
||
task_id = Fastlane::Actions::AsanaExtractTaskIdAction.run(task_url: task_url) if task_url | ||
|
||
if template_name | ||
template_content = load_template_file(template_name) | ||
return unless template_content | ||
|
||
html_text = process_template_content(template_content) | ||
create_story(asana_access_token, task_id, html_text: html_text) | ||
else | ||
text = "#{comment}\n\nWorkflow URL: #{workflow_url}" | ||
create_story(asana_access_token, task_id, text: text) | ||
end | ||
end | ||
|
||
def self.description | ||
"Adds a comment to the Asana task" | ||
end | ||
|
||
def self.authors | ||
["DuckDuckGo"] | ||
end | ||
|
||
def self.return_value | ||
"" | ||
end | ||
|
||
def self.details | ||
# Optional: | ||
"" | ||
end | ||
|
||
def self.available_options | ||
[ | ||
FastlaneCore::ConfigItem.asana_access_token, | ||
FastlaneCore::ConfigItem.new(key: :task_id, | ||
description: "Asana task ID", | ||
optional: true, | ||
type: String), | ||
FastlaneCore::ConfigItem.new(key: :task_url, | ||
description: "Asana task URL", | ||
optional: true, | ||
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: :workflow_url, | ||
description: "Workflow URL to include in the comment", | ||
optional: true, | ||
type: String) | ||
] | ||
end | ||
|
||
def self.is_supported?(platform) | ||
true | ||
end | ||
|
||
def self.validate_params(task_id, task_url, comment, template_name, workflow_url) | ||
if task_id.to_s.empty? && task_url.to_s.empty? | ||
raise ArgumentError, "Both task_id and task_url cannot be empty. At least one must be provided." | ||
end | ||
|
||
if comment.to_s.empty? && template_name.to_s.empty? | ||
raise ArgumentError, "Both comment and template_name cannot be empty. At least one must be provided." | ||
end | ||
|
||
if comment && workflow_url.to_s.empty? | ||
raise ArgumentError, "If comment is provided, workflow_url cannot be empty" | ||
end | ||
end | ||
|
||
def self.load_template_file(template_name) | ||
template_file = Helper::DdgAppleAutomationHelper.path_for_asset_file("asana_add_comment/templates/#{template_name}.html") | ||
File.read(template_file) | ||
rescue StandardError | ||
UI.user_error!("Error: The file '#{template_name}.html' does not exist.") | ||
end | ||
|
||
def self.create_story(asana_access_token, task_id, text: nil, html_text: nil) | ||
client = Asana::Client.new do |c| | ||
c.authentication(:access_token, asana_access_token) | ||
end | ||
begin | ||
if text | ||
client.stories.create_story_for_task(task_gid: task_id, text: text) | ||
else | ||
client.stories.create_story_for_task(task_gid: task_id, html_text: html_text) | ||
end | ||
rescue StandardError => e | ||
UI.user_error!("Failed to post comment: #{e}") | ||
end | ||
end | ||
|
||
def self.process_template_content(template_content) | ||
template_content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } # replace environment variables | ||
.gsub(/\s+/, ' ') # replace multiple whitespaces with a single space | ||
.gsub(/>\s+</, '><') # remove spaces between HTML tags | ||
.strip # remove leading and trailing whitespaces | ||
.gsub(%r{<br\s*/?>}, "\n") # replace <br> tags with newlines | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
7 changes: 7 additions & 0 deletions
7
...plugin/ddg_apple_automation/assets/asana_add_comment/templates/appcast-failed-hotfix.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Publishing ${TAG} hotfix release to Sparkle failed</h2> | ||
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your | ||
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
7 changes: 7 additions & 0 deletions
7
...ugin/ddg_apple_automation/assets/asana_add_comment/templates/appcast-failed-internal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Publishing ${TAG} internal release to Sparkle failed</h2> | ||
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your | ||
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
7 changes: 7 additions & 0 deletions
7
...plugin/ddg_apple_automation/assets/asana_add_comment/templates/appcast-failed-public.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Publishing ${TAG} release to Sparkle failed</h2> | ||
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with generating appcast2.xml and uploading files to S3 from your | ||
local machine, <a data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
5 changes: 5 additions & 0 deletions
5
...lugin/ddg_apple_automation/assets/asana_add_comment/templates/debug-symbols-uploaded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<body> | ||
🐛 Debug symbols archive for ${TAG} build is uploaded to <code>${DSYM_S3_PATH}</code>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
5 changes: 5 additions & 0 deletions
5
...fastlane/plugin/ddg_apple_automation/assets/asana_add_comment/templates/dmg-uploaded.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<body> | ||
📥 DMG for ${TAG} is available from <a href='${DMG_URL}'>${DMG_URL}</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
9 changes: 9 additions & 0 deletions
9
...e/plugin/ddg_apple_automation/assets/asana_add_comment/templates/hotfix-branch-ready.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<body> | ||
<h2>Hotfix branch ${BRANCH} ready ⚙️</h2> | ||
<ul> | ||
<li>🔱 <code>${BRANCH}</code> branch has been created off <code>${RELEASE_TAG}</code> tag.</li> | ||
<li>Point any pull requests with changes required for the hotfix release to that branch.</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
8 changes: 8 additions & 0 deletions
8
...e_automation/assets/asana_add_comment/templates/internal-release-complete-with-tasks.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<body> | ||
Build ${TAG} is now available for internal testing through Sparkle and TestFlight.<br> | ||
<br> | ||
Added in this release: | ||
${TASKS_SINCE_LAST_INTERNAL_RELEASE}<br> | ||
<br> | ||
<a href='${DMG_URL}'>📥 DMG download link</a> | ||
</body> |
5 changes: 5 additions & 0 deletions
5
...in/ddg_apple_automation/assets/asana_add_comment/templates/internal-release-complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<body> | ||
Build ${TAG} is now available for internal testing through Sparkle and TestFlight.<br> | ||
<br> | ||
<a href='${DMG_URL}'>📥 DMG download link</a> | ||
</body> |
16 changes: 16 additions & 0 deletions
16
...le_automation/assets/asana_add_comment/templates/internal-release-ready-merge-failed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Internal release build ${TAG} ready</h2> | ||
<ul> | ||
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li> | ||
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li> | ||
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} pre-release</a> is created.</li> | ||
<li><b>❗️ Merging <code>${BRANCH}</code> to <code>${BASE_BRANCH}</code> failed.</b> | ||
<ul> | ||
<li><a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with manual merging <a data-asana-gid='${TASK_ID}' | ||
data-asana-dynamic='false'>according to instructions</a>.</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
13 changes: 13 additions & 0 deletions
13
...pple_automation/assets/asana_add_comment/templates/internal-release-ready-tag-failed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Internal release build ${TAG} ready</h2> | ||
<ul> | ||
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li> | ||
<li><b>❗️ Tagging repository failed.</b></li> | ||
<li><b>⚠️ GitHub release creation was skipped.</b></li> | ||
<li><b>⚠️ Merging <code>${BRANCH}</code> to <code>${BASE_BRANCH}</code> was skipped.</b></li> | ||
</ul> | ||
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with manual tagging and merging <a data-asana-gid='${TASK_ID}' | ||
data-asana-dynamic='false'>according to instructions</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
16 changes: 16 additions & 0 deletions
16
...lugin/ddg_apple_automation/assets/asana_add_comment/templates/internal-release-ready.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<body> | ||
<h2>Internal release build ${TAG} ready ✅</h2> | ||
<ul> | ||
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>. | ||
<ul> | ||
<li>If this is a subsequent internal release (started by calling <em>Bump Internal Release</em> workflow), the | ||
DMG will be automatically published to Sparkle in a few minutes. Sit tight.</li> | ||
</ul> | ||
</li> | ||
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li> | ||
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} pre-release</a> is created.</li> | ||
<li>🔱 <code>${BRANCH}</code> branch has been successfully merged to <code>${BASE_BRANCH}</code>.</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
5 changes: 5 additions & 0 deletions
5
...ugin/ddg_apple_automation/assets/asana_add_comment/templates/public-release-complete.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<body> | ||
Build ${TAG} is now available publicly through Sparkle and TestFlight.<br> | ||
<br> | ||
<a href='${DMG_URL}'>📥 DMG download link</a> | ||
</body> |
13 changes: 13 additions & 0 deletions
13
...in/ddg_apple_automation/assets/asana_add_comment/templates/public-release-tag-failed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Failed to publish ${TAG} release – tagging failed</h2> | ||
<ul> | ||
<li><b>❗️ Tagging repository with ${TAG} tag failed.</b></li> | ||
<li><b>⚠️ GitHub release creation was skipped.</b></li> | ||
<li><b>⚠️ Deleting <code>${BRANCH}</code> was skipped.</b></li> | ||
</ul> | ||
<br> | ||
<a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with the release <a data-asana-gid='${TASK_ID}' | ||
data-asana-dynamic='false'>according to instructions</a>.<br> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
15 changes: 15 additions & 0 deletions
15
...mation/assets/asana_add_comment/templates/public-release-tagged-delete-branch-failed.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<body> | ||
<h2>[ACTION NEEDED] Public release ${TAG} tagged</h2> | ||
<ul> | ||
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li> | ||
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} release</a> is created.</li> | ||
<li><b>❗️ Deleting <code>${BRANCH}</code> failed.</b> | ||
<ul> | ||
<li><a data-asana-gid='${ASSIGNEE_ID}' />, please proceed with deleting the branch manually <a | ||
data-asana-gid='${TASK_ID}' data-asana-dynamic='false'>according to instructions</a>.</li> | ||
</ul> | ||
</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
12 changes: 12 additions & 0 deletions
12
...plugin/ddg_apple_automation/assets/asana_add_comment/templates/public-release-tagged.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<body> | ||
<h2>Public release ${TAG} has been tagged ✅</h2> | ||
<ul> | ||
<li>📥 DMG is available from <a href='${DMG_URL}'>${DMG_URL}</a>.</li> | ||
<li>🏷️ Repository is tagged with <code>${TAG}</code> tag.</li> | ||
<li>🚢 GitHub <a href='${RELEASE_URL}'>${TAG} release</a> is created.</li> | ||
<li>🔱 <code>${BRANCH}</code> branch has been deleted.</li> | ||
<li>🚀 The relase will be published to Sparkle in a few minutes (you'll get notified).</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
10 changes: 10 additions & 0 deletions
10
...le_automation/assets/asana_add_comment/templates/validate-check-for-updates-internal.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<body> | ||
<h2>Build ${TAG} is available for internal testing through Sparkle 🚀</h2> | ||
<ul> | ||
<li>🌟 New appcast file has been generated and uploaded to S3, together with binary delta files.</li> | ||
<li>👀 <a data-asana-gid='${ASSIGNEE_ID}' />, please proceed by following instructions in <a | ||
data-asana-gid='${TASK_ID}' /> which concludes the internal release process.</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
11 changes: 11 additions & 0 deletions
11
...pple_automation/assets/asana_add_comment/templates/validate-check-for-updates-public.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<body> | ||
<h2>Build ${TAG} is available publicly through Sparkle 🚀</h2> | ||
<ul> | ||
<li>🌟 New appcast file has been generated and uploaded to S3, together with binary delta files.</li> | ||
<li>👀 <a data-asana-gid='${ASSIGNEE_ID}' />, please proceed by following instructions in <a | ||
data-asana-gid='${TASK_ID}' /> and <a data-asana-gid='${ANNOUNCEMENT_TASK_ID}' /> which concludes the release | ||
process.</li> | ||
</ul> | ||
<br> | ||
🔗 Workflow URL: <a href='${WORKFLOW_URL}'>${WORKFLOW_URL}</a>. | ||
</body> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
module Fastlane | ||
module DdgAppleAutomation | ||
VERSION = "0.5.0" | ||
VERSION = "0.6.0" | ||
end | ||
end |
Oops, something went wrong.