FIX: Remote themes Github link should go to custom branch #9184

This commit is contained in:
Vinoth Kannan 2020-03-18 03:57:54 +05:30
parent 0b2e6f4301
commit 48d690ae01
4 changed files with 62 additions and 2 deletions

View File

@ -203,6 +203,17 @@ export default Controller.extend({
);
},
sourceIsHttp: match("model.remote_theme.remote_url", /^http(s)?:\/\//),
@discourseComputed(
"model.remote_theme.remote_url",
"model.remote_theme.branch"
)
remoteThemeLink(remoteThemeUrl, remoteThemeBranch) {
return remoteThemeBranch
? `${remoteThemeUrl.replace(/\.git$/, "")}/tree/${remoteThemeBranch}`
: remoteThemeUrl;
},
actions: {
updateToLatest() {
this.set("updatingRemote", true);

View File

@ -63,7 +63,7 @@
{{#if model.remote_theme.remote_url}}
{{#if sourceIsHttp}}
<a class="remote-url" href={{model.remote_theme.remote_url}}>{{i18n "admin.customize.theme.source_url"}}{{d-icon "link"}}</a>
<a class="remote-url" href={{remoteThemeLink}}>{{i18n "admin.customize.theme.source_url"}}{{d-icon "link"}}</a>
{{else}}
<div class="remote-url"><code>{{model.remote_theme.remote_url}}</code></div>
{{/if}}

View File

@ -47,7 +47,7 @@ class BasicThemeSerializer < ApplicationSerializer
end
class RemoteThemeSerializer < ApplicationSerializer
attributes :id, :remote_url, :remote_version, :local_version, :commits_behind,
attributes :id, :remote_url, :remote_version, :local_version, :commits_behind, :branch,
:remote_updated_at, :updated_at, :github_diff_link, :last_error_text, :is_git?,
:license_url, :about_url, :authors, :theme_version, :minimum_discourse_version, :maximum_discourse_version

View File

@ -0,0 +1,49 @@
import { mapRoutes } from "discourse/mapping-router";
import Theme from "admin/models/theme";
moduleFor("controller:admin-customize-themes-show", {
beforeEach() {
this.registry.register("router:main", mapRoutes());
},
needs: ["controller:adminUser"]
});
const repoUrl = "https://github.com/discourse/discourse-brand-header.git";
const remoteTheme = Theme.create({
id: 2,
default: true,
name: "default",
remote_theme: {
remote_url: repoUrl
}
});
QUnit.test("can display source url for remote themes", function(assert) {
const controller = this.subject({
model: remoteTheme
});
assert.deepEqual(
controller.get("remoteThemeLink"),
repoUrl,
"returns theme's repo URL"
);
});
QUnit.test("can display source url for remote theme branches", function(
assert
) {
const branchUrl =
"https://github.com/discourse/discourse-brand-header/tree/beta";
remoteTheme["remote_theme"]["branch"] = "beta";
const controller = this.subject({
model: remoteTheme
});
assert.deepEqual(
controller.get("remoteThemeLink"),
branchUrl,
"returns theme's repo URL to branch"
);
});