git-pr-release-roadrunner 0.0.1

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
+ SHA256:
3
+ metadata.gz: 7a689cf932f38077f8f0d23da3949b9c98261644f20ed22870e2d0ae4fb0b147
4
+ data.tar.gz: 9ba85b17b301d6aec00a0fa0bb7acac42a084dd554a4573c2c6bd44facdb7a04
5
+ SHA512:
6
+ metadata.gz: ce83873a6c66bce05955b09ef4d9c7bc0e200fd87a885381c87c15fbcad24915cf89aec3c89d854f5d7764cf43492bba0a1b751c48cb22a4412fb3733c5e504c
7
+ data.tar.gz: a180b841f26f58261e6d6cb2cbb259d7e3b986fc7920e5155a0ca7084f44b38737fa03fe30efc4b9459d5e762a7a542d7ed920aa3b50d89fb6e61b6219055eb6
data/.DS_Store ADDED
Binary file
@@ -0,0 +1,13 @@
1
+ version: 2.1
2
+ jobs:
3
+ build:
4
+ docker:
5
+ - image: ruby:2.5.7
6
+ steps:
7
+ - checkout
8
+ - run:
9
+ name: Run the default task
10
+ command: |
11
+ gem install bundler -v 2.3.19
12
+ bundle install
13
+ bundle exec rake
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ /.bundle/
2
+ *.gem
3
+ Gemfile.lock
4
+ /.rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.rubocop.yml ADDED
@@ -0,0 +1,13 @@
1
+ AllCops:
2
+ TargetRubyVersion: 2.5
3
+
4
+ Style/StringLiterals:
5
+ Enabled: true
6
+ EnforcedStyle: double_quotes
7
+
8
+ Style/StringLiteralsInInterpolation:
9
+ Enabled: true
10
+ EnforcedStyle: double_quotes
11
+
12
+ Layout/LineLength:
13
+ Max: 120
@@ -0,0 +1,84 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6
+
7
+ We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community.
8
+
9
+ ## Our Standards
10
+
11
+ Examples of behavior that contributes to a positive environment for our community include:
12
+
13
+ * Demonstrating empathy and kindness toward other people
14
+ * Being respectful of differing opinions, viewpoints, and experiences
15
+ * Giving and gracefully accepting constructive feedback
16
+ * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience
17
+ * Focusing on what is best not just for us as individuals, but for the overall community
18
+
19
+ Examples of unacceptable behavior include:
20
+
21
+ * The use of sexualized language or imagery, and sexual attention or
22
+ advances of any kind
23
+ * Trolling, insulting or derogatory comments, and personal or political attacks
24
+ * Public or private harassment
25
+ * Publishing others' private information, such as a physical or email
26
+ address, without their explicit permission
27
+ * Other conduct which could reasonably be considered inappropriate in a
28
+ professional setting
29
+
30
+ ## Enforcement Responsibilities
31
+
32
+ Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful.
33
+
34
+ Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate.
35
+
36
+ ## Scope
37
+
38
+ This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event.
39
+
40
+ ## Enforcement
41
+
42
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at pcorrea@roadrunnerwm.com. All complaints will be reviewed and investigated promptly and fairly.
43
+
44
+ All community leaders are obligated to respect the privacy and security of the reporter of any incident.
45
+
46
+ ## Enforcement Guidelines
47
+
48
+ Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct:
49
+
50
+ ### 1. Correction
51
+
52
+ **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community.
53
+
54
+ **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested.
55
+
56
+ ### 2. Warning
57
+
58
+ **Community Impact**: A violation through a single incident or series of actions.
59
+
60
+ **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban.
61
+
62
+ ### 3. Temporary Ban
63
+
64
+ **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior.
65
+
66
+ **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban.
67
+
68
+ ### 4. Permanent Ban
69
+
70
+ **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals.
71
+
72
+ **Consequence**: A permanent ban from any sort of public interaction within the community.
73
+
74
+ ## Attribution
75
+
76
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0,
77
+ available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html.
78
+
79
+ Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity).
80
+
81
+ [homepage]: https://www.contributor-covenant.org
82
+
83
+ For answers to common questions about this code of conduct, see the FAQ at
84
+ https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations.
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+
3
+ source "https://rubygems.org"
4
+
5
+ # gem "rails"
6
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2022 Peter Correa
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,37 @@
1
+ # Git::Pr::Release::Roadrunner
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/git/pr/release/roadrunner`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Install the gem and add to the application's Gemfile by executing:
10
+
11
+ $ bundle add git-pr-release-roadrunner
12
+
13
+ If bundler is not being used to manage dependencies, install the gem by executing:
14
+
15
+ $ gem install git-pr-release-roadrunner
16
+
17
+ ## Usage
18
+
19
+ TODO: Write usage instructions here
20
+
21
+ ## Development
22
+
23
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
24
+
25
+ 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 the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
26
+
27
+ ## Contributing
28
+
29
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/git-pr-release-roadrunner. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/[USERNAME]/git-pr-release-roadrunner/blob/master/CODE_OF_CONDUCT.md).
30
+
31
+ ## License
32
+
33
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
34
+
35
+ ## Code of Conduct
36
+
37
+ Everyone interacting in the Git::Pr::Release::Roadrunner project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/git-pr-release-roadrunner/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
data/bin/console ADDED
@@ -0,0 +1,15 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require "bundler/setup"
5
+ require "git/pr/release/roadrunner"
6
+
7
+ # You can add fixtures and/or initialization code here to make experimenting
8
+ # with your gem easier. You can also use a different console, if you like.
9
+
10
+ # (If you use this, don't forget to add pry to your Gemfile!)
11
+ # require "pry"
12
+ # Pry.start
13
+
14
+ require "irb"
15
+ 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,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "git/pr/release"
4
+
5
+ Git::Pr::Release::CLI.start
@@ -0,0 +1,30 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "git-pr-release-roadrunner"
7
+ spec.version = '0.0.1'
8
+ spec.authors = ["trashypete"]
9
+ spec.email = ["n/a"]
10
+ spec.summary = 'Creates a release pull request'
11
+ spec.description = 'git-pr-release creates a pull request which summarizes feature branches that are to be released into production'
12
+ spec.homepage = ''
13
+
14
+ spec.files = `git ls-files`.split($/)
15
+ spec.bindir = "exe"
16
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
17
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
18
+ spec.require_paths = ["lib"]
19
+
20
+ spec.add_dependency 'octokit', '>= 4.23.0'
21
+ spec.add_dependency 'highline'
22
+ spec.add_dependency 'colorize'
23
+ spec.add_dependency 'diff-lcs'
24
+
25
+ spec.add_development_dependency 'rspec'
26
+ spec.add_development_dependency 'timecop'
27
+ spec.add_development_dependency 'webmock'
28
+
29
+ spec.license = 'MIT'
30
+ end
@@ -0,0 +1,271 @@
1
+ require 'octokit'
2
+ require 'optparse'
3
+
4
+ module Git
5
+ module Pr
6
+ module Release
7
+ class CLI
8
+ include Git::Pr::Release::Util
9
+ attr_reader :repository, :production_branch, :staging_branch, :template_path, :labels
10
+
11
+ def self.start
12
+ result = self.new.start
13
+ exit result
14
+ end
15
+
16
+ def initialize
17
+ @dry_run = false
18
+ @json = false
19
+ @no_fetch = false
20
+ @squashed = false
21
+ end
22
+
23
+ puts "---Generating RoadRunner Release PR----"
24
+
25
+ def start
26
+ OptionParser.new do |opts|
27
+ opts.on('-n', '--dry-run', 'Do not create/update a PR. Just prints out') do |v|
28
+ @dry_run = v
29
+ end
30
+ opts.on('--json', 'Show data of target PRs in JSON format') do |v|
31
+ @json = v
32
+ end
33
+ opts.on('--no-fetch', 'Do not fetch from remote repo before determining target PRs (CI friendly)') do |v|
34
+ @no_fetch = v
35
+ end
36
+ opts.on('--squashed', 'Handle squash merged PRs') do |v|
37
+ @squashed = v
38
+ end
39
+ opts.on('--overwrite-description', 'Force overwrite PR description') do |v|
40
+ @overwrite_description = v
41
+ end
42
+ end.parse!
43
+
44
+ ### Set up configuration
45
+ configure
46
+
47
+ ### Fetch merged PRs
48
+ merged_prs = fetch_merged_prs
49
+ if merged_prs.empty?
50
+ say 'No pull requests to be released', :error
51
+ return 1
52
+ end
53
+
54
+ ### Create a release PR
55
+ create_release_pr(merged_prs)
56
+ return 0
57
+ end
58
+
59
+ def client
60
+ @client ||= Octokit::Client.new :access_token => obtain_token!
61
+ end
62
+
63
+ def configure
64
+ host, @repository, scheme = host_and_repository_and_scheme
65
+
66
+ if host
67
+ if scheme == 'https' # GitHub Enterprise
68
+ ssl_no_verify = %w[true 1].include? ENV.fetch('GIT_PR_RELEASE_SSL_NO_VERIFY') { git_config('ssl-no-verify') }
69
+ if ssl_no_verify
70
+ OpenSSL::SSL.const_set :VERIFY_PEER, OpenSSL::SSL::VERIFY_NONE
71
+ end
72
+ end
73
+
74
+ Octokit.configure do |c|
75
+ c.api_endpoint = "#{scheme}://#{host}/api/v3"
76
+ c.web_endpoint = "#{scheme}://#{host}/"
77
+ end
78
+ end
79
+
80
+ @production_branch = ENV.fetch('GIT_PR_RELEASE_BRANCH_PRODUCTION') { git_config('branch.production') } || 'master'
81
+ @staging_branch = ENV.fetch('GIT_PR_RELEASE_BRANCH_STAGING') { git_config('branch.staging') } || 'staging'
82
+ @template_path = ENV.fetch('GIT_PR_RELEASE_TEMPLATE') { git_config('template') }
83
+
84
+ _labels = ENV.fetch('GIT_PR_RELEASE_LABELS') { git_config('labels') }
85
+ @labels = _labels && _labels.split(/\s*,\s*/) || []
86
+
87
+ say "Repository: #{repository}", :debug
88
+ say "Production branch: #{production_branch}", :debug
89
+ say "Staging branch: #{staging_branch}", :debug
90
+ say "Template path: #{template_path}", :debug
91
+ say "Labels #{labels}", :debug
92
+ end
93
+
94
+ def fetch_merged_prs
95
+ bool = git(:'rev-parse', '--is-shallow-repository').first.chomp
96
+ if bool == 'true'
97
+ git(:fetch, '--unshallow')
98
+ end
99
+ git :remote, 'update', 'origin' unless @no_fetch
100
+
101
+ merged_pull_request_numbers = fetch_merged_pr_numbers_from_git_remote
102
+ if @squashed
103
+ merged_pull_request_numbers.concat(fetch_squash_merged_pr_numbers_from_github)
104
+ end
105
+
106
+ merged_prs = merged_pull_request_numbers.uniq.sort.map do |nr|
107
+ pr = client.pull_request repository, nr
108
+ say "To be released: ##{pr.number} #{pr.title}", :notice
109
+ pr
110
+ end
111
+
112
+ merged_prs
113
+ end
114
+
115
+ def fetch_merged_pr_numbers_from_git_remote
116
+ merged_feature_head_sha1s = git(:log, '--merges', '--pretty=format:%P', "origin/#{production_branch}..origin/#{staging_branch}").map do |line|
117
+ main_sha1, feature_sha1 = line.chomp.split /\s+/
118
+ feature_sha1
119
+ end
120
+
121
+ git('ls-remote', 'origin', 'refs/pull/*/head').map do |line|
122
+ sha1, ref = line.chomp.split /\s+/
123
+
124
+ if merged_feature_head_sha1s.include? sha1
125
+ if %r<^refs/pull/(\d+)/head$>.match ref
126
+ pr_number = $1.to_i
127
+
128
+ if git('merge-base', sha1, "origin/#{production_branch}").first.chomp == sha1
129
+ say "##{pr_number} (#{sha1}) is already merged into #{production_branch}", :debug
130
+ else
131
+ pr_number
132
+ end
133
+ else
134
+ say "Bad pull request head ref format: #{ref}", :warn
135
+ nil
136
+ end
137
+ end
138
+ end.compact
139
+ end
140
+
141
+ def search_issue_numbers(query)
142
+ sleep 1
143
+ say "search issues with query:#{query}", :debug
144
+ # Fortunately, we don't need to take care of the page count in response, because
145
+ # the default value of per_page is 30 and we can't specify more than 30 commits due to
146
+ # the length limit specification of the query string.
147
+ client.search_issues("#{query}")[:items].map(&:number)
148
+ end
149
+
150
+ def fetch_squash_merged_pr_numbers_from_github
151
+ # When "--abbrev" is specified, the length of the each line of the stdout isn't fixed.
152
+ # It is just a minimum length, and if the commit cannot be uniquely identified with
153
+ # that length, a longer commit hash will be displayed.
154
+ # We specify this option to minimize the length of the query string, but we use
155
+ # "--abbrev=7" because the SHA syntax of the search API requires a string of at
156
+ # least 7 characters.
157
+ # ref. https://docs.github.com/en/search-github/searching-on-github/searching-issues-and-pull-requests#search-by-commit-sha
158
+ # This is done because there is a length limit on the API query string, and we want
159
+ # to create a string with the minimum possible length.
160
+ shas = git(:log, '--pretty=format:%h', "--abbrev=7", "--no-merges", "--first-parent",
161
+ "origin/#{production_branch}..origin/#{staging_branch}").map(&:chomp)
162
+
163
+ pr_nums = []
164
+ query_base = "repo:#{repository} is:pr is:closed"
165
+ query = query_base
166
+ # Make bulk requests with multiple SHAs of the maximum possible length.
167
+ # If multiple SHAs are specified, the issue search API will treat it like an OR search,
168
+ # and all the pull requests will be searched.
169
+ # This is difficult to read from the current documentation, but that is the current
170
+ # behavior and GitHub support has responded that this is the spec.
171
+ shas.each do |sha|
172
+ # Longer than 256 characters are not supported in the query.
173
+ # ref. https://docs.github.com/en/rest/reference/search#limitations-on-query-length
174
+ if query.length + 1 + sha.length >= 256
175
+ pr_nums.concat(search_issue_numbers(query))
176
+ query = query_base
177
+ end
178
+ query += " " + sha
179
+ end
180
+ if query != query_base
181
+ pr_nums.concat(search_issue_numbers(query))
182
+ end
183
+ pr_nums
184
+ end
185
+
186
+ def create_release_pr(merged_prs)
187
+ found_release_pr = detect_existing_release_pr
188
+ create_mode = found_release_pr.nil?
189
+
190
+ if create_mode
191
+ if @dry_run
192
+ release_pr = nil
193
+ changed_files = []
194
+ else
195
+ release_pr = prepare_release_pr
196
+ changed_files = pull_request_files(release_pr)
197
+ end
198
+ else
199
+ release_pr = found_release_pr
200
+ changed_files = pull_request_files(release_pr)
201
+ end
202
+
203
+ pr_title, pr_body = if @overwrite_description
204
+ build_pr_title_and_body(release_pr, merged_prs, changed_files, template_path)
205
+ else
206
+ build_and_merge_pr_title_and_body(release_pr, merged_prs, changed_files)
207
+ end
208
+
209
+ if @dry_run
210
+ say 'Dry-run. Not updating PR', :info
211
+ say pr_title, :notice
212
+ say pr_body, :notice
213
+ dump_result_as_json( release_pr, merged_prs, changed_files ) if @json
214
+ return
215
+ end
216
+
217
+ update_release_pr(release_pr, pr_title, pr_body)
218
+
219
+ say "#{create_mode ? 'Created' : 'Updated'} pull request: #{release_pr.rels[:html].href}", :notice
220
+ dump_result_as_json( release_pr, merged_prs, changed_files ) if @json
221
+ end
222
+
223
+ def detect_existing_release_pr
224
+ say 'Searching for existing release pull requests...', :info
225
+ user=repository.split("/")[0]
226
+ client.pull_requests(repository, head: "#{user}:#{staging_branch}", base: production_branch).first
227
+ end
228
+
229
+ def prepare_release_pr
230
+ client.create_pull_request(
231
+ repository, production_branch, staging_branch, 'Preparing release pull request...', ''
232
+ )
233
+ end
234
+
235
+ def build_and_merge_pr_title_and_body(release_pr, merged_prs, changed_files)
236
+ # release_pr is nil when dry_run && create_mode
237
+ old_body = (release_pr && release_pr.body != nil) ? release_pr.body : ""
238
+ pr_title, new_body = build_pr_title_and_body(release_pr, merged_prs, changed_files, template_path)
239
+
240
+ [pr_title, merge_pr_body(old_body, new_body)]
241
+ end
242
+
243
+ def update_release_pr(release_pr, pr_title, pr_body)
244
+ say 'Pull request body:', :debug
245
+ say pr_body, :debug
246
+
247
+ client.update_pull_request(
248
+ repository, release_pr.number, :title => pr_title, :body => pr_body
249
+ )
250
+
251
+ unless labels.empty?
252
+ client.add_labels_to_an_issue(
253
+ repository, release_pr.number, labels
254
+ )
255
+ end
256
+ end
257
+
258
+ # Fetch PR files of specified pull_request
259
+ def pull_request_files(pull_request)
260
+ return [] if pull_request.nil?
261
+
262
+ # Fetch files as many as possible
263
+ client.auto_paginate = true
264
+ files = client.pull_request_files repository, pull_request.number
265
+ client.auto_paginate = false
266
+ return files
267
+ end
268
+ end
269
+ end
270
+ end
271
+ end
@@ -0,0 +1,23 @@
1
+ module Git
2
+ module Pr
3
+ module Release
4
+ class DummyPullRequest
5
+ def initialize
6
+ # nop
7
+ end
8
+
9
+ def to_checklist_item
10
+ "- [ ] #??? THIS IS DUMMY PULL REQUEST"
11
+ end
12
+
13
+ def html_link
14
+ 'http://github.com/DUMMY/DUMMY/issues/?'
15
+ end
16
+
17
+ def to_hash
18
+ { :data => {} }
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,54 @@
1
+ module Git
2
+ module Pr
3
+ module Release
4
+ class PullRequest
5
+ include Git::Pr::Release::Util
6
+ extend Git::Pr::Release::Util
7
+ attr_reader :pr
8
+
9
+ def initialize(pr)
10
+ @pr = pr
11
+ end
12
+
13
+ def to_checklist_item(print_title = false)
14
+ if print_title
15
+ "- [ ] ##{pr.number} #{pr.title}" + mention
16
+ else
17
+ "- [ ] ##{pr.number}" + mention
18
+ end
19
+ end
20
+
21
+ def html_link
22
+ pr.rels[:html].href
23
+ end
24
+
25
+ def to_hash
26
+ { :data => @pr.to_hash }
27
+ end
28
+
29
+ def mention
30
+ mention = case PullRequest.mention_type
31
+ when 'author'
32
+ pr.user ? "@#{pr.user.login}" : nil
33
+ else
34
+ pr.assignee ? "@#{pr.assignee.login}" : pr.user ? "@#{pr.user.login}" : nil
35
+ end
36
+
37
+ mention ? " #{mention}" : ""
38
+ end
39
+
40
+ def self.mention_type
41
+ @mention_type ||= (ENV.fetch('GIT_PR_RELEASE_MENTION') { git_config('mention') } || 'default')
42
+ end
43
+
44
+ def method_missing(name, *args, &block)
45
+ @pr.public_send name, *args, &block
46
+ end
47
+
48
+ def respond_to_missing?(name, include_private = false)
49
+ @pr.respond_to?(name, include_private)
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end