horn_of_plenty 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (114) hide show
  1. checksums.yaml +7 -0
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/LICENSE.txt +19 -0
  5. data/README.md +36 -0
  6. data/lib/horn_of_plenty.rb +22 -0
  7. data/lib/horn_of_plenty/adapters/github/client.rb +82 -0
  8. data/lib/horn_of_plenty/adapters/github/collections/card.rb +46 -0
  9. data/lib/horn_of_plenty/adapters/github/configuration.rb +38 -0
  10. data/lib/horn_of_plenty/adapters/github/error.rb +44 -0
  11. data/lib/horn_of_plenty/adapters/github/parsers/board.rb +52 -0
  12. data/lib/horn_of_plenty/adapters/github/parsers/card.rb +91 -0
  13. data/lib/horn_of_plenty/adapters/github/parsers/issue.rb +95 -0
  14. data/lib/horn_of_plenty/adapters/github/parsers/lane.rb +50 -0
  15. data/lib/horn_of_plenty/adapters/github/parsers/pull_request.rb +38 -0
  16. data/lib/horn_of_plenty/adapters/github/queries/list_boards.rb +18 -0
  17. data/lib/horn_of_plenty/adapters/github/queries/list_cards.rb +19 -0
  18. data/lib/horn_of_plenty/adapters/github/queries/list_issues.rb +22 -0
  19. data/lib/horn_of_plenty/adapters/github/queries/list_lanes.rb +19 -0
  20. data/lib/horn_of_plenty/adapters/github/queries/list_pull_requests.rb +22 -0
  21. data/lib/horn_of_plenty/adapters/github/repositories/board.rb +24 -0
  22. data/lib/horn_of_plenty/adapters/github/repositories/card.rb +24 -0
  23. data/lib/horn_of_plenty/adapters/github/repositories/issue.rb +24 -0
  24. data/lib/horn_of_plenty/adapters/github/repositories/lane.rb +24 -0
  25. data/lib/horn_of_plenty/adapters/github/repositories/pull_request.rb +24 -0
  26. data/lib/horn_of_plenty/adapters/github/requests/list_boards.rb +50 -0
  27. data/lib/horn_of_plenty/adapters/github/requests/list_cards.rb +52 -0
  28. data/lib/horn_of_plenty/adapters/github/requests/list_issues.rb +50 -0
  29. data/lib/horn_of_plenty/adapters/github/requests/list_lanes.rb +52 -0
  30. data/lib/horn_of_plenty/adapters/github/requests/list_pull_requests.rb +50 -0
  31. data/lib/horn_of_plenty/adapters/github/response.rb +16 -0
  32. data/lib/horn_of_plenty/adapters/github/responses/list_boards.rb +17 -0
  33. data/lib/horn_of_plenty/adapters/github/responses/list_cards.rb +23 -0
  34. data/lib/horn_of_plenty/adapters/github/responses/list_issues.rb +18 -0
  35. data/lib/horn_of_plenty/adapters/github/responses/list_lanes.rb +17 -0
  36. data/lib/horn_of_plenty/adapters/github/responses/list_pull_requests.rb +17 -0
  37. data/lib/horn_of_plenty/collection.rb +60 -0
  38. data/lib/horn_of_plenty/core_ext/string.rb +95 -0
  39. data/lib/horn_of_plenty/models/board.rb +32 -0
  40. data/lib/horn_of_plenty/models/card.rb +51 -0
  41. data/lib/horn_of_plenty/models/issue.rb +46 -0
  42. data/lib/horn_of_plenty/models/lane.rb +30 -0
  43. data/lib/horn_of_plenty/models/parsable.rb +44 -0
  44. data/lib/horn_of_plenty/models/pull_request.rb +12 -0
  45. data/lib/horn_of_plenty/null_objects/board.rb +10 -0
  46. data/lib/horn_of_plenty/null_objects/card.rb +10 -0
  47. data/lib/horn_of_plenty/null_objects/issue.rb +10 -0
  48. data/lib/horn_of_plenty/null_objects/lane.rb +10 -0
  49. data/lib/horn_of_plenty/null_objects/pull_request.rb +10 -0
  50. data/lib/horn_of_plenty/paginator.rb +109 -0
  51. data/lib/horn_of_plenty/parsers/hash.rb +95 -0
  52. data/lib/horn_of_plenty/queries/fetch.rb +36 -0
  53. data/lib/horn_of_plenty/repositories/board.rb +26 -0
  54. data/lib/horn_of_plenty/repositories/card.rb +26 -0
  55. data/lib/horn_of_plenty/repositories/issue.rb +26 -0
  56. data/lib/horn_of_plenty/repositories/lane.rb +26 -0
  57. data/lib/horn_of_plenty/repositories/pull_request.rb +26 -0
  58. data/lib/horn_of_plenty/repository.rb +29 -0
  59. data/lib/horn_of_plenty/request.rb +32 -0
  60. data/lib/horn_of_plenty/response.rb +44 -0
  61. data/lib/horn_of_plenty/version.rb +4 -0
  62. data/spec/fixtures/responses/board_github.json +29 -0
  63. data/spec/fixtures/responses/card_github.json +7 -0
  64. data/spec/fixtures/responses/issue_github.json +163 -0
  65. data/spec/fixtures/responses/lane_github.json +7 -0
  66. data/spec/fixtures/responses/pull_request_github.json +361 -0
  67. data/spec/lib/horn_of_plenty/adapters/github/client_spec.rb +12 -0
  68. data/spec/lib/horn_of_plenty/adapters/github/collections/card_spec.rb +14 -0
  69. data/spec/lib/horn_of_plenty/adapters/github/configuration_spec.rb +12 -0
  70. data/spec/lib/horn_of_plenty/adapters/github/error_spec.rb +35 -0
  71. data/spec/lib/horn_of_plenty/adapters/github/parsers/board_spec.rb +39 -0
  72. data/spec/lib/horn_of_plenty/adapters/github/parsers/card_spec.rb +64 -0
  73. data/spec/lib/horn_of_plenty/adapters/github/parsers/issue_spec.rb +47 -0
  74. data/spec/lib/horn_of_plenty/adapters/github/parsers/lane_spec.rb +38 -0
  75. data/spec/lib/horn_of_plenty/adapters/github/parsers/pull_request_spec.rb +50 -0
  76. data/spec/lib/horn_of_plenty/adapters/github/queries/list_boards_spec.rb +19 -0
  77. data/spec/lib/horn_of_plenty/adapters/github/queries/list_cards_spec.rb +19 -0
  78. data/spec/lib/horn_of_plenty/adapters/github/queries/list_issues_spec.rb +19 -0
  79. data/spec/lib/horn_of_plenty/adapters/github/queries/list_lanes_spec.rb +19 -0
  80. data/spec/lib/horn_of_plenty/adapters/github/queries/list_pull_requests_spec.rb +19 -0
  81. data/spec/lib/horn_of_plenty/adapters/github/repositories/board_spec.rb +22 -0
  82. data/spec/lib/horn_of_plenty/adapters/github/repositories/card_spec.rb +67 -0
  83. data/spec/lib/horn_of_plenty/adapters/github/repositories/issue_spec.rb +22 -0
  84. data/spec/lib/horn_of_plenty/adapters/github/repositories/lane_spec.rb +25 -0
  85. data/spec/lib/horn_of_plenty/adapters/github/repositories/pull_request_spec.rb +24 -0
  86. data/spec/lib/horn_of_plenty/adapters/github/requests/list_boards_spec.rb +42 -0
  87. data/spec/lib/horn_of_plenty/adapters/github/requests/list_cards_spec.rb +51 -0
  88. data/spec/lib/horn_of_plenty/adapters/github/requests/list_issues_spec.rb +42 -0
  89. data/spec/lib/horn_of_plenty/adapters/github/requests/list_lanes_spec.rb +51 -0
  90. data/spec/lib/horn_of_plenty/adapters/github/requests/list_pull_requests_spec.rb +42 -0
  91. data/spec/lib/horn_of_plenty/adapters/github/responses/list_boards_spec.rb +78 -0
  92. data/spec/lib/horn_of_plenty/adapters/github/responses/list_cards_spec.rb +86 -0
  93. data/spec/lib/horn_of_plenty/adapters/github/responses/list_issues_spec.rb +104 -0
  94. data/spec/lib/horn_of_plenty/adapters/github/responses/list_lanes_spec.rb +86 -0
  95. data/spec/lib/horn_of_plenty/adapters/github/responses/list_pull_requests_spec.rb +109 -0
  96. data/spec/lib/horn_of_plenty/models/board_spec.rb +10 -0
  97. data/spec/lib/horn_of_plenty/models/card_spec.rb +10 -0
  98. data/spec/lib/horn_of_plenty/models/issue_spec.rb +10 -0
  99. data/spec/lib/horn_of_plenty/models/lane_spec.rb +10 -0
  100. data/spec/lib/horn_of_plenty/models/pull_request_spec.rb +10 -0
  101. data/spec/lib/horn_of_plenty/null_objects/board_spec.rb +10 -0
  102. data/spec/lib/horn_of_plenty/null_objects/card_spec.rb +10 -0
  103. data/spec/lib/horn_of_plenty/null_objects/issue_spec.rb +10 -0
  104. data/spec/lib/horn_of_plenty/null_objects/lane_spec.rb +10 -0
  105. data/spec/lib/horn_of_plenty/null_objects/pull_request_spec.rb +10 -0
  106. data/spec/lib/horn_of_plenty/queries/fetch_spec.rb +15 -0
  107. data/spec/lib/horn_of_plenty/repositories/board_spec.rb +48 -0
  108. data/spec/lib/horn_of_plenty/repositories/card_spec.rb +51 -0
  109. data/spec/lib/horn_of_plenty/repositories/issue_spec.rb +48 -0
  110. data/spec/lib/horn_of_plenty/repositories/lane_spec.rb +51 -0
  111. data/spec/lib/horn_of_plenty/repositories/pull_request_spec.rb +50 -0
  112. data/spec/support/patterns.rb +1 -0
  113. metadata +396 -0
  114. metadata.gz.sig +0 -0
