-
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
Implement asana_add_comment action #5
Conversation
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.
@jaceklyp this looks good overall! Just leaving some improvement ideas for now and will look at tests now.
lib/fastlane/plugin/ddg_apple_automation/actions/asana_add_comment_action.rb
Show resolved
Hide resolved
if task_id.nil? && task_url.nil? | ||
raise ArgumentError, "Both task_id and task_url cannot be nil. At least one must be provided." | ||
end | ||
|
||
if comment.nil? && template_name.nil? | ||
raise ArgumentError, "Both comment and template_name cannot be nil. At least one must be provided." | ||
end | ||
|
||
if comment && workflow_url.nil? | ||
raise ArgumentError, "If comment is provided, workflow_url cannot be nil" | ||
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.
We also don't want empty values, so please rewrite all .nil?
checks in this function as .to_s.empty?
(nil.to_s
equals ""
)
File.read(template_file) | ||
rescue StandardError | ||
UI.user_error!("Error: The file '#{template_name}.yml' does not exist.") | ||
nil |
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.
I don't think it's needed to explicitly return nil, but I may be wrong 🤷
processed_content = template_content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } | ||
processed_content.gsub(/\s*\n\s*/, ' ').strip |
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.
I think the following would be equivalent:
processed_content = template_content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } | |
processed_content.gsub(/\s*\n\s*/, ' ').strip | |
template_content.gsub(/\$\{(\w+)\}/) { ENV.fetch($1, '') } | |
.gsub(/\s*\n\s*/, ' ') | |
.strip |
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.
@jaceklyp overall looks great. Please address the comments and also add 1 more test that I've outlined in one of the comments. Thanks a lot!
@@ -8,6 +9,16 @@ module Helper | |||
class DdgAppleAutomationHelper | |||
ASANA_API_URL = "https://app.asana.com/api/1.0" | |||
ERROR_ASANA_ACCESS_TOKEN_NOT_SET = "ASANA_ACCESS_TOKEN is not set" | |||
|
|||
def self.load_asset_file(file) |
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.
Just a note that this isn't strictly "loading" the file, but only constructing file path. We could have loading here, in which case we need File.read
at the end, or we can keep it as is and rename to path_for_asset_file
for instance (?)
end | ||
end | ||
|
||
it "removes newlines and leading/trailing spaces" do |
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.
Could you add one more test similar to this one? It's about removing only 1 consecutive newline, i.e.
Hello\n \n World
should render
Hello\nWorld
(or something similar 🤪 but we have a bunch of templates that add 2 newlines to end up with 1 newline in Asana)
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.
LGTM, great job 💪
.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 |
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.
<3
Task URL: https://app.asana.com/0/1201392122292466/1208220385338233/f