lolcommits-sample_plugin 0.0.1

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
+ SHA1:
3
+ metadata.gz: 7ffe2fc5bb37796e2caa83cdc405f1ab4808549f
4
+ data.tar.gz: c619b4df32c1e19f25d3bbce19a7b84fd0ee549c
5
+ SHA512:
6
+ metadata.gz: d453e58648d7b88bd2a8d7b842ae99779b05a90ddc80405f3181b0c9f5c9a267f50509bfc770dad363e56dbcca22de8bec2190d29462e90d665fb881de67bb34
7
+ data.tar.gz: 3bac9cf3fcd42827acac4ae7834b3f889d0cc21db2cbef0596a01de2e3c3bdd79c7d0ea5858f7aebaf606c72771b33d49e2566afb5b280149a4ce6132f1ad59f
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.simplecov ADDED
@@ -0,0 +1,9 @@
1
+ SimpleCov.start do
2
+ add_filter '/test/'
3
+ add_filter '/vendor/'
4
+ end
5
+
6
+ SimpleCov.at_exit do
7
+ SimpleCov.result.format!
8
+ `open ./coverage/index.html` if RUBY_PLATFORM =~ /darwin/
9
+ end
data/.travis.yml ADDED
@@ -0,0 +1,31 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.10
7
+ - 2.2.8
8
+ - 2.3.5
9
+ - 2.4.2
10
+ - ruby-head
11
+
12
+ before_install:
13
+ - gem install bundler -v 1.13.7
14
+ - git --version
15
+ - git config --global user.email "lol@commits.org"
16
+ - git config --global user.name "Lolcommits"
17
+
18
+ matrix:
19
+ allow_failures:
20
+ - rvm: ruby-head
21
+
22
+ env:
23
+ global:
24
+ - CC_TEST_REPORTER_ID=7fb6d4a66ca2ac21658b29d3738952994f3b68354a8e3e6318bf1108eda6c243
25
+ - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
26
+ before_script:
27
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
28
+ - chmod +x ./cc-test-reporter
29
+ - ./cc-test-reporter before-build - GIT_COMMITTED_AT=$(if [ "$TRAVIS_PULL_REQUEST" == "false" ]; then git log -1 --pretty=format:%ct; else git log -1 --skip 1 --pretty=format:%ct; fi)
30
+ after_script:
31
+ - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
@@ -0,0 +1,50 @@
1
+ # Contributor Code of Conduct
2
+
3
+ As contributors and maintainers of this project, and in the interest of
4
+ fostering an open and welcoming community, we pledge to respect all people who
5
+ contribute through reporting issues, posting feature requests, updating
6
+ documentation, submitting pull requests or patches, and other activities.
7
+
8
+ We are committed to making participation in this project a harassment-free
9
+ experience for everyone, regardless of level of experience, gender, gender
10
+ identity and expression, sexual orientation, disability, personal appearance,
11
+ body size, race, ethnicity, age, religion, or nationality.
12
+
13
+ Examples of unacceptable behavior by participants include:
14
+
15
+ * The use of sexualized language or imagery
16
+ * Personal attacks
17
+ * Trolling or insulting/derogatory comments
18
+ * Public or private harassment
19
+ * Publishing other's private information, such as physical or electronic
20
+ addresses, without explicit permission
21
+ * Other unethical or unprofessional conduct
22
+
23
+ Project maintainers have the right and responsibility to remove, edit, or
24
+ reject comments, commits, code, wiki edits, issues, and other contributions
25
+ that are not aligned to this Code of Conduct, or to ban temporarily or
26
+ permanently any contributor for other behaviors that they deem inappropriate,
27
+ threatening, offensive, or harmful.
28
+
29
+ By adopting this Code of Conduct, project maintainers commit themselves to
30
+ fairly and consistently applying these principles to every aspect of managing
31
+ this project. Project maintainers who do not follow or enforce the Code of
32
+ Conduct may be permanently removed from the project team.
33
+
34
+ This code of conduct applies both within project spaces and in public spaces
35
+ when an individual is representing the project or its community.
36
+
37
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
38
+ reported by contacting a project maintainer via [GitHub][maintainer]. All
39
+ complaints will be reviewed and investigated and will result in a response that
40
+ is deemed necessary and appropriate to the circumstances. Maintainers are
41
+ obligated to maintain confidentiality with regard to the reporter of an
42
+ incident.
43
+
44
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage],
45
+ version 1.3.0, available at
46
+ [http://contributor-covenant.org/version/1/3/0/][version]
47
+
48
+ [maintainer]: https://github.com/matthutchinson
49
+ [homepage]: http://contributor-covenant.org
50
+ [version]: http://contributor-covenant.org/version/1/3/0/
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,37 @@
1
+ ### Contributing
2
+
3
+ Pull Requests are welcome! To start helping out:
4
+
5
+ [Fork](https://guides.github.com/activities/forking) then clone the repository:
6
+
7
+ git clone git@github.com:your-username/lolcommits-sample_plugin.git
8
+
9
+ Create your feature branch:
10
+
11
+ git checkout -b my-new-feature
12
+
13
+ When you are happy with your change, run the full test suite:
14
+
15
+ bundle exec rake
16
+
17
+ With a passing test suite, commit your changes, push and submit a new [Pull
18
+ Request](https://github.com/lolcommits/lolcommits-sample_plugin/compare):
19
+
20
+ git commit -am 'Added some feature'
21
+ git push origin my-new-feature
22
+
23
+ At this point you'll be waiting for one of our maintainers to review it. We will
24
+ try to reply to new Pull Requests within a few days. We might suggest some
25
+ changes, improvements or alternatives. To increase the chance that your pull
26
+ request gets accepted:
27
+
28
+ * Explain what your are doing (and why) in your Pull Request description.
29
+ * If you are fixing an
30
+ [issue](https://github.com/lolcommits/lolcommits-sample_plugin/issues), link to
31
+ it in your description and [mention
32
+ it](https://help.github.com/articles/closing-issues-via-commit-messages) in
33
+ the commit message.
34
+ * Write a good [commit
35
+ message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html).
36
+ * Write tests.
37
+
data/Gemfile ADDED
@@ -0,0 +1,2 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README.md ADDED
@@ -0,0 +1,286 @@
1
+ # Lolcommits Sample Plugin
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lolcommits-sample_plugin.svg?style=flat)](http://rubygems.org/gems/lolcommits-sample_plugin)
4
+ [![Travis Build Status](https://travis-ci.org/lolcommits/lolcommits-sample_plugin.svg?branch=master)](https://travis-ci.org/lolcommits/lolcommits-sample_plugin)
5
+ [![Maintainability](https://img.shields.io/codeclimate/maintainability/lolcommits/lolcommits-sample_plugin.svg)](https://codeclimate.com/github/lolcommits/lolcommits-sample_plugin/maintainability)
6
+ [![Test Coverage](https://img.shields.io/codeclimate/c/lolcommits/lolcommits-sample_plugin.svg)](https://codeclimate.com/github/lolcommits/lolcommits-sample_plugin/test_coverage)
7
+ [![Gem Dependency Status](https://gemnasium.com/badges/github.com/lolcommits/lolcommits-sample_plugin.svg)](https://gemnasium.com/github.com/lolcommits/lolcommits-sample_plugin)
8
+
9
+ [lolcommits](https://lolcommits.github.io/) takes a snapshot with your webcam
10
+ every time you git commit code, and archives a lolcat style image with it. Git
11
+ blame has never been so much fun!
12
+
13
+ Lolcommit plugins are automatically loaded before the capturing process starts.
14
+ The flexible class design allows developers to add features by running code
15
+ before or after snapshots are taken.
16
+
17
+ This gem showcases an example plugin. It prints short messages to the screen
18
+ before and after every lolcommit. Something like this;
19
+
20
+ ✨ Say cheese 😁 !
21
+ *** Preserving this moment in history.
22
+ 📸 Snap
23
+ ✨ wow! 9e6303c is your best looking commit yet! 😘 💻
24
+
25
+ Use this repo to jump-start development on your own plugin. It has tests, docs
26
+ and integration with useful tools (Travis, CodeClimate, Rdoc etc.) See below for
27
+ more information on how to get started.
28
+
29
+ ## Developing your own plugin
30
+
31
+ First, there are some things your gem *must* do to be loaded and executed
32
+ correctly. At the very least:
33
+
34
+ * Name your gem with the `lolcommits-` prefix.
35
+ * Include a class that inherits from `Lolcommits::Plugin::Base` (this will be
36
+ the entry point to your plugin from the lolcommits gem).
37
+ * This main plugin class must meet the requirements explained below.
38
+ * Require `lolcommits` in your gem spec as a development dependency.
39
+
40
+ ### Your Plugin Class
41
+
42
+ You plugin class must have a namespace and path that matches your gem name and
43
+ be in the `LOAD_PATH` (required) with the gem for example:
44
+
45
+ # a gem named: lolcommits-zapier
46
+ # should have a plugin class inheriting from Base like so:
47
+ class Lolcommits::Plugin::Zapier < Lolcommits::Plugin::Base
48
+ ...
49
+ end
50
+ # at lib/lolcommits/plugin/zapier.rb
51
+ # required in a file at lib/lolcommits/zapier.rb
52
+
53
+ # or a gem named: lolcommits-super_awesome
54
+ # should have a plugin class
55
+ class Lolcommits::Plugin::SuperAwesome < Lolcommits::Plugin::Base
56
+ ...
57
+ end
58
+ # required in a file at lib/lolcommits/super_awesome.rb
59
+
60
+ You **should** override the following methods in this class:
61
+
62
+ * `def self.name` - identifies the plugin to lolcommits and users, keep things
63
+ simple and choose a name that matches your gem name.
64
+ * `def self.runner_order` - return the hooks this plugin should run at during
65
+ the capture process (`:pre_capture`, `:post_capture` and/or `:capture_ready`).
66
+ * `def run_pre_capture`, `def run_post_capture` and/or `def run_capture_ready` -
67
+ override with your plugin's behaviour.
68
+
69
+ Three hooks points are available during the lolcommits capture process.
70
+
71
+ * `:pre_capture` - called before the camera starts capturing, at this point you
72
+ could alter the commit message/sha text.
73
+ * `:post_capture` - called immediately after the camera snaps the raw image (or
74
+ video for gif captures) use this hook to alter the image, other plugins may
75
+ hook here to modify the image too.
76
+ `:capture_ready` - called after all `:post_capture` plugins have ran, at this
77
+ point the capture should be ready for exporting or sharing.
78
+
79
+ ### Plugin configuration
80
+
81
+ The `Base` class initializer defines an `@options` instance var, with an array
82
+ of setting names that the user can configure. By default, the only option is
83
+ `enabled` and plugins *must* be configured as `enabled = true` to run.
84
+
85
+ A plugin can be configured by the lolcommits gem with;
86
+
87
+ lolcommits --config
88
+ # or
89
+ lolcommits --config -p plugin-name
90
+
91
+ Use the `configuration` method in your plugin class to read these options.
92
+ Plugin methods you may want to override with custom configuration code include:
93
+
94
+ * `def enabled?` - usually checks `configuration['enabled']` to determine if the
95
+ plugin should run.
96
+ * `def configure_options!` - prompts the user for configuration (based on the
97
+ `@options`) returns a hash that will be persisted.
98
+ * `def configured?` - checks the persisted config hash is present.
99
+ * `def valid_configuration?`- checks the persisted config hash has valid data.
100
+
101
+ If your plugin requires no configuration, you could override the `enabled?`
102
+ method to always return `true`. Users could disable your plugin by uninstalling
103
+ the gem.
104
+
105
+ By default a plugin will only run it's capture hooks if:
106
+
107
+ * `valid_configuration?` returns true
108
+ * `enabled?` returns true
109
+
110
+ For more help, check out [the
111
+ documentation](http://www.rubydoc.info/github/lolcommits/lolcommits-sample_plugin/Lolcommits/Plugin/SamplePlugin)
112
+ for this plugin, or take a look at [other
113
+ lolcommit_plugins](https://github.com/search?q=topic%3Alolcommits-plugin+org%3Alolcommits&type=Repositories) in the wild.
114
+
115
+ ### The Lolcommits 'runner'
116
+
117
+ The only required argument for your plugin class initializer is a
118
+ `Lolcommits::Runner` instance. By default, the base plugin initializer will set
119
+ this in the `runner` instance var.
120
+
121
+ Use these runner methods to access the commit, repo and configuration:
122
+
123
+ * `runner.message` - the git commit message.
124
+ * `runner.sha` - the git sha for the current commit.
125
+ * `runner.vcs_info` - a reference to the
126
+ [Lolcommits::VCSInfo](https://github.com/mroth/lolcommits/blob/master/lib/lolcommits/vcs_info.rb)
127
+ instance.
128
+ * `runner.config` - a reference to the
129
+ [Lolcommits::Configuration](https://github.com/mroth/lolcommits/blob/master/lib/lolcommits/configuration.rb)
130
+ instance.
131
+
132
+ After the capturing process has completed, (i.e. in the `run_post_capture` or
133
+ `run_capture_ready` hooks) these methods will reveal the captured snapshot file.
134
+
135
+ * `runner.snapshot_loc` - the raw image file.
136
+ * `runner.main_image` - the processed image file, resized, with text overlay
137
+ applied (or any other effects from other plugins).
138
+
139
+ During plugin configuration, your plugin class will be initialized with the
140
+ optional `config` argument (and no runner). This allows you to read the existing
141
+ saved options during configuration. E.g. to show the existing options back to
142
+ the user.
143
+
144
+ Take a look at the
145
+ [Lolcommits::Runner](https://github.com/mroth/lolcommits/blob/master/lib/lolcommits/runner.rb)
146
+ for more details.
147
+
148
+ ### Testing your plugin
149
+
150
+ It's a good idea to include tests with your gem. To make this easier for you,
151
+ the main lolcommits gem provides helpers to work with IO and Git repos in
152
+ test.
153
+
154
+ # add one or both of these to your plugin's test_helper file
155
+ require 'lolcommits/test_helpers/git_repo'
156
+ require 'lolcommits/test_helpers/fake_io'
157
+
158
+ # and include either (or both) modules in your test
159
+ include Lolcommits::TestHelpers::GitRepo
160
+ include Lolcommits::TestHelpers::FakeIO
161
+
162
+ Use the following methods to manage a test repo:
163
+
164
+ setup_repo # create the test repo
165
+ commit_repo_with_message # perform a git commit in the test repo
166
+ last_commit # git commit info for the last commit in the test repo
167
+ teardown_repo # destroy the test repo
168
+ in_repo(&block) # run lolcommits within the test repo
169
+
170
+ For submitting and capturing IO use the `fake_io_capture` method. E.g. to
171
+ capture the output of the `configure_options` method, while sending the string
172
+ input 'true' (followed by a carriage return) when prompted on STDIN:
173
+
174
+ output = fake_io_capture(inputs: %w(true)) do
175
+ configured_plugin_options = plugin.configure_options!
176
+ end
177
+
178
+ For more examples take a look at the [tests in this
179
+ repo](https://github.com/lolcommits/lolcommits-sample_plugin/blob/master/test/lolcommits/plugin/sample_plugin_test.rb)
180
+ (MiniTest).
181
+
182
+ ### General advice
183
+
184
+ Use this gem as a starting point, renaming files, classes and references. Or
185
+ build a new plugin gem from scratch with:
186
+
187
+ bundle gem lolcommits-my-plugin
188
+
189
+ For more examples, take a look at other published [lolcommit
190
+ plugins](https://github.com/lolcommits).
191
+
192
+ If you feel something is missing (or out of date) in this short guide. Please
193
+ create a new
194
+ [issue](https://github.com/lolcommits/lolcommits-sample_plugin/issues).
195
+
196
+ ## History
197
+
198
+ Until recently, all plugins lived inside the main lolcommits gem. We are in the
199
+ process of extracting them to individual gems, loaded with the new plugin
200
+ manager. Ruby gem versioning will take care of managing dependencies and
201
+ compatibility with the main gem.
202
+
203
+ ---
204
+
205
+ ## Requirements
206
+
207
+ * Ruby >= 2.0.0
208
+ * A webcam
209
+ * [ImageMagick](http://www.imagemagick.org)
210
+ * [ffmpeg](https://www.ffmpeg.org) (optional) for animated gif capturing
211
+
212
+ ## Installation
213
+
214
+ Follow the [install guide](https://github.com/mroth/lolcommits#installation) for
215
+ lolcommits first. Then run the following:
216
+
217
+ $ gem install lolcommits-sample_plugin
218
+
219
+ Next configure and enable this plugin with:
220
+
221
+ $ lolcommits --config -p sample_plugin
222
+ # set enabled to `true`
223
+
224
+ That's it! Every lolcommit now comes with it's own short (emoji themed) message!
225
+
226
+ ## Development
227
+
228
+ Check out this repo and run `bin/setup`, this will install dependencies and
229
+ generate docs. Run `bundle exec rake` to run all tests and generate a coverage
230
+ report.
231
+
232
+ You can also run `bin/console` for an interactive prompt that will allow you to
233
+ experiment with the gem code.
234
+
235
+ ## Tests
236
+
237
+ MiniTest is used for testing. Run the test suite with:
238
+
239
+ $ rake test
240
+
241
+ ## Docs
242
+
243
+ Generate docs for this gem with:
244
+
245
+ $ rake rdoc
246
+
247
+ ## Troubles?
248
+
249
+ If you think something is broken or missing, please raise a new
250
+ [issue](https://github.com/lolcommits/lolcommits-sample_plugin/issues). Take
251
+ a moment to check it hasn't been raised in the past (and possibly closed).
252
+
253
+ ## Contributing
254
+
255
+ Bug [reports](https://github.com/lolcommits/lolcommits-sample_plugin/issues) and [pull
256
+ requests](https://github.com/lolcommits/lolcommits-sample_plugin/pulls) are welcome on
257
+ GitHub.
258
+
259
+ When submitting pull requests, remember to add tests covering any new behaviour,
260
+ and ensure all tests are passing on [Travis
261
+ CI](https://travis-ci.org/lolcommits/lolcommits-sample_plugin). Read the
262
+ [contributing
263
+ guidelines](https://github.com/lolcommits/lolcommits-sample_plugin/blob/master/CONTRIBUTING.md)
264
+ for more details.
265
+
266
+ This project is intended to be a safe, welcoming space for collaboration, and
267
+ contributors are expected to adhere to the [Contributor
268
+ Covenant](http://contributor-covenant.org) code of conduct. See
269
+ [here](https://github.com/lolcommits/lolcommits-sample_plugin/blob/master/CODE_OF_CONDUCT.md)
270
+ for more details.
271
+
272
+ ## License
273
+
274
+ The gem is available as open source under the terms of
275
+ [LGPL-3](https://opensource.org/licenses/LGPL-3.0).
276
+
277
+ ## Links
278
+
279
+ * [Travis CI](https://travis-ci.org/lolcommits/lolcommits-sample_plugin)
280
+ * [Test Coverage](https://codeclimate.com/github/lolcommits/lolcommits-sample_plugin/test_coverage)
281
+ * [Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-sample_plugin)
282
+ * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-sample_plugin)
283
+ * [Issues](http://github.com/lolcommits/lolcommits-sample_plugin/issues)
284
+ * [Report a bug](http://github.com/lolcommits/lolcommits-sample_plugin/issues/new)
285
+ * [Gem](http://rubygems.org/gems/lolcommits-sample_plugin)
286
+ * [GitHub](https://github.com/lolcommits/lolcommits-sample_plugin)
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+ require "rdoc/task"
4
+
5
+ # generate docs
6
+ RDoc::Task.new do |rd|
7
+ rd.main = "README.md"
8
+ rd.title = "Lolcommits Sample Plugin"
9
+ rd.rdoc_dir = "doc"
10
+ rd.options << "--all"
11
+ rd.rdoc_files.include("README.md", "LICENSE", "lib/**/*.rb")
12
+ end
13
+
14
+ # run tests
15
+ Rake::TestTask.new(:test) do |t|
16
+ t.libs << "test"
17
+ t.libs << "lib"
18
+ t.test_files = FileList["test/**/*_test.rb"]
19
+ end
20
+
21
+ # run tests with code coverage (default)
22
+ namespace :test do
23
+ desc "Run all tests and features and generate a code coverage report"
24
+ task :coverage do
25
+ ENV['COVERAGE'] = 'true'
26
+ Rake::Task['test'].execute
27
+ end
28
+ end
29
+
30
+
31
+ task :default => ['test:coverage']
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "lolcommits/sample_plugin"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ # install deps
7
+ bundle install
8
+
9
+ # generate docs
10
+ bundle exec rake rdoc
@@ -0,0 +1,163 @@
1
+ require 'lolcommits/plugin/base'
2
+
3
+ module Lolcommits
4
+ module Plugin
5
+ class SamplePlugin < Base
6
+
7
+ ##
8
+ # Returns the name of the plugin.
9
+ #
10
+ # Identifies the plugin to lolcommits. This should be uniq and
11
+ # descriptive.
12
+ #
13
+ # @return [String] the plugin name
14
+ #
15
+ def self.name
16
+ 'plugin-sample'
17
+ end
18
+
19
+ # Returns position(s) of when this plugin should run during the capture
20
+ # process.
21
+ #
22
+ # Defines when the plugin will execute in the capture process. This must
23
+ # be defined, if the method returns nil, or [] the plugin will never run.
24
+ # Three hook positions exist, your plugin code can execute in one or more
25
+ # of these.
26
+ #
27
+ # @return [Array] the position(s) (:pre_capture, :post_capture,
28
+ # :capture_ready)
29
+ #
30
+ def self.runner_order
31
+ [:pre_capture, :post_capture, :capture_ready]
32
+ end
33
+
34
+ ##
35
+ #
36
+ # Plugin initializer
37
+ #
38
+ # @param runner [Lolcommits::Runner] a instance of a lolcommits runner
39
+ # @param config [Lolcommits::Configuration] (optional)
40
+ #
41
+ # The default superclass method sets @runner and @config instance vars and
42
+ # the default plugin option key `@options = ['enabled']`. `@runner.config`
43
+ # is used if no `config` parameter is passed.
44
+ #
45
+ # Override this method to change the default options, or assign any useful
46
+ # variables necessary for the plugin to run.
47
+ #
48
+ def initialize(runner: nil, config: nil)
49
+ super
50
+ end
51
+
52
+ ##
53
+ #
54
+ # Pre-capture hook, runs before lolcommits captures a snapshot.
55
+ #
56
+ # Override this method to execute plugin code before the lolcommit
57
+ # snapshot is captured.
58
+ #
59
+ # Prints a short (emoji themed) message to STDOUT
60
+ #
61
+ def run_pre_capture
62
+ puts "✨ Say cheese 😁 !"
63
+ end
64
+
65
+ ##
66
+ #
67
+ # Post-capture hook, run after lolcommits captures a snapshot.
68
+ #
69
+ # Override this method to execute plugin code after the lolcommit
70
+ # snapshot is captured.
71
+ #
72
+ # Prints a short (emoji themed) message to STDOUT
73
+ #
74
+ def run_post_capture
75
+ puts "📸 Snap "
76
+ end
77
+
78
+ ##
79
+ #
80
+ # Capture ready hook, runs after lolcommits captures a snapshot.
81
+ #
82
+ # Override this method to execute plugin code after the lolcommit snapshot
83
+ # is captured and all image processing in post capture hooks (from other
84
+ # plugins) has completed
85
+ #
86
+ # Prints a short (emoji themed) message to STDOUT with the current commit
87
+ # sha.
88
+ #
89
+ def run_capture_ready
90
+ puts "✨ wow! #{self.runner.sha} is your best looking commit yet! 😘 💻"
91
+ end
92
+
93
+ ##
94
+ # Returns true/false indicating if the plugin is enabled or not.
95
+ #
96
+ # The default superclass method will return true if the enabled option is
97
+ # true e.g. configuration['enabled'] == true
98
+ #
99
+ # Override this method to define your own custom enabled logic. E.g. check
100
+ # for valid or required configuration options to be set. If this method
101
+ # always returns true, the only way to disable the plugin will be to
102
+ # uninstall the gem.
103
+ #
104
+ # @return [Boolean] true/false indicating if plugin is enabled
105
+ #
106
+ def enabled?
107
+ super
108
+ end
109
+
110
+ ##
111
+ # Prompts the user to configure the plugin's options.
112
+ #
113
+ # The default superclass method will iterate over the @options array and
114
+ # build a configuration hash, prompting for user input on each option key.
115
+ #
116
+ # Lolcommits will save this configuration hash to its default config file
117
+ # (YAML). This config Hash is loaded and parsed during the capturing
118
+ # process and available in this plugin class via the configuration method.
119
+ #
120
+ # Override this method to define your own configuration flow. A helpful
121
+ # parse_user_input method is available to help parse strings from STDIN.
122
+ #
123
+ # @return [Hash] a hash of configured plugin options
124
+ #
125
+ def configure_options!
126
+ super
127
+ end
128
+
129
+ ##
130
+ # Returns true/false indicating if the plugin has been correctly
131
+ # configured.
132
+ #
133
+ # The default superclass method calls configured?. When false a message is
134
+ # shown explaining the plugin has not yet been configured, with help on
135
+ # how to configure it.
136
+ #
137
+ # Override this method to define your own configuration checks and
138
+ # messaging.
139
+ #
140
+ # This method must return true for the plugin to execute. It is checked by
141
+ # the lolcommits runner prior to running a pre or post capture hook.
142
+ #
143
+ # @return [Boolean] true/false indicating if plugin is correct configured
144
+ #
145
+ def valid_configuration?
146
+ super
147
+ end
148
+
149
+ ##
150
+ # Returns true/false indicating if the plugin has been configured.
151
+ #
152
+ # The default superclass method checks if the configuration hash is empty.
153
+ # Override this method to define your own check on whether configuration
154
+ # has taken place.
155
+ #
156
+ # @return [Boolean] true/false indicating if plugin has been configured
157
+ #
158
+ def configured?
159
+ super
160
+ end
161
+ end
162
+ end
163
+ end
@@ -0,0 +1,5 @@
1
+ module Lolcommits
2
+ module SamplePlugin
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'lolcommits/sample_plugin/version'
2
+ require 'lolcommits/plugin/sample_plugin'
@@ -0,0 +1,41 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lolcommits/sample_plugin/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lolcommits-sample_plugin"
8
+ spec.version = Lolcommits::SamplePlugin::VERSION
9
+ spec.authors = ["Matthew Hutchinson"]
10
+ spec.email = ["matt@hiddenloop.com"]
11
+
12
+ spec.summary = %q{Example gem for lolcommits plugin development}
13
+ spec.description = %q{Use this gem as a guide or template to get started with lolcommits plugin development}
14
+
15
+ spec.homepage = "https://github.com/lolcommits/lolcommits-sample_plugin"
16
+ spec.license = "LGPL-3"
17
+
18
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
20
+ if spec.respond_to?(:metadata)
21
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
22
+ else
23
+ raise "RubyGems 2.0 or newer is required to protect against " \
24
+ "public gem pushes."
25
+ end
26
+
27
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|features)/}) }
28
+ spec.test_files = `git ls-files -- {test,features}/*`.split("\n")
29
+ spec.bindir = "bin"
30
+ spec.executables = []
31
+ spec.require_paths = ["lib"]
32
+
33
+ spec.required_ruby_version = ">= 2.0.0"
34
+
35
+ spec.add_development_dependency "lolcommits", ">= 0.9.8"
36
+ spec.add_development_dependency "bundler"
37
+ spec.add_development_dependency "rake"
38
+ spec.add_development_dependency "minitest"
39
+ spec.add_development_dependency "simplecov"
40
+ spec.add_development_dependency "pry"
41
+ end
@@ -0,0 +1,112 @@
1
+ require 'test_helper'
2
+
3
+ describe Lolcommits::Plugin::SamplePlugin do
4
+
5
+ include Lolcommits::TestHelpers::GitRepo
6
+ include Lolcommits::TestHelpers::FakeIO
7
+
8
+ it 'should run on pre_capture and capture_ready' do
9
+ ::Lolcommits::Plugin::SamplePlugin.runner_order.must_equal [
10
+ :pre_capture, :post_capture, :capture_ready
11
+ ]
12
+ end
13
+
14
+ describe 'with a runner' do
15
+ def runner
16
+ # a simple lolcommits runner with an empty configuration Hash
17
+ @runner ||= Lolcommits::Runner.new(
18
+ config: OpenStruct.new(read_configuration: {})
19
+ )
20
+ end
21
+
22
+ def plugin
23
+ @plugin ||= Lolcommits::Plugin::SamplePlugin.new(runner: runner)
24
+ end
25
+
26
+ def valid_enabled_config
27
+ @config ||= OpenStruct.new(
28
+ read_configuration: {
29
+ plugin.class.name => { 'enabled' => true }
30
+ }
31
+ )
32
+ end
33
+
34
+ describe 'initalizing' do
35
+ it 'should assign runner and an enabled option' do
36
+ plugin.runner.must_equal runner
37
+ plugin.options.must_equal ['enabled']
38
+ end
39
+ end
40
+
41
+ describe '#run_pre_capture' do
42
+
43
+ before { commit_repo_with_message }
44
+
45
+ it 'should output a message to stdout' do
46
+ in_repo do
47
+ Proc.new { plugin.run_pre_capture }.
48
+ must_output "✨ Say cheese 😁 !\n"
49
+ end
50
+ end
51
+
52
+ after { teardown_repo }
53
+ end
54
+
55
+ describe '#run_capture_ready' do
56
+
57
+ before { commit_repo_with_message }
58
+
59
+ it 'should output a message to stdout' do
60
+ in_repo do
61
+ Proc.new { plugin.run_capture_ready }.
62
+ must_output "✨ wow! #{last_commit.sha[0..10]} is your best looking commit yet! 😘 💻\n"
63
+ end
64
+ end
65
+
66
+ after { teardown_repo }
67
+ end
68
+
69
+ describe '#enabled?' do
70
+ it 'should be false by default' do
71
+ plugin.enabled?.must_equal false
72
+ end
73
+
74
+ it 'should true when configured' do
75
+ plugin.config = valid_enabled_config
76
+ plugin.enabled?.must_equal true
77
+ end
78
+ end
79
+
80
+ describe 'configuration' do
81
+ it 'should not be configured by default' do
82
+ plugin.configured?.must_equal false
83
+ end
84
+
85
+ it 'should allow plugin options to be configured' do
86
+ configured_plugin_options = {}
87
+
88
+ output = fake_io_capture(inputs: %w(true)) do
89
+ configured_plugin_options = plugin.configure_options!
90
+ end
91
+
92
+ configured_plugin_options.must_equal( { "enabled" => true })
93
+ end
94
+
95
+ it 'should indicate when configured' do
96
+ plugin.config = valid_enabled_config
97
+ plugin.configured?.must_equal true
98
+ end
99
+
100
+ describe '#valid_configuration?' do
101
+ it 'should be false without config set' do
102
+ plugin.valid_configuration?.must_equal(false)
103
+ end
104
+
105
+ it 'should be true for a valid configuration' do
106
+ plugin.config = valid_enabled_config
107
+ plugin.valid_configuration?.must_equal true
108
+ end
109
+ end
110
+ end
111
+ end
112
+ end
@@ -0,0 +1,22 @@
1
+ $LOAD_PATH.unshift File.expand_path('../../lib', __FILE__)
2
+
3
+ # necessary libs from lolcommits (allowing plugin to run)
4
+ require 'git'
5
+ require 'lolcommits/runner'
6
+ require 'lolcommits/vcs_info'
7
+ require 'lolcommits/backends/git_info'
8
+
9
+ # lolcommit test helpers
10
+ require 'lolcommits/test_helpers/git_repo'
11
+ require 'lolcommits/test_helpers/fake_io'
12
+
13
+ if ENV['COVERAGE']
14
+ require 'simplecov'
15
+ end
16
+
17
+ # plugin gem test libs
18
+ require 'lolcommits/sample_plugin'
19
+ require 'minitest/autorun'
20
+
21
+ # swallow all debug output during test runs
22
+ def debug(msg); end
metadata ADDED
@@ -0,0 +1,149 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits-sample_plugin
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Matthew Hutchinson
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: lolcommits
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 0.9.8
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 0.9.8
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
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
+ - !ruby/object:Gem::Dependency
56
+ name: minitest
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: simplecov
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: pry
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Use this gem as a guide or template to get started with lolcommits plugin
98
+ development
99
+ email:
100
+ - matt@hiddenloop.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - ".gitignore"
106
+ - ".simplecov"
107
+ - ".travis.yml"
108
+ - CODE_OF_CONDUCT.md
109
+ - CONTRIBUTING.md
110
+ - Gemfile
111
+ - LICENSE
112
+ - README.md
113
+ - Rakefile
114
+ - bin/console
115
+ - bin/setup
116
+ - lib/lolcommits/plugin/sample_plugin.rb
117
+ - lib/lolcommits/sample_plugin.rb
118
+ - lib/lolcommits/sample_plugin/version.rb
119
+ - lolcommits-plugin-sample.gemspec
120
+ - test/lolcommits/plugin/sample_plugin_test.rb
121
+ - test/test_helper.rb
122
+ homepage: https://github.com/lolcommits/lolcommits-sample_plugin
123
+ licenses:
124
+ - LGPL-3
125
+ metadata:
126
+ allowed_push_host: https://rubygems.org
127
+ post_install_message:
128
+ rdoc_options: []
129
+ require_paths:
130
+ - lib
131
+ required_ruby_version: !ruby/object:Gem::Requirement
132
+ requirements:
133
+ - - ">="
134
+ - !ruby/object:Gem::Version
135
+ version: 2.0.0
136
+ required_rubygems_version: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ requirements: []
142
+ rubyforge_project:
143
+ rubygems_version: 2.6.13
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: Example gem for lolcommits plugin development
147
+ test_files:
148
+ - test/lolcommits/plugin/sample_plugin_test.rb
149
+ - test/test_helper.rb