我有一个简单的2种方法,它可以从Jira项目中获取数据,并向用户分配任务,而这些任务尚待完成。现在,我从Jira API中获取了customfields
(time_to_resolution
和desired_time_to_resolution),但它看起来不太好,是否可以用一种更加清晰易读的方式来实现?
def assigned_task_list
assigned_tasks.map do |issue|
fields = issue.fields
{
key: issue.key,
desired_time_to_resolution: issue.customfield_14777.dig('ongoingCycle', 'remainingTime', 'friendly'),
time_to_resolution: issue.customfield_10031.dig('ongoingCycle', 'remainingTime', 'friendly'),
name: fields.dig('assignee', 'name'),
email: fields.dig('assignee', 'emailAddress'),
status: fields.dig('status', 'name')
}
end
end
下面的assigned_tasks
方法:
def assigned_tasks
project.issues.select do |issue|
issue.fields.dig('status', 'name') != 'Done' &&
issue.fields.dig('assignee', 'name')
end
end
您可以创建多个方法并将其隐藏在其中。
def assigned_task_list
assigned_tasks.map do |issue|
{
key: issue.key,
desired_time_to_resolution: desired_time_to_resolution(issue),
time_to_resolution: time_to_resolution(issue),
name: name(issue),
email: email(issue),
status: status(issue)
}
end
end
private
def desired_time_to_resolution(issue)
issue.customfield_14777.dig('ongoingCycle', 'remainingTime', 'friendly')
end
def time_to_resolution(issue)
issue.customfield_10031.dig('ongoingCycle', 'remainingTime', 'friendly')
end
def name(issue)
issue.fields.dig('assignee', 'name')
end
def email(issue)
issue.fields.dig('assignee', 'emailAddress')
end
def status(issue)
issue.fields.dig('status', 'name')
end