Class: PlanMyStuff::IssueMetadata

Inherits:
BaseMetadata show all
Defined in:
lib/plan_my_stuff/issue_metadata.rb

Constant Summary

Constants inherited from BaseMetadata

BaseMetadata::SCHEMA_VERSION

Instance Attribute Summary collapse

Attributes inherited from BaseMetadata

#app_name, #created_by, #custom_fields, #gem_version, #rails_env, #schema_version, #visibility

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseMetadata

#internal?, #public?, #to_json, #validate_custom_fields!

Constructor Details

#initializeIssueMetadata

Returns a new instance of IssueMetadata.



170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/plan_my_stuff/issue_metadata.rb', line 170

def initialize
  super
  @priority_list = false
  @priority_list_priority = -1
  @visibility_allowlist = []
  @auto_complete = true
  @links = []
  @approvals = []
  @waiting_on_user_at = nil
  @waiting_on_approval_at = nil
  @next_reminder_at = nil
  @reminder_days = nil
  @closed_by_inactivity = false
  @archived_at = nil
end

Instance Attribute Details

#approvalsArray<PlanMyStuff::Approval>

Returns manager approvals required on this issue. See Issue.request_approvals! and Issue#fully_approved?.

Returns:

  • (Array<PlanMyStuff::Approval>)

    manager approvals required on this issue. See Issue.request_approvals! and Issue#fully_approved?.



25
26
27
# File 'lib/plan_my_stuff/issue_metadata.rb', line 25

def approvals
  @approvals
end

#archived_atTime?

Returns when the archive sweep tagged this issue as archived.

Returns:

  • (Time, nil)

    when the archive sweep tagged this issue as archived



38
39
40
# File 'lib/plan_my_stuff/issue_metadata.rb', line 38

def archived_at
  @archived_at
end

#auto_completeBoolean

Returns whether to auto-complete on deployment (default: true).

Returns:

  • (Boolean)

    whether to auto-complete on deployment (default: true)



18
19
20
# File 'lib/plan_my_stuff/issue_metadata.rb', line 18

def auto_complete
  @auto_complete
end

#closed_by_inactivityBoolean

Returns whether this issue was auto-closed by the inactivity sweep.

Returns:

  • (Boolean)

    whether this issue was auto-closed by the inactivity sweep



36
37
38
# File 'lib/plan_my_stuff/issue_metadata.rb', line 36

def closed_by_inactivity
  @closed_by_inactivity
end

#commit_shaString?

Returns merged PR commit SHA for release tracking.

Returns:

  • (String, nil)

    merged PR commit SHA for release tracking



16
17
18
# File 'lib/plan_my_stuff/issue_metadata.rb', line 16

def commit_sha
  @commit_sha
end

#issues_urlString?

Returns user-facing URL in the consuming app.

Returns:

  • (String, nil)

    user-facing URL in the consuming app



8
9
10
# File 'lib/plan_my_stuff/issue_metadata.rb', line 8

def issues_url
  @issues_url
end

Returns metadata-backed issue relationships. Only :related links live here; native relationships (blocking, parent, sub_ticket, duplicate_of) live on GitHub.

Returns:

  • (Array<PlanMyStuff::Link>)

    metadata-backed issue relationships. Only :related links live here; native relationships (blocking, parent, sub_ticket, duplicate_of) live on GitHub.



22
23
24
# File 'lib/plan_my_stuff/issue_metadata.rb', line 22

def links
  @links
end

#next_reminder_atTime?

Returns when the next reminder event should fire for this issue.

Returns:

  • (Time, nil)

    when the next reminder event should fire for this issue



31
32
33
# File 'lib/plan_my_stuff/issue_metadata.rb', line 31

def next_reminder_at
  @next_reminder_at
end

#priority_listBoolean

Returns whether this issue appears on the priority dashboard.

Returns:

  • (Boolean)

    whether this issue appears on the priority dashboard



10
11
12
# File 'lib/plan_my_stuff/issue_metadata.rb', line 10

def priority_list
  @priority_list
end

#priority_list_priorityInteger

Returns sort order on priority dashboard (-1 = unranked).

Returns:

  • (Integer)

    sort order on priority dashboard (-1 = unranked)



12
13
14
# File 'lib/plan_my_stuff/issue_metadata.rb', line 12

def priority_list_priority
  @priority_list_priority
end

#reminder_daysArray<Integer>?

Returns per-issue override of config.reminder_days; applies to both waiting kinds.

Returns:

  • (Array<Integer>, nil)

    per-issue override of config.reminder_days; applies to both waiting kinds



34
35
36
# File 'lib/plan_my_stuff/issue_metadata.rb', line 34

def reminder_days
  @reminder_days
end

#responded_atTime?

Returns first support action timestamp, nil until set.

Returns:

  • (Time, nil)

    first support action timestamp, nil until set



6
7
8
# File 'lib/plan_my_stuff/issue_metadata.rb', line 6

def responded_at
  @responded_at
end

#visibility_allowlistArray<Integer>

Returns user IDs of non-support users allowed to view internal comments.

Returns:

  • (Array<Integer>)

    user IDs of non-support users allowed to view internal comments



14
15
16
# File 'lib/plan_my_stuff/issue_metadata.rb', line 14

def visibility_allowlist
  @visibility_allowlist
end

#waiting_on_approval_atTime?

Returns when the issue entered “waiting on approval” state.

Returns:

  • (Time, nil)

    when the issue entered “waiting on approval” state



29
30
31
# File 'lib/plan_my_stuff/issue_metadata.rb', line 29

def waiting_on_approval_at
  @waiting_on_approval_at
end

#waiting_on_user_atTime?

Returns when the issue entered “waiting on user reply” state.

Returns:

  • (Time, nil)

    when the issue entered “waiting on user reply” state



27
28
29
# File 'lib/plan_my_stuff/issue_metadata.rb', line 27

def waiting_on_user_at
  @waiting_on_user_at
end

Class Method Details

.build(user:, visibility: 'public', custom_fields: {}) ⇒ IssueMetadata

Builds a new IssueMetadata for issue creation, auto-filling gem defaults

Parameters:

  • user (Object, Integer)

    user object or user_id

  • custom_fields (Hash) (defaults to: {})

    app-defined field values

Returns:



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/plan_my_stuff/issue_metadata.rb', line 77

def build(user:, visibility: 'public', custom_fields: {})
   = new
  apply_common_build(
    ,
    user: user,
    visibility: visibility,
    custom_fields_data: custom_fields,
    custom_fields_schema: PlanMyStuff.configuration.custom_fields_for(:issue),
  )

  .responded_at = nil
  .issues_url = build_issues_url(PlanMyStuff.configuration)
  .priority_list = false
  .priority_list_priority = -1
  .visibility_allowlist = []
  .commit_sha = nil
  .auto_complete = true
  .links = []
  .approvals = []
  .waiting_on_user_at = nil
  .waiting_on_approval_at = nil
  .next_reminder_at = nil
  .reminder_days = nil
  .closed_by_inactivity = false
  .archived_at = nil

  
end

.from_hash(hash) ⇒ IssueMetadata

Builds an IssueMetadata from a parsed hash (e.g. from MetadataParser)

Parameters:

  • hash (Hash)

Returns:



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/plan_my_stuff/issue_metadata.rb', line 47

def from_hash(hash)
   = new
  apply_common_from_hash(, hash, PlanMyStuff.configuration.custom_fields_for(:issue))

  .responded_at = parse_time(hash[:responded_at])
  .issues_url = hash[:issues_url]
  .priority_list = hash.fetch(:priority_list, false)
  .priority_list_priority = hash.fetch(:priority_list_priority, -1)
  .visibility_allowlist = Array.wrap(hash[:visibility_allowlist])
  .commit_sha = hash[:commit_sha]
  .auto_complete = hash.fetch(:auto_complete, true)
  .links = normalize_links(hash[:links])
  .approvals = normalize_approvals(hash[:approvals])
  .waiting_on_user_at = parse_time(hash[:waiting_on_user_at])
  .waiting_on_approval_at = parse_time(hash[:waiting_on_approval_at])
  .next_reminder_at = parse_time(hash[:next_reminder_at])
  .reminder_days = normalize_reminder_days(hash[:reminder_days])
  .closed_by_inactivity = hash.fetch(:closed_by_inactivity, false)
  .archived_at = parse_time(hash[:archived_at])

  
end

Instance Method Details

#auto_complete?Boolean

Returns:

  • (Boolean)


187
188
189
# File 'lib/plan_my_stuff/issue_metadata.rb', line 187

def auto_complete?
  !!auto_complete
end

#priority_list?Boolean

Returns:

  • (Boolean)


192
193
194
# File 'lib/plan_my_stuff/issue_metadata.rb', line 192

def priority_list?
  !!priority_list
end

#responded?Boolean

Returns:

  • (Boolean)


197
198
199
# File 'lib/plan_my_stuff/issue_metadata.rb', line 197

def responded?
  !responded_at.nil?
end

#to_hHash

Returns:

  • (Hash)


219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
# File 'lib/plan_my_stuff/issue_metadata.rb', line 219

def to_h
  super.merge(
    responded_at: format_time(responded_at),
    issues_url: issues_url,
    priority_list: priority_list,
    priority_list_priority: priority_list_priority,
    visibility_allowlist: visibility_allowlist,
    commit_sha: commit_sha,
    auto_complete: auto_complete,
    links: links.map(&:to_h),
    approvals: approvals.map(&:to_h),
    waiting_on_user_at: format_time(waiting_on_user_at),
    waiting_on_approval_at: format_time(waiting_on_approval_at),
    next_reminder_at: format_time(next_reminder_at),
    reminder_days: reminder_days,
    closed_by_inactivity: closed_by_inactivity,
    archived_at: format_time(archived_at),
  )
end

#visible_to?(user) ⇒ Boolean

Checks whether a user can see this issue’s internal content. Public issues are always visible. Internal issues are visible if the user is support staff or their ID is in the visibility_allowlist.

Parameters:

  • user (Object, Integer)

    user object or user_id

Returns:

  • (Boolean)


209
210
211
212
213
214
215
216
# File 'lib/plan_my_stuff/issue_metadata.rb', line 209

def visible_to?(user)
  return true if public?

  resolved = UserResolver.resolve(user)
  return true if UserResolver.support?(resolved)

  visibility_allowlist.include?(UserResolver.user_id(resolved))
end