Skip to content

feat: config を薄くして外部から差し込みやすくする#5005

Open
uni-kakurenbo wants to merge 2 commits into
masterfrom
feat/remove-config-js
Open

feat: config を薄くして外部から差し込みやすくする#5005
uni-kakurenbo wants to merge 2 commits into
masterfrom
feat/remove-config-js

Conversation

@uni-kakurenbo
Copy link
Copy Markdown
Contributor

@uni-kakurenbo uni-kakurenbo commented Dec 31, 2025

概要

なぜこの PR を入れたいのか

closes: #4796

Summary by CodeRabbit

リリースノート

  • ドキュメント

    • Docker環境での外部設定ファイル(config.json / config.js)マウント方法をREADMEに追記しました。
  • 新機能

    • 設定のJSON Schemaを追加し、スキーマに基づく検証を導入しました。
  • 改善

    • 起動時の設定ファイル処理を改善し、config.json と config.js の競合や変換を扱うようになりました。
    • プルリクエストで設定スキーマの整合性を自動チェックする仕組みを追加しました。

@github-actions
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov Bot commented Dec 31, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 62.60%. Comparing base (e40810e) to head (04b1f1a).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5005   +/-   ##
=======================================
  Coverage   62.60%   62.60%           
=======================================
  Files         108      108           
  Lines        3097     3097           
  Branches      630      630           
=======================================
  Hits         1939     1939           
  Misses       1048     1048           
  Partials      110      110           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes config.js from the build process, requiring it to be mounted externally when deploying with Docker. The change introduces TypeScript type definitions and JSON schema for configuration validation, and adds automated schema generation via GitHub Actions.

  • Removed public/config.js from the repository and excluded it from build artifacts via a custom Vite plugin
  • Added config.d.ts TypeScript definitions and config.schema.json for configuration validation
  • Updated Docker deployment to require external mounting of config.js with validation in the startup script

Reviewed changes

Copilot reviewed 9 out of 12 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
vite.config.ts Added Rollup plugin to exclude config.js from build output
tsconfig.json Included config.d.ts in TypeScript compilation
tests/unit/tsconfig.json Included config.d.ts for unit tests
public/config.js Removed configuration file from repository (143 lines deleted)
package.json Added ts-json-schema-generator dependency for schema generation
package-lock.json Updated lock file with new dependency and transitive dependencies
config.schema.json Added JSON schema for configuration validation (134 lines)
config.d.ts Added TypeScript type definitions for Config interface (118 lines)
build/docker/startup.sh Added validation check to ensure config.js is mounted at startup
Dockerfile Removed config.js from default files as it's now externally injected
README.md Added Docker deployment documentation requiring config.js mounting
.github/workflows/generate-schema.yml Added automated workflow to regenerate schema from TypeScript definitions

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread README.md Outdated
Comment thread build/docker/startup.sh Outdated
@uni-kakurenbo uni-kakurenbo force-pushed the feat/remove-config-js branch 3 times, most recently from 768d51d to c5a9e4c Compare January 1, 2026 06:13
@uni-kakurenbo uni-kakurenbo self-assigned this Jan 1, 2026
Comment thread Dockerfile Outdated
ENV THEME_COLOR=#0D67EA

# 設定上書き処理用に、.brを消して、元の設定を別のディレクトリに保存しておく
# config.js は外部から注入されるため除外
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] これって breaking change はあります?(このままアップデートかけても壊れない?)

というか config.js は消すと fork 先がまずかったりする?もしかして(ちゃんと想像がついてないけど) 特に ex とかで困る可能性があるから、どういう対応が必要になるかが分かるような資料は必要になるかも (理想はそのままアップデートかけてもなにも問題がない状態)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

manifest 側の対応が済んでいれば壊れることはないはずですが、fork は何もしないと確実に動かなくなると思います。
ちょっと考えてみます

Comment thread build/docker/startup.sh Outdated

if [ ! -f /app/override/config.js ]; then
echo "ERROR: config.js is not mounted at /app/override/config.js"
echo "Please mount config.js when starting the container:"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[imo] README.md に誘導する文言入れてあげてほしいかも

