fbe 0.14.1 → 0.16.0

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.
data/lib/fbe/sec.rb CHANGED
@@ -6,15 +6,22 @@
6
6
  require 'tago'
7
7
  require_relative '../fbe'
8
8
 
9
- # Converts number of seconds into text.
9
+ # Converts number of seconds into human-readable time format.
10
10
  #
11
11
  # The number of seconds is taken from the +fact+ provided, usually stored
12
- # there in the +seconds+ property. The seconds are formatted to hours,
13
- # days, or weeks.
12
+ # there in the +seconds+ property. The seconds are formatted into a
13
+ # human-readable string like "3 days ago" or "5 hours ago" using the
14
+ # tago gem.
14
15
  #
15
- # @param [Factbase::Fact] fact The fact, where to get the number of seconds
16
- # @param [String] prop The property in the fact, with the seconds
17
- # @return [String] Time interval as a text
16
+ # @param [Factbase::Fact] fact The fact containing the seconds property
17
+ # @param [String, Symbol] prop The property name with seconds (defaults to :seconds)
18
+ # @return [String] Human-readable time interval (e.g., "2 weeks ago", "3 hours ago")
19
+ # @raise [RuntimeError] If the specified property doesn't exist in the fact
20
+ # @note Uses the tago gem's ago method for formatting
21
+ # @example Format elapsed time from a fact
22
+ # build_fact = fb.query('(eq type "build")').first
23
+ # build_fact.duration = 7200 # 2 hours in seconds
24
+ # puts Fbe.sec(build_fact, :duration) # => "2 hours ago"
18
25
  def Fbe.sec(fact, prop = :seconds)
19
26
  s = fact[prop.to_s]
20
27
  raise "There is no #{prop.inspect} property" if s.nil?
@@ -6,31 +6,52 @@
6
6
  require_relative '../fbe'
7
7
  require_relative 'octo'
8
8
 
9
- # Converts mask to repository name.
9
+ # Converts a repository mask pattern to a regular expression.
10
10
  #
11
- # This function takes something like +"zerocracy/*"+ as an input and returns
12
- # a regular expression that may match repositories defined by this mask, which
13
- # is +/zerocracy\/.*+ in this particular case.
11
+ # @example Basic wildcard matching
12
+ # Fbe.mask_to_regex('zerocracy/*')
13
+ # # => /zerocracy\/.*/i
14
14
  #
15
- # @param [String] mask The mask
16
- # @return [Regex] Regular expression
15
+ # @example Specific repository (no wildcard)
16
+ # Fbe.mask_to_regex('zerocracy/fbe')
17
+ # # => /zerocracy\/fbe/i
18
+ #
19
+ # @param [String] mask Repository mask in format 'org/repo' where repo can contain '*'
20
+ # @return [Regexp] Case-insensitive regular expression for matching repositories
21
+ # @raise [RuntimeError] If organization part contains asterisk
17
22
  def Fbe.mask_to_regex(mask)
18
23
  org, repo = mask.split('/')
19
24
  raise "Org '#{org}' can't have an asterisk" if org.include?('*')
20
25
  Regexp.compile("#{org}/#{repo.gsub('*', '.*')}", Regexp::IGNORECASE)
21
26
  end
22
27
 
23
- # Builds a list of repositories required by the +repositories+ option.
28
+ # Resolves repository masks to actual GitHub repository names.
29
+ #
30
+ # Takes a comma-separated list of repository masks from options and expands
31
+ # wildcards by querying GitHub API. Supports inclusion and exclusion patterns.
32
+ # Archived repositories are automatically filtered out.
33
+ #
34
+ # @example Basic usage with wildcards
35
+ # # options.repositories = "zerocracy/fbe,zerocracy/ab*"
36
+ # repos = Fbe.unmask_repos
37
+ # # => ["zerocracy/fbe", "zerocracy/abc", "zerocracy/abcd"]
38
+ #
39
+ # @example Using exclusion patterns
40
+ # # options.repositories = "zerocracy/*,-zerocracy/private*"
41
+ # repos = Fbe.unmask_repos
42
+ # # Returns all zerocracy repos except those starting with 'private'
24
43
  #
25
- # The +repositories+ option defined in the +$options+ must contain something
26
- # like "zerocracy/fbe,zerocracy/ab*" (a comma-separated list of masks). This
27
- # function will go to the GitHub API and fetch all available repositories
28
- # matching these masks.
44
+ # @example Empty result handling
45
+ # # options.repositories = "nonexistent/*"
46
+ # Fbe.unmask_repos # Raises error: "No repos found matching: nonexistent/*"
29
47
  #
