Class: RepoProvider::Bitbucket

Inherits:
Object
  • Object
show all
Defined in:
lib/git-issues/providers/bitbucket.rb

Overview

Constant Summary collapse

URL_PATTERNS =
[
  /^[email protected]:(?<user>[^\/]+)\/(?<repo>.+)\.git$/,
  /^(ssh:\/\/)[email protected]\/(?<user>[^\/]+)\/(?<repo>.+)\.git$/,
  /^https:\/\/([^@]+@)?bitbucket.org\/(?<user>[^\/]+)\/(?<repo>.+)\.git$/
]

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get_repo(url) ⇒ Object



14
15
16
17
# File 'lib/git-issues/providers/bitbucket.rb', line 14

def self.get_repo url
  # find the url pattern that matches the url
  URL_PATTERNS.map{|p| p.match url }.compact.first
end

Instance Method Details

#issue_close(id) ⇒ Object



46
47
48
49
# File 'lib/git-issues/providers/bitbucket.rb', line 46

def issue_close id
  res = bitbucket.issues.edit( repo['user'], repo['repo'], id, {status: 'resolved'})
  res['status'] == 'resolved'
end

#issue_create(title, content) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/git-issues/providers/bitbucket.rb', line 32

def issue_create title, content
  ret = bitbucket.issues.create( repo['user'], repo['repo'], {
    title:    title,
    content:  content
    })
  id = ret['resource_uri'].match(/[0-9]+$/)
  id && id[0].to_i || -1
end

#issue_delete(id) ⇒ Object



51
52
53
# File 'lib/git-issues/providers/bitbucket.rb', line 51

def issue_delete id
  bitbucket.issues.delete( repo['user'], repo['repo'], id)
end

#issue_reopen(id) ⇒ Object



41
42
43
44
# File 'lib/git-issues/providers/bitbucket.rb', line 41

def issue_reopen id
  res = bitbucket.issues.edit( repo['user'], repo['repo'], id, {status: 'open'})
  res['status'] == 'open'
end

#issues_list(opts = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/git-issues/providers/bitbucket.rb', line 19

def issues_list opts = {}
  # get issues for this repo
  issues = bitbucket.issues.list_repo(repo['user'], repo['repo'])
  # filter closed issues if the user doesn't want all
  if not opts[:all]
    issues = issues.find_all{|i|
        'resolved' != i['status']
      }
  end
  # return issues
  format_issues( issues )
end

#providerObject



55
56
57
# File 'lib/git-issues/providers/bitbucket.rb', line 55

def provider
  bitbucket
end