diff --git a/app/models/changeset.rb b/app/models/changeset.rb
index 10611d8e9a..6a86bf35b9 100644
--- a/app/models/changeset.rb
+++ b/app/models/changeset.rb
@@ -2,7 +2,7 @@
class Changeset
attr_reader :repo, :previous_commit, :commit
BRANCH_TAGS = ["master", "develop"].freeze
- ATTRIBUTE_TABS = %w[files commits pull_requests risks jira_issues].freeze
+ ATTRIBUTE_TABS = %w[files commits pull_requests statuses risks jira_issues].freeze
def initialize(repo, previous_commit, commit)
@repo = repo
@@ -34,6 +34,10 @@ def pull_requests
@pull_requests ||= find_pull_requests
end
+ def github_status
+ @github_status ||= GithubStatus.for_reference(repo, commit)
+ end
+
def risks?
risky_pull_requests.any?
end
diff --git a/app/models/github_status.rb b/app/models/github_status.rb
index 27a6828e6a..2d774e55c7 100644
--- a/app/models/github_status.rb
+++ b/app/models/github_status.rb
@@ -33,16 +33,7 @@ def initialize(state, statuses)
@statuses = statuses
end
- def self.fetch(release)
- repo = release.project.repository_path
- ref = release.commit
-
- # Base the cache key on the Release, so that an update to it effectively
- # clears the cache.
- cache_key = [name, release]
-
- response = Rails.cache.read(cache_key)
-
+ def self.for_reference(repo, ref)
# Fetch the data if the cache returned nil.
response ||= begin
GITHUB.combined_status(repo, ref)
@@ -57,12 +48,23 @@ def self.fetch(release)
Status.new(context, statuses.max_by { |status| status.created_at.to_i })
end
+ new(response.state, statuses)
+ end
+
+ def self.for_release(release)
+ # Base the cache key on the Release, so that an update to it effectively
+ # clears the cache.
+ cache_key = [name, release, "v2"]
+
+ status = Rails.cache.read(cache_key)
+ status ||= for_reference(release.project.repository_path, release.commit)
+
# Don't cache pending statuses, since we expect updates soon.
- unless statuses.any?(&:pending?)
- Rails.cache.write(cache_key, response, expires_in: 1.hour)
+ unless status.statuses.any?(&:pending?)
+ Rails.cache.write(cache_key, status, expires_in: 1.hour)
end
- new(response.state, statuses)
+ status
end
def success?
diff --git a/app/models/release.rb b/app/models/release.rb
index cfd025a460..48f5c331c3 100644
--- a/app/models/release.rb
+++ b/app/models/release.rb
@@ -33,7 +33,7 @@ def to_param
end
def github_status
- @github_status ||= GithubStatus.fetch(self)
+ @github_status ||= GithubStatus.for_release(self)
end
def self.find_by_param!(version)
diff --git a/app/views/changeset/_statuses.html.erb b/app/views/changeset/_statuses.html.erb
new file mode 100644
index 0000000000..c3b590f913
--- /dev/null
+++ b/app/views/changeset/_statuses.html.erb
@@ -0,0 +1,3 @@
+<% changeset.github_status.statuses.each do |status| %>
+ <%= github_commit_status_icon(status.state) %> <%= status.context %>: <%= link_to status.description, status.url %>
+<% end %>
diff --git a/app/views/releases/row_content.html.erb b/app/views/releases/row_content.html.erb
index c879d3f139..e4843b4cff 100644
--- a/app/views/releases/row_content.html.erb
+++ b/app/views/releases/row_content.html.erb
@@ -4,6 +4,7 @@
- <% @release.github_status.statuses.each do |status| %>
- <%= github_commit_status_icon(status.state) %> <%= status.context %>: <%= link_to status.description, status.url %>
- <% end %>
+ <%= render "changeset/statuses", changeset: @changeset %>