errbit_gitlab_plugin 0.1.0 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0fdae03cfb0481b0da9efa7aa9d4ca02391a035a
4
- data.tar.gz: 9e29e0427988426a3ac1e750e95bfa092390dbc4
3
+ metadata.gz: 888f007985de3d983cad03f5d42cc191036ec28c
4
+ data.tar.gz: 31cfef1b01855ea219de3fe6be90915549be3cbd
5
5
  SHA512:
6
- metadata.gz: 2d6ab5bfd04c9254c48ade0f847fefa6d370b984d1c95759b2a781540f41242f51b0505d78103528c64805ab80618e40a7a0fb1814c962abaea03a7ce2fb2bca
7
- data.tar.gz: ea6f4b2002fb8f13b1beac573e1557b4b5579dc091c7ae8061baebd973e073466a477541aa4baac93562f638e4201266525779b07f0cefb34661fcf1f2c23545
6
+ metadata.gz: c9a85f40914a30284631c75b6aa8acc2a4983d90e446c1511bf0d9e2b5daaa44318d6fd394c18949201d46ed9bf430d1a08446df0794afea2937301e2c1bb709
7
+ data.tar.gz: 4e1cd3f73c7d63fcd87947c39760efdeded6b2c432b11ead717f5e9351ff8409708ed266189a1c7a376ada3cbc63790a92cc768a1420a03973014a5721b1005e
data/README.md CHANGED
@@ -1,24 +1,39 @@
1
1
  # ErrbitGitlabPlugin
2
2
 
3
- TODO: Write a gem description
3
+ This gem adds Gitlab issue tracker support to Errbit.
4
+
5
+ Version 1.0 is compatible with Errbit 0.4.
6
+
7
+ For (much) older versions of Errbit, try the 0.x gem versions or consider
8
+ updating your Errbit installation
4
9
 
5
10
  ## Installation
6
11
 
7
- Add this line to your application's Gemfile:
12
+ As described in [Errbit's README](https://github.com/errbit/errbit#plugins-and-integrations),
13
+ just add the gem to your `UserGemfile`:
8
14
 
9
- gem 'errbit_gitlab_plugin'
15
+ echo "gem 'errbit_gitlab_plugin'" > UserGemfile
10
16
 
11
17
  And then execute:
12
18
 
13
19
  $ bundle
14
20
 
15
- Or install it yourself as:
21
+ ## Usage
16
22
 
17
- $ gem install errbit_gitlab_plugin
23
+ Simply add your Gitlab URL, private token and project name to your errbit app.
18
24
 
19
- ## Usage
25
+ You can find your private token by clicking on "Account" in your Gitlab profile settings.
26
+
27
+ Upon saving the app, the gem will automatically test if your entered
28
+ credentials are valid and inform you otherwise.
29
+
30
+ ## Troubleshoot
31
+
32
+ > I entered my Gitlab settings and the tracker was saved, but I cannot create issues
20
33
 
21
- TODO: Write usage instructions here
34
+ The Gitlab API (at least on gitlab.com) does not seem to accept POST requests when using
35
+ a non-encrypted connection. Therefore, please make sure to use `https://` when
36
+ using gitlab.com as URL.
22
37
 
23
38
  ## Contributing
24
39
 
@@ -0,0 +1,43 @@
1
+ [See this exception on Errbit](<%= app_problem_url problem.app, problem %>)
2
+
3
+ <% if notice = problem.notices.first %>
4
+ # <%= notice.message.lines.map(&:strip).join(' ') %>
5
+
6
+ ## Summary ##
7
+ <% if notice.request['url'].present? %>
8
+ ### URL ###
9
+ <%= notice.request['url'] %>
10
+ <% end %>
11
+ ### Where ###
12
+ <%= notice.where %>
13
+
14
+ ### Occured ###
15
+ <%= notice.created_at.to_s(:precise) %>
16
+
17
+ ### Similar ###
18
+ <%= [notice.problem.notices_count - 1, 1].max %>
19
+
20
+ ## Params ##
21
+ ```ruby
22
+ <%= pretty_hash(notice.params).html_safe %>
23
+ ```
24
+
25
+ ## Session ##
26
+ ```ruby
27
+ <%= pretty_hash(notice.session).html_safe %>
28
+ ```
29
+
30
+ ## Backtrace ##
31
+ ```
32
+ <% notice.backtrace.lines.each do |line| %><%= format '%4d:', line.number %> <%= line.file_relative %> -> **<%= line.method %>**
33
+ <% end %>
34
+ ```
35
+
36
+ <% if notice.env_vars.present? %>
37
+ ## Environment ##
38
+ | Key | Value |
39
+ |------------|------------|
40
+ <% notice.env_vars.each do |key, val| %>| <%= key %> | <%= val %> |
41
+ <% end %>
42
+ <% end %>
43
+ <% end %>
@@ -18,8 +18,8 @@ Gem::Specification.new do |spec|
18
18
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
19
  spec.require_paths = ["lib"]
20
20
 
21
- spec.add_runtime_dependency 'errbit_plugin', '~> 0.4', '>= 0.4.0'
22
- spec.add_runtime_dependency 'gitlab', '~> 3.0.0', '>= 3.0.0'
21
+ spec.add_runtime_dependency 'errbit_plugin', '~> 0.5', '>= 0.5.0'
22
+ spec.add_runtime_dependency 'gitlab', '~> 3.4', '>= 3.4.0'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
25
25
  spec.add_development_dependency 'rake', '~> 0'
@@ -4,7 +4,11 @@ require 'errbit_gitlab_plugin/rails'
4
4
 
5
5
  module ErrbitGitlabPlugin
6
6
  def self.root
7
- File.expand_path '../..', __FILE__
7
+ Pathname.new File.expand_path('../..', __FILE__)
8
+ end
9
+
10
+ def self.read_static_file(file)
11
+ File.read(root.join('static', file))
8
12
  end
9
13
  end
10
14
 
@@ -4,25 +4,24 @@ module ErrbitGitlabPlugin
4
4
  class IssueTracker < ErrbitPlugin::IssueTracker
5
5
  LABEL = 'gitlab'
6
6
 
7
- NOTE = ''
8
-
9
- FIELDS = [
10
- [:account, {
11
- :label => "Gitlab URL",
12
- :placeholder => "e.g. https://example.net"
13
- }],
14
- [:api_token, {
15
- :placeholder => "API Token for your account"
16
- }],
17
- [:project_id, {
18
- :label => "Ticket Project ID (use Number)",
19
- :placeholder => "Gitlab Project where issues will be created"
20
- }],
21
- [:alt_project_id, {
22
- :label => "Project Name (namespace/project)",
23
- :placeholder => "Gitlab Project where issues will be created"
24
- }]
25
- ]
7
+ NOTE = "Creating issues may take some time as the actual project ID has to be looked up using the Gitlab API. <br/>
8
+ If you are using gitlab.com as installation, please make sure to use 'https://', otherwise, their API
9
+ will not accept some of the our commands."
10
+
11
+ FIELDS = {
12
+ endpoint: {
13
+ label: 'Gitlab URL',
14
+ placeholder: 'The URL to your gitlab installation or the public gitlab server, e.g. https://www.gitlab.com'
15
+ },
16
+ api_token: {
17
+ label: 'API Token',
18
+ placeholder: "Your account's API token (see Profile -> Account)"
19
+ },
20
+ path_with_namespace: {
21
+ label: 'Project name',
22
+ placeholder: 'E.g. your_username/your_project'
23
+ }
24
+ }
26
25
 
27
26
  def self.label
28
27
  LABEL
@@ -32,66 +31,148 @@ module ErrbitGitlabPlugin
32
31
  NOTE
33
32
  end
34
33
 
34
+ #
35
+ # Form fields that will be presented to the administrator when setting up
36
+ # or editing the errbit app. The values we collect will be available for use
37
+ # later when we have an instance of this class.
38
+ #
35
39
  def self.fields
36
40
  FIELDS
37
41
  end
38
42
 
39
- def self.body_template
40
- @body_template ||= ERB.new(File.read(
41
- File.join(
42
- ErrbitGitlabPlugin.root, 'views', 'gitlab_issues_body.txt.erb'
43
- )
44
- ))
43
+ #
44
+ # Icons to be displayed for this issue tracker
45
+ #
46
+ def self.icons
47
+ @icons ||= {
48
+ create: ['image/png', ErrbitGitlabPlugin.read_static_file('gitlab_create.png')],
49
+ goto: ['image/png', ErrbitGitlabPlugin.read_static_file('gitlab_goto.png')],
50
+ inactive: ['image/png', ErrbitGitlabPlugin.read_static_file('gitlab_inactive.png')]
51
+ }
45
52
  end
46
53
 
47
- def self.summary_template
48
- @summary_template ||= ERB.new(File.read(
49
- File.join(
50
- ErrbitGitlabPlugin.root, 'views', 'gitlab_issues_summary.txt.erb'
51
- )
52
- ))
54
+ #
55
+ # Used to pass an own template to errbit's issue rendering.
56
+ # The rendered template is then passed to any #create_issue call.
57
+ #
58
+ def render_body_args
59
+ ['errbit_gitlab_plugin/issue', :formats => [:md]]
53
60
  end
54
61
 
62
+ #
63
+ # @return [String] the URL to the given project's issues section
64
+ #
55
65
  def url
56
- sprintf('%s/%s/issues', params['account'], params['alt_project_id'])
66
+ format '%s/%s/issues', options[:endpoint], options[:path_with_namespace]
57
67
  end
58
68
 
59
69
  def configured?
60
- params['project_id'].present? && params['api_token'].present?
70
+ self.class.fields.keys.all? { |field_name| options[field_name].present? }
61
71
  end
62
72
 
63
- def comments_allowed?; false; end
73
+ def comments_allowed?
74
+ true
75
+ end
64
76
 
77
+ # Called to validate user input. Just return a hash of errors if there are any
65
78
  def errors
66
- errors = []
67
- if self.class.fields.detect {|f| params[f[0]].blank? }
68
- errors << [:base, 'You must specify your Gitlab URL, API token, Project ID and Project Name']
79
+ errs = []
80
+
81
+ # Make sure that every field is filled out
82
+ self.class.fields.except(:project_id).each_with_object({}) do |(field_name, field_options), h|
83
+ if options[field_name].blank?
84
+ errs << "#{field_options[:label]} must be present"
85
+ end
86
+ end
87
+
88
+ # We can only perform the other tests if the necessary values are at least present
89
+ return {:base => errs.to_sentence} unless errs.size.zero?
90
+
91
+ # Check if the given endpoint actually exists
92
+ unless gitlab_endpoint_exists?(options[:endpoint])
93
+ errs << 'No Gitlab installation was found under the given URL'
94
+ return {:base => errs.to_sentence}
95
+ end
96
+
97
+ # Check if a user by the given token exists
98
+ unless gitlab_user_exists?(options[:endpoint], options[:api_token])
99
+ errs << 'No user with the given API token was found'
100
+ return {:base => errs.to_sentence}
101
+ end
102
+
103
+ # Check if there is a project with the given name on the server
104
+ unless gitlab_project_id(options[:endpoint], options[:api_token], options[:path_with_namespace])
105
+ errs << "A project named '#{options[:path_with_namespace]}' could not be found on the server.
106
+ Please make sure to enter it exactly as it appears in your address bar in Gitlab (case sensitive)"
107
+ return {:base => errs.to_sentence}
108
+ end
109
+
110
+ {}
111
+ end
112
+
113
+ def create_issue(title, body, reported_by = nil)
114
+ ticket = with_gitlab do |g|
115
+ g.create_issue(gitlab_project_id, title, description: body, labels: 'errbit')
69
116
  end
70
- errors
117
+
118
+ format('%s/%s', url, ticket.id)
71
119
  end
72
120
 
73
- def create_issue(problem, reported_by = nil)
74
- Gitlab.configure do |config|
75
- config.endpoint = sprintf('%s/api/v3', params['account'])
76
- config.private_token = params['api_token']
77
- config.user_agent = 'Errbit User Agent'
121
+ private
122
+
123
+ #
124
+ # Tries to find a project with the given name in the given Gitlab installation
125
+ # and returns its ID (if any)
126
+ #
127
+ def gitlab_project_id(gitlab_url = options[:endpoint], token = options[:api_token], project = options[:path_with_namespace])
128
+ @project_id ||= with_gitlab(gitlab_url, token) do |g|
129
+ g.projects.detect { |p| p.path_with_namespace == project }.try(:id)
78
130
  end
131
+ end
79
132
 
80
- title = "[#{ problem.environment }][#{ problem.where }] #{problem.message.to_s.truncate(100)}"
81
- description_summary = self.class.summary_template.result(binding)
82
- description_body = self.class.body_template.result(binding)
133
+ #
134
+ # @return [String] a formatted APIv3 URL for the given +gitlab_url+
135
+ #
136
+ def gitlab_endpoint(gitlab_url)
137
+ format '%s/api/v3', gitlab_url
138
+ end
83
139
 
84
- ticket = Gitlab.create_issue(params['project_id'], title, {
85
- :description => description_summary,
86
- :labels => "errbit"
87
- })
140
+ #
141
+ # Checks whether there is a gitlab installation
142
+ # at the given +gitlab_url+
143
+ #
144
+ def gitlab_endpoint_exists?(gitlab_url)
145
+ with_gitlab(gitlab_url, 'Iamsecret') do |g|
146
+ g.user
147
+ end
148
+ rescue Gitlab::Error::Unauthorized
149
+ true
150
+ rescue Exception
151
+ false
152
+ end
88
153
 
89
- Gitlab.create_issue_note(params['project_id'], ticket.id, description_body)
154
+ #
155
+ # Checks whether a user with the given +token+ exists
156
+ # in the gitlab installation located at +gitlab_url+
157
+ #
158
+ def gitlab_user_exists?(gitlab_url, private_token)
159
+ with_gitlab(gitlab_url, private_token) do |g|
160
+ g.user
161
+ end
162
+
163
+ true
164
+ rescue Gitlab::Error::Unauthorized
165
+ false
166
+ end
90
167
 
91
- problem.update_attributes(
92
- :issue_link => sprintf("%s/%s", url, ticket.id),
93
- :issue_type => self.class.label
94
- )
168
+ #
169
+ # Connects to the gitlab installation at +gitlab_url+
170
+ # using the given +private_token+ and executes the given block
171
+ #
172
+ def with_gitlab(gitlab_url = options[:endpoint], private_token = options[:api_token])
173
+ yield Gitlab.client(endpoint: gitlab_endpoint(gitlab_url),
174
+ private_token: private_token,
175
+ user_agent: 'Errbit User Agent')
95
176
  end
96
177
  end
97
178
  end
@@ -1,3 +1,3 @@
1
1
  module ErrbitGitlabPlugin
2
- VERSION = "0.1.0"
2
+ VERSION = '1.0.0'
3
3
  end
File without changes
File without changes
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: errbit_gitlab_plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Stephen Crosby
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-10 00:00:00.000000000 Z
11
+ date: 2015-10-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: errbit_plugin
@@ -16,40 +16,40 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0.4'
19
+ version: '0.5'
20
20
  - - ">="
21
21
  - !ruby/object:Gem::Version
22
- version: 0.4.0
22
+ version: 0.5.0
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - "~>"
28
28
  - !ruby/object:Gem::Version
29
- version: '0.4'
29
+ version: '0.5'
30
30
  - - ">="
31
31
  - !ruby/object:Gem::Version
32
- version: 0.4.0
32
+ version: 0.5.0
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: gitlab
35
35
  requirement: !ruby/object:Gem::Requirement
36
36
  requirements:
37
37
  - - "~>"
38
38
  - !ruby/object:Gem::Version
39
- version: 3.0.0
39
+ version: '3.4'
40
40
  - - ">="
41
41
  - !ruby/object:Gem::Version
42
- version: 3.0.0
42
+ version: 3.4.0
43
43
  type: :runtime
44
44
  prerelease: false
45
45
  version_requirements: !ruby/object:Gem::Requirement
46
46
  requirements:
47
47
  - - "~>"
48
48
  - !ruby/object:Gem::Version
49
- version: 3.0.0
49
+ version: '3.4'
50
50
  - - ">="
51
51
  - !ruby/object:Gem::Version
52
- version: 3.0.0
52
+ version: 3.4.0
53
53
  - !ruby/object:Gem::Dependency
54
54
  name: bundler
55
55
  requirement: !ruby/object:Gem::Requirement
@@ -91,16 +91,15 @@ files:
91
91
  - LICENSE.txt
92
92
  - README.md
93
93
  - Rakefile
94
+ - app/views/errbit_gitlab_plugin/issue.md.erb
94
95
  - errbit_gitlab_plugin.gemspec
95
96
  - lib/errbit_gitlab_plugin.rb
96
97
  - lib/errbit_gitlab_plugin/issue_tracker.rb
97
98
  - lib/errbit_gitlab_plugin/rails.rb
98
99
  - lib/errbit_gitlab_plugin/version.rb
99
- - vendor/assets/images/gitlab_create.png
100
- - vendor/assets/images/gitlab_goto.png
101
- - vendor/assets/images/gitlab_inactive.png
102
- - views/gitlab_issues_body.txt.erb
103
- - views/gitlab_issues_summary.txt.erb
100
+ - static/gitlab_create.png
101
+ - static/gitlab_goto.png
102
+ - static/gitlab_inactive.png
104
103
  homepage: https://github.com/brandedcrate/errbit_gitlab_plugin
105
104
  licenses:
106
105
  - MIT
@@ -1,29 +0,0 @@
1
- <% if notice = problem.notices.first %>
2
- ## Params ##
3
- ```
4
- <%= pretty_hash(notice.params) %>
5
- ```
6
-
7
- ## Session ##
8
- ```
9
- <%= pretty_hash(notice.session) %>
10
- ```
11
-
12
- ## Backtrace ##
13
- ```
14
- <% notice.backtrace_lines.each do |line| %><%= line.number %>: <%= line.file_relative %> -> **<%= line.method %>**
15
- <% end %>
16
- ```
17
-
18
- ## Environment ##
19
-
20
- <table>
21
- <% for key, val in notice.env_vars %>
22
- <tr>
23
- <td><%= key %>:</td>
24
- <td><%= val %></td>
25
- </tr>
26
- <% end %>
27
- </table>
28
- <% end %>
29
-
@@ -1,17 +0,0 @@
1
- [See this exception on Errbit](<%= problem.url %> "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 %>