open_github_issue 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: df9cf04a1ed325115b8e2e66a7ff4549e154dccd4aed589ee13d71850bea7a54
4
+ data.tar.gz: 6916b20e5bb1419c3de06e4d8ea48c27b42d3d5610b6a926c35221fa265af6bc
5
+ SHA512:
6
+ metadata.gz: 11bd35a4e18d0a985cf02a9834938705eaf198e84c7300eba93b26c0a775c84f5f1d22e228d71f4d52e8908c4c25fdf7ad480303d72ab100b74cdf2f20d34800
7
+ data.tar.gz: 9d96bbff0174b0cceddb3ba9841155760b3535d47982822b53e9e84a119c1835dbe0abb727460d6ece6c74fbdd210a795b0b1b149a6c82a2e0c337eec08d4930
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2018 Paweł J. Wal
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,118 @@
1
+ # OpenGithubIssue
2
+
3
+ A simple mountable Rails engine to provide a secure way for users to report issues they see with the application. Useful
4
+ in QA and UAT environments. Minimal gem with no dependencies outside of Rails and Octokit.
5
+
6
+ ## Installation
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'open_github_issue'
11
+ ```
12
+
13
+ And then execute:
14
+ ```bash
15
+ $ bundle
16
+ ```
17
+
18
+ Or install it yourself as:
19
+ ```bash
20
+ $ gem install open_github_issue
21
+ ```
22
+
23
+ This engine requires mounting, e.g.:
24
+
25
+ ```ruby
26
+ # config/routes.rb
27
+
28
+ mount OpenGithubIssue::Engine, on: '/ogi'
29
+ ```
30
+
31
+ Include JavaScript in `app/assets/javascripts/application.js`:
32
+
33
+ ```javascript
34
+ // = require 'open_github_issue'
35
+ ```
36
+
37
+ Include default CSS in `app/assets/stylesheets/application.css` (or equivalent):
38
+
39
+ ``` css
40
+ /*
41
+ * = require 'open_github_issue'
42
+ */
43
+ ```
44
+
45
+ Or, if you're using SCSS:
46
+
47
+ ``` scss
48
+ @import('open_github_issue');
49
+ ```
50
+
51
+
52
+ ## Configuration
53
+
54
+ Build an initializer like this one (defaults presented where available):
55
+
56
+ ```ruby
57
+ OpenGithubIssue.configure do |config|
58
+ config.github_access_token = 'insert-token-here' # default: nil
59
+ config.github_repo = 'paweljw/open_github_issue' # default: nil
60
+ config.user_method = :current_user # default
61
+ config.user_name_method = :email # default
62
+ config.constraint = proc { |user| user } # default
63
+ end
64
+ ```
65
+
66
+ ### `github_access_token`
67
+
68
+ A personal access token (get one in the GitHub settings) with `repo` permissions.
69
+
70
+ ### `github_repo`
71
+
72
+ Path to your GitHub repository (see above example).
73
+
74
+ ### `user_method`
75
+
76
+ This is expected to exist on controllers where OpenGithubIssue is used. Passed to `constraint`. `user_name_method` is also
77
+ called on the result of this method. It can be `nil`; nothing will be passed to constraint and user names will not be attached
78
+ to reports. `current_user` used by default - if you're using Devise, you're all set.
79
+
80
+ ### `user_name_method`
81
+
82
+ Attached to issue reports, transparently to the user reporting the issues. Useful for reporter identification purposes. Not
83
+ attached to reports if set to nil. `email` by default - if your current user responds to this, you're all set.
84
+
85
+ ### `constraint`
86
+
87
+ Called to determine whether the user should be shown the option to report issues. For example, if you want to show the form
88
+ to all logged in users, `proc { |user| user }` will suffice, or `proc { |_| true }` if everyone should have the possibility.
89
+ You can screen this out by role with e.g. `proc { |user| user.qa? }`. If everyone should have access, but only in e.g. staging
90
+ environment, `proc { |_| Rails.env.staging? }` will come in handy.
91
+
92
+ ## Customizing
93
+
94
+ This gem's behavior can be customized in several ways.
95
+
96
+ ### The report form
97
+
98
+ The report form can be customized to fit in better with the design of your application. If you place a partial in
99
+ `app/views/application/_open_github_issue_form.html.erb`, it will take precedence over the built-in view.
100
+
101
+ ### I18n
102
+
103
+ Localize this gem for your application using `config/locales/open_github_issue.en.yml` as reference. This gem is currently
104
+ localized in `:en` and `:pl` locales.
105
+
106
+ ### Controller behavior
107
+
108
+ Define your own `OpenGithubIssue::ReportsController` using the one in `app/controllers/open_github_issue/reports_controller.rb`
109
+ as reference to customize behavior, e.g. redirects and flashes.
110
+
111
+ ## TODO
112
+
113
+ [ ] Proper specs
114
+ [ ] Hook up CI (e.g. Travis CI)
115
+ [ ] Hook up a linting service (e.g. CodeClimate)
116
+
117
+ ## License
118
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'OpenGithubIssue'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.md')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+ APP_RAKEFILE = File.expand_path("../test/dummy/Rakefile", __FILE__)
18
+ load 'rails/tasks/engine.rake'
19
+
20
+
21
+ load 'rails/tasks/statistics.rake'
22
+
23
+
24
+
25
+ require 'bundler/gem_tasks'
26
+
27
+ require 'rake/testtask'
28
+
29
+ Rake::TestTask.new(:test) do |t|
30
+ t.libs << 'test'
31
+ t.pattern = 'test/**/*_test.rb'
32
+ t.verbose = false
33
+ end
34
+
35
+
36
+ task default: :test
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts/ .js
2
+ //= link_directory ../stylesheets/ .css
@@ -0,0 +1,3 @@
1
+ function openGithubIssueFormToggle() {
2
+ document.getElementById('open-github-issue-form').classList.toggle('active');
3
+ }
@@ -0,0 +1,73 @@
1
+ /*
2
+ *= require_self
3
+ */
4
+
5
+ .open-github-issue-form {
6
+ display: none;
7
+ width: 30%;
8
+ background: #fff;
9
+ position: fixed;
10
+ bottom: 80px;
11
+ right: 20px;
12
+ padding: 10px;
13
+ border-radius: 5px;
14
+ border: 1px solid #ccc;
15
+ box-shadow: 0px 0px 15px #666;
16
+ }
17
+
18
+ .open-github-issue-form.active {
19
+ display: block;
20
+ }
21
+
22
+ .open-github-issue-header {
23
+ font-size: 20px;
24
+ }
25
+
26
+ .open-github-issue-form.active {
27
+ display: block;
28
+ }
29
+
30
+ .open-github-issue-form-group .open-github-issue-form-text-area textarea {
31
+ width: 100%;
32
+ }
33
+
34
+ .open-github-issue-form-group .open-github-issue-form-text-input input {
35
+ width: 100%;
36
+ }
37
+
38
+ .open-github-issue-form-group, .open-github-issue-form-submit {
39
+ padding-top: 10px;
40
+ }
41
+
42
+ .open-github-issue-show {
43
+ width: 50px;
44
+ height: 50px;
45
+ background: #d9534f;
46
+ display: block;
47
+ position: fixed;
48
+ bottom: 20px;
49
+ right: 20px;
50
+ border-radius: 25px;
51
+ border: 0px none;
52
+ box-shadow: 3px 3px 5px #666;
53
+ text-align: center;
54
+ cursor: pointer;
55
+ }
56
+
57
+ .open-github-issue-show span {
58
+ color: #fff;
59
+ font-weight: bold;
60
+ font-size: 25px;
61
+ display: block;
62
+ margin: 15px auto;
63
+ }
64
+
65
+ .open-github-issue-show:hover span {
66
+ -webkit-animation:open-github-issue-spin 1s ease;
67
+ -moz-animation:open-github-issue-spin 1s ease;
68
+ animation:open-github-issue-spin 1s ease;
69
+ }
70
+
71
+ @-moz-keyframes open-github-issue-spin { 100% { -moz-transform: rotate(360deg); } }
72
+ @-webkit-keyframes open-github-issue-spin { 100% { -webkit-transform: rotate(360deg); } }
73
+ @keyframes open-github-issue-spin { 100% { -webkit-transform: rotate(360deg); transform:rotate(360deg); } }
@@ -0,0 +1,5 @@
1
+ module OpenGithubIssue
2
+ class ApplicationController < ActionController::Base
3
+ protect_from_forgery with: :exception
4
+ end
5
+ end
@@ -0,0 +1,19 @@
1
+ module OpenGithubIssue
2
+ class ReportsController < ApplicationController
3
+ def report
4
+ if Constraint.call(self) && Reporter.call(permitted_params, self)
5
+ flash[:notice] = t('open_github_issue.thanks')
6
+ else
7
+ flash[:alert] = t('open_github_issue.error')
8
+ end
9
+
10
+ redirect_to permitted_params[:path]
11
+ end
12
+
13
+ private
14
+
15
+ def permitted_params
16
+ params.require(:open_github_report).permit(:title, :body, :path)
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,8 @@
1
+ module OpenGithubIssue
2
+ module OpenGithubIssueHelper
3
+ def open_github_issue_form
4
+ return unless Constraint.call(self)
5
+ render partial: 'open_github_issue_form'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,32 @@
1
+ <div class="open-github-issue-show" onclick="openGithubIssueFormToggle()">
2
+ <span>&#9888;<span>
3
+ </div>
4
+
5
+ <div class="open-github-issue-form" id="open-github-issue-form">
6
+ <strong class="open-github-issue-header"><%= t('open_github_issue.header') %></strong>
7
+ <%= form_for :open_github_report, url: OpenGithubIssue::Engine.routes.url_helpers.report_path do |f| %>
8
+ <div class="open-github-issue-form-group">
9
+ <div class="open-github-issue-form-description">
10
+ <%= label :title, t('open_github_issue.title') %>
11
+ </div>
12
+ <div class="open-github-issue-form-text-input">
13
+ <%= f.text_field :title %>
14
+ </div>
15
+ </div>
16
+
17
+ <div class="open-github-issue-form-group">
18
+ <div class="open-github-issue-form-description">
19
+ <%= label :body, t('open_github_issue.body') %>
20
+ </div>
21
+ <div class="open-github-issue-form-text-area">
22
+ <%= f.text_area :body %>
23
+ </div>
24
+ </div>
25
+
26
+ <%= f.hidden_field :path, value: request.path %>
27
+
28
+ <div class="open-github-issue-form-submit">
29
+ <%= f.submit t('open_github_issue.submit') %>
30
+ </div>
31
+ <% end %>
32
+ </div>
@@ -0,0 +1,8 @@
1
+ en:
2
+ open_github_issue:
3
+ header: Report an issue
4
+ title: Title
5
+ body: Description
6
+ submit: Submit
7
+ thanks: Thank you for submitting the issue!
8
+ error: Your issue could not be submitted at this time.
@@ -0,0 +1,8 @@
1
+ pl:
2
+ open_github_issue:
3
+ header: Zgłoś błąd
4
+ title: Tytuł
5
+ body: Treść
6
+ submit: Wyślij
7
+ thanks: Dziękujemy za zgłoszenie problemu!
8
+ error: W tej chwili nie można było wysłać zgłoszenia.
data/config/routes.rb ADDED
@@ -0,0 +1,3 @@
1
+ OpenGithubIssue::Engine.routes.draw do
2
+ post :report, to: 'reports#report', as: :report
3
+ end
@@ -0,0 +1,7 @@
1
+ module OpenGithubIssue
2
+ class BaseService
3
+ def self.call(*args)
4
+ new(*args).call
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,13 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenGithubIssue
4
+ class Configuration
5
+ attr_accessor :github_access_token, :github_repo, :user_method, :user_name_method, :constraint
6
+
7
+ def initialize
8
+ self.user_method = :current_user
9
+ self.user_name_method = :email
10
+ self.constraint = proc { |user| user }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,23 @@
1
+ module OpenGithubIssue
2
+ class Constraint < BaseService
3
+ def initialize(controller)
4
+ @controller = controller
5
+ end
6
+
7
+ def call
8
+ constraint_proc.call(user)
9
+ end
10
+
11
+ private
12
+
13
+ def constraint_proc
14
+ @constraint_proc ||= OpenGithubIssue.configuration.constraint
15
+ end
16
+
17
+ def user
18
+ user_method = OpenGithubIssue.configuration.user_method
19
+ return unless user_method
20
+ @controller.public_send(user_method)
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,10 @@
1
+ module OpenGithubIssue
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace OpenGithubIssue
4
+ engine_name 'open_github_issue'
5
+
6
+ config.before_initialize do
7
+ ActiveSupport.on_load(:action_controller_base) { helper(OpenGithubIssue::OpenGithubIssueHelper) }
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,20 @@
1
+ module OpenGithubIssue
2
+ class GithubIssue < BaseService
3
+ def initialize(title, message)
4
+ @title = title
5
+ @message = message
6
+ end
7
+
8
+ def call
9
+ client.create_issue(repo, @title, @message)
10
+ end
11
+
12
+ def client
13
+ @client ||= Octokit::Client.new(access_token: OpenGithubIssue.configuration.github_access_token)
14
+ end
15
+
16
+ def repo
17
+ @repo ||= OpenGithubIssue.configuration.github_repo
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,55 @@
1
+ module OpenGithubIssue
2
+ class Reporter < BaseService
3
+ def initialize(params, controller)
4
+ @params = params
5
+ @controller = controller
6
+ end
7
+
8
+ def call
9
+ GithubIssue.call(title, message)
10
+ true
11
+ rescue Octokit::Error
12
+ false
13
+ end
14
+
15
+ private
16
+
17
+ attr_reader :controller, :params
18
+
19
+ def message
20
+ message = <<-MESSAGE
21
+ **User**: #{name}
22
+ **Path**: #{path}
23
+
24
+ ---
25
+
26
+ #{body}
27
+ MESSAGE
28
+ message.strip_heredoc
29
+ end
30
+
31
+ def title
32
+ params[:title]
33
+ end
34
+
35
+ def body
36
+ params[:body]
37
+ end
38
+
39
+ def path
40
+ params[:path]
41
+ end
42
+
43
+ def user
44
+ user_method = OpenGithubIssue.configuration.user_method
45
+ return unless user_method
46
+ controller.public_send(user_method)
47
+ end
48
+
49
+ def name
50
+ user_name_method = OpenGithubIssue.configuration.user_name_method
51
+ return '' unless user_name_method
52
+ user.public_send(user_name_method)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module OpenGithubIssue
2
+ VERSION = '0.1.0'
3
+ end
@@ -0,0 +1,19 @@
1
+ require 'octokit'
2
+
3
+ require 'open_github_issue/engine'
4
+
5
+ require 'open_github_issue/configuration'
6
+ require 'open_github_issue/base_service'
7
+ require 'open_github_issue/reporter'
8
+ require 'open_github_issue/github_issue'
9
+ require 'open_github_issue/constraint'
10
+
11
+ module OpenGithubIssue
12
+ def self.configuration
13
+ @configuration ||= Configuration.new
14
+ end
15
+
16
+ def self.configure
17
+ yield configuration
18
+ end
19
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :open_github_issue do
3
+ # # Task goes here
4
+ # end
metadata ADDED
@@ -0,0 +1,108 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: open_github_issue
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Paweł J. Wal
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-05-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 5.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 5.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: octokit
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '4.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '4.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: sqlite3
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ description:
56
+ email:
57
+ - p@steamshard.net
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - MIT-LICENSE
63
+ - README.md
64
+ - Rakefile
65
+ - app/assets/config/open_github_issue_manifest.js
66
+ - app/assets/javascripts/open_github_issue.js
67
+ - app/assets/stylesheets/open_github_issue.css
68
+ - app/controllers/open_github_issue/application_controller.rb
69
+ - app/controllers/open_github_issue/reports_controller.rb
70
+ - app/helpers/open_github_issue/open_github_issue_helper.rb
71
+ - app/views/application/_open_github_issue_form.html.erb
72
+ - config/locales/open_github_issue.en.yml
73
+ - config/locales/open_github_issue.pl.yml
74
+ - config/routes.rb
75
+ - lib/open_github_issue.rb
76
+ - lib/open_github_issue/base_service.rb
77
+ - lib/open_github_issue/configuration.rb
78
+ - lib/open_github_issue/constraint.rb
79
+ - lib/open_github_issue/engine.rb
80
+ - lib/open_github_issue/github_issue.rb
81
+ - lib/open_github_issue/reporter.rb
82
+ - lib/open_github_issue/version.rb
83
+ - lib/tasks/open_github_issue_tasks.rake
84
+ homepage: https://github.com/paweljw/open_github_issue
85
+ licenses:
86
+ - MIT
87
+ metadata: {}
88
+ post_install_message:
89
+ rdoc_options: []
90
+ require_paths:
91
+ - lib
92
+ required_ruby_version: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ requirements:
99
+ - - ">="
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ requirements: []
103
+ rubyforge_project:
104
+ rubygems_version: 2.7.3
105
+ signing_key:
106
+ specification_version: 4
107
+ summary: Allow users to open issues on GitHub from your UI securely.
108
+ test_files: []