Commit 0c062811ba80b56a1d18b8d36ba5e9011ca7247b
Exists in
master
and in
1 other branch
Merge pull request #339 from jozefvaclavik/master
Updated Gitlab integration.
Showing
8 changed files
with
67 additions
and
57 deletions
Show diff stats
Gemfile
... | ... | @@ -37,7 +37,7 @@ gem 'ruby-fogbugz', :require => 'fogbugz' |
37 | 37 | # Github Issues |
38 | 38 | gem 'octokit', '~> 1.0.0' |
39 | 39 | # Gitlab |
40 | -gem 'gitlab' | |
40 | +gem 'gitlab', :git => 'git://github.com/NARKOZ/gitlab' | |
41 | 41 | |
42 | 42 | # Bitbucket Issues |
43 | 43 | gem 'bitbucket_rest_api' | ... | ... |
Gemfile.lock
1 | +GIT | |
2 | + remote: git://github.com/NARKOZ/gitlab | |
3 | + revision: e4d7dd7dd4be587e44de388eb64d164cab5d464f | |
4 | + specs: | |
5 | + gitlab (2.2.0) | |
6 | + httparty | |
7 | + | |
1 | 8 | GEM |
2 | 9 | remote: http://rubygems.org/ |
3 | 10 | specs: |
... | ... | @@ -99,8 +106,6 @@ GEM |
99 | 106 | ffi (1.1.4) |
100 | 107 | foreman (0.60.2) |
101 | 108 | thor (>= 0.13.6) |
102 | - gitlab (2.1.0) | |
103 | - httparty | |
104 | 109 | haml (3.1.6) |
105 | 110 | happymapper (0.4.0) |
106 | 111 | libxml-ruby (~> 2.0) | ... | ... |
README.md
... | ... | @@ -387,9 +387,7 @@ card_type = Defect, status = Open, priority = Essential |
387 | 387 | |
388 | 388 | * Account is the host of your gitlab installation. i.e. **http://gitlab.example.com** |
389 | 389 | * To authenticate, Errbit uses token-based authentication. Get your API Key in your user settings (or create special user for this purpose) |
390 | -* You also need to provide project name (shortname) or ID (number) for issues to be created | |
391 | -* **Currently (as of 3.0), Gitlab has 2000 character limit for issue description.** It is necessary to turn it off at your instance, because Errbit issues body is much longer. Please comment validation line in issue model in models folder https://github.com/gitlabhq/gitlabhq/blob/master/app/models/issue.rb#L10 | |
392 | - | |
390 | +* You also need to provide project ID (it needs to be Number) for issues to be created | |
393 | 391 | |
394 | 392 | |
395 | 393 | What if Errbit has an error? | ... | ... |
app/models/issue_trackers/gitlab_tracker.rb
... | ... | @@ -10,7 +10,7 @@ if defined? Gitlab |
10 | 10 | :placeholder => "API Token for your account" |
11 | 11 | }], |
12 | 12 | [:project_id, { |
13 | - :label => "Ticket Project Short Name / ID", | |
13 | + :label => "Ticket Project ID (use Number)", | |
14 | 14 | :placeholder => "Gitlab Project where issues will be created" |
15 | 15 | }] |
16 | 16 | ] |
... | ... | @@ -23,19 +23,25 @@ if defined? Gitlab |
23 | 23 | |
24 | 24 | def create_issue(problem, reported_by = nil) |
25 | 25 | Gitlab.configure do |config| |
26 | - config.endpoint = "#{account}/api/v2" | |
26 | + config.endpoint = "#{account}/api/v3" | |
27 | 27 | config.private_token = api_token |
28 | 28 | config.user_agent = 'Errbit User Agent' |
29 | 29 | end |
30 | 30 | title = issue_title problem |
31 | - description = body_template.result(binding) | |
32 | - Gitlab.create_issue(project_id, title, { :description => description, :labels => "errbit" } ) | |
31 | + description_summary = summary_template.result(binding) | |
32 | + description_body = body_template.result(binding) | |
33 | + ticket = Gitlab.create_issue(project_id, title, { :description => description_summary, :labels => "errbit" } ) | |
34 | + Gitlab.create_issue_note(project_id, ticket.id, description_body) | |
35 | + end | |
36 | + | |
37 | + def summary_template | |
38 | + @@summary_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/gitlab_summary.txt.erb").gsub(/^\s*/, '')) | |
33 | 39 | end |
34 | 40 | |
35 | 41 | def body_template |
36 | 42 | @@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/gitlab_body.txt.erb").gsub(/^\s*/, '')) |
37 | 43 | end |
38 | - | |
44 | + | |
39 | 45 | def url |
40 | 46 | "#{account}/#{project_id}/issues" |
41 | 47 | end | ... | ... |
app/views/issue_trackers/gitlab_body.txt.erb
1 | -[See this exception on Errbit](<%= app_problem_url problem.app, problem %> "See this exception on Errbit") | |
2 | 1 | <% if notice = problem.notices.first %> |
3 | -# <%= notice.message %> # | |
4 | -## Summary ## | |
5 | -<% if notice.request['url'].present? %> | |
6 | - ### URL ### | |
7 | - [<%= notice.request['url'] %>](<%= notice.request['url'] %>)" | |
8 | -<% end %> | |
9 | -### Where ### | |
10 | -<%= notice.where %> | |
11 | - | |
12 | -### Occured ### | |
13 | -<%= notice.created_at.to_s(:micro) %> | |
14 | - | |
15 | -### Similar ### | |
16 | -<%= (notice.problem.notices_count - 1).to_s %> | |
17 | - | |
18 | 2 | ## Params ## |
19 | 3 | ``` |
20 | 4 | <%= pretty_hash(notice.params) %> | ... | ... |
... | ... | @@ -0,0 +1,17 @@ |
1 | +[See this exception on Errbit](<%= app_problem_url problem.app, problem %> "See this exception on Errbit") | |
2 | +<% if notice = problem.notices.first %> | |
3 | +# <%= notice.message %> # | |
4 | +## Summary ## | |
5 | +<% if notice.request['url'].present? %> | |
6 | + ### URL ### | |
7 | + [<%= notice.request['url'] %>](<%= notice.request['url'] %>)" | |
8 | +<% end %> | |
9 | +### Where ### | |
10 | +<%= notice.where %> | |
11 | + | |
12 | +### Occured ### | |
13 | +<%= notice.created_at.to_s(:micro) %> | |
14 | + | |
15 | +### Similar ### | |
16 | +<%= (notice.problem.notices_count - 1).to_s %> | |
17 | +<% end %> | |
0 | 18 | \ No newline at end of file | ... | ... |
spec/models/issue_trackers/github_issues_tracker_spec 2.rb
... | ... | @@ -1,30 +0,0 @@ |
1 | -require 'spec_helper' | |
2 | - | |
3 | -describe IssueTrackers::GitlabTracker do | |
4 | - it "should create an issue on Gitlab with problem params" do | |
5 | - notice = Fabricate :notice | |
6 | - tracker = Fabricate :gitlab_tracker, :app => notice.app | |
7 | - problem = notice.problem | |
8 | - | |
9 | - number = 5 | |
10 | - @issue_link = "#{tracker.account}/#{tracker.project_id}/issues/#{number}/#{tracker.api_token}" | |
11 | - body = <<EOF | |
12 | -{ | |
13 | - "title": "Title" | |
14 | -} | |
15 | -EOF | |
16 | - | |
17 | - stub_request(:post, "#{tracker.account}/#{tracker.project_id}/issues/#{tracker.api_token}"). | |
18 | - to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) | |
19 | - | |
20 | - problem.app.issue_tracker.create_issue(problem) | |
21 | - problem.reload | |
22 | - | |
23 | - requested = have_requested(:post, "#{tracker.account}/#{tracker.project_id}/issues/#{tracker.api_token}") | |
24 | - WebMock.should requested.with(:body => /[production][foo#bar] FooError: Too Much Bar/) | |
25 | - WebMock.should requested.with(:body => /See this exception on Errbit/) | |
26 | - | |
27 | - problem.issue_link.should == @issue_link | |
28 | - end | |
29 | -end | |
30 | - |
spec/models/issue_trackers/gitlab_issues_tracker_spec.rb
0 → 100644
... | ... | @@ -0,0 +1,30 @@ |
1 | +require 'spec_helper' | |
2 | + | |
3 | +describe IssueTrackers::GitlabTracker do | |
4 | + it "should create an issue on Gitlab with problem params" do | |
5 | + notice = Fabricate :notice | |
6 | + tracker = Fabricate :gitlab_tracker, :app => notice.app | |
7 | + problem = notice.problem | |
8 | + | |
9 | + number = 5 | |
10 | + @issue_link = "#{tracker.account}/api/v3/projects/#{tracker.project_id}/issues/#{number}/?private_token=#{tracker.api_token}" | |
11 | + body = <<EOF | |
12 | +{ | |
13 | + "title": "Title" | |
14 | +} | |
15 | +EOF | |
16 | + | |
17 | + stub_request(:post, "#{tracker.account}/api/v3/projects/#{tracker.project_id}/issues/?private_token=#{tracker.api_token}"). | |
18 | + to_return(:status => 201, :headers => {'Location' => @issue_link}, :body => body ) | |
19 | + | |
20 | + problem.app.issue_tracker.create_issue(problem) | |
21 | + problem.reload | |
22 | + | |
23 | + requested = have_requested(:post, "#{tracker.account}/api/v3/projects/#{tracker.project_id}/issues/?private_token=#{tracker.api_token}") | |
24 | + WebMock.should requested.with(:body => /[production][foo#bar] FooError: Too Much Bar/) | |
25 | + WebMock.should requested.with(:body => /See this exception on Errbit/) | |
26 | + | |
27 | + problem.issue_link.should == @issue_link | |
28 | + end | |
29 | +end | |
30 | + | ... | ... |