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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 093d1614cfcf90a313fddb5d1b9e8e23ccaf44bf
4
- data.tar.gz: 58bfb5159b11c65f62a9985b28e562dd5b374c90
3
+ metadata.gz: 6b529aabc96d23db82568cf953c9893ceb313f34
4
+ data.tar.gz: 51c0942be60ed3eb2abbb51bee21f87ded0ba34a
5
5
  SHA512:
6
- metadata.gz: 6402e655cb325d41478424554fb8f9a35884b1c2c0a4e8b97b2c5375a30766dce44ae4303b6db3138e77febafb5e0d84ee4e9d2832b6955cccdc0b931c4309fe
7
- data.tar.gz: f1d46447fd0bc857845d19a8e6f1ff618b0e96c5781d9bb5df72a3f2f887e9a2f99e1f7f38c5ce69ab325514faea0901f579a90822140217c3beaf2fda6f8828
6
+ metadata.gz: 0512725c0cfe6fe77c76b46b2131efa22e4b603981fb410c1843d4b152e18505f574847c3421764b2506353d3e9158e7dd7bd953f85c39260157acb9486f3201
7
+ data.tar.gz: 760462d06ec9955905c03d63a13b0f28bdee3d7d13607e8ab925a9a3d287accd27744a942236cd52a710169dfb6d17d048ce67f7e2e72c2df9049feebbfdea2c
@@ -1,3 +1,6 @@
1
+ ## 0.3.0
2
+ - Add `create branch <to_branch> from <from>` command
3
+
1
4
  ## 0.2.1
2
5
  - Add `search issues <query>` command
3
6
 
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  module Ruboty
2
2
  module Github
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  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.logger.should_receive(:info).with("I don't know your github access token")
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.logger.should_receive(:info).with("Closed #{html_url}")
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.logger.should_receive(:info).with("Remembered #{sender}'s github access token")
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.2.1
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: 2015-11-13 00:00:00.000000000 Z
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.4.5
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: