Module: Repofetch::BitbucketCloud::Stats

Included in:
Repofetch::BitbucketCloud
Defined in:
lib/repofetch/bitbucketcloud/stats.rb

Overview

Methods to get Bitbucket Cloud stats.

Instance Method Summary collapse

Instance Method Details

#clone_urlsObject (protected)



15
16
17
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 15

def clone_urls
  @clone_urls ||= repo_data['links']['clone'].to_h { |clone| [clone['name'].to_sym, clone['href']] }
end

#createdObject (protected)



37
38
39
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 37

def created
  Repofetch::TimespanStat.new('created', repo_data['created_on'], emoji: '🐣')
end

#forksObject (protected)



32
33
34
35
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 32

def forks
  @fork_data ||= agent.call(:get, "repositories/#{@repo_identifier}/forks").data
  Repofetch::Stat.new('forks', @fork_data['size'], emoji: '🔱')
end

#http_clone_urlObject (protected)



19
20
21
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 19

def http_clone_url
  Repofetch::Stat.new('HTTP(S)', clone_urls[:https], emoji: '🌐')
end

#issuesObject (protected)



53
54
55
56
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 53

def issues
  @issue_data ||= agent.call(:get, "repositories/#{@repo_identifier}/issues").data
  Repofetch::Stat.new('issues', @issue_data['size'], emoji: '')
end

#pull_requestsObject (protected)



58
59
60
61
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 58

def pull_requests
  @pull_request_data ||= agent.call(:get, "repositories/#{@repo_identifier}/pullrequests").data
  Repofetch::Stat.new('pull requests', @pull_request_data['size'], emoji: '🔀')
end

#repo_dataObject (protected)



11
12
13
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 11

def repo_data
  @repo_data ||= agent.call(:get, "repositories/#{@repo_identifier}").data
end

#sizeObject (protected)



45
46
47
48
49
50
51
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 45

def size
  # NOTE: Size is in bytes
  # TODO: Move this somewhere else instead of using a copy-paste
  byte_size = number_to_human_size(repo_data['size'] || 0, precision: 2, significant: false,
                                                           strip_insignificant_zeros: false)
  Repofetch::Stat.new('size', byte_size, emoji: '💽')
end

#ssh_clone_urlObject (protected)



23
24
25
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 23

def ssh_clone_url
  Repofetch::Stat.new('SSH', clone_urls[:ssh], emoji: '🔑')
end

#updatedObject (protected)



41
42
43
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 41

def updated
  Repofetch::TimespanStat.new('updated', repo_data['updated_on'], emoji: '📤')
end

#watchersObject (protected)



27
28
29
30
# File 'lib/repofetch/bitbucketcloud/stats.rb', line 27

def watchers
  @watcher_data ||= agent.call(:get, "repositories/#{@repo_identifier}/watchers").data
  Repofetch::Stat.new('subscribers', @watcher_data['size'], emoji: '👀')
end