plan_my_stuff 0.6.0 → 0.7.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 69661ace546ff5f775e0e9fb5e4a153c3aca9e68da0b568e85238d8b66ef620a
4
- data.tar.gz: e0698c727fe6c3f1e8e135d0a2b1860731188dc01496065e3622a0a1d6ef0c45
3
+ metadata.gz: c4ce40c49bbe2d0ef870cf9983a5571631bdcce7f3ce52c31d5cf9885b143e3b
4
+ data.tar.gz: 8e62775d14932c50fe1b69cf76990345adf697dbdf509603eb7d5b4e35cc982f
5
5
  SHA512:
6
- metadata.gz: 876ac7c9c1baf371e09d81535324ae9a35bcd1c3a30509931395e274a229fcf25397ba1377450cb6a8ad6465f0474174ea664579b59f0d407c9b83ee08523647
7
- data.tar.gz: 89c4a1865f38c614c05d802c02d267b0ff2e83339da936403fac08f3d98476a6b87b722eecf422b5ee8f101f5db1ce75e8d3f836a3f54dd0ca86713df3146feb
6
+ metadata.gz: cf7fcd9a19a7845293c4b52f69ac7ef0cd9aa966bd0ddeb8851521d842e21f98a6e8ef49996125044bc453d99336ea086852d2d605951d348052a3ce16d2f250
7
+ data.tar.gz: 9f30fdb98fd6977eeb4362fe41f99472b4771299fa123a080bc83900c65bb794f69f19d5cdb1642efb4867435413ce01169014555641264896b1465b54dc6952
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Added
6
+
7
+ - `Issue#user_link` returns the per-issue URL in the consuming app, computed from `config.issues_url_prefix` + issue number
8
+
9
+ ### Changed
10
+
11
+ - GitHub issues created/updated by PMS now render a markdown link `[Org/Repo#number](user_link)` as the visible body (previously empty); skipped when `issues_url_prefix` is unset
12
+
3
13
  ## 0.6.0
4
14
 
5
15
  ### Breaking
@@ -93,8 +93,12 @@ PMS.configure do |config|
93
93
  # --------------------------------------------------------------------------
94
94
  # URL prefix
95
95
  # --------------------------------------------------------------------------
96
- # Prefix for building user-facing ticket URLs in your app.
97
- # config.issues_url_prefix = 'https://myapp.example.com/tickets/'
96
+ # Prefix for building user-facing ticket URLs in your app. The issue
97
+ # number is appended to form `Issue#user_link`, which the gem also
98
+ # writes as the visible body of the GitHub issue.
99
+ # Recommended default:
100
+ # config.issues_url_prefix =
101
+ # "#{Rails.application.config.action_mailer.default_url_options[:host]}/issues"
98
102
 
99
103
  # --------------------------------------------------------------------------
100
104
  # Request gateway
@@ -82,6 +82,17 @@ module PlanMyStuff
82
82
  number = read_field(result, :number)
83
83
  store_etag_to_cache(client, resolved_repo, number, result, cache_writer: :write_issue)
84
84
 
85
+ link_body = visible_body_for(number, resolved_repo)
86
+ if link_body.present?
87
+ result = client.rest(
88
+ :update_issue,
89
+ resolved_repo,
90
+ number,
91
+ body: MetadataParser.serialize(issue_metadata.to_h, link_body),
92
+ )
93
+ store_etag_to_cache(client, resolved_repo, number, result, cache_writer: :write_issue)
94
+ end
95
+
85
96
  issue = find(number, repo: resolved_repo)
86
97
 
87
98
  if add_to_project.present?
@@ -147,7 +158,7 @@ module PlanMyStuff
147
158
  case metadata
148
159
  when PlanMyStuff::IssueMetadata
149
160
  metadata.validate_custom_fields!
150
- options[:body] = MetadataParser.serialize(metadata.to_h, '')
161
+ options[:body] = MetadataParser.serialize(metadata.to_h, visible_body_for(number, resolved_repo))
151
162
  when Hash
152
163
  current = client.rest(:issue, resolved_repo, number)
153
164
  current_body = current.respond_to?(:body) ? current.body : current[:body]
@@ -162,7 +173,7 @@ module PlanMyStuff
162
173
  merged_custom_fields,
163
174
  ).validate!
164
175
 
165
- options[:body] = MetadataParser.serialize(existing_metadata, '')
176
+ options[:body] = MetadataParser.serialize(existing_metadata, visible_body_for(number, resolved_repo))
166
177
  end
167
178
 
168
179
  update_body_comment(number, resolved_repo, body) if body
@@ -235,6 +246,26 @@ module PlanMyStuff
235
246
 
236
247
  private
237
248
 
249
+ # Builds the visible body string written to GitHub for an issue:
250
+ # a markdown link to the consuming-app per-issue URL (carrying
251
+ # the repo as a +?repo=+ query param so the consuming app knows
252
+ # which repo this issue lives in), labelled with the GitHub
253
+ # +Org/Repo#number+. Returns +""+ when either
254
+ # +config.issues_url_prefix+ or +number+ is missing.
255
+ #
256
+ # @param number [Integer]
257
+ # @param repo [String] full repo path, e.g. +"BrandsInsurance/Element"+
258
+ #
259
+ # @return [String]
260
+ #
261
+ def visible_body_for(number, repo)
262
+ prefix = PlanMyStuff.configuration.issues_url_prefix
263
+ return '' if prefix.blank? || number.blank?
264
+
265
+ url = "#{prefix.to_s.chomp('/')}/#{number}?repo=#{URI.encode_www_form_component(repo)}"
266
+ "[#{repo}##{number}](#{url})"
267
+ end
268
+
238
269
  # Hydrates an Issue from a GitHub API response.
239
270
  #
240
271
  # @param github_issue [Object] Octokit issue response
@@ -298,6 +329,20 @@ module PlanMyStuff
298
329
  @body_dirty = true
299
330
  end
300
331
 
332
+ # @return [String, nil] per-issue URL in the consuming app
333
+ # (+config.issues_url_prefix+ + +"/"+ + +number+ + +"?repo=Org/Repo"+,
334
+ # or +nil+ when either prefix or number is missing). Also rendered
335
+ # as the destination of the markdown link in the GitHub issue body.
336
+ def user_link
337
+ prefix = PlanMyStuff.configuration.issues_url_prefix
338
+ return if prefix.blank? || number.blank?
339
+
340
+ base = "#{prefix.to_s.chomp('/')}/#{number}"
341
+ return base if repo.blank?
342
+
343
+ "#{base}?repo=#{URI.encode_www_form_component(repo.full_name)}"
344
+ end
345
+
301
346
  # @return [Array<PlanMyStuff::Approval>] all required approvers (pending + approved)
302
347
  def approvers
303
348
  metadata.approvals
@@ -3,7 +3,7 @@
3
3
  module PlanMyStuff
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 6
6
+ MINOR = 7
7
7
  TINY = 0
8
8
 
9
9
  # Set PRE to nil unless it's a pre-release (beta, rc, etc.)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: plan_my_stuff
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.0
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance