ruboty-github_pr_release 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: b08ffb05f4863cd4c6d0cb3548451f929fe7e5ba
4
+ data.tar.gz: e5773eef7ed4990d88644348ec8dc3b2a905617a
5
+ SHA512:
6
+ metadata.gz: a6290d730d69ef0921a45ca62ecd8b55800360d850ea02129dba70a2eb14b11405eca3183925692bbc69e86daeb1d85441a21cd8ee4972f063e32f04f776fc59
7
+ data.tar.gz: 35d06658a64e057ea290c04dc0f93e51ec2e03e6c873804be04491092c923796b1d3ce1cad146bfb320843211499e7b5698cd030f1797d8813f58736a31ceeb7
data/.gitignore ADDED
@@ -0,0 +1,50 @@
1
+ ### https://raw.github.com/github/gitignore/be3333655bffe9507d66cc864aee95ed6052b4ed/Global/Vim.gitignore
2
+
3
+ [._]*.s[a-w][a-z]
4
+ [._]s[a-w][a-z]
5
+ *.un~
6
+ Session.vim
7
+ .netrwhist
8
+ *~
9
+
10
+
11
+ ### https://raw.github.com/github/gitignore/be3333655bffe9507d66cc864aee95ed6052b4ed/Ruby.gitignore
12
+
13
+ *.gem
14
+ *.rbc
15
+ /.config
16
+ /coverage/
17
+ /InstalledFiles
18
+ /pkg/
19
+ /spec/reports/
20
+ /spec/examples.txt
21
+ /test/tmp/
22
+ /test/version_tmp/
23
+ /tmp/
24
+
25
+ ## Specific to RubyMotion:
26
+ .dat*
27
+ .repl_history
28
+ build/
29
+
30
+ ## Documentation cache and generated files:
31
+ /.yardoc/
32
+ /_yardoc/
33
+ /doc/
34
+ /rdoc/
35
+
36
+ ## Environment normalization:
37
+ /.bundle/
38
+ /vendor/bundle
39
+ /lib/bundler/man/
40
+
41
+ # for a library or gem, you might want to ignore these files since the code is
42
+ # intended to run in multiple environments; otherwise, check them in:
43
+ Gemfile.lock
44
+ .ruby-version
45
+ .ruby-gemset
46
+
47
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
48
+ .rvmrc
49
+
50
+
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in ruboty-github_pr_release.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2017 Michael H. Oshita
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,33 @@
1
+ # Ruboty::GithubPrRelease
2
+
3
+ Manages the creation and merging of `release pull requests` via Ruboty.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ # Gemfile
11
+ gem 'ruboty-github_pr_release'
12
+ ```
13
+
14
+ ## Usage
15
+
16
+ @ruboty release from "from" to "to"[as "title"] - Creates a `release pull request`
17
+ @ruboty update release from "from" to "to"[as "title"] - Updates a `release pull request`
18
+ @ruboty deploy release from "from" to "to" - Merges a `release pull request` for deployment
19
+
20
+ ## Notes
21
+
22
+ Be careful not to `revert` a merge. Otherwise, further pull requests cannot be made.
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
27
+
28
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
29
+
30
+ ## Contributing
31
+
32
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/ruboty-github_pr_release.
33
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "ruboty/github_pr_release"
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(__FILE__)
data/bin/setup ADDED
@@ -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,30 @@
1
+ module Ruboty
2
+ module GithubPrRelease
3
+ module Actions
4
+ class DeployRelease < UpdateRelease
5
+
6
+ private
7
+
8
+ def create
9
+ message.reply("Merged #{pull_request.html_url} for deployment")
10
+ rescue Octokit::Unauthorized
11
+ message.reply("Failed in authentication (401)")
12
+ rescue Octokit::NotFound
13
+ message.reply("Could not find that repository")
14
+ rescue => exception
15
+ message.reply("Failed by #{exception.class} #{exception}")
16
+ rescue NoPrExistsError => e
17
+ message.reply(e) #TODO e=> e.message?
18
+ end
19
+
20
+ def pull_request
21
+ current_pr = current_pull_request
22
+ raise NoPrExistsError if current_pr.empty?
23
+ issue = current_pr.first
24
+ client.merge_pull_request(repository, issue.number)
25
+ issue
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,58 @@
1
+ module Ruboty
2
+ module GithubPrRelease
3
+ module Actions
4
+ class Release < Ruboty::Github::Actions::CreatePullRequest
5
+
6
+ private
7
+
8
+ def body
9
+ diff = client.compare(repository, base, from_branch)
10
+ merged_pr = diff.commits.select{|c| c.commit.message =~ /Merge pull request #/}
11
+ Ruboty.logger.debug("Found merged pull requests: #{merged_pr.size}")
12
+ body = "Releasing these pull requests:\n\n"
13
+ merged_pr.collect do |pr|
14
+ num, title = /Merge pull request (?<merge_num>#\d+) from.*\n\n(?<merge_title>.*)/.match(pr.commit.message).captures
15
+ body += "- [ ] #{num} #{title} @#{pr.author.login}\n"
16
+ end
17
+ Ruboty.logger.debug("body: \n#{body}")
18
+ # TODO: put slack login id if exists
19
+ body
20
+ end
21
+
22
+ def create
23
+ message.reply("Created #{pull_request.html_url}")
24
+ rescue Octokit::Unauthorized
25
+ message.reply("Failed in authentication (401)")
26
+ rescue Octokit::NotFound
27
+ message.reply("Could not find that repository")
28
+ rescue => exception
29
+ message.reply("Failed by #{exception.class} #{exception}")
30
+ rescue PrExistsError => e
31
+ message.reply(e)
32
+ end
33
+
34
+ def pull_request
35
+ Ruboty.logger.debug("repo: #{repository}")
36
+ Ruboty.logger.debug("base: #{base}")
37
+ Ruboty.logger.debug("from_branch (head): #{from_branch}")
38
+ Ruboty.logger.debug("title: #{title}")
39
+ current_pr = current_pull_request
40
+ raise PrExistsError, "Pull Request already exists" unless current_pr.empty?
41
+ client.create_pull_request(repository, base, from_branch, title, body)
42
+ end
43
+
44
+ def title
45
+ # TODO: title with date (jst active support)
46
+ message[:title] || "release to #{base}"
47
+ end
48
+
49
+ def current_pull_request
50
+ client.pull_requests(repository, head: from_branch, base: base)
51
+ end
52
+ end
53
+
54
+ class PrExistsError < StandardError
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,47 @@
1
+ module Ruboty
2
+ module GithubPrRelease
3
+ module Actions
4
+ class UpdateRelease < Release
5
+
6
+ private
7
+
8
+ def create
9
+ message.reply("Updated #{pull_request.html_url}")
10
+ rescue Octokit::Unauthorized
11
+ message.reply("Failed in authentication (401)")
12
+ rescue Octokit::NotFound
13
+ message.reply("Could not find that repository")
14
+ rescue => exception
15
+ message.reply("Failed by #{exception.class} #{exception}")
16
+ rescue NoPrExistsError => e
17
+ message.reply(e)
18
+ end
19
+
20
+ def pull_request
21
+ Ruboty.logger.debug("repo: #{repository}")
22
+ Ruboty.logger.debug("base: #{base}")
23
+ Ruboty.logger.debug("from_branch (head): #{from_branch}")
24
+ Ruboty.logger.debug("title: #{title}")
25
+ current_pr = current_pull_request
26
+ raise NoPrExistsError, "Pull Request does NOT exist" if current_pr.empty?
27
+ b = body
28
+ message_diff('title', current_pr.first.title, title)
29
+ message_diff('body', current_pr.first.body, b)
30
+ client.update_pull_request(repository, current_pr.first.number, title: title, body: b)
31
+ end
32
+
33
+ def message_diff(what, old, new)
34
+ diff = Diffy::Diff.new(old, new)
35
+ if
36
+ Ruboty.logger.debug("updating #{what}:\n#{diff.to_s(:color)}\n")
37
+ message.reply("updating #{what}:\n#{diff}\n")
38
+ end
39
+ end
40
+
41
+ end
42
+
43
+ class NoPrExistsError < StandardError
44
+ end
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,5 @@
1
+ module Ruboty
2
+ module GithubPrRelease
3
+ VERSION = "0.2.0"
4
+ end
5
+ end
@@ -0,0 +1,13 @@
1
+ require "diffy"
2
+ require "ruboty/github"
3
+ require "ruboty/github_pr_release/version"
4
+ require "ruboty/github_pr_release/actions/release"
5
+ require "ruboty/github_pr_release/actions/update_release"
6
+ require "ruboty/github_pr_release/actions/deploy_release"
7
+ require "ruboty/handlers/github_pr_release"
8
+
9
+ module Ruboty
10
+ module GithubPrRelease
11
+ # Your code goes here...
12
+ end
13
+ end
@@ -0,0 +1,37 @@
1
+ require "ruboty/github_pr_release/actions/release"
2
+
3
+ module Ruboty
4
+ module Handlers
5
+ class GithubPrRelease < Base
6
+ on(
7
+ /release from (?<from>.+) to (?<to>.+:\S+)( as "(?<title>\w+)")?\z/,
8
+ name: 'release',
9
+ description: "Creates a 'release pull request'"
10
+ )
11
+
12
+ on(
13
+ /update release from (?<from>.+) to (?<to>.+:\S+)( as "(?<title>\w+)")?\z/,
14
+ name: 'update_release',
15
+ description: "Updates a 'release pull request'"
16
+ )
17
+
18
+ on(
19
+ /deploy release from (?<from>.+) to (?<to>.+)\z/,
20
+ name: 'deploy_release',
21
+ description: "Merges a 'release pull request' for deployment"
22
+ )
23
+
24
+ def release(message)
25
+ Ruboty::GithubPrRelease::Actions::Release.new(message).call
26
+ end
27
+
28
+ def update_release(message)
29
+ Ruboty::GithubPrRelease::Actions::UpdateRelease.new(message).call
30
+ end
31
+
32
+ def deploy_release(message)
33
+ Ruboty::GithubPrRelease::Actions::DeployRelease.new(message).call
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,28 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'ruboty/github_pr_release/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "ruboty-github_pr_release"
8
+ spec.version = Ruboty::GithubPrRelease::VERSION
9
+ spec.authors = ["Micahel H. Oshita"]
10
+ spec.email = ["ijinpublic+github@gmail.com"]
11
+
12
+ spec.summary = %q{Manages a 'release pull request'}
13
+ spec.description = spec.summary
14
+ spec.homepage = "https://github.com/ijin/ruboty-github_pr_release"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_dependency "ruboty-github", "0.2.1"
27
+ spec.add_dependency "diffy", "~> 3.1"
28
+ end
metadata ADDED
@@ -0,0 +1,115 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruboty-github_pr_release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.0
5
+ platform: ruby
6
+ authors:
7
+ - Micahel H. Oshita
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-03-26 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: ruboty-github
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '='
46
+ - !ruby/object:Gem::Version
47
+ version: 0.2.1
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '='
53
+ - !ruby/object:Gem::Version
54
+ version: 0.2.1
55
+ - !ruby/object:Gem::Dependency
56
+ name: diffy
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '3.1'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '3.1'
69
+ description: Manages a 'release pull request'
70
+ email:
71
+ - ijinpublic+github@gmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - Gemfile
78
+ - LICENSE.txt
79
+ - README.md
80
+ - Rakefile
81
+ - bin/console
82
+ - bin/setup
83
+ - lib/ruboty/github_pr_release.rb
84
+ - lib/ruboty/github_pr_release/actions/deploy_release.rb
85
+ - lib/ruboty/github_pr_release/actions/release.rb
86
+ - lib/ruboty/github_pr_release/actions/update_release.rb
87
+ - lib/ruboty/github_pr_release/version.rb
88
+ - lib/ruboty/handlers/github_pr_release.rb
89
+ - ruboty-github_pr_release.gemspec
90
+ homepage: https://github.com/ijin/ruboty-github_pr_release
91
+ licenses:
92
+ - MIT
93
+ metadata: {}
94
+ post_install_message:
95
+ rdoc_options: []
96
+ require_paths:
97
+ - lib
98
+ required_ruby_version: !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - - ">="
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ required_rubygems_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: '0'
108
+ requirements: []
109
+ rubyforge_project:
110
+ rubygems_version: 2.2.2
111
+ signing_key:
112
+ specification_version: 4
113
+ summary: Manages a 'release pull request'
114
+ test_files: []
115
+ has_rdoc: