ruboty-github 0.0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/CHANGELOG.md +26 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +25 -0
- data/Rakefile +2 -0
- data/images/screenshot.png +0 -0
- data/lib/ruboty/github.rb +12 -0
- data/lib/ruboty/github/actions/base.rb +69 -0
- data/lib/ruboty/github/actions/close_issue.rb +52 -0
- data/lib/ruboty/github/actions/create_issue.rb +39 -0
- data/lib/ruboty/github/actions/create_pull_request.rb +74 -0
- data/lib/ruboty/github/actions/merge_pull_request.rb +18 -0
- data/lib/ruboty/github/actions/remember.rb +26 -0
- data/lib/ruboty/github/version.rb +5 -0
- data/lib/ruboty/handlers/github.rb +57 -0
- data/ruboty-github.gemspec +27 -0
- data/spec/ruboty/handlers/github_spec.rb +163 -0
- data/spec/spec_helper.rb +11 -0
- metadata +178 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 9578aec46d62100c00525797a1ef5688bb9515c3
|
4
|
+
data.tar.gz: 5872787611bc3e2661647bd159355fb54c4491c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 34f4eecc7f53069fe1449ef827a679bed6d1fadcf727d1cfa28bff5d27d71353dc5550f1a5b39ee8e8eedd9b707be1af07bdcca0af974bf5bc1c095a3bd45563
|
7
|
+
data.tar.gz: 1b5f37293212512b0e1da96521499708761d73fde94c255dc12f92739b3319abfe6349ced4756a21fae63aae362e17ad0a6ec132212567ceb10e6e6bfc27f958
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
## 0.0.9
|
2
|
+
* Rename: Ellen -> Ruboty
|
3
|
+
|
4
|
+
## 0.0.8
|
5
|
+
* Support Github Enterprise
|
6
|
+
|
7
|
+
## 0.0.7
|
8
|
+
* Use Ruboty::Message#from_name as user identifier
|
9
|
+
|
10
|
+
## 0.0.6
|
11
|
+
* Add Create & Merge Pull Request commands
|
12
|
+
|
13
|
+
## 0.0.5
|
14
|
+
* Description support
|
15
|
+
|
16
|
+
## 0.0.4
|
17
|
+
* Add close command
|
18
|
+
|
19
|
+
## 0.0.3
|
20
|
+
* Support Ruboty v0.2.0
|
21
|
+
|
22
|
+
## 0.0.2
|
23
|
+
* Memorize access token and use it to create a new issue
|
24
|
+
|
25
|
+
## 0.0.1
|
26
|
+
* 1st Release
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Ryo Nakamura
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# Ruboty::Github
|
2
|
+
Manage GitHub via Ruboty.
|
3
|
+
|
4
|
+
## Install
|
5
|
+
```ruby
|
6
|
+
# Gemfile
|
7
|
+
gem "ruboty-github"
|
8
|
+
```
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
```
|
12
|
+
@ruboty close issue <repo>#<number> - Close an Issue
|
13
|
+
@ruboty create issue "<title>" on <repo>[\n<description>] - Create a new Issue
|
14
|
+
@ruboty merge pull request<repo>#<number> - Merge a Pull Request
|
15
|
+
@ruboty pull request "<title>" from <from> to <to> - Create a new Pull Request
|
16
|
+
@ruboty remember my github token <token> - Remember sender's GitHub access token
|
17
|
+
```
|
18
|
+
|
19
|
+
## ENV
|
20
|
+
```
|
21
|
+
GITHUB_HOST - Pass GitHub Host if needed (e.g. github.example.com)
|
22
|
+
```
|
23
|
+
|
24
|
+
## Image
|
25
|
+
![](https://raw.githubusercontent.com/r7kamura/ruboty-github/master/images/screenshot.png)
|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,12 @@
|
|
1
|
+
require "active_support/core_ext/string/strip"
|
2
|
+
require "octokit"
|
3
|
+
|
4
|
+
require "ruboty"
|
5
|
+
require "ruboty/github/actions/base"
|
6
|
+
require "ruboty/github/actions/close_issue"
|
7
|
+
require "ruboty/github/actions/create_issue"
|
8
|
+
require "ruboty/github/actions/create_pull_request"
|
9
|
+
require "ruboty/github/actions/merge_pull_request"
|
10
|
+
require "ruboty/github/actions/remember"
|
11
|
+
require "ruboty/github/version"
|
12
|
+
require "ruboty/handlers/github"
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class Base
|
5
|
+
NAMESPACE = "github"
|
6
|
+
|
7
|
+
attr_reader :message
|
8
|
+
|
9
|
+
def initialize(message)
|
10
|
+
@message = message
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def access_tokens
|
16
|
+
message.robot.brain.data[NAMESPACE] ||= {}
|
17
|
+
end
|
18
|
+
|
19
|
+
def sender_name
|
20
|
+
message.from_name
|
21
|
+
end
|
22
|
+
|
23
|
+
def require_access_token
|
24
|
+
message.reply("I don't know your github access token")
|
25
|
+
end
|
26
|
+
|
27
|
+
def has_access_token?
|
28
|
+
!!access_token
|
29
|
+
end
|
30
|
+
|
31
|
+
def access_token
|
32
|
+
@access_token ||= access_tokens[sender_name]
|
33
|
+
end
|
34
|
+
|
35
|
+
def client
|
36
|
+
Octokit::Client.new(client_options)
|
37
|
+
end
|
38
|
+
|
39
|
+
def repository
|
40
|
+
message[:repo]
|
41
|
+
end
|
42
|
+
|
43
|
+
def client_options
|
44
|
+
client_options_with_nil_value.reject {|key, value| value.nil? }
|
45
|
+
end
|
46
|
+
|
47
|
+
def client_options_with_nil_value
|
48
|
+
{
|
49
|
+
access_token: access_token,
|
50
|
+
api_endpoint: api_endpoint,
|
51
|
+
web_endpoint: web_endpoint,
|
52
|
+
}
|
53
|
+
end
|
54
|
+
|
55
|
+
def web_endpoint
|
56
|
+
"https://#{github_host}/" if github_host
|
57
|
+
end
|
58
|
+
|
59
|
+
def api_endpoint
|
60
|
+
"https://#{github_host}/api/v3" if github_host
|
61
|
+
end
|
62
|
+
|
63
|
+
def github_host
|
64
|
+
ENV["GITHUB_HOST"]
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class CloseIssue < Base
|
5
|
+
def call
|
6
|
+
case
|
7
|
+
when !has_access_token?
|
8
|
+
require_access_token
|
9
|
+
when has_closed_issue_number?
|
10
|
+
reply_already_closed
|
11
|
+
else
|
12
|
+
close
|
13
|
+
end
|
14
|
+
rescue Octokit::Unauthorized
|
15
|
+
message.reply("Failed in authentication (401)")
|
16
|
+
rescue Octokit::NotFound
|
17
|
+
message.reply("Could not find that issue")
|
18
|
+
rescue => exception
|
19
|
+
raise exception
|
20
|
+
message.reply("Failed by #{exception.class}")
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def close
|
26
|
+
request
|
27
|
+
message.reply("Closed #{issue.html_url}")
|
28
|
+
end
|
29
|
+
|
30
|
+
def request
|
31
|
+
client.close_issue(repository, issue_number)
|
32
|
+
end
|
33
|
+
|
34
|
+
def has_closed_issue_number?
|
35
|
+
issue.state == "closed"
|
36
|
+
end
|
37
|
+
|
38
|
+
def reply_already_closed
|
39
|
+
message.reply("Already closed #{issue.html_url}")
|
40
|
+
end
|
41
|
+
|
42
|
+
def issue
|
43
|
+
@issue ||= client.issue(repository, issue_number)
|
44
|
+
end
|
45
|
+
|
46
|
+
def issue_number
|
47
|
+
message[:number]
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class CreateIssue < Base
|
5
|
+
def call
|
6
|
+
if has_access_token?
|
7
|
+
create
|
8
|
+
else
|
9
|
+
require_access_token
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create
|
16
|
+
message.reply("Created #{issue.html_url}")
|
17
|
+
rescue Octokit::Unauthorized
|
18
|
+
message.reply("Failed in authentication (401)")
|
19
|
+
rescue Octokit::NotFound
|
20
|
+
message.reply("Could not find that repository")
|
21
|
+
rescue => exception
|
22
|
+
message.reply("Failed by #{exception.class}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def issue
|
26
|
+
client.create_issue(repository, title, body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def title
|
30
|
+
message[:title]
|
31
|
+
end
|
32
|
+
|
33
|
+
def body
|
34
|
+
message[:description]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class CreatePullRequest < Base
|
5
|
+
def call
|
6
|
+
if has_access_token?
|
7
|
+
create
|
8
|
+
else
|
9
|
+
require_access_token
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def create
|
16
|
+
message.reply("Created #{pull_request.html_url}")
|
17
|
+
rescue Octokit::Unauthorized
|
18
|
+
message.reply("Failed in authentication (401)")
|
19
|
+
rescue Octokit::NotFound
|
20
|
+
message.reply("Could not find that repository")
|
21
|
+
rescue => exception
|
22
|
+
message.reply("Failed by #{exception.class} #{exception}")
|
23
|
+
end
|
24
|
+
|
25
|
+
def pull_request
|
26
|
+
client.create_pull_request(repository, base, head, title, description)
|
27
|
+
end
|
28
|
+
|
29
|
+
def title
|
30
|
+
message[:title]
|
31
|
+
end
|
32
|
+
|
33
|
+
def description
|
34
|
+
message[:description]
|
35
|
+
end
|
36
|
+
|
37
|
+
# e.g. alice/foo:test
|
38
|
+
def from
|
39
|
+
message[:from]
|
40
|
+
end
|
41
|
+
|
42
|
+
# e.g. alice
|
43
|
+
def from_user
|
44
|
+
from.split("/").first
|
45
|
+
end
|
46
|
+
|
47
|
+
# e.g. test
|
48
|
+
def from_branch
|
49
|
+
from.split(":").last
|
50
|
+
end
|
51
|
+
|
52
|
+
# e.g. bob/foo:master
|
53
|
+
def to
|
54
|
+
message[:to]
|
55
|
+
end
|
56
|
+
|
57
|
+
# e.g. bob/foo
|
58
|
+
def repository
|
59
|
+
to.split(":").first
|
60
|
+
end
|
61
|
+
|
62
|
+
# e.g. alice:test
|
63
|
+
def head
|
64
|
+
"#{from_user}:#{from_branch}"
|
65
|
+
end
|
66
|
+
|
67
|
+
# e.g. master
|
68
|
+
def base
|
69
|
+
to.split(":").last
|
70
|
+
end
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class MergePullRequest < CloseIssue
|
5
|
+
private
|
6
|
+
|
7
|
+
def close
|
8
|
+
request
|
9
|
+
message.reply("Merged #{issue.html_url}")
|
10
|
+
end
|
11
|
+
|
12
|
+
def request
|
13
|
+
client.merge_pull_request(repository, issue_number)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class Remember < Base
|
5
|
+
def call
|
6
|
+
remember
|
7
|
+
report
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
|
12
|
+
def report
|
13
|
+
message.reply("Remembered #{sender_name}'s github access token")
|
14
|
+
end
|
15
|
+
|
16
|
+
def remember
|
17
|
+
access_tokens[sender_name] = given_access_token
|
18
|
+
end
|
19
|
+
|
20
|
+
def given_access_token
|
21
|
+
message[:token]
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Github < Base
|
4
|
+
env :GITHUB_HOST, "Pass GitHub Host if needed (e.g. github.example.com)", optional: true
|
5
|
+
|
6
|
+
on(
|
7
|
+
/create issue "(?<title>.+)" on (?<repo>.+)(?:\n(?<description>[\s\S]+))?\z/,
|
8
|
+
name: "create_issue",
|
9
|
+
description: "Create a new issue",
|
10
|
+
)
|
11
|
+
|
12
|
+
on(
|
13
|
+
/remember my github token (?<token>.+)\z/,
|
14
|
+
name: "remember",
|
15
|
+
description: "Remember sender's GitHub access token",
|
16
|
+
)
|
17
|
+
|
18
|
+
on(
|
19
|
+
/close issue (?<repo>.+)#(?<number>\d+)\z/,
|
20
|
+
name: "close_issue",
|
21
|
+
description: "Close an issue",
|
22
|
+
)
|
23
|
+
|
24
|
+
on(
|
25
|
+
/pull request "(?<title>.+)" from (?<from>.+) to (?<to>.+)(?:\n(?<description>[\s\S]+))?\z/,
|
26
|
+
name: "create_pull_request",
|
27
|
+
description: "Create a pull request",
|
28
|
+
)
|
29
|
+
|
30
|
+
on(
|
31
|
+
/merge pull request (?<repo>.+)#(?<number>\d+)\z/,
|
32
|
+
name: "merge_pull_request",
|
33
|
+
description: "Merge pull request",
|
34
|
+
)
|
35
|
+
|
36
|
+
def create_issue(message)
|
37
|
+
Ruboty::Github::Actions::CreateIssue.new(message).call
|
38
|
+
end
|
39
|
+
|
40
|
+
def close_issue(message)
|
41
|
+
Ruboty::Github::Actions::CloseIssue.new(message).call
|
42
|
+
end
|
43
|
+
|
44
|
+
def remember(message)
|
45
|
+
Ruboty::Github::Actions::Remember.new(message).call
|
46
|
+
end
|
47
|
+
|
48
|
+
def create_pull_request(message)
|
49
|
+
Ruboty::Github::Actions::CreatePullRequest.new(message).call
|
50
|
+
end
|
51
|
+
|
52
|
+
def merge_pull_request(message)
|
53
|
+
Ruboty::Github::Actions::MergePullRequest.new(message).call
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
lib = File.expand_path("../lib", __FILE__)
|
2
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
|
+
require 'ruboty/github/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |spec|
|
6
|
+
spec.name = "ruboty-github"
|
7
|
+
spec.version = Ruboty::Github::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura"]
|
9
|
+
spec.email = ["r7kamura@gmail.com"]
|
10
|
+
spec.summary = "Manage GitHub via Ruboty."
|
11
|
+
spec.homepage = "https://github.com/r7kamura/ruboty-github"
|
12
|
+
spec.license = "MIT"
|
13
|
+
|
14
|
+
spec.files = `git ls-files -z`.split("\x0")
|
15
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
16
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
+
spec.require_paths = ["lib"]
|
18
|
+
|
19
|
+
spec.add_dependency "activesupport"
|
20
|
+
spec.add_dependency "ruboty"
|
21
|
+
spec.add_dependency "octokit"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "rspec", "2.14.1"
|
25
|
+
spec.add_development_dependency "simplecov"
|
26
|
+
spec.add_development_dependency "webmock"
|
27
|
+
end
|
@@ -0,0 +1,163 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
require "json"
|
3
|
+
|
4
|
+
describe Ruboty::Handlers::Github do
|
5
|
+
before do
|
6
|
+
access_tokens.merge!(sender => stored_access_token)
|
7
|
+
end
|
8
|
+
|
9
|
+
let(:robot) do
|
10
|
+
Ruboty::Robot.new
|
11
|
+
end
|
12
|
+
|
13
|
+
let(:stored_access_token) do
|
14
|
+
github_access_token
|
15
|
+
end
|
16
|
+
|
17
|
+
let(:github_access_token) do
|
18
|
+
"dummy"
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:sender) do
|
22
|
+
"bob"
|
23
|
+
end
|
24
|
+
|
25
|
+
let(:channel) do
|
26
|
+
"#general"
|
27
|
+
end
|
28
|
+
|
29
|
+
let(:user) do
|
30
|
+
"alice"
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:repository) do
|
34
|
+
"test"
|
35
|
+
end
|
36
|
+
|
37
|
+
let(:access_tokens) do
|
38
|
+
robot.brain.data[Ruboty::Github::Actions::Base::NAMESPACE] ||= {}
|
39
|
+
end
|
40
|
+
|
41
|
+
let(:call) do
|
42
|
+
robot.receive(body: body, from: sender, to: channel)
|
43
|
+
end
|
44
|
+
|
45
|
+
shared_examples_for "requires access token without access token" do
|
46
|
+
context "without access token" do
|
47
|
+
let(:stored_access_token) do
|
48
|
+
nil
|
49
|
+
end
|
50
|
+
|
51
|
+
it "requires access token" do
|
52
|
+
Ruboty.logger.should_receive(:info).with("I don't know your github access token")
|
53
|
+
call
|
54
|
+
a_request(:any, //).should_not have_been_made
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#create_issue" do
|
60
|
+
before do
|
61
|
+
stub_request(:post, "https://github.com/api/v3/repos/#{user}/#{repository}/issues").
|
62
|
+
with(
|
63
|
+
body: {
|
64
|
+
labels: nil,
|
65
|
+
title: title,
|
66
|
+
body: nil,
|
67
|
+
}.to_json,
|
68
|
+
headers: {
|
69
|
+
Authorization: "token #{github_access_token}"
|
70
|
+
},
|
71
|
+
)
|
72
|
+
end
|
73
|
+
|
74
|
+
let(:title) do
|
75
|
+
"This is a test issue"
|
76
|
+
end
|
77
|
+
|
78
|
+
let(:body) do
|
79
|
+
%<ruboty create issue "#{title}" on #{user}/#{repository}>
|
80
|
+
end
|
81
|
+
|
82
|
+
include_examples "requires access token without access token"
|
83
|
+
|
84
|
+
context "with access token" do
|
85
|
+
it "creates a new issue with given title on given repository" do
|
86
|
+
call
|
87
|
+
a_request(:any, //).should have_been_made
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
describe "#close_issue" do
|
93
|
+
before do
|
94
|
+
stub_request(:get, "https://github.com/api/v3/repos/#{user}/#{repository}/issues/#{issue_number}").
|
95
|
+
with(
|
96
|
+
headers: {
|
97
|
+
Authorization: "token #{github_access_token}"
|
98
|
+
},
|
99
|
+
).
|
100
|
+
to_return(
|
101
|
+
body: {
|
102
|
+
state: issue_status,
|
103
|
+
html_url: html_url,
|
104
|
+
}.to_json,
|
105
|
+
headers: {
|
106
|
+
"Content-Type" => "application/json",
|
107
|
+
},
|
108
|
+
)
|
109
|
+
stub_request(:patch, "https://github.com/api/v3/repos/#{user}/#{repository}/issues/#{issue_number}").
|
110
|
+
with(
|
111
|
+
body: {
|
112
|
+
state: "closed",
|
113
|
+
}.to_json,
|
114
|
+
headers: {
|
115
|
+
Authorization: "token #{github_access_token}"
|
116
|
+
},
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
120
|
+
let(:html_url) do
|
121
|
+
"http://example.com/#{user}/#{repository}/issues/#{issue_number}"
|
122
|
+
end
|
123
|
+
|
124
|
+
let(:issue_status) do
|
125
|
+
"open"
|
126
|
+
end
|
127
|
+
|
128
|
+
let(:body) do
|
129
|
+
"@ruboty close issue #{user}/#{repository}##{issue_number}"
|
130
|
+
end
|
131
|
+
|
132
|
+
let(:issue_number) do
|
133
|
+
1
|
134
|
+
end
|
135
|
+
|
136
|
+
include_examples "requires access token without access token"
|
137
|
+
|
138
|
+
context "with closed issue" do
|
139
|
+
it "replies so" do
|
140
|
+
Ruboty.logger.should_receive(:info).with("Closed #{html_url}")
|
141
|
+
call
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
context "with access token" do
|
146
|
+
it "closes specified issue" do
|
147
|
+
call
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
|
152
|
+
describe "#remember" do
|
153
|
+
let(:body) do
|
154
|
+
"@ruboty remember my github token #{github_access_token}"
|
155
|
+
end
|
156
|
+
|
157
|
+
it "remembers sender's access token in its brain" do
|
158
|
+
Ruboty.logger.should_receive(:info).with("Remembered #{sender}'s github access token")
|
159
|
+
call
|
160
|
+
access_tokens[sender].should == github_access_token
|
161
|
+
end
|
162
|
+
end
|
163
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start
|
3
|
+
|
4
|
+
require "ruboty/github"
|
5
|
+
require "webmock/rspec"
|
6
|
+
|
7
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
end
|
metadata
ADDED
@@ -0,0 +1,178 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-github
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.9
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-05-31 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: activesupport
|
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: ruboty
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: octokit
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
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: '1.6'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
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: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 2.14.1
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 2.14.1
|
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: webmock
|
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:
|
126
|
+
email:
|
127
|
+
- r7kamura@gmail.com
|
128
|
+
executables: []
|
129
|
+
extensions: []
|
130
|
+
extra_rdoc_files: []
|
131
|
+
files:
|
132
|
+
- ".gitignore"
|
133
|
+
- CHANGELOG.md
|
134
|
+
- Gemfile
|
135
|
+
- LICENSE.txt
|
136
|
+
- README.md
|
137
|
+
- Rakefile
|
138
|
+
- images/screenshot.png
|
139
|
+
- lib/ruboty/github.rb
|
140
|
+
- lib/ruboty/github/actions/base.rb
|
141
|
+
- lib/ruboty/github/actions/close_issue.rb
|
142
|
+
- lib/ruboty/github/actions/create_issue.rb
|
143
|
+
- lib/ruboty/github/actions/create_pull_request.rb
|
144
|
+
- lib/ruboty/github/actions/merge_pull_request.rb
|
145
|
+
- lib/ruboty/github/actions/remember.rb
|
146
|
+
- lib/ruboty/github/version.rb
|
147
|
+
- lib/ruboty/handlers/github.rb
|
148
|
+
- ruboty-github.gemspec
|
149
|
+
- spec/ruboty/handlers/github_spec.rb
|
150
|
+
- spec/spec_helper.rb
|
151
|
+
homepage: https://github.com/r7kamura/ruboty-github
|
152
|
+
licenses:
|
153
|
+
- MIT
|
154
|
+
metadata: {}
|
155
|
+
post_install_message:
|
156
|
+
rdoc_options: []
|
157
|
+
require_paths:
|
158
|
+
- lib
|
159
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
160
|
+
requirements:
|
161
|
+
- - ">="
|
162
|
+
- !ruby/object:Gem::Version
|
163
|
+
version: '0'
|
164
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
165
|
+
requirements:
|
166
|
+
- - ">="
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0'
|
169
|
+
requirements: []
|
170
|
+
rubyforge_project:
|
171
|
+
rubygems_version: 2.2.2
|
172
|
+
signing_key:
|
173
|
+
specification_version: 4
|
174
|
+
summary: Manage GitHub via Ruboty.
|
175
|
+
test_files:
|
176
|
+
- spec/ruboty/handlers/github_spec.rb
|
177
|
+
- spec/spec_helper.rb
|
178
|
+
has_rdoc:
|