Skip to content

Instantly share code, notes, and snippets.

@bogdanRada
Created January 27, 2016 18:20
Show Gist options
  • Save bogdanRada/ecc5e4b3071520358573 to your computer and use it in GitHub Desktop.
Save bogdanRada/ecc5e4b3071520358573 to your computer and use it in GitHub Desktop.
Pull asana tasks/ids into git commit message file
require 'asana'
access_token = '12345678'
project_id = 12345678 # find this in your URL
user_id = 12345678 # found this by right clicking on my avatar in asana and inspecting element - it's in the URL there
COMMENT_CHAR = '#' # replace with your editor's comment character(s)
client = Asana::Client.new do |c|
c.authentication :access_token, access_token
end
tasks = client.tasks.find_by_project(projectId: project_id, options: { fields: ['name', 'id', 'assignee'] })
gitmsg = "\n\n"
first = true
tasks.each do |task|
# only find tasks starting with a number in square brackets, that isn't set to zero
if (task.name =~ /[\d]/) && (!task.name.include? "[0]")
if task.assignee && task.assignee['id'] == user_id
# the first task (top most in Asana UI) is prefixed with a dot so it's not commented out (I use vim for commit messages)
if first
first = false
gitmsg += "."
end
gitmsg += COMMENT_CHAR + task.id.to_s + " " + COMMENT_CHAR + task.name + "\n"
end
end
end
File.open('.git/.gitmsg', 'w') { |file|
file.write(gitmsg)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment