Jun 14, 2006
[Trac] Trac にチャレンジ(5)
カスタムレポートの作成
Trac はバグや TODO、その他 issue などを Ticket として管理する。 レポート機能を使用することで Ticket の一覧画面を簡単にカスタマイズできる。 例えば、「バージョンが 1.0.0 の Ticket 全て」「マイルストーン MS_001 の Ticket の内クローズされていないもの」といった画面を作成できる。 レポートは非常に便利な機能なので、自前の Report 作成にチャレンジしてみた。
カスタムレポートの作成方法
カスタムレポートの作成方法は Trac のヘルプに記述されている。
- Trac Reports
- https://www.in-vitro.jp/projects/wiki/TracReports
- Trac Permissions
- https://www.in-vitro.jp/projects/wiki/TracPermissions
アカウントにレポート生成権限を付与
デフォルト状態のアカウントはレポート生成権限を持っていない。 そのため、trac-admin コマンドを使用してレポート生成権限を与える。
ちなみに、レポート関連の権限には REPORT_VIEW, REPORT_CREATE, REPORT_MODIFY, REPORT_DELETE, REPORT_ADMIN, REPORT_SQL_VIEW がある。 REPORT_CREATE を付与するついでに REPORT_MODIFY を付与しておくと、デフォルトで用意されているレポートの定義情報を見られるようになる。# trac-admin /tmp/trac/myprojects permission add me REPORT_CREATE
レポートの作成
REPORT_CREATE 権限を所有しているアカウントでログインすると、"View Tickets" 画面に "New Report" というリンクが表示される。 "New Report" からレポート生成画面に移動し、Report Title、Description、SQL Query for Report を入力するとレポートが生成される。 今回は特定のコンポーネント用の Ticket を表示するレポートを作成してみた。 作成した、とは言ってもほとんどデフォルトで用意されているレポートの Copy & Paste。
Active Tickets by Component [MyComponent] SELECT p.value AS __color__, t.milestone AS __group__, (CASE status WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;' ELSE (CASE owner WHEN '$USER' THEN 'font-weight: bold' END) END) AS __style__, id AS ticket, summary, component, status, resolution,version, severity, priority, owner, changetime AS modified, time AS _time,reporter AS _reporter FROM ticket t,enum p WHERE status IN ('new', 'assigned', 'reopened') AND p.name=t.priority AND p.type='priority' AND component='MyComponent' ORDER BY (milestone IS NULL), milestone DESC, (status = 'closed'), (CASE status WHEN 'closed' THEN modified ELSE -p.value END) DESC
All Tickets By Component[MyComponent] (Including closed) SELECT p.value AS __color__, t.milestone AS __group__, (CASE status WHEN 'closed' THEN 'color: #777; background: #ddd; border-color: #ccc;' ELSE (CASE owner WHEN '$USER' THEN 'font-weight: bold' END) END) AS __style__, id AS ticket, summary, component, status, resolution,version, severity, priority, owner, changetime AS modified, time AS _time,reporter AS _reporter FROM ticket t,enum p WHERE p.name=t.priority AND p.type='priority' AND component='MyComponent' ORDER BY (milestone IS NULL), milestone DESC, (status = 'closed'), (CASE status WHEN 'closed' THEN modified ELSE -p.value END) DESC