Class: Fbe::Graph
- Inherits:
-
Object
- Object
- Fbe::Graph
- Defined in:
- lib/fbe/github_graph.rb
Overview
A client to GitHub GraphQL.
- Author
-
Yegor Bugayenko ([email protected])
- Copyright
-
Copyright © 2024-2025 Zerocracy
- License
-
MIT
Defined Under Namespace
Instance Method Summary collapse
-
#initialize(token:, host: 'api.github.com') ⇒ Graph
constructor
A new instance of Graph.
- #query(qry) ⇒ Object
- #resolved_conversations(owner, name, number) ⇒ Object
- #total_commits(owner, name, branch) ⇒ Object
- #total_issues_and_pulls(owner, name) ⇒ Object
Constructor Details
#initialize(token:, host: 'api.github.com') ⇒ Graph
Returns a new instance of Graph.
33 34 35 36 |
# File 'lib/fbe/github_graph.rb', line 33 def initialize(token:, host: 'api.github.com') @token = token @host = host end |
Instance Method Details
#query(qry) ⇒ Object
38 39 40 41 |
# File 'lib/fbe/github_graph.rb', line 38 def query(qry) result = client.query(client.parse(qry)) result.data end |
#resolved_conversations(owner, name, number) ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/fbe/github_graph.rb', line 43 def resolved_conversations(owner, name, number) result = query( " {\n repository(owner: \"\#{owner}\", name: \"\#{name}\") {\n pullRequest(number: \#{number}) {\n reviewThreads(first: 100) {\n nodes {\n id\n isResolved\n comments(first: 100) {\n nodes {\n id\n body\n author {\n login\n }\n createdAt\n }\n }\n }\n }\n }\n }\n }\n GRAPHQL\n )\n result&.to_h&.dig('repository', 'pullRequest', 'reviewThreads', 'nodes')&.select do |thread|\n thread['isResolved']\n end || []\nend\n" |
#total_commits(owner, name, branch) ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/fbe/github_graph.rb', line 75 def total_commits(owner, name, branch) result = query( " {\n repository(owner: \"\#{owner}\", name: \"\#{name}\") {\n ref(qualifiedName: \"\#{branch}\") {\n target {\n ... on Commit {\n history {\n totalCount\n }\n }\n }\n }\n }\n }\n GRAPHQL\n )\n result.repository.ref.target.history.total_count\nend\n" |
#total_issues_and_pulls(owner, name) ⇒ Object
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/fbe/github_graph.rb', line 96 def total_issues_and_pulls(owner, name) result = query( " {\n repository(owner: \"\#{owner}\", name: \"\#{name}\") {\n issues {\n totalCount\n }\n pullRequests {\n totalCount\n }\n }\n }\n GRAPHQL\n ).to_h\n {\n 'issues' => result.dig('repository', 'issues', 'totalCount') || 0,\n 'pulls' => result.dig('repository', 'pullRequests', 'totalCount') || 0\n }\nend\n" |