-
Notifications
You must be signed in to change notification settings - Fork 0
/
github.rb
84 lines (83 loc) · 2.33 KB
/
github.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
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
74
75
76
77
78
79
80
81
82
83
84
module Github
HTTP = GraphQL::Client::HTTP.new('https://api.github.com/graphql') do
def headers(context)
{
'Authorization': "Bearer #{ENV.fetch('GITHUB_TOKEN')}"
}
end
end
# NOTE - Disabled intentionally to increase boot speed
# Schema = GraphQL::Client.load_schema(HTTP)
# GraphQL::Client.dump_schema(HTTP, 'github-graphql-schema.json')
Schema = GraphQL::Client.load_schema('github-graphql-schema.json')
Client = GraphQL::Client.new(schema: Schema, execute: HTTP)
module Queries
RawRepositoryIssues = <<~GRAPHQL
query(
$filter_labels: [String!]!,
$filter_states: [IssueState!]!,
$pagination_cursor: String,
$pagination_limit: Int!,
$repository_name: String!,
$repository_owner: String!,
$sort_direction: OrderDirection!,
$sort_field: IssueOrderField!
) {
repository(
owner: $repository_owner,
name: $repository_name
) {
issues(
first: $pagination_limit,
after: $pagination_cursor,
states: $filter_states,
filterBy: {
labels: $filter_labels
},
orderBy: {
field: $sort_field,
direction: $sort_direction
}
) {
edges {
cursor
node {
id
number
url
title
state
createdAt
comments {
totalCount
}
labels(first: 100) {
edges {
node {
name
}
}
}
}
}
pageInfo {
startCursor
hasNextPage
hasPreviousPage
endCursor
}
totalCount
}
}
}
GRAPHQL
# TODO: Refactor - Could not figure out how to conditionally set dynamic
# graphql parameters
RepositoryIssuesAfter = Client.parse(RawRepositoryIssues)
RepositoryIssuesBefore = Client.parse(
RawRepositoryIssues
.sub("after: $pagination_cursor", "before: $pagination_cursor")
.sub("first: $pagination_limit", "last: $pagination_limit")
)
end
end