relsr 0.0.2

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: ca4948573df960dcef8b8bef529bed14b9461e70
4
+ data.tar.gz: de593211017d930fff99ed08051bb06c8e749af5
5
+ SHA512:
6
+ metadata.gz: e198224981df581dd25f39b5b86e16cbd6c630b47024c775e4d47413055f1610e279aaae10ae39fa894156a0d40614873f10202b21a6af0e3712cfe16bb3fc77
7
+ data.tar.gz: 1631f806a13edea365894e89756e3b8fa429162e84ec4f6949f35ea58927f0a4dbc2f19c5340dcc0acd21b8a1afcfd824ba62a290b2b5c27ae3f20c14c72e57c
data/bin/relsr ADDED
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'relsr'
4
+
5
+ Relsr::Initializer.init
data/lib/relsr.rb ADDED
@@ -0,0 +1,2 @@
1
+ require_relative 'relsr/initializer'
2
+ require_relative 'relsr/release_manager'
@@ -0,0 +1,75 @@
1
+ require 'yaml'
2
+ require 'optparse'
3
+
4
+ module Relsr
5
+ class Initializer
6
+
7
+ YAML_FILE = 'relsr.yml'
8
+
9
+ def self.init
10
+ parse_options
11
+ parse_yaml
12
+ process
13
+ end
14
+
15
+ private
16
+
17
+ def self.parse_options
18
+ @options = {}
19
+ OptionParser.new do |opts|
20
+ opts.banner = "Usage: relsr [options]"
21
+
22
+ opts.on("-r", "--release", "Create a release branch and open a pull request") do |v|
23
+ @options[:branch] = true
24
+ @options[:pull_request] = true
25
+ end
26
+
27
+ opts.on("-b", "--branch", "Create a release branch only") do |v|
28
+ @options[:branch] = true
29
+ end
30
+
31
+ opts.on("-d", "--dry-run", "Dry run") do |v|
32
+ @options[:dry_run] = true
33
+ end
34
+
35
+ opts.on("-i", "--init", "Create relst.yml for project") do |v|
36
+ create_default_yaml
37
+ exit 0
38
+ end
39
+ end.parse!
40
+ end
41
+
42
+ def self.parse_yaml
43
+ unless File.exists?(YAML_FILE)
44
+ puts 'Could not file relsr.yml file.'
45
+ exit 1
46
+ end
47
+ begin
48
+ config = YAML.load_file(YAML_FILE)
49
+ raise 'repo: has not been set' if config['repo'].nil?
50
+ raise 'label: has not been set' if config['label'].nil?
51
+ @repo = config['repo']
52
+ @label = config['label']
53
+ rescue StandardError => error
54
+ puts 'invalid relsr.yml file'
55
+ puts error.message
56
+ exit 1
57
+ end
58
+ end
59
+
60
+ def self.process
61
+ manager = Relsr::ReleaseManager.new(@repo, @label, @options[:dry_run])
62
+ manager.create_release if @options[:branch]
63
+ manager.create_pull_request if @options[:pull_request]
64
+ end
65
+
66
+ def self.create_default_yaml
67
+ content = {
68
+ 'repo' => 'username/repo_name',
69
+ 'label' => 'acceptance-done'
70
+ }
71
+ File.open(YAML_FILE, 'w') {|f| f.write content.to_yaml }
72
+ end
73
+ end
74
+
75
+ end
@@ -0,0 +1,92 @@
1
+ require 'octokit'
2
+
3
+ module Relsr
4
+ class ReleaseManager
5
+
6
+ def initialize(repo_name, label, dry_run = false)
7
+ @repo_name = repo_name
8
+ @label = label
9
+ @release_branch_name = Time.now.strftime('release/%Y%m%d-%H%M%S')
10
+ @dry_run = dry_run
11
+ Octokit.auto_paginate = true
12
+ end
13
+
14
+ def create_release
15
+ create_release_branch
16
+ merge_work_branches
17
+ end
18
+
19
+ def create_pull_request
20
+ puts "Creating Pull Request"
21
+ return if @dry_run
22
+ client.create_pull_request(
23
+ @repo_name,
24
+ 'master',
25
+ @release_branch_name,
26
+ @release_branch_name,
27
+ pr_body
28
+ )
29
+ end
30
+
31
+ private
32
+
33
+ def create_release_branch
34
+ puts "Creating release branch '#{@release_branch_name}' on '#{@repo_name}'"
35
+ return if @dry_run
36
+ client.create_ref(@repo_name, "heads/#{@release_branch_name}", master.object.sha)
37
+ end
38
+
39
+ def merge_work_branches
40
+ branches_to_merge.each do |work_branch|
41
+ puts "Merging '#{work_branch}' into release"
42
+ next if @dry_run
43
+ client.merge(
44
+ @repo_name,
45
+ @release_branch_name,
46
+ work_branch,
47
+ commit_message: "Merging #{work_branch} into release"
48
+ )
49
+ end
50
+ end
51
+
52
+ def client
53
+ @client ||= Octokit::Client.new(netrc: true)
54
+ end
55
+
56
+ def repo
57
+ @repo ||= client.repo(@repo_name)
58
+ end
59
+
60
+ def branch_names
61
+ @branch_names ||= client.branches(@repo_name).collect { |b| b.name }
62
+ end
63
+
64
+ def branches_to_merge
65
+ branches_to_merge = []
66
+
67
+ issues.each do |issue|
68
+ branch_names.each do |branch|
69
+ if branch.include? "##{issue.number}"
70
+ branches_to_merge << branch
71
+ end
72
+ end
73
+ end
74
+ branches_to_merge
75
+ end
76
+
77
+ def master
78
+ @master ||= client.refs(@repo_name, 'heads/master')
79
+ end
80
+
81
+ def issues
82
+ @issues ||= client.list_issues(@repo_name, labels: @label)
83
+ end
84
+
85
+ def pr_body
86
+ issues.collect do |issue|
87
+ "Connects ##{issue.number} - #{issue.title}"
88
+ end.join("\n")
89
+ end
90
+
91
+ end
92
+ end
@@ -0,0 +1,3 @@
1
+ module Relsr
2
+ VERSION = '0.0.2'.freeze
3
+ end
metadata ADDED
@@ -0,0 +1,78 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: relsr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - John Cleary
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-07-02 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: octokit
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: netrc
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.11'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.11'
41
+ description:
42
+ email:
43
+ - john@createk.io
44
+ executables:
45
+ - relsr
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - bin/relsr
50
+ - lib/relsr.rb
51
+ - lib/relsr/initializer.rb
52
+ - lib/relsr/release_manager.rb
53
+ - lib/relsr/version.rb
54
+ homepage: https://github.com/jcleary/relsr
55
+ licenses:
56
+ - MIT
57
+ metadata: {}
58
+ post_install_message:
59
+ rdoc_options: []
60
+ require_paths:
61
+ - lib
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '2.0'
67
+ required_rubygems_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ requirements: []
73
+ rubyforge_project:
74
+ rubygems_version: 2.5.1
75
+ signing_key:
76
+ specification_version: 4
77
+ summary: Command-line release managment tool for GitHub projects.
78
+ test_files: []