repofetch 0.4.2.pre.rc.3 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f023092a0a4175633900e4bd9da512c5287a781be907cf57a8971a1fdd7fda6c
4
- data.tar.gz: 6d1a8f7e801bf4f4e228249a650f5270dc38153bdfa9a7c32771dd02d01c098b
3
+ metadata.gz: a76fb4a912612b2c1c549434f7cfae5fbb88728d036a17f77060e5ae868eebaa
4
+ data.tar.gz: 01c3fefe7a5799a65e5a078bbb6d3ca891fe56c8db3b38a9f4989b8cd0336bf7
5
5
  SHA512:
6
- metadata.gz: 3fc54f3354a0f0b531eea8a183391ac839244c714546439f4e21d5d42e4d9233ffc17150149b8c48c29fa1adcb21b7c5d46a504855daffbf9e36c10ab8710d1a
7
- data.tar.gz: 29a97740e37ea30bd2f5017f42a0647c3cb944bd811e4d17831fb1d9fc55fe125c9db1d54aa4c9c4c14bef271ae850e2a6b0af067c78604006cc3aa5b939fd25
6
+ metadata.gz: 7190241c2007f706a366628ff13d1aeea7c64a2c37fc54b335d20eca2d3697a640dfd6cef50192d551dab8712e9abb4ca52a9cd0d43044922ca8f7fce6cb4eea
7
+ data.tar.gz: '0295d4dbc84815a2037dc239cbfcbfd2d3062d1d8ceb8fb17b9990744a67923c5310ddb5bfa9a6515eb723d981bca6b8e4a8394b63aa3c520d49254d43bdba49'
data/Gemfile.lock CHANGED
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- repofetch (0.4.2.pre.rc.3)
4
+ repofetch (0.4.2)
5
5
  actionview (~> 7.0, >= 7.0.4)
6
6
  dotenv (~> 2.8)
7
7
  faraday-retry (~> 2.0)
8
8
  git (~> 1.12)
9
9
  octokit (~> 6.0, >= 6.0.1)
10
+ sawyer (~> 0.9)
10
11
 
11
12
  GEM
12
13
  remote: https://rubygems.org/
@@ -33,7 +34,7 @@ GEM
33
34
  diff-lcs (1.5.0)
34
35
  docile (1.4.0)
35
36
  dotenv (2.8.1)
36
- erubi (1.11.0)
37
+ erubi (1.12.0)
37
38
  faraday (2.7.2)
38
39
  faraday-net_http (>= 2.0, < 3.1)
39
40
  ruby2_keywords (>= 0.0.4)
@@ -46,18 +47,19 @@ GEM
46
47
  i18n (1.12.0)
47
48
  concurrent-ruby (~> 1.0)
48
49
  iniparse (1.5.0)
49
- json (2.6.2)
50
+ json (2.6.3)
50
51
  loofah (2.19.1)
51
52
  crass (~> 1.0.2)
52
53
  nokogiri (>= 1.5.9)
53
- mini_portile2 (2.8.0)
54
- minitest (5.16.3)
54
+ mini_portile2 (2.8.1)
55
+ minitest (5.17.0)
55
56
  nokogiri (1.13.10)
56
57
  mini_portile2 (~> 2.8.0)
57
58
  racc (~> 1.4)
58
59
  octokit (6.0.1)
59
60
  faraday (>= 1, < 3)
60
61
  sawyer (~> 0.9)
62
+ os (1.1.4)
61
63
  overcommit (0.59.1)
62
64
  childprocess (>= 0.6.3, < 5)
63
65
  iniparse (~> 1.4)
@@ -66,7 +68,7 @@ GEM
66
68
  parser (3.1.3.0)
67
69
  ast (~> 2.4.1)
68
70
  public_suffix (5.0.1)
69
- racc (1.6.1)
71
+ racc (1.6.2)
70
72
  rails-dom-testing (2.0.3)
71
73
  activesupport (>= 4.2.0)
