lolcommits-flowdock 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 229c3fe9dad428db79982b126c86a6077048497d
4
+ data.tar.gz: 2743c1ee0e9f5b296bc8f792d76902eaefeb7130
5
+ SHA512:
6
+ metadata.gz: 43e3b8d827f40c9a05f799b8e4c515deddd7951f19fdbc9c7876ca647639b2c5027e78c9e5d76c33f04ccdf715d01cd4c56313e4fe705d4868650103de62c560
7
+ data.tar.gz: 450d05ef2234e6f5c6abfb6b3298ae9e82a6d0f19f7c6260b6d56b987e7bc9205471d7c3ff81dda8b27602568fb08d818959ffbb43edf3274eb2a5e8ef949115
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,35 @@
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
+ branches:
23
+ except:
24
+ - gh-pages
25
+
26
+ env:
27
+ global:
28
+ - CC_TEST_REPORTER_ID=d25af1c4cb3517d081d6df66f79b913b7142da989ab733f6d0f556f642558f56
29
+ - 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
+ before_script:
31
+ - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
32
+ - chmod +x ./cc-test-reporter
33
+ - ./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)
34
+ after_script:
35
+ - ./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-flowdock.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-flowdock/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-flowdock/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,4 @@
1
+ source 'https://rubygems.org'
2
+ gemspec
3
+
4
+ gem "lolcommits", git: "https://github.com/mroth/lolcommits.git"
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,107 @@
1
+ # Lolcommits Flowdock
2
+
3
+ [![Gem Version](https://img.shields.io/gem/v/lolcommits-flowdock.svg?style=flat)](http://rubygems.org/gems/lolcommits-flowdock)
4
+ [![Travis Build Status](https://travis-ci.org/lolcommits/lolcommits-flowdock.svg?branch=master)](https://travis-ci.org/lolcommits/lolcommits-flowdock)
5
+ [![Test Coverage](https://api.codeclimate.com/v1/badges/ad7324f710e10daffd52/test_coverage)](https://codeclimate.com/github/lolcommits/lolcommits-flowdock/test_coverage)
6
+ [![Maintainability](https://api.codeclimate.com/v1/badges/ad7324f710e10daffd52/maintainability)](https://codeclimate.com/github/lolcommits/lolcommits-flowdock/maintainability)
7
+ [![Gem Dependency Status](https://gemnasium.com/badges/github.com/lolcommits/lolcommits-flowdock.svg)](https://gemnasium.com/github.com/lolcommits/lolcommits-flowdock)
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 lolcommit images to a Flowdock flow (room) with
14
+ the `#lolcommits` hashtag. They wll appear like this:
15
+
16
+ ![example
17
+ commit](https://github.com/lolcommits/lolcommits-flowdock/raw/master/assets/images/example-commit.png)
18
+
19
+ ## Requirements
20
+
21
+ * Ruby >= 2.0.0
22
+ * A webcam
23
+ * [ImageMagick](http://www.imagemagick.org)
24
+ * [ffmpeg](https://www.ffmpeg.org) (optional) for animated gif capturing
25
+ * A [Flowdock](https://www.flowdock.com) account
26
+
27
+ ## Installation
28
+
29
+ After installing the lolcommits gem, install this plugin with:
30
+
31
+ $ gem install lolcommits-flowdock
32
+
33
+ Then configure to enable with:
34
+
35
+ $ lolcommits --config -p flowdock
36
+ # set enabled to `true`
37
+ # paste your Flowdock personal API token (from https://flowdock.com/account/tokens)
38
+ # set your Flowdock organization (tab to autocomplete)
39
+ # set the Flowdock flow to post messages to (tab to autocomplete)
40
+
41
+ That's it! Your next lolcommit will be posted as a new message to the flow. To
42
+ disable uninstall this gem or use:
43
+
44
+ $ lolcommits --config -p flowdock
45
+ # and set enabled to `false`
46
+
47
+ ## Development
48
+
49
+ Check out this repo and run `bin/setup`, this will install all dependencies and
50
+ generate docs. Use `bundle exec rake` to run all tests and generate a coverage
51
+ report.
52
+
53
+ You can also run `bin/console` for an interactive prompt, allowing you to
54
+ experiment with the gem code.
55
+
56
+ ## Tests
57
+
58
+ MiniTest is used for testing. Run the test suite with:
59
+
60
+ $ rake test
61
+
62
+ ## Docs
63
+
64
+ Generate docs for this gem with:
65
+
66
+ $ rake rdoc
67
+
68
+ ## Troubles?
69
+
70
+ If you think something is broken or missing, please raise a new
71
+ [issue](https://github.com/lolcommits/lolcommits-flowdock/issues). Take
72
+ a moment to check it hasn't been raised in the past (and possibly closed).
73
+
74
+ ## Contributing
75
+
76
+ Bug [reports](https://github.com/lolcommits/lolcommits-flowdock/issues) and [pull
77
+ requests](https://github.com/lolcommits/lolcommits-flowdock/pulls) are welcome on
78
+ GitHub.
79
+
80
+ When submitting pull requests, remember to add tests covering any new behaviour,
81
+ and ensure all tests are passing on [Travis
82
+ CI](https://travis-ci.org/lolcommits/lolcommits-flowdock). Read the
83
+ [contributing
84
+ guidelines](https://github.com/lolcommits/lolcommits-flowdock/blob/master/CONTRIBUTING.md)
85
+ for more details.
86
+
87
+ This project is intended to be a safe, welcoming space for collaboration, and
88
+ contributors are expected to adhere to the [Contributor
89
+ Covenant](http://contributor-covenant.org) code of conduct. See
90
+ [here](https://github.com/lolcommits/lolcommits-flowdock/blob/master/CODE_OF_CONDUCT.md)
91
+ for more details.
92
+
93
+ ## License
94
+
95
+ The gem is available as open source under the terms of
96
+ [LGPL-3](https://opensource.org/licenses/LGPL-3.0).
97
+
98
+ ## Links
99
+
100
+ * [Travis CI](https://travis-ci.org/lolcommits/lolcommits-flowdock)
101
+ * [Test Coverage](https://codeclimate.com/github/lolcommits/lolcommits-flowdock/test_coverage)
102
+ * [Maintainability](https://codeclimate.com/github/lolcommits/lolcommits-flowdock/maintainability)
103
+ * [RDoc](http://rdoc.info/projects/lolcommits/lolcommits-flowdock)
104
+ * [Issues](http://github.com/lolcommits/lolcommits-flowdock/issues)
105
+ * [Report a bug](http://github.com/lolcommits/lolcommits-flowdock/issues/new)
106
+ * [Gem](http://rubygems.org/gems/lolcommits-flowdock)
107
+ * [GitHub](https://github.com/lolcommits/lolcommits-flowdock)
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 Flowdock"
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/flowdock"
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,72 @@
1
+ require 'rest_client'
2
+ require 'json'
3
+
4
+ module Lolcommits
5
+ module Flowdock
6
+ class RequestFailed < StandardError; end
7
+
8
+ class Client
9
+ attr_accessor :access_token, :organization, :flow
10
+
11
+ API_HOST = 'api.flowdock.com'
12
+
13
+ def initialize(access_token, organization: nil, flow: nil)
14
+ @access_token = access_token
15
+ @organization = organization
16
+ @flow = flow
17
+ end
18
+
19
+ # GET /organizations
20
+ def organizations
21
+ get(organizations_url)
22
+ end
23
+
24
+ # GET /flows
25
+ def flows
26
+ get(flows_url)
27
+ end
28
+
29
+ # POST /flows/:organization/:flow/messages
30
+ def create_message(organization: nil, flow: nil, params: {})
31
+ post(messages_url(organization, flow), params)
32
+ end
33
+
34
+ private
35
+
36
+ def post(*args)
37
+ request(*args, :post)
38
+ end
39
+
40
+ def get(*args)
41
+ request(*args)
42
+ end
43
+
44
+ def request(url, params = {}, method = :get)
45
+ response = RestClient.send(method, url, params)
46
+ if response.code.to_s =~ /^2/
47
+ JSON.parse(response)
48
+ else
49
+ raise RestClient::RequestFailed.new(response)
50
+ end
51
+ rescue RestClient::RequestFailed, JSON::ParserError => e
52
+ raise Flowdock::RequestFailed.new(e.message)
53
+ end
54
+
55
+ def base_url
56
+ "https://#{access_token}@#{API_HOST}"
57
+ end
58
+
59
+ def organizations_url
60
+ "#{base_url}/organizations"
61
+ end
62
+
63
+ def flows_url
64
+ "#{base_url}/flows"
65
+ end
66
+
67
+ def messages_url(organization, flow)
68
+ "#{base_url}/flows/#{organization}/#{flow}/messages"
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,5 @@
1
+ module Lolcommits
2
+ module Flowdock
3
+ VERSION = "0.0.1".freeze
4
+ end
5
+ end
@@ -0,0 +1,2 @@
1
+ require 'lolcommits/flowdock/version'
2
+ require 'lolcommits/plugin/flowdock'
@@ -0,0 +1,138 @@
1
+ require 'lolcommits/plugin/base'
2
+ require 'lolcommits/cli/launcher'
3
+ require 'lolcommits/flowdock/client'
4
+ require 'readline'
5
+
6
+ module Lolcommits
7
+ module Plugin
8
+ class Flowdock < Base
9
+
10
+ ##
11
+ # Returns the name of the plugin. Identifies the plugin to lolcommits.
12
+ #
13
+ # @return [String] the plugin name
14
+ #
15
+ def self.name
16
+ 'flowdock'
17
+ end
18
+
19
+ ##
20
+ # Returns position(s) of when this plugin should run during the capture
21
+ # process. Posting to Flowdock happens when a new capture is ready.
22
+ #
23
+ # @return [Array] the position(s) (:capture_ready)
24
+ #
25
+ def self.runner_order
26
+ [:capture_ready]
27
+ end
28
+
29
+ ##
30
+ # Returns true if the plugin has been configured. An access token,
31
+ # organization and flow must be set.
32
+ #
33
+ # @return [Boolean] true/false indicating if plugin is configured
34
+ #
35
+ def configured?
36
+ !!(configuration['access_token'] &&
37
+ configuration['organization'] &&
38
+ configuration['flow'])
39
+ end
40
+
41
+ ##
42
+ # Prompts the user to configure plugin options. Options are enabled
43
+ # (true/false), a Flowdock Personal API token, and the Flowdock
44
+ # organization and flow names.
45
+ #
46
+ # @return [Hash] a hash of configured plugin options
47
+ #
48
+ def configure_options!
49
+ options = super
50
+ if options['enabled']
51
+ puts "\nCopy (or create) your Flowdock personal API token (paste it below)"
52
+ open_url("https://flowdock.com/account/tokens")
53
+ print "API token: "
54
+ access_token = gets.strip
55
+ flowdock.access_token = access_token
56
+
57
+ puts "\nEnter your Flowdock organization name (tab to autocomplete)"
58
+ organization = prompt_autocomplete_hash("Organization: ", flowdock.organizations)
59
+
60
+ puts "\nEnter your Flowdock flow name (tab to autocomplete)"
61
+ flow = prompt_autocomplete_hash("Flow: ", flowdock.flows)
62
+
63
+ options.merge!(
64
+ 'access_token' => access_token,
65
+ 'flow' => flow,
66
+ 'organization' => organization
67
+ )
68
+ end
69
+ rescue Interrupt
70
+ debug "aborting due to user cancelling configuration"
71
+ options ||= {}
72
+ options['enabled'] = false
73
+ ensure
74
+ options
75
+ end
76
+
77
+ ##
78
+ # Post-capture hook, runs after lolcommits captures a snapshot. Posts the
79
+ # lolcommit image (as a file message) to the configured Flowdock flow.
80
+ #
81
+ # @return [Hash] JSON response object (newly created message hash)
82
+ # @return [Nil] if an error occurs
83
+ #
84
+ def run_capture_ready
85
+ print "Posting to Flowdock ... "
86
+ message = flowdock.create_message(
87
+ organization: configuration['organization'],
88
+ flow: configuration['flow'],
89
+ params: {
90
+ event: 'file',
91
+ content: File.new(runner.main_image),
92
+ tags: %w(lolcommits)
93
+ }
94
+ )
95
+ print "done!\n"
96
+ message
97
+ rescue Lolcommits::Flowdock::RequestFailed => e
98
+ print "failed :( (try again with --debug)\n"
99
+ log_error(e, "ERROR: POST to Flowdock FAILED - #{e.message}")
100
+ nil
101
+ end
102
+
103
+
104
+ private
105
+
106
+ def prompt_autocomplete_hash(prompt, items, name: 'name', value: 'parameterized_name', suggest_words: 5)
107
+ words = items.map {|item| item[name] }.sort
108
+ puts "e.g. #{words.take(suggest_words).join(", ")}" if suggest_words > 0
109
+ completed_input = gets_autocomplete(prompt, words)
110
+ items.find { |item| item[name] == completed_input }[value]
111
+ end
112
+
113
+ def gets_autocomplete(prompt, words)
114
+ completion_handler = proc { |s| words.grep(/^#{Regexp.escape(s)}/) }
115
+ Readline.completion_append_character = ""
116
+ Readline.completion_proc = completion_handler
117
+
118
+ while line = Readline.readline(prompt, true).strip
119
+ if words.include?(line)
120
+ return line
121
+ else
122
+ puts "'#{line}' not found"
123
+ end
124
+ end
125
+ end
126
+
127
+ def open_url(url)
128
+ Lolcommits::CLI::Launcher.open_url(url)
129
+ end
130
+
131
+ def flowdock
132
+ @flowdock ||= Lolcommits::Flowdock::Client.new(
133
+ configuration['access_token']
134
+ )
135
+ end
136
+ end
137
+ end
138
+ end
@@ -0,0 +1,47 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'lolcommits/flowdock/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "lolcommits-flowdock"
8
+ spec.version = Lolcommits::Flowdock::VERSION
9
+ spec.authors = ["Matthew Hutchinson"]
10
+ spec.email = ["matt@hiddenloop.com"]
11
+ spec.summary = %q{Posts lolcommits to Flowdockr}
12
+
13
+ spec.description = <<-EOF
14
+ Automatically posts lolcommit images to a Flowdock flow (room) with the
15
+ #lolcommits hashtag.
16
+ EOF
17
+
18
+ spec.homepage = "https://github.com/lolcommits/lolcommits-flowdock"
19
+ spec.license = "LGPL-3"
20
+
21
+ # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
22
+ # to allow pushing to a single host or delete this section to allow pushing to any host.
23
+ if spec.respond_to?(:metadata)
24
+ spec.metadata['allowed_push_host'] = "https://rubygems.org"
25
+ else
26
+ raise "RubyGems 2.0 or newer is required to protect against " \
27
+ "public gem pushes."
28
+ end
29
+
30
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(assets|test|features)/}) }
31
+ spec.test_files = `git ls-files -- {test,features}/*`.split("\n")
32
+ spec.bindir = "bin"
33
+ spec.executables = []
34
+ spec.require_paths = ["lib"]
35
+
36
+ spec.required_ruby_version = ">= 2.0.0"
37
+
38
+ spec.add_runtime_dependency "rest-client"
39
+
40
+ spec.add_development_dependency "lolcommits", ">= 0.9.8"
41
+ spec.add_development_dependency "bundler"
42
+ spec.add_development_dependency "webmock"
43
+ spec.add_development_dependency "pry"
44
+ spec.add_development_dependency "rake"
45
+ spec.add_development_dependency "minitest"
46
+ spec.add_development_dependency "simplecov"
47
+ end
@@ -0,0 +1,140 @@
1
+ require "test_helper"
2
+ require 'webmock/minitest'
3
+
4
+ describe Lolcommits::Plugin::Flowdock do
5
+
6
+ include Lolcommits::TestHelpers::GitRepo
7
+ include Lolcommits::TestHelpers::FakeIO
8
+
9
+ def plugin_name
10
+ "flowdock"
11
+ end
12
+
13
+ it "should have a name" do
14
+ ::Lolcommits::Plugin::Flowdock.name.must_equal plugin_name
15
+ end
16
+
17
+ it "should run on capture ready" do
18
+ ::Lolcommits::Plugin::Flowdock.runner_order.must_equal [:capture_ready]
19
+ end
20
+
21
+ describe "with a runner" do
22
+ def runner
23
+ # a simple lolcommits runner with an empty configuration Hash
24
+ @runner ||= Lolcommits::Runner.new(
25
+ main_image: Tempfile.new('main_image.jpg'),
26
+ config: OpenStruct.new(read_configuration: {})
27
+ )
28
+ end
29
+
30
+ def plugin
31
+ @plugin ||= Lolcommits::Plugin::Flowdock.new(runner: runner)
32
+ end
33
+
34
+ def valid_enabled_config
35
+ @config ||= OpenStruct.new(
36
+ read_configuration: { "flowdock" => flowdock_config }
37
+ )
38
+ end
39
+
40
+ def flowdock_config
41
+ {
42
+ "enabled" => true,
43
+ "access_token" => "f4f6aa86fd747a00e75238810412x543",
44
+ 'organization' => 'myorg',
45
+ 'flow' => 'myflow'
46
+ }
47
+ end
48
+
49
+ describe "#enabled?" do
50
+ it "is false by default" do
51
+ plugin.enabled?.must_equal false
52
+ end
53
+
54
+ it "is true when configured" do
55
+ plugin.config = valid_enabled_config
56
+ plugin.enabled?.must_equal true
57
+ end
58
+ end
59
+
60
+ describe "run_capture_ready" do
61
+ before { commit_repo_with_message("first commit!") }
62
+ after { teardown_repo }
63
+
64
+ it "posts lolcommit as a new file message to Flowdock" do
65
+ in_repo do
66
+ plugin.config = valid_enabled_config
67
+ message_url = "https://api.flowdock.com/flows/#{flowdock_config['organization']}/#{flowdock_config['flow']}/messages"
68
+ valid_response = { id: "123", event: "file", tags: ["lolcommits"]}
69
+
70
+ stub_request(:post, message_url).to_return(status: 200, body: valid_response.to_json)
71
+
72
+ output = fake_io_capture do
73
+ plugin.run_capture_ready
74
+ end
75
+
76
+ output.must_equal "Posting to Flowdock ... done!\n"
77
+ assert_requested :post, message_url, times: 1, headers: {
78
+ 'Content-Type' => /multipart\/form-data/,
79
+ 'Host' => Lolcommits::Flowdock::Client::API_HOST
80
+ } do |req|
81
+ req.body.must_match(/Content-Disposition: form-data;.+name="content"; filename="main_image.jpg.+"/)
82
+ req.body.must_match(/Content-Disposition: form-data;.+name="tags\[\]"/)
83
+ end
84
+ end
85
+ end
86
+ end
87
+
88
+ describe "configuration" do
89
+ it "returns false when not configured" do
90
+ plugin.configured?.must_equal false
91
+ end
92
+
93
+ it "returns true when configured" do
94
+ plugin.config = valid_enabled_config
95
+ plugin.configured?.must_equal true
96
+ end
97
+
98
+ it "allows plugin options to be configured" do
99
+ # enabled, access token, organization and flow
100
+ access_token = "mytoken"
101
+ configured_plugin_options = {}
102
+
103
+ stub_request(:get, "https://api.flowdock.com/organizations").to_return(
104
+ status: 200,
105
+ body: [
106
+ { name: "My Org", parameterized_name: "myorgparam" },
107
+ { name: "Another", parameterized_name: "anotherorg" }
108
+ ].to_json
109
+ )
110
+
111
+ stub_request(:get, "https://api.flowdock.com/flows").to_return(
112
+ status: 200,
113
+ body: [
114
+ { name: "Flowtwo", parameterized_name: "anotherflow" },
115
+ { name: "My Flow", parameterized_name: "myflowparam" }
116
+ ].to_json
117
+ )
118
+
119
+ # fake readline input and redirect output to a file
120
+ Readline.input = File.new("./test/readline/config_input.txt", "r")
121
+ Readline.output = File.new("./test/readline/config_output.txt", "w+")
122
+ output = fake_io_capture(inputs: ["true", access_token]) do
123
+ configured_plugin_options = plugin.configure_options!
124
+ end
125
+
126
+ output.must_match(/Enter your Flowdock organization name \(tab to autocomplete\)/)
127
+ output.must_match(/e.g. Another, My Org/)
128
+ output.must_match(/Enter your Flowdock flow name \(tab to autocomplete\)/)
129
+ output.must_match(/e.g. Flowtwo, My Flow/)
130
+
131
+ configured_plugin_options.must_equal({
132
+ "enabled" => true,
133
+ "access_token" => access_token,
134
+ "organization" => "myorgparam",
135
+ "flow" => "myflowparam"
136
+ })
137
+ end
138
+ end
139
+ end
140
+ end
@@ -0,0 +1,3 @@
1
+ My Org
2
+ My Flow
3
+
@@ -0,0 +1,2 @@
1
+ Organization: My Org
2
+ Flow: My Flow
@@ -0,0 +1,27 @@
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/flowdock'
19
+ require 'minitest/autorun'
20
+
21
+ # swallow all debug output during test runs
22
+ def debug(msg); end
23
+
24
+ # do not launch URLs
25
+ class Lolcommits::CLI::Launcher
26
+ def self.open_url(url); end
27
+ end
Binary file
metadata ADDED
@@ -0,0 +1,184 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lolcommits-flowdock
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-05 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: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
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.8
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.8
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
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: webmock
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: pry
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: rake
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: minitest
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: simplecov
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: |2
126
+ Automatically posts lolcommit images to a Flowdock flow (room) with the
127
+ #lolcommits hashtag.
128
+ email:
129
+ - matt@hiddenloop.com
130
+ executables: []
131
+ extensions: []
132
+ extra_rdoc_files: []
133
+ files:
134
+ - ".gitignore"
135
+ - ".simplecov"
136
+ - ".travis.yml"
137
+ - CODE_OF_CONDUCT.md
138
+ - CONTRIBUTING.md
139
+ - Gemfile
140
+ - LICENSE
141
+ - README.md
142
+ - Rakefile
143
+ - bin/console
144
+ - bin/setup
145
+ - lib/lolcommits/flowdock.rb
146
+ - lib/lolcommits/flowdock/client.rb
147
+ - lib/lolcommits/flowdock/version.rb
148
+ - lib/lolcommits/plugin/flowdock.rb
149
+ - lolcommits-flowdock.gemspec
150
+ - test/lolcommits/plugin/flowdock_test.rb
151
+ - test/readline/config_input.txt
152
+ - test/readline/config_output.txt
153
+ - test/test_helper.rb
154
+ - vendor/fonts/Impact.ttf
155
+ homepage: https://github.com/lolcommits/lolcommits-flowdock
156
+ licenses:
157
+ - LGPL-3
158
+ metadata:
159
+ allowed_push_host: https://rubygems.org
160
+ post_install_message:
161
+ rdoc_options: []
162
+ require_paths:
163
+ - lib
164
+ required_ruby_version: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: 2.0.0
169
+ required_rubygems_version: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - ">="
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ requirements: []
175
+ rubyforge_project:
176
+ rubygems_version: 2.6.13
177
+ signing_key:
178
+ specification_version: 4
179
+ summary: Posts lolcommits to Flowdockr
180
+ test_files:
181
+ - test/lolcommits/plugin/flowdock_test.rb
182
+ - test/readline/config_input.txt
183
+ - test/readline/config_output.txt
184
+ - test/test_helper.rb