ruboty-github 0.2.1 → 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/CHANGELOG.md +3 -0
- data/README.md +1 -0
- data/lib/ruboty/github.rb +1 -0
- data/lib/ruboty/github/actions/create_branch.rb +53 -0
- data/lib/ruboty/github/version.rb +1 -1
- data/lib/ruboty/handlers/github.rb +10 -0
- data/spec/ruboty/handlers/github_spec.rb +78 -3
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 6b529aabc96d23db82568cf953c9893ceb313f34
|
4
|
+
data.tar.gz: 51c0942be60ed3eb2abbb51bee21f87ded0ba34a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0512725c0cfe6fe77c76b46b2131efa22e4b603981fb410c1843d4b152e18505f574847c3421764b2506353d3e9158e7dd7bd953f85c39260157acb9486f3201
|
7
|
+
data.tar.gz: 760462d06ec9955905c03d63a13b0f28bdee3d7d13607e8ab925a9a3d287accd27744a942236cd52a710169dfb6d17d048ce67f7e2e72c2df9049feebbfdea2c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -10,6 +10,7 @@ gem "ruboty-github"
|
|
10
10
|
## Usage
|
11
11
|
```
|
12
12
|
@ruboty close <URL> - Close an Issue
|
13
|
+
@ruboty create branch <to_branch> from <from> - Create a new Branch
|
13
14
|
@ruboty create issue "<title>" on <repo>[\n<description>] - Create a new Issue
|
14
15
|
@ruboty search issues <query> - Search issues
|
15
16
|
@ruboty merge <URL> - Merge a Pull Request
|
data/lib/ruboty/github.rb
CHANGED
@@ -4,6 +4,7 @@ require "octokit"
|
|
4
4
|
require "ruboty"
|
5
5
|
require "ruboty/github/actions/base"
|
6
6
|
require "ruboty/github/actions/close_issue"
|
7
|
+
require "ruboty/github/actions/create_branch"
|
7
8
|
require "ruboty/github/actions/create_issue"
|
8
9
|
require "ruboty/github/actions/search_issues"
|
9
10
|
require "ruboty/github/actions/create_pull_request"
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module Github
|
3
|
+
module Actions
|
4
|
+
class CreateBranch < 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 #{create_branch._links.html}")
|
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 create_branch
|
26
|
+
sha = client.branch(from_repo, from_branch).commit.sha
|
27
|
+
client.create_ref(from_repo, "heads/#{to_branch}", sha)
|
28
|
+
client.branch(from_repo, to_branch)
|
29
|
+
end
|
30
|
+
|
31
|
+
# e.g. new-branch-name
|
32
|
+
def to_branch
|
33
|
+
message[:to_branch]
|
34
|
+
end
|
35
|
+
|
36
|
+
# e.g. alice/foo:test
|
37
|
+
def from
|
38
|
+
message[:from]
|
39
|
+
end
|
40
|
+
|
41
|
+
# e.g. alice/foo
|
42
|
+
def from_repo
|
43
|
+
from.split(":").first
|
44
|
+
end
|
45
|
+
|
46
|
+
# e.g. test
|
47
|
+
def from_branch
|
48
|
+
from.split(":").last
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -41,6 +41,12 @@ module Ruboty
|
|
41
41
|
description: "Search issues",
|
42
42
|
)
|
43
43
|
|
44
|
+
on(
|
45
|
+
/create branch (?<to_branch>.+) from (?<from>.+)\z/,
|
46
|
+
name: "create_branch",
|
47
|
+
description: "Create a branch",
|
48
|
+
)
|
49
|
+
|
44
50
|
def create_issue(message)
|
45
51
|
Ruboty::Github::Actions::CreateIssue.new(message).call
|
46
52
|
end
|
@@ -64,6 +70,10 @@ module Ruboty
|
|
64
70
|
def search_issues(message)
|
65
71
|
Ruboty::Github::Actions::SearchIssues.new(message).call
|
66
72
|
end
|
73
|
+
|
74
|
+
def create_branch(message)
|
75
|
+
Ruboty::Github::Actions::CreateBranch.new(message).call
|
76
|
+
end
|
67
77
|
end
|
68
78
|
end
|
69
79
|
end
|
@@ -49,7 +49,7 @@ describe Ruboty::Handlers::Github do
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "requires access token" do
|
52
|
-
Ruboty.
|
52
|
+
Ruboty::Message.any_instance.should_receive(:reply).with("I don't know your github access token")
|
53
53
|
call
|
54
54
|
a_request(:any, //).should_not have_been_made
|
55
55
|
end
|
@@ -137,7 +137,7 @@ describe Ruboty::Handlers::Github do
|
|
137
137
|
|
138
138
|
context "with closed issue" do
|
139
139
|
it "replies so" do
|
140
|
-
Ruboty.
|
140
|
+
Ruboty::Message.any_instance.should_receive(:reply).with("Closed #{html_url}")
|
141
141
|
call
|
142
142
|
end
|
143
143
|
end
|
@@ -155,9 +155,84 @@ describe Ruboty::Handlers::Github do
|
|
155
155
|
end
|
156
156
|
|
157
157
|
it "remembers sender's access token in its brain" do
|
158
|
-
Ruboty.
|
158
|
+
Ruboty::Message.any_instance.should_receive(:reply).with("Remembered #{sender}'s github access token")
|
159
159
|
call
|
160
160
|
access_tokens[sender].should == github_access_token
|
161
161
|
end
|
162
162
|
end
|
163
|
+
|
164
|
+
describe "#create_branch" do
|
165
|
+
let(:from_branch) do
|
166
|
+
"master"
|
167
|
+
end
|
168
|
+
|
169
|
+
let(:to_branch) do
|
170
|
+
"hotfix"
|
171
|
+
end
|
172
|
+
|
173
|
+
let(:sha) do
|
174
|
+
"8d265b39db79a2871427563ca51c28ca197ce0ff"
|
175
|
+
end
|
176
|
+
|
177
|
+
before do
|
178
|
+
stub_request(:get, "https://api.github.com/repos/#{user}/#{repository}/branches/#{from_branch}").
|
179
|
+
with(
|
180
|
+
headers: {
|
181
|
+
Authorization: "token #{github_access_token}"
|
182
|
+
},
|
183
|
+
).
|
184
|
+
to_return(
|
185
|
+
body: {
|
186
|
+
commit: {
|
187
|
+
sha: sha,
|
188
|
+
},
|
189
|
+
}.to_json,
|
190
|
+
headers: {
|
191
|
+
"Content-Type" => "application/json",
|
192
|
+
},
|
193
|
+
)
|
194
|
+
|
195
|
+
stub_request(:post, "https://api.github.com/repos/#{user}/#{repository}/git/refs").
|
196
|
+
with(
|
197
|
+
body: {
|
198
|
+
ref: "refs/heads/#{to_branch}",
|
199
|
+
sha: sha,
|
200
|
+
}.to_json,
|
201
|
+
headers: {
|
202
|
+
Authorization: "token #{github_access_token}"
|
203
|
+
},
|
204
|
+
)
|
205
|
+
|
206
|
+
stub_request(:get, "https://api.github.com/repos/#{user}/#{repository}/branches/#{to_branch}").
|
207
|
+
with(
|
208
|
+
headers: {
|
209
|
+
Authorization: "token #{github_access_token}"
|
210
|
+
},
|
211
|
+
).
|
212
|
+
to_return(
|
213
|
+
body: {
|
214
|
+
_links: {
|
215
|
+
html: "https://github.com/#{user}/#{repository}/tree/#{to_branch}",
|
216
|
+
},
|
217
|
+
}.to_json,
|
218
|
+
headers: {
|
219
|
+
"Content-Type" => "application/json",
|
220
|
+
}
|
221
|
+
)
|
222
|
+
end
|
223
|
+
|
224
|
+
let(:body) do
|
225
|
+
%<ruboty create branch #{to_branch} from #{user}/#{repository}:#{from_branch}>
|
226
|
+
end
|
227
|
+
|
228
|
+
include_examples "requires access token without access token"
|
229
|
+
|
230
|
+
context "with access token" do
|
231
|
+
it "creates a new branch" do
|
232
|
+
Ruboty::Message.any_instance.should_receive(:reply).with("Created https://github.com/#{user}/#{repository}/tree/#{to_branch}")
|
233
|
+
call
|
234
|
+
a_request(:any, //).should have_been_made.times(3)
|
235
|
+
end
|
236
|
+
end
|
237
|
+
end
|
163
238
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-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
|
- Ryo Nakamura
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-12-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -139,6 +139,7 @@ files:
|
|
139
139
|
- lib/ruboty/github.rb
|
140
140
|
- lib/ruboty/github/actions/base.rb
|
141
141
|
- lib/ruboty/github/actions/close_issue.rb
|
142
|
+
- lib/ruboty/github/actions/create_branch.rb
|
142
143
|
- lib/ruboty/github/actions/create_issue.rb
|
143
144
|
- lib/ruboty/github/actions/create_pull_request.rb
|
144
145
|
- lib/ruboty/github/actions/merge_pull_request.rb
|
@@ -169,11 +170,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
170
|
version: '0'
|
170
171
|
requirements: []
|
171
172
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.
|
173
|
+
rubygems_version: 2.6.11
|
173
174
|
signing_key:
|
174
175
|
specification_version: 4
|
175
176
|
summary: Manage GitHub via Ruboty.
|
176
177
|
test_files:
|
177
178
|
- spec/ruboty/handlers/github_spec.rb
|
178
179
|
- spec/spec_helper.rb
|
179
|
-
has_rdoc:
|