ellen-github 0.0.3 → 0.0.4
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 +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +4 -0
- data/images/screenshot.png +0 -0
- data/lib/ellen/github.rb +3 -0
- data/lib/ellen/github/actions/base.rb +20 -0
- data/lib/ellen/github/actions/close_issue.rb +52 -0
- data/lib/ellen/github/actions/create_issue.rb +0 -24
- data/lib/ellen/github/version.rb +1 -1
- data/lib/ellen/handlers/github.rb +20 -2
- data/spec/ellen/handlers/github_spec.rb +94 -30
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 840f7c706f1f5332b87c3e9e0ab87df61dab4a41
|
4
|
+
data.tar.gz: 5d9a376a02e562220123eec71a7f38c9179ed5de
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 23048c0c8fb1fcf8f3839aaf8e52d6be836dd1f05a4417af37e41ffaa49cc8a43ed69c1bbea4ef3f2d9f8c6fa6673674e71e438be7452758999a7ac9673aa13b
|
7
|
+
data.tar.gz: 9617bcf4c983e776b4fe17d7d1a457ae7268540ca4dcdafc5fd5f2d53fe4724587b6f021e37dc16a282917ec1b07564ac8e3fb5969590d308f4eade08fac2db5
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -9,6 +9,10 @@ gem "ellen-github"
|
|
9
9
|
|
10
10
|
## Usage
|
11
11
|
```
|
12
|
+
@ellen close issue <username>/<repository>#<number> - Close an Issue
|
12
13
|
@ellen create issue "<title>" on <username>/<repository> - Create a new Issue
|
13
14
|
@ellen remember my github token <token> - Remember sender's GitHub access token
|
14
15
|
```
|
16
|
+
|
17
|
+
## Image
|
18
|
+

