-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathkonomin-bot.rb
66 lines (54 loc) · 1.79 KB
/
konomin-bot.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
require 'octokit'
require 'git'
class KonominBotExecutor
TARGET_REPOSITORY = 'mlborder/mlborder.com'
TARGET_DIR = 'mlborder'
GIT_USER_NAME = 'konomin-bot'
GIT_USER_EMAIL = '[email protected]'
def execute
git_agent = if Dir.exists?(TARGET_DIR)
Git.open(TARGET_DIR).tap do |g|
g.checkout('master')
g.pull
end
else
Git.clone("[email protected]:#{TARGET_REPOSITORY}.git", '', path: TARGET_DIR)
end
git_agent.tap do |g|
g.config('user.name', GIT_USER_NAME)
g.config('user.email', GIT_USER_EMAIL)
g.branch(branch_name).checkout
end
`heroku run --app mlborder rails runner 'ActiveRecord::Base.logger = nil; puts Event.dump_seeds' | nkf -Lu > #{TARGET_DIR}/db/seeds.rb`
git_agent.tap do |g|
g.add
g.commit("Update db/seeds.rb #{time_stamp}")
g.push('origin', branch_name)
end
github_agent.create_pull_request TARGET_REPOSITORY, 'master', branch_name, *message_from_konomin
end
def message_from_konomin
["Seed update #{time_stamp}",
"お疲れ様、プロデューサー\n" + message_body]
end
def message_body
['疲れてる子がいないかちゃんと見ててよ?',
'みんな、合言葉はセクシーよ!',
'最後はなんとかしてあげるから、思い切って頑張りなさーい♪'
].sample(1).first
end
def github_agent
unless @cli
@cli = Octokit::Client.new(login: ENV['KONOMIN_USERNAME'], password: ENV['KONOMIN_PASSWORD'])
@cli.login
end
@cli
end
def branch_name
@branch_name ||= "update-seed-#{time_stamp}"
end
def time_stamp
@time_stamp ||= Time.now.strftime('%Y%m%d-%H%M')
end
end
KonominBotExecutor.new.execute