lita-github 0.0.4 → 0.0.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0cc46959df4d539d8ae57127dc70528eb0f8c693
4
- data.tar.gz: d1a064ef57e8a8dd86e72cb4336b93f221ced29a
3
+ metadata.gz: 84ebbc2e578a216a3e4e15fa00011549924cb610
4
+ data.tar.gz: 700ad40378f13ab0d10b1775a361ccbca3aca5a1
5
5
  SHA512:
6
- metadata.gz: 3e9d24e71ecc36a25262e459c924c60ed4f0c2667a0008a6122fe2fbde1ea23628c91620280677f28dadc2b48685ff43365ac247774b7d06a627dad867d10300
7
- data.tar.gz: 0368bb271581c4aa7939a423c1cd16e62d6ec795d2f1df84701aed8bc7bc5c6e33bde356bb74f3d9d13e7e2f491fffd1b05f04d9b0ed2c23e864fac456919289
6
+ metadata.gz: 9b7c3e7b9a3db900ad5033f72d44078935c1e11265764e3be9ead51ba9f1d2422a7100416c0897af2ac0c1b3127b7a8d9f20ef89be7ee563027dbdf3a7f8103f
7
+ data.tar.gz: af6d62477813175ea4abc97117f4169ff4cd1f64da4028ab129e961fd023745ef38a8f4dcd6279623870cad641cf605832b3b63229b8424042e47f918bf2290e
data/README.md CHANGED
@@ -1,9 +1,9 @@
1
1
  lita-github
2
2
  ===========
3
3
  [![Build Status](https://img.shields.io/travis/PagerDuty/lita-github/master.svg)](https://travis-ci.org/PagerDuty/lita-github)
4
- [![MIT License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
5
- [![RubyGems :: lita-github Gem Version](http://img.shields.io/gem/v/lita-github.svg)](https://rubygems.org/gems/lita-github)
6
4
  [![Code Climate Coverage](http://img.shields.io/codeclimate/coverage/github/PagerDuty/lita-github.svg)](https://codeclimate.com/github/PagerDuty/lita-github)
5
+ [![RubyGems :: lita-github Gem Version](http://img.shields.io/gem/v/lita-github.svg)](https://rubygems.org/gems/lita-github)
6
+ [![MIT License](https://img.shields.io/badge/license-Apache%202.0-brightgreen.svg)](https://tldrlegal.com/license/apache-license-2.0-(apache-2.0))
7
7
 
8
8
  Copyright 2014 PagerDuty, Inc.
9
9
 
@@ -46,6 +46,8 @@ Here is the current functionality:
46
46
  * get the current system status for GitHub
47
47
  * `!gh version`
48
48
  * get the version of handler
49
+ * `!gh token`
50
+ * generate a TOTP token if `config.handlers.github.totp_secret` is set in the config
49
51
 
50
52
  ### GitHub Repository Handler
51
53
  * `!gh repo create PagerDuty/lita-github private:true team:<team_slug>`
@@ -27,6 +27,7 @@ module LitaGithub
27
27
  # set up the Octokit client
28
28
  def setup_octo(_)
29
29
  @@octo ||= Octokit::Client.new(access_token: access_token)
30
+ @@octo.auto_paginate = true
30
31
  end
31
32
 
32
33
  # object access method for Octokit client
@@ -16,6 +16,6 @@
16
16
 
17
17
  # Administer your Hub of Gits with Lita!
18
18
  module LitaGithub
19
- VERSION = '0.0.4'
19
+ VERSION = '0.0.5'
20
20
  MAJ, MIN, REV = VERSION.split('.').map(&:to_i)
21
21
  end
@@ -14,6 +14,7 @@
14
14
  # See the License for the specific language governing permissions and
15
15
  # limitations under the License.
16
16
 
17
+ require 'rotp'
17
18
  require 'lita-github/version'
18
19
  require 'lita-github/r'
19
20
  require 'lita-github/config'
@@ -47,6 +48,14 @@ module Lita
47
48
  }
48
49
  )
49
50
 
51
+ route(
52
+ /#{LitaGithub::R::A_REG}(?:token|2fa|tfa)/, :token_generate,
53
+ command: true,
54
+ help: {
55
+ 'gh token' => 'generate a Time-based One-Time Password (TOTP) using provided secret'
56
+ }
57
+ )
58
+
50
59
  def self.default_config(config)
51
60
  # when setting default configuration values please remember one thing:
52
61
  # secure and safe by default
@@ -56,6 +65,9 @@ module Lita
56
65
  # Method Filters
57
66
  ####
58
67
 
68
+ # Lita::Handlers::Github
69
+ config.totp_secret = nil
70
+
59
71
  # Lita::Handlers::GithubRepo
60
72
  config.repo_create_enabled = true
61
73
  config.repo_delete_enabled = false
@@ -69,6 +81,14 @@ module Lita
69
81
  response.reply(t("status.#{status[:status]}", status))
70
82
  end
71
83
 
84
+ def token_generate(response)
85
+ if config.totp_secret.is_a?(String)
86
+ response.reply(t('token_generate.totp', token: ROTP::TOTP.new(config.totp_secret).now))
87
+ else
88
+ response.reply(t('token_generate.no_secret'))
89
+ end
90
+ end
91
+
72
92
  def gh_version(response)
73
93
  response.reply("lita-github v#{LitaGithub::VERSION}")
74
94
  end
data/lita-github.gemspec CHANGED
@@ -44,5 +44,6 @@ Gem::Specification.new do |s|
44
44
 
45
45
  s.add_runtime_dependency 'lita', '~> 3.3'
46
46
  s.add_runtime_dependency 'octokit', '~> 3.3'
47
+ s.add_runtime_dependency 'rotp', '~> 2.0'
47
48
  s.add_runtime_dependency 'lita-confirmation'
48
49
  end
data/locales/en.yml CHANGED
@@ -6,6 +6,9 @@ en:
6
6
  good: "GitHub is reporting that all systems are green!"
7
7
  minor: "GitHub is reporting minor issues (status:yellow)! Last message:\n%{created_on} :: %{body}"
8
8
  major: "GitHub is reporting major issues (status:red)! Last message:\n%{created_on} :: %{body}"
9
+ token_generate:
10
+ no_secret: "'totp_secret' has not been provided in the config, unable to generate TOTP"
11
+ totp: "%{token}"
9
12
  github_repo:
10
13
  method_disabled: "Sorry, this function has either been disabled or not enabled in the config"
11
14
  repo_create:
@@ -16,14 +16,22 @@
16
16
 
17
17
  require 'spec_helper'
18
18
 
19
+ # Dummy class for mocking Octokit::Client
20
+ class DoubleFixer
21
+ class << self
22
+ attr_accessor :auto_paginate
23
+ end
24
+ end
25
+
19
26
  # Dummy class for testing some mixin
20
27
  class DummyClass
21
28
  include LitaGithub::Octo
29
+ extend LitaGithub::Octo
22
30
  end
23
31
 
24
32
  describe LitaGithub::Octo do
25
33
  before do
26
- allow(Octokit::Client).to receive(:new).with(access_token: 'abc123').and_return(:ohai)
34
+ allow(Octokit::Client).to receive(:new).with(access_token: 'abc123').and_return(DoubleFixer)
27
35
  @conf_obj = double('Lita::Config', access_token: 'abc123')
28
36
  allow(self).to receive(:config).and_return(@conf_obj)
29
37
  allow_any_instance_of(DummyClass).to receive(:config).and_return(@conf_obj)
@@ -41,13 +49,19 @@ describe LitaGithub::Octo do
41
49
 
42
50
  describe '.setup_octo' do
43
51
  it 'should set up the Octokit client instance' do
44
- expect(DummyClass.class_variable_get(:@@octo)).to eql :ohai
52
+ x = DummyClass.class_variable_get(:@@octo)
53
+ expect(x).to eql DoubleFixer
54
+ end
55
+
56
+ it 'should turn on auto pagination' do
57
+ expect(DoubleFixer).to receive(:auto_paginate=).with(true)
58
+ DummyClass.setup_octo(nil)
45
59
  end
46
60
  end
47
61
 
48
62
  describe '.octo' do
49
63
  it 'should return the @@octo instance variable' do
50
- expect(@dummy.octo).to eql :ohai
64
+ expect(@dummy.octo).to eql DoubleFixer
51
65
  end
52
66
  end
53
67
  end
@@ -17,11 +17,12 @@
17
17
  require 'spec_helper'
18
18
 
19
19
  describe Lita::Handlers::Github, lita_handler: true do
20
- let(:github) { Lita::Handlers::Forecast.new('robot') }
20
+ let(:github) { Lita::Handlers::Github.new('robot') }
21
21
 
22
22
  it { routes_command('gh status').to(:gh_status) }
23
23
  it { routes_command('github status').to(:gh_status) }
24
24
  it { routes_command('gh version').to(:gh_version) }
25
+ it { routes_command('gh token').to(:token_generate) }
25
26
 
26
27
  describe '#default_config' do
27
28
  it 'should set repos to private by default' do
@@ -109,4 +110,33 @@ describe Lita::Handlers::Github, lita_handler: true do
109
110
  expect(replies.last).to eql "lita-github v#{LitaGithub::VERSION}"
110
111
  end
111
112
  end
113
+
114
+ describe '.token_generate' do
115
+ before do
116
+ @secret = 'GZSDEMLDMY3TQYLG'
117
+ conf_obj = double('Lita::Configuration', totp_secret: @secret)
118
+ allow(github).to receive(:config).and_return(conf_obj)
119
+ end
120
+
121
+ context 'when token is set' do
122
+ it 'should return the correct totp token' do
123
+ t = ROTP::TOTP.new(@secret)
124
+ send_command('gh token')
125
+ expect(replies.last).to eql t.now
126
+ end
127
+ end
128
+
129
+ context 'when token is not set' do
130
+ before do
131
+ conf_obj = double('Lita::Configuration', totp_secret: nil)
132
+ allow(github).to receive(:config).and_return(conf_obj)
133
+ end
134
+
135
+ it 'should return the error message' do
136
+ send_command('gh token')
137
+ expect(replies.last)
138
+ .to eql "'totp_secret' has not been provided in the config, unable to generate TOTP"
139
+ end
140
+ end
141
+ end
112
142
  end
@@ -0,0 +1,61 @@
1
+ Lita + GitHub syntax sketches
2
+ =============================
3
+ These sketches were originally made by Eric Sigler (@esigler) at PagerDuty. They are being added
4
+ to the repo just for development purposes. This file will be removed later on.
5
+
6
+ As a note, these are the results of brainstorming. They in no way indicate the final syntax, nor
7
+ should they be treated as the end-all-be-all for how the commands should look. Follow convention
8
+ and do what feels right.
9
+
10
+ ### Committers
11
+ ```
12
+ github commiters <repo> - shows commiters of repository
13
+ github commiters top <repo> - shows top commiters of repository
14
+ ```
15
+
16
+ ### Issues
17
+ ```
18
+ github issues show <repo> - List all issues for given repo
19
+ github issues show mine - List all issues for user
20
+ github issues show all - List all issues for all followed repos
21
+ github issues new <repo> <issue> - List all issues for given repo
22
+ github issues delete <issue ID> - List all issues for given repo
23
+ ```
24
+
25
+ ### Pull Requests
26
+ ```
27
+ github pr <pr #> merge - Merge a pull request
28
+ shipit <pull request> - Add a :shipit: squirrel to a PR
29
+ ```
30
+
31
+ ### Merging
32
+ ```
33
+ github merge project_name/<head> into <base> - merges the selected branches or SHA commits
34
+ ```
35
+
36
+ ### Repositories
37
+ ```
38
+ github repo new
39
+ github repo add committer
40
+ github repo show <repo> - shows activity of repository
41
+ ```
42
+
43
+ ### Searches
44
+ ```
45
+ github search <query> [repo] - Search for <query> in [repo] or anywhere
46
+ ```
47
+
48
+ ### Github site status
49
+ ```
50
+ github status - Returns the current system status and timestamp
51
+ github status last - Returns the last human communication, status, and timestamp
52
+ github status messages - Returns the most recent human communications with status and timestamp
53
+ github status stalk [seconds] - Returns the last human communication, status, and timestamp, watches [seconds, default 60] for updates, and posts if it changes
54
+ ```
55
+
56
+ ### Misc.
57
+ ```
58
+ github identify <email address>
59
+ github whoami
60
+ github forget
61
+ ```
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lita-github
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tim Heckman
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-02 00:00:00.000000000 Z
11
+ date: 2014-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -128,6 +128,20 @@ dependencies:
128
128
  - - "~>"
129
129
  - !ruby/object:Gem::Version
130
130
  version: '3.3'
131
+ - !ruby/object:Gem::Dependency
132
+ name: rotp
133
+ requirement: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - "~>"
136
+ - !ruby/object:Gem::Version
137
+ version: '2.0'
138
+ type: :runtime
139
+ prerelease: false
140
+ version_requirements: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - "~>"
143
+ - !ruby/object:Gem::Version
144
+ version: '2.0'
131
145
  - !ruby/object:Gem::Dependency
132
146
  name: lita-confirmation
133
147
  requirement: !ruby/object:Gem::Requirement
@@ -181,6 +195,7 @@ files:
181
195
  - spec/unit/lita/handlers/github_pr_spec.rb
182
196
  - spec/unit/lita/handlers/github_repo_spec.rb
183
197
  - spec/unit/lita/handlers/github_spec.rb
198
+ - syntax_sketches.md
184
199
  homepage: https://github.com/PagerDuty/lita-github
185
200
  licenses:
186
201
  - Apache 2.0