@@ -0,0 +1,95 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/parsers/hash'
3
+ require 'horn_of_plenty/null_objects/issue'
4
+ require 'horn_of_plenty/models/issue'
5
+
6
+ # rubocop:disable Style/SpaceAroundOperators
7
+ module HornOfPlenty
8
+ module Adapters
9
+ module Github
10
+ module Parsers
11
+ class Issue
12
+ include HornOfPlenty::Parsers::Hash
13
+
14
+ attr_accessor :raw
15
+
16
+ def initialize(raw:)
17
+ self.raw = raw
18
+ end
19
+
20
+ def id
21
+ @id ||= parse_text(raw, 'number')
22
+ end
23
+
24
+ def author_id
25
+ @author_id ||= parse_text(raw, 'user/:/login')
26
+ end
27
+
28
+ def assignee_ids
29
+ @assignee_ids ||= begin
30
+ parse_key(raw, 'assignees').map { |assignee| assignee['login'] }
31
+ end
32
+ end
33
+
34
+ def closer_id
35
+ @closer_id ||= parse_text(raw, 'closed_by/:/login')
36
+ end
37
+
38
+ def repository
39
+ @repository ||= parse_text(raw, 'url') do |url|
40
+ repo_name = url.match(%r{\A.*/repos/((?:[^/]+/){2}).*\z})[1]
41
+
42
+ repo_name && repo_name[0..-2]
43
+ end
44
+ end
45
+
46
+ def status
47
+ @status ||= parse_text(raw, 'state')
48
+ end
49
+
50
+ def title
51
+ @title ||= parse_text(raw, 'title')
52
+ end
53
+
54
+ def description
55
+ @description ||= parse_text(raw, 'body') do |description|
56
+ description.delete("\r")
57
+ end
58
+ end
59
+
60
+ def labels
61
+ @labels ||= begin
62
+ labels = parse_key(raw, 'labels').map { |label| label['name'] }
63
+ milestone = Array(parse_key(raw, 'milestone/:/title'))
64
+
65
+ labels + milestone
66
+ end
67
+ end
68
+
69
+ def closed_at
70
+ @closed_at ||= parse_time(raw, 'closed_at')
71
+ end
72
+
73
+ def created_at
74
+ @created_at ||= parse_time(raw, 'created_at')
75
+ end
76
+
77
+ def updated_at
78
+ @updated_at ||= parse_time(raw, 'updated_at')
79
+ end
80
+
81
+ def has_pull_request?
82
+ @has_pull_request ||= parse_existance(raw, 'pull_request')
83
+ end
84
+
85
+ def self.to_model(raw_item)
86
+ return NullObjects::Issue.instance unless raw_item
87
+
88
+ Models::Issue.from_parser(parser: new(raw: raw_item))
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
95
+ # rubocop:enable Style/SpaceAroundOperators
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/parsers/hash'
3
+ require 'horn_of_plenty/null_objects/lane'
4
+ require 'horn_of_plenty/models/lane'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Parsers
10
+ class Lane
11
+ include HornOfPlenty::Parsers::Hash
12
+
13
+ attr_accessor :raw
14
+
15
+ def initialize(raw:)
16
+ self.raw = raw
17
+ end
18
+
19
+ def id
20
+ @id ||= parse_text(raw, 'id')
21
+ end
22
+
23
+ def board_id
24
+ @board_id ||= parse_text(raw, 'project_url') do |url|
25
+ url.match(%r{\A.*/(\d+)\z})[1]
26
+ end
27
+ end
28
+
29
+ def title
30
+ @title ||= parse_text(raw, 'name')
31
+ end
32
+
33
+ def created_at
34
+ @created_at ||= parse_time(raw, 'created_at')
35
+ end
36
+
37
+ def updated_at
38
+ @updated_at ||= parse_time(raw, 'updated_at')
39
+ end
40
+
41
+ def self.to_model(raw_item)
42
+ return NullObjects::Lane.instance unless raw_item
43
+
44
+ Models::Lane.from_parser(parser: new(raw: raw_item))
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/parsers/hash'
3
+ require 'horn_of_plenty/null_objects/pull_request'
4
+ require 'horn_of_plenty/adapters/github/parsers/issue'
5
+ require 'horn_of_plenty/models/pull_request'
6
+
7
+ module HornOfPlenty
8
+ module Adapters
9
+ module Github
10
+ module Parsers
11
+ class PullRequest < Parsers::Issue
12
+ def labels
13
+ []
14
+ end
15
+
16
+ def merger_id
17
+ @merger_id ||= parse_text(raw, 'merged_by/:/login')
18
+ end
19
+
20
+ def status
21
+ @status ||= begin
22
+ status = parse_text(raw, 'state')
23
+ merged_at = parse_text(raw, 'merged_at')
24
+
25
+ merged_at ? 'merged' : status
26
+ end
27
+ end
28
+
29
+ def self.to_model(raw_item)
30
+ return NullObjects::PullRequest.instance unless raw_item
31
+
32
+ Models::PullRequest.from_parser(parser: new(raw: raw_item))
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,18 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/queries/fetch'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Queries
8
+ class ListBoards < HornOfPlenty::Queries::Fetch
9
+ def translate(query)
10
+ query.delete(:id)
11
+
12
+ query
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/queries/fetch'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Queries
8
+ class ListCards < HornOfPlenty::Queries::Fetch
9
+ def translate(query)
10
+ query.delete(:id)
11
+ query.delete(:lane_id)
12
+
13
+ query
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/queries/fetch'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Queries
8
+ class ListIssues < HornOfPlenty::Queries::Fetch
9
+ def translate(query)
10
+ query.delete(:id)
11
+
12
+ rename_key(from: :author_id, to: :creator)
13
+ rename_key(from: :assignee_id, to: :assignee)
14
+ rename_key(from: :status, to: :state)
15
+
16
+ query
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,19 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/queries/fetch'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Queries
8
+ class ListLanes < HornOfPlenty::Queries::Fetch
9
+ def translate(query)
10
+ query.delete(:id)
11
+ query.delete(:board_id)
12
+
13
+ query
14
+ end
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/queries/fetch'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Queries
8
+ class ListPullRequests < HornOfPlenty::Queries::Fetch
9
+ def translate(query)
10
+ query.delete(:id)
11
+
12
+ rename_key(from: :author_id, to: :creator)
13
+ rename_key(from: :assignee_id, to: :assignee)
14
+ rename_key(from: :status, to: :state)
15
+
16
+ query
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/client'
3
+ require 'horn_of_plenty/adapters/github/requests/list_boards'
4
+ require 'horn_of_plenty/repository'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Repositories
10
+ class Board < HornOfPlenty::Repository
11
+ private
12
+
13
+ def client
14
+ @client || Github::Client.pool
15
+ end
16
+
17
+ def fetch_class(_attrs)
18
+ @fetch_class ||= Requests::ListBoards
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/client'
3
+ require 'horn_of_plenty/adapters/github/requests/list_cards'
4
+ require 'horn_of_plenty/repository'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Repositories
10
+ class Card < HornOfPlenty::Repository
11
+ private
12
+
13
+ def client
14
+ @client || Github::Client.pool
15
+ end
16
+
17
+ def fetch_class(_attrs)
18
+ @fetch_class ||= Requests::ListCards
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/client'
3
+ require 'horn_of_plenty/adapters/github/requests/list_issues'
4
+ require 'horn_of_plenty/repository'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Repositories
10
+ class Issue < HornOfPlenty::Repository
11
+ private
12
+
13
+ def client
14
+ @client || Github::Client.pool
15
+ end
16
+
17
+ def fetch_class(_attrs)
18
+ @fetch_class ||= Requests::ListIssues
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/client'
3
+ require 'horn_of_plenty/adapters/github/requests/list_lanes'
4
+ require 'horn_of_plenty/repository'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Repositories
10
+ class Lane < HornOfPlenty::Repository
11
+ private
12
+
13
+ def client
14
+ @client || Github::Client.pool
15
+ end
16
+
17
+ def fetch_class(_attrs)
18
+ @fetch_class ||= Requests::ListLanes
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/adapters/github/client'
3
+ require 'horn_of_plenty/adapters/github/requests/list_pull_requests'
4
+ require 'horn_of_plenty/repository'
5
+
6
+ module HornOfPlenty
7
+ module Adapters
8
+ module Github
9
+ module Repositories
10
+ class PullRequest < HornOfPlenty::Repository
11
+ private
12
+
13
+ def client
14
+ @client || Github::Client.pool
15
+ end
16
+
17
+ def fetch_class(_attrs)
18
+ @fetch_class ||= Requests::ListPullRequests
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,50 @@
1
+ # frozen_string_literal: true
2
+ require 'horn_of_plenty/request'
3
+
4
+ module HornOfPlenty
5
+ module Adapters
6
+ module Github
7
+ module Requests
8
+ class ListBoards < HornOfPlenty::Request
9
+ attr_accessor :format,
10
+ :pagination,
11
+ :query,
12
+ :repository
13
+
14
+ def initialize(format: 'raw',
15
+ pagination: {},
16
+ query: {},
17
+ repository:)
18
+
19
+ self.format = format
20
+ self.pagination = pagination
21
+ self.query = query
22
+ self.repository = repository
23
+ end
24
+
25
+ def method
26
+ 'get'
27
+ end
28
+
29
+ def path
30
+ return "repos/#{repository}/projects" unless query[:id]
31
+
32
+ "repos/#{repository}/projects/#{query[:id]}"
33
+ end
34
+
35
+ def to_h
36
+ @to_h ||= query_class.new(query).to_h.
37
+ merge(pagination_hash)
38
+ end
39
+ alias to_params to_h
40
+
41
+ private
42
+
43
+ def pagination_hash
44
+ pagination.to_h
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
50
+ end