Commit 1295712176f14cf79a9fe7c513bc19661ae8e73e
1 parent
78b19e34
Exists in
master
and in
1 other branch
Working on Gitlab integration
Showing
6 changed files
with
118 additions
and
0 deletions
Show diff stats
4.47 KB
4.47 KB
4.35 KB
... | ... | @@ -0,0 +1,43 @@ |
1 | +if defined? Gitlab | |
2 | + class IssueTrackers::GitlabTracker < IssueTracker | |
3 | + Label = "gitlab" | |
4 | + Fields = [ | |
5 | + [:account, { | |
6 | + :label => "Gitlab URL", | |
7 | + :placeholder => "e.g. https://example.net" | |
8 | + }], | |
9 | + [:api_token, { | |
10 | + :placeholder => "API Token for your account" | |
11 | + }], | |
12 | + [:project_id, { | |
13 | + :label => "Ticket Project Short Name / ID", | |
14 | + :placeholder => "Gitlab Project where issues will be created" | |
15 | + }] | |
16 | + ] | |
17 | + | |
18 | + def check_params | |
19 | + if Fields.detect {|f| self[f[0]].blank?} | |
20 | + errors.add :base, 'You must specify your Gitlab URL, API token and Project ID' | |
21 | + end | |
22 | + end | |
23 | + | |
24 | + def create_issue(problem, reported_by = nil) | |
25 | + Gitlab.configure do |config| | |
26 | + config.endpoint = "#{account}/api/v2" | |
27 | + config.private_token = api_token | |
28 | + config.user_agent = 'Errbit User Agent' | |
29 | + end | |
30 | + title = issue_title problem | |
31 | + description = body_template.result(binding) | |
32 | + Gitlab.create_issue(project_id, title, { :description => description, :labels => "errbit" } ) | |
33 | + end | |
34 | + | |
35 | + def body_template | |
36 | + @@body_template ||= ERB.new(File.read(Rails.root + "app/views/issue_trackers/gitlab_body.txt.erb").gsub(/^\s*/, '')) | |
37 | + end | |
38 | + | |
39 | + def url | |
40 | + "#{account}/#{project_id}/issues" | |
41 | + end | |
42 | + end | |
43 | +end | ... | ... |
... | ... | @@ -0,0 +1,45 @@ |
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 | + | |
18 | +## Params ## | |
19 | +``` | |
20 | +<%= pretty_hash(notice.params) %> | |
21 | +``` | |
22 | + | |
23 | +## Session ## | |
24 | +``` | |
25 | +<%= pretty_hash(notice.session) %> | |
26 | +``` | |
27 | + | |
28 | +## Backtrace ## | |
29 | +``` | |
30 | +<% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>** | |
31 | +<% end %> | |
32 | +``` | |
33 | + | |
34 | +## Environment ## | |
35 | + | |
36 | +<table> | |
37 | +<% for key, val in notice.env_vars %> | |
38 | + <tr> | |
39 | + <td><%= key %>:</td> | |
40 | + <td><%= val %></td> | |
41 | + </tr> | |
42 | +<% end %> | |
43 | +</table> | |
44 | +<% end %> | |
45 | + | ... | ... |
spec/models/issue_trackers/github_issues_tracker_spec 2.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}/#{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 | + | ... | ... |