class Danger::DangerAsana
Links Asana
issues to a pull request. @example Check PR for the following Asana
project keys and links them
asana.check()
@see thomasjoulin/danger-asana @tags asana
Public Class Methods
new(dangerfile)
click to toggle source
Calls superclass method
# File lib/asana/plugin.rb, line 15 def initialize(dangerfile) super(dangerfile) @client = Asana::Client.new do |c| c.authentication :access_token, ENV["_ASANA_TOKEN"] c.default_headers "asana-enable" => "new_user_task_lists" end end
Public Instance Methods
check()
click to toggle source
Checks PR for Asana
IDs and links them
@return [void]
# File lib/asana/plugin.rb, line 28 def check issues = find_asana_issues messages = [] issues.each do |issue| task = find_by_id(issue) unless task.nil? name = task.name[0..300].gsub("\n", "<br />").strip notes = task.notes[0..300].gsub("\n", "<br />").strip messages << "**[#{name}](#{task.permalink_url})**\n#{notes} |" end end unless messages.empty? header = [ "Asana tasks in this PR |", "--- |" ] markdown header .concat(messages) .join("\n") end end
Private Instance Methods
find_asana_issues(search_title: true, search_commits: true, search_body: true)
click to toggle source
# File lib/asana/plugin.rb, line 64 def find_asana_issues(search_title: true, search_commits: true, search_body: true) regexps = [/\[#([^\]]+)\]/, %r{(?:https://)?app\.asana\.com/0/[0-9]+/([0-9]+)}x] asana_issues = [] regexps.each do |regexp| if search_title vcs_host.pr_title.scan(regexp) do |match| asana_issues << match end end if search_commits git.commits.map do |commit| commit.message.scan(regexp) do |match| asana_issues << match end end end if search_body vcs_host.pr_body.scan(regexp) do |match| asana_issues << match end end end return asana_issues.flatten.uniq end
find_by_id(id)
click to toggle source
# File lib/asana/plugin.rb, line 94 def find_by_id(id) @client.tasks.find_by_id(id) rescue Asana::Errors::NotFound puts "task #{id} not found" return nil end
vcs_host()
click to toggle source
# File lib/asana/plugin.rb, line 58 def vcs_host return gitlab if defined? @dangerfile.gitlab return github end