Skip to content

Commit 4945242

Browse files
committed
Merge pull request #11 from mfrederickson/github-close-issue
GitHub close issue feature
2 parents bde8969 + 87468e3 commit 4945242

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

lib/errbit_github_plugin/issue_tracker.rb

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,23 @@ def create_issue(title, body, user: {})
8282
rescue Octokit::Unauthorized
8383
raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
8484
end
85+
86+
def close_issue(url, user: {})
87+
if user['github_login'] && user['github_oauth_token']
88+
github_client = Octokit::Client.new(
89+
login: user['github_login'], access_token: user['github_oauth_token'])
90+
else
91+
github_client = Octokit::Client.new(
92+
login: options['username'], password: options['password'])
93+
end
94+
# It would be better to get the number from issue.number when we create the issue,
95+
# however, since we only have the url, get the number from it.
96+
# ex: "https://github.com/octocat/Hello-World/issues/1347"
97+
issue_number = url.split("/").last
98+
issue = github_client.close_issue(repo, issue_number)
99+
issue.html_url
100+
rescue Octokit::Unauthorized
101+
raise ErrbitGithubPlugin::AuthenticationError, "Could not authenticate with GitHub. Please check your username and password."
102+
end
85103
end
86104
end

0 commit comments

Comments
 (0)