Add a pull request link to Asana using GitHub actions.

Hosun Yoo
In Engineering
Published in
4 min readDec 6, 2020
Photo by Austin Distel on Unsplash

My team uses Asana for Kanban tasks / bug tracking and GitHub for source control. I always wanted one simple integration to add a GitHub PR (pull request) link to a Asana ticket so that my team can track what code change was required for a task, and I could not find any suitable solution. Unito has a paid product, but the costs are high, compared to a simple feature that I wanted.

I recently found GitHub actions for the integration, and I selected the action called “Asana Git”.

https://github.com/marketplace?type=actions&query=asana

With the action, the following line in a PR triggers to insert an Asana comment with the PR link.
**Asana Task:** [Task Name](https://app.asana.com/0/1/2)

Asana comment

The action looks for the phrase **Asana Task:** to find the Asana ticket URL and the phrase is configurable.

Here are the steps of the integration.

Create an Asana PAT (Personal Access Token)

The GitHub action needs to access your Asana ticket, and you will have to create a new PAT for the action by clicking the “New access token” button at the bottom of this Asana page.

https://app.asana.com/0/developer-console

The Asana developer page below includes further information about the PAT:

Add a GitHub Secret for the PAT

The GitHub action requires the PAT to add a comment or create a new Asana ticket, and it is good to store the PAT in a GitHub secret. As described in the document below, a secret can be created at a repository or an organization level and it will be convenient to make it at the organization if the secret is shared across multiple repositories.

Secret creation at the organization level

In the GitHub action, the secret will be accessed by {{ secrets.ASANA_TOKEN }} .

Add the GitHub Action

Now, we will create a GitHub action file for pull requests and create directories “.github/workflows” and add the “pull-request.yml” file.

on:
pull_request:
types: [ opened ]

I specified the action to trigger when a pull request is opened, and the document below explains other activity types of the pull request trigger (i.e. reopened).

task-comment: '* Pull Request: '                               trigger-phrase: "\\*\\*Asana Task:\\*\\*"

Based on the task-comment, * Pull Request: https://github.com/PULL-REQUST-URL is added to an Asana ticket, and a pull request is expected to have **Asana Task:** [Task Name](https://app.asana.com/0/1/2)

Asana comment
- name: Run PR stats                            
uses: flowwer-dev/pull-request-stats@v1

I found another PR action, which is helpful to encourage my team to review PRs, and after a PR is created, it will insert statistics of reviews to the GitHub PR.

From flowwer-dev/pull-request-stats

For public repositories, you may be able to share GitHub actions across multiple repositories at your organization.

https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/sharing-workflows-with-your-organization#creating-a-workflow-template

Write a GitHub PR template (optional)

It may not be easy to remember to insert the target phrase and format that is required by the action and a GitHub PR template is very handy.

https://app.asana.com/0/1/2” just needs to be replaced with an actual Asana ticket link.

🎉 Test!

The PR shows the progress of GitHub actions, and once they are complete, you can check your Asana ticket to see if the PR URL is inserted.

Billing

Based on your plan, GitHub offers free minutes of actions. (GitHub charges actions by computational time and OS types.) And, you can monitor the usage and set a spending limit on your billing page.

https://docs.github.com/en/free-pro-team@latest/github/setting-up-and-managing-billing-and-payments-on-github/about-billing-for-github-actions

More Actions?

If you like to explore more GitHub actions, Awesome Actions will be a great place, and I found Pull Request Stats on the page.

--

--