Class: ScheduledIssuesManager

Inherits:
Object
  • Object
show all
Defined in:
lib/scheduled/scheduled_issues_manager.rb

Overview

Configuration for repeatables.

Instance Method Summary collapse

Instance Method Details

#add_scheduled(issue_id, repeat, date, start_time, duration) ⇒ Object

Adds a scheduled issue to database.

Parameters:

  • issue_id (String)

    The JIRA issue id.

  • repeat (Integer)

    An integer that indicates the day of the week that this issue will be repeated. 0: Every day 1: Monday 2: Tuesday 3: Wednesday 4: Thursday 5: Friday 6: Saturday 7: Sunday

  • date (String)

    A date that the issue will be scheduled in MM/DD/YYYY format.

  • start_time (String)

    The String representation of start time in 24h format, e.g. 10:00

  • duration (String)

    A String representation of duration, e.g. 2h30m



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/scheduled/scheduled_issues_manager.rb', line 40

def add_scheduled(issue_id, repeat, date, start_time, duration)
  validate_input(repeat, date, start_time, duration)
  Communication::API.get_issue(issue_id) do |issue|
    update_issue_attributes(issue, repeat, date, start_time, duration).save
    Utilities.log "Added issue #{issue.jira_id}: #{issue.description}.", { type: :info }
  end
rescue LogworkException::APIResourceNotFound
  Utilities.log("JIRA issue '#{issue_id}' not found.", { type: :error })
rescue LogworkException::RepeatedOrScheduledRequired, LogworkException::ScheduledCannotBeCombinedWithRepeated,
       LogworkException::InvalidRepeatValue, LogworkException::InvalidDateFormat,
       LogworkException::DuplicateIssueFound, LogworkException::InputValueRequired,
       LogworkException::InvalidTimeException => e
  Utilities.log(e, { type: :error })
end

#all_issuesArray<WorklogIssue>

Return all scheduled issues.

Returns:

  • (Array<WorklogIssue>)

    List scheduled issues.



85
86
87
# File 'lib/scheduled/scheduled_issues_manager.rb', line 85

def all_issues
  WorklogIssue.all
end

#remove_scheduled(issue_id, date, repeat) ⇒ Object

Remove a scheduled issue from database.

Parameters:

  • issue_id (String)

    The JIRA issue id.

  • date (String)

    The date of the issue.

  • repeat (String)

    A number that indicates the date of the week.



75
76
77
78
79
80
# File 'lib/scheduled/scheduled_issues_manager.rb', line 75

def remove_scheduled(issue_id, date, repeat)
  filters = { jira_id: issue_id }
  filters[:date] = date unless date.nil?
  filters[:repeat] = date unless repeat.nil?
  WorklogIssue.where(filters).delete_all
end

#update_issue_attributes(issue, repeat, date, start_time, duration) ⇒ Object

Updates issue's attributes with command line arguments

Parameters:

  • issue (WorklogIssue)

    The WorklogIssue created by API service.

  • repeat (String)

    A number that indicates the date of the week.

  • date (String)

    The date input of the issue.

  • start_time (String)

    The start time input of the issue.

  • duration (String)

    A String representation of duration, e.g. 2h30m



62
63
64
65
66
67
68
# File 'lib/scheduled/scheduled_issues_manager.rb', line 62

def update_issue_attributes(issue, repeat, date, start_time, duration)
  issue.date = date
  issue.start_time = start_time
  issue.repeat = repeat
  issue.duration = duration
  issue
end