lita-github 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -0
- data/README.md +33 -2
- data/docker-compose.yml +23 -0
- data/lib/lita-github/version.rb +1 -1
- data/lib/lita/handlers/github.rb +33 -33
- data/lib/lita/handlers/github_repo.rb +13 -3
- data/lita-github.gemspec +1 -1
- data/lita_config.example.rb +23 -0
- data/locales/en.yml +3 -0
- data/spec/spec_helper.rb +10 -0
- data/spec/unit/lita/handlers/github_issues_spec.rb +1 -1
- data/spec/unit/lita/handlers/github_org_spec.rb +1 -1
- data/spec/unit/lita/handlers/github_pr_spec.rb +1 -1
- data/spec/unit/lita/handlers/github_repo_spec.rb +11 -1
- data/spec/unit/lita/handlers/github_spec.rb +4 -4
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4fb70c20f1df1ecc8a2bbab4f0d15ca99e654c88
|
4
|
+
data.tar.gz: 4dce6a2923469c0a456f5b47ad76867ce66b94b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 22855d06a6172229a3e1f1a2edd5bf8a15521e3f317b53d1efb6b65254ff3e29c9be97e86752f04696f648796aa6007075097dc98c54f689302e11e761583eea
|
7
|
+
data.tar.gz: 13929d9be901a4ad208d3cdbaf1ea5a032595264760d321c48ef96a107a1549ff9fd94e5220acc7f18c43fc25f112a66a575177c4d4d0bcc94cc6492876bfa15
|
data/.gitignore
CHANGED
data/README.md
CHANGED
@@ -17,6 +17,27 @@ This Gem is currently in development, and is not suited for production use. Ther
|
|
17
17
|
|
18
18
|
In addition, the documentation will be lacking while the development is underway.
|
19
19
|
|
20
|
+
Running Locally
|
21
|
+
---------------
|
22
|
+
### Set Up
|
23
|
+
You'll need to have checked out this repo and `cd` into its directory.
|
24
|
+
Then run the following commands.
|
25
|
+
|
26
|
+
```
|
27
|
+
docker-compose run --rm lita-github bundle install --jobs=5
|
28
|
+
cp lita_config.example.rb lita_config.rb
|
29
|
+
```
|
30
|
+
Edit the lita_config.rb file as needed, you'll most likely need to add your own Github Access Token.
|
31
|
+
```
|
32
|
+
docker-compose run --rm lita-github bundle exec rake
|
33
|
+
```
|
34
|
+
If the above command works and everything passes then you're good to go!
|
35
|
+
|
36
|
+
### Interacting with Lita on the command line
|
37
|
+
```
|
38
|
+
docker-compose run --rm lita-github bundle exec lita
|
39
|
+
```
|
40
|
+
|
20
41
|
Configuration
|
21
42
|
-------------
|
22
43
|
The configuration options will get their own in-depth doc a little further down the line. Here are the important ones for now:
|
@@ -31,6 +52,16 @@ The configuration options will get their own in-depth doc a little further down
|
|
31
52
|
* the default teams that should be added to a repo based on the slug name:
|
32
53
|
* When clicking on a team in your org you can use the URL to get the slug: `https://github.com/orgs/<ORG>/teams/[slug]`
|
33
54
|
|
55
|
+
### Github Enterprise configuration
|
56
|
+
To set your github enterprise hostname you have to directly [configure
|
57
|
+
Octokit](https://github.com/octokit/octokit.rb#working-with-github-enterprise). All you have to do is add
|
58
|
+
the following snippet to ``lita_config.rb``.
|
59
|
+
```ruby
|
60
|
+
Octokit.configure do |octo_config|
|
61
|
+
octo_config.api_endpoint = "https://<your-api-hostname>/api/v3/"
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
34
65
|
Commands
|
35
66
|
--------
|
36
67
|
Use the source, Luke. We will try to keep this list up to date, but it will be inevitably deprecated by proper documentation.
|
@@ -53,8 +84,8 @@ Here is the current functionality:
|
|
53
84
|
* show some information about a GitHub user
|
54
85
|
|
55
86
|
### GitHub Repository Handler
|
56
|
-
* `!gh repo create PagerDuty/lita-github private:true team:<team_slug>`
|
57
|
-
* This creates a new repository, sets it to private,
|
87
|
+
* `!gh repo create PagerDuty/lita-github private:true team:<team_slug> admin:<username>`
|
88
|
+
* This creates a new repository, sets it to private, adds the team you've specified, and adds the GitHub user with <username> as admin
|
58
89
|
* This method can be disabled by setting `config.handlers.github.repo_create_enabled = false` in your configuration file
|
59
90
|
* `!gh repo delete PagerDuty/lita-github`
|
60
91
|
* Deletes the repo you specify, requires confirmation before doing so
|
data/docker-compose.yml
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
---
|
2
|
+
version: '3'
|
3
|
+
services:
|
4
|
+
lita-github:
|
5
|
+
image: 'ruby:2.1'
|
6
|
+
expose:
|
7
|
+
- '8080'
|
8
|
+
volumes:
|
9
|
+
- '.:/usr/src/app'
|
10
|
+
- 'lita-github-bundle:/usr/local/bundle'
|
11
|
+
working_dir: '/usr/src/app'
|
12
|
+
environment:
|
13
|
+
- 'BUNDLE_PATH=/usr/local/bundle'
|
14
|
+
- 'RSPEC_REDIS_HOST=redis'
|
15
|
+
command: 'bundle exec lita'
|
16
|
+
depends_on:
|
17
|
+
- 'redis'
|
18
|
+
redis:
|
19
|
+
image: 'redis'
|
20
|
+
expose:
|
21
|
+
- '8080'
|
22
|
+
volumes:
|
23
|
+
lita-github-bundle: {}
|
data/lib/lita-github/version.rb
CHANGED
@@ -21,7 +21,7 @@
|
|
21
21
|
# @author Tim Heckman <tim@pagerduty.com>
|
22
22
|
module LitaGithub
|
23
23
|
# lita-github version
|
24
|
-
VERSION = '0.
|
24
|
+
VERSION = '0.3.0'
|
25
25
|
|
26
26
|
# lita-github version split amongst different revisions
|
27
27
|
MAJOR_VERSION, MINOR_VERSION, REVISION = VERSION.split('.').map(&:to_i)
|
data/lib/lita/handlers/github.rb
CHANGED
@@ -65,39 +65,39 @@ module Lita
|
|
65
65
|
}
|
66
66
|
)
|
67
67
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
68
|
+
# when setting default configuration values please remember one thing:
|
69
|
+
# secure and safe by default
|
70
|
+
config :access_token, default: nil
|
71
|
+
config :default_team_slugs, default: nil
|
72
|
+
config :repo_private_default, default: true
|
73
|
+
config :org_team_add_allowed_perms, default: %w(pull)
|
74
|
+
|
75
|
+
####
|
76
|
+
# Method Filters
|
77
|
+
####
|
78
|
+
|
79
|
+
# Lita::Handlers::Github
|
80
|
+
config :totp_secret, default: nil
|
81
|
+
|
82
|
+
# Lita::Handlers::GithubRepo
|
83
|
+
config :repo_create_enabled, default: true
|
84
|
+
config :repo_rename_enabled, default: true
|
85
|
+
config :repo_delete_enabled, default: false
|
86
|
+
config :repo_team_add_enabled, default: false
|
87
|
+
config :repo_team_rm_enabled, default: false
|
88
|
+
config :repo_update_description_enabled, default: true
|
89
|
+
config :repo_update_homepage_enabled, default: true
|
90
|
+
|
91
|
+
# Lita::Handlers::GithubPR
|
92
|
+
config :pr_merge_enabled, default: true
|
93
|
+
|
94
|
+
# Lita::Handlers::GithubOrg
|
95
|
+
config :default_org, default: nil
|
96
|
+
config :org_team_add_enabled, default: false
|
97
|
+
config :org_team_rm_enabled, default: false
|
98
|
+
config :org_user_add_enabled, default: false
|
99
|
+
config :org_user_rm_enabled, default: false
|
100
|
+
config :org_eject_user_enabled, default: false
|
101
101
|
|
102
102
|
def status(response)
|
103
103
|
status = octo.github_status_last_message
|
@@ -42,10 +42,11 @@ module Lita
|
|
42
42
|
:repo_create,
|
43
43
|
command: true,
|
44
44
|
help: {
|
45
|
-
'gh repo create PagerDuty/lita-github private:true team:heckman' =>
|
46
|
-
'Create the PagerDuty/lita-github repo, make it private,
|
45
|
+
'gh repo create PagerDuty/lita-github private:true team:heckman admin:anon' =>
|
46
|
+
'Create the PagerDuty/lita-github repo, make it private,'\
|
47
|
+
'use team with "heckman" slug, with GitHub user "anon" as repo admin',
|
47
48
|
'gh repo new PagerDuty/lita-github' =>
|
48
|
-
'create new repo using the default privacy
|
49
|
+
'create new repo using the default privacy, team, admin settings'
|
49
50
|
}
|
50
51
|
)
|
51
52
|
|
@@ -333,6 +334,7 @@ module Lita
|
|
333
334
|
opts[:other_teams].each do |team_id|
|
334
335
|
add_team_to_repo(full_name, gh_team(org, team_id))
|
335
336
|
end if opts.key?(:other_teams)
|
337
|
+
add_admin_to_repo(full_name, opts[:admin]) if opts.key?(:admin)
|
336
338
|
ensure
|
337
339
|
if repo?(full_name)
|
338
340
|
repo_url = "https://github.com/#{full_name}"
|
@@ -401,6 +403,14 @@ module Lita
|
|
401
403
|
return t('repo_team_rm.fail', repo: full_name, team: team[:name])
|
402
404
|
end
|
403
405
|
end
|
406
|
+
|
407
|
+
def add_admin_to_repo(full_name, user)
|
408
|
+
if octo.add_collaborator(full_name, user, permission: 'admin')
|
409
|
+
return t('repo_admin_add.pass', repo: full_name, user: user)
|
410
|
+
else
|
411
|
+
return t('repo_admin_add.fail', repo: full_name, user: user)
|
412
|
+
end
|
413
|
+
end
|
404
414
|
end
|
405
415
|
|
406
416
|
Lita.register_handler(GithubRepo)
|
data/lita-github.gemspec
CHANGED
@@ -44,7 +44,7 @@ Gem::Specification.new do |s|
|
|
44
44
|
s.add_development_dependency 'codeclimate-test-reporter', '~> 0.4', '>= 0.4.0'
|
45
45
|
s.add_development_dependency 'yard', '~> 0.8.7'
|
46
46
|
|
47
|
-
s.add_runtime_dependency 'lita', '
|
47
|
+
s.add_runtime_dependency 'lita', '>= 4.0'
|
48
48
|
s.add_runtime_dependency 'octokit', '~> 3.3'
|
49
49
|
s.add_runtime_dependency 'rotp', '~> 2.0'
|
50
50
|
s.add_runtime_dependency 'lita-confirmation'
|
@@ -0,0 +1,23 @@
|
|
1
|
+
Lita.configure do |config|
|
2
|
+
config.robot.log_level = :debug
|
3
|
+
config.robot.alias = '!'
|
4
|
+
config.redis[:host] = 'redis'
|
5
|
+
|
6
|
+
# For Github/octokit use
|
7
|
+
config.handlers.github.access_token = '<GITHUB ACCESS TOKEN>'
|
8
|
+
config.handlers.github.default_org = '<ORGANIZATION NAME>'
|
9
|
+
config.handlers.github.default_team_slugs = %w(<TEAM1> <TEAM2> <ETC>)
|
10
|
+
config.handlers.github.repo_create_enabled = true
|
11
|
+
config.handlers.github.repo_delete_enabled = true
|
12
|
+
config.handlers.github.repo_private_default = true
|
13
|
+
config.handlers.github.org_team_add_allowed_perms = %w(pull push)
|
14
|
+
config.handlers.github.repo_create_enabled = true
|
15
|
+
config.handlers.github.repo_delete_enabled = true
|
16
|
+
config.handlers.github.pr_merge_enabled = true
|
17
|
+
config.handlers.github.repo_team_add_enabled = true
|
18
|
+
config.handlers.github.repo_team_rm_enabled = true
|
19
|
+
config.handlers.github.repo_update_description_enabled = true
|
20
|
+
config.handlers.github.repo_update_homepage_enabled = true
|
21
|
+
config.handlers.github.org_team_add_enabled = true
|
22
|
+
config.handlers.github.org_team_rm_enabled = true
|
23
|
+
end
|
data/locales/en.yml
CHANGED
@@ -53,6 +53,9 @@ en:
|
|
53
53
|
updated: "The homepage for %{repo} has been updated to: '%{url}'"
|
54
54
|
invalid_url: "The URL provided is not valid: '%{url}'"
|
55
55
|
boom: "An uncaught exception was hit while trying to update the homepage of %{repo}. Is GitHub having issues?"
|
56
|
+
repo_admin_add:
|
57
|
+
pass: "Added user '%{user}' as admin to %{repo}"
|
58
|
+
fail: "Something went wrong trying to add user '%{user}' as admin to %{repo}. Is that user in your organization?"
|
56
59
|
github_pr:
|
57
60
|
method_disabled: "Sorry, this function has either been disabled or not enabled in the config"
|
58
61
|
exception: "An unexpected exception was hit during the GitHub API operation. Please make sure all arguments are proper and try again, or try checking the GitHub status (gh status)"
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,16 @@ require 'rspec'
|
|
18
18
|
require 'lita/rspec'
|
19
19
|
require 'codeclimate-test-reporter'
|
20
20
|
|
21
|
+
RSpec.configure do |config|
|
22
|
+
config.before do
|
23
|
+
if ENV['RSPEC_REDIS_HOST']
|
24
|
+
Lita.configure do |c|
|
25
|
+
c.redis[:host] = ENV['RSPEC_REDIS_HOST']
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
21
31
|
Lita.version_3_compatibility_mode = false
|
22
32
|
|
23
33
|
CodeClimate::TestReporter.start
|
@@ -27,7 +27,7 @@ describe Lita::Handlers::GithubIssues, lita_handler: true do
|
|
27
27
|
|
28
28
|
let(:gh_org) { 'GapeDuty' }
|
29
29
|
let(:gh_repo) { 'lita-test' }
|
30
|
-
let(:github_issues) { Lita::Handlers::GithubIssues.new(
|
30
|
+
let(:github_issues) { Lita::Handlers::GithubIssues.new(robot) }
|
31
31
|
|
32
32
|
describe '.validate_list_opts' do
|
33
33
|
let(:good_opts) { { state: 'open', sort: 'updated', direction: 'asc' } }
|
@@ -51,7 +51,7 @@ describe Lita::Handlers::GithubOrg, lita_handler: true do
|
|
51
51
|
it { is_expected.to route_command('gh org eject GrapeDuty theckman').to(:org_eject_user) }
|
52
52
|
it { is_expected.to route_command('gh org eject theckman').to(:org_eject_user) }
|
53
53
|
|
54
|
-
let(:github_org) { Lita::Handlers::GithubOrg.new(
|
54
|
+
let(:github_org) { Lita::Handlers::GithubOrg.new(robot) }
|
55
55
|
let(:disabled_err) { 'Sorry, this function has either been disabled or not enabled in the config' }
|
56
56
|
|
57
57
|
####
|
@@ -33,7 +33,7 @@ describe Lita::Handlers::GithubPR, lita_handler: true do
|
|
33
33
|
it { is_expected.to route_command('gh pr list GrapeDuty/lita-test').to(:pr_list) }
|
34
34
|
it { is_expected.to route_command('gh pr list lita-test').to(:pr_list) }
|
35
35
|
|
36
|
-
let(:github_pr) { Lita::Handlers::GithubPR.new(
|
36
|
+
let(:github_pr) { Lita::Handlers::GithubPR.new(robot) }
|
37
37
|
let(:github_org) { 'GrapeDuty' }
|
38
38
|
let(:github_repo) { 'lita-test' }
|
39
39
|
let(:full_name) { "#{github_org}/#{github_repo}" }
|
@@ -22,6 +22,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
22
22
|
it { is_expected.to route_command('gh repo new GrapeDuty/lita-test').to(:repo_create) }
|
23
23
|
it { is_expected.to route_command('gh repo new lita-test').to(:repo_create) }
|
24
24
|
it { is_expected.to route_command('gh repo new GrapeDuty/lita-test private:true team:heckman').to(:repo_create) }
|
25
|
+
it { is_expected.to route_command('gh repo new GrapeDuty/lita-test private:true team:heckman admin:anon').to(:repo_create) }
|
25
26
|
it { is_expected.to route_command('gh repo new GrapeDuty/lita-test private:true randomunparseabletext ').to(:repo_create) }
|
26
27
|
|
27
28
|
# repo_rename command routing
|
@@ -76,7 +77,7 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
76
77
|
it { is_expected.to route_command('gh repo update description GrapeDuty/lita-test Some description here').to(:repo_update_router) }
|
77
78
|
it { is_expected.to route_command('gh repo update description lita-test Some description here').to(:repo_update_router) }
|
78
79
|
|
79
|
-
let(:github_repo) { Lita::Handlers::GithubRepo.new(
|
80
|
+
let(:github_repo) { Lita::Handlers::GithubRepo.new(robot) }
|
80
81
|
let(:github_org) { 'GrapeDuty' }
|
81
82
|
let(:disabled_reply) { 'Sorry, this function has either been disabled or not enabled in the config' }
|
82
83
|
|
@@ -361,6 +362,15 @@ describe Lita::Handlers::GithubRepo, lita_handler: true do
|
|
361
362
|
.to eql 'Created GrapeDuty/lita-test: https://github.com/GrapeDuty/lita-test'
|
362
363
|
end
|
363
364
|
end
|
365
|
+
|
366
|
+
context 'when an admin user is given' do
|
367
|
+
it 'should add an admin to the repo after creating it' do
|
368
|
+
expect(github_repo).to receive(:add_admin_to_repo).with('GrapeDuty/lita-test', 'anon')
|
369
|
+
opts = { private: true, team_id: 1, organization: github_org, admin: 'anon'}
|
370
|
+
expect(github_repo.send(:create_repo, github_org, 'lita-test', opts))
|
371
|
+
.to eql 'Created GrapeDuty/lita-test: https://github.com/GrapeDuty/lita-test'
|
372
|
+
end
|
373
|
+
end
|
364
374
|
end
|
365
375
|
|
366
376
|
context 'when repo not created' do
|
@@ -17,7 +17,7 @@
|
|
17
17
|
require 'spec_helper'
|
18
18
|
|
19
19
|
describe Lita::Handlers::Github, lita_handler: true do
|
20
|
-
let(:github) { Lita::Handlers::Github.new(
|
20
|
+
let(:github) { Lita::Handlers::Github.new(robot) }
|
21
21
|
|
22
22
|
# status routing
|
23
23
|
it { is_expected.to route_command('gh status').to(:status) }
|
@@ -33,9 +33,9 @@ describe Lita::Handlers::Github, lita_handler: true do
|
|
33
33
|
it { is_expected.to route_command('gh whois theckman').to(:whois) }
|
34
34
|
it { is_expected.to route_command('gh user theckman').to(:whois) }
|
35
35
|
|
36
|
-
describe '#
|
37
|
-
it 'should set default
|
38
|
-
expect(Lita.config.handlers.github.
|
36
|
+
describe '#config' do
|
37
|
+
it 'should set default teams to nil' do
|
38
|
+
expect(Lita.config.handlers.github.default_team_slugs).to be_nil
|
39
39
|
end
|
40
40
|
|
41
41
|
it 'should set repos to private by default' do
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tim Heckman
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-05-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -138,14 +138,14 @@ dependencies:
|
|
138
138
|
name: lita
|
139
139
|
requirement: !ruby/object:Gem::Requirement
|
140
140
|
requirements:
|
141
|
-
- - "
|
141
|
+
- - ">="
|
142
142
|
- !ruby/object:Gem::Version
|
143
143
|
version: '4.0'
|
144
144
|
type: :runtime
|
145
145
|
prerelease: false
|
146
146
|
version_requirements: !ruby/object:Gem::Requirement
|
147
147
|
requirements:
|
148
|
-
- - "
|
148
|
+
- - ">="
|
149
149
|
- !ruby/object:Gem::Version
|
150
150
|
version: '4.0'
|
151
151
|
- !ruby/object:Gem::Dependency
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- LICENSE
|
206
206
|
- README.md
|
207
207
|
- Rakefile
|
208
|
+
- docker-compose.yml
|
208
209
|
- lib/lita-github.rb
|
209
210
|
- lib/lita-github/config.rb
|
210
211
|
- lib/lita-github/filters.rb
|
@@ -220,6 +221,7 @@ files:
|
|
220
221
|
- lib/lita/handlers/github_pr.rb
|
221
222
|
- lib/lita/handlers/github_repo.rb
|
222
223
|
- lita-github.gemspec
|
224
|
+
- lita_config.example.rb
|
223
225
|
- locales/en.yml
|
224
226
|
- spec/spec_helper.rb
|
225
227
|
- spec/unit/lita-github/config_spec.rb
|
@@ -257,7 +259,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
257
259
|
version: '0'
|
258
260
|
requirements: []
|
259
261
|
rubyforge_project:
|
260
|
-
rubygems_version: 2.
|
262
|
+
rubygems_version: 2.2.0
|
261
263
|
signing_key:
|
262
264
|
specification_version: 4
|
263
265
|
summary: GitHub repo/org management in Lita; handler not ready for production
|