Skip to content

Commit

Permalink
今週のマイルストーンがない場合は先週のものを表示
Browse files Browse the repository at this point in the history
  • Loading branch information
eiel committed Dec 31, 2014
1 parent 6d13932 commit cd87fae
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 6 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,16 @@ def index
@repo = 'great-h/great-h.github.io'
@milestone = milestone_name
@issues = Issue.filter_milestone(@repo, @milestone)
if @issues.length == 0
@milestone = milestone_name(Date.today.prev_week)
@issues = Issue.filter_milestone(@repo, @milestone)
end
Rails.logger.info(Github.rate_limit.to_s)
end

private

def milestone_name
Date.today.beginning_of_week(:wednesday).strftime('%Y%m%d')
def milestone_name(date = Date.today)
date.beginning_of_week(:wednesday).strftime('%Y%m%d')
end
end
2 changes: 1 addition & 1 deletion app/models/issue.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
class Issue
def self.filter_milestone(repo, name)
milestone = Milestone.find(repo, name)
raise "not found milestone: #{milestone.title}" if milestone.nil?
return [] if milestone.nil?

Rails.cache.fetch(issues_key(repo, name), expires_in: 3.minutes) do
Github.client.list_issues(repo, milestone: milestone.number, state: 'all')
Expand Down

0 comments on commit cd87fae

Please sign in to comment.