This repository has been archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Safari - Jira to Notion.applescript
85 lines (58 loc) · 4.87 KB
/
Safari - Jira to Notion.applescript
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
# ______________________________
# Generic functions
on findAndReplaceInText(theText, theSearchString, theReplacementString)
set AppleScript's text item delimiters to theSearchString
set theTextItems to every text item of theText
set AppleScript's text item delimiters to theReplacementString
set theText to theTextItems as string
set AppleScript's text item delimiters to ""
return theText
end findAndReplaceInText
on htmlDecode(theText)
set sRet to theText
set sRet to findAndReplaceInText(sRet, "ç", "ç")
set sRet to findAndReplaceInText(sRet, "Ç", "Ç")
set sRet to findAndReplaceInText(sRet, "ö", "ö")
set sRet to findAndReplaceInText(sRet, "Ö", "Ö")
set sRet to findAndReplaceInText(sRet, "ü", "ü")
set sRet to findAndReplaceInText(sRet, "Ü", "Ü")
return sRet
end htmlDecode
# ______________________________
# Safari related functions
on getSubIssueNumberFromSafari()
tell application "Safari"
set sName to name of current tab in window 1
end tell
set sName to findAndReplaceInText(sName, " - Eczacıbaşı Tüketim Ürünleri Grubu JIRA", "")
set sName to findAndReplaceInText(sName, "]", " -")
set sName to findAndReplaceInText(sName, "[", "")
set iOffset to offset of " " in sName
set sName to text (iOffset - 1) thru 1 of sName as string
return sName
end getSubIssueNumberFromSafari
on getIssueNumberFromSafari()
set sPrefix to "<a class=\"issue-link\" data-issue-key=\""
tell application "Safari" to set sHTML to source of document 1
set iOffset to offset of sPrefix in sHTML
set sTrim to text iOffset thru -1 of sHTML as string
set iPrefixLength to length of sPrefix
set sTrim to text iPrefixLength thru -1 of sTrim as string
set iOffset to offset of "href" in sTrim
set sTrim to text (iOffset - 2) thru 1 of sTrim as string
set sTrim to findAndReplaceInText(sTrim, "\"", "")
return sTrim
end getIssueNumberFromSafari
# ______________________________
# Notion related functions
on buildJiraLink(theIssue)
return "http://tugjira.eczacibasi.com.tr/browse/" & theIssue
end buildJiraLink
# ______________________________
# Main Flow
-- Get Jira issue number from Safari
set sIssueNumber to getIssueNumberFromSafari()
-- Create subpage in Notion
set sSubIssueNumber to getSubIssueNumberFromSafari()
do shell script "/Users/kerem/Documents/Software/Kerem/Development/Jira2Notion/venv/bin/python /Users/kerem/Documents/Software/Kerem/Development/Jira2Notion/main.py " & sSubIssueNumber