errbit_plugin 0.5.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,8 +1,14 @@
1
- # ErrbitPlugin [![Build Status](https://travis-ci.org/errbit/errbit_plugin.svg?branch=master)](https://travis-ci.org/errbit/errbit_plugin)
1
+ # ErrbitPlugin
2
+
3
+ [![RSpec](https://github.com/errbit/errbit_plugin/actions/workflows/rspec.yml/badge.svg)](https://github.com/errbit/errbit_plugin/actions/workflows/rspec.yml)
4
+ [![RSpec on JRuby](https://github.com/errbit/errbit_plugin/actions/workflows/jruby.yml/badge.svg)](https://github.com/errbit/errbit_plugin/actions/workflows/jruby.yml)
5
+ [![Ruby Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://github.com/standardrb/standard)
6
+
2
7
  ErrbitPlugin provides a set of base classes that you can extend to create
3
8
  Errbit plugins.
4
9
 
5
10
  ## Creating plugins
11
+
6
12
  ErrbitPlugins are Ruby gems that extend the functionality of Errbit. To get
7
13
  started, create a Ruby gem and add 'errbit_plugin' as a dependency in your
8
14
  gem's gemspec.
@@ -11,16 +17,20 @@ Now you can start adding plugins. At the moment, there is only one kind of
11
17
  plugin you can create, and that is the issue tracker.
12
18
 
13
19
  ### Issue Trackers
20
+
14
21
  An issue tracker plugin is a Ruby class that enables you to link errors within
15
22
  errbit to an issue in an external issue tracker like Github. An app within
16
23
  errbit can be associated an issue tracker or not. When there is an association,
17
24
  errbit users can choose 'create issue' from an error page which will both
18
25
  create an issue on the external issue tracker out of the given error and link
19
- that issue to the errbit error.
26
+ that issue to the errbit error. Likewise, a user can also choose 'close issue'
27
+ to close the issue on the external issue tracker, if your plugin provides a
28
+ method to do so.
20
29
 
21
30
  Your issue tracker plugin is responsible for providing the interface defined by
22
31
  ErrbitPlugin::IssueTracker. All of the required methods must be implemented and
23
32
  the class must extend ErrbitPlugin::IssueTracker. Here's an example:
33
+
24
34
  ```ruby
25
35
  class MyIssueTracker < ErrbitPlugin::IssueTracker
26
36
 
@@ -42,7 +52,8 @@ class MyIssueTracker < ErrbitPlugin::IssueTracker
42
52
  placeholder: "Some placeholder text"
43
53
  },
44
54
  password: {
45
- placeholder: "Some more placeholder text"
55
+ placeholder: "Some more placeholder text",
56
+ label: "Passphrase" # a label to use in the UI instead of 'password'
46
57
  }
47
58
  }
48
59
  end
@@ -63,30 +74,53 @@ class MyIssueTracker < ErrbitPlugin::IssueTracker
63
74
  # errbit know by returning a Boolean here
64
75
  def configured?
65
76
  # In this case, we'll say this issue tracker is configured when username
66
- # is set
67
- !!params['username']
77
+ # and password are set
78
+ options[:username].present? && options[:password].present?
68
79
  end
69
80
 
70
81
  # Called to validate user input. Just return a hash of errors if there are
71
82
  # any
72
83
  def errors
73
- if @params['field_one']
84
+ if options[:username]
74
85
  {}
75
86
  else
76
- { :field_one, 'Field One must be present' }
87
+ { field_one: 'username must be present' }
77
88
  end
78
89
  end
79
90
 
80
91
  # This is where you actually go create the issue on the external issue
81
- # tracker. You get access to everything in params, a problem resource and a
82
- # user resource (reported_by). Once you've created an external issue, save
83
- # its type and url on the problem resource.
84
- def create_issue(problem, reported_by = nil)
92
+ # tracker. You get access to everything in options, an issue title, body and
93
+ # a user record representing the user who's creating the issue.
94
+ #
95
+ # Return a string with a link to the issue
96
+ def create_issue(title, body, user: {})
85
97
  # Create an issue! Then update the problem to link it.
86
- problem.update_attributes(
87
- :issue_type => 'bug',
88
- :issue_link => 'http://some-remote-tracker.com/mynewissue'
89
- )
98
+
99
+ 'http://sometracker.com/my/issue/123'
100
+ end
101
+
102
+ # This method is optional. Errbit will create body text for your issue by
103
+ # calling render_to_string with some arguments. If you want control over
104
+ # those arguments, you can specify them here. You can control which file is
105
+ # rendered and anything else Rails allows you to specify as arguments in
106
+ # render_to_string.
107
+ #
108
+ # If you don't implement this method, Errbit will render a body using a
109
+ # default template
110
+ #
111
+ # @see http://apidock.com/rails/ActionController/Base/render_to_string
112
+ def render_body_args
113
+ # In this example, we want to render a special file
114
+ ['/path/to/some/template', formats: [:rdoc]]
115
+ end
116
+
117
+ # This method is optional, and is where you actually go close the issue on
118
+ # the external issue tracker. You get access to everything in options, a
119
+ # string with a link to the issue # and a user resource.
120
+ #
121
+ # return true if successful, false otherwise
122
+ def close_issue(issue_link, user = {})
123
+ # Close the issue! (Perhaps using the passed in issue_link url to identify it.)
90
124
  end
91
125
 
92
126
  # The URL for your remote issue tracker
data/Rakefile CHANGED
@@ -1 +1,3 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "bundler/gem_tasks"
@@ -1,23 +1,25 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
3
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
- require 'errbit_plugin/version'
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "lib/errbit_plugin/version"
5
4
 
6
5
  Gem::Specification.new do |spec|
7
- spec.name = "errbit_plugin"
8
- spec.version = ErrbitPlugin::VERSION
9
- spec.authors = ["Stephen Crosby"]
10
- spec.email = ["stevecrozz@gmail.com"]
11
- spec.description = %q{Base to create an errbit plugin}
12
- spec.summary = %q{Base to create an errbit plugin}
13
- spec.homepage = "http://github.com/errbit/errbit"
14
- spec.license = "MIT"
6
+ spec.name = "errbit_plugin"
7
+ spec.version = ErrbitPlugin::VERSION
8
+ spec.authors = ["Stephen Crosby"]
9
+ spec.email = ["stevecrozz@gmail.com"]
15
10
 
16
- spec.files = `git ls-files`.split($/)
17
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
18
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
19
- spec.require_paths = ["lib"]
11
+ spec.summary = "Base to create an errbit plugin"
12
+ spec.description = "Base to create an errbit plugin"
13
+ spec.homepage = "https://github.com/errbit/errbit_plugin"
14
+ spec.license = "MIT"
15
+ spec.required_ruby_version = ">= 3.1.0"
20
16
 
21
- spec.add_development_dependency "bundler", "~> 1.3"
22
- spec.add_development_dependency "rake"
17
+ spec.metadata["homepage_uri"] = spec.homepage
18
+ spec.metadata["source_code_uri"] = spec.homepage
19
+ spec.metadata["bug_tracker_uri"] = "#{spec.homepage}/issues"
20
+ spec.metadata["rubygems_mfa_required"] = "true"
21
+
22
+ spec.files = `git ls-files`.split($/)
23
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
23
25
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ErrbitPlugin
2
4
  # abstract class for issue trackers
3
5
  class IssueTracker
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ErrbitPlugin
2
- class ValidateIssueTracker
4
+ class IssueTrackerValidator
3
5
  def initialize(klass)
4
6
  @klass = klass
5
7
  @errors = []
@@ -17,11 +19,11 @@ module ErrbitPlugin
17
19
  private
18
20
 
19
21
  def good_inherit?
20
- unless @klass.ancestors.include?(ErrbitPlugin::IssueTracker)
22
+ if @klass.ancestors.include?(ErrbitPlugin::IssueTracker)
23
+ true
24
+ else
21
25
  add_errors(:not_inherited)
22
26
  false
23
- else
24
- true
25
27
  end
26
28
  end
27
29
 
@@ -55,7 +57,7 @@ module ErrbitPlugin
55
57
  @instance ||= @klass.new({})
56
58
  end
57
59
 
58
- def add_errors(key, value=nil)
60
+ def add_errors(key, value = nil)
59
61
  @errors << [key, value].compact
60
62
  end
61
63
  end
@@ -0,0 +1,57 @@
1
+ # frozen_string_literal: true
2
+
3
+ module ErrbitPlugin
4
+ class NoneIssueTracker < IssueTracker
5
+ def self.label
6
+ "none"
7
+ end
8
+
9
+ def self.note
10
+ "When no issue tracker has been configured, you will be able to " \
11
+ "leave comments on errors."
12
+ end
13
+
14
+ def self.fields
15
+ {}
16
+ end
17
+
18
+ def self.icons
19
+ @icons ||= {
20
+ create: ["image/png", read_static_file("none_create.png")],
21
+ goto: ["image/png", read_static_file("none_create.png")],
22
+ inactive: ["image/png", read_static_file("none_inactive.png")]
23
+ }
24
+ end
25
+
26
+ def self.read_static_file(file)
27
+ File.read(File.expand_path(File.join(
28
+ File.dirname(__FILE__), "..", "..", "static", file
29
+ )))
30
+ end
31
+
32
+ ##
33
+ # The NoneIssueTracker is mark like configured? false because it not valid
34
+ # like a real IssueTracker
35
+ def configured?
36
+ false
37
+ end
38
+
39
+ def errors
40
+ {}
41
+ end
42
+
43
+ def url
44
+ ""
45
+ end
46
+
47
+ def create_issue(*)
48
+ false
49
+ end
50
+
51
+ def close_issue(*)
52
+ false
53
+ end
54
+ end
55
+ end
56
+
57
+ ErrbitPlugin::Registry.add_issue_tracker(ErrbitPlugin::NoneIssueTracker)
@@ -1,5 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ErrbitPlugin
2
4
  class IncompatibilityError < StandardError; end
5
+
3
6
  class AlreadyRegisteredError < StandardError; end
4
7
 
5
8
  module Registry
@@ -13,12 +16,12 @@ module ErrbitPlugin
13
16
  "issue_tracker '#{key}' already registered"
14
17
  end
15
18
 
16
- validate = ValidateIssueTracker.new(klass)
19
+ validator = IssueTrackerValidator.new(klass)
17
20
 
18
- if validate.valid?
21
+ if validator.valid?
19
22
  @issue_trackers[key] = klass
20
23
  else
21
- raise IncompatibilityError.new(validate.errors.join('; '))
24
+ raise IncompatibilityError.new(validator.errors.join("; "))
22
25
  end
23
26
  end
24
27
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module ErrbitPlugin
2
- VERSION = "0.5.0"
4
+ VERSION = "0.7.0"
3
5
  end
data/lib/errbit_plugin.rb CHANGED
@@ -1,5 +1,7 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "errbit_plugin/version"
2
4
  require "errbit_plugin/registry"
3
5
  require "errbit_plugin/issue_tracker"
4
- require "errbit_plugin/validate_issue_tracker"
5
- require "errbit_plugin/issue_trackers/none"
6
+ require "errbit_plugin/issue_tracker_validator"
7
+ require "errbit_plugin/none_issue_tracker"