Skip to content
This repository has been archived by the owner on Mar 3, 2022. It is now read-only.

List issues by milestone #301

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion lib/ghi/commands/list.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ def options
assigns[:org] = org
@repo = nil
end
opts.on(
'--by-milestone', 'filter by milestone'
) do
assigns[:by_m] = true
end
opts.separator ''
end
end
Expand Down Expand Up @@ -164,7 +169,11 @@ def execute
if verbose
puts issues.map { |i| format_issue i }
else
puts format_issues(issues, repo.nil?)
if assigns[:by_m]
puts format_issues_by_milestone(issues, repo.nil?)
else
puts format_issues(issues, repo.nil?)
end
end
break unless res.next_page
res = throb { api.get res.next_page }
Expand Down
49 changes: 49 additions & 0 deletions lib/ghi/formatting.rb
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,55 @@ def format_issues issues, include_repo
}
end

def extract_milestones_from_issues issues
return 'None.' if issues.empty?

nmax, rmax = %w(number repo).map { |f|
issues.sort_by { |i| i[f].to_s.size }.last[f].to_s.size
}

milestones = {}
extracted_milestones = []
milestone_index = 0
issues.map { |i|
milestone = i['milestone']
milestone["issues"] = [] if milestone && !(milestones.key? milestone["id"])
if milestone
if !milestones.key? milestone["id"]
milestones.merge!({milestone["id"] => milestone_index })
i.delete "milestone"
milestone["issues"] << i
extracted_milestones << milestone
milestone_index += 1
else
pos_of_existent_milestone = milestones[milestone["id"]]
i.delete "milestone"
extracted_milestones[pos_of_existent_milestone]["issues"] << i
end
end
}
extracted_milestones.sort! { |m1, m2| m1['number'] <=> m2['number'] }
end

def format_issues_by_milestone issues, include_repo
issues_by_milestone = extract_milestones_from_issues issues

nmax, rmax = %w(number repo).map { |f|
issues.sort_by { |i| i[f].to_s.size }.last[f].to_s.size
}

l = 9 + nmax + rmax

issues_by_milestone.map { |milestone|
title = milestone['title'] if milestone["issues"]
[
("\n " if milestone["issues"]),
("Milestone: " + fg(:green) { truncate(title,l) } if title),
(format_issues(milestone["issues"], include_repo))
].compact
}
end

def format_number n
colorize? ? "#{bright { n }}:" : "#{n} "
end
Expand Down