30
- # @param [Judges::Options] options The options coming from the +judges+ tool
31
- # @param [Hash] global The hash for global caching
32
- # @param [Loog] loog The logging facility
33
- # @return [Array<String>] List of repository full names
48
+ # @param [Judges::Options] options Options containing 'repositories' field with masks
49
+ # @param [Hash] global Global cache for storing API responses
50
+ # @param [Loog] loog Logger for debug output
51
+ # @return [Array<String>] Shuffled list of repository full names (e.g., 'org/repo')
52
+ # @raise [RuntimeError] If no repositories match the provided masks
53
+ # @note Exclusion patterns must start with '-' (e.g., '-org/pattern*')
54
+ # @note Results are shuffled to distribute load when processing
34
55
  def Fbe.unmask_repos(options: $options, global: $global, loog: $loog)
35
56
  repos = []
36
57
  octo = Fbe.octo(loog:, global:, options:)
data/lib/fbe/who.rb CHANGED
@@ -6,19 +6,26 @@
6
6
  require_relative '../fbe'
7
7
  require_relative 'octo'
8
8
 
9
- # Converts an ID of GitHub user into a nicely formatted string with their name.
9
+ # Converts a GitHub user ID into a formatted username string.
10
10
  #
11
11
  # The ID of the user (integer) is expected to be stored in the +who+ property of the
12
- # provided +fact+. This function makes a live request to GitHub API in order
13
- # to find out what is the name of the user. For example, the ID +526301+
14
- # will be converted to the +"@yegor256"+ string.
12
+ # provided +fact+. This function makes a live request to GitHub API to
13
+ # retrieve the username. The result is cached globally to minimize API calls.
14
+ # For example, the ID +526301+ will be converted to +"@yegor256"+.
15
15
  #
16
- # @param [Factbase::Fact] fact The fact, where to get the ID of GitHub user
17
- # @param [String] prop The property in the fact, with the ID
18
- # @param [Judges::Options] options The options coming from the +judges+ tool
19
- # @param [Hash] global The hash for global caching
20
- # @param [Loog] loog The logging facility
21
- # @return [String] Full name of the user
16
+ # @param [Factbase::Fact] fact The fact containing the GitHub user ID
17
+ # @param [String, Symbol] prop The property name with the ID (defaults to :who)
18
+ # @param [Judges::Options] options The options from judges tool (uses $options global)
19
+ # @param [Hash] global The hash for global caching (uses $global)
20
+ # @param [Loog] loog The logging facility (uses $loog global)
21
+ # @return [String] Formatted username with @ prefix (e.g., "@yegor256")
22
+ # @raise [RuntimeError] If the specified property doesn't exist in the fact
23
+ # @note Results are cached to reduce GitHub API calls
24
+ # @note Subject to GitHub API rate limits
25
+ # @example Convert user ID to username
26
+ # contributor = fb.query('(eq type "contributor")').first
27
+ # contributor.author_id = 526301
28
+ # puts Fbe.who(contributor, :author_id) # => "@yegor256"
22
29
  def Fbe.who(fact, prop = :who, options: $options, global: $global, loog: $loog)
23
30
  id = fact[prop.to_s]
24
31
  raise "There is no #{prop.inspect} property" if id.nil?
data/lib/fbe.rb CHANGED
@@ -10,5 +10,5 @@
10
10
  # License:: MIT
11
11
  module Fbe
12
12
  # Current version of the gem (changed by +.rultor.yml+ on every release)
13
- VERSION = '0.14.1' unless const_defined?(:VERSION)
13
+ VERSION = '0.16.0' unless const_defined?(:VERSION)
14
14
  end
@@ -274,4 +274,23 @@ class TestOcto < Fbe::Test
274
274
  assert_raises(Octokit::NotFound) { o.repository(404_123) }
275
275
  assert_raises(Octokit::NotFound) { o.repository(404_124) }
276
276
  end
277
+
278
+ def test_fetches_fake_issue_events_has_assigned_event
279
+ o = Fbe.octo(loog: Loog::NULL, global: {}, options: Judges::Options.new({ 'testing' => true }))
280
+ result = o.issue_events('foo/foo', 123)
281
+ assert_instance_of(Array, result)
282
+ assert_equal(7, result.size)
283
+ event = result.find { _1[:event] == 'assigned' }
284
+ assert_equal(608, event[:id])
285
+ assert_pattern do
286
+ event => {
287
+ id: Integer,
288
+ actor: { login: 'user2', id: 422, type: 'User' },
289
+ event: 'assigned',
290
+ created_at: Time,
291
+ assignee: { login: 'user2', id: 422, type: 'User' },
292
+ assigner: { login: 'user', id: 411, type: 'User' }
293
+ }
294
+ end
295
+ end
277
296
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fbe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.14.1
4
+ version: 0.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yegor Bugayenko
@@ -13,42 +13,42 @@ dependencies:
13
13
  name: backtrace
