Module: PlanMyStuff::IssueExtractions::Waiting

Included in:
PlanMyStuff::Issue
Defined in:
lib/plan_my_stuff/issue_extractions/waiting.rb

Instance Method Summary collapse

Instance Method Details

#awaiting_reply?Boolean

Returns:

  • (Boolean)


7
8
9
# File 'lib/plan_my_stuff/issue_extractions/waiting.rb', line 7

def awaiting_reply?
  issue_fields['Issue Status'] == 'Waiting on Reply'
end

#clear_waiting_on_user!self

Clears the waiting-on-user state: removes the label, clears metadata.waiting_on_user_at, and clears metadata.next_reminder_at unless a waiting-on-approval timer is still active. No-ops if the issue is not currently waiting on a user reply.

Returns:

  • (self)


50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/plan_my_stuff/issue_extractions/waiting.rb', line 50

def clear_waiting_on_user!
  label = PlanMyStuff.configuration.waiting_on_user_label
  return self if .waiting_on_user_at.nil? && labels.exclude?(label)

  PlanMyStuff::Label.remove!(issue: self, labels: [label]) if labels.include?(label)

  to_update = {}
  if PlanMyStuff.configuration.issue_fields_enabled
    to_update[:issue_fields] = { 'Issue Status' => 'Open' }
  end

  self.class.update!(
    number: number,
    repo: repo,
    metadata: {
      waiting_on_user_at: nil,
      next_reminder_at:
        .waiting_on_approval_at ? PlanMyStuff.format_time(.next_reminder_at) : nil,
    },
    **to_update,
  )
  reload
end

#enter_waiting_on_user!(user: nil) ⇒ self

Marks the issue as waiting on an end-user reply. Sets metadata.waiting_on_user_at to now, (re)computes metadata.next_reminder_at, and adds the configured waiting_on_user_label to the issue. Called from Comment.create! when a support user posts a comment with waiting_on_reply: true, and from the Issues::WaitingsController toggle.

Parameters:

  • user (Object, nil) (defaults to: nil)

    actor for the label notification event

Returns:

  • (self)


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/plan_my_stuff/issue_extractions/waiting.rb', line 20

def enter_waiting_on_user!(user: nil)
  now = Time.now.utc
  label = PlanMyStuff.configuration.waiting_on_user_label

  PlanMyStuff::Label.ensure!(repo: repo, name: label)
  PlanMyStuff::Label.add!(issue: self, labels: [label], user: user) if labels.exclude?(label)

  to_update = {}
  if PlanMyStuff.configuration.issue_fields_enabled
    to_update[:issue_fields] = { 'Issue Status' => 'Waiting on Reply' }
  end

  self.class.update!(
    number: number,
    repo: repo,
    metadata: {
      waiting_on_user_at: PlanMyStuff.format_time(now),
      next_reminder_at: format_next_reminder_at(from: now),
    },
    **to_update,
  )
  reload
end

#reopen_by_reply!(comment:, user: nil) ⇒ self

Reopens an issue that was auto-closed by the inactivity sweep, clears metadata.closed_by_inactivity, and emits issue_reopened_by_reply.plan_my_stuff carrying the reopening comment. Does not emit the regular issue.reopened event - subscribers that specifically care about this flow subscribe to the dedicated event.

Parameters:

  • comment (PlanMyStuff::Comment)

    the reopening comment

  • user (Object, nil) (defaults to: nil)

    actor for the notification event

Returns:

  • (self)


83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
# File 'lib/plan_my_stuff/issue_extractions/waiting.rb', line 83

def reopen_by_reply!(comment:, user: nil)
  inactive_label = PlanMyStuff.configuration.user_inactive_label
  PlanMyStuff::Label.remove!(issue: self, labels: [inactive_label]) if labels.include?(inactive_label)

  to_update = {}
  if PlanMyStuff.configuration.issue_fields_enabled
    to_update[:issue_fields] = { 'Issue Status' => 'Reopened' }
  end

  self.class.update!(
    number: number,
    repo: repo,
    state: :open,
    metadata: { closed_by_inactivity: false },
    **to_update,
  )
  reload

  PlanMyStuff::Notifications.instrument(
    'issue_reopened_by_reply',
    self,
    user: user,
    comment: comment,
  )
  self
end