Class: Cyclid::API::Plugins::GithubComment
- Inherits:
-
Action
- Object
- Action
- Cyclid::API::Plugins::GithubComment
- Defined in:
- lib/cyclid/plugins/action/github_comment.rb
Overview
Post a comment to a Github plugin (including Pull Requests)
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ GithubComment
constructor
A new instance of GithubComment.
- #perform(log) ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ GithubComment
Returns a new instance of GithubComment.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/cyclid/plugins/action/github_comment.rb', line 29 def initialize(args = {}) args.symbolize_keys! # There must be a repository name. raise 'a github comment action requires a repository' unless args.include? :repo # There must be an issue number. raise 'a github comment action requires an issue number' unless args.include? :number @repo = args[:repo] @number = args[:number].to_s @comment = args[:comment] if args.include? :comment @path = args[:path] if args.include? :path # There must be either a comment or a file to read as a comment raise 'a github comment action requires a comment or file' if @comment.nil? && @path.nil? end |
Instance Method Details
#perform(log) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/cyclid/plugins/action/github_comment.rb', line 48 def perform(log) # If a path was given, read the file and use it as the comment if @path content = StringIO.new @transport.download(content, @path**@ctx) @comment = content.string end # Insert context repo = @repo**@ctx number = @number**@ctx comment = @comment**@ctx # Append the comment client = Octokit::Client.new(access_token: oauth_token) client.add_comment(repo, number, comment) [true, 0] rescue StandardError => ex log.write "Failed to add Github comment to #{repo} ##{number}: #{ex}" [false, 0] end |