diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..bfe7a09 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,9 @@ +language: ruby +rvm: + - 2.1 + - 2.2 + - 2.3.0 +sudo: false +cache: bundler +script: + - bundle exec rspec diff --git a/Gemfile b/Gemfile index cbd451e..5ee986f 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ source 'https://rubygems.org' # Specify your gem's dependencies in errbit_github_plugin.gemspec gemspec -gem 'errbit_plugin', :git => 'https://github.com/errbit/errbit_plugin.git' +gem 'errbit_plugin' gem 'rspec' gem 'guard' gem 'guard-rspec' diff --git a/errbit_github_plugin.gemspec b/errbit_github_plugin.gemspec index 6170215..53d31f5 100644 --- a/errbit_github_plugin.gemspec +++ b/errbit_github_plugin.gemspec @@ -24,4 +24,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency "bundler", "~> 1.3" spec.add_development_dependency "rake" + spec.add_development_dependency "activesupport" end diff --git a/lib/errbit_github_plugin/issue_tracker.rb b/lib/errbit_github_plugin/issue_tracker.rb index 1329cab..3587972 100644 --- a/lib/errbit_github_plugin/issue_tracker.rb +++ b/lib/errbit_github_plugin/issue_tracker.rb @@ -82,5 +82,23 @@ def create_issue(title, body, user: {}) rescue Octokit::Unauthorized raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." end + + def close_issue(url, user: {}) + if user['github_login'] && user['github_oauth_token'] + github_client = Octokit::Client.new( + login: user['github_login'], access_token: user['github_oauth_token']) + else + github_client = Octokit::Client.new( + login: options['username'], password: options['password']) + end + # It would be better to get the number from issue.number when we create the issue, + # however, since we only have the url, get the number from it. + # ex: "https://github.com/octocat/Hello-World/issues/1347" + issue_number = url.split("/").last + issue = github_client.close_issue(repo, issue_number) + issue.html_url + rescue Octokit::Unauthorized + raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password." + end end end