ruboty-github 0.2.1 → 0.4.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 093d1614cfcf90a313fddb5d1b9e8e23ccaf44bf
4
- data.tar.gz: 58bfb5159b11c65f62a9985b28e562dd5b374c90
2
+ SHA256:
3
+ metadata.gz: ca90484555edbcd0c7d115256daf80863bac1e3e1fc196654c7b4ffb6d5a0a01
4
+ data.tar.gz: 98414de76d55e9ffbd9463d3321663a2b205c312ba55c7865d5b56b4f67b513b
5
5
  SHA512:
6
- metadata.gz: 6402e655cb325d41478424554fb8f9a35884b1c2c0a4e8b97b2c5375a30766dce44ae4303b6db3138e77febafb5e0d84ee4e9d2832b6955cccdc0b931c4309fe
7
- data.tar.gz: f1d46447fd0bc857845d19a8e6f1ff618b0e96c5781d9bb5df72a3f2f887e9a2f99e1f7f38c5ce69ab325514faea0901f579a90822140217c3beaf2fda6f8828
6
+ metadata.gz: 45b57c5e82d2fdbb77e39cbf33411ea30159e213e9f87765c41f0f9626ef3c6b3d03eff33be86e537ab0fcb3fe8e271bce6cfb182f8222bd0972d7d342702146
7
+ data.tar.gz: 7dcc15dbaf50a4c93c6f44e5206bb76a1297c63df65499bc87255478d67fdbb57e48197916f73ef067fd7f3305cd17aa747b54da5aa69109e61f1307b2a29ce6
@@ -0,0 +1,23 @@
1
+ changelog:
2
+ categories:
3
+ - title: Added
4
+ labels:
5
+ - add
6
+ - title: Changed
7
+ labels:
8
+ - change
9
+ - title: Deprecated
10
+ labels:
11
+ - deprecate
12
+ - title: Fixed
13
+ labels:
14
+ - fix
15
+ - title: Removed
16
+ labels:
17
+ - remove
18
+ - title: Security
19
+ labels:
20
+ - security
21
+ - title: Others
22
+ labels:
23
+ - "*"
@@ -0,0 +1,37 @@
1
+ # This file is machine-generated by `gh actions-lock`.
2
+ # Do not edit by hand; run `gh actions-lock` to update.
3
+ # Docs: https://gh.io/actions-lockfile
4
+ version: 'v0.0.3'
5
+ workflows:
6
+ '.github/workflows/bump-request.yml':
7
+ - 'actions/checkout@v7.0.1'
8
+ - 'r7kamura/bump-request@v0.7.1'
9
+ - 'ruby/setup-ruby@v1.336.0'
10
+ '.github/workflows/ci.yml':
11
+ - 'actions/checkout@v7.0.1'
12
+ - 'ruby/setup-ruby@v1.336.0'
13
+ '.github/workflows/release.yml': []
14
+ dependencies:
15
+ 'actions/checkout@v7.0.1':
16
+ ref: 'v7.0.1'
17
+ commit: 'sha1-3d3c42e5aac5ba805825da76410c181273ba90b1'
18
+ owner_id: 44036562
19
+ repo_id: 197814629
20
+ 'actions/setup-node@v7.1.0':
21
+ ref: 'v7.1.0'
22
+ commit: 'sha1-949feb2413d6458794dcd2491c4babbbce0c15c1'
23
+ owner_id: 44036562
24
+ repo_id: 189476904
25
+ 'r7kamura/bump-request@v0.7.1':
26
+ ref: 'v0.7.1'
27
+ commit: 'sha1-b27937188d404bc0c2fd442403e6de1d20f9b349'
28
+ owner_id: 111689
29
+ repo_id: 533135195
30
+ uses:
31
+ - 'actions/checkout@v7.0.1'
32
+ - 'actions/setup-node@v7.1.0'
33
+ 'ruby/setup-ruby@v1.336.0':
34
+ ref: 'v1.336.0'
35
+ commit: 'sha1-de492cf36cbab201753d720ce4f4e336cd688c94'
36
+ owner_id: 210414
37
+ repo_id: 231208785
@@ -0,0 +1,26 @@
1
+ name: bump-request
2
+
3
+ on:
4
+ workflow_dispatch:
5
+ inputs:
6
+ version:
7
+ description: Version to change to.
8
+ required: true
9
+ type: string
10
+
11
+ jobs:
12
+ run:
13
+ runs-on: ubuntu-latest
14
+ steps:
15
+ - uses: actions/checkout@v7.0.1
16
+ - name: Set up Ruby
17
+ uses: ruby/setup-ruby@v1.336.0
18
+ with:
19
+ ruby-version: 3.3
20
+ bundler-cache: true
21
+ - uses: r7kamura/bump-request@v0.7.1
22
+ with:
23
+ command: |
24
+ sed -i -r 's/([0-9]+\.[0-9]+\.[0-9]+)/${{ inputs.version }}/' lib/ruboty/github/version.rb
25
+ bundle install
26
+ version: ${{ inputs.version }}
@@ -0,0 +1,26 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ build:
11
+ runs-on: ubuntu-latest
12
+ name: Ruby ${{ matrix.ruby }}
13
+ strategy:
14
+ fail-fast: false
15
+ matrix:
16
+ ruby:
17
+ - '3.3'
18
+ - '3.4'
19
+ - '4.0'
20
+ steps:
21
+ - uses: actions/checkout@v7.0.1
22
+ - uses: ruby/setup-ruby@v1.336.0
23
+ with:
24
+ ruby-version: ${{ matrix.ruby }}
25
+ bundler-cache: true
26
+ - run: bundle exec rspec
@@ -0,0 +1,11 @@
1
+ name: release
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+
8
+ jobs:
9
+ release:
10
+ uses: r7kamura/workflows/.github/workflows/gem-release.yml@main
11
+ if: github.repository_owner == 'r7kamura'
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
@@ -23,4 +24,4 @@ GITHUB_BASE_URL - Pass GitHub base URL if needed (e.g. https://github.example.co
23
24
  ```
24
25
 
25
26
  ## Image
26
- ![](https://raw.githubusercontent.com/r7kamura/ruboty-github/master/images/screenshot.png)
27
+ ![](https://raw.githubusercontent.com/r7kamura/ruboty-github/main/images/screenshot.png)
@@ -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.4.0"
4
4
  end
5
5
  end
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"
@@ -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
@@ -11,17 +11,23 @@ Gem::Specification.new do |spec|
11
11
  spec.homepage = "https://github.com/r7kamura/ruboty-github"
12
12
  spec.license = "MIT"
13
13
 
14
+ spec.metadata["homepage_uri"] = spec.homepage
15
+ spec.metadata["source_code_uri"] = spec.homepage
16
+ spec.metadata["changelog_uri"] = "#{spec.homepage}/releases"
17
+ spec.metadata["rubygems_mfa_required"] = "true"
18
+
14
19
  spec.files = `git ls-files -z`.split("\x0")
15
20
  spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
16
21
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
17
22
  spec.require_paths = ["lib"]
18
23
 
24
+ spec.required_ruby_version = ">= 3.3"
25
+
19
26
  spec.add_dependency "activesupport"
20
27
  spec.add_dependency "ruboty"
21
28
  spec.add_dependency "octokit"
22
- spec.add_development_dependency "bundler", "~> 1.6"
23
29
  spec.add_development_dependency "rake"
24
- spec.add_development_dependency "rspec", "2.14.1"
30
+ spec.add_development_dependency "rspec"
25
31
  spec.add_development_dependency "simplecov"
26
32
  spec.add_development_dependency "webmock"
27
33
  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
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,6 @@ require "ruboty/github"
5
5
  require "webmock/rspec"
6
6
 
7
7
  RSpec.configure do |config|
8
- config.treat_symbols_as_metadata_keys_with_true_values = true
9
8
  config.run_all_when_everything_filtered = true
10
9
  config.filter_run :focus
11
10
  end
metadata CHANGED
@@ -1,14 +1,13 @@
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.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryo Nakamura
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-11-13 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -52,20 +51,6 @@ dependencies:
52
51
  - - ">="
53
52
  - !ruby/object:Gem::Version
54
53
  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
54
  - !ruby/object:Gem::Dependency
70
55
  name: rake
71
56
  requirement: !ruby/object:Gem::Requirement
@@ -84,16 +69,16 @@ dependencies:
84
69
  name: rspec
85
70
  requirement: !ruby/object:Gem::Requirement
86
71
  requirements:
87
- - - '='
72
+ - - ">="
88
73
  - !ruby/object:Gem::Version
89
- version: 2.14.1
74
+ version: '0'
90
75
  type: :development
91
76
  prerelease: false
92
77
  version_requirements: !ruby/object:Gem::Requirement
93
78
  requirements:
94
- - - '='
79
+ - - ">="
95
80
  - !ruby/object:Gem::Version
96
- version: 2.14.1
81
+ version: '0'
97
82
  - !ruby/object:Gem::Dependency
98
83
  name: simplecov
99
84
  requirement: !ruby/object:Gem::Requirement
@@ -122,15 +107,18 @@ dependencies:
122
107
  - - ">="
123
108
  - !ruby/object:Gem::Version
124
109
  version: '0'
125
- description:
126
110
  email:
127
111
  - r7kamura@gmail.com
128
112
  executables: []
129
113
  extensions: []
130
114
  extra_rdoc_files: []
131
115
  files:
116
+ - ".github/release.yml"
117
+ - ".github/workflows/actions.lock"
118
+ - ".github/workflows/bump-request.yml"
119
+ - ".github/workflows/ci.yml"
120
+ - ".github/workflows/release.yml"
132
121
  - ".gitignore"
133
- - CHANGELOG.md
134
122
  - Gemfile
135
123
  - LICENSE.txt
136
124
  - README.md
@@ -139,6 +127,7 @@ files:
139
127
  - lib/ruboty/github.rb
140
128
  - lib/ruboty/github/actions/base.rb
141
129
  - lib/ruboty/github/actions/close_issue.rb
130
+ - lib/ruboty/github/actions/create_branch.rb
142
131
  - lib/ruboty/github/actions/create_issue.rb
143
132
  - lib/ruboty/github/actions/create_pull_request.rb
144
133
  - lib/ruboty/github/actions/merge_pull_request.rb
@@ -152,8 +141,11 @@ files:
152
141
  homepage: https://github.com/r7kamura/ruboty-github
153
142
  licenses:
154
143
  - MIT
155
- metadata: {}
156
- post_install_message:
144
+ metadata:
145
+ homepage_uri: https://github.com/r7kamura/ruboty-github
146
+ source_code_uri: https://github.com/r7kamura/ruboty-github
147
+ changelog_uri: https://github.com/r7kamura/ruboty-github/releases
148
+ rubygems_mfa_required: 'true'
157
149
  rdoc_options: []
158
150
  require_paths:
159
151
  - lib
@@ -161,19 +153,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
161
153
  requirements:
162
154
  - - ">="
163
155
  - !ruby/object:Gem::Version
164
- version: '0'
156
+ version: '3.3'
165
157
  required_rubygems_version: !ruby/object:Gem::Requirement
166
158
  requirements:
167
159
  - - ">="
168
160
  - !ruby/object:Gem::Version
169
161
  version: '0'
170
162
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.4.5
173
- signing_key:
163
+ rubygems_version: 4.0.20
174
164
  specification_version: 4
175
165
  summary: Manage GitHub via Ruboty.
176
166
  test_files:
177
167
  - spec/ruboty/handlers/github_spec.rb
178
168
  - spec/spec_helper.rb
179
- has_rdoc:
data/CHANGELOG.md DELETED
@@ -1,45 +0,0 @@
1
- ## 0.2.1
2
- - Add `search issues <query>` 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