ruboty-byebranch 0.1.0

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: 172dbc55997d90c43f639eba40377e230103496d
4
+ data.tar.gz: f16909e3486ae57400121896092eb9a0a8f60699
5
+ SHA512:
6
+ metadata.gz: 0cea3e79538e6204bd8fe5096cb0f47babaf4ff135b0082b9bb725af08f99c0e1aa2fbdcc9acc48009fdfb01a3785fe306053b1bca42e70334debed488d69b27
7
+ data.tar.gz: 81933929432658a9f96a3479e5dd977612a29d5742497a2a696e233631812226053d1edbbb50f001008a11b50e924c81ed3a0cf07a0c29bdd110fd34baa2d158
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-byebranch.gemspec
4
+ gemspec
@@ -0,0 +1,50 @@
1
+ # Ruboty::Byebranch
2
+
3
+ An Ruboty Handler + Actions to Delete merged branches.
4
+
5
+ [Ruboty](https://github.com/r7kamura/ruboty) is Chat bot framework. Ruby + Bot = Ruboty
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'ruboty-byebranch'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ ## Commands
20
+
21
+ |Command|Pattern|Description|
22
+ |:--|:--|:--|
23
+ |[byebranch](#byebranch)|byebranch (?<user>.+?) (?<repository>.+?) (?<exclude_branches>.+?)\z/|Delete merged branches|
24
+
25
+ ## Usage
26
+ ### byebranch
27
+ * Delete merged branch
28
+
29
+ ~~~
30
+ @ruboty byebranch tbpgr eto master,release
31
+ ~~~
32
+
33
+ ## ENV
34
+
35
+ |Name|Description|
36
+ |:--|:--|
37
+ |GITHUB_USER|GitHub USER|
38
+ |GITHUB_TOKEN|GitHub API Token|
39
+
40
+ ## Dependency
41
+
42
+ Nothing
43
+
44
+ ## Contributing
45
+
46
+ 1. Fork it ( https://github.com/tbpgr/ruboty-byebranch/fork )
47
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
48
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
49
+ 4. Push to the branch (`git push origin my-new-feature`)
50
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/byebranch"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,8 @@
1
+ require "ruboty/byebranch/version"
2
+ require "ruboty/handlers/byebranch"
3
+
4
+ module Ruboty
5
+ module Byebranch
6
+ # Your code goes here...
7
+ end
8
+ end
@@ -0,0 +1,46 @@
1
+ module Ruboty
2
+ module Byebranch
3
+ module Actions
4
+ class Byebranch < Ruboty::Actions::Base
5
+ def call
6
+ message.reply(byebranch)
7
+ rescue => e
8
+ message.reply(e.message)
9
+ end
10
+
11
+ private
12
+ def byebranch
13
+ clone_repository
14
+ return "target branch is not exist." unless exist_target_branch?
15
+ delete_target_branches.join("\n")
16
+ end
17
+
18
+ def clone_repository
19
+ `rm -rf /tmp/test && mkdir /tmp/test && cd /tmp/test && git clone #{github_url} > /dev/null 2>&1`
20
+ fail "fail clone" unless $?.success?
21
+ end
22
+
23
+ def github_url
24
+ user_token = "#{ENV['GITHUB_USER']}:#{ENV['GITHUB_TOKEN']}"
25
+ "https://#{user_token}@github.com/#{message[:user]}/#{message[:repository]}.git"
26
+ end
27
+
28
+ def exist_target_branch?
29
+ @branches = `cd /tmp/test/#{message[:repository]} && git branch -r --merged master | grep -v -w #{exclude_branches} | sed -e 's% *origin/%%'`
30
+ fail "fail check target branch" unless $?.success?
31
+ !@branches.split("\n").size.zero?
32
+ end
33
+
34
+ def delete_target_branches
35
+ `cd /tmp/test/#{message[:repository]} && git branch -r --merged master | grep -v -w #{exclude_branches} | sed -e 's% *origin/%%' | xargs -I% git push --delete origin % > /dev/null 2>&1`
36
+ fail "fail delete branches" unless $?.success?
37
+ @branches.split("\n").map {|e|"success delete branch - #{e}" }
38
+ end
39
+
40
+ def exclude_branches
41
+ message[:exclude_branches].split(',').map {|e|" -e #{e}" }.join
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module Byebranch
3
+ VERSION = "0.1.0"
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require "ruboty/byebranch/actions/byebranch"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ # An Ruboty Handler + Actions to delete merged branch.
6
+ class Byebranch < Base
7
+ on /byebranch (?<user>.+?) (?<repository>.+?) (?<exclude_branches>.+?)\z/, name: 'byebranch', description: 'Delete merged branches'
8
+ env :GITHUB_TOKEN, "GitHub API Token"
9
+ env :GITHUB_USER, "GitHub USER"
10
+
11
+ def byebranch(message)
12
+ Ruboty::Byebranch::Actions::Byebranch.new(message).call
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,24 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/byebranch/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-byebranch"
8
+ spec.version = Ruboty::Byebranch::VERSION
9
+ spec.authors = ["tbpgr"]
10
+ spec.email = ["tbpgr@tbpgr.jp"]
11
+
12
+ spec.summary = %q{An Ruboty Handler + Actions to Delete merged branches.}
13
+ spec.description = %q{An Ruboty Handler + Actions to Delete merged branches.}
14
+ spec.homepage = "https://github.com/tbpgr/ruboty-byebranch"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_runtime_dependency 'ruboty'
22
+ spec.add_development_dependency "bundler", "~> 1.12"
23
+ spec.add_development_dependency "rake", "~> 10.0"
24
+ end
metadata ADDED
@@ -0,0 +1,97 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-byebranch
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - tbpgr
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2016-05-19 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.12'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.12'
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: An Ruboty Handler + Actions to Delete merged branches.
56
+ email:
57
+ - tbpgr@tbpgr.jp
58
+ executables: []
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - .gitignore
63
+ - Gemfile
64
+ - README.md
65
+ - Rakefile
66
+ - bin/console
67
+ - bin/setup
68
+ - lib/ruboty/byebranch.rb
69
+ - lib/ruboty/byebranch/actions/byebranch.rb
70
+ - lib/ruboty/byebranch/version.rb
71
+ - lib/ruboty/handlers/byebranch.rb
72
+ - ruboty-byebranch.gemspec
73
+ homepage: https://github.com/tbpgr/ruboty-byebranch
74
+ licenses: []
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.3.0
93
+ signing_key:
94
+ specification_version: 4
95
+ summary: An Ruboty Handler + Actions to Delete merged branches.
96
+ test_files: []
97
+ has_rdoc: