Skip to content

Instantly share code, notes, and snippets.

@vexus2
Last active August 29, 2015 13:56
Show Gist options
  • Save vexus2/8910905 to your computer and use it in GitHub Desktop.
Save vexus2/8910905 to your computer and use it in GitHub Desktop.
特定リポジトリにたまっているPull Request数をChatWorkに通知
#!/usr/bin/env ruby
#-*- encoding: utf-8 -*-
require 'json'
require 'pit'
require 'time'
require 'net/https'
require 'octokit'
## get config from pit
Config = Pit.get('restore_config',
:require => {
'api' => {
'chatwork_api_key' => 'chatwork_api_key',
'chatwork_room_id' => 'chatwork_room_id',
'github_token' => 'api_token',
'github_repository' => ':name/:repos',
},
})
client = Octokit::Client.new :access_token => Config['api']['github_token']
pull_requests = client.pull_requests(Config['api']['github_repository'])
exit if pull_requests.count == 0
body = "おはようございます★今日は#{pull_requests.count}件のPull Requestがあります!\n\n"
pull_requests.each do |pull_request|
title = pull_request.title
url = pull_request._links.html.href
body << "- #{title}\n #{url}\n\n"
end
body << "今日も一日がんばりましょー\n"
uri = URI.parse("https://api.chatwork.com/v1/rooms/#{Config['api']['chatwork_room_id']}/messages")
request = Net::HTTP::Post.new(uri.request_uri)
request['Content-Type'] = 'application/x-www-form-urlencoded'
request['X-ChatWorkToken'] = Config['api']['chatwork_api_key']
request.set_form_data({:body => body})
https = Net::HTTP.new(uri.host, uri.port)
https.use_ssl = true
https.set_debug_output $stderr
https.request(request)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment