Commit 0cfeb5a5655cff1c0b2b5417e965d21a62b87eb1

Authored by Arthur Neves
1 parent 8d743567
Exists in master and in 1 other branch production

Fix github issue tracker creation

When creating a issue using octokit, we need to pass a  instead of a , as those are changes on the new octokit gem.

[fixes #675]
app/models/issue_trackers/github_issues_tracker.rb
@@ -29,7 +29,7 @@ if defined? Octokit @@ -29,7 +29,7 @@ if defined? Octokit
29 def create_issue(problem, reported_by = nil) 29 def create_issue(problem, reported_by = nil)
30 # Login using OAuth token, if given. 30 # Login using OAuth token, if given.
31 if oauth_token 31 if oauth_token
32 - client = Octokit::Client.new(:login => username, :oauth_token => oauth_token) 32 + client = Octokit::Client.new(:login => username, :access_token => oauth_token)
33 else 33 else
34 client = Octokit::Client.new(:login => username, :password => password) 34 client = Octokit::Client.new(:login => username, :password => password)
35 end 35 end
spec/models/issue_trackers/github_issues_tracker_spec.rb
@@ -17,10 +17,10 @@ describe IssueTrackers::GithubIssuesTracker do @@ -17,10 +17,10 @@ describe IssueTrackers::GithubIssuesTracker do
17 Fabricate :github_issues_tracker, app: notice.app 17 Fabricate :github_issues_tracker, app: notice.app
18 end 18 end
19 19
20 - it "should create an issue on GitHub Issues with problem params, and set issue link for problem" do  
21 - number = 5  
22 - issue_link = "https://github.com/#{repo}/issues/#{number}"  
23 - body = <<EOF 20 + let(:number) { 5 }
  21 + let(:issue_link) { "https://github.com/#{repo}/issues/#{number}" }
  22 + let(:body) do
  23 + <<EOF
24 { 24 {
25 "position": 1.0, 25 "position": 1.0,
26 "number": #{number}, 26 "number": #{number},
@@ -34,7 +34,9 @@ describe IssueTrackers::GithubIssuesTracker do @@ -34,7 +34,9 @@ describe IssueTrackers::GithubIssuesTracker do
34 "html_url": "#{issue_link}" 34 "html_url": "#{issue_link}"
35 } 35 }
36 EOF 36 EOF
  37 +end
37 38
  39 + it "should create an issue on GitHub Issues with problem params, and set issue link for problem" do
38 stub_request(:post, 40 stub_request(:post,
39 "https://#{tracker.username}:#{tracker.password}@api.github.com/repos/#{repo}/issues"). 41 "https://#{tracker.username}:#{tracker.password}@api.github.com/repos/#{repo}/issues").
40 to_return(:status => 201, 42 to_return(:status => 201,
@@ -53,4 +55,19 @@ EOF @@ -53,4 +55,19 @@ EOF
53 55
54 expect(problem.issue_link).to eq issue_link 56 expect(problem.issue_link).to eq issue_link
55 end 57 end
  58 +
  59 + it "should create an issue with oauth token" do
  60 + issue_tracker = problem.app.issue_tracker
  61 + issue_tracker.oauth_token = 'secret_token'
  62 +
  63 + stub_request(:post, "https://api.github.com/repos/#{repo}/issues").
  64 + to_return({
  65 + status: 201,
  66 + headers: {'Location' => issue_link, 'Content-Type' => 'application/json' },
  67 + body: body })
  68 +
  69 + issue_tracker.create_issue(problem)
  70 + requested = have_requested(:post, "https://api.github.com/repos/#{repo}/issues")
  71 + expect(WebMock).to requested.with(headers: {'Authorization'=>'token secret_token'})
  72 + end
56 end 73 end