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) ⇒ GraphQL::Client::Response
Executes a GraphQL query against the GitHub API.
-
#resolved_conversations(owner, name, number) ⇒ Array<Hash>
Retrieves resolved conversation threads from a pull request.
-
#total_commits(owner, name, branch) ⇒ Integer
Gets the total number of commits in a branch.
-
#total_issues_and_pulls(owner, name) ⇒ Hash
Gets the total number of issues and pull requests in a repository.
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) ⇒ GraphQL::Client::Response
Executes a GraphQL query against the GitHub API.
46 47 48 49 |
# File 'lib/fbe/github_graph.rb', line 46 def query(qry) result = client.query(client.parse(qry)) result.data end |
#resolved_conversations(owner, name, number) ⇒ Array<Hash>
Retrieves resolved conversation threads from a pull request.
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/fbe/github_graph.rb', line 61 def resolved_conversations(owner, name, number) result = query( <<~GRAPHQL { repository(owner: "#{owner}", name: "#{name}") { pullRequest(number: #{number}) { reviewThreads(first: 100) { nodes { id isResolved comments(first: 100) { nodes { id body author { login } createdAt } } } } } } } GRAPHQL ) result&.to_h&.dig('repository', 'pullRequest', 'reviewThreads', 'nodes')&.select do |thread| thread['isResolved'] end || [] end |
#total_commits(owner, name, branch) ⇒ Integer
Gets the total number of commits in a branch.
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
# File 'lib/fbe/github_graph.rb', line 103 def total_commits(owner, name, branch) result = query( <<~GRAPHQL { repository(owner: "#{owner}", name: "#{name}") { ref(qualifiedName: "#{branch}") { target { ... on Commit { history { totalCount } } } } } } GRAPHQL ) result.repository.ref.target.history.total_count end |
#total_issues_and_pulls(owner, name) ⇒ Hash
Gets the total number of issues and pull requests in a repository.
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/fbe/github_graph.rb', line 133 def total_issues_and_pulls(owner, name) result = query( <<~GRAPHQL { repository(owner: "#{owner}", name: "#{name}") { issues { totalCount } pullRequests { totalCount } } } GRAPHQL ).to_h { 'issues' => result.dig('repository', 'issues', 'totalCount') || 0, 'pulls' => result.dig('repository', 'pullRequests', 'totalCount') || 0 } end |