Skip to content

Commit 5f4f38a

Browse files
authored
Add support for Asana V1 URLs (#36)
Task/Issue URL: https://app.asana.com/1/137249556945/project/1201899738287924/task/1209664522647706 Description: This change adds support for Asana V1 URLs.
1 parent 96984c8 commit 5f4f38a

3 files changed

Lines changed: 77 additions & 20 deletions

File tree

lib/fastlane/plugin/ddg_apple_automation/helper/asana_helper.rb

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,12 @@ class AsanaHelper # rubocop:disable Metrics/ClassLength
1515
ASANA_API_URL = "https://app.asana.com/api/1.0"
1616
ASANA_TASK_URL_TEMPLATE = "https://app.asana.com/0/0/%s/f"
1717
ASANA_TAG_URL_TEMPLATE = "https://app.asana.com/0/%s/list"
18-
ASANA_TASK_URL_REGEX = %r{https://app.asana.com/[0-9]/[0-9]+/([0-9]+)(:/f)?}
18+
19+
# https://app.asana.com/0/<project_id>/<task_id>
20+
ASANA_V0_TASK_URL_REGEX = %r{https://app.asana.com/0/[0-9]+/([0-9]+)(?:/f)?}
21+
# https://app.asana.com/<url_format_version>/<workspace_id>/<object_name>/<object_id>/<subobject_name>/<subobject_id>
22+
ASANA_V1_TASK_URL_REGEX = %r{https://app.asana.com/1/[0-9]+(?:/[0-9a-z/]*)?/task/([0-9]+)(:?/[0-9a-z/]*)?(?:\?focus=true)?}
23+
1924
ASANA_WORKSPACE_ID = "137249556945"
2025

2126
IOS_HOTFIX_TASK_TEMPLATE_ID = "1209242676101485"
@@ -53,14 +58,14 @@ def self.asana_tag_url(tag_id)
5358
end
5459

5560
def self.extract_asana_task_id(task_url, set_gha_output: true)
56-
if (match = task_url.match(ASANA_TASK_URL_REGEX))
61+
if (match = task_url.match(ASANA_V0_TASK_URL_REGEX)) || (match = task_url.match(ASANA_V1_TASK_URL_REGEX))
5762
task_id = match[1]
5863
if set_gha_output
5964
Helper::GitHubActionsHelper.set_output("asana_task_id", task_id)
6065
end
6166
task_id
6267
else
63-
UI.user_error!("URL has incorrect format (attempted to match #{ASANA_TASK_URL_REGEX})")
68+
UI.user_error!("URL has incorrect format (attempted to match #{ASANA_V0_TASK_URL_REGEX} or #{ASANA_V1_TASK_URL_REGEX})")
6469
end
6570
end
6671

@@ -416,7 +421,7 @@ def self.get_task_ids_from_git_log(from_ref, to_ref = "HEAD")
416421

417422
git_log
418423
.gsub("\n", " ")
419-
.scan(%r{\bTask/Issue URL:\s*https://app\.asana\.com[/0-9f]+\b})
424+
.scan(%r{\bTask/Issue URL:\s*https://app\.asana\.com[/0-9a-z]+\b})
420425
.map { |task_line| task_line.gsub(/.*(https.*)/, '\1') }
421426
.map { |task_url| extract_asana_task_id(task_url, set_gha_output: false) }
422427
.uniq
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module Fastlane
22
module DdgAppleAutomation
3-
VERSION = "2.0.2"
3+
VERSION = "2.1.0"
44
end
55
end

spec/asana_helper_spec.rb

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,44 @@ def asana_task_url(task_id)
1717
end
1818

1919
describe "#extract_asana_task_id" do
20-
it "extracts task ID" do
21-
expect(extract_asana_task_id("https://app.asana.com/0/0/0")).to eq("0")
22-
end
20+
context "v0 task URL" do
21+
it "extracts task ID" do
22+
expect(extract_asana_task_id("https://app.asana.com/0/0/0")).to eq("0")
23+
end
2324

24-
it "extracts task ID when project ID is non-zero" do
25-
expect(extract_asana_task_id("https://app.asana.com/0/753241/9999")).to eq("9999")
26-
end
25+
it "extracts task ID when project ID is non-zero" do
26+
expect(extract_asana_task_id("https://app.asana.com/0/753241/9999")).to eq("9999")
27+
end
2728

28-
it "extracts task ID when first digit is non-zero" do
29-
expect(extract_asana_task_id("https://app.asana.com/4/753241/9999")).to eq("9999")
30-
end
29+
it "extracts long task ID" do
30+
expect(extract_asana_task_id("https://app.asana.com/0/0/12837864576817392")).to eq("12837864576817392")
31+
end
3132

32-
it "extracts long task ID" do
33-
expect(extract_asana_task_id("https://app.asana.com/0/0/12837864576817392")).to eq("12837864576817392")
33+
it "extracts task ID from a URL in focused mode" do
34+
expect(extract_asana_task_id("https://app.asana.com/0/0/1234/f")).to eq("1234")
35+
end
3436
end
3537

36-
it "extracts task ID from a URL with a trailing /f" do
37-
expect(extract_asana_task_id("https://app.asana.com/0/0/1234/f")).to eq("1234")
38+
context "v1 task URL" do
39+
it "extracts task ID" do
40+
expect(extract_asana_task_id("https://app.asana.com/1/1234/project/5678/task/9999")).to eq("9999")
41+
end
42+
43+
it "extracts task ID when subtask is present" do
44+
expect(extract_asana_task_id("https://app.asana.com/1/1234/project/5678/task/9999/subtask/0001")).to eq("9999")
45+
end
46+
47+
it "extracts task ID when project is missing in the URL" do
48+
expect(extract_asana_task_id("https://app.asana.com/1/1234/task/9999")).to eq("9999")
49+
end
50+
51+
it "extracts long task ID" do
52+
expect(extract_asana_task_id("https://app.asana.com/1/1234/task/12837864576817392")).to eq("12837864576817392")
53+
end
54+
55+
it "extracts task ID from a URL in focused mode" do
56+
expect(extract_asana_task_id("https://app.asana.com/1/1234/project/5678/task/9999?focused=true")).to eq("9999")
57+
end
3858
end
3959

4060
it "sets GHA output" do
@@ -46,7 +66,7 @@ def asana_task_url(task_id)
4666

4767
it "fails when garbage is passed" do
4868
expect(Fastlane::UI).to receive(:user_error!)
49-
.with("URL has incorrect format (attempted to match #{Fastlane::Helper::AsanaHelper::ASANA_TASK_URL_REGEX})")
69+
.with("URL has incorrect format (attempted to match #{Fastlane::Helper::AsanaHelper::ASANA_V0_TASK_URL_REGEX} or #{Fastlane::Helper::AsanaHelper::ASANA_V1_TASK_URL_REGEX})")
5070

5171
extract_asana_task_id("not a URL")
5272
end
@@ -556,6 +576,30 @@ def sanitize_asana_html_notes(content)
556576
#{' '}
557577
Task/Issue URL: https://app.asana.com/0/1202406491309510/1208589738926535/f
558578
579+
commit 7202ff2597d21db57fd6dc9a295e11991c81b3e7
580+
581+
Hide continue setup cards after 1 week (#3471)
582+
#{' '}
583+
Task/Issue URL: https://app.asana.com/1/1552213/task/1208589738999999
584+
585+
commit 7202ff2597d21db57fd6dc9a295e11991c81b3e7
586+
587+
Hide continue setup cards after 1 week (#3471)
588+
#{' '}
589+
Task/Issue URL: https://app.asana.com/1/1552213/task/1208589738888888?focus=true
590+
591+
commit 7202ff2597d21db57fd6dc9a295e11991c81b3e7
592+
593+
Hide continue setup cards after 1 week (#3471)
594+
#{' '}
595+
Task/Issue URL: https://app.asana.com/1/1552213/project/123/task/1208589738777777?focus=true
596+
597+
commit 7202ff2597d21db57fd6dc9a295e11991c81b3e7
598+
599+
Hide continue setup cards after 1 week (#3471)
600+
#{' '}
601+
Task/Issue URL: https://app.asana.com/1/1552213/project/123/task/1208589738666666/subtask/527?focus=true
602+
559603
commit e83fd007c0bdf054658068a79f5b7ea45d846468
560604
561605
Receive privacy config updates in AddressBarModel on main thread (#3574)
@@ -593,7 +637,15 @@ def sanitize_asana_html_notes(content)
593637
allow(Fastlane::Helper::AsanaHelper).to receive(:`).with("git log v1.0.0..HEAD -- ./ ../BrowserServicesKit/").and_return(git_log)
594638

595639
task_ids = Fastlane::Helper::AsanaHelper.get_task_ids_from_git_log("v1.0.0")
596-
expect(task_ids).to eq(["1208700893044577", "1208589738926535", "1208804405760977"])
640+
expect(task_ids).to eq([
641+
"1208700893044577",
642+
"1208589738926535",
643+
"1208589738999999",
644+
"1208589738888888",
645+
"1208589738777777",
646+
"1208589738666666",
647+
"1208804405760977"
648+
])
597649
end
598650

599651
it "returns an empty array if no task IDs are found" do

0 commit comments

Comments
 (0)