mirror of
https://github.com/discourse/discourse.git
synced 2024-11-25 10:20:58 -06:00
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:
parent
cc77a285ee
commit
18b396ad56
@ -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}}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -3235,6 +3235,7 @@ en:
|
||||
commits_behind:
|
||||
one: "Theme is 1 commit behind!"
|
||||
other: "Theme is {{count}} commits behind!"
|
||||
compare_commits: "(See new commits)"
|
||||
scss:
|
||||
text: "CSS"
|
||||
title: "Enter custom CSS, we accept all valid CSS and SCSS styles"
|
||||
|
@ -152,6 +152,41 @@ describe RemoteTheme do
|
||||
end
|
||||
end
|
||||
|
||||
let(:github_repo) do
|
||||
RemoteTheme.create!(
|
||||
remote_url: "https://github.com/org/testtheme.git",
|
||||
local_version: "a2ec030e551fc8d8579790e1954876fe769fe40a",
|
||||
remote_version: "21122230dbfed804067849393c3332083ddd0c07",
|
||||
commits_behind: 2
|
||||
)
|
||||
end
|
||||
|
||||
let(:gitlab_repo) do
|
||||
RemoteTheme.create!(
|
||||
remote_url: "https://gitlab.com/org/repo.git",
|
||||
local_version: "a2ec030e551fc8d8579790e1954876fe769fe40a",
|
||||
remote_version: "21122230dbfed804067849393c3332083ddd0c07",
|
||||
commits_behind: 5
|
||||
)
|
||||
end
|
||||
|
||||
context "#github_diff_link" do
|
||||
it "is blank for non-github repos" do
|
||||
expect(gitlab_repo.github_diff_link).to be_blank
|
||||
end
|
||||
|
||||
it "returns URL for comparing between local_version and remote_version" do
|
||||
expect(github_repo.github_diff_link).to eq(
|
||||
"https://github.com/org/testtheme/compare/#{github_repo.local_version}...#{github_repo.remote_version}"
|
||||
)
|
||||
end
|
||||
|
||||
it "is blank when theme is up-to-date" do
|
||||
github_repo.update!(local_version: github_repo.remote_version, commits_behind: 0)
|
||||
expect(github_repo.reload.github_diff_link).to be_blank
|
||||
end
|
||||
end
|
||||
|
||||
context ".out_of_date_themes" do
|
||||
let(:remote) { RemoteTheme.create!(remote_url: "https://github.com/org/testtheme") }
|
||||
let!(:theme) { Theme.create!(remote_theme_id: remote.id, name: "Test Theme", user_id: -1) }
|
||||
|
Loading…
Reference in New Issue
Block a user