Module: OmniFocus::Github

Defined in:
lib/omnifocus/github.rb

Constant Summary collapse

VERSION =
"1.8.0"
PREFIX =
"GH"

Instance Method Summary collapse

Instance Method Details

#gh_client(account, auth, endpoints) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/omnifocus/github.rb', line 47

def gh_client , auth, endpoints
  if  != "github"
    if endpoints[:api] && endpoints[:web]
      Octokit.configure do |c|
        c.api_endpoint = endpoints[:api]
        c.web_endpoint = endpoints[:web]
      end
    else
      raise ArgumentError, "api and web endpoint configs required for github enterprise"
    end
  end

  if auth[:user] && auth[:password]
    client = Octokit::Client.new(:login => auth[:user],
                                 :password => auth[:password])

    client.user(auth[:name])
  elsif auth[:user] && auth[:oauth]
    client = Octokit::Client.new :access_token => auth[:oauth]
    client.user.
  else
    raise ArgumentError, "Missing authentication"
  end
  client
end

#omnifocus_git_param(name, default = nil, prefix = "omnifocus-github") ⇒ Object



42
43
44
45
# File 'lib/omnifocus/github.rb', line 42

def omnifocus_git_param name, default = nil, prefix = "omnifocus-github"
  param = `git config --global #{prefix}.#{name}`.chomp
  param.empty? ? default : param
end

#populate_github_tasksObject



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/omnifocus/github.rb', line 11

def populate_github_tasks
  processed = false
  omnifocus_git_param(:accounts, "github").split(/\s+/).each do ||
    endpoints = {}
    endpoints[:api] = omnifocus_git_param(:api, nil, )
    endpoints[:web] = omnifocus_git_param(:web, nil, )

    # User + password is required
    auth = {
      :name     => omnifocus_git_param(:name,         nil, ),
      :user     => omnifocus_git_param(:user,         nil, ),
      :password => omnifocus_git_param(:password,     nil, ),
      :oauth    => omnifocus_git_param("oauth-token", nil, ),
    }

    unless auth[:user] && (auth[:password] || auth[:oauth])
      warn "Missing authentication parameters for account #{account}."
      next
    end

    auth[:name] = auth[:user] if auth[:name].nil?

    processed = true
     =  == "github" ? nil : 

    process(, gh_client(, auth, endpoints))
  end

  raise "No accounts authenticated. Bailing." unless processed
end

#process(account, client) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/omnifocus/github.rb', line 73

def process , client
  client.list_issues.each do |issue|
    pr        = issue["pull_request"] && !issue["pull_request"]["diff_url"].nil?
    number    = issue.number
    project   = issue.repository.full_name.split("/").last
    ticket_id = "#{PREFIX}-#{project}##{number}"
    title     = "#{ticket_id}: #{pr ? "[PR] " : ""}#{issue["title"]}"
    # HACK
    url       = "https://github.com/#{issue.repository.full_name}/issues/#{number}"
    note      = "#{url}\n\n#{issue["body"]}"

    if existing[ticket_id] then
      bug_db[project][ticket_id] = true
      next
    end

    bug_db[project][ticket_id] = [title, note]
  end
end