FEATURE: add link to see new commits when updates are available for themes (#6233)

* FEATURE: add link to see new commits when updates are available for themes

* shorten regexp
This commit is contained in:
Osama Sayegh
2018-08-06 15:29:15 +10:00
committed by Sam
parent cc77a285ee
commit 18b396ad56
5 changed files with 65 additions and 1 deletions
@@ -77,6 +77,11 @@
{{else}}
{{#if model.remote_theme.commits_behind}}
{{i18n 'admin.customize.theme.commits_behind' count=model.remote_theme.commits_behind}}
{{#if model.remote_theme.github_diff_link}}
<a href="{{model.remote_theme.github_diff_link}}">
{{i18n 'admin.customize.theme.compare_commits'}}
</a>
{{/if}}
{{else}}
{{i18n 'admin.customize.theme.up_to_date'}} {{format-date model.remote_theme.updated_at leaveAgo="true"}}
{{/if}}
+18
View File
@@ -6,6 +6,9 @@ class RemoteTheme < ActiveRecord::Base
ALLOWED_FIELDS = %w{scss embedded_scss head_tag header after_header body_tag footer}
GITHUB_REGEXP = /^https?:\/\/github\.com\//
GITHUB_SSH_REGEXP = /^git@github\.com:/
has_one :theme
def self.update_tgz_theme(filename, user: Discourse.system_user)
@@ -189,6 +192,21 @@ class RemoteTheme < ActiveRecord::Base
end
end
def github_diff_link
if github_repo_url.present? && local_version != remote_version
"#{github_repo_url.gsub(/\.git$/, "")}/compare/#{local_version}...#{remote_version}"
end
end
def github_repo_url
url = remote_url.strip
return url if url.match?(GITHUB_REGEXP)
if url.match?(GITHUB_SSH_REGEXP)
org_repo = url.gsub(GITHUB_SSH_REGEXP, "")
"https://github.com/#{org_repo}"
end
end
end
# == Schema Information
+6 -1
View File
@@ -46,13 +46,18 @@ end
class RemoteThemeSerializer < ApplicationSerializer
attributes :id, :remote_url, :remote_version, :local_version, :about_url,
:license_url, :commits_behind, :remote_updated_at, :updated_at
:license_url, :commits_behind, :remote_updated_at, :updated_at,
:github_diff_link
# wow, AMS has some pretty nutty logic where it tries to find the path here
# from action dispatch, tell it not to
def about_url
object.about_url
end
def include_github_diff_link?
github_diff_link.present?
end
end
class ThemeSerializer < ChildThemeSerializer