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.



162
163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/plan_my_stuff/issue_metadata.rb', line 162

def initialize
  super
  @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?.



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

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



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

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)



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

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



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

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



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

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.



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

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



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

def next_reminder_at
  @next_reminder_at
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



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

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



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

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



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

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



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

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:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/plan_my_stuff/issue_metadata.rb', line 71

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)
  .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:



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/plan_my_stuff/issue_metadata.rb', line 43

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]
  .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)


177
178
179
# File 'lib/plan_my_stuff/issue_metadata.rb', line 177

def auto_complete?
  !!auto_complete
end

#responded?Boolean

Returns:

  • (Boolean)


182
183
184
# File 'lib/plan_my_stuff/issue_metadata.rb', line 182

def responded?
  !responded_at.nil?
end

#to_hHash

Returns:

  • (Hash)


204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
# File 'lib/plan_my_stuff/issue_metadata.rb', line 204

def to_h
  super.merge(
    responded_at: PlanMyStuff.format_time(responded_at),
    issues_url: issues_url,
    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: PlanMyStuff.format_time(waiting_on_user_at),
    waiting_on_approval_at: PlanMyStuff.format_time(waiting_on_approval_at),
    next_reminder_at: PlanMyStuff.format_time(next_reminder_at),
    reminder_days: reminder_days,
    closed_by_inactivity: closed_by_inactivity,
    archived_at: PlanMyStuff.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)


194
195
196
197
198
199
200
201
# File 'lib/plan_my_stuff/issue_metadata.rb', line 194

def visible_to?(user)
  return true if public?

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

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