DEV: Clean up the code (#245)

gjs, helper invocation case, typos, latest license template, unnecessary tracking, concatClass, unnecessary service injection, new imports, whitespace, pure function helper, htmlSafe calling convention, this. in template, unused vars in ruby, update linting, qunit-dom
This commit is contained in:
Jarek Radosz 2024-10-23 11:21:22 +02:00 committed by GitHub
parent 06cc8dba9d
commit ea174f7e36
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
26 changed files with 163 additions and 157 deletions

View File

@ -1,82 +1,79 @@
GEM
remote: https://rubygems.org/
specs:
activesupport (7.1.3.3)
activesupport (7.2.1.1)
base64
bigdecimal
concurrent-ruby (~> 1.0, >= 1.0.2)
concurrent-ruby (~> 1.0, >= 1.3.1)
connection_pool (>= 2.2.5)
drb
i18n (>= 1.6, < 2)
logger (>= 1.4.2)
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
securerandom (>= 0.3)
tzinfo (~> 2.0, >= 2.0.5)
ast (2.4.2)
base64 (0.2.0)
bigdecimal (3.1.8)
concurrent-ruby (1.2.3)
concurrent-ruby (1.3.4)
connection_pool (2.4.1)
drb (2.2.1)
i18n (1.14.5)
i18n (1.14.6)
concurrent-ruby (~> 1.0)
json (2.7.2)
language_server-protocol (3.17.0.3)
minitest (5.23.1)
mutex_m (0.2.0)
parallel (1.24.0)
parser (3.3.1.0)
logger (1.6.1)
minitest (5.25.1)
parallel (1.26.3)
parser (3.3.5.0)
ast (~> 2.4.1)
racc
prettier_print (1.2.1)
racc (1.8.0)
rack (3.0.11)
racc (1.8.1)
rack (3.1.8)
rainbow (3.1.1)
regexp_parser (2.9.2)
rexml (3.3.6)
strscan
rubocop (1.64.0)
rubocop (1.67.0)
json (~> 2.3)
language_server-protocol (>= 3.17.0)
parallel (~> 1.10)
parser (>= 3.3.0.2)
rainbow (>= 2.2.2, < 4.0)
regexp_parser (>= 1.8, < 3.0)
rexml (>= 3.2.5, < 4.0)
rubocop-ast (>= 1.31.1, < 2.0)
regexp_parser (>= 2.4, < 3.0)
rubocop-ast (>= 1.32.2, < 2.0)
ruby-progressbar (~> 1.7)
unicode-display_width (>= 2.4.0, < 3.0)
rubocop-ast (1.31.3)
rubocop-ast (1.32.3)
parser (>= 3.3.1.0)
rubocop-capybara (2.20.0)
rubocop-capybara (2.21.0)
rubocop (~> 1.41)
rubocop-discourse (3.8.0)
rubocop-discourse (3.8.2)
activesupport (>= 6.1)
rubocop (>= 1.59.0)
rubocop-capybara (>= 2.0.0)
rubocop-factory_bot (>= 2.0.0)
rubocop-rails (>= 2.25.0)
rubocop-rspec (>= 2.25.0)
rubocop-factory_bot (2.25.1)
rubocop (~> 1.41)
rubocop-rails (2.25.0)
rubocop-rspec (>= 3.0.1)
rubocop-rspec_rails (>= 2.30.0)
rubocop-factory_bot (2.26.1)
rubocop (~> 1.61)
rubocop-rails (2.26.2)
activesupport (>= 4.2.0)
rack (>= 1.1)
rubocop (>= 1.33.0, < 2.0)
rubocop (>= 1.52.0, < 2.0)
rubocop-ast (>= 1.31.1, < 2.0)
rubocop-rspec (2.29.2)
rubocop (~> 1.40)
rubocop-capybara (~> 2.17)
rubocop-factory_bot (~> 2.22)
rubocop-rspec_rails (~> 2.28)
rubocop-rspec_rails (2.28.3)
rubocop (~> 1.40)
rubocop-rspec (3.1.0)
rubocop (~> 1.61)
rubocop-rspec_rails (2.30.0)
rubocop (~> 1.61)
rubocop-rspec (~> 3, >= 3.0.1)
ruby-progressbar (1.13.0)
strscan (3.1.0)
securerandom (0.3.1)
syntax_tree (6.2.0)
prettier_print (>= 1.2.0)
tzinfo (2.0.6)
concurrent-ruby (~> 1.0)
unicode-display_width (2.5.0)
unicode-display_width (2.6.0)
PLATFORMS
ruby

29
LICENSE
View File

@ -1,20 +1,21 @@
The MIT License (MIT)
Copyright (c) 2014 Civilized Discourse Construction Kit, Inc.
Copyright (c) Civilized Discourse Construction Kit, Inc.
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

View File

@ -0,0 +1,23 @@
import Component from "@glimmer/component";
import didInsert from "@ember/render-modifiers/modifiers/did-insert";
import didUpdate from "@ember/render-modifiers/modifiers/did-update";
import { bind } from "discourse-common/utils/decorators";
export default class Console extends Component {
@bind
scrollToBottom(element) {
if (this.args.followOutput) {
element.scrollTop = element.scrollHeight;
}
}
<template>
<div
class="console-logs"
{{didInsert this.scrollToBottom}}
{{didUpdate this.scrollToBottom @output}}
>
{{~@output~}}
</div>
</template>
}

View File

@ -1,7 +0,0 @@
<div
class="console-logs"
{{did-insert this.scrollToBottom}}
{{did-update this.scrollToBottom @output}}
>
{{~@output~}}
</div>

View File

@ -1,11 +0,0 @@
import Component from "@glimmer/component";
import { bind } from "discourse-common/utils/decorators";
export default class Console extends Component {
@bind
scrollToBottom(element) {
if (this.args.followOutput) {
element.scrollTop = element.scrollHeight;
}
}
}

View File

@ -1,5 +1,6 @@
import Component from "@glimmer/component";
import { htmlSafe } from "@ember/template";
import concatClass from "discourse/helpers/concat-class";
export default class ProgressBar extends Component {
get active() {
@ -15,4 +16,10 @@ export default class ProgressBar extends Component {
return htmlSafe(`width: ${percent}%`);
}
<template>
<div class={{concatClass "progress-bar" (if this.active "active")}}>
<div class="progress-bar-inner" style={{this.barStyle}}></div>
</div>
</template>
}

View File

@ -1,3 +0,0 @@
<div class="progress-bar {{if this.active 'active'}}">
<div class="progress-bar-inner" style={{this.barStyle}}></div>
</div>

View File

@ -0,0 +1,22 @@
import Component from "@glimmer/component";
import { LinkTo } from "@ember/routing";
import { service } from "@ember/service";
import i18n from "discourse-common/helpers/i18n";
export default class UpgradeNotice extends Component {
@service currentUser;
<template>
{{#if this.currentUser.admin}}
{{#unless @versionCheck.upToDate}}
<div class="upgrades-banner">
{{i18n "admin.docker.outdated_notice"}}
<LinkTo @route="update">
{{i18n "admin.docker.perform_update"}}
</LinkTo>
</div>
{{/unless}}
{{/if}}
</template>
}

View File

@ -1,11 +0,0 @@
{{#if this.currentUser.admin}}
{{#unless @versionCheck.upToDate}}
<div class="upgrades-banner">
{{i18n "admin.docker.outdated_notice"}}
<LinkTo @route="update">
{{i18n "admin.docker.perform_update"}}
</LinkTo>
</div>
{{/unless}}
{{/if}}

View File

@ -1,6 +0,0 @@
import Component from "@glimmer/component";
import { inject as service } from "@ember/service";
export default class UpgradeNotice extends Component {
@service currentUser;
}

View File

@ -1,13 +1,12 @@
import Component from "@glimmer/component";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { service } from "@ember/service";
import DButton from "discourse/components/d-button";
import FormatDate from "discourse/helpers/format-date";
import formatDate from "discourse/helpers/format-date";
import icon from "discourse-common/helpers/d-icon";
import i18n from "discourse-common/helpers/i18n";
import I18n from "I18n";
import CommitUrl from "../helpers/commit-url";
import NewCommits from "../helpers/new-commits";
import commitUrl from "../helpers/commit-url";
import newCommits from "../helpers/new-commits";
export default class RepoStatus extends Component {
@service router;
@ -33,9 +32,9 @@ export default class RepoStatus extends Component {
get upgradeButtonLabel() {
if (this.args.repo.upgrading) {
return I18n.t("admin.docker.updating");
return i18n("admin.docker.updating");
} else {
return I18n.t("admin.docker.update_action");
return i18n("admin.docker.update_action");
}
}
@ -52,14 +51,17 @@ export default class RepoStatus extends Component {
<div class="d-admin-row__overview-name">
{{@repo.nameTitleized}}
</div>
{{#if @repo.author}}
<div class="d-admin-row__overview-author">
{{@repo.author}}
</div>
{{/if}}
{{#if @repo.plugin}}
<div class="d-admin-row__overview-about">
{{@repo.plugin.about}}
{{#if @repo.linkUrl}}
<a
href={{@repo.linkUrl}}
@ -72,6 +74,7 @@ export default class RepoStatus extends Component {
{{/if}}
</div>
{{/if}}
{{#if @repo.hasNewVersion}}
<div class="repo__new-version">
{{i18n "admin.docker.new_version_available"}}
@ -83,14 +86,14 @@ export default class RepoStatus extends Component {
<div class="d-admin-row__mobile-label">
{{i18n "admin.docker.repo.commit_hash"}}
</div>
{{CommitUrl "current" @repo.version @repo.prettyVersion @repo.url}}
{{commitUrl "current" @repo.version @repo.prettyVersion @repo.url}}
</td>
<td class="d-admin-row__detail">
<div class="d-admin-row__mobile-label">
{{i18n "admin.docker.repo.last_updated"}}
</div>
{{FormatDate @repo.latest.date leaveAgo="true"}}
{{formatDate @repo.latest.date leaveAgo="true"}}
</td>
<td class="d-admin-row__detail">
@ -99,7 +102,7 @@ export default class RepoStatus extends Component {
</div>
<div class="repo__latest-version">
<div>
{{CommitUrl
{{commitUrl
"new"
@repo.latest.version
@repo.prettyLatestVersion
@ -107,7 +110,7 @@ export default class RepoStatus extends Component {
}}
</div>
<div class="new-commits">
{{NewCommits
{{newCommits
@repo.latest.commits_behind
@repo.version
@repo.latest.version

View File

@ -1,7 +1,7 @@
import { cached } from "@glimmer/tracking";
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { service } from "@ember/service";
import { needsImageUpgrade } from "../models/repo";
export default class UpgradeIndex extends Controller {

View File

@ -1,12 +1,11 @@
import Controller from "@ember/controller";
import { action } from "@ember/object";
import { inject as service } from "@ember/service";
import { service } from "@ember/service";
import { makeArray } from "discourse-common/lib/helpers";
import I18n from "I18n";
import I18n from "discourse-i18n";
import Repo from "../models/repo";
export default class UpgradeShow extends Controller {
@service messageBus;
@service dialog;
@service upgradeStore;

View File

@ -4,8 +4,8 @@ import { action } from "@ember/object";
import { TrackedArray } from "@ember-compat/tracked-built-ins";
export default class Upgrade extends Controller {
@tracked banner = new TrackedArray([]);
@tracked bannerDismissed = false;
banner = new TrackedArray();
get showBanner() {
if (this.bannerDismissed) {

View File

@ -10,7 +10,7 @@ export default function commitUrl(cssClass, version, prettyVersion, url) {
}
const repoUrl = url.substr(0, url.search(/(\.git)?$/));
const description = `<a class='${cssClass} commit-hash' title='${version}' href='${repoUrl}/commit/${version}'>${prettyVersion}</a>`;
return new htmlSafe(description);
return htmlSafe(
`<a class='${cssClass} commit-hash' title='${version}' href='${repoUrl}/commit/${version}'>${prettyVersion}</a>`
);
}

View File

@ -1,10 +1,7 @@
import { helper as buildHelper } from "@ember/component/helper";
import { htmlSafe } from "@ember/template";
import I18n from "I18n";
export default buildHelper(function (params) {
const [commitsBehind, oldSha, newSha, url] = params;
import I18n from "discourse-i18n";
export default function newCommits(commitsBehind, oldSha, newSha, url) {
if (!commitsBehind) {
return "";
}
@ -13,7 +10,7 @@ export default buildHelper(function (params) {
return "";
}
let description = I18n.t("admin.docker.commits", {
const description = I18n.t("admin.docker.commits", {
count: commitsBehind,
});
@ -22,7 +19,7 @@ export default buildHelper(function (params) {
}
const _url = url.substr(0, url.search(/(\.git)?$/));
description = `<a href='${_url}/compare/${oldSha}...${newSha}'>${description}</a>`;
return new htmlSafe(description);
});
return htmlSafe(
`<a href='${_url}/compare/${oldSha}...${newSha}'>${description}</a>`
);
}

View File

@ -1,5 +1,5 @@
import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
import { service } from "@ember/service";
import Repo from "../models/repo";
export default class UpgradeShow extends Route {

View File

@ -1,7 +1,7 @@
import Route from "@ember/routing/route";
import { inject as service } from "@ember/service";
import { service } from "@ember/service";
import { bind } from "discourse-common/utils/decorators";
import I18n from "I18n";
import I18n from "discourse-i18n";
import Repo from "../models/repo";
export default class Upgrade extends Route {

View File

@ -1 +1 @@
<DockerManager::Console @output={{model.output}} />
<DockerManager::Console @output={{this.model.output}} />

View File

@ -9,7 +9,7 @@ module DockerManager::FallbackCompatibilityParser
begin
version_list = YAML.safe_load(version_list)
rescue Psych::SyntaxError, Psych::DisallowedClass => e
rescue Psych::SyntaxError, Psych::DisallowedClass
end
raise Discourse::InvalidVersionListError unless version_list.is_a?(Hash)
@ -18,7 +18,7 @@ module DockerManager::FallbackCompatibilityParser
version_list
.transform_keys do |v|
Gem::Requirement.parse(v)
rescue Gem::Requirement::BadRequirementError => e
rescue Gem::Requirement::BadRequirementError
raise Discourse::InvalidVersionListError, "Invalid version specifier: #{v}"
end
.sort_by do |parsed_requirement, _|
@ -61,12 +61,12 @@ module DockerManager::FallbackCompatibilityParser
# Find a compatible resource from a git repo
def self.find_compatible_git_resource(path)
return unless File.directory?("#{path}/.git")
compat_resource, std_error, s =
compat_resource, _, s =
Open3.capture3(
"git -C '#{path}' show HEAD@{upstream}:#{Discourse::VERSION_COMPATIBILITY_FILENAME}",
)
self.find_compatible_resource(compat_resource) if s.success?
rescue Discourse::InvalidVersionListError => e
rescue Discourse::InvalidVersionListError
$stderr.puts "Invalid version list in #{path}"
end
end

View File

@ -178,7 +178,7 @@ class DockerManager::GitRepo
def run(cmd)
@memoize[cmd] ||= begin
stdout, stderr, status = Open3.capture3("git #{cmd}", chdir: path)
stdout, _, status = Open3.capture3("git #{cmd}", chdir: path)
status == 0 ? stdout.strip : nil
end
rescue => e

View File

@ -1,7 +1,7 @@
{
"private": true,
"devDependencies": {
"@discourse/lint-configs": "1.3.10",
"@discourse/lint-configs": "1.4.2",
"ember-template-lint": "6.0.0",
"eslint": "8.57.1",
"prettier": "2.8.8",

View File

@ -12,8 +12,8 @@ importers:
specifier: ^7.25.7
version: 7.25.7(@babel/core@7.25.8)
'@discourse/lint-configs':
specifier: 1.3.10
version: 1.3.10(ember-template-lint@6.0.0)(eslint@8.57.1)(prettier@2.8.8)
specifier: 1.4.2
version: 1.4.2(ember-template-lint@6.0.0)(eslint@8.57.1)(prettier@2.8.8)
ember-template-lint:
specifier: 6.0.0
version: 6.0.0
@ -152,11 +152,11 @@ packages:
resolution: {integrity: sha512-JWtuCu8VQsMladxVz/P4HzHUGCAwpuqacmowgXFs5XjxIgKuNjnLokQzuVjlTvIzODaDmpjT3oxcC48vyk9EWg==}
engines: {node: '>=6.9.0'}
'@discourse/lint-configs@1.3.10':
resolution: {integrity: sha512-PQ56xx4UfceLR/wJm7ig1JRNKkLVYPAeyp5bV6k6jQhpVr9TeZdobeCfGbVtKG6hhuaQ4aECPjRf/MoNw00/cw==}
'@discourse/lint-configs@1.4.2':
resolution: {integrity: sha512-AhwEfqy7ByheuNEhioXlkcgrbvzQY8yFbSWwtqAB0GXsp4UNaMZFyjdMoPFgaUDdUzjY/eKFFZ/j4FkA9EY4qA==}
peerDependencies:
ember-template-lint: 6.0.0
eslint: 8.57.0
eslint: 8.57.1
prettier: 2.8.8
'@ember-data/rfc395-data@0.0.4':
@ -1947,7 +1947,7 @@ snapshots:
'@babel/helper-validator-identifier': 7.25.7
to-fast-properties: 2.0.0
'@discourse/lint-configs@1.3.10(ember-template-lint@6.0.0)(eslint@8.57.1)(prettier@2.8.8)':
'@discourse/lint-configs@1.4.2(ember-template-lint@6.0.0)(eslint@8.57.1)(prettier@2.8.8)':
dependencies:
'@babel/core': 7.25.8
'@babel/eslint-parser': 7.25.8(@babel/core@7.25.8)(eslint@8.57.1)

View File

@ -195,7 +195,7 @@ module GitHelpers
def git(*commands)
Dir.chdir(@path) do
commands.map do |command|
stdout, stderr, status = Open3.capture3("git #{command}".strip)
stdout, _, status = Open3.capture3("git #{command}".strip)
status.success? ? stdout : (raise RuntimeError)
end
end

View File

@ -8,7 +8,7 @@ RSpec.describe "Admin update", type: :system do
before { sign_in(admin) }
xit "displays the admin update page with the right respositories" do
xit "displays the admin update page with the right repositories" do
visit("/admin/update")
expect(page).to have_css("h3", exact_text: I18n.t("js.admin.docker.update_title"))

View File

@ -1,9 +1,8 @@
import { getOwner } from "@ember/application";
import { getOwner } from "@ember/owner";
import { render, settled } from "@ember/test-helpers";
import { setupRenderingTest } from "ember-qunit";
import hbs from "htmlbars-inline-precompile";
import { module, test } from "qunit";
import { query } from "discourse/tests/helpers/qunit-helpers";
const repoProps = {
unloaded: false,
@ -46,7 +45,7 @@ const managerProps = {
module("Integration | Component | RepoStatus", function (hooks) {
setupRenderingTest(hooks);
test("it renders correctly", async function (assert) {
test("renders correctly", async function (assert) {
const store = getOwner(this).lookup("service:store");
this.set("repo", store.createRecord("repo", repoProps));
this.set("managerRepo", store.createRecord("repo", managerProps));
@ -65,26 +64,24 @@ module("Integration | Component | RepoStatus", function (hooks) {
assert
.dom("div.new-commits a")
.hasText("3 new commits", "shows number of new commits");
assert.strictEqual(
query("div.new-commits a").href.trim(),
"https://github.com/discourse/discourse/compare/8f65e4f...2b006c0",
"links to GitHub diff page"
);
assert
.dom("div.new-commits a")
.hasAttribute(
"href",
"https://github.com/discourse/discourse/compare/8f65e4f...2b006c0",
"links to GitHub diff page"
);
this.repo.pretty_version = null;
this.repo.latest.pretty_version = null;
await settled();
assert.strictEqual(
query("a.current.commit-hash").textContent.trim(),
"8f65e4f",
"commit hash is used when tag version is absent"
);
assert.strictEqual(
query("a.new.commit-hash").textContent.trim(),
"2b006c0",
"commit hash is used when tag version is absent"
);
assert
.dom("a.current.commit-hash")
.hasText("8f65e4f", "commit hash is used when tag version is absent");
assert
.dom("a.new.commit-hash")
.hasText("2b006c0", "commit hash is used when tag version is absent");
});
test("official plugin", async function (assert) {
@ -97,11 +94,9 @@ module("Integration | Component | RepoStatus", function (hooks) {
hbs`<RepoStatus @repo={{this.repo}} @managerRepo={{this.managerRepo}} />`
);
assert.strictEqual(
query("div.d-admin-row__overview-author").textContent.trim(),
"By Discourse",
"shows plugin author"
);
assert
.dom("div.d-admin-row__overview-author")
.hasText("By Discourse", "shows plugin author");
});
test("update button", async function (assert) {