ruboty-qiita-github 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/CHANGELOG.md +45 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +26 -0
- data/Rakefile +2 -0
- data/images/screenshot.png +0 -0
- data/lib/ruboty/github.rb +13 -0
- data/lib/ruboty/github/actions/base.rb +79 -0
- data/lib/ruboty/github/actions/close_issue.rb +52 -0
- data/lib/ruboty/github/actions/create_deploy_pull_request.rb +42 -0
- data/lib/ruboty/github/actions/create_issue.rb +35 -0
- data/lib/ruboty/github/actions/create_pull_request.rb +70 -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 +69 -0
- data/ruboty-github.gemspec +27 -0
- data/spec/ruboty/handlers/github_spec.rb +163 -0
- data/spec/spec_helper.rb +11 -0
- metadata +180 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 96c938e72fd549a149fdc0d61bff0821f57e7ded
|
4
|
+
data.tar.gz: 22b6c1482858da90504feeb718787d28768cb61b
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fab45c38d5b88dc86720e13046fb32819095e940c85cef3e498eba7617a5a6a18be4ce29dae5ba4b5ea3b9589b9f1c36025bdc1c54fe8b60ad9f16432fd7229b
|
7
|
+
data.tar.gz: c292600be3b67976d952baffb76c48f11e750981130b080122bea87edee0868c960ff50e5a92123634f467e2a0dc5a7f4db16145de0b8d8173dc56ea9025d90b
|
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,45 @@
|
|
1
|
+
## 0.2.1
|
2
|
+
- Add `deploy pull request` command
|
3
|
+
|
4
|
+
## 0.2.0
|
5
|
+
- Change ENV from GITHUB_HOST to GITHUB_BASE_URL
|
6
|
+
|
7
|
+
## 0.1.3
|
8
|
+
- Fix bug that would not respond to issue URL
|
9
|
+
|
10
|
+
## 0.1.2
|
11
|
+
- Allow merge & issue commands to take issue's URL
|
12
|
+
- `close issue <target>` -> `close[ issue] <target>`
|
13
|
+
|
14
|
+
## 0.1.1
|
15
|
+
- Pass empty string as issue body instead of nil
|
16
|
+
|
17
|
+
## 0.1.0
|
18
|
+
- Change command: merge pull request -> merge
|
19
|
+
|
20
|
+
## 0.0.9
|
21
|
+
- Rename: Ellen -> Ruboty
|
22
|
+
|
23
|
+
## 0.0.8
|
24
|
+
- Support Github Enterprise
|
25
|
+
|
26
|
+
## 0.0.7
|
27
|
+
- Use Ruboty::Message#from_name as user identifier
|
28
|
+
|
29
|
+
## 0.0.6
|
30
|
+
- Add Create & Merge Pull Request commands
|
31
|
+
|
32
|
+
## 0.0.5
|
33
|
+
- Description support
|
34
|
+
|
35
|
+
## 0.0.4
|
36
|
+
- Add close command
|
37
|
+
|
38
|
+
## 0.0.3
|
39
|
+
- Support Ruboty v0.2.0
|
40
|
+
|
41
|
+
## 0.0.2
|
42
|
+
- Memorize access token and use it to create a new issue
|
43
|
+
|
44
|
+
## 0.0.1
|
45
|
+
- 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,26 @@
|
|
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 <URL> - Close an Issue
|
13
|
+
@ruboty create issue "<title>" on <repo>[\n<description>] - Create a new Issue
|
14
|
+
@ruboty merge <URL> - Merge a Pull Request
|
15
|
+
@ruboty pull request "<title>" from <from> to <to> - Create a new Pull Request
|
16
|
+
@ruboty deploy pull request "<title>" from <from> to <to> - Create a new Pull Request for Deploy
|
17
|
+
@ruboty remember my github token <token> - Remember sender's GitHub access token
|
18
|
+
```
|
19
|
+
|
20
|
+
## ENV
|
21
|
+
```
|
22
|
+
GITHUB_BASE_URL - Pass GitHub base URL if needed (e.g. https://github.example.com)
|
23
|
+
```
|
24
|
+
|
25
|
+
## Image
|
26
|
+

|
data/Rakefile
ADDED
Binary file
|
@@ -0,0 +1,13 @@
|
|
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/create_deploy_pull_request"
|
10
|
+
require "ruboty/github/actions/merge_pull_request"
|
11
|
+
require "ruboty/github/actions/remember"
|
12
|
+
require "ruboty/github/version"
|
13
|
+
require "ruboty/handlers/github"
|
@@ -0,0 +1,79 @@
|
|
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 body
|
20
|
+
message[:description] || ""
|
21
|
+
end
|
22
|
+
|
23
|
+
def sender_name
|
24
|
+
message.from_name
|
25
|
+
end
|
26
|
+
|
27
|
+
def require_access_token
|
28
|
+
message.reply("I don't know your github access token")
|
29
|
+
end
|
30
|
+
|
31
|
+
def has_access_token?
|
32
|
+
!!access_token
|
33
|
+
end
|
34
|
+
|
35
|
+
def access_token
|
36
|
+
@access_token ||= access_tokens[sender_name]
|
37
|
+
end
|
38
|
+
|
39
|
+
def client
|
40
|
+
Octokit::Client.new(client_options)
|
41
|
+
end
|
42
|
+
|
43
|
+
def repository
|
44
|
+
message[:repo]
|
45
|
+
end
|
46
|
+
|
47
|
+
def client_options
|
48
|
+
client_options_with_nil_value.reject {|key, value| value.nil? }
|
49
|
+
end
|
50
|
+
|
51
|
+
def client_options_with_nil_value
|
52
|
+
{
|
53
|
+
access_token: access_token,
|
54
|
+
api_endpoint: api_endpoint,
|
55
|
+
web_endpoint: web_endpoint,
|
56
|
+
}
|
57
|
+
end
|
58
|
+
|
59
|
+
def web_endpoint
|
60
|
+
"#{github_base_url}/" if github_base_url
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_endpoint
|
64
|
+
"#{github_base_url}/api/v3" if github_base_url
|
65
|
+
end
|
66
|
+
|
67
|
+
# @note GITHUB_HOST will be deprecated on the next major version
|
68
|
+
def github_base_url
|
69
|
+
case
|
70
|
+
when ENV["GITHUB_BASE_URL"]
|
71
|
+
ENV["GITHUB_BASE_URL"]
|
72
|
+
when ENV["GITHUB_HOST"]
|
73
|
+
"https://#{ENV['GITHUB_HOST']}"
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
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,42 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class CreateDeployPullRequest < CreatePullRequest
|
5
|
+
private
|
6
|
+
|
7
|
+
# e.g. master
|
8
|
+
def to_branch
|
9
|
+
to.split(":").last
|
10
|
+
end
|
11
|
+
|
12
|
+
def body
|
13
|
+
body = "## Pull Request to deloy\n\n"
|
14
|
+
pull_requests_to_deploy(repository, to_branch, from_branch).each do |pr|
|
15
|
+
body = body + [
|
16
|
+
"-",
|
17
|
+
"[##{pr[:number]}](#{pr[:html_url]}):",
|
18
|
+
pr[:title],
|
19
|
+
"by",
|
20
|
+
"@#{pr[:head][:user][:login]}\n",
|
21
|
+
].join(' ')
|
22
|
+
end
|
23
|
+
body
|
24
|
+
end
|
25
|
+
|
26
|
+
def pull_requests_to_deploy(repository, to_branch, from_branch)
|
27
|
+
numbers = compare(repository, to_branch, from_branch).commits.map do |commit|
|
28
|
+
/^Merge pull request #(\d+) from/ =~ commit[:commit][:message]
|
29
|
+
$1
|
30
|
+
end
|
31
|
+
numbers.compact.map { |n| client.pull_request(repository, n.to_i) }
|
32
|
+
end
|
33
|
+
|
34
|
+
def compare(repository, to_branch, from_branch)
|
35
|
+
start = client.branch(repository, to_branch)[:commit][:sha]
|
36
|
+
endd = client.branch(repository, from_branch)[:commit][:sha]
|
37
|
+
client.compare(repository, start, endd)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
@@ -0,0 +1,35 @@
|
|
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
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,70 @@
|
|
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, body)
|
27
|
+
end
|
28
|
+
|
29
|
+
def title
|
30
|
+
message[:title]
|
31
|
+
end
|
32
|
+
|
33
|
+
# e.g. alice/foo:test
|
34
|
+
def from
|
35
|
+
message[:from]
|
36
|
+
end
|
37
|
+
|
38
|
+
# e.g. alice
|
39
|
+
def from_user
|
40
|
+
from.split("/").first
|
41
|
+
end
|
42
|
+
|
43
|
+
# e.g. test
|
44
|
+
def from_branch
|
45
|
+
from.split(":").last
|
46
|
+
end
|
47
|
+
|
48
|
+
# e.g. bob/foo:master
|
49
|
+
def to
|
50
|
+
message[:to]
|
51
|
+
end
|
52
|
+
|
53
|
+
# e.g. bob/foo
|
54
|
+
def repository
|
55
|
+
to.split(":").first
|
56
|
+
end
|
57
|
+
|
58
|
+
# e.g. alice:test
|
59
|
+
def head
|
60
|
+
"#{from_user}:#{from_branch}"
|
61
|
+
end
|
62
|
+
|
63
|
+
# e.g. master
|
64
|
+
def base
|
65
|
+
to.split(":").last
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
70
|
+
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,69 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Handlers
|
3
|
+
class Github < Base
|
4
|
+
ISSUE_PATTERN = %r<(?:https?://[^/]+/)?(?<repo>.+)(?:#|/pull/|/issues/)(?<number>\d+) ?>
|
5
|
+
|
6
|
+
env :GITHUB_BASE_URL, "Pass GitHub URL if needed (e.g. https://github.example.com)", optional: true
|
7
|
+
|
8
|
+
on(
|
9
|
+
/create issue "(?<title>.+)" on (?<repo>.+)(?:\n(?<description>[\s\S]+))?\z/,
|
10
|
+
name: "create_issue",
|
11
|
+
description: "Create a new issue",
|
12
|
+
)
|
13
|
+
|
14
|
+
on(
|
15
|
+
/remember my github token (?<token>.+)\z/,
|
16
|
+
name: "remember",
|
17
|
+
description: "Remember sender's GitHub access token",
|
18
|
+
)
|
19
|
+
|
20
|
+
on(
|
21
|
+
/close(?: issue)? #{ISSUE_PATTERN}\z/,
|
22
|
+
name: "close_issue",
|
23
|
+
description: "Close an issue",
|
24
|
+
)
|
25
|
+
|
26
|
+
on(
|
27
|
+
/pull request "(?<title>.+)" from (?<from>.+) to (?<to>.+)(?:\n(?<description>[\s\S]+))?\z/,
|
28
|
+
name: "create_pull_request",
|
29
|
+
description: "Create a pull request",
|
30
|
+
)
|
31
|
+
|
32
|
+
on(
|
33
|
+
/deploy pull request "(?<title>.+)" from (?<from>.+) to (?<to>.+)(?:\n(?<description>[\s\S]+))?\z/,
|
34
|
+
name: "create_deploy_pull_request",
|
35
|
+
description: "Create a pull request to deploy",
|
36
|
+
)
|
37
|
+
|
38
|
+
on(
|
39
|
+
/merge #{ISSUE_PATTERN}\z/,
|
40
|
+
name: "merge_pull_request",
|
41
|
+
description: "Merge pull request",
|
42
|
+
)
|
43
|
+
|
44
|
+
def create_issue(message)
|
45
|
+
Ruboty::Github::Actions::CreateIssue.new(message).call
|
46
|
+
end
|
47
|
+
|
48
|
+
def close_issue(message)
|
49
|
+
Ruboty::Github::Actions::CloseIssue.new(message).call
|
50
|
+
end
|
51
|
+
|
52
|
+
def remember(message)
|
53
|
+
Ruboty::Github::Actions::Remember.new(message).call
|
54
|
+
end
|
55
|
+
|
56
|
+
def create_pull_request(message)
|
57
|
+
Ruboty::Github::Actions::CreatePullRequest.new(message).call
|
58
|
+
end
|
59
|
+
|
60
|
+
def create_deploy_pull_request(message)
|
61
|
+
Ruboty::Github::Actions::CreateDeployPullRequest.new(message).call
|
62
|
+
end
|
63
|
+
|
64
|
+
def merge_pull_request(message)
|
65
|
+
Ruboty::Github::Actions::MergePullRequest.new(message).call
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
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-qiita-github"
|
7
|
+
spec.version = Ruboty::Github::VERSION
|
8
|
+
spec.authors = ["Ryo Nakamura", "Seigo Uchida"]
|
9
|
+
spec.email = ["r7kamura@gmail.com", "spesnova@gmail.com"]
|
10
|
+
spec.summary = "Manage GitHub via Ruboty."
|
11
|
+
spec.homepage = "https://github.com/increments/ruboty-qiita-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://api.github.com/repos/#{user}/#{repository}/issues").
|
62
|
+
with(
|
63
|
+
body: {
|
64
|
+
labels: [],
|
65
|
+
title: title,
|
66
|
+
body: "",
|
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://api.github.com/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://api.github.com/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,180 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-qiita-github
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Ryo Nakamura
|
8
|
+
- Seigo Uchida
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2015-10-28 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activesupport
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - ">="
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: '0'
|
21
|
+
type: :runtime
|
22
|
+
prerelease: false
|
23
|
+
version_requirements: !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
version: '0'
|
28
|
+
- !ruby/object:Gem::Dependency
|
29
|
+
name: ruboty
|
30
|
+
requirement: !ruby/object:Gem::Requirement
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: '0'
|
35
|
+
type: :runtime
|
36
|
+
prerelease: false
|
37
|
+
version_requirements: !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
version: '0'
|
42
|
+
- !ruby/object:Gem::Dependency
|
43
|
+
name: octokit
|
44
|
+
requirement: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
type: :runtime
|
50
|
+
prerelease: false
|
51
|
+
version_requirements: !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: '0'
|
56
|
+
- !ruby/object:Gem::Dependency
|
57
|
+
name: bundler
|
58
|
+
requirement: !ruby/object:Gem::Requirement
|
59
|
+
requirements:
|
60
|
+
- - "~>"
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '1.6'
|
63
|
+
type: :development
|
64
|
+
prerelease: false
|
65
|
+
version_requirements: !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "~>"
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: '1.6'
|
70
|
+
- !ruby/object:Gem::Dependency
|
71
|
+
name: rake
|
72
|
+
requirement: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
type: :development
|
78
|
+
prerelease: false
|
79
|
+
version_requirements: !ruby/object:Gem::Requirement
|
80
|
+
requirements:
|
81
|
+
- - ">="
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
- !ruby/object:Gem::Dependency
|
85
|
+
name: rspec
|
86
|
+
requirement: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - '='
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: 2.14.1
|
91
|
+
type: :development
|
92
|
+
prerelease: false
|
93
|
+
version_requirements: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - '='
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: 2.14.1
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: simplecov
|
100
|
+
requirement: !ruby/object:Gem::Requirement
|
101
|
+
requirements:
|
102
|
+
- - ">="
|
103
|
+
- !ruby/object:Gem::Version
|
104
|
+
version: '0'
|
105
|
+
type: :development
|
106
|
+
prerelease: false
|
107
|
+
version_requirements: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
- !ruby/object:Gem::Dependency
|
113
|
+
name: webmock
|
114
|
+
requirement: !ruby/object:Gem::Requirement
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: '0'
|
119
|
+
type: :development
|
120
|
+
prerelease: false
|
121
|
+
version_requirements: !ruby/object:Gem::Requirement
|
122
|
+
requirements:
|
123
|
+
- - ">="
|
124
|
+
- !ruby/object:Gem::Version
|
125
|
+
version: '0'
|
126
|
+
description:
|
127
|
+
email:
|
128
|
+
- r7kamura@gmail.com
|
129
|
+
- spesnova@gmail.com
|
130
|
+
executables: []
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- ".gitignore"
|
135
|
+
- CHANGELOG.md
|
136
|
+
- Gemfile
|
137
|
+
- LICENSE.txt
|
138
|
+
- README.md
|
139
|
+
- Rakefile
|
140
|
+
- images/screenshot.png
|
141
|
+
- lib/ruboty/github.rb
|
142
|
+
- lib/ruboty/github/actions/base.rb
|
143
|
+
- lib/ruboty/github/actions/close_issue.rb
|
144
|
+
- lib/ruboty/github/actions/create_deploy_pull_request.rb
|
145
|
+
- lib/ruboty/github/actions/create_issue.rb
|
146
|
+
- lib/ruboty/github/actions/create_pull_request.rb
|
147
|
+
- lib/ruboty/github/actions/merge_pull_request.rb
|
148
|
+
- lib/ruboty/github/actions/remember.rb
|
149
|
+
- lib/ruboty/github/version.rb
|
150
|
+
- lib/ruboty/handlers/github.rb
|
151
|
+
- ruboty-github.gemspec
|
152
|
+
- spec/ruboty/handlers/github_spec.rb
|
153
|
+
- spec/spec_helper.rb
|
154
|
+
homepage: https://github.com/increments/ruboty-qiita-github
|
155
|
+
licenses:
|
156
|
+
- MIT
|
157
|
+
metadata: {}
|
158
|
+
post_install_message:
|
159
|
+
rdoc_options: []
|
160
|
+
require_paths:
|
161
|
+
- lib
|
162
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
167
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
168
|
+
requirements:
|
169
|
+
- - ">="
|
170
|
+
- !ruby/object:Gem::Version
|
171
|
+
version: '0'
|
172
|
+
requirements: []
|
173
|
+
rubyforge_project:
|
174
|
+
rubygems_version: 2.4.5.1
|
175
|
+
signing_key:
|
176
|
+
specification_version: 4
|
177
|
+
summary: Manage GitHub via Ruboty.
|
178
|
+
test_files:
|
179
|
+
- spec/ruboty/handlers/github_spec.rb
|
180
|
+
- spec/spec_helper.rb
|