Class: Marlens::GithubToJiraComment::GithubClient
- Inherits:
-
Object
- Object
- Marlens::GithubToJiraComment::GithubClient
- Defined in:
- lib/marlens/github_to_jira_comment/github_client.rb
Defined Under Namespace
Classes: Content
Constant Summary collapse
- API_ROOT =
"https://api.github.com"
Instance Method Summary collapse
- #fetch(source) ⇒ Object
-
#initialize(token:, http: nil, requester: nil) ⇒ GithubClient
constructor
A new instance of GithubClient.
- #render_markdown(markdown, context:) ⇒ Object
Constructor Details
#initialize(token:, http: nil, requester: nil) ⇒ GithubClient
Returns a new instance of GithubClient.
14 15 16 17 18 |
# File 'lib/marlens/github_to_jira_comment/github_client.rb', line 14 def initialize(token:, http: nil, requester: nil) @token = token @http = http @requester = requester || method(:request) end |
Instance Method Details
#fetch(source) ⇒ Object
20 21 22 23 24 |
# File 'lib/marlens/github_to_jira_comment/github_client.rb', line 20 def fetch(source) source = GithubUrl.parse(source) if source.is_a?(String) json = get_json(source.api_path) Content.new(title: json.fetch("title"), body: json["body"].to_s) end |
#render_markdown(markdown, context:) ⇒ Object
26 27 28 29 30 31 32 33 34 |
# File 'lib/marlens/github_to_jira_comment/github_client.rb', line 26 def render_markdown(markdown, context:) uri = URI("#{API_ROOT}/markdown") request = Net::HTTP::Post.new(uri) request.body = JSON.dump("text" => markdown, "mode" => "gfm", "context" => context) response = perform(uri, request) return response.body if response.code.to_i.between?(200, 299) raise "GitHub Markdown render failed: #{response.code} #{response.body}" end |