Skip to content

Instantly share code, notes, and snippets.

@ultimatecoder
Created January 8, 2019 17:09
Show Gist options
  • Save ultimatecoder/5f4250a394fd5074a9daa0a6e1eafc0b to your computer and use it in GitHub Desktop.
Save ultimatecoder/5f4250a394fd5074a9daa0a6e1eafc0b to your computer and use it in GitHub Desktop.
Adding a script to create individual Github issues for each Asana tasks. Dependencies are Python 2.7 runtime, asana (https://pypi.org/project/asana/) and PyGithub (https://pypi.org/project/PyGithub/).
#! /usr/bin/env python
# -*- coding: utf-8 -*-
"""Automated script to create Asana tasks to Github issues
Python version:
2.7
Build:
Installing Python packages:
pip install asana PyGithub
Environment variables: Define below environment variables.
1. ASANA_PERSONAL_ACCESS_TOKEN: Personal access token created at Asana.
Perform steps mentioned at
https://asana.com/guide/help/api/api#gl-access-tokens for creating a
personal access token.
2. ASANA_PROJECT_ID: An id of project from which this script will fetch
tasks and create an Github issue.
3. GITHUB_ACCESS_TOKEN: Access token created at Github. Perform steps
mentioned at
https://help.github.com/articles/creating-a-personal-access-token-for-the-command-line/
4. GITHUB_REPOSITORY: A repository where this script will create
issues. For example, 'ultimatecoder/arjun' is an appropriate repository
name.
Usage:
python asana_task_to_github_issue.py
"""
import os
import sys
import asana
import github
REQUIRED_VARIABLES = [
'ASANA_PERSONAL_ACCESS_TOKEN',
'ASANA_PROJECT_ID',
'GITHUB_ACCESS_TOKEN',
'GITHUB_REPOSITORY'
]
try:
# Asana variables
ASANA_PERSONAL_ACCESS_TOKEN = os.environ['ASANA_PERSONAL_ACCESS_TOKEN']
ASANA_PROJECT_ID = os.environ['ASANA_PROJECT_ID']
# Github variables
GITHUB_ACCESS_TOKEN = os.environ['GITHUB_ACCESS_TOKEN']
GITHUB_REPOSITORY = os.environ['GITHUB_REPOSITORY']
except KeyError as e:
for variable in REQUIRED_VARIABLES:
if variable in e.message:
print("Missing value for %s in environment variable." % (variable))
sys.exit(1)
asana_client = asana.Client.access_token(ASANA_PERSONAL_ACCESS_TOKEN)
github_client = github.Github(GITHUB_ACCESS_TOKEN)
repository = github_client.get_repo(GITHUB_REPOSITORY)
for task in asana_client.projects.tasks(ASANA_PROJECT_ID):
print("Creating issue for %s..." % (task['name']))
repository.create_issue(title=task['name'])
print("Created issue for %s !" % (task['name']))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment