plan_my_stuff 0.27.0 → 0.28.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4162f792a9b4fbc7cced8a9a91721c21d15010189cf38021b87d20d53dbcb56
4
- data.tar.gz: 72c6220c9be50c083360357ba28f1cb7225c784ed9c8813430e24e9e27736f04
3
+ metadata.gz: 9aac5ec777cf9b53a459843e9bdbf1177178fe1623457a60d266e993db3d2d93
4
+ data.tar.gz: 1b7089b760fa0552e3b861732472e43cab09667699e1528703809a2ce753254f
5
5
  SHA512:
6
- metadata.gz: af715bae691caff87d81935e140a3bc2d4af7ef49780686f85b8f145ce9e7a6ff32a6ea689c697a4bc6d193ca0612ff7147a850ea5088876282c4a6bf284ab26
7
- data.tar.gz: 94d67d34bc302ceb3ec4fa815d5420f60323a9be1c6b4003af4948675861328d5c0ae74c7cd71031a9102c30af7e63a7586d72b64136263c865b7f3cdd46d8ce
6
+ metadata.gz: 84f1cc4e7dd87ed3e33f2095d3c0f57c9ad61972ffaa5ed1d9379dfb6bb0e7bc1b07491c76c6c4f4618c39b977d7240689de5552a8c9f60fe1b474c29dde2637
7
+ data.tar.gz: 1d355a051c6d6f0903c80558019790ab0e1d84adb8885b28b0c18b57802ed16c338ab7793ca24f535dc01980296fcc33b19eacc3acd204d08586db25d63138d4
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.28.0
4
+
5
+ ### Added
6
+
7
+ - `Issue.list_page_info(...)` returns a `PlanMyStuff::Issue::PageInfo` value object exposing `.issues`, `.page`,
8
+ `.per_page`, `.has_next?`, and `.has_prev?`. `Issue.list` now delegates to it; return type unchanged
9
+ (`Array<Issue>`). Closes #63.
10
+
3
11
  ## 0.27.0
4
12
 
5
13
  ### Added
@@ -9,6 +9,21 @@ module PlanMyStuff
9
9
  # - `Issue.create!` / `Issue.find` / `Issue.list` return persisted instances
10
10
  # - `issue.save!` / `issue.update!` / `issue.reload` for persistence
11
11
  class Issue < PlanMyStuff::ApplicationRecord
12
+ # Value object returned by +Issue.list_page_info+: the fetched issues plus pagination metadata read from the
13
+ # +Link+ header of the +list_issues+ response. +:total_pages+ is intentionally absent -- GitHub's issues endpoint
14
+ # is cursor-paginated and never advertises +rel="last"+.
15
+ #
16
+ # @!attribute [r] issues
17
+ # @return [Array<PlanMyStuff::Issue>]
18
+ # @!attribute [r] page
19
+ # @return [Integer] echo of the requested page
20
+ # @!attribute [r] per_page
21
+ # @return [Integer] echo of the requested per_page
22
+ PageInfo = Data.define(:issues, :page, :per_page, :has_next, :has_prev) do
23
+ alias_method :has_next?, :has_next
24
+ alias_method :has_prev?, :has_prev
25
+ end
26
+
12
27
  include PlanMyStuff::IssueExtractions::Approvals
13
28
  include PlanMyStuff::IssueExtractions::Links
14
29
  include PlanMyStuff::IssueExtractions::Viewers
@@ -332,7 +347,38 @@ module PlanMyStuff
332
347
  #
333
348
  # @return [Array<PlanMyStuff::Issue>]
334
349
  #
335
- def list(
350
+ def list(**)
351
+ list_page_info(**).issues
352
+ end
353
+
354
+ # Lists GitHub issues like +.list+, but returns a +PageInfo+ value object carrying the issues plus pagination
355
+ # metadata read from the response's +Link+ header in the same request. Use this over +.list+ when a caller needs
356
+ # to know whether more pages exist (e.g. to render "Next"/"Prev" controls) without an optimistic +page + 1+
357
+ # probe.
358
+ #
359
+ # Shares the entire parameter surface, filtering, and PR-rejection behavior of +.list+; see it for semantics.
360
+ #
361
+ # Note the PR-filter wart: +per_page+ caps GitHub's raw item count (issues + PRs), but PRs are stripped
362
+ # client-side afterward, so +page_info.issues.length+ may be smaller than +per_page+. +has_next?+ comes straight
363
+ # from the +Link+ header, so it reflects raw items too -- a page can report +has_next? == true+ while showing
364
+ # fewer than +per_page+ issues.
365
+ #
366
+ # @raise [ArgumentError] when +priority_list: false+ is passed, or when +issue_type:+ is an Array
367
+ # @raise [PlanMyStuff::IssueFieldsNotEnabledError] when +issue_fields:+ is passed and
368
+ # +config.issue_fields_enabled+ is +false+
369
+ #
370
+ # @param repo [Symbol, String, nil] defaults to config.default_repo
371
+ # @param state [Symbol] :open, :closed, or :all
372
+ # @param labels [Array<String>]
373
+ # @param issue_type [String, Symbol, nil] a single GitHub issue type name
374
+ # @param issue_fields [Hash{String,Symbol => Object,Range,nil}, nil] GitHub Issue Field equality / range filters
375
+ # @param priority_list [Boolean, nil] when +true+, restricts to +Priority List+ +Yes+ issues
376
+ # @param page [Integer]
377
+ # @param per_page [Integer]
378
+ #
379
+ # @return [PlanMyStuff::Issue::PageInfo]
380
+ #
381
+ def list_page_info(
336
382
  repo: nil,
337
383
  state: :open,
338
384
  labels: [],
@@ -366,8 +412,16 @@ module PlanMyStuff
366
412
  params[:issue_field_values] = field_pairs.join(',') if field_pairs.present?
367
413
 
368
414
  github_issues = client.rest(:list_issues, resolved_repo, **params)
415
+ rels = client.last_response&.rels || {}
369
416
  filtered = github_issues.reject { |gi| gi.respond_to?(:pull_request) && gi.pull_request }
370
- filtered.map { |gi| build(gi, repo: resolved_repo) }
417
+
418
+ PageInfo.new(
419
+ issues: filtered.map { |gi| build(gi, repo: resolved_repo) },
420
+ page: page,
421
+ per_page: per_page,
422
+ has_next: rels[:next].present?,
423
+ has_prev: rels[:prev].present?,
424
+ )
371
425
  end
372
426
 
373
427
  # Convenience shortcut for +list(priority_list: true, ...)+. See +.list+ for parameter semantics.
@@ -3,7 +3,7 @@
3
3
  module PlanMyStuff
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 27
6
+ MINOR = 28
7
7
  TINY = 0
8
8
 
9
9
  # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plan_my_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance