Class: Specular::Integration::GitHub
- Defined in:
- lib/specular/integration/github.rb
Instance Method Summary collapse
- #create_issue!(title:, body:) ⇒ Object
-
#initialize(github_token:, repo:) ⇒ GitHub
constructor
A new instance of GitHub.
- #issue_mutation ⇒ Object
- #repository_id ⇒ Object
- #repository_query ⇒ Object
Methods inherited from Base
Constructor Details
#initialize(github_token:, repo:) ⇒ GitHub
Returns a new instance of GitHub.
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/specular/integration/github.rb', line 9 def initialize(github_token:, repo:) @https = GraphQL::Client::HTTP.new('https://api.github.com/graphql') do define_method(:headers) do |_context| { "User-Agent": "Specular/#{Specular.version}", "Authorization": "Bearer #{github_token}" } end end @repo = repo @schema = GraphQL::Client.load_schema(@https) @client = GraphQL::Client.new(schema: @schema, execute: @https) @client.allow_dynamic_queries = true end |
Instance Method Details
#create_issue!(title:, body:) ⇒ Object
63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/specular/integration/github.rb', line 63 def create_issue!(title:, body:) result = @client.query( self.issue_mutation, variables: { input: { title: title, body: body, repositoryId: self.repository_id } } ) { url: result.data.create_issue.issue.url } end |
#issue_mutation ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/specular/integration/github.rb', line 37 def issue_mutation @issue_mutation ||= @client.parse <<-'GRAPHQL' mutation ($input: CreateIssueInput!) { createIssue(input: $input) { issue { url } } } GRAPHQL end |
#repository_id ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/specular/integration/github.rb', line 49 def repository_id owner, name = URI.parse(@repo).path.split('/')[1,2] result = @client.query( self.repository_query, variables: { name: name, owner: owner } ) result.data.repository.id end |
#repository_query ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/specular/integration/github.rb', line 27 def repository_query @repository_query ||= @client.parse <<-'GRAPHQL' query ($name: String!, $owner: String!) { repository(name: $name, owner: $owner) { id } } GRAPHQL end |