Class: GithubNotify::Comment
- Inherits:
-
Object
- Object
- GithubNotify::Comment
- Defined in:
- lib/github_notify/comment.rb
Constant Summary collapse
- API_GITHUB_ROOT =
"https://api.github.com"
Instance Method Summary collapse
-
#initialize(token:, url: nil, owner: nil, repository: nil, number: nil, body:) ⇒ Comment
constructor
A new instance of Comment.
- #post ⇒ Object
Constructor Details
#initialize(token:, url: nil, owner: nil, repository: nil, number: nil, body:) ⇒ Comment
Returns a new instance of Comment.
6 7 8 9 10 11 12 13 |
# File 'lib/github_notify/comment.rb', line 6 def initialize(token:, url: nil, owner: nil, repository: nil, number: nil, body:) @token = token # Set token @url = url # Full URL ex. https://api.github.com/repos/YOUR_NAME/REPOSITORY_NAME/issues/1/comments @owner = owner # Your Name or Organization @repository = repository # Your Repository @number = number # PR Number @body = body # GitHub Markdown Text end |
Instance Method Details
#post ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/github_notify/comment.rb', line 15 def post @url ||= "#{API_GITHUB_ROOT}/repos/#{@owner}/#{@repository}/issues/#{@number}/comments" uri = URI.parse(@url) https = Net::HTTP.new(uri.host, uri.port) https.use_ssl = true req = Net::HTTP::Post.new(uri.request_uri) if @token.nil? p "Not setting token." return end req["Authorization"] = "token #{@token}" if @body.nil? p "Not setting comment." return end query = {body: @body} req.body = query.to_json https.request(req) end |