|
Binary file
|
data/lib/ellen/github.rb
CHANGED
@@ -21,6 +21,26 @@ module Ellen
|
|
21
21
|
def sender_name
|
22
22
|
message.from
|
23
23
|
end
|
24
|
+
|
25
|
+
def require_access_token
|
26
|
+
message.reply("I don't know your github access token")
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_access_token?
|
30
|
+
!!access_token
|
31
|
+
end
|
32
|
+
|
33
|
+
def access_token
|
34
|
+
@access_token ||= access_tokens[sender_name]
|
35
|
+
end
|
36
|
+
|
37
|
+
def client
|
38
|
+
Octokit::Client.new(access_token: access_token)
|
39
|
+
end
|
40
|
+
|
41
|
+
def repository
|
42
|
+
message[:repo]
|
43
|
+
end
|
24
44
|
end
|
25
45
|
end
|
26
46
|
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
module Ellen
|
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
|
@@ -14,14 +14,6 @@ module Ellen
|
|
14
14
|
|
15
15
|
private
|
16
16
|
|
17
|
-
def require_access_token
|
18
|
-
message.reply("I don't know your github access token")
|
19
|
-
end
|
20
|
-
|
21
|
-
def created
|
22
|
-
message.reply("Created a new Issue")
|
23
|
-
end
|
24
|
-
|
25
17
|
def create
|
26
18
|
message.reply("Created #{issue.html_url}")
|
27
19
|
rescue Octokit::Unauthorized
|
@@ -36,22 +28,6 @@ module Ellen
|
|
36
28
|
client.create_issue(repository, title, body)
|
37
29
|
end
|
38
30
|
|
39
|
-
def has_access_token?
|
40
|
-
!!access_token
|
41
|
-
end
|
42
|
-
|
43
|
-
def access_token
|
44
|
-
@access_token ||= access_tokens[sender_name]
|
45
|
-
end
|
46
|
-
|
47
|
-
def client
|
48
|
-
Octokit::Client.new(access_token: access_token)
|
49
|
-
end
|
50
|
-
|
51
|
-
def repository
|
52
|
-
message[:repo]
|
53
|
-
end
|
54
|
-
|
55
31
|
def title
|
56
32
|
message[:title]
|
57
33
|
end
|
data/lib/ellen/github/version.rb
CHANGED
@@ -1,14 +1,32 @@
|
|
1
1
|
module Ellen
|
2
2
|
module Handlers
|
3
3
|
class Github < Base
|
4
|
-
on(
|
4
|
+
on(
|
5
|
+
/create issue "(?<title>.+)" on (?<repo>.+)\z/,
|
6
|
+
name: "create_issue",
|
7
|
+
description: "Create a new issue",
|
8
|
+
)
|
5
9
|
|
6
|
-
on(
|
10
|
+
on(
|
11
|
+
/remember my github token (?<token>.+)\z/,
|
12
|
+
name: "remember",
|
13
|
+
description: "Remember sender's GitHub access token",
|
14
|
+
)
|
15
|
+
|
16
|
+
on(
|
17
|
+
/close issue (?<repo>.+)#(?<number>\d+)\z/,
|
18
|
+
name: "close_issue",
|
19
|
+
description: "Close an issue",
|
20
|
+
)
|
7
21
|
|
8
22
|
def create_issue(message)
|
9
23
|
Ellen::Github::Actions::CreateIssue.new(message).call
|
10
24
|
end
|
11
25
|
|
26
|
+
def close_issue(message)
|
27
|
+
Ellen::Github::Actions::CloseIssue.new(message).call
|
28
|
+
end
|
29
|
+
|
12
30
|
def remember(message)
|
13
31
|
Ellen::Github::Actions::Remember.new(message).call
|
14
32
|
end
|
@@ -2,10 +2,18 @@ require "spec_helper"
|
|
2
2
|
require "json"
|
3
3
|
|
4
4
|
describe Ellen::Handlers::Github do
|
5
|
+
before do
|
6
|
+
access_tokens.merge!(sender => stored_access_token)
|
7
|
+
end
|
8
|
+
|
5
9
|
let(:robot) do
|
6
10
|
Ellen::Robot.new
|
7
11
|
end
|
8
12
|
|
13
|
+
let(:stored_access_token) do
|
14
|
+
github_access_token
|
15
|
+
end
|
16
|
+
|
9
17
|
let(:github_access_token) do
|
10
18
|
"dummy"
|
11
19
|
end
|
@@ -18,13 +26,38 @@ describe Ellen::Handlers::Github do
|
|
18
26
|
"#general"
|
19
27
|
end
|
20
28
|
|
29
|
+
let(:user) do
|
30
|
+
"alice"
|
31
|
+
end
|
32
|
+
|
33
|
+
let(:repository) do
|
34
|
+
"test"
|
35
|
+
end
|
36
|
+
|
21
37
|
let(:access_tokens) do
|
22
38
|
robot.brain.data[Ellen::Github::Actions::Base::NAMESPACE] ||= {}
|
23
39
|
end
|
24
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
|
+
Ellen.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
|
+
|
25
59
|
describe "#create_issue" do
|
26
60
|
before do
|
27
|
-
Ellen.logger.stub(:info)
|
28
61
|
stub_request(:post, "https://api.github.com/repos/#{user}/#{repository}/issues").
|
29
62
|
with(
|
30
63
|
body: {
|
@@ -38,14 +71,6 @@ describe Ellen::Handlers::Github do
|
|
38
71
|
)
|
39
72
|
end
|
40
73
|
|
41
|
-
let(:user) do
|
42
|
-
"alice"
|
43
|
-
end
|
44
|
-
|
45
|
-
let(:repository) do
|
46
|
-
"test"
|
47
|
-
end
|
48
|
-
|
49
74
|
let(:title) do
|
50
75
|
"This is a test issue"
|
51
76
|
end
|
@@ -54,29 +79,72 @@ describe Ellen::Handlers::Github do
|
|
54
79
|
%<ellen create issue "#{title}" on #{user}/#{repository}>
|
55
80
|
end
|
56
81
|
|
57
|
-
|
58
|
-
before do
|
59
|
-
access_tokens.merge!(sender => github_access_token)
|
60
|
-
end
|
82
|
+
include_examples "requires access token without access token"
|
61
83
|
|
84
|
+
context "with access token" do
|
62
85
|
it "creates a new issue with given title on given repository" do
|
63
|
-
|
64
|
-
body: body,
|
65
|
-
from: sender,
|
66
|
-
to: channel,
|
67
|
-
)
|
86
|
+
call
|
68
87
|
a_request(:any, //).should have_been_made
|
69
88
|
end
|
70
89
|
end
|
90
|
+
end
|
71
91
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
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
|
+
},
|
78
108
|
)
|
79
|
-
|
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
|
+
"@ellen 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
|
+
Ellen.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
|
80
148
|
end
|
81
149
|
end
|
82
150
|
end
|
@@ -88,11 +156,7 @@ describe Ellen::Handlers::Github do
|
|
88
156
|
|
89
157
|
it "remembers sender's access token in its brain" do
|
90
158
|
Ellen.logger.should_receive(:info).with("Remembered #{sender}'s github access token")
|
91
|
-
|
92
|
-
body: body,
|
93
|
-
from: sender,
|
94
|
-
to: channel,
|
95
|
-
)
|
159
|
+
call
|
96
160
|
access_tokens[sender].should == github_access_token
|
97
161
|
end
|
98
162
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ellen-github
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -122,8 +122,10 @@ files:
|
|
122
122
|
- README.md
|
123
123
|
- Rakefile
|
124
124
|
- ellen-github.gemspec
|
125
|
+
- images/screenshot.png
|
125
126
|
- lib/ellen/github.rb
|
126
127
|
- lib/ellen/github/actions/base.rb
|
128
|
+
- lib/ellen/github/actions/close_issue.rb
|
127
129
|
- lib/ellen/github/actions/create_issue.rb
|
128
130
|
- lib/ellen/github/actions/remember.rb
|
129
131
|
- lib/ellen/github/version.rb
|