Commit 96cfdfd7f7503eb8df3f25e0fdcb0ed90289d7fb
1 parent
ecc4f777
Exists in
master
and in
1 other branch
Avoid failure if you delete the bitbucket_rest_api in Gemfile
The bitbucket_rest_api gem is need only in issue_tracker bitbucket. If you optimise your Gemfile by delete it errbit not work. But he need to work. Fix #558
Showing
1 changed file
with
45 additions
and
40 deletions
Show diff stats
app/models/issue_trackers/bitbucket_issues_tracker.rb
| 1 | -require 'bitbucket_rest_api' | |
| 2 | -class IssueTrackers::BitbucketIssuesTracker < IssueTracker | |
| 3 | - Label = "bitbucket" | |
| 4 | - Note = 'Please configure your Bitbucket repository in the <strong>BITBUCKET REPO</strong> field above.' | |
| 5 | - Fields = [ | |
| 6 | - [:api_token, { | |
| 7 | - :placeholder => "Your username on Bitbucket account", | |
| 8 | - :label => "Username" | |
| 9 | - }], | |
| 10 | - [:project_id, { | |
| 11 | - :placeholder => "Password for your Bitbucket account", | |
| 12 | - :label => "Password" | |
| 13 | - }] | |
| 14 | - ] | |
| 1 | +begin | |
| 2 | + require 'bitbucket_rest_api' | |
| 3 | +rescue LoadError | |
| 4 | +end | |
| 5 | + | |
| 6 | +if defined? BitBucket | |
| 7 | + class IssueTrackers::BitbucketIssuesTracker < IssueTracker | |
| 8 | + Label = "bitbucket" | |
| 9 | + Note = 'Please configure your Bitbucket repository in the <strong>BITBUCKET REPO</strong> field above.' | |
| 10 | + Fields = [ | |
| 11 | + [:api_token, { | |
| 12 | + :placeholder => "Your username on Bitbucket account", | |
| 13 | + :label => "Username" | |
| 14 | + }], | |
| 15 | + [:project_id, { | |
| 16 | + :placeholder => "Password for your Bitbucket account", | |
| 17 | + :label => "Password" | |
| 18 | + }] | |
| 19 | + ] | |
| 15 | 20 | |
| 16 | - def check_params | |
| 17 | - if Fields.detect {|f| self[f[0]].blank? } | |
| 18 | - errors.add :base, 'You must specify your Bitbucket username and password' | |
| 21 | + def check_params | |
| 22 | + if Fields.detect {|f| self[f[0]].blank? } | |
| 23 | + errors.add :base, 'You must specify your Bitbucket username and password' | |
| 24 | + end | |
| 19 | 25 | end |
| 20 | - end | |
| 21 | 26 | |
| 22 | - def repo_name | |
| 23 | - app.bitbucket_repo | |
| 24 | - end | |
| 27 | + def repo_name | |
| 28 | + app.bitbucket_repo | |
| 29 | + end | |
| 25 | 30 | |
| 26 | - def create_issue(problem, reported_by = nil) | |
| 27 | - bitbucket = BitBucket.new :basic_auth => "#{api_token}:#{project_id}" | |
| 31 | + def create_issue(problem, reported_by = nil) | |
| 32 | + bitbucket = BitBucket.new :basic_auth => "#{api_token}:#{project_id}" | |
| 28 | 33 | |
| 29 | - begin | |
| 30 | - r_user = repo_name.split('/')[0] | |
| 31 | - r_name = repo_name.split('/')[1] | |
| 32 | - issue = bitbucket.issues.create r_user, r_name, :title => issue_title(problem), :content => body_template.result(binding), :priority => 'critical' | |
| 33 | - problem.update_attributes( | |
| 34 | - :issue_link => "https://bitbucket.org/#{repo_name}/issue/#{issue.local_id}/", | |
| 35 | - :issue_type => Label | |
| 36 | - ) | |
| 37 | - rescue BitBucket::Error::Unauthorized | |
| 38 | - raise IssueTrackers::AuthenticationError, "Could not authenticate with BitBucket. Please check your username and password." | |
| 34 | + begin | |
| 35 | + r_user = repo_name.split('/')[0] | |
| 36 | + r_name = repo_name.split('/')[1] | |
| 37 | + issue = bitbucket.issues.create r_user, r_name, :title => issue_title(problem), :content => body_template.result(binding), :priority => 'critical' | |
| 38 | + problem.update_attributes( | |
| 39 | + :issue_link => "https://bitbucket.org/#{repo_name}/issue/#{issue.local_id}/", | |
| 40 | + :issue_type => Label | |
| 41 | + ) | |
| 42 | + rescue BitBucket::Error::Unauthorized | |
| 43 | + raise IssueTrackers::AuthenticationError, "Could not authenticate with BitBucket. Please check your username and password." | |
| 44 | + end | |
| 39 | 45 | end |
| 40 | - end | |
| 41 | 46 | |
| 42 | - def body_template | |
| 43 | - @@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/bitbucket_issues_body.txt.erb")) | |
| 44 | - end | |
| 47 | + def body_template | |
| 48 | + @@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/bitbucket_issues_body.txt.erb")) | |
| 49 | + end | |
| 45 | 50 | |
| 46 | - def url | |
| 47 | - "https://www.bitbucket.org/#{repo_name}/issues" | |
| 51 | + def url | |
| 52 | + "https://www.bitbucket.org/#{repo_name}/issues" | |
| 53 | + end | |
| 48 | 54 | end |
| 49 | 55 | end |
| 50 | - | ... | ... |