72
74
  nokogiri (>= 1.6)
@@ -93,28 +95,28 @@ GEM
93
95
  awesome_print (> 1.0.0)
94
96
  rspec (> 3.0.0)
95
97
  rspec-support (3.12.0)
96
- rubocop (1.39.0)
98
+ rubocop (1.42.0)
97
99
  json (~> 2.3)
98
100
  parallel (~> 1.10)
99
101
  parser (>= 3.1.2.1)
100
102
  rainbow (>= 2.2.2, < 4.0)
101
103
  regexp_parser (>= 1.8, < 3.0)
102
104
  rexml (>= 3.2.5, < 4.0)
103
- rubocop-ast (>= 1.23.0, < 2.0)
105
+ rubocop-ast (>= 1.24.1, < 2.0)
104
106
  ruby-progressbar (~> 1.7)
105
107
  unicode-display_width (>= 1.4.0, < 3.0)
106
- rubocop-ast (1.24.0)
108
+ rubocop-ast (1.24.1)
107
109
  parser (>= 3.1.1.0)
108
110
  rubocop-rake (0.6.0)
109
111
  rubocop (~> 1.0)
110
- rubocop-rspec (2.15.0)
112
+ rubocop-rspec (2.16.0)
111
113
  rubocop (~> 1.33)
112
114
  ruby-progressbar (1.11.0)
113
115
  ruby2_keywords (0.0.5)
114
116
  sawyer (0.9.2)
115
117
  addressable (>= 2.3.5)
116
118
  faraday (>= 0.17.3, < 3)
117
- simplecov (0.21.2)
119
+ simplecov (0.22.0)
118
120
  docile (~> 1.1)
119
121
  simplecov-html (~> 0.11)
120
122
  simplecov_json_formatter (~> 0.1)
@@ -135,6 +137,7 @@ PLATFORMS
135
137
 
136
138
  DEPENDENCIES
137
139
  bundler (~> 2.0)
140
+ os (~> 1.1)
138
141
  overcommit (~> 0.59)
139
142
  rake (~> 13.0)
140
143
  repofetch!
data/README.md CHANGED
@@ -33,6 +33,14 @@ gem install repofetch
33
33
 