14
14
  requirement: !ruby/object:Gem::Requirement
15
15
  requirements:
16
- - - "~>"
16
+ - - ">"
17
17
  - !ruby/object:Gem::Version
18
18
  version: '0'
19
19
  type: :runtime
20
20
  prerelease: false
21
21
  version_requirements: !ruby/object:Gem::Requirement
22
22
  requirements:
23
- - - "~>"
23
+ - - ">"
24
24
  - !ruby/object:Gem::Version
25
25
  version: '0'
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: baza.rb
28
28
  requirement: !ruby/object:Gem::Requirement
29
29
  requirements:
30
- - - "~>"
30
+ - - ">"
31
31
  - !ruby/object:Gem::Version
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
35
  version_requirements: !ruby/object:Gem::Requirement
36
36
  requirements:
37
- - - "~>"
37
+ - - ">"
38
38
  - !ruby/object:Gem::Version
39
39
  version: '0'
40
40
  - !ruby/object:Gem::Dependency
41
41
  name: decoor
42
42
  requirement: !ruby/object:Gem::Requirement
43
43
  requirements:
44
- - - "~>"
44
+ - - ">"
45
45
  - !ruby/object:Gem::Version
46
46
  version: '0'
47
47
  type: :runtime
48
48
  prerelease: false
49
49
  version_requirements: !ruby/object:Gem::Requirement
50
50
  requirements:
51
- - - "~>"
51
+ - - ">"
52
52
  - !ruby/object:Gem::Version
53
53
  version: '0'
54
54
  - !ruby/object:Gem::Dependency
@@ -71,124 +71,124 @@ dependencies:
71
71
  requirements:
72
72
  - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '2'
74
+ version: '2.0'
75
75
  type: :runtime
76
76
  prerelease: false
77
77
  version_requirements: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - "~>"
80
80
  - !ruby/object:Gem::Version
81
- version: '2'
81
+ version: '2.0'
82
82
  - !ruby/object:Gem::Dependency
83
83
  name: faraday-http-cache
84
84
  requirement: !ruby/object:Gem::Requirement
85
85
  requirements:
86
86
  - - "~>"
87
87
  - !ruby/object:Gem::Version
88
- version: '2'
88
+ version: '2.0'
89
89
  type: :runtime
90
90
  prerelease: false
91
91
  version_requirements: !ruby/object:Gem::Requirement
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '2'
95
+ version: '2.0'
96
96
  - !ruby/object:Gem::Dependency
97
97
  name: faraday-multipart
98
98
  requirement: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1'
102
+ version: '1.0'
103
103
  type: :runtime
104
104
  prerelease: false
105
105
  version_requirements: !ruby/object:Gem::Requirement
106
106
  requirements:
107
107
  - - "~>"
108
108
  - !ruby/object:Gem::Version
109
- version: '1'
109
+ version: '1.0'
110
110
  - !ruby/object:Gem::Dependency
111
111
  name: faraday-retry
112
112
  requirement: !ruby/object:Gem::Requirement
113
113
  requirements:
114
114
  - - "~>"
115
115
  - !ruby/object:Gem::Version
116
- version: '2'
116
+ version: '2.0'
117
117
  type: :runtime
118
118
  prerelease: false
119
119
  version_requirements: !ruby/object:Gem::Requirement
120
120
  requirements:
121
121
  - - "~>"
122
122
  - !ruby/object:Gem::Version
123
- version: '2'
123
+ version: '2.0'
124
124
  - !ruby/object:Gem::Dependency
125
125
  name: graphql-client
126
126
  requirement: !ruby/object:Gem::Requirement
127
127
  requirements:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
- version: '0'
130
+ version: '0.0'
131
131
  type: :runtime
132
132
  prerelease: false
133
133
  version_requirements: !ruby/object:Gem::Requirement
134
134
  requirements:
135
135
  - - "~>"
136
136
  - !ruby/object:Gem::Version
137
- version: '0'
137
+ version: '0.0'
138
138
  - !ruby/object:Gem::Dependency
139
139
  name: judges
140
140
  requirement: !ruby/object:Gem::Requirement
141
141
  requirements:
