nya_pr 0.1.0 → 0.3.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.
- checksums.yaml +4 -4
- data/README.md +75 -0
- data/lib/nya_pr/cli/command.rb +21 -50
- data/lib/nya_pr/config/global.rb +135 -0
- data/lib/nya_pr/config/loader.rb +71 -0
- data/lib/nya_pr/github/client.rb +14 -0
- data/lib/nya_pr/github/connection.rb +38 -0
- data/lib/nya_pr/github/request.rb +99 -0
- data/lib/nya_pr/progress.rb +16 -2
- data/lib/nya_pr/pull_request/config.rb +23 -0
- data/lib/nya_pr/pull_request/filter.rb +23 -0
- data/lib/nya_pr/pull_request/finder.rb +60 -37
- data/lib/nya_pr/pull_request/paths.rb +41 -0
- data/lib/nya_pr/repository/collector.rb +12 -12
- data/lib/nya_pr/repository/config.rb +29 -0
- data/lib/nya_pr/repository/filter.rb +29 -16
- data/lib/nya_pr/repository/finder.rb +13 -7
- data/lib/nya_pr/repository/paths.rb +27 -0
- data/lib/nya_pr/runner.rb +47 -42
- data/lib/nya_pr/version.rb +1 -1
- metadata +25 -5
- data/lib/nya_pr/client.rb +0 -12
- data/lib/nya_pr/connection.rb +0 -34
- data/lib/nya_pr/paths.rb +0 -60
- data/lib/nya_pr/request.rb +0 -97
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: fcee9fc7fd9c910f937d04b717a08558f1400f90029aca67ae4676a90db85031
|
|
4
|
+
data.tar.gz: 97e1630078e1fb9ebb0e01aafa61c2249dd1859cb48e611823e6105f7b422b5a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: bde310b1529f25c20adf0e58031d028448f75b19a7d5e601fbb18432f768fb32ea22d1f7f869703977adf6ee22f40d0cc6a428fb0ca655937fae265d1069238b
|
|
7
|
+
data.tar.gz: 2932d0bba96e2ee071020fc21f0128d0d48b2d6b08f16966622067884d3a7e2ec91f769be0466b5b1e7c45e7f1f1f1b6539fb0012ba74c456f29f07a1f0170c5
|
data/README.md
CHANGED
|
@@ -1,11 +1,42 @@
|
|
|
1
1
|
# NyaPr ฅ^•ﻌ•^ฅ
|
|
2
2
|
|
|
3
|
+

|
|
4
|
+

