class Fbe::Graph
- License
- MIT
Copyright - Copyright © 2024-2025 Zerocracy
Author -
Yegor Bugayenko (yegor256@gmail.com)
A client to GitHub GraphQL.
- Copyright © 2024-2025 Zerocracy
- MIT
def initialize(token:, host: 'api.github.com')
def initialize(token:, host: 'api.github.com') @token = token http = HTTP.new(token, host) @client = GraphQL::Client.new(schema: GraphQL::Client.load_schema(http), execute: http) @client.allow_dynamic_queries = true end
def query(query_string)
def query(query_string) result = @client.query(@client.parse(query_string)) result.data end
def resolved_conversations(owner, name, number)
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
def total_commits(owner, name, branch)
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
def total_issues_and_pulls(owner, name)
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