Class: GHX::GraphqlClient

Inherits:
Object
  • Object
show all
Defined in:
lib/ghx/graphql_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(api_key) ⇒ GraphqlClient

Returns a new instance of GraphqlClient.



3
4
5
# File 'lib/ghx/graphql_client.rb', line 3

def initialize(api_key)
  @api_key = api_key
end

Instance Method Details

#query(query) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
# File 'lib/ghx/graphql_client.rb', line 7

def query(query)
  uri = URI("https://api.github.com/graphql")
  req = Net::HTTP::Post.new(uri)
  req["Authorization"] = "Bearer #{@api_key}"
  req["Content-Type"] = "application/json"
  req.body = {query: query}.to_json

  Net::HTTP.start(uri.hostname, uri.port, use_ssl: true) do |http|
    http.request(req)
  end
end

#update_project_item_reported_at(project_item_id:, reported_at:, project_id: GithubProject::MAIN_GH_PROJECT_ID) ⇒ Object

Parameters:

  • project_id (String) (defaults to: GithubProject::MAIN_GH_PROJECT_ID)
  • project_item (GithubProjectItem)
  • reported_at (DateTime)


22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/ghx/graphql_client.rb', line 22

def update_project_item_reported_at(project_item_id:, reported_at:, project_id: GithubProject::MAIN_GH_PROJECT_ID)
  field_id = "PVTF_lADOALH_aM4Ac-_zzgSzAZs" # project_item.field_map["Reported At"]

  gql_query = "    mutation {\n      updateProjectV2ItemFieldValue(input: {\n        fieldId: \"\#{field_id}\",\n        itemId: \"\#{project_item_id}\",\n        projectId: \"\#{project_id}\",\n        value: { \n          date: \"\#{reported_at.to_date}\"\n        }\n      }) {\n        projectV2Item {\n          id  \n        }\n      }\n    }\n  GQL\n\n  query(gql_query)\nend\n"

#update_project_item_reported_by(project_item_id:, reported_by:, project_id: GithubProject::MAIN_GH_PROJECT_ID) ⇒ Object



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/ghx/graphql_client.rb', line 45

def update_project_item_reported_by(project_item_id:, reported_by:, project_id: GithubProject::MAIN_GH_PROJECT_ID)
  field_id = "PVTF_lADOALH_aM4Ac-_zzgSzBcc" # project_item.field_map["Reporter"]

  gql_query = "    mutation {\n      updateProjectV2ItemFieldValue(input: {\n        fieldId: \"\#{field_id}\",\n        itemId: \"\#{project_item_id}\",\n        projectId: \"\#{project_id}\",\n        value: { \n          text: \"\#{reported_by}\"\n        }\n      }) {\n        projectV2Item {\n          id  \n        }\n      }\n    }\n  GQL\n\n  query(gql_query)\nend\n"