ruboty-bundler 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/lib/ruboty/bundler/version.rb +1 -1
- data/lib/ruboty/handlers/bundler.rb +105 -65
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b6a1d555d04a3c52fea096e09f7e26910e5029fd
|
4
|
+
data.tar.gz: 1c8f0a0c0e714c5c6695208531597eef69ec0a38
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00d94a9f9eb8b6ba333104bb3fc570678f0df880039c5daa990f8914398745fee27b63a5209f87d96d7b18a0e8d7cdb1840c7556bb8e83f626f35051f342f5e7
|
7
|
+
data.tar.gz: 232d481002d5d4a04720881eeee223c19e9b4d9d78af2446726f7a7057fe1897160d8aefee92fb3b7853ae8be58e360f63ad17aa2f0152d13574bc243c5accce
|
data/CHANGELOG.md
ADDED
@@ -7,8 +7,6 @@ require "tmpdir"
|
|
7
7
|
module Ruboty
|
8
8
|
module Handlers
|
9
9
|
class Bundler < Base
|
10
|
-
DEFAULT_GIT_REPOSITORY_PATH = "/tmp/app"
|
11
|
-
DEFAULT_GITHUB_HOST = "github.com"
|
12
10
|
NAMESPACE = Ruboty::Github::Actions::Base::NAMESPACE
|
13
11
|
|
14
12
|
env :RUBOTY_BUNDLER_REPOSITORY, "Target repository name (e.g. r7kamura/kokodeikku_bot)"
|
@@ -28,30 +26,15 @@ module Ruboty
|
|
28
26
|
def add(message)
|
29
27
|
if client = client_for(message.from_name)
|
30
28
|
message.reply("Bundler started")
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
29
|
+
gems = Gems.new(
|
30
|
+
gemfile_content: Base64.decode64(client.get("Gemfile")[:content]),
|
31
|
+
gemfile_lock_content: Base64.decode64(client.get("Gemfile.lock")[:content]),
|
32
|
+
)
|
35
33
|
gems.add(message[:gem_name], version: message[:version])
|
36
|
-
gemfile_content = gems.to_s
|
37
|
-
gemfile_sha = response[:sha]
|
34
|
+
gemfile_content = GemfileView.new(gems).to_s
|
38
35
|
gemfile_lock_content = Install.new(gemfile_content).call
|
39
|
-
|
40
|
-
|
41
|
-
client.update_contents(
|
42
|
-
repository,
|
43
|
-
"Gemfile",
|
44
|
-
commit_message,
|
45
|
-
gemfile_sha,
|
46
|
-
gemfile_content,
|
47
|
-
)
|
48
|
-
client.update_contents(
|
49
|
-
repository,
|
50
|
-
"Gemfile.lock",
|
51
|
-
commit_message,
|
52
|
-
gemfile_lock_sha,
|
53
|
-
gemfile_lock_content,
|
54
|
-
)
|
36
|
+
client.update("Gemfile", gemfile_content)
|
37
|
+
client.update("Gemfile.lock", gemfile_lock_content)
|
55
38
|
message.reply("Bundler finished")
|
56
39
|
else
|
57
40
|
message.reply("I don't know your GitHub access token")
|
@@ -60,12 +43,26 @@ module Ruboty
|
|
60
43
|
message.reply("Failed to add gem")
|
61
44
|
end
|
62
45
|
|
63
|
-
# TODO
|
64
46
|
def delete(message)
|
65
47
|
if client = client_for(message.from_name)
|
48
|
+
message.reply("Bundler started")
|
49
|
+
gems = Gems.new(
|
50
|
+
gemfile_content: Base64.decode64(client.get("Gemfile")[:content]),
|
51
|
+
gemfile_lock_content: Base64.decode64(client.get("Gemfile.lock")[:content]),
|
52
|
+
)
|
53
|
+
gems.delete(message[:gem_name])
|
54
|
+
gemfile_content = GemfileView.new(gems).to_s
|
55
|
+
gemfile_lock_content = Install.new(gemfile_content).call
|
56
|
+
client.update("Gemfile", gemfile_content)
|
57
|
+
client.update("Gemfile.lock", gemfile_lock_content)
|
58
|
+
message.reply("Bundler finished")
|
66
59
|
else
|
67
60
|
message.reply("I don't know your GitHub access token")
|
68
61
|
end
|
62
|
+
rescue GemNotFound
|
63
|
+
message.reply("Gem not found")
|
64
|
+
rescue Errno::ENOENT
|
65
|
+
message.reply("Failed to delete gem")
|
69
66
|
end
|
70
67
|
|
71
68
|
private
|
@@ -75,17 +72,57 @@ module Ruboty
|
|
75
72
|
robot.brain.data[NAMESPACE] ||= {}
|
76
73
|
end
|
77
74
|
|
78
|
-
def api_endpoint
|
79
|
-
"https://#{github_host}/api/v3" if github_host
|
80
|
-
end
|
81
|
-
|
82
75
|
# @param username [String, nil]
|
83
|
-
# @return [
|
76
|
+
# @return [Ruboty::Bundler::Client, nil]
|
84
77
|
def client_for(username)
|
85
78
|
if access_token = access_tokens_table[username]
|
86
|
-
|
79
|
+
Client.new(access_token: access_token)
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
class Client
|
84
|
+
DEFAULT_GITHUB_HOST = "github.com"
|
85
|
+
|
86
|
+
def initialize(access_token: nil)
|
87
|
+
@access_token = access_token
|
88
|
+
end
|
89
|
+
|
90
|
+
# @param path [String] File path (e.g. "Gemfile")
|
91
|
+
# @return [String] File content
|
92
|
+
def get(path)
|
93
|
+
cache[path] ||= octokit_client.contents(repository, path: path)
|
94
|
+
end
|
95
|
+
|
96
|
+
# @param path [String] File path (e.g. "Gemfile")
|
97
|
+
# @param content [String] File content
|
98
|
+
def update(path, content)
|
99
|
+
octokit_client.update_contents(
|
100
|
+
repository,
|
101
|
+
path,
|
102
|
+
"Update #{path}",
|
103
|
+
get(path)[:sha],
|
104
|
+
content,
|
105
|
+
)
|
106
|
+
end
|
107
|
+
|
108
|
+
private
|
109
|
+
|
110
|
+
def api_endpoint
|
111
|
+
"https://#{github_host}/api/v3" if github_host
|
112
|
+
end
|
113
|
+
|
114
|
+
def cache
|
115
|
+
@cache ||= {}
|
116
|
+
end
|
117
|
+
|
118
|
+
def github_host
|
119
|
+
ENV["GITHUB_HOST"]
|
120
|
+
end
|
121
|
+
|
122
|
+
def octokit_client
|
123
|
+
@octokit_client ||= Octokit::Client.new(
|
87
124
|
{
|
88
|
-
access_token: access_token,
|
125
|
+
access_token: @access_token,
|
89
126
|
api_endpoint: api_endpoint,
|
90
127
|
web_endpoint: web_endpoint,
|
91
128
|
}.reject do |key, value|
|
@@ -93,26 +130,14 @@ module Ruboty
|
|
93
130
|
end
|
94
131
|
)
|
95
132
|
end
|
96
|
-
end
|
97
133
|
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
def git_repository_url
|
103
|
-
web_endpoint + ENV["RUBOTY_BUNDLER_REPOSITORY"]
|
104
|
-
end
|
105
|
-
|
106
|
-
def github_host
|
107
|
-
ENV["GITHUB_HOST"]
|
108
|
-
end
|
109
|
-
|
110
|
-
def repository
|
111
|
-
ENV["RUBOTY_BUNDLER_REPOSITORY"]
|
112
|
-
end
|
134
|
+
def repository
|
135
|
+
ENV["RUBOTY_BUNDLER_REPOSITORY"]
|
136
|
+
end
|
113
137
|
|
114
|
-
|
115
|
-
|
138
|
+
def web_endpoint
|
139
|
+
"https://#{github_host || DEFAULT_GITHUB_HOST}/"
|
140
|
+
end
|
116
141
|
end
|
117
142
|
|
118
143
|
class DependencyView
|
@@ -141,12 +166,28 @@ module Ruboty
|
|
141
166
|
end
|
142
167
|
end
|
143
168
|
|
169
|
+
class GemfileView
|
170
|
+
def initialize(gems)
|
171
|
+
@gems = gems
|
172
|
+
end
|
173
|
+
|
174
|
+
def to_s
|
175
|
+
%<source "https://rubygems.org"\n\n> +
|
176
|
+
@gems.dependencies.map do |dependency|
|
177
|
+
DependencyView.new(dependency).to_s
|
178
|
+
end.join("\n")
|
179
|
+
end
|
180
|
+
end
|
181
|
+
|
182
|
+
class GemNotFound < StandardError
|
183
|
+
end
|
184
|
+
|
144
185
|
class Gems
|
145
|
-
# @param
|
146
|
-
# @param
|
147
|
-
def initialize(
|
148
|
-
@
|
149
|
-
@
|
186
|
+
# @param gemfile_content [String]
|
187
|
+
# @param gemfile_lcok_content [String]
|
188
|
+
def initialize(gemfile_content: nil, gemfile_lock_content: nil)
|
189
|
+
@gemfile_content = gemfile_content
|
190
|
+
@gemfile_lock_content = gemfile_lock_content
|
150
191
|
end
|
151
192
|
|
152
193
|
def add(gem_name, version: nil)
|
@@ -156,16 +197,13 @@ module Ruboty
|
|
156
197
|
dependencies << ::Bundler::Dependency.new(gem_name, version || ">= 0")
|
157
198
|
end
|
158
199
|
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
end.join("\n")
|
200
|
+
def delete(gem_name)
|
201
|
+
raise GemNotFound if dependencies.all? {|dependency| dependency.name != gem_name }
|
202
|
+
dependencies.reject! do |dependency|
|
203
|
+
dependency.name == gem_name
|
204
|
+
end
|
165
205
|
end
|
166
206
|
|
167
|
-
private
|
168
|
-
|
169
207
|
def dependencies
|
170
208
|
@dependencies ||= ::Bundler::Dsl.evaluate(
|
171
209
|
gemfile_file.path,
|
@@ -174,16 +212,18 @@ module Ruboty
|
|
174
212
|
).dependencies
|
175
213
|
end
|
176
214
|
|
215
|
+
private
|
216
|
+
|
177
217
|
def gemfile_file
|
178
218
|
@gemfile_file ||= Tempfile.new("Gemfile").tap do |file|
|
179
|
-
file.write(@
|
219
|
+
file.write(@gemfile_content)
|
180
220
|
file.flush
|
181
221
|
end
|
182
222
|
end
|
183
223
|
|
184
224
|
def gemfile_lock_file
|
185
225
|
@gemfile_lock_file ||= Tempfile.new("Gemfile.lock").tap do |file|
|
186
|
-
file.write(@
|
226
|
+
file.write(@gemfile_lock_content)
|
187
227
|
file.flush
|
188
228
|
end
|
189
229
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruboty-bundler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryo Nakamura
|
@@ -74,6 +74,7 @@ extensions: []
|
|
74
74
|
extra_rdoc_files: []
|
75
75
|
files:
|
76
76
|
- ".gitignore"
|
77
|
+
- CHANGELOG.md
|
77
78
|
- Gemfile
|
78
79
|
- LICENSE.txt
|
79
80
|
- README.md
|