|
|
5
|
+
|
|
3
6
|
**NyaPr** is a tiny Ruby tool for people who have too many GitHub repositories, too many organizations, too many pull requests, and absolutely no desire to click through all that manually.
|
|
4
7
|
|
|
5
8
|
It collects repositories you own or contribute to, finds their open pull requests, and puts everything into one place.
|
|
6
9
|
|
|
7
10
|
For maximum kawaii.
|
|
8
11
|
|
|
12
|
+
## Quick start
|
|
13
|
+
|
|
14
|
+
Install the gem:
|
|
15
|
+
|
|
16
|
+
```bash
|
|
17
|
+
gem install nya_pr
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
Set your GitHub token:
|
|
21
|
+
|
|
22
|
+
```bash
|
|
23
|
+
export GITHUB_TOKEN=your_token
|
|
24
|
+
```
|
|
25
|
+
|
|
26
|
+
Run NyaPr:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
nya-pr --user your-github-username
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
To include additional users or organizations:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
nya-pr --user your-github-username --owners org-one,org-two
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
NyaPr will collect relevant repositories, find open pull requests, print them to the terminal, and save the results under `data/`.
|
|
39
|
+
|
|
9
40
|
## Why NyaPr?
|
|
10
41
|
|
|
11
42
|
GitHub is perfectly happy to show you:
|
|
@@ -270,9 +301,12 @@ Logs are written to `stderr`, while actual pull request output goes to `stdout`.
|
|
|
270
301
|
-l, --limit N Maximum number of pull requests to collect
|
|
271
302
|
-r, --refresh Refresh repositories from GitHub
|
|
272
303
|
--skip-archived Ignore archived repositories
|
|
304
|
+
--skip-drafts Ignore draft pull requests
|
|
273
305
|
--[no-]progress Show or hide progress bars
|
|
274
306
|
--log-level LEVEL Logging level
|
|
307
|
+
-w, --workers Number of repository scan workers
|
|
275
308
|
-v, --version Show NyaPr version
|
|
309
|
+
-c, --config Configuration file path
|
|
276
310
|
```
|
|
277
311
|
|
|
278
312
|
Example with most options enabled:
|
|
@@ -289,6 +323,47 @@ ruby run.rb \
|
|
|
289
323
|
--log-level debug
|
|
290
324
|
```
|
|
291
325
|
|
|
326
|
+
## YAML configuration
|
|
327
|
+
|
|
328
|
+
NyaPr can load options from a YAML configuration file. By default, it looks for `.nya-pr.yml` in the current directory.
|
|
329
|
+
|
|
330
|
+
```yaml
|
|
331
|
+
username: your-github-username
|
|
332
|
+
|
|
333
|
+
owners:
|
|
334
|
+
- organization-one
|
|
335
|
+
- organization-two
|
|
336
|
+
|
|
337
|
+
limit: 100
|
|
338
|
+
skip_archived: true
|
|
339
|
+
skip_drafts: true
|
|
340
|
+
progress: true
|
|
341
|
+
log_level: info
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
You can also provide a custom configuration file:
|
|
345
|
+
|
|
346
|
+
```bash
|
|
347
|
+
nya-pr --config path/to/config.yml
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
Command-line options override values from the YAML file. Any options not defined in either place use NyaPr's built-in defaults.
|
|
351
|
+
|
|
352
|
+
For example:
|
|
353
|
+
|
|
354
|
+
```yaml
|
|
355
|
+
limit: 200
|
|
356
|
+
progress: true
|
|
357
|
+
```
|
|
358
|
+
|
|
359
|
+
```bash
|
|
360
|
+
nya-pr --limit 50 --no-progress
|
|
361
|
+
```
|
|
362
|
+
|
|
363
|
+
In this case, NyaPr uses `limit: 50` and disables progress output.
|
|
364
|
+
|
|
365
|
+
Unknown configuration options and invalid values are reported as errors.
|
|
366
|
+
|
|
292
367
|
## How repository discovery works
|
|
293
368
|
|
|
294
369
|
For your own GitHub username, NyaPr collects repositories owned by your authenticated account.
|
data/lib/nya_pr/cli/command.rb
CHANGED
|
@@ -3,16 +3,12 @@
|
|
|
3
3
|
module NyaPr
|
|
4
4
|
module Cli
|
|
5
5
|
class Command < Dry::CLI::Command
|
|
6
|
-
LOG_LEVELS = {
|
|
7
|
-
'debug' => Logger::DEBUG,
|
|
8
|
-
'info' => Logger::INFO,
|
|
9
|
-
'warn' => Logger::WARN,
|
|
10
|
-
'error' => Logger::ERROR,
|
|
11
|
-
'fatal' => Logger::FATAL
|
|
12
|
-
}.freeze
|
|
13
|
-
|
|
14
6
|
desc 'Collect open GitHub pull requests'
|
|
15
7
|
|
|
8
|
+
option :config,
|
|
9
|
+
aliases: ['-c'],
|
|
10
|
+
desc: 'Configuration file path'
|
|
11
|
+
|
|
16
12
|
option :username,
|
|
17
13
|
aliases: ['-u', '--user'],
|
|
18
14
|
desc: 'GitHub username'
|
|
@@ -20,7 +16,6 @@ module NyaPr
|
|
|
20
16
|
option :owners,
|
|
21
17
|
aliases: ['-o'],
|
|
22
18
|
type: :array,
|
|
23
|
-
default: [],
|
|
24
19
|
desc: 'Repository owners'
|
|
25
20
|
|
|
26
21
|
option :token,
|
|
@@ -34,76 +29,52 @@ module NyaPr
|
|
|
34
29
|
|
|
35
30
|
option :limit,
|
|
36
31
|
aliases: ['-l'],
|
|
37
|
-
default: PullRequest::Finder::MAX_PULL_REQUESTS,
|
|
38
32
|
desc: 'Maximum number of pull requests'
|
|
39
33
|
|
|
40
34
|
option :refresh,
|
|
41
35
|
aliases: ['-r'],
|
|
42
36
|
type: :boolean,
|
|
43
|
-
default: false,
|
|
44
37
|
desc: 'Refresh repositories from GitHub'
|
|
45
38
|
|
|
46
39
|
option :skip_archived,
|
|
47
40
|
type: :boolean,
|
|
48
|
-
default: false,
|
|
49
41
|
desc: 'Skip archived repositories'
|
|
50
42
|
|
|
43
|
+
option :skip_drafts,
|
|
44
|
+
type: :boolean,
|
|
45
|
+
desc: 'Ignore draft pull requests'
|
|
46
|
+
|
|
51
47
|
option :progress,
|
|
52
48
|
type: :boolean,
|
|
53
|
-
default: true,
|
|
54
49
|
desc: 'Show progress bars'
|
|
55
50
|
|
|
56
51
|
option :log_level,
|
|
57
|
-
values: LOG_LEVELS.keys,
|
|
58
|
-
default: 'info',
|
|
52
|
+
values: Config::Global::LOG_LEVELS.keys,
|
|
59
53
|
desc: 'Log level'
|
|
60
54
|
|
|
55
|
+
option :workers,
|
|
56
|
+
aliases: ['-w'],
|
|
57
|
+
desc: 'Number of repository scan workers'
|
|
58
|
+
|
|
61
59
|
option :version,
|
|
62
60
|
aliases: ['-v'],
|
|
63
61
|
type: :flag,
|
|
64
62
|
desc: 'Show version'
|
|
65
63
|
|
|
66
|
-
def call(version: false, **options)
|
|
64
|
+
def call(version: false, config: nil, **options)
|
|
67
65
|
if version
|
|
68
66
|
puts NyaPr::VERSION
|
|
69
67
|
return
|
|
70
68
|
end
|
|
71
69
|
|
|
72
|
-
|
|
73
|
-
validate_username!(options)
|
|
74
|
-
|
|
75
|
-
Runner.new(options).run
|
|
76
|
-
end
|
|
77
|
-
|
|
78
|
-
private
|
|
79
|
-
|
|
80
|
-
def normalize_options!(options)
|
|
81
|
-
options[:owners] = normalize_owners(options[:owners])
|
|
82
|
-
options[:limit] = normalize_limit(options[:limit])
|
|
83
|
-
options[:log_level] = LOG_LEVELS.fetch(options[:log_level])
|
|
84
|
-
end
|
|
85
|
-
|
|
86
|
-
def normalize_owners(owners)
|
|
87
|
-
Array(owners).
|
|
88
|
-
flat_map { |owner| owner.split(',') }.
|
|
89
|
-
map(&:strip).
|
|
90
|
-
reject(&:empty?)
|
|
91
|
-
end
|
|
92
|
-
|
|
93
|
-
def normalize_limit(value)
|
|
94
|
-
limit = Integer(value)
|
|
95
|
-
|
|
96
|
-
return limit if limit.positive?
|
|
97
|
-
|
|
98
|
-
raise NyaPr::Error, 'limit must be greater than 0'
|
|
99
|
-
rescue ArgumentError, TypeError
|
|
100
|
-
raise NyaPr::Error, 'limit must be a positive integer'
|
|
101
|
-
end
|
|
102
|
-
|
|
103
|
-
def validate_username!(options)
|
|
104
|
-
return unless options[:username].to_s.empty?
|
|
70
|
+
file_options = Config::Loader.load(config)
|
|
105
71
|
|
|
106
|
-
|
|
72
|
+
Runner.new(
|
|
73
|
+
Config::Global.from_options(
|
|
74
|
+
options,
|
|
75
|
+
file_options: file_options
|
|
76
|
+
)
|
|
77
|
+
).run
|
|
107
78
|
end
|
|
108
79
|
end
|
|
109
80
|
end
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NyaPr
|
|
4
|
+
module Config
|
|
5
|
+
class Global < Data.define(
|
|
6
|
+
:username,
|
|
7
|
+
:owners,
|
|
8
|
+
:token,
|
|
9
|
+
:repositories_csv,
|
|
10
|
+
:pull_requests_dir,
|
|
11
|
+
:limit,
|
|
12
|
+
:refresh,
|
|
13
|
+
:skip_archived,
|
|
14
|
+
:skip_drafts,
|
|
15
|
+
:progress,
|
|
16
|
+
:log_level,
|
|
17
|
+
:workers
|
|
18
|
+
)
|
|
19
|
+
LOG_LEVELS = {
|
|
20
|
+
'debug' => Logger::DEBUG,
|
|
21
|
+
'info' => Logger::INFO,
|
|
22
|
+
'warn' => Logger::WARN,
|
|
23
|
+
'error' => Logger::ERROR,
|
|
24
|
+
'fatal' => Logger::FATAL
|
|
25
|
+
}.freeze
|
|
26
|
+
|
|
27
|
+
DEFAULTS = {
|
|
28
|
+
owners: [],
|
|
29
|
+
token: nil,
|
|
30
|
+
repositories_csv: nil,
|
|
31
|
+
pull_requests_dir: nil,
|
|
32
|
+
limit: PullRequest::Config::DEFAULT_LIMIT,
|
|
33
|
+
refresh: false,
|
|
34
|
+
skip_archived: false,
|
|
35
|
+
skip_drafts: false,
|
|
36
|
+
progress: true,
|
|
37
|
+
log_level: 'info',
|
|
38
|
+
workers: Repository::Config::DEFAULT_WORKERS
|
|
39
|
+
}.freeze
|
|
40
|
+
|
|
41
|
+
BOOLEAN_KEYS = %i[
|
|
42
|
+
refresh
|
|
43
|
+
skip_archived
|
|
44
|
+
skip_drafts
|
|
45
|
+
progress
|
|
46
|
+
].freeze
|
|
47
|
+
|
|
48
|
+
class << self
|
|
49
|
+
def from_options(options, file_options: {})
|
|
50
|
+
validate_keys!(file_options)
|
|
51
|
+
|
|
52
|
+
attributes = DEFAULTS.
|
|
53
|
+
merge(file_options).
|
|
54
|
+
merge(options.compact)
|
|
55
|
+
|
|
56
|
+
build(attributes)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def build(attributes)
|
|
62
|
+
normalized = attributes.merge(
|
|
63
|
+
username: normalize_username(attributes[:username]),
|
|
64
|
+
owners: normalize_owners(attributes[:owners]),
|
|
65
|
+
limit: normalize_positive_integer(attributes[:limit], :limit),
|
|
66
|
+
workers: normalize_positive_integer(attributes[:workers], :workers),
|
|
67
|
+
log_level: normalize_log_level(attributes[:log_level]),
|
|
68
|
+
**normalize_booleans(attributes)
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
new(**normalized)
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
def normalize_username(value)
|
|
75
|
+
username = value.to_s.strip
|
|
76
|
+
|
|
77
|
+
validate_username!(username)
|
|
78
|
+
|
|
79
|
+
username
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
def normalize_booleans(attributes)
|
|
83
|
+
BOOLEAN_KEYS.to_h do |key|
|
|
84
|
+
[key, normalize_boolean(attributes[key], key)]
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def validate_keys!(options)
|
|
89
|
+
unknown = options.keys - members
|
|
90
|
+
|
|
91
|
+
return if unknown.empty?
|
|
92
|
+
|
|
93
|
+
raise NyaPr::Error,
|
|
94
|
+
"Unknown config option(s): #{unknown.join(', ')}"
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
def normalize_owners(owners)
|
|
98
|
+
Array(owners).
|
|
99
|
+
flat_map { |owner| owner.to_s.split(',') }.
|
|
100
|
+
map(&:strip).
|
|
101
|
+
reject(&:empty?)
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def normalize_positive_integer(value, name)
|
|
105
|
+
number = Integer(value)
|
|
106
|
+
|
|
107
|
+
return number if number.positive?
|
|
108
|
+
|
|
109
|
+
raise NyaPr::Error, "#{name} must be greater than 0"
|
|
110
|
+
rescue ArgumentError, TypeError
|
|
111
|
+
raise NyaPr::Error, "#{name} must be a positive integer"
|
|
112
|
+
end
|
|
113
|
+
|
|
114
|
+
def normalize_boolean(value, name)
|
|
115
|
+
return value if [true, false].include?(value)
|
|
116
|
+
|
|
117
|
+
raise NyaPr::Error, "#{name} must be true or false"
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
def normalize_log_level(value)
|
|
121
|
+
LOG_LEVELS.fetch(value.to_s) do
|
|
122
|
+
raise NyaPr::Error,
|
|
123
|
+
"Invalid log level: #{value}"
|
|
124
|
+
end
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
def validate_username!(username)
|
|
128
|
+
return unless username.empty?
|
|
129
|
+
|
|
130
|
+
raise NyaPr::Error, 'GitHub username is required'
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
135
|
+
end
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'yaml'
|
|
4
|
+
|
|
5
|
+
module NyaPr
|
|
6
|
+
module Config
|
|
7
|
+
class Loader
|
|
8
|
+
DEFAULT_PATH = '.nya-pr.yml'
|
|
9
|
+
|
|
10
|
+
def self.load(path = nil)
|
|
11
|
+
new(path).load
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
attr_reader :path
|
|
15
|
+
|
|
16
|
+
def initialize(path = nil)
|
|
17
|
+
@explicit_path = !path.nil?
|
|
18
|
+
@path = Pathname.new(path || DEFAULT_PATH)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def load
|
|
22
|
+
unless path.exist?
|
|
23
|
+
return {} unless explicit_path?
|
|
24
|
+
|
|
25
|
+
raise NyaPr::Error, "Config file not found: #{path}"
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
parse
|
|
29
|
+
rescue Psych::SyntaxError => e
|
|
30
|
+
raise NyaPr::Error,
|
|
31
|
+
"Invalid YAML in #{path}: #{e.problem}"
|
|
32
|
+
rescue Errno::EACCES, Errno::ENOENT => e
|
|
33
|
+
raise NyaPr::Error,
|
|
34
|
+
"Cannot read config file #{path}: #{e.message}"
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
private
|
|
38
|
+
|
|
39
|
+
def explicit_path?
|
|
40
|
+
@explicit_path
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def parse
|
|
44
|
+
data = YAML.safe_load_file(
|
|
45
|
+
path.to_s,
|
|
46
|
+
aliases: false
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
return {} if data.nil?
|
|
50
|
+
|
|
51
|
+
unless data.is_a?(Hash)
|
|
52
|
+
raise NyaPr::Error,
|
|
53
|
+
"Config file must contain a mapping: #{path}"
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
symbolize_keys(data)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def symbolize_keys(data)
|
|
60
|
+
data.to_h do |key, value|
|
|
61
|
+
unless key.is_a?(String) || key.is_a?(Symbol)
|
|
62
|
+
raise NyaPr::Error,
|
|
63
|
+
"Invalid config key: #{key.inspect}"
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
[key.to_sym, value]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'faraday'
|
|
4
|
+
require 'faraday/gzip'
|
|
5
|
+
|
|
6
|
+
module NyaPr
|
|
7
|
+
module Github
|
|
8
|
+
module Connection
|
|
9
|
+
API_URL = 'https://api.github.com'
|
|
10
|
+
API_VERSION = '2026-03-10'
|
|
11
|
+
|
|
12
|
+
def connection(client)
|
|
13
|
+
Faraday.new(connection_options(client)) do |faraday|
|
|
14
|
+
faraday.request :gzip
|
|
15
|
+
faraday.adapter Faraday.default_adapter
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
private
|
|
20
|
+
|
|
21
|
+
def connection_options(client)
|
|
22
|
+
{
|
|
23
|
+
url: API_URL,
|
|
24
|
+
headers: {
|
|
25
|
+
accept: 'application/vnd.github+json',
|
|
26
|
+
user_agent: "nya_pr gem/#{NyaPr::VERSION}",
|
|
27
|
+
authorization: "Bearer #{client.token}",
|
|
28
|
+
'X-GitHub-Api-Version': client.options.fetch(:api_version, API_VERSION)
|
|
29
|
+
},
|
|
30
|
+
request: {
|
|
31
|
+
timeout: client.options.fetch(:timeout, 60),
|
|
32
|
+
open_timeout: client.options.fetch(:open_timeout, 10)
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'oj'
|
|
4
|
+
|
|
5
|
+
module NyaPr
|
|
6
|
+
module Github
|
|
7
|
+
module Request
|
|
8
|
+
include Connection
|
|
9
|
+
|
|
10
|
+
MAX_PAGES = 1_000
|
|
11
|
+
PER_PAGE = 100
|
|
12
|
+
|
|
13
|
+
def get(path, params = {})
|
|
14
|
+
_response, body = do_get(path, params)
|
|
15
|
+
|
|
16
|
+
body
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def paginate(path, params = {})
|
|
20
|
+
params = params.merge(per_page: params.fetch(:per_page, PER_PAGE))
|
|
21
|
+
|
|
22
|
+
page = 1
|
|
23
|
+
result = []
|
|
24
|
+
|
|
25
|
+
loop do
|
|
26
|
+
raise NyaPr::Error, 'Pagination limit exceeded' if page > MAX_PAGES
|
|
27
|
+
|
|
28
|
+
NyaPr.logger.debug("Fetching page #{page} for #{path}")
|
|
29
|
+
response, body = do_get(path, params.merge(page: page))
|
|
30
|
+
|
|
31
|
+
raise NyaPr::Error, 'Expected paginated response to be an array' unless body.is_a?(Array)
|
|
32
|
+
|
|
33
|
+
result.concat(body)
|
|
34
|
+
|
|
35
|
+
break if body.empty?
|
|
36
|
+
break unless next_page?(response)
|
|
37
|
+
|
|
38
|
+
page += 1
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
result
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
private
|
|
45
|
+
|
|
46
|
+
def do_get(path, params = {})
|
|
47
|
+
prepared_path = prepare(path)
|
|
48
|
+
|
|
49
|
+
NyaPr.logger.debug("GET #{prepared_path} #{params.inspect}")
|
|
50
|
+
|
|
51
|
+
response = connection(client).get(prepared_path, params)
|
|
52
|
+
body = parse_body(response)
|
|
53
|
+
|
|
54
|
+
NyaPr.logger.debug(
|
|
55
|
+
"GET #{prepared_path} -> HTTP #{response.status}"
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
raise_on_error!(response, body, prepared_path)
|
|
59
|
+
|
|
60
|
+
[response, body]
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
def parse_body(response)
|
|
64
|
+
return nil if response.body.nil? || response.body.empty?
|
|
65
|
+
|
|
66
|
+
Oj.load(response.body)
|
|
67
|
+
rescue Oj::ParseError
|
|
68
|
+
raise NyaPr::Error, "Failed to parse response: #{response.body}"
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def raise_on_error!(response, body, path)
|
|
72
|
+
return if response.success?
|
|
73
|
+
|
|
74
|
+
message =
|
|
75
|
+
if body.is_a?(Hash)
|
|
76
|
+
body['message'] || body
|
|
77
|
+
else
|
|
78
|
+
body
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
raise NyaPr::Error.new(
|
|
82
|
+
"GET #{path}: GitHub API error #{response.status}: #{message}",
|
|
83
|
+
status: response.status
|
|
84
|
+
)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
def next_page?(response)
|
|
88
|
+
response.headers['link']&.include?('rel="next"')
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
def prepare(path)
|
|
92
|
+
path.
|
|
93
|
+
delete_prefix('/').
|
|
94
|
+
gsub(%r{//}, '/').
|
|
95
|
+
gsub(%r{/+\z}, '')
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
end
|
|
99
|
+
end
|
data/lib/nya_pr/progress.rb
CHANGED
|
@@ -19,7 +19,14 @@ module NyaPr
|
|
|
19
19
|
@output = output
|
|
20
20
|
@enabled = enabled
|
|
21
21
|
@current = 0
|
|
22
|
+
|
|
23
|
+
# Use a monotonic clock so elapsed time is not affected by system
|
|
24
|
+
# clock changes while the progress bar is running.
|
|
22
25
|
@started_at = monotonic_time
|
|
26
|
+
|
|
27
|
+
# Progress may be updated by multiple worker threads. The mutex keeps
|
|
28
|
+
# the counter update and terminal rendering atomic relative to each
|
|
29
|
+
# other, preventing lost increments and interleaved output.
|
|
23
30
|
@mutex = Mutex.new
|
|
24
31
|
|
|
25
32
|
render if enabled?
|
|
@@ -29,6 +36,7 @@ module NyaPr
|
|
|
29
36
|
return unless enabled?
|
|
30
37
|
|
|
31
38
|
mutex.synchronize do
|
|
39
|
+
# Never allow the displayed counter to exceed the expected total.
|
|
32
40
|
@current = [@current + step, total].min
|
|
33
41
|
render
|
|
34
42
|
end
|
|
@@ -38,6 +46,8 @@ module NyaPr
|
|
|
38
46
|
return unless enabled?
|
|
39
47
|
|
|
40
48
|
mutex.synchronize do
|
|
49
|
+
# Render the final known state, then move subsequent output
|
|
50
|
+
# to a new terminal line.
|
|
41
51
|
render
|
|
42
52
|
output.puts
|
|
43
53
|
output.flush
|
|
@@ -49,11 +59,13 @@ module NyaPr
|
|
|
49
59
|
attr_reader :current, :started_at, :mutex
|
|
50
60
|
|
|
51
61
|
def enabled?
|
|
62
|
+
# A zero-sized task does not need a progress bar.
|
|
52
63
|
@enabled && total.positive?
|
|
53
64
|
end
|
|
54
65
|
|
|
55
66
|
def render
|
|
56
67
|
output.print(
|
|
68
|
+
# Return to the beginning of the line and clear the previous render.
|
|
57
69
|
"\r\e[2K",
|
|
58
70
|
title,
|
|
59
71
|
' [',
|
|
@@ -63,7 +75,6 @@ module NyaPr
|
|
|
63
75
|
"#{percentage}% ",
|
|
64
76
|
"ETA #{eta}"
|
|
65
77
|
)
|
|
66
|
-
|
|
67
78
|
output.flush
|
|
68
79
|
end
|
|
69
80
|
|
|
@@ -99,8 +110,11 @@ module NyaPr
|
|
|
99
110
|
return "#{seconds}s" if seconds < 60
|
|
100
111
|
|
|
101
112
|
minutes, seconds = seconds.divmod(60)
|
|
113
|
+
return "#{minutes}m #{seconds.to_s.rjust(2, '0')}s" if minutes < 60
|
|
114
|
+
|
|
115
|
+
hours, minutes = minutes.divmod(60)
|
|
102
116
|
|
|
103
|
-
"#{
|
|
117
|
+
"#{hours}h #{minutes.to_s.rjust(2, '0')}m"
|
|
104
118
|
end
|
|
105
119
|
|
|
106
120
|
def monotonic_time
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NyaPr
|
|
4
|
+
module PullRequest
|
|
5
|
+
class Config < Data.define(
|
|
6
|
+
:limit,
|
|
7
|
+
:skip_drafts,
|
|
8
|
+
:progress_enabled,
|
|
9
|
+
:pull_requests_dir
|
|
10
|
+
)
|
|
11
|
+
DEFAULT_LIMIT = 100
|
|
12
|
+
|
|
13
|
+
def self.from_app(config)
|
|
14
|
+
new(
|
|
15
|
+
limit: config.limit,
|
|
16
|
+
skip_drafts: config.skip_drafts,
|
|
17
|
+
progress_enabled: config.progress,
|
|
18
|
+
pull_requests_dir: config.pull_requests_dir
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module NyaPr
|
|
4
|
+
module PullRequest
|
|
5
|
+
class Filter
|
|
6
|
+
attr_reader :config
|
|
7
|
+
|
|
8
|
+
def initialize(config)
|
|
9
|
+
@config = config
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def match?(pull_request)
|
|
13
|
+
return false if config.skip_drafts && pull_request['draft']
|
|
14
|
+
|
|
15
|
+
true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def ===(pull_request)
|
|
19
|
+
match?(pull_request)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|