142
- - - "~>"
142
+ - - ">"
143
143
  - !ruby/object:Gem::Version
144
144
  version: '0'
145
145
  type: :runtime
146
146
  prerelease: false
147
147
  version_requirements: !ruby/object:Gem::Requirement
148
148
  requirements:
149
- - - "~>"
149
+ - - ">"
150
150
  - !ruby/object:Gem::Version
151
151
  version: '0'
152
152
  - !ruby/object:Gem::Dependency
153
153
  name: liquid
154
154
  requirement: !ruby/object:Gem::Requirement
155
155
  requirements:
156
- - - '='
156
+ - - "~>"
157
157
  - !ruby/object:Gem::Version
158
- version: 5.5.1
158
+ version: '5.5'
159
159
  type: :runtime
160
160
  prerelease: false
161
161
  version_requirements: !ruby/object:Gem::Requirement
162
162
  requirements:
163
- - - '='
163
+ - - "~>"
164
164
  - !ruby/object:Gem::Version
165
- version: 5.5.1
165
+ version: '5.5'
166
166
  - !ruby/object:Gem::Dependency
167
167
  name: loog
168
168
  requirement: !ruby/object:Gem::Requirement
169
169
  requirements:
170
- - - "~>"
170
+ - - ">"
171
171
  - !ruby/object:Gem::Version
172
172
  version: '0'
173
173
  type: :runtime
174
174
  prerelease: false
175
175
  version_requirements: !ruby/object:Gem::Requirement
176
176
  requirements:
177
- - - "~>"
177
+ - - ">"
178
178
  - !ruby/object:Gem::Version
179
179
  version: '0'
180
180
  - !ruby/object:Gem::Dependency
181
181
  name: obk
182
182
  requirement: !ruby/object:Gem::Requirement
183
183
  requirements:
184
- - - "~>"
184
+ - - ">"
185
185
  - !ruby/object:Gem::Version
186
186
  version: '0'
187
187
  type: :runtime
188
188
  prerelease: false
189
189
  version_requirements: !ruby/object:Gem::Requirement
190
190
  requirements:
191
- - - "~>"
191
+ - - ">"
192
192
  - !ruby/object:Gem::Version
193
193
  version: '0'
194
194
  - !ruby/object:Gem::Dependency
@@ -197,54 +197,54 @@ dependencies:
197
197
  requirements:
198
198
  - - "~>"
199
199
  - !ruby/object:Gem::Version
200
- version: '9'
200
+ version: '10.0'
201
201
  type: :runtime
202
202
  prerelease: false
203
203
  version_requirements: !ruby/object:Gem::Requirement
204
204
  requirements:
205
205
  - - "~>"
206
206
  - !ruby/object:Gem::Version
207
- version: '9'
207
+ version: '10.0'
208
208
  - !ruby/object:Gem::Dependency
209
209
  name: others
210
210
  requirement: !ruby/object:Gem::Requirement
211
211
  requirements:
212
- - - "~>"
212
+ - - ">"
213
213
  - !ruby/object:Gem::Version
214
214
  version: '0'
215
215
  type: :runtime
216
216
  prerelease: false
217
217
  version_requirements: !ruby/object:Gem::Requirement
218
218
  requirements:
219
- - - "~>"
219
+ - - ">"
220
220
  - !ruby/object:Gem::Version
221
221
  version: '0'
222
222
  - !ruby/object:Gem::Dependency
223
223
  name: tago
224
224
  requirement: !ruby/object:Gem::Requirement
225
225
  requirements:
226
- - - "~>"
226
+ - - ">"
227
227
  - !ruby/object:Gem::Version
228
228
  version: '0'
229
229
  type: :runtime
230
230
  prerelease: false
231
231
  version_requirements: !ruby/object:Gem::Requirement
232
232
  requirements:
233
- - - "~>"
233
+ - - ">"
234
234
  - !ruby/object:Gem::Version
235
235
  version: '0'
236
236
  - !ruby/object:Gem::Dependency
237
237
  name: verbose
238
238
  requirement: !ruby/object:Gem::Requirement
239
239
  requirements:
240
- - - "~>"
240
+ - - ">"
241
241
  - !ruby/object:Gem::Version
242
242
  version: '0'
243
243
  type: :runtime
244
244
  prerelease: false
245
245
  version_requirements: !ruby/object:Gem::Requirement
246
246
  requirements:
247
- - - "~>"
247
+ - - ">"
248
248
  - !ruby/object:Gem::Version
249
249
  version: '0'
250
250
  description: A collection of extensions for a factbase, helping the judges of Zerocracy