lolcommits-slack 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: 9d4b1c94c1a4906e1cbc7297c634bc179d95f01c
4
+ data.tar.gz: b10b9ac9a23dc2eeb13c3917f6b1c2cb3f129131
5
+ SHA512:
6
+ metadata.gz: 44baafddf76f4ca6b0fa9aec4539be58a972af934975320b505e11c5954db85b22f85611c5469f81e7312b4b82e3b00cf6837e134f51cf4422ca0f64f4d59a55
7
+ data.tar.gz: c07272971d48b68e06d4d0c7ed44e8bfec9556c5a7bf7ae86901ece03fb27bd9dfd3eb171a92db8dbbb1e70d556a24f4b2c4a94e10387898f852525f0dcb8a73
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,20 @@
1
+ sudo: false
2
+ language: ruby
3
+ cache: bundler
4
+ rvm:
5
+ - 2.0.0
6
+ - 2.1.7
7
+ - 2.2.4
8
+ - 2.3.3
9
+ - 2.4.1
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
@@ -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-slack.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-slack/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-slack/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,119 @@
1
+ # Lolcommits Slack
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lolcommits-slack.svg?style=flat)](http://rubygems.org/gems/lolcommits-slack)
4
+ [![Travis Build Status](https://travis-ci.org/lolcommits/lolcommits-slack.svg?branch=master)](https://travis-ci.org/lolcommits/lolcommits-slack)
5
+ [![Coverage Status](https://coveralls.io/repos/github/lolcommits/lolcommits-slack/badge.svg?branch=master)](https://coveralls.io/github/lolcommits/lolcommits-slack)
6
+ [![Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-slack/badges/gpa.svg)](https://codeclimate.com/github/lolcommits/lolcommits-slack)
7
+ [![Gem Dependency Status](https://gemnasium.com/badges/github.com/lolcommits/lolcommits-slack.svg)](https://gemnasium.com/github.com/lolcommits/lolcommits-slack)
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
+ This plugin automatically posts your lolcommits to one (or more)
14
+ [Slack](https://slack.com) channels.
15
+
16
+ The Slack post will contain the git commit message and repo name. The SHA is
17
+ used as the uploaded image file name. Posting will be retried (once) should any
18
+ error occur.
19
+
20
+ ## Requirements
21
+
22
+ * Ruby >= 2.0.0
23
+ * A webcam
24
+ * [ImageMagick](http://www.imagemagick.org)
25
+ * [ffmpeg](https://www.ffmpeg.org) (optional) for animated gif capturing
26
+
27
+ ## Installation
28
+
29
+ Follow the [install guide](https://github.com/mroth/lolcommits#installation) for
30
+ lolcommits first. Then run the following:
31
+
32
+ $ gem install lolcommits-slack
33
+
34
+ ## Configuration
35
+
36
+ Next configure and enable with:
37
+
38
+ $ lolcommits --config -p slack
39
+ # set enabled to `true`
40
+ # enter your access token and Slack channel ID list (see below)
41
+
42
+ That's it! Every lolcommit will now be posted to these Slack channels. To
43
+ disable simply reconfigure with `enabled: false`.
44
+
45
+ ### Access Token
46
+
47
+ This plugin uses Slack [legacy
48
+ tokens](https://api.slack.com/custom-integrations/legacy-tokens) for
49
+ authentication. Create (or grab) them
50
+ [here](https://api.slack.com/custom-integrations/legacy-tokens).
51
+
52
+ ### Channel List
53
+
54
+ You must supply one or more Slack channel *IDs*. You can use Slack's own
55
+ [API testing tool](https://api.slack.com/methods/channels.list/test)
56
+ to list all Slack channels in your account, and grab the IDs from the JSON
57
+ response presented.
58
+
59
+ ## Development
60
+
61
+ Check out this repo and run `bin/setup`, this will install dependencies and
62
+ generate docs. Run `bundle exec rake` to run all tests and generate a coverage
63
+ report.
64
+
65
+ You can also run `bin/console` for an interactive prompt that will allow you to
66
+ experiment with the gem code.
67
+
68
+ ## Tests
69
+
70
+ MiniTest is used for testing. Run the test suite with:
71
+
72
+ $ rake test
73
+
74
+ ## Docs
75
+
76
+ Generate docs for this gem with:
77
+
78
+ $ rake rdoc
79
+
80
+ ## Troubles?
81
+
82
+ If you think something is broken or missing, please raise a new
83
+ [issue](https://github.com/lolcommits/lolcommits-slack/issues). Take
84
+ a moment to check it hasn't been raised in the past (and possibly closed).
85
+
86
+ ## Contributing
87
+
88
+ Bug [reports](https://github.com/lolcommits/lolcommits-slack/issues) and [pull
89
+ requests](https://github.com/lolcommits/lolcommits-slack/pulls) are welcome on
90
+ GitHub.
91
+
92
+ When submitting pull requests, remember to add tests covering any new behaviour,
93
+ and ensure all tests are passing on [Travis
94
+ CI](https://travis-ci.org/lolcommits/lolcommits-slack). Read the
95
+ [contributing
96
+ guidelines](https://github.com/lolcommits/lolcommits-slack/blob/master/CONTRIBUTING.md)
97
+ for more details.
98
+
99
+ This project is intended to be a safe, welcoming space for collaboration, and
100
+ contributors are expected to adhere to the [Contributor
101
+ Covenant](http://contributor-covenant.org) code of conduct. See
102
+ [here](https://github.com/lolcommits/lolcommits-slack/blob/master/CODE_OF_CONDUCT.md)
103
+ for more details.
104
+
105
+ ## License
106
+
107
+ The gem is available as open source under the terms of
108
+ [LGPL-3](https://opensource.org/licenses/LGPL-3.0).
109
+
110
+ ## Links
111
+
112
+ * [Travis CI](https://travis-ci.org/lolcommits/lolcommits-slack)
113
+ * [Test Coverage](https://coveralls.io/github/lolcommits/lolcommits-slack?branch=master)
114
+ * [Code Climate](https://codeclimate.com/github/lolcommits/lolcommits-slack)
115
+ * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-slack)
116
+ * [Issues](http://github.com/lolcommits/lolcommits-slack/issues)
117
+ * [Report a bug](http://github.com/lolcommits/lolcommits-slack/issues/new)
118
+ * [Gem](http://rubygems.org/gems/lolcommits-slack)
119
+ * [GitHub](https://github.com/lolcommits/lolcommits-slack)
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 Slack"
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/plugin/slack"
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,120 @@
1
+ require 'lolcommits/plugin/base'
2
+ require 'rest_client'
3
+
4
+ module Lolcommits
5
+ module Plugin
6
+ class Slack < Base
7
+ # Slack API File upload endpoint
8
+ ENDPOINT_URL = 'https://slack.com/api/files.upload'.freeze
9
+
10
+ # Number of times to retry if RestClient.post fails
11
+ RETRY_COUNT = 2
12
+
13
+ ##
14
+ # Returns the name of the plugin.
15
+ #
16
+ # Identifies the plugin to lolcommits.
17
+ #
18
+ # @return [String] the plugin name
19
+ #
20
+ def self.name
21
+ 'slack'
22
+ end
23
+
24
+ ##
25
+ # Returns position(s) of when this plugin should run during the capture
26
+ # process.
27
+ #
28
+ # The lolcommit is posted to Slack when all proccessing has completed and
29
+ # the capture is ready.
30
+ #
31
+ # @return [Array] the position [:capture_ready]
32
+ #
33
+ def self.runner_order
34
+ [:capture_ready]
35
+ end
36
+
37
+ ##
38
+ # Capture ready hook, runs after lolcommits captures a snapshot.
39
+ #
40
+ # Uses `RestClient` to post the lolcommit image to (one or more) Slack
41
+ # channels. Posting will be retried (`RETRY_COUNT`) times if any error
42
+ # occurs.
43
+ #
44
+ # The post contains the git commit message, repo name and the SHA is used
45
+ # for the image filename. The response from the POST request is sent to
46
+ # the debug log.
47
+ #
48
+ def run_capture_ready
49
+ retries = RETRY_COUNT
50
+ begin
51
+ print "Posting to Slack ... "
52
+ response = RestClient.post(
53
+ ENDPOINT_URL,
54
+ file: File.new(runner.main_image),
55
+ token: configuration['access_token'],
56
+ filetype: 'jpg',
57
+ filename: runner.sha,
58
+ title: runner.message + "[#{runner.vcs_info.repo}]",
59
+ channels: configuration['channels']
60
+ )
61
+
62
+ debug response
63
+ print "done!\n"
64
+ rescue => e
65
+ retries -= 1
66
+ print "failed! #{e.message}"
67
+ if retries > 0
68
+ print " - retrying ...\n"
69
+ retry
70
+ else
71
+ print " - giving up ...\n"
72
+ puts 'Try running config again:'
73
+ puts "\tlolcommits --config --p slack"
74
+ end
75
+ end
76
+ end
77
+
78
+ ##
79
+ # Prompts the user to configure integration with Slack
80
+ #
81
+ # Prompts user for a Slack `access_token` and a comma seperated list of
82
+ # valid Slack channel IDs.
83
+ #
84
+ # @return [Hash] a hash of configured plugin options
85
+ #
86
+ def configure_options!
87
+ options = super
88
+
89
+ if options['enabled']
90
+ print "open the url below and issue a token for your user:\n"
91
+ print "https://api.slack.com/custom-integrations/legacy-tokens\n"
92
+ print "enter the generated token below, then press enter: (e.g. xxxx-xxxxxxxxx-xxxx) \n"
93
+ code = parse_user_input(gets.strip)
94
+
95
+ print "enter a comma-seperated list of channel ids to post images in, then press enter: (e.g. c1234567890,c1234567890)\n"
96
+ print "note: you must use channel ids (not channel names). grab them from here; https://api.slack.com/methods/channels.list/test\n"
97
+ channels = parse_user_input(gets.strip)
98
+
99
+ options.merge!(
100
+ 'access_token' => code,
101
+ 'channels' => channels
102
+ )
103
+ end
104
+
105
+ options
106
+ end
107
+
108
+ ##
109
+ # Returns true/false indicating if the plugin has been configured.
110
+ #
111
+ # Checks the `access_token` ond `channels` options have been set.
112
+ #
113
+ # @return [Boolean] true/false
114
+ #
115
+ def configured?
116
+ !configuration['access_token'].nil? && !configuration['channels'].nil?
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,2 @@
1
+ require 'lolcommits/slack/version'
2
+ require 'lolcommits/plugin/slack'
@@ -0,0 +1,5 @@
1
+ module Lolcommits
2
+ module Slack
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
@@ -0,0 +1,46 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ require 'lolcommits/slack/version'
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "lolcommits-slack"
9
+ spec.version = Lolcommits::Slack::VERSION
10
+ spec.authors = ["Matthew Hutchinson"]
11
+ spec.email = ["matt@hiddenloop.com"]
12
+
13
+ spec.summary = %q{Sends lolcommits to one (or more) Slack channels}
14
+ spec.description = %q{Automatically post your lolcommits to Slack}
15
+ spec.homepage = "https://github.com/lolcommits/lolcommits-slack"
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
+ # limited by lolcommits yam gem dep (remove when yammer plugin extracted from
36
+ # lolcommits)
37
+ spec.add_runtime_dependency "rest-client", "~> 1.8"
38
+
39
+ spec.add_development_dependency "lolcommits", "~> 0.9.6"
40
+ spec.add_development_dependency "webmock"
41
+ spec.add_development_dependency "bundler"
42
+ spec.add_development_dependency "rake"
43
+ spec.add_development_dependency "minitest"
44
+ spec.add_development_dependency "simplecov"
45
+ spec.add_development_dependency "coveralls"
46
+ end
@@ -0,0 +1,135 @@
1
+ require 'test_helper'
2
+
3
+ describe Lolcommits::Plugin::Slack do
4
+
5
+ include Lolcommits::TestHelpers::GitRepo
6
+ include Lolcommits::TestHelpers::FakeIO
7
+
8
+ def plugin_name
9
+ 'slack'
10
+ end
11
+
12
+ it 'should have a name' do
13
+ ::Lolcommits::Plugin::Slack.name.must_equal plugin_name
14
+ end
15
+
16
+ it 'should run on pre_capture and capture_ready' do
17
+ ::Lolcommits::Plugin::Slack.runner_order.must_equal [:capture_ready]
18
+ end
19
+
20
+ describe 'with a runner' do
21
+
22
+ def runner
23
+ # a simple lolcommits runner with an empty configuration Hash
24
+ @_runner ||= Lolcommits::Runner.new(
25
+ config: OpenStruct.new(read_configuration: {}),
26
+ main_image: Tempfile.new('test_image')
27
+ )
28
+ end
29
+
30
+ def plugin
31
+ @_plugin ||= Lolcommits::Plugin::Slack.new(runner: runner)
32
+ end
33
+
34
+ def valid_enabled_config
35
+ @_config ||= OpenStruct.new(
36
+ read_configuration: {
37
+ plugin.class.name => {
38
+ 'enabled' => true,
39
+ 'access_token' => 'acbd-1234-wxyz-5678',
40
+ 'channels' => 'c123,c456'
41
+ }
42
+ }
43
+ )
44
+ end
45
+
46
+ describe 'initalizing' do
47
+ it 'should assign runner and an enabled option' do
48
+ plugin.runner.must_equal runner
49
+ plugin.options.must_equal ['enabled']
50
+ end
51
+ end
52
+
53
+ describe '#run_capture_ready' do
54
+ before do
55
+ commit_repo_with_message
56
+ end
57
+
58
+ it 'should post the message to slack' do
59
+ stub_request(:any, plugin.class::ENDPOINT_URL)
60
+ in_repo do
61
+ plugin.config = valid_enabled_config
62
+ output = fake_io_capture { plugin.run_capture_ready }
63
+ assert_equal output, "Posting to Slack ... done!\n"
64
+
65
+ assert_requested :post, plugin.class::ENDPOINT_URL,
66
+ headers: { 'Content-Type' => /multipart\/form-data;/ },
67
+ times: 1
68
+ end
69
+ end
70
+
71
+ it 'should retry (and explain) if there is a failure (req timeout)' do
72
+ in_repo do
73
+ stub_request(:any, plugin.class::ENDPOINT_URL).to_timeout
74
+ plugin.config = valid_enabled_config
75
+
76
+ Proc.new { plugin.run_capture_ready }.
77
+ must_output("Posting to Slack ... failed! Request Timeout - retrying ...\nPosting to Slack ... failed! Request Timeout - giving up ...\nTry running config again:\n\tlolcommits --config --p slack\n")
78
+
79
+ assert_requested :post, plugin.class::ENDPOINT_URL,
80
+ headers: { 'Content-Type' => /multipart\/form-data;/ },
81
+ times: plugin.class::RETRY_COUNT
82
+ end
83
+ end
84
+
85
+ after { teardown_repo }
86
+ end
87
+
88
+ describe '#enabled?' do
89
+ it 'should be false by default' do
90
+ plugin.enabled?.must_equal false
91
+ end
92
+
93
+ it 'should true when configured' do
94
+ plugin.config = valid_enabled_config
95
+ plugin.enabled?.must_equal true
96
+ end
97
+ end
98
+
99
+ describe 'configuration' do
100
+ it 'should not be configured by default' do
101
+ plugin.configured?.must_equal false
102
+ end
103
+
104
+ it 'should allow plugin options to be configured' do
105
+ configured_plugin_options = {}
106
+
107
+ output = fake_io_capture(inputs: %w(true abc-def c1,c3,c4)) do
108
+ configured_plugin_options = plugin.configure_options!
109
+ end
110
+
111
+ configured_plugin_options.must_equal( {
112
+ "enabled" => true,
113
+ "access_token" => 'abc-def',
114
+ "channels" => 'c1,c3,c4'
115
+ })
116
+ end
117
+
118
+ it 'should indicate when configured' do
119
+ plugin.config = valid_enabled_config
120
+ plugin.configured?.must_equal true
121
+ end
122
+
123
+ describe '#valid_configuration?' do
124
+ it 'should be false without config set' do
125
+ plugin.valid_configuration?.must_equal(false)
126
+ end
127
+
128
+ it 'should be true for a valid configuration' do
129
+ plugin.config = valid_enabled_config
130
+ plugin.valid_configuration?.must_equal true
131
+ end
132
+ end
133
+ end
134
+ end
135
+ end
@@ -0,0 +1,28 @@
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 'webmock/minitest'
11
+ require 'lolcommits/test_helpers/git_repo'
12
+ require 'lolcommits/test_helpers/fake_io'
13
+
14
+ if ENV['COVERAGE']
15
+ if ENV['TRAVIS']
16
+ require 'coveralls'
17
+ Coveralls.wear!
18
+ else
19
+ require 'simplecov'
20
+ end
21
+ end
22
+
23
+ # plugin gem test libs
24
+ require 'lolcommits/plugin/slack'
25
+ require 'minitest/autorun'
26
+
27
+ # swallow all debug output during test runs
28
+ def debug(msg); end
metadata ADDED
@@ -0,0 +1,176 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits-slack
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-08-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rest-client
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.8'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.8'
27
+ - !ruby/object:Gem::Dependency
28
+ name: lolcommits
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 0.9.6
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: 0.9.6
41
+ - !ruby/object:Gem::Dependency
42
+ name: webmock
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: bundler
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: rake
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: minitest
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
+ - !ruby/object:Gem::Dependency
98
+ name: simplecov
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - '>='
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - '>='
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: coveralls
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ description: Automatically post your lolcommits to Slack
126
+ email:
127
+ - matt@hiddenloop.com
128
+ executables: []
129
+ extensions: []
130
+ extra_rdoc_files: []
131
+ files:
132
+ - .gitignore
133
+ - .simplecov
134
+ - .travis.yml
135
+ - CODE_OF_CONDUCT.md
136
+ - CONTRIBUTING.md
137
+ - Gemfile
138
+ - LICENSE
139
+ - README.md
140
+ - Rakefile
141
+ - bin/console
142
+ - bin/setup
143
+ - lib/lolcommits/plugin/slack.rb
144
+ - lib/lolcommits/slack.rb
145
+ - lib/lolcommits/slack/version.rb
146
+ - lolcommits-slack.gemspec
147
+ - test/lolcommits/plugin/slack_test.rb
148
+ - test/test_helper.rb
149
+ homepage: https://github.com/lolcommits/lolcommits-slack
150
+ licenses:
151
+ - LGPL-3
152
+ metadata:
153
+ allowed_push_host: https://rubygems.org
154
+ post_install_message:
155
+ rdoc_options: []
156
+ require_paths:
157
+ - lib
158
+ required_ruby_version: !ruby/object:Gem::Requirement
159
+ requirements:
160
+ - - '>='
161
+ - !ruby/object:Gem::Version
162
+ version: 2.0.0
163
+ required_rubygems_version: !ruby/object:Gem::Requirement
164
+ requirements:
165
+ - - '>='
166
+ - !ruby/object:Gem::Version
167
+ version: '0'
168
+ requirements: []
169
+ rubyforge_project:
170
+ rubygems_version: 2.0.14
171
+ signing_key:
172
+ specification_version: 4
173
+ summary: Sends lolcommits to one (or more) Slack channels
174
+ test_files:
175
+ - test/lolcommits/plugin/slack_test.rb
176
+ - test/test_helper.rb