Skip to content

Commit

Permalink
Move update_asana_tasks_for_release into asana helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoy committed Oct 2, 2024
1 parent 197c534 commit 846484e
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require "fastlane/action"
require "fastlane_core/configuration/config_item"
require_relative "../helper/asana_helper"
require_relative "../helper/ddg_apple_automation_helper"
require_relative "../helper/git_helper"

Expand All @@ -10,10 +11,12 @@ def self.run(params)
Helper::GitHelper.setup_git_user
params[:platform] ||= Actions.lane_context[Actions::SharedValues::PLATFORM_NAME]
Helper::DdgAppleAutomationHelper.bump_version_and_build_number(params[:platform], params, other_action)

Helper::AsanaHelper.update_asana_tasks_for_release(options)
end

def self.description
"Bumps the project build number (and optionally sets a new version) and pushes the changes to the remote repository"
"Starts a new internal release"
end

def self.authors
Expand All @@ -25,8 +28,14 @@ def self.return_value
end

def self.details
# Optional:
""
<<-DETAILS
This action performs the following tasks:
* finds the git branch and Asana task for the current internal release,
* checks for are changes to the release branch,
* ensures that release notes aren't empty or placeholder,
* increments the project build number,
* pushes the changes to the remote repository.
DETAILS
end

def self.available_options
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,45 +43,7 @@ def self.run(params)
release_task_id = Helper::AsanaHelper.create_release_task(options[:platform], options[:version], options[:asana_user_id], options[:asana_access_token])
options[:release_task_id] = release_task_id

update_asana_tasks_for_release(options)
end

def self.update_asana_tasks_for_release(params)
UI.message("Checking latest public release in GitHub")
client = Octokit::Client.new(access_token: params[:github_token])
latest_public_release = client.latest_release(@constants[:repo_name])
UI.success("Latest public release: #{latest_public_release.tag_name}")

UI.message("Extracting task IDs from git log since #{latest_public_release.tag_name} release")
task_ids = Helper::AsanaHelper.get_task_ids_from_git_log(latest_public_release.tag_name)
UI.success("#{task_ids.count} task(s) found.")

UI.message("Fetching release notes from Asana release task (#{Helper::AsanaHelper.asana_task_url(params[:release_task_id])})")
release_notes = Helper::AsanaHelper.fetch_release_notes(params[:release_task_id], params[:asana_access_token])
UI.success("Release notes: #{release_notes}")

UI.message("Generating release task description using fetched release notes and task IDs")
html_notes = Helper::ReleaseTaskHelper.construct_release_task_description(release_notes, task_ids)

UI.message("Updating release task")
asana_client = Helper::AsanaHelper.make_asana_client(params[:asana_access_token])
asana_client.tasks.update_task(task_gid: params[:release_task_id], html_notes: html_notes)
UI.success("Release task content updated: #{Helper::AsanaHelper.asana_task_url(params[:release_task_id])}")

task_ids.append(params[:release_task_id])

UI.message("Moving tasks to Validation section")
Helper::AsanaHelper.move_tasks_to_section(task_ids, params[:validation_section_id], params[:asana_access_token])
UI.success("All tasks moved to Validation section")

tag_name = "#{@constants[:release_tag_prefix]}#{params[:version]}"
UI.message("Fetching or creating #{tag_name} Asana tag")
tag_id = Helper::AsanaHelper.find_or_create_asana_release_tag(tag_name, params[:release_task_id], params[:asana_access_token])
UI.success("#{tag_name} tag URL: #{Helper::AsanaHelper.asana_tag_url(tag_id)}")

UI.message("Tagging tasks with #{tag_name} tag")
Helper::AsanaHelper.tag_tasks(tag_id, task_ids, params[:asana_access_token])
UI.success("All tasks tagged with #{tag_name} tag")
Helper::AsanaHelper.update_asana_tasks_for_release(options)
end

def self.description
Expand Down
39 changes: 39 additions & 0 deletions lib/fastlane/plugin/ddg_apple_automation/helper/asana_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require "fastlane_core/ui/ui"
require "asana"
require "httparty"
require "octokit"
require_relative "ddg_apple_automation_helper"
require_relative "github_actions_helper"
require_relative "release_task_helper"
Expand Down Expand Up @@ -193,6 +194,44 @@ def self.create_release_task(platform, version, assignee_id, asana_access_token)
task_id
end

def self.update_asana_tasks_for_release(params)
UI.message("Checking latest public release in GitHub")
client = Octokit::Client.new(access_token: params[:github_token])
latest_public_release = client.latest_release(@constants[:repo_name])
UI.success("Latest public release: #{latest_public_release.tag_name}")

UI.message("Extracting task IDs from git log since #{latest_public_release.tag_name} release")
task_ids = get_task_ids_from_git_log(latest_public_release.tag_name)
UI.success("#{task_ids.count} task(s) found.")

UI.message("Fetching release notes from Asana release task (#{asana_task_url(params[:release_task_id])})")
release_notes = fetch_release_notes(params[:release_task_id], params[:asana_access_token])
UI.success("Release notes: #{release_notes}")

UI.message("Generating release task description using fetched release notes and task IDs")
html_notes = Helper::ReleaseTaskHelper.construct_release_task_description(release_notes, task_ids)

UI.message("Updating release task")
asana_client = make_asana_client(params[:asana_access_token])
asana_client.tasks.update_task(task_gid: params[:release_task_id], html_notes: html_notes)
UI.success("Release task content updated: #{asana_task_url(params[:release_task_id])}")

task_ids.append(params[:release_task_id])

UI.message("Moving tasks to Validation section")
move_tasks_to_section(task_ids, params[:validation_section_id], params[:asana_access_token])
UI.success("All tasks moved to Validation section")

tag_name = "#{@constants[:release_tag_prefix]}#{params[:version]}"
UI.message("Fetching or creating #{tag_name} Asana tag")
tag_id = find_or_create_asana_release_tag(tag_name, params[:release_task_id], params[:asana_access_token])
UI.success("#{tag_name} tag URL: #{asana_tag_url(tag_id)}")

UI.message("Tagging tasks with #{tag_name} tag")
tag_tasks(tag_id, task_ids, params[:asana_access_token])
UI.success("All tasks tagged with #{tag_name} tag")
end

def self.move_tasks_to_section(task_ids, section_id, asana_access_token)
asana_client = make_asana_client(asana_access_token)

Expand Down

0 comments on commit 846484e

Please sign in to comment.