34
34
  If you are using an Arch machine, you can install repofetch from the [Aur](https://aur.archlinux.org).
35
35
 
36
+ #### Stable
37
+
38
+ ```
39
+ yay -S ruby-repofetch-bin
40
+ ```
41
+
42
+ #### Development
43
+
36
44
  ```
37
45
  yay -S ruby-repofetch
38
46
  ```
data/RELEASE_NOTES CHANGED
@@ -1,6 +1,18 @@
1
- 0.4.2-rc.3
1
+ 0.4.2
2
+
3
+ ## Added
4
+
5
+ - GitLab plugin
6
+ - Enable by adding `- repofetch/gitlab` to your config file
2
7
 
3
8
  ## Other
4
9
 
5
- - Deploy built gem as GitHub release asset for each release
6
10
  - Publish gem with GitHub Actions
11
+
12
+ ## Breaking for 3rd-party plugins
13
+
14
+ ### Changed
15
+
16
+ - Configuration to be a class variable on `Repofetch` instead of a value that's
17
+ passed to various instantiation and rendering methods
18
+ - Stats to automatically receive theme from the base `Plugin` class
data/Rakefile CHANGED
@@ -3,11 +3,18 @@
3
3
  require 'bundler/setup'
4
4
  require 'rake'
5
5
 
6
+ require 'os'
6
7
  require 'rspec/core/rake_task'
7
8
  require 'rubocop/rake_task'
8
9
  require 'yard'
9
10
 
10
- RSpec::Core::RakeTask.new(:spec)
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = if OS.windows?
13
+ '--exclude-pattern spec/**/*_unix_spec.rb'
14
+ else
15
+ '--exclude-pattern spec/**/*_windows_spec.rb'
16
+ end
17
+ end
11
18
  RuboCop::RakeTask.new(:format) do |t|
12
19
  t.requires << 'rubocop-rspec'
13
20
  end
@@ -2,4 +2,5 @@
2
2
  # vim: set ft=yaml:
3
3
  plugins:
4
4
  - 'repofetch/github'
5
+ - 'repofetch/gitlab'
5
6
  emojis: true
@@ -30,7 +30,8 @@ class Repofetch
30
30
  end
31
31
 
32
32
  def stats
33
- [url, stargazers, subscribers, forks, created, updated, size, issues, pull_requests]
33
+ stats = [url, stargazers, subscribers, forks, created, updated, size, issues, pull_requests]
34
+ stats.each { |stat| stat.style_label!(:bold) }
34
35
  end
35
36
 
36
37
  # Detects that the repository is a GitHub repository.
@@ -109,27 +110,27 @@ class Repofetch
109
110
  end
110
111
 
111
112
  def url
112
- Repofetch::Stat.new('URL', repo_stats['clone_url'], emoji: '🌐', theme: theme)
113
+ Repofetch::Stat.new('URL', repo_stats['clone_url'], emoji: '🌐')
113
114
  end
114
115
 
115
116
  def stargazers
116
- Repofetch::Stat.new('stargazers', repo_stats['stargazers_count'], emoji: '⭐', theme: theme)
117
+ Repofetch::Stat.new('stargazers', repo_stats['stargazers_count'], emoji: '⭐')
117
118
  end
118
119
 
119
120
  def subscribers
120
- Repofetch::Stat.new('subscribers', repo_stats['subscribers_count'], emoji: '👀', theme: theme)
121
+ Repofetch::Stat.new('subscribers', repo_stats['subscribers_count'], emoji: '👀')
121
122
  end
122
123
 
123
124
  def forks
124
- Repofetch::Stat.new('forks', repo_stats['forks_count'], emoji: '🔱', theme: theme)
125
+ Repofetch::Stat.new('forks', repo_stats['forks_count'], emoji: '🔱')
125
126
  end
126
127
 
127
128
  def created
128
- Repofetch::TimespanStat.new('created', repo_stats['created_at'], emoji: '🐣', theme: theme)
129
+ Repofetch::TimespanStat.new('created', repo_stats['created_at'], emoji: '🐣')
129
130
  end
130
131
 
131
132
  def updated
132
- Repofetch::TimespanStat.new('updated', repo_stats['updated_at'], emoji: '📤', theme: theme)
133
+ Repofetch::TimespanStat.new('updated', repo_stats['updated_at'], emoji: '📤')
133
134
  end
134
135
 
135
136
  def size
@@ -139,17 +140,17 @@ class Repofetch
139
140
  significant: false,
140
141
  strip_insignificant_zeros: false
141
142
  )
142
- Repofetch::Stat.new('size', byte_size, emoji: '💽', theme: theme)
143
+ Repofetch::Stat.new('size', byte_size, emoji: '💽')
143
144
  end
144
145
 
145
146
  def issues
146
147
  @issue_search = @client.search_issues("repo:#{repo_id} is:issue", per_page: 1, page: 0) if @issue_search.nil?
147
- Repofetch::Stat.new('issues', @issue_search['total_count'], emoji: '❗', theme: theme)
148
+ Repofetch::Stat.new('issues', @issue_search['total_count'], emoji: '❗')
148
149
  end
149
150
 
150
151
  def pull_requests
151
152
  @pr_search = @client.search_issues("repo:#{repo_id} is:pr", per_page: 1, page: 0) if @pr_search.nil?
152
- Repofetch::Stat.new('pull requests', @pr_search['total_count'], emoji: '🔀', theme: theme)
153
+ Repofetch::Stat.new('pull requests', @pr_search['total_count'], emoji: '🔀')
153
154
  end
154
155
  end
155
156
  end
@@ -0,0 +1,17 @@
1
+ %{red} OOO OOO
2
+ %{red} OOOOOO OOOOOO
3
+ %{red} OOOOOOOO OOOOOOOO
4
+ %{red} OOOOOOOOOO OOOOOOOOOO
5
+ %{red} OOOOOOOOOOOO OOOOOOOOOOOO
6
+ %{red} OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
7
+ %{red} OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
8
+ %{yellow} ...%{red}OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO%{yellow}...
9
+ %{yellow} ......%{red}OOOOOOOOOOOOOOOOOOOOOOOOOO%{yellow}......
10
+ %{yellow} ........%{red}OOOOOOOOOOOOOOOOOOOO%{yellow}........
11
+ %{yellow} ..........%{red}OOOOOOOOOOOOOO%{yellow}..........
12
+ %{yellow} ............%{red}OOOOOOOO%{yellow}............
13
+ %{yellow} .............%{red}OO%{yellow}..............
14
+ %{yellow} .......%{yellow}@@@@@@@@%{yellow}........
15
+ %{yellow} ..%{yellow}@@@@@@@@@@@@@@@%{yellow}..
16
+ %{yellow} @@@@@@@@@@@@@
17
+ %{yellow} @@@@@@@
@@ -0,0 +1,127 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'cgi'
4
+ require 'repofetch'
5
+ require 'sawyer'
6
+
7
+ class Repofetch
8
+ # Adds support for GitLab repositories.
9
+ class Gitlab < Repofetch::Plugin
10
+ HTTP_REMOTE_REGEX = %r{https?://gitlab\.com/(?<path>[\w.\-][\w.\-/]+)}.freeze
11
+ SSH_REMOTE_REGEX = %r{git@gitlab\.com:(?<path>[\w.\-][\w.\-/]+)}.freeze
12
+ ASCII = File.read(File.expand_path('gitlab/ASCII', __dir__))
13
+
14
+ attr_reader :repo_identifier
15
+
16
+ # @param repo_identifier [String] The repository identifier (either the ID number or the namespaced repo name).
17
+ def initialize(repo_identifier)
18
+ super
19
+
20
+ @repo_identifier = CGI.escape(repo_identifier)
21
+ end
22
+
23
+ def header
24
+ "#{repo_data['name_with_namespace']} @ GitLab"
25
+ end
26
+
27
+ def stats
28
+ stats = [url, stars, forks, created, updated]
29
+
30
+ # NOTE: Stats that require authentication
31
+ stats << open_issues unless token.nil?
32
+
33
+ stats.each { |stat| %i[bold red].each { |style| stat.style_label!(style) } }
34
+ end
35
+
36
+ def ascii
37
+ ASCII
38
+ end
39
+
40
+ def agent
41
+ @agent ||= Sawyer::Agent.new('https://gitlab.com/api/v4', links_parser: Sawyer::LinkParsers::Simple.new) do |http|
42
+ http.headers['Authorization'] = "Bearer #{token}" unless token.nil?
43
+ end
44
+ end
45
+
46
+ def token
47
+ ENV.fetch('GITLAB_TOKEN', nil)
48
+ end
49
+
50
+ def repo_data
51
+ @repo_data ||= agent.call(:get, "projects/#{@repo_identifier}").data
52
+ end
53
+
54
+ def url
55
+ Repofetch::Stat.new('URL', repo_data['http_url_to_repo'], emoji: '🌐')
56
+ end
57
+
58
+ def stars
59
+ Repofetch::Stat.new('stars', repo_data['star_count'], emoji: '⭐')
60
+ end
61
+
62
+ def forks
63
+ Repofetch::Stat.new('forks', repo_data['forks_count'], emoji: '🔱')
64
+ end
65
+
66
+ def created
67
+ Repofetch::TimespanStat.new('created', repo_data['created_at'], emoji: '🐣')
68
+ end
69
+
70
+ def updated
71
+ Repofetch::TimespanStat.new('updated', repo_data['last_activity_at'], emoji: '📤')
72
+ end
73
+
74
+ def open_issues
75
+ # NOTE: It seems like the auth token must be set to get the open issues count.
76
+ Repofetch::Stat.new('open issues', repo_data['open_issues_count'], emoji: '❗')
77
+ end
78
+
79
+ # Gets the path (+owner/subproject/repo+) of the repository.
80
+ def self.repo_identifier(git)
81
+ default_remote = Repofetch.default_remote(git)
82
+ url = default_remote&.url
83
+ remote_identifier(url)
84
+ end
85
+
86
+ # Gets the path (+owner/subproject/repo+) of the repository.
87
+ #
88
+ # Returns nil if there is no match.
89
+ def self.remote_identifier(remote)
90
+ match = HTTP_REMOTE_REGEX.match(remote)
91
+ match = SSH_REMOTE_REGEX.match(remote) if match.nil?
92
+ raise "Remote #{remote.inspect} doesn't look like a GitLab remote" if match.nil?
93
+
94
+ match[:path].delete_suffix('.git')
95
+ end
96
+
97
+ # Detects that the repository is a GitHub repository.
98
+ def self.matches_repo?(git)
99
+ default_remote = Repofetch.default_remote(git)
100
+ url = default_remote&.url
101
+ matches_remote?(url)
102
+ end
103
+
104
+ # Detects that the remote URL is for a GitHub repository.
105
+ def self.matches_remote?(remote)
106
+ HTTP_REMOTE_REGEX.match?(remote) || SSH_REMOTE_REGEX.match?(remote)
107
+ end
108
+
109
+ # Creates an instance from a +Git::Base+ instance.
110
+ #
111
+ # @raise [ArgumentError] if this plugin was selected *and* arguments were passed.
112
+ def self.from_git(git, args)
113
+ # TODO: Raise a better exception than ArgumentError
114
+ raise ArgumentError, 'Explicitly activate this plugin to CLI arguments' unless args.empty?
115
+
116
+ path = repo_identifier(git)
117
+
118
+ new(path)
119
+ end
120
+
121
+ def self.from_args(args)
122
+ new(args[0])
123
+ end
124
+ end
125
+ end
126
+
127
+ Repofetch::Gitlab.register
@@ -28,6 +28,9 @@ class Repofetch
28
28
 
29
29
  attr_reader :styles
30
30
 
31
+ # Initializes a new theme.
32
+ #
33
+ # @param [Hash] styles A Hash of styles to use. Is merged with the default styles.
31
34
  def initialize(styles = {})
32
35
  @styles = DEFAULT_STYLES.merge(styles)
33
36
  end
data/lib/repofetch.rb CHANGED
@@ -193,9 +193,20 @@ class Repofetch
193
193
  []
194
194
  end
195
195
 
196
+ # Adds +theme+ to the stats, mutating those stats.
197
+ #
198
+ # @return [Array<Stat>]
199
+ def theme_stats!
200
+ stats.each do |stat|
201
+ stat.theme = theme if stat.respond_to?(:theme=)
202
+ end
203
+ end
204
+
196
205
  # Makes an array of stat lines, including the header and separator.
197
- def stat_lines
198
- [header, separator, *stats.map(&:to_s)]
206
+ #
207
+ # Mutates +stats+ to add the +theme+.
208
+ def stat_lines!
209
+ [header, separator, *theme_stats!.map(&:to_s)]
199
210
  end
200
211
 
201
212
  # Zips ASCII lines with stat lines.
@@ -203,6 +214,7 @@ class Repofetch
203
214
  # If there are more of one than the other, than the zip will be padded with empty strings.
204
215
  def zipped_lines
205
216
  ascii_lines = ascii.lines.map(&:chomp)
217
+ stat_lines = stat_lines!
206
218
  if ascii_lines.length > stat_lines.length
207
219
  ascii_lines.zip(stat_lines)
208
220
  else
@@ -214,23 +226,40 @@ class Repofetch
214
226
  # Base class for stats.
215
227
  class Stat
216
228
  attr_reader :label, :value, :emoji
229
+ attr_writer :theme
217
230
 
218
231
  # Creates a stat
219
232
  #
220
233
  # @param [String] label The label of the stat
221
234
  # @param value The value of the stat
222
235
  # @param [String] emoji An optional emoji for the stat
223
- def initialize(label, value, emoji: nil, theme: nil)
236
+ def initialize(label, value, emoji: nil)
224
237
  @label = label
225
238
  @value = value
226
239
  @emoji = emoji
227
- @theme = theme
240
+ @label_styles = []
228
241
  end
229
242
 
230
243
  def to_s
231
244
  emoji = @emoji
232
245
  emoji = nil unless Repofetch.config.nil? || Repofetch.config.emojis?
233
- "#{emoji}#{@theme.nil? ? @label : @theme.format(:bold, @label)}: #{format_value}"
246
+ "#{emoji}#{format_label}: #{format_value}"
247
+ end
248
+
249
+ # Adds a style for the label
250
+ #
251
+ # @param [Symbol] style The theme's style to add
252
+ def style_label!(style)
253
+ @label_styles << style
254
+ end
255
+
256
+ # Formats the label, including styles.
257
+ #
258
+ # @return [String]
259
+ def format_label
260
+ return @label if @theme.nil?
261
+
262
+ @label_styles.inject(@label) { |label, style| @theme.format(style, label) }
234
263
  end
235
264
 
236
265
  # Formats the value
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: repofetch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.2.pre.rc.3
4
+ version: 0.4.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Spenser Black
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-12-16 00:00:00.000000000 Z
11
+ date: 2023-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: actionview
@@ -92,6 +92,20 @@ dependencies:
92
92
  - - ">="
93
93
  - !ruby/object:Gem::Version
94
94
  version: 6.0.1
95
+ - !ruby/object:Gem::Dependency
96
+ name: sawyer
97
+ requirement: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - "~>"
100
+ - !ruby/object:Gem::Version
101
+ version: '0.9'
102
+ type: :runtime
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '0.9'
95
109
  - !ruby/object:Gem::Dependency
96
110
  name: bundler
97
111
  requirement: !ruby/object:Gem::Requirement
@@ -106,6 +120,20 @@ dependencies:
106
120
  - - "~>"
107
121
  - !ruby/object:Gem::Version
108
122
  version: '2.0'
123
+ - !ruby/object:Gem::Dependency
124
+ name: os
125
+ requirement: !ruby/object:Gem::Requirement
126
+ requirements:
127
+ - - "~>"
128
+ - !ruby/object:Gem::Version
129
+ version: '1.1'
130
+ type: :development
131
+ prerelease: false
132
+ version_requirements: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - "~>"
135
+ - !ruby/object:Gem::Version
136
+ version: '1.1'
109
137
  - !ruby/object:Gem::Dependency
110
138
  name: overcommit
111
139
  requirement: !ruby/object:Gem::Requirement
@@ -274,6 +302,8 @@ files:
274
302
  - lib/repofetch/exceptions.rb
275
303
  - lib/repofetch/github.rb
276
304
  - lib/repofetch/github/ASCII
305
+ - lib/repofetch/gitlab.rb
306
+ - lib/repofetch/gitlab/ASCII
277
307
  - lib/repofetch/theme.rb
278
308
  - lib/repofetch/util.rb
279
309
  homepage: https://github.com/spenserblack/repofetch
@@ -297,9 +327,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
297
327
  version: 2.7.0
298
328
  required_rubygems_version: !ruby/object:Gem::Requirement
299
329
  requirements:
300
- - - ">"
330
+ - - ">="
301
331
  - !ruby/object:Gem::Version
302
- version: 1.3.1
332
+ version: '0'
303
333
  requirements: []
304
334
  rubygems_version: 3.1.6
305
335
  signing_key: