Class: Worktool::Github

Inherits:
Object
  • Object
show all
Defined in:
lib/worktool/github.rb

Instance Method Summary collapse

Instance Method Details

#extract(query) ⇒ Object



4
5
6
7
8
9
# File 'lib/worktool/github.rb', line 4

def extract(query)
  if query.match(/^https?:\/\//)
    return extract_url(query)
  end
  extract_hash(query)
end

#extract_hash(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/worktool/github.rb', line 25

def extract_hash(hash)
  matches = hash.match(/^(?:([^#\/]+)\/)?([^#\/]+)(?:#([0-9]+))?$/)
  return nil unless matches
  data = {
      :repo => matches[2],
  }
  data[:user] = matches[1] if matches[1]
  data[:issue] = matches[3].to_i if matches[3]
  data
end

#extract_url(url) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/worktool/github.rb', line 11

def extract_url(url)
  matches = url.match(/^https?:\/\/(?:www\.)?github\.com\/([^\/]+)\/([^\/]+)\/(.*)/)
  return nil unless matches
  data = {
      :user => matches[1],
      :repo => matches[2]
  }
  suffix = matches[3]

  matches = suffix.match(/^(issues|pull)\/([0-9]+)/)
  data[:issue] = matches[2].to_i if matches
  data
end