Created
November 10, 2017 16:06
-
-
Save skuroki/2981efb1929cee474cbbb2f2f933cebe to your computer and use it in GitHub Desktop.
Github API v4にgraphql-client gemを使ってアクセスする ref: http://qiita.com/skuroki@github/items/eecc454edb2ac984be25
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
source 'https://rubygems.org' | |
gem 'graphql-client' # 0.12.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#! /usr/bin/env ruby | |
require 'graphql/client' | |
require 'graphql/client/http' | |
h = GraphQL::Client::HTTP.new('https://api.github.com/graphql') do | |
def headers(context) | |
{ | |
"Authorization" => "Bearer #{ENV['ACCESS_TOKEN']}" | |
} | |
end | |
end | |
s = GraphQL::Client.load_schema(h) | |
c = GraphQL::Client.new(schema: s, execute: h) | |
Q = c.parse <<-GraphQL | |
query($after: String) { | |
repository(owner:"our_company", name:"awesome_project") { | |
pullRequests(first: 100, states: [MERGED], orderBy: {field: UPDATED_AT, direction: DESC}, after: $after) { | |
edges { | |
cursor | |
node { | |
number | |
title | |
updatedAt | |
mergedAt | |
author { | |
login | |
} | |
} | |
} | |
} | |
} | |
} | |
GraphQL | |
all_nodes = [] | |
after = nil | |
loop do | |
r = c.query(Q, variables: { after: after }) | |
nodes = r.data.repository.pull_requests.edges.map(&:node) | |
nodes_in_time = nodes.select { |n| Time.parse(n.updated_at) > Time.new(2017, 10, 30) } | |
all_nodes += nodes_in_time.select { |n| %w(alice bob carol).include?(n.author.login) } | |
break if nodes.size > nodes_in_time.size | |
after = r.data.repository.pull_requests.edges.last.cursor | |
end | |
puts all_nodes.map { |n| "##{n.number}\t#{n.author.login}\t#{n.merged_at}\t#{n.title}" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment