gitcafe-maid 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43c7dcca3404cfc2bc72b813e4bdff3593063adb
4
+ data.tar.gz: b1c2679298405b1174e42e3d5b12c7fd68724444
5
+ SHA512:
6
+ metadata.gz: 61019578ed05fcd79f260df94eceac6c54eb758660a5f2658ffc9e9313262fee8c46b789faf56f4e0e767dc5f89f44423ae161c7029fa77a4513e63cf6ee0997
7
+ data.tar.gz: 2b5a1e36e2f96618c0524701369dfe6556e6e3879851a28fff47a276f449038763f312b9a065dd18335dd0956342323f2eec8e208029fd45ea1dc8fbf3d55f06
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 Richard Huang
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,17 @@
1
+ # gitcafe-maid
2
+ gitcafe-maid 利用 gitcafe 提供的 webhook 监听分支的 push 行为 自动启动测试 并把结果通知到
3
+ slack/瀑布 中 还可以在提供的回调函数中执行自动部署.
4
+
5
+ ## Installation
6
+
7
+ $ gem install gitcafe-maid
8
+
9
+ ## Usage
10
+
11
+ 1. 增加配置文件 示例在example目录下
12
+ 2. 在 gitcafe 相应项目里设置 push webhook
13
+ 3. 在配置文件的目录下执行 `RACK_ENV=production gitcafe-maid` 会开始监听本机的4567端口, 等待 gitcafe webhook 调用.
14
+
15
+ ## Contributing
16
+
17
+ Bug reports and pull requests are welcome on GitHub at https://github.com/xyuwang/gitcafe-maid.
@@ -0,0 +1,5 @@
1
+ $:.unshift File.expand_path("../lib", __FILE__)
2
+
3
+ #@require "gitcafe-maid"
4
+ require "bundler/gem_tasks"
5
+ require "bundler/setup"
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift File.expand_path(File.join(File.dirname(__FILE__), "..", "lib"))
4
+ require 'gitcafe_maid'
5
+
6
+ GitcafeMaid::Configuration.class_eval do
7
+ eval File.read('./config/gitcafe-maid.rb')
8
+ end
9
+
10
+ GitcafeMaid::User.initialize_users
11
+
12
+ GitcafeMaid::Web.run!
@@ -0,0 +1,8 @@
1
+ require 'gitcafe_maid/user'
2
+ require 'gitcafe_maid/configuration'
3
+ require 'gitcafe_maid/web'
4
+ require 'gitcafe_maid/version'
5
+ require 'gitcafe_maid/webhook'
6
+
7
+ module GitcafeMaid
8
+ end
@@ -0,0 +1,40 @@
1
+ module GitcafeMaid
2
+ class Configuration
3
+ class << self
4
+ def ci *args, &block
5
+ if block_given?
6
+ @@ci_block = block
7
+ else
8
+ @@ci_block.call *args
9
+ end
10
+ end
11
+
12
+ def run command
13
+ `cd #{path} && #{command}`
14
+ end
15
+
16
+ def set name, value
17
+ define_singleton_method name do
18
+ value
19
+ end
20
+ end
21
+
22
+
23
+ def fail author=nil, path=nil, &script
24
+ if block_given?
25
+ @@fail = script
26
+ else
27
+ @@fail.call(author, path)
28
+ end
29
+ end
30
+
31
+ def succ author=nil, path=nil, &script
32
+ if block_given?
33
+ @@succ = script
34
+ else
35
+ @@succ.call(author, path)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,55 @@
1
+ require 'uri'
2
+ require 'yaml'
3
+ require 'rest-client'
4
+
5
+ module GitcafeMaid
6
+ class User
7
+ attr_accessor :good_words, :bad_words, :url
8
+ @@users = []
9
+
10
+ def initialize good_words, bad_words, url
11
+ @good_words = good_words.shuffle
12
+ @bad_words = bad_words.shuffle
13
+ @url = url
14
+ end
15
+
16
+ def say_good
17
+ word = @good_words.pop
18
+ @good_words.unshift word
19
+ word
20
+ end
21
+
22
+ def say_bad
23
+ word = @bad_words.pop
24
+ @bad_words.unshift word
25
+ word
26
+ end
27
+
28
+ def notify author, good= true, msg=nil
29
+ if msg
30
+ msg = "#{author}: #{msg}"
31
+ else
32
+ msg = (good ? say_good : say_bad)
33
+ end
34
+
35
+ if Configuration.im.to_s == "pubu"
36
+ RestClient.post @url, {text: msg}.to_json, :content_type => :json, :accept => :json
37
+ else
38
+ body = {attachments: [color: (good ? "good" : "bad"), text: msg]}
39
+ RestClient.post @url, body.to_json, :content_type => :json, :accept => :json
40
+ end
41
+ end
42
+
43
+ def self.initialize_users
44
+ Dir.glob('users/*.yml').each do |f|
45
+ data = YAML.load File.open(f)
46
+ new_user = User.new data["good_words"],data["bad_words"], data["url"]
47
+ @@users << new_user
48
+ end
49
+ end
50
+
51
+ def self.notify author, good = true, msg = nil
52
+ @@users.sample.notify(author, good, msg)
53
+ end
54
+ end
55
+ end
@@ -0,0 +1,3 @@
1
+ module GitcafeMaid
2
+ VERSION='0.1'
3
+ end
@@ -0,0 +1,29 @@
1
+ require 'json'
2
+ require 'byebug'
3
+ require 'sinatra'
4
+
5
+ module GitcafeMaid
6
+ class Web < Sinatra::Base
7
+ post '/' do
8
+ begin
9
+ params = JSON.parse(request.env["rack.input"].read)
10
+ webhook = Webhook.new(params)
11
+ author = webhook.author
12
+ branch = webhook.branch
13
+ puts "检测到 #{branch} 分支有新提交"
14
+ return puts "#{webhook.branch}分支, 忽略." if webhook.branch != Configuration.branch
15
+ User.notify author, true, "检测到#{branch}分支有新提交, 准备进行测试.."
16
+
17
+ puts "准备进行测试"
18
+ result = Configuration.ci Configuration.path
19
+ User.notify author, result[:success], result[:msg]
20
+
21
+ result[:success] ? Configuration.succ(author, branch) : Configuration.fail(author, branch)
22
+
23
+ rescue StandardError => e
24
+ puts e
25
+ puts e.backtrace.join("\n")
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,17 @@
1
+ require 'net/http'
2
+
3
+ module GitcafeMaid
4
+ class Webhook
5
+ def initialize params
6
+ @params = params
7
+ end
8
+
9
+ def author
10
+ @params['sender']['username']
11
+ end
12
+
13
+ def branch
14
+ @params['ref'][11..-1]
15
+ end
16
+ end
17
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gitcafe-maid
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sam Wang
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-09-16 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sinatra
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rest-client
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ 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.3'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rake
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: byebug
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: "为GitCafe Webhook 打造的CI Robot 支持 slack 自动提醒"
98
+ email:
99
+ - sam@dgz.sh
100
+ executables:
101
+ - gitcafe-maid
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - LICENSE.txt
106
+ - README.md
107
+ - Rakefile
108
+ - bin/gitcafe-maid
109
+ - lib/gitcafe_maid.rb
110
+ - lib/gitcafe_maid/configuration.rb
111
+ - lib/gitcafe_maid/user.rb
112
+ - lib/gitcafe_maid/version.rb
113
+ - lib/gitcafe_maid/web.rb
114
+ - lib/gitcafe_maid/webhook.rb
115
+ homepage: https://gitcafe.com/awsam/gitcafe-maid
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: 2.0.0
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.4.6
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: "为GitCafe Webhook 打造的CI Robot"
139
+ test_files: []