YouTrack クラウド 2024.3 ヘルプ

カスタムスクリプト

カスタムスクリプトを使用すると、コードブロックを整理して再利用できます。特定のタイプのルールは含まれていません。代わりに、他のスクリプトで使用できるコードが含まれています。

どのスクリプトでも、exports オブジェクトのプロパティとして割り当てることにより、他のスクリプトで使用するオブジェクトと関数を定義できます。

以下に例を示します。

最初に、単純な関数を定義するカスタムスクリプトを作成します。

// 'math.js' exports.f = function (x) { return x * x - 6 * x + 13; }; // And these are a couple of constants we need. exports.lower = 0; exports.upper = 9;

これで、exports オブジェクトに対して定義したプロパティを含む math オブジェクトが作成されました。これは、この関数に math.f としてアクセスできることを意味します。

次に、この関数を参照するアクションルールを記述します。

// 'chart.js' const entities = require('@jetbrains/youtrack-scripting-api/entities'); const math = require('./math'); exports.rule = entities.Issue.action({ title: 'Draw a chart', command: 'draw', action: (ctx) => { const issue = ctx.issue; var chart = ''; for (var x = math.lower; x <= math.upper; x++) { var fx = math.f(x); var line = x + ' | '; for (var i = 0; i < fx; i++) { line = line + "#"; } chart = chart + line + "\n"; } issue.addComment(chart); } });