Class: Decidim::GithubManager::Poster

Inherits:
Object
  • Object
show all
Defined in:
lib/decidim/github_manager/poster.rb

Overview

Allows to make POST requests to GitHub Rest API about Pull Requests

Instance Method Summary collapse

Constructor Details

#initialize(token:, params:) ⇒ Poster

Returns a new instance of Poster.

Parameters:

  • token (String)

    token for GitHub authentication

  • params (Hash)

    Parameters accepted by the GitHub API



14
15
16
17
# File 'lib/decidim/github_manager/poster.rb', line 14

def initialize(token:, params:)
  @token = token
  @params = params
end

Instance Method Details

#callFaraday::Response

Create the pull request or give error messages

Returns:

  • (Faraday::Response)

    An instance that represents an HTTP response from making an HTTP request



22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/decidim/github_manager/poster.rb', line 22

def call
  response = create_pull_request!
  pull_request_id = JSON.parse(response.body)["number"]
  unless pull_request_id
    puts "Pull request could not be created!"
    puts "Please make sure you have enabled the 'public_repo' scope for the access token"
    return
  end
  puts "Pull request created at https://github.com/decidim/decidim/pull/#{pull_request_id}"

  add_labels_to_issue!(pull_request_id)
end