Comment thread build/docker/startup.sh
CACHE_KEY=$(md5sum /usr/share/caddy/new-relic.js | cut -d ' ' -f 1)
mv /usr/share/caddy/new-relic.js /usr/share/caddy/new-relic-$CACHE_KEY.js
sed -i -e "s/<!-- <script src=\"\/new-relic-{hash}.js\"><\/script> -->/<script src=\"\/new-relic-$CACHE_KEY.js\"><\/script>/" /usr/share/caddy/index.html
echo "Startup: set up New Relic"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

なんか format がかかっちゃってる?理由がなければ戻してほしいかも

Comment thread .github/workflows/generate-schema.yml Outdated
on:
push:
branches:
- master
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[imo] できれば master で push する前に PR のタイミングで生成してもらう(自動テストで diff ないかチェックしてあったら落とす) の方が、 master で変なデータが挟まる可能性がなくて良い気がする

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにです
そうします

Comment thread build/setup-dev-config.sh Outdated

cp "${CONFIG_SOURCE_PATH}" "${CONFIG_DIST_PATH}"
else
echo "config.js not found, downloading from manifest repository..."
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[q] これ echo で出力する理由ってある? なんか 気持ち的には debug レベルの出力( = 普通はなくていい)な気がしちゃう

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

手癖で書いてしまいました
私もいらないと思います

Comment thread config/config.fallback.json Outdated
@@ -0,0 +1,13 @@
{
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fallback よりなんか default config として使えるといいかも

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

たしかにです
薄いほうがいいとは思うのですが、どうしましょう……?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

今の内容で default config を作ってしまえば良いと思います!元々のゴールは conflict 防止なので、別に最悪そこまで薄くなくても良い

Copy link
Copy Markdown
Contributor

@ras0q ras0q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue立てて全然動向を終えてなくてすみません。
問題が複雑になっていそうな気がします。
現状の public/config.js ($schema付きJSONでいいのは間違いないが時すでに遅し) をどこでも動くようにfallbackのものにして、各環境でDockerでマウント or フォークで直接書き換えだけだと足りないですかね?

@uni-kakurenbo
Copy link
Copy Markdown
Contributor Author

issue立てて全然動向を終えてなくてすみません。 問題が複雑になっていそうな気がします。 現状の public/config.js ($schema付きJSONでいいのは間違いないが時すでに遅し) をどこでも動くようにfallbackのものにして、各環境でDockerでマウント or フォークで直接書き換えだけだと足りないですかね?

改めて考えるとたしかにそうですね、なんか勘違いしていた気がします
override する機能は既にあるので文字通り薄くすればいいだけでした

@ras0q
Copy link
Copy Markdown
Contributor

ras0q commented Jan 9, 2026

今更知ったんですが既に/app/overrideにvolumeするだけで上書きできるようになってたんですね #2145
OSSとしてのtraPtitech/traQにq.trap.jp用の設定が書いてあるのは好ましくないですが、#4796 で書いたmergeするたびにconflictは既に避けられるようになっていたのか、、、

@uni-kakurenbo uni-kakurenbo force-pushed the feat/remove-config-js branch from c5a9e4c to fdac172 Compare March 24, 2026 04:21
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Mar 24, 2026

📝 Walkthrough

Walkthrough

TypeScript型からJSON Schemaを自動生成し、生成物の差分をPull Requestでチェックするワークフローを追加。Docker起動時に外部のconfig.jsonを受け取りconfig.jsへ変換する処理を導入し、既存のデフォルトpublic/config.jsを簡素化した。

Changes

Cohort / File(s) Summary
CI ワークフロー
\.github/workflows/check-schema\.yml
Pull Requestごとにnpm run generate-schemaconfig.schema.jsonを再生成し、差分があればジョブを失敗させるワークフローを追加。
スキーマ生成ツール & スクリプト
package\.json, scripts/generate-schema\.js, \.prettierignore
ts-json-schema-generatorをdevDependencyに追加、generate-schemaスクリプトを追加。config.schema.jsonをPrettierの対象外に設定。
TypeScript設定拡張
tsconfig\.json, tests/unit/tsconfig\.json
型定義config.d.tsをコンパイル/テストのincludeに追加し、スキーマ生成で参照可能に。
JSON Schema
config\.schema\.json
Config型から生成されたJSON Schema(Draft-07)を追加。設定の構造と必須項目・禁止プロパティを定義。
Docker 起動スクリプト
build/docker/startup\.sh
/app/override/config.jsonが存在する場合に/usr/share/caddy/config.jsを生成する変換ステップを追加。config.jsonconfig.jsの同時マウント時に警告を出力し、条件分岐の閉じ忘れを修正。
ドキュメント
README\.md
Dockerでの外部config.json/config.jsマウント方法を追記。config.d.tsconfig.schema.jsonへの参照を追加。
公開デフォルト設定の簡素化
public/config\.js
デフォルトpublic/config.jsの中身を大幅に簡素化(Firebaseや多数のサービス/設定項目を除去)し、JSDoc参照先をimport('config').Configへ更新。

Sequence Diagram(s)

sequenceDiagram
    participant GH as GitHub Actions
    participant Repo as Repository
    participant Node as Node.js
    participant FS as Filesystem/Git

    GH->>Repo: checkout
    GH->>Node: setup Node 20
    GH->>Node: npm ci
    GH->>Node: npm run generate-schema
    Node->>FS: read `config.d.ts` & tsconfig
    Node->>FS: write `config.schema.json`
    GH->>FS: git diff --exit-code config.schema.json
    alt diff found
        FS->>GH: non-zero exit -> job fails
    else no diff
        FS->>GH: zero exit -> job passes
    end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning PR の説明は最小限で、概要と関連する issue の番号のみが記載されている。テンプレートで要求されている「なぜこの PR を入れたいのか」「動作確認の手順」「UI 変更部分のスクリーンショット」「見てほしいところ」などの主要セクションが記入されていない。 PR テンプレートの各セクション(概要、動作確認手順、見てほしいところなど)をより詳細に記入してください。少なくとも「なぜこの PR を入れたいのか」と「見てほしいところ」を追加してください。
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed PR タイトルは「config を薄くして外部から差し込みやすくする」で、変更内容の主要な目的(public/config.js を簡潔化し、外部からの設定上書きを容易にする)と一致している。
Linked Issues check ✅ Passed PR で実装されたコード変更は issue #4796 の要件(public/config.js を薄くして q.trap.jp 固有の設定を削除し、外部からの上書きを容易にする)を満たしており、config.schema.json、GitHub Actions ワークフロー、Docker スタートアップスクリプトの改善を通じて外部設定注入メカニズムが強化されている。
Out of Scope Changes check ✅ Passed すべての変更(config.js の簡潔化、generate-schema スクリプト、GitHub Actions ワークフロー、Docker スタートアップ改善、README 更新、prettier 設定、TypeScript 設定)は issue #4796 の目的と外部設定注入メカニズムの構築という範囲内で一貫している。
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/remove-config-js

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (3)
scripts/generate-schema.js (1)

21-23: エラー発生時にエラー内容をログ出力することを推奨します。

現在の実装ではエラーが発生しても内容が出力されないため、デバッグが困難になります。

🐛 提案する修正
 } catch (e) {
+  console.error('Failed to generate schema:', e)
   process.exit(1)
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/generate-schema.js` around lines 21 - 23, The catch block in
scripts/generate-schema.js currently swallows errors (catch (e) {
process.exit(1) }); update it to log the caught error before exiting: inside the
catch (e) handler, call console.error(...) (or a logger if available) with the
error message/stack (e or e.stack) so the error details are output, then call
process.exit(1); keep the existing behavior but ensure the error is logged for
debugging.
README.md (1)

22-31: ドキュメントに config.json のサポートも記載することを検討してください。

startup.sh では config.json から config.js への変換機能が追加されていますが、ドキュメントでは config.js のマウントのみが説明されています。config.json をマウントするオプションも記載すると、ユーザーにとってより分かりやすくなります。

📝 提案する追記例
 When deploying using Docker, you can mount `config.js` externally:
 
 ```bash
 docker run -d \
   -p 80:80 \
   -v /path/to/your/config.js:/app/override/config.js \
   traq-ui:latest

+Alternatively, you can mount config.json which will be automatically converted to config.js:
+
+```bash
+docker run -d \

  • -p 80:80 \
  • -v /path/to/your/config.json:/app/override/config.json \
  • traq-ui:latest
    +```

See config.json in our manifest repository for an example. Refer to config.d.ts for the TypeScript type definition and config.schema.json for the JSON Schema.

</details>

<details>
<summary>🤖 Prompt for AI Agents</summary>

Verify each finding against the current code and only fix it if needed.

In @README.md around lines 22 - 31, The README currently only documents mounting
config.js via Docker but startup.sh also supports mounting config.json which it
converts to config.js; update the README example text to mention and show the
alternative Docker run that mounts config.json (referencing config.json and
config.js and the startup.sh conversion behavior) and include the same links to
the manifest example and config.d.ts/config.schema.json so users know they can
supply either file and that startup.sh will perform the conversion.


</details>

</blockquote></details>
<details>
<summary>.github/workflows/check-schema.yml (1)</summary><blockquote>

`25-27`: **スキーマ変更時のエラーメッセージを改善することを検討してください。**

`git diff --exit-code` が失敗した場合、ユーザーにとって何をすべきか分かりにくい可能性があります。

<details>
<summary>📝 提案する改善</summary>

```diff
       - name: Check for changes
         run: |
           git diff --exit-code config.schema.json
+        continue-on-error: false
+      
+      - name: Fail with helpful message
+        if: failure()
+        run: |
+          echo "::error::config.schema.json is out of sync with config.d.ts. Please run 'npm run generate-schema' and commit the changes."
+          exit 1
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.github/workflows/check-schema.yml around lines 25 - 27, The "Check for
changes" workflow step currently runs "git diff --exit-code config.schema.json"
which fails without guidance; update that step to catch failure and print a
clear, actionable message telling the user what to do (e.g., that the schema
changed and they should run the schema generation/formatter command and commit
the updated config.schema.json), include a brief git diff output for context,
and then exit non-zero; locate the step named "Check for changes" and replace
the direct git diff invocation with a command sequence that echoes the
user-facing instructions on failure, shows the diff for debugging, and returns
the failing exit code.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.github/workflows/check-schema.yml:
- Around line 25-27: The "Check for changes" workflow step currently runs "git
diff --exit-code config.schema.json" which fails without guidance; update that
step to catch failure and print a clear, actionable message telling the user
what to do (e.g., that the schema changed and they should run the schema
generation/formatter command and commit the updated config.schema.json), include
a brief git diff output for context, and then exit non-zero; locate the step
named "Check for changes" and replace the direct git diff invocation with a
command sequence that echoes the user-facing instructions on failure, shows the
diff for debugging, and returns the failing exit code.

In `@README.md`:
- Around line 22-31: The README currently only documents mounting config.js via
Docker but startup.sh also supports mounting config.json which it converts to
config.js; update the README example text to mention and show the alternative
Docker run that mounts config.json (referencing config.json and config.js and
the startup.sh conversion behavior) and include the same links to the manifest
example and config.d.ts/config.schema.json so users know they can supply either
file and that startup.sh will perform the conversion.

In `@scripts/generate-schema.js`:
- Around line 21-23: The catch block in scripts/generate-schema.js currently
swallows errors (catch (e) { process.exit(1) }); update it to log the caught
error before exiting: inside the catch (e) handler, call console.error(...) (or
a logger if available) with the error message/stack (e or e.stack) so the error
details are output, then call process.exit(1); keep the existing behavior but
ensure the error is logged for debugging.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ceeb2c41-73ab-484b-9d5f-8f7776ab387f

📥 Commits

Reviewing files that changed from the base of the PR and between e40810e and fdac172.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (10)
  • .github/workflows/check-schema.yml
  • .prettierignore
  • README.md
  • build/docker/startup.sh
  • config.d.ts
  • config.schema.json
  • package.json
  • scripts/generate-schema.js
  • tests/unit/tsconfig.json
  • tsconfig.json

@uni-kakurenbo uni-kakurenbo force-pushed the feat/remove-config-js branch 3 times, most recently from 08b8ecd to 91fbd9f Compare March 24, 2026 04:38
@uni-kakurenbo uni-kakurenbo changed the title feat: config.js をビルドから除外する feat: config を薄くして外部から差し込みやすくする Mar 25, 2026
@uni-kakurenbo uni-kakurenbo force-pushed the feat/remove-config-js branch from 91fbd9f to 6f0e0cf Compare March 25, 2026 07:51
@uni-kakurenbo uni-kakurenbo force-pushed the feat/remove-config-js branch from 6f0e0cf to 04b1f1a Compare March 25, 2026 09:10
Copy link
Copy Markdown

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
build/docker/startup.sh (1)

30-34: (オプション)JSON の基本的なバリデーションを追加することを検討してください。

不正な JSON がマウントされた場合、生成される config.js は無効な JavaScript となり、アプリケーションが起動時にエラーを出す可能性があります。jq を使用したシンプルなバリデーションで、起動前にわかりやすいエラーメッセージを表示できます。

💡 バリデーション追加の提案
 if [ -f /app/override/config.json ]; then
     if [ -f /app/override/config.js ]; then
         echo "WARNING: Both config.json and config.js are mounted at /app/override/"
         echo "WARNING: config.js will be ignored and overwritten by the mapped config.json"
     fi
+    if ! jq empty /app/override/config.json 2>/dev/null; then
+        echo "ERROR: /app/override/config.json is not valid JSON"
+        exit 1
+    fi
     echo "Startup: converting config.json to config.js"
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@build/docker/startup.sh` around lines 30 - 34, Add a JSON validation step in
the startup.sh block that builds /usr/share/caddy/config.js: before running the
existing heredoc that cats /app/override/config.json, run a check like invoking
jq -e . on /app/override/config.json and if it fails print a clear error to
stderr and exit non‑zero; only on success continue to write the file (the code
that echoes ";(() => { self.traQConfig = " and cats the file into
/usr/share/caddy/config.js should remain unchanged but guarded by this
validation).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@build/docker/startup.sh`:
- Around line 30-34: Add a JSON validation step in the startup.sh block that
builds /usr/share/caddy/config.js: before running the existing heredoc that cats
/app/override/config.json, run a check like invoking jq -e . on
/app/override/config.json and if it fails print a clear error to stderr and exit
non‑zero; only on success continue to write the file (the code that echoes ";(()
=> { self.traQConfig = " and cats the file into /usr/share/caddy/config.js
should remain unchanged but guarded by this validation).

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5fd79f12-8068-4e39-a1fd-1b07179b454c

📥 Commits

Reviewing files that changed from the base of the PR and between fdac172 and 04b1f1a.

⛔ Files ignored due to path filters (1)
  • package-lock.json is excluded by !**/package-lock.json
📒 Files selected for processing (11)
  • .github/workflows/check-schema.yml
  • .prettierignore
  • README.md
  • build/docker/startup.sh
  • config.d.ts
  • config.schema.json
  • package.json
  • public/config.js
  • scripts/generate-schema.js
  • tests/unit/tsconfig.json
  • tsconfig.json
✅ Files skipped from review due to trivial changes (6)
  • tests/unit/tsconfig.json
  • tsconfig.json
  • .github/workflows/check-schema.yml
  • scripts/generate-schema.js
  • README.md
  • .prettierignore
🚧 Files skipped from review as they are similar to previous changes (1)
  • config.schema.json

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

デフォルトのconfig.jsを薄くする

4 participants