ruboty-bitbucket_merge 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +14 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +41 -0
- data/Rakefile +2 -0
- data/lib/ruboty/bitbucket_merge/actions/merge_branch.rb +95 -0
- data/lib/ruboty/bitbucket_merge/version.rb +5 -0
- data/lib/ruboty/bitbucket_merge.rb +8 -0
- data/lib/ruboty/handlers/bitbucket_merge.rb +22 -0
- data/ruboty-bitbucket_merge.gemspec +23 -0
- metadata +96 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e2407008019474d8809e639c9067af9f0a8774c0
|
4
|
+
data.tar.gz: 7e4d09232fc287723fbca1ddcb49af191f5877c8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fdcf03ea0aacc635ce3528613216135ae058c87fbc7619aeb8bb29220c767e974246e870f448b04430e3345f0e5730e799b1a5bcb963b59309a8686f22acdb25
|
7
|
+
data.tar.gz: 721685ec9b47e9f1ae4d05ee4cf76af56fc09254be6f94d5c878f1bdd5dae0f1e5255faef83485becea85ef9e03c935417de00dc5c6c25f629336e6dd0496a8e
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 SET_ME_LOCALLY
|
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.
|
data/README.md
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
# Ruboty::BitbucketMerge
|
2
|
+
|
3
|
+
An Ruboty Handler + Actions to merge branches on bitbucket via Ruboty..
|
4
|
+
|
5
|
+
[Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
|
6
|
+
|
7
|
+
## Commands
|
8
|
+
|
9
|
+
|Command|Pattern|Description|
|
10
|
+
|:--|:--|:--|
|
11
|
+
|[bb-br-merge](#bb-br-merge)|/bb-br-merge (?<source>..+) (?<target>.+) (?<team>.+)/(?<repo>.+)z/|Merge source branch to target branch on specified repository.|
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
### bb-br-merge
|
15
|
+
* Merge source branch to target branch on specified repository.
|
16
|
+
|
17
|
+
~~~
|
18
|
+
botname bb-br-merge master release myaccount/myrepo
|
19
|
+
~~~
|
20
|
+
|
21
|
+
## ENV
|
22
|
+
|
23
|
+
|Name|Description|
|
24
|
+
|:--|:--|
|
25
|
+
|BITBUCKET_USERNAME|your Bitbucket username|
|
26
|
+
|BITBUCKET_PASSWORD|your Bitbucket password|
|
27
|
+
|BITBUCKET_EMAIL|your Bitbucket e-mail|
|
28
|
+
|
29
|
+
## Dependency
|
30
|
+
|
31
|
+
|Name|Description|
|
32
|
+
|:--|:--|
|
33
|
+
|||
|
34
|
+
|
35
|
+
## Contributing
|
36
|
+
|
37
|
+
1. Fork it ( https://github.com/xoyip/ruboty-bitbucket_merge/fork )
|
38
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
39
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
40
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
41
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,95 @@
|
|
1
|
+
module Ruboty
|
2
|
+
module BitbucketMerge
|
3
|
+
module Actions
|
4
|
+
class MergeBranch < Ruboty::Actions::Base
|
5
|
+
|
6
|
+
def call
|
7
|
+
@team = message[:team]
|
8
|
+
@repo = message[:repo]
|
9
|
+
@source = message[:source]
|
10
|
+
@target = message[:target]
|
11
|
+
|
12
|
+
@user = ENV["BITBUCKET_USERNAME"]
|
13
|
+
@pass = ENV["BITBUCKET_PASSWORD"]
|
14
|
+
@emakl = ENV["BITBUCKET_EMAIL"]
|
15
|
+
|
16
|
+
begin
|
17
|
+
pr_id, links = create_pull_request
|
18
|
+
merge_message = build_merge_message(links["commits"]["href"])
|
19
|
+
merge_pull_request(links["merge"]["href"], pr_id, merge_message)
|
20
|
+
message.reply("Successfully merged.\n\n" + merge_message)
|
21
|
+
rescue
|
22
|
+
message.reply("Failed to merge.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def create_pull_request
|
29
|
+
urlstr = "https://api.bitbucket.org/2.0/repositories/#{@team}/#{@repo}/pullrequests"
|
30
|
+
url = URI.parse(urlstr)
|
31
|
+
params = {
|
32
|
+
"title"=> "Merge #{@source} to #{@target}",
|
33
|
+
"description"=> "Merge #{@source} to #{@target}",
|
34
|
+
"source"=> {
|
35
|
+
"branch"=> {
|
36
|
+
"name"=> @source
|
37
|
+
},
|
38
|
+
"repository"=> {
|
39
|
+
"full_name"=> "#{@team}/#{@repo}"
|
40
|
+
}
|
41
|
+
},
|
42
|
+
"destination"=> {
|
43
|
+
"branch"=> {
|
44
|
+
"name"=> @target
|
45
|
+
}
|
46
|
+
},
|
47
|
+
"close_source_branch"=> false
|
48
|
+
}
|
49
|
+
|
50
|
+
req = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json'})
|
51
|
+
req.basic_auth @user, @pass
|
52
|
+
req.body = params.to_json
|
53
|
+
http = Net::HTTP.new(url.host, url.port)
|
54
|
+
http.use_ssl = true
|
55
|
+
|
56
|
+
res = http.start {|http| http.request(req)}
|
57
|
+
hash = JSON.parse(res.body)
|
58
|
+
return hash["id"], hash["links"]
|
59
|
+
end
|
60
|
+
|
61
|
+
def build_merge_message(href)
|
62
|
+
url = URI.parse(href)
|
63
|
+
req = Net::HTTP::Get.new(url.path, initheader = {'Content-Type' =>'application/json'})
|
64
|
+
req.basic_auth @user, @pass
|
65
|
+
http = Net::HTTP.new(url.host, url.port)
|
66
|
+
http.use_ssl = true
|
67
|
+
res = http.start {|http| http.request(req)}
|
68
|
+
JSON.parse(res.body)["values"].map{|h| "- " + h["message"]}.join("\n")
|
69
|
+
end
|
70
|
+
|
71
|
+
def merge_pull_request(href, pr_id, merge_message)
|
72
|
+
url = URI.parse(href)
|
73
|
+
params = {
|
74
|
+
"owner" => @team,
|
75
|
+
"repo_slug" => @repo,
|
76
|
+
"pull_request_id" => pr_id,
|
77
|
+
"name" => @user,
|
78
|
+
"email" => @email,
|
79
|
+
"message" => merge_message
|
80
|
+
}
|
81
|
+
|
82
|
+
req = Net::HTTP::Post.new(url.path, initheader = {'Content-Type' =>'application/json'})
|
83
|
+
req.basic_auth @user, @pass
|
84
|
+
req.body = params.to_json
|
85
|
+
http = Net::HTTP.new(url.host, url.port)
|
86
|
+
http.use_ssl = true
|
87
|
+
|
88
|
+
res = http.start {|http| http.request(req)}
|
89
|
+
res.body
|
90
|
+
end
|
91
|
+
|
92
|
+
end
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
require "ruboty/bitbucket_merge/actions/merge_branch"
|
2
|
+
|
3
|
+
module Ruboty
|
4
|
+
module Handlers
|
5
|
+
class BitbucketMerge < Base
|
6
|
+
|
7
|
+
env :BITBUCKET_USERNAME, "Bitbucket username"
|
8
|
+
env :BITBUCKET_PASSWORD, "Bitbucket password"
|
9
|
+
env :BITBUCKET_EMAIL, "Bitbucket email"
|
10
|
+
|
11
|
+
on(
|
12
|
+
/bb-br-merge (?<source>..+) (?<target>.+) (?<team>.+)\/(?<repo>.+)\z/,
|
13
|
+
name: "merge_branch",
|
14
|
+
description: "Merge source branch to target branch on specified repository.\nUsage: botname bb-br-merge master release myaccount/myrepo"
|
15
|
+
)
|
16
|
+
|
17
|
+
def merge_branch(message)
|
18
|
+
Ruboty::BitbucketMerge::Actions::MergeBranch.new(message).call
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ruboty/bitbucket_merge/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ruboty-bitbucket_merge"
|
8
|
+
spec.version = Ruboty::BitbucketMerge::VERSION
|
9
|
+
spec.authors = ["xoyip"]
|
10
|
+
spec.email = ["xoyip@piyox.info"]
|
11
|
+
spec.summary = %q{To merge branches on bitbucket via Ruboty.}
|
12
|
+
spec.homepage = "https://github.com/xoyip/ruboty-bitbucket_merge"
|
13
|
+
spec.license = "MIT"
|
14
|
+
|
15
|
+
spec.files = `git ls-files -z`.split("\x0")
|
16
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
17
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
18
|
+
spec.require_paths = ["lib"]
|
19
|
+
|
20
|
+
spec.add_runtime_dependency "ruboty"
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,96 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ruboty-bitbucket_merge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- xoyip
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-12-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: ruboty
|
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: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.7'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.7'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
description:
|
56
|
+
email:
|
57
|
+
- xoyip@piyox.info
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/ruboty/bitbucket_merge.rb
|
68
|
+
- lib/ruboty/bitbucket_merge/actions/merge_branch.rb
|
69
|
+
- lib/ruboty/bitbucket_merge/version.rb
|
70
|
+
- lib/ruboty/handlers/bitbucket_merge.rb
|
71
|
+
- ruboty-bitbucket_merge.gemspec
|
72
|
+
homepage: https://github.com/xoyip/ruboty-bitbucket_merge
|
73
|
+
licenses:
|
74
|
+
- MIT
|
75
|
+
metadata: {}
|
76
|
+
post_install_message:
|
77
|
+
rdoc_options: []
|
78
|
+
require_paths:
|
79
|
+
- lib
|
80
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
81
|
+
requirements:
|
82
|
+
- - ">="
|
83
|
+
- !ruby/object:Gem::Version
|
84
|
+
version: '0'
|
85
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements: []
|
91
|
+
rubyforge_project:
|
92
|
+
rubygems_version: 2.2.2
|
93
|
+
signing_key:
|
94
|
+
specification_version: 4
|
95
|
+
summary: To merge branches on bitbucket via Ruboty.
|
96
|
+
test_files: []
|