Clone and create a feature branch from Jira Ticket Chrome Tab using Mac Touch Bar

Mathieu Demuynck
Texeï
Published in
4 min readApr 28, 2021

--

When I begin to work on a SalesForce Jira Ticket from Bitbucket repository, I usually create a feature/Ticket-Number Git branch from the master (or any reference branch) to do my developments. So, I use my favorite Git tool, copy the ticket number and create my branch. On Mac OS, there is a way to do it with more fun by creating a Quick Action Workflow !

How to do this ?

The idea is to get the title of the Jira web page that looks like this :

[TICKET-7324] title of the ticket (short description of the feature)

and retrieve this title from a unix Shell script to run the Git commands

How to retrieve the web page title ?

By using an Apple script called by the Shell script like this :

tell application "Google Chrome"
set webPageTitle to title of active tab of window 0
return webPageTitle
end tell

This Apple script is called in the Shell script like this :

#!/bin/zshTITLE=`/usr/bin/osascript<<END
tell application "Google Chrome"
set webPageTitle to title of active tab of window 0
return webPageTitle
end tell
END`

TICKET=$(echo $TITLE | awk -F'[][]' '{print $2}')
COMMENT=$(echo $TITLE | awk -F'[][]' '{print $3}' | sed -e 's: ::')

And now I can run the Git commands. the Shell script named CloneAndCreateFeatureBranchFromJiraTicket.sh is now :

#!/bin/zshSFDX_DIR=$BASE/sfdx-projectTITLE=`/usr/bin/osascript<<END
tell application "Google Chrome"
set webPageTitle to title of active tab of window 0
return webPageTitle
end tell
END`

TICKET=$(echo $TITLE | awk -F'[][]' '{print $2}')
COMMENT=$(echo $TITLE | awk -F'[][]' '{print $3}' | sed -e 's: ::')
echo 'Create Git branch'
cd $SFDX_DIR
git clone -b reference-branch-name --single-branch https://username@bitbucket.org/team/company-sfdx.git
mv company-sfdx $TICKET
cd $TICKET
git branch feature/$TICKET
git checkout feature/$TICKET

And you can also create an Apple Note with the Apple script :

#!/bin/zshSFDX_DIR=$BASE/sfdx-projectTITLE=`/usr/bin/osascript<<END
tell application "Google Chrome"
set webPageTitle to title of active tab of window 0
return webPageTitle
end tell
END`

TICKET=$(echo $TITLE | awk -F'[][]' '{print $2}')
COMMENT=$(echo $TITLE | awk -F'[][]' '{print $3}' | sed -e 's: ::')
echo 'Create Git branch'
cd $SFDX_DIR
git clone -b reference-branch-name --single-branch https://username@bitbucket.org/team/company-sfdx.git
mv company-sfdx $TICKET
cd $TICKET
git branch feature/$TICKET
git checkout feature/$TICKET
/usr/bin/osascript <<END
set noteBody to "
<body>
<h2>$TICKET : $COMMENT</h2>
<br>
<h3>Tickets : </h3>
<br>
<ul>
<li><a href='https://xxx.atlassian.net/browse/$TICKET'>$TICKET</a>
</li>
</ul>
<br>
<h3>Notes : </h3>
<br>
<h3>ToDo : </h3>
<br>
</body>"
tell application "Notes"
tell account "iCloud"
make new note at folder "ToDo" with properties {name:" ", body:noteBody}
end tell
end tell
END

How to set the Quick Action Workflow ?

This Apple guide explains how to create a Quick Action accessible from the Touch bar or the Service menu of any applications. The idea is to follow this guide and at the step “4. Add actions to your workflow” you add the Action : Execute a Shell script with no entries and for any applications.

In the Shell script you add the line to call the CloneAndCreateFeatureBranchFromJiraTicket.sh script like this :

Finally !

You can now go on the Jira Ticket Chrome tab, press the Quick Actions icon on the Touch bar and press your actions to create your “feature” branch.

You can also run the action from the service menu like this :

To sum up

This article gives a simple example of Apple Quick Action Workflow usage and show the power of automation with Mac OS. My Shell script is very simple but I run more complex scripts to do more complex tasks from other applications or Web browsers. You can also use the scripting language of your choice (like Javascript or Python) and the standard Apple Actions from library to compose your Quick Actions.

Additional information

--

--