update-draft-release 0.2.3

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d7a621a4f85e53f6e7f366bb3fa541e86324d58d
4
+ data.tar.gz: dd247cf409fc01cacbcd48ba32213fd353485371
5
+ SHA512:
6
+ metadata.gz: 4f94a485d0785bb6db60e146e048f6890e2f2b46b8d7e873d7145fdbbfb18d9d188c294b074b0ae2af07f515bb6cc707e9922f966edae31f529968278fcc69d3
7
+ data.tar.gz: 153f1bbe5dbc733f3bc3f121f69d10e3b1d95a980bdfcfbe944eedb2ab568e19f534c0a7aa54731e08b86c1ad6e05fa3cdb746189c1d8f44d1cee0ab6bab52d0
data/.gitignore ADDED
@@ -0,0 +1,66 @@
1
+ # Created by https://www.gitignore.io
2
+
3
+ ### OSX ###
4
+ .DS_Store
5
+ .AppleDouble
6
+ .LSOverride
7
+
8
+ # Icon must end with two \r
9
+ Icon
10
+
11
+ # Thumbnails
12
+ ._*
13
+
14
+ # Files that might appear in the root of a volume
15
+ .DocumentRevisions-V100
16
+ .fseventsd
17
+ .Spotlight-V100
18
+ .TemporaryItems
19
+ .Trashes
20
+ .VolumeIcon.icns
21
+
22
+ # Directories potentially created on remote AFP share
23
+ .AppleDB
24
+ .AppleDesktop
25
+ Network Trash Folder
26
+ Temporary Items
27
+ .apdisk
28
+
29
+
30
+ ### Ruby ###
31
+ *.gem
32
+ *.rbc
33
+ /.config
34
+ /coverage/
35
+ /InstalledFiles
36
+ /pkg/
37
+ /spec/reports/
38
+ /test/tmp/
39
+ /test/version_tmp/
40
+ /tmp/
41
+
42
+ ## Specific to RubyMotion:
43
+ .dat*
44
+ .repl_history
45
+ build/
46
+
47
+ ## Documentation cache and generated files:
48
+ /.yardoc/
49
+ /_yardoc/
50
+ /doc/
51
+ /rdoc/
52
+
53
+ ## Environment normalisation:
54
+ /.bundle/
55
+ /vendor/bundle
56
+ /lib/bundler/man/
57
+
58
+ # for a library or gem, you might want to ignore these files since the code is
59
+ # intended to run in multiple environments; otherwise, check them in:
60
+ # Gemfile.lock
61
+ # .ruby-version
62
+ # .ruby-gemset
63
+
64
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
65
+ .rvmrc
66
+
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec # declared in update-draft-release.gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,46 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ update-draft-release (0.2.3)
5
+ netrc (~> 0.10.3)
6
+ octokit (~> 3.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ addressable (2.3.8)
12
+ diff-lcs (1.2.5)
13
+ faraday (0.9.1)
14
+ multipart-post (>= 1.2, < 3)
15
+ multipart-post (2.0.0)
16
+ netrc (0.10.3)
17
+ octokit (3.8.0)
18
+ sawyer (~> 0.6.0, >= 0.5.3)
19
+ rake (10.4.2)
20
+ rspec (3.2.0)
21
+ rspec-core (~> 3.2.0)
22
+ rspec-expectations (~> 3.2.0)
23
+ rspec-mocks (~> 3.2.0)
24
+ rspec-core (3.2.3)
25
+ rspec-support (~> 3.2.0)
26
+ rspec-expectations (3.2.1)
27
+ diff-lcs (>= 1.2.0, < 2.0)
28
+ rspec-support (~> 3.2.0)
29
+ rspec-mocks (3.2.1)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.2.0)
32
+ rspec-support (3.2.2)
33
+ sawyer (0.6.0)
34
+ addressable (~> 2.3.5)
35
+ faraday (~> 0.8, < 0.10)
36
+
37
+ PLATFORMS
38
+ ruby
39
+
40
+ DEPENDENCIES
41
+ rake (~> 10.4.2)
42
+ rspec (~> 3.2.0)
43
+ update-draft-release!
44
+
45
+ BUNDLED WITH
46
+ 1.10.5
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2015 Wang Zhuochun
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,49 @@
1
+ # Update Draft Release
2
+
3
+ Add your latest commit message to your GitHub repository's draft release.
4
+
5
+ ## Setup
6
+
7
+ Install this gem by clone this repo. Run `bundle install & rake install` in it.
8
+
9
+ Create `~/.netrc` file with your GitHub login/password:
10
+
11
+ ```
12
+ machine api.github.com
13
+ login your_login_id
14
+ password your_password_or_token
15
+ ```
16
+
17
+ ## Usage
18
+
19
+ ```
20
+ $ update-draft-release your/repo
21
+
22
+ INFO: Logged in as: zhuochun
23
+ INFO: Repository used: your/repo
24
+ INFO: Prepare to insert line: New commit e4d5c0bf29055187d13e5e83c909
25
+ ##################################################
26
+ Draft
27
+ ==================================================
28
+ Old commit 11124f700882108e69ecdcf04074
29
+
30
+ New commit e4d5c0bf29055187d13e5e83c909
31
+ ##################################################
32
+ Ok? (Y/N): y
33
+ INFO: Updating to URL: https://www.github.com/your/repo/draft
34
+ INFO: Release 'Draft' updated!
35
+ ```
36
+
37
+ ### Options
38
+
39
+ - `--at-top-level`: Insert into top level.
40
+ - `--at-the-end`: Insert at the end.
41
+ - `--in-secton_name`: Insert into the section with heading 'Section Name'. E.g. `--in-gamma`.
42
+ - `--create-section`: Create a new section if not exists, used with `--in-secton_name`.
43
+ - `--open-url`: Open the release URL after update succeed.
44
+ - `--can-can`: Skip the final confirmation.
45
+ - `--i-am-kiasu`: Make sure the final confirmation is not skipped.
46
+
47
+ ## More
48
+
49
+ Run `gem uninstall update-draft-release` to uninstall.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
7
+ task :test => :spec
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+
4
+ require 'update_draft_release'
5
+
6
+ if ARGV.empty? || ARGV[0].empty?
7
+ puts 'Missing: no repository name leh?'
8
+ exit
9
+ end
10
+
11
+ repo = nil
12
+ options = {}
13
+
14
+ ARGV.each do |arg|
15
+ case arg
16
+ when /\A--(in|on|at)-(\w+)\Z/
17
+ puts "Assuming '#{arg}' is a Singlish way of saying '--in-#{$2}'" if $1 != 'in'
18
+ options[:insert_at] = $2.gsub('_', ' ')
19
+ when /\A--(in|on|at)-top-level\Z/
20
+ puts "Assuming '#{arg}' is a Singlish way of saying '--at-top-level'" if $1 != 'at'
21
+ options[:insert_at_top_level] = true
22
+ when /\A--(in|on|at)-the-end\Z/
23
+ puts "Assuming '#{arg}' is a Singlish way of saying '--at-the-end'" if $1 != 'at'
24
+ options[:insert_at_the_end] = true
25
+ when '--create-heading', '--create-section'
26
+ options[:create_heading] = true
27
+ when '--open-url'
28
+ options[:open_url_after_update] = true
29
+ when '--skip-confirmation', /\A--can(?:-can)+\Z/
30
+ options[:skip_confirmation] = true
31
+ when '--i-am-kiasu'
32
+ puts "Relak lah! Got confirmation deh."
33
+ options[:kiasu_mode] = true
34
+ when /\A\w+\/\w+\Z/
35
+ repo = arg
36
+ when /\A--([-\w]+)\Z/
37
+ puts "Invalid option: --#{$1}. So how?"
38
+ exit
39
+ else
40
+ puts "Bro, what's '#{arg}'? Don’t play play ah!"
41
+ exit
42
+ end
43
+ end
44
+
45
+ if repo.nil?
46
+ puts 'Missing: repo why you no repo (╯°□°)╯︵ ┻━┻'
47
+ exit
48
+ end
49
+
50
+ begin
51
+ runner = UpdateDraftRelease::Runner.new(repo, options)
52
+ runner.update_draft_release
53
+ rescue Exception => e
54
+ puts "#{e.message} (╯°Д°)╯︵ /(.□ . \)"
55
+ end
data/lib/content.rb ADDED
@@ -0,0 +1,49 @@
1
+ module UpdateDraftRelease
2
+ class Content
3
+ HEADING_REGEX = /^\s*#+\s+.+/
4
+
5
+ attr_reader :body, :line_separator, :lines
6
+
7
+ def initialize(body)
8
+ @body = body
9
+ @line_separator = if body =~ /(\r\n|\n)/ then $1 else %(\r\n) end
10
+ @lines = body.split(@line_separator)
11
+ end
12
+
13
+ def title
14
+ @lines.first[0].upcase + @lines.first[1..-1]
15
+ end
16
+
17
+ def headings
18
+ @lines.select { |line| line.match(HEADING_REGEX) }
19
+ end
20
+
21
+ def heading_indexes
22
+ @lines.each_index.select { |i| @lines[i].match(HEADING_REGEX) }
23
+ end
24
+
25
+ def find_heading(heading)
26
+ @lines.index { |line| line.match(/^\s*#+\s+.*#{heading}.*/i) }
27
+ end
28
+
29
+ def append(new_lines)
30
+ insert(@lines.size, new_lines)
31
+ end
32
+
33
+ def insert(line_num, new_lines)
34
+ if line_num == 0 || @lines[line_num - 1].strip.empty?
35
+ @lines[line_num,0] = Array(new_lines).flat_map { |line| [line, ''] }
36
+ else
37
+ @lines[line_num,0] = Array(new_lines).flat_map { |line| ['', line] }
38
+ end
39
+ end
40
+
41
+ def include?(sha)
42
+ @body.include?(sha)
43
+ end
44
+
45
+ def to_s
46
+ @lines.join(@line_separator)
47
+ end
48
+ end
49
+ end
data/lib/github.rb ADDED
@@ -0,0 +1,44 @@
1
+ require 'Octokit'
2
+
3
+ module UpdateDraftRelease
4
+ class Github
5
+ attr_reader :client, :repo
6
+
7
+ def self.open(repository)
8
+ Github.new(repository)
9
+ end
10
+
11
+ def initialize(repository)
12
+ @client = Octokit::Client.new(netrc: true)
13
+ @repo = repository
14
+ end
15
+
16
+ def user
17
+ @user ||= @client.user
18
+ end
19
+
20
+ def releases
21
+ return @releases if defined?(@releases)
22
+ @releases = @client.releases(@repo)
23
+ end
24
+
25
+ def draft_releases
26
+ releases.select { |release| release.draft }
27
+ end
28
+
29
+ def update_release(release, body)
30
+ @client.update_release(release.url, body: body.to_s)
31
+ end
32
+
33
+ def commits
34
+ return @commits if defined?(@commits)
35
+ @commits = @client.commits(@repo)
36
+ end
37
+
38
+ def user_commits
39
+ commits.select do |commit|
40
+ commit.committer && commit.committer.login == user.login
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,159 @@
1
+ require 'Logger'
2
+
3
+ require 'content'
4
+ require 'github'
5
+
6
+ module UpdateDraftRelease
7
+ LOGGER = Logger.new(STDOUT)
8
+ LOGGER.level = Logger::INFO
9
+ LOGGER.formatter = proc do |severity, datetime, progname, msg|
10
+ "#{severity}: #{msg}\n"
11
+ end
12
+
13
+ class Runner
14
+ DEFAULT_OPTIONS = { skip_confirmation: false,
15
+ open_url_after_update: false }
16
+
17
+ def initialize(repo, opts = {})
18
+ @github = Github.open(repo)
19
+ @opts = DEFAULT_OPTIONS.merge(opts)
20
+
21
+ LOGGER.info "Logged in as: #{@github.user.login}"
22
+ LOGGER.info "Repository used: #{repo}"
23
+ end
24
+
25
+ def update_draft_release
26
+ draft_release = get_draft_release
27
+ lines = get_user_commit_lines
28
+
29
+ body = Content.new(draft_release.body)
30
+
31
+ if body.headings.empty?
32
+ body.append(lines)
33
+ else
34
+ line_num = ask_where_to_insert_line(body)
35
+ body.insert(line_num, lines)
36
+ end
37
+
38
+ unless ask_confirmation(draft_release.name, body)
39
+ LOGGER.warn('Update cancelled')
40
+ exit
41
+ end
42
+
43
+ LOGGER.info("Updating to URL: #{draft_release.html_url}")
44
+ @github.update_release(draft_release, body)
45
+
46
+ LOGGER.info("Release '#{draft_release.name}' updated!")
47
+ `open #{draft_release.html_url}` if @opts[:open_url_after_update]
48
+ end
49
+
50
+ private
51
+
52
+ def get_draft_release
53
+ draft_releases = @github.draft_releases
54
+
55
+ if draft_releases.empty?
56
+ LOGGER.error "Unable to find any drafts/releases in '#{@github.repo}'"
57
+ exit
58
+ end
59
+
60
+ ask_which_release(draft_releases)
61
+ end
62
+
63
+ def get_user_commit_lines
64
+ if @github.user_commits.empty?
65
+ LOGGER.error "No recent commit from '#{@github.user.login}' is found in '#{@github.repo}'"
66
+ exit
67
+ end
68
+
69
+ release_bodies = @github.releases.map(&:body).join
70
+
71
+ lines = @github.user_commits.map do |commit|
72
+ line = "#{Content.new(commit.commit.message).title} #{commit.sha}"
73
+
74
+ if release_bodies.include?(commit.sha[0..6])
75
+ LOGGER.warn "Commit existed: #{line}"
76
+ next nil
77
+ end
78
+
79
+ LOGGER.info "Prepare to insert line: #{line}"
80
+ line
81
+ end.compact
82
+
83
+ if lines.empty?
84
+ LOGGER.warn "All commits existed in the releases"
85
+ exit
86
+ end
87
+
88
+ lines
89
+ end
90
+
91
+ def ask_which_release(releases)
92
+ return releases.first if releases.size == 1
93
+
94
+ puts '##################################################'
95
+ puts 'Please select insert position: '
96
+ puts '##################################################'
97
+ releases.each_with_index do |release, i|
98
+ puts "#{i} -> #{release.name}"
99
+ end
100
+
101
+ print 'Enter number: '
102
+ releases[$stdin.gets.chomp.to_i]
103
+ end
104
+
105
+ def ask_where_to_insert_line(body)
106
+ if @opts[:insert_at_the_end]
107
+ return body.lines.size
108
+ end
109
+
110
+ headings = body.heading_indexes
111
+
112
+ if @opts[:insert_at_top_level]
113
+ return headings.empty? ? body.lines.size : [0, headings[0] - 1].max
114
+ end
115
+
116
+ if @opts[:insert_at] && (heading_index = body.find_heading(@opts[:insert_at]))
117
+ return body.lines.size if headings[-1] == heading_index
118
+ return headings[headings.index(heading_index) + 1] - 1
119
+ end
120
+
121
+ if @opts[:insert_at] && @opts[:create_heading]
122
+ body.append(["## #{@opts[:insert_at].capitalize} ##"])
123
+ return body.lines.size
124
+ end
125
+
126
+ puts '##################################################'
127
+ puts 'Please select insert position: '
128
+ puts '##################################################'
129
+
130
+ candidates = [0, *headings, body.lines.size - 1].uniq
131
+ candidates.each do |heading|
132
+ start_line_num = [heading - 3, 0].max
133
+ end_line_num = [heading + 3, body.lines.size - 1].min
134
+
135
+ (start_line_num..end_line_num).each do |l|
136
+ puts "[#{l.to_s.rjust(2)}] #{body.lines[l]}" unless body.lines[l].empty?
137
+ end
138
+
139
+ puts "=================================================="
140
+ end
141
+
142
+ print 'Enter line number: '
143
+ $stdin.gets.chomp.to_i + 1
144
+ end
145
+
146
+ def ask_confirmation(name, body)
147
+ puts '##################################################'
148
+ puts name
149
+ puts '=================================================='
150
+ puts body.to_s
151
+ puts '##################################################'
152
+
153
+ return true if !@opts[:kiasu_mode] && @opts[:skip_confirmation]
154
+
155
+ print 'Ok? (Y/N): '
156
+ $stdin.gets.chomp.upcase == 'Y'
157
+ end
158
+ end
159
+ end
@@ -0,0 +1,132 @@
1
+ require 'spec_helper'
2
+ require 'content'
3
+
4
+ RSpec.describe UpdateDraftRelease::Content do
5
+ describe '#initialize' do
6
+ it 'parse body with \n' do
7
+ body = UpdateDraftRelease::Content.new %(abc Efg\nabc\n## efg)
8
+ expect(body.lines).to eq(['abc Efg', 'abc', '## efg'])
9
+ expect(body.title).to eq('Abc Efg')
10
+ expect(body.headings).to eq(['## efg'])
11
+ expect(body.heading_indexes).to eq([2])
12
+ end
13
+
14
+ it 'parse body with \r\n' do
15
+ body = UpdateDraftRelease::Content.new %(abc\r\n## efg\r\nabc)
16
+ expect(body.lines).to eq(['abc', '## efg', 'abc'])
17
+ expect(body.title).to eq('Abc')
18
+ expect(body.headings).to eq(['## efg'])
19
+ expect(body.heading_indexes).to eq([1])
20
+ end
21
+ end
22
+
23
+ describe '#line_separator' do
24
+ context 'no line_separator exists' do
25
+ subject { UpdateDraftRelease::Content.new(%(line 1)).line_separator }
26
+ it { is_expected.to eq(%(\r\n)) }
27
+ end
28
+
29
+ context 'line_separator exists' do
30
+ subject { UpdateDraftRelease::Content.new(%(line 1\nline 2)).line_separator }
31
+ it { is_expected.to eq(%(\n)) }
32
+ end
33
+
34
+ context 'mixed line_separator exists' do
35
+ subject { UpdateDraftRelease::Content.new(%(line 1\nline 2\r\n)).line_separator }
36
+ it { is_expected.to eq(%(\n)) }
37
+ end
38
+ end
39
+
40
+ describe '#find_heading' do
41
+ subject { UpdateDraftRelease::Content.new %(# heading 1\r\nline 2\r\nline 3\r\n## heading 2\r\nline 5) }
42
+
43
+ it 'return nil if not found' do
44
+ expect(subject.find_heading('line 1')).to be(nil)
45
+ end
46
+
47
+ it 'find in different cases' do
48
+ expect(subject.find_heading('HEADING 1')).to eq(0)
49
+ end
50
+
51
+ it 'find in different heading level' do
52
+ expect(subject.find_heading('heading 2')).to eq(3)
53
+ end
54
+ end
55
+
56
+ describe '#append' do
57
+ subject { UpdateDraftRelease::Content.new %(line 1\r\nline 2\r\n) }
58
+
59
+ it 'add single line to the end' do
60
+ subject.append('new line')
61
+ expect(subject.line_separator).to eq(%(\r\n))
62
+ expect(subject.lines.size).to eq(4)
63
+ expect(subject.lines.last).to eq('new line')
64
+ end
65
+
66
+ it 'add lines to the end' do
67
+ subject.append(['new line 1', 'new line 2'])
68
+ expect(subject.line_separator).to eq(%(\r\n))
69
+ expect(subject.lines.size).to eq(6)
70
+ expect(subject.lines.last).to eq('new line 2')
71
+ end
72
+ end
73
+
74
+ describe '#insert' do
75
+ subject { UpdateDraftRelease::Content.new %(line 1\nline 2\n\nline 3\n) }
76
+
77
+ it 'add to the beginning' do
78
+ subject.insert(0, 'new line')
79
+ expect(subject.lines.size).to eq(6)
80
+ expect(subject.lines[0]).to eq('new line')
81
+ expect(subject.lines[1]).to eq('')
82
+ end
83
+
84
+ it 'add to any lines in between' do
85
+ subject.insert(1, 'new line')
86
+ expect(subject.lines.size).to eq(6)
87
+ expect(subject.lines[1]).to eq('')
88
+ expect(subject.lines[2]).to eq('new line')
89
+ end
90
+
91
+ it 'add to an empty line' do
92
+ subject.insert(2, 'new line')
93
+ expect(subject.lines.size).to eq(6)
94
+ expect(subject.lines[2]).to eq('')
95
+ expect(subject.lines[3]).to eq('new line')
96
+ expect(subject.lines[4]).to eq('')
97
+ end
98
+
99
+ it 'add to the end' do
100
+ subject.insert(4, 'new line')
101
+ expect(subject.lines.size).to eq(6)
102
+ expect(subject.lines[4]).to eq('')
103
+ expect(subject.lines[5]).to eq('new line')
104
+ end
105
+ end
106
+
107
+ describe '#include?' do
108
+ subject { UpdateDraftRelease::Content.new %(line 1\nline 2\n) }
109
+
110
+ it 'return true on inclusion' do
111
+ expect(subject.include?('1')).to be(true)
112
+ end
113
+
114
+ it 'return false on exclusion' do
115
+ expect(subject.include?('3')).to be(false)
116
+ end
117
+ end
118
+
119
+ describe '#to_s' do
120
+ let(:body) { %(line 1\n\nline 2) }
121
+ subject { UpdateDraftRelease::Content.new body }
122
+
123
+ it 'construct back itself' do
124
+ expect(subject.to_s).to eq(body)
125
+ end
126
+
127
+ it 'construct correct body' do
128
+ subject.append 'new line'
129
+ expect(subject.to_s).to eq(body << %(\n\nnew line))
130
+ end
131
+ end
132
+ end
@@ -0,0 +1,91 @@
1
+ # This file was generated by the `rspec --init` command. Conventionally, all
2
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
3
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
4
+ # this file to always be loaded, without a need to explicitly require it in any
5
+ # files.
6
+ #
7
+ # Given that it is always loaded, you are encouraged to keep this file as
8
+ # light-weight as possible. Requiring heavyweight dependencies from this file
9
+ # will add to the boot time of your test suite on EVERY test run, even for an
10
+ # individual file that may not need all of that loaded. Instead, consider making
11
+ # a separate helper file that requires the additional dependencies and performs
12
+ # the additional setup, and require it from the spec files that actually need
13
+ # it.
14
+ #
15
+ # The `.rspec` file also contains a few flags that are not defaults but that
16
+ # users commonly want.
17
+ #
18
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
19
+ RSpec.configure do |config|
20
+ # rspec-expectations config goes here. You can use an alternate
21
+ # assertion/expectation library such as wrong or the stdlib/minitest
22
+ # assertions if you prefer.
23
+ config.expect_with :rspec do |expectations|
24
+ # This option will default to `true` in RSpec 4. It makes the `description`
25
+ # and `failure_message` of custom matchers include text for helper methods
26
+ # defined using `chain`, e.g.:
27
+ # be_bigger_than(2).and_smaller_than(4).description
28
+ # # => "be bigger than 2 and smaller than 4"
29
+ # ...rather than:
30
+ # # => "be bigger than 2"
31
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
32
+ end
33
+
34
+ # rspec-mocks config goes here. You can use an alternate test double
35
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
36
+ config.mock_with :rspec do |mocks|
37
+ # Prevents you from mocking or stubbing a method that does not exist on
38
+ # a real object. This is generally recommended, and will default to
39
+ # `true` in RSpec 4.
40
+ mocks.verify_partial_doubles = true
41
+ end
42
+
43
+ # The settings below are suggested to provide a good initial experience
44
+ # with RSpec, but feel free to customize to your heart's content.
45
+ =begin
46
+ # These two settings work together to allow you to limit a spec run
47
+ # to individual examples or groups you care about by tagging them with
48
+ # `:focus` metadata. When nothing is tagged with `:focus`, all examples
49
+ # get run.
50
+ config.filter_run :focus
51
+ config.run_all_when_everything_filtered = true
52
+
53
+ # Limits the available syntax to the non-monkey patched syntax that is
54
+ # recommended. For more details, see:
55
+ # - http://myronmars.to/n/dev-blog/2012/06/rspecs-new-expectation-syntax
56
+ # - http://teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
57
+ # - http://myronmars.to/n/dev-blog/2014/05/notable-changes-in-rspec-3#new__config_option_to_disable_rspeccore_monkey_patching
58
+ config.disable_monkey_patching!
59
+
60
+ # This setting enables warnings. It's recommended, but in some cases may
61
+ # be too noisy due to issues in dependencies.
62
+ config.warnings = true
63
+
64
+ # Many RSpec users commonly either run the entire suite or an individual
65
+ # file, and it's useful to allow more verbose output when running an
66
+ # individual spec file.
67
+ if config.files_to_run.one?
68
+ # Use the documentation formatter for detailed output,
69
+ # unless a formatter has already been configured
70
+ # (e.g. via a command-line flag).
71
+ config.default_formatter = 'doc'
72
+ end
73
+
74
+ # Print the 10 slowest examples and example groups at the
75
+ # end of the spec run, to help surface which specs are running
76
+ # particularly slow.
77
+ config.profile_examples = 10
78
+
79
+ # Run specs in random order to surface order dependencies. If you find an
80
+ # order dependency and want to debug it, you can fix the order by providing
81
+ # the seed, which is printed after each run.
82
+ # --seed 1234
83
+ config.order = :random
84
+
85
+ # Seed global randomization in this process using the `--seed` CLI option.
86
+ # Setting this allows you to use `--seed` to deterministically reproduce
87
+ # test failures related to randomization by passing the same `--seed` value
88
+ # as the one that triggered the failure.
89
+ Kernel.srand config.seed
90
+ =end
91
+ end
@@ -0,0 +1,144 @@
1
+ require 'spec_helper'
2
+ require 'update_draft_release'
3
+
4
+ RSpec.describe UpdateDraftRelease::Runner do
5
+ let(:user) { double(login: 'user') }
6
+ let(:client) { double(user: user) }
7
+ let(:draft) { double(draft: true, name: 'draft', url: 'http://draft/', html_url: 'http://draft/html', body: 'draft') }
8
+ let(:release) { double(draft: false, name: '2015-07-02', body: 'release') }
9
+ let(:commit) do
10
+ double(committer: double(login: 'user'),
11
+ commit: double(message: 'message'),
12
+ sha: 'abc')
13
+ end
14
+
15
+ before do
16
+ allow(Octokit::Client).to receive(:new).and_return(client)
17
+ end
18
+
19
+ context 'when no valid release' do
20
+ let(:runner) { UpdateDraftRelease::Runner.new('repo/repo') }
21
+
22
+ it 'exit on no release' do
23
+ allow(client).to receive(:releases).and_return([])
24
+ expect { runner.update_draft_release }.to raise_error(SystemExit)
25
+ end
26
+
27
+ it 'exit on no draft release' do
28
+ allow(client).to receive(:releases).and_return([double(draft: false)])
29
+ expect { runner.update_draft_release }.to raise_error(SystemExit)
30
+ end
31
+
32
+ it 'ask which release on multiple draft releases' do
33
+ allow(client).to receive(:releases).and_return([draft, draft])
34
+
35
+ expect($stdin).to receive(:gets).and_return('1')
36
+ expect(client).to receive(:commits).and_return([])
37
+ expect { runner.update_draft_release }.to output.to_stdout.and raise_error(SystemExit)
38
+ end
39
+ end
40
+
41
+ context 'when no valid commits' do
42
+ let(:runner) { UpdateDraftRelease::Runner.new('repo/repo') }
43
+
44
+ before { allow(client).to receive(:releases).and_return([draft, release]) }
45
+
46
+ it 'exit on no commits' do
47
+ allow(client).to receive(:commits).and_return([])
48
+ expect { runner.update_draft_release }.to raise_error(SystemExit)
49
+ end
50
+
51
+ it 'exit on commits already in draft' do
52
+ allow(client).to receive(:commits).and_return([commit])
53
+ allow(draft).to receive(:body).and_return("Message #{commit.sha}")
54
+ expect { runner.update_draft_release }.to raise_error(SystemExit)
55
+ end
56
+
57
+ it 'exit on commits already in release' do
58
+ allow(client).to receive(:commits).and_return([commit])
59
+ allow(release).to receive(:body).and_return("Message #{commit.sha}")
60
+ expect { runner.update_draft_release }.to raise_error(SystemExit)
61
+ end
62
+ end
63
+
64
+ describe 'when things go well' do
65
+ before do
66
+ allow(client).to receive(:releases).and_return([release, draft, release])
67
+ allow(client).to receive(:commits).and_return([commit])
68
+ end
69
+
70
+ context 'basic usage case' do
71
+ let(:runner) do
72
+ UpdateDraftRelease::Runner.new('repo/repo', { skip_confirmation: true })
73
+ end
74
+
75
+ it 'update the release' do
76
+ expect(client).to receive(:update_release)
77
+ .with('http://draft/', body: %(draft\r\n\r\nMessage abc))
78
+ .and_return(true)
79
+ runner.update_draft_release
80
+ end
81
+ end
82
+
83
+ context 'with insert-at-top-level' do
84
+ let(:runner) do
85
+ UpdateDraftRelease::Runner.new('repo/repo', {
86
+ skip_confirmation: true,
87
+ insert_at_top_level: true
88
+ })
89
+ end
90
+
91
+ before do
92
+ allow(draft).to receive(:body).and_return(%(# h1\r\nCommit A\r\n# h2))
93
+ end
94
+
95
+ it 'update the release' do
96
+ expect(client).to receive(:update_release)
97
+ .with('http://draft/', body: %(Message abc\r\n\r\n# h1\r\nCommit A\r\n# h2))
98
+ .and_return(true)
99
+ runner.update_draft_release
100
+ end
101
+ end
102
+
103
+ context 'with insert-at section' do
104
+ let(:runner) do
105
+ UpdateDraftRelease::Runner.new('repo/repo', {
106
+ skip_confirmation: true,
107
+ insert_at: 'h2'
108
+ })
109
+ end
110
+
111
+ before do
112
+ allow(draft).to receive(:body).and_return(%(# h1\r\nCommit A\r\n# h2))
113
+ end
114
+
115
+ it 'update the release' do
116
+ expect(client).to receive(:update_release)
117
+ .with('http://draft/', body: %(# h1\r\nCommit A\r\n# h2\r\n\r\nMessage abc))
118
+ .and_return(true)
119
+ runner.update_draft_release
120
+ end
121
+ end
122
+
123
+ context 'with insert-at && create-heading' do
124
+ let(:runner) do
125
+ UpdateDraftRelease::Runner.new('repo/repo', {
126
+ skip_confirmation: true,
127
+ insert_at: 'h3',
128
+ create_heading: true
129
+ })
130
+ end
131
+
132
+ before do
133
+ allow(draft).to receive(:body).and_return(%(# h1\r\nCommit A\r\n# h2))
134
+ end
135
+
136
+ it 'update the release' do
137
+ expect(client).to receive(:update_release)
138
+ .with('http://draft/', body: %(# h1\r\nCommit A\r\n# h2\r\n\r\n## H3 ##\r\n\r\nMessage abc))
139
+ .and_return(true)
140
+ runner.update_draft_release
141
+ end
142
+ end
143
+ end
144
+ end
@@ -0,0 +1,22 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'update-draft-release'
3
+ s.version = '0.2.3'
4
+ s.authors = ['Wang Zhuochun']
5
+ s.email = 'zhuochun@hotmail.com'
6
+
7
+ s.summary = 'Update Draft Release'
8
+ s.description = 'Add your lastest commit to your GitHub repo\'s draft release'
9
+ s.homepage = 'https://github.com/zhuochun/update-draft-release'
10
+ s.license = 'MIT'
11
+
12
+ s.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
13
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
14
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ s.require_paths = ['lib']
16
+
17
+ s.add_runtime_dependency 'octokit', '~> 3.0'
18
+ s.add_runtime_dependency 'netrc', '~> 0.10.3'
19
+
20
+ s.add_development_dependency 'rake', '~> 10.4.2'
21
+ s.add_development_dependency 'rspec', '~> 3.2.0'
22
+ end
metadata ADDED
@@ -0,0 +1,119 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: update-draft-release
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.2.3
5
+ platform: ruby
6
+ authors:
7
+ - Wang Zhuochun
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-07-17 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: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
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.10.3
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.10.3
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.4.2
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 10.4.2
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.2.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.2.0
69
+ description: Add your lastest commit to your GitHub repo's draft release
70
+ email: zhuochun@hotmail.com
71
+ executables:
72
+ - update-draft-release
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - ".gitignore"
77
+ - ".rspec"
78
+ - Gemfile
79
+ - Gemfile.lock
80
+ - LICENSE.txt
81
+ - README.md
82
+ - Rakefile
83
+ - bin/update-draft-release
84
+ - lib/content.rb
85
+ - lib/github.rb
86
+ - lib/update_draft_release.rb
87
+ - spec/content_spec.rb
88
+ - spec/spec_helper.rb
89
+ - spec/update_draft_release_spec.rb
90
+ - update-draft-release.gemspec
91
+ homepage: https://github.com/zhuochun/update-draft-release
92
+ licenses:
93
+ - MIT
94
+ metadata: {}
95
+ post_install_message:
96
+ rdoc_options: []
97
+ require_paths:
98
+ - lib
99
+ required_ruby_version: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ required_rubygems_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - ">="
107
+ - !ruby/object:Gem::Version
108
+ version: '0'
109
+ requirements: []
110
+ rubyforge_project:
111
+ rubygems_version: 2.4.8
112
+ signing_key:
113
+ specification_version: 4
114
+ summary: Update Draft Release
115
+ test_files:
116
+ - spec/content_spec.rb
117
+ - spec/spec_helper.rb
118
+ - spec/update_draft_release_spec.rb
119
+ has_rdoc: