@we-scrum/cli 6.11.5 → 6.11.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +58 -0
- package/dist/cli.js +287 -80
- package/package.json +5 -4
- package/src/cli.ts +4 -0
- package/src/commands/analysis.ts +53 -0
- package/src/commands/index.ts +2 -0
- package/src/commands/policy.ts +40 -2
- package/src/commands/story.ts +0 -10
- package/src/commands/task-type.ts +24 -0
- package/src/hbs.d.ts +5 -0
- package/src/helpers/change-hint.helper.ts +59 -0
- package/src/helpers/index.ts +1 -0
- package/src/helpers/project-helper.ts +7 -5
- package/src/helpers/template.helper.ts +6 -2
- package/src/helpers/we-scrum.helper.ts +206 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/read-content.ts +11 -0
- package/templates/analyse-story-skill.hbs +197 -0
- package/templates/analysis-dsl.md +218 -0
- package/templates/analysis-review-criteria.hbs +22 -0
- package/templates/get-next-task.hbs +1 -1
- package/templates/review-analysis-skill.hbs +4 -25
- package/templates/analysis-dsl-legend.hbs +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@we-scrum/cli",
|
|
3
|
-
"version": "6.11.
|
|
3
|
+
"version": "6.11.20",
|
|
4
4
|
"description": "Cli tool for we-scrum application",
|
|
5
5
|
"main": "dist/cli.js",
|
|
6
6
|
"bin": {
|
|
@@ -22,7 +22,8 @@
|
|
|
22
22
|
"@my-devkit/*"
|
|
23
23
|
],
|
|
24
24
|
"loader": {
|
|
25
|
-
".hbs": "text"
|
|
25
|
+
".hbs": "text",
|
|
26
|
+
".md": "text"
|
|
26
27
|
}
|
|
27
28
|
},
|
|
28
29
|
"dependencies": {
|
|
@@ -40,9 +41,9 @@
|
|
|
40
41
|
"@my-devkit/cli": "2.1.0",
|
|
41
42
|
"@we-scrum/commands": "1.0.0",
|
|
42
43
|
"@my-devkit/core": "1.0.0",
|
|
43
|
-
"@we-scrum/
|
|
44
|
+
"@we-scrum/utils": "1.0.0",
|
|
44
45
|
"@we-scrum/models": "1.0.0",
|
|
45
|
-
"@we-scrum/
|
|
46
|
+
"@we-scrum/enums": "1.0.0"
|
|
46
47
|
},
|
|
47
48
|
"scripts": {
|
|
48
49
|
"start": "node dist/cli.js",
|
package/src/cli.ts
CHANGED
|
@@ -3,6 +3,7 @@ import { Logger } from '@my-devkit/core';
|
|
|
3
3
|
import { Command } from 'commander';
|
|
4
4
|
import { version } from '../package.json';
|
|
5
5
|
import {
|
|
6
|
+
registerAnalysisCommands,
|
|
6
7
|
registerAuthCommands,
|
|
7
8
|
registerChangeThreadCommands,
|
|
8
9
|
registerIterationCommands,
|
|
@@ -10,6 +11,7 @@ import {
|
|
|
10
11
|
registerProjectCommands,
|
|
11
12
|
registerStoryCommands,
|
|
12
13
|
registerTaskCommands,
|
|
14
|
+
registerTaskTypeCommands,
|
|
13
15
|
} from './commands';
|
|
14
16
|
|
|
15
17
|
Logger.registerLogger(new Logger.ConsoleImplementation());
|
|
@@ -21,7 +23,9 @@ program.name('we-scrum').description('CLI for we-scrum application').version(ver
|
|
|
21
23
|
registerAuthCommands(program);
|
|
22
24
|
registerProjectCommands(program);
|
|
23
25
|
registerStoryCommands(program);
|
|
26
|
+
registerAnalysisCommands(program);
|
|
24
27
|
registerTaskCommands(program);
|
|
28
|
+
registerTaskTypeCommands(program);
|
|
25
29
|
registerPolicyCommands(program);
|
|
26
30
|
registerIterationCommands(program);
|
|
27
31
|
registerChangeThreadCommands(program);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { WeScrumHelper } from '@helpers';
|
|
2
|
+
import { Logger } from '@my-devkit/core';
|
|
3
|
+
import { readContent, runProjectCommand } from '@utils';
|
|
4
|
+
import { Command } from 'commander';
|
|
5
|
+
|
|
6
|
+
export function registerAnalysisCommands(program: Command): void {
|
|
7
|
+
program
|
|
8
|
+
.command('get-story-analysis')
|
|
9
|
+
.description('Get the analysis DSL for a story')
|
|
10
|
+
.requiredOption('-i, --identificationNumber <id>', 'Story identification number')
|
|
11
|
+
.action(
|
|
12
|
+
runProjectCommand<{ identificationNumber: string }>(async (options) => {
|
|
13
|
+
return WeScrumHelper.getStoryAnalysis(options.identificationNumber);
|
|
14
|
+
}),
|
|
15
|
+
);
|
|
16
|
+
|
|
17
|
+
program
|
|
18
|
+
.command('update-story-analysis')
|
|
19
|
+
.description('Create or update one change of a story analysis')
|
|
20
|
+
.requiredOption('-i, --identificationNumber <id>', 'Story identification number')
|
|
21
|
+
.option('-c, --content <dsl>', 'Analysis DSL of exactly one change (read from stdin when omitted)')
|
|
22
|
+
.action(
|
|
23
|
+
runProjectCommand<{ identificationNumber: string; content?: string }>(async (options) => {
|
|
24
|
+
const content = await readContent(options.content);
|
|
25
|
+
const changeId = await WeScrumHelper.updateStoryAnalysis(options.identificationNumber, content);
|
|
26
|
+
Logger.info(`Change "${changeId}" saved successfully.`);
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
program
|
|
31
|
+
.command('reorganize-story-analysis')
|
|
32
|
+
.description('Reorder the sections and changes of a story analysis')
|
|
33
|
+
.requiredOption('-i, --identificationNumber <id>', 'Story identification number')
|
|
34
|
+
.option('-c, --content <content>', 'Reorganization content (read from stdin when omitted)')
|
|
35
|
+
.action(
|
|
36
|
+
runProjectCommand<{ identificationNumber: string; content?: string }>(async (options) => {
|
|
37
|
+
const content = await readContent(options.content);
|
|
38
|
+
await WeScrumHelper.reorganizeStoryAnalysis(options.identificationNumber, content);
|
|
39
|
+
Logger.info('Story analysis reorganized successfully.');
|
|
40
|
+
}),
|
|
41
|
+
);
|
|
42
|
+
|
|
43
|
+
program
|
|
44
|
+
.command('delete-change')
|
|
45
|
+
.description('Delete one change of a story analysis')
|
|
46
|
+
.requiredOption('-c, --changeId <id>', 'Unique identifier of the change')
|
|
47
|
+
.action(
|
|
48
|
+
runProjectCommand<{ changeId: string }>(async (options) => {
|
|
49
|
+
await WeScrumHelper.deleteChange(options.changeId);
|
|
50
|
+
Logger.info('Change deleted successfully.');
|
|
51
|
+
}),
|
|
52
|
+
);
|
|
53
|
+
}
|
package/src/commands/index.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
export * from './analysis';
|
|
1
2
|
export * from './auth';
|
|
2
3
|
export * from './change-thread';
|
|
3
4
|
export * from './iteration';
|
|
@@ -5,3 +6,4 @@ export * from './policy';
|
|
|
5
6
|
export * from './project';
|
|
6
7
|
export * from './story';
|
|
7
8
|
export * from './task';
|
|
9
|
+
export * from './task-type';
|
package/src/commands/policy.ts
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
import { WeScrumHelper } from '@helpers';
|
|
2
|
-
import { Logger } from '@my-devkit/core';
|
|
2
|
+
import { assert, Logger } from '@my-devkit/core';
|
|
3
3
|
import { runProjectCommand } from '@utils';
|
|
4
|
-
import {
|
|
4
|
+
import { ChangeType, RouteMethod } from '@we-scrum/enums';
|
|
5
|
+
import { Command, Option } from 'commander';
|
|
6
|
+
|
|
7
|
+
type AnalysisGuidelinesOptions = {
|
|
8
|
+
changeType?: ChangeType;
|
|
9
|
+
taskType?: string;
|
|
10
|
+
objectName?: string;
|
|
11
|
+
routeMethod?: RouteMethod;
|
|
12
|
+
relationObjects?: string;
|
|
13
|
+
};
|
|
5
14
|
|
|
6
15
|
export function registerPolicyCommands(program: Command): void {
|
|
7
16
|
program
|
|
@@ -14,4 +23,33 @@ export function registerPolicyCommands(program: Command): void {
|
|
|
14
23
|
Logger.info(`Synchronized ${count} ${count === 1 ? 'guideline' : 'guidelines'}.`);
|
|
15
24
|
}),
|
|
16
25
|
);
|
|
26
|
+
|
|
27
|
+
program
|
|
28
|
+
.command('get-analysis-guidelines')
|
|
29
|
+
.description('List the analysis guidelines of the project, or find the one matching a change')
|
|
30
|
+
.addOption(
|
|
31
|
+
new Option('--changeType <type>', 'Type of the change to match').choices(
|
|
32
|
+
ChangeType.helper.members.filter((changeType) => changeType !== ChangeType.Global),
|
|
33
|
+
),
|
|
34
|
+
)
|
|
35
|
+
.option('--taskType <name>', 'Task type name of an OpenTask change')
|
|
36
|
+
.option('--objectName <name>', 'Object name of an Object change')
|
|
37
|
+
.addOption(new Option('--routeMethod <method>', 'Method of a Route change').choices(RouteMethod.helper.members))
|
|
38
|
+
.option('--relationObjects <a,b,c>', 'Comma separated object names of the first relation of a Handler change')
|
|
39
|
+
.action(
|
|
40
|
+
runProjectCommand<AnalysisGuidelinesOptions>(async ({ changeType, relationObjects, ...criteria }) => {
|
|
41
|
+
if (!changeType) {
|
|
42
|
+
assert(
|
|
43
|
+
!relationObjects && Object.values(criteria).every((value) => value === undefined),
|
|
44
|
+
'The criteria options require --changeType.',
|
|
45
|
+
);
|
|
46
|
+
return WeScrumHelper.getAnalysisGuidelinesIndex();
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return WeScrumHelper.getMatchingAnalysisGuidelines(changeType, {
|
|
50
|
+
...criteria,
|
|
51
|
+
relationObjects: relationObjects?.split(',').map((name) => name.trim()),
|
|
52
|
+
});
|
|
53
|
+
}),
|
|
54
|
+
);
|
|
17
55
|
}
|
package/src/commands/story.ts
CHANGED
|
@@ -13,16 +13,6 @@ export function registerStoryCommands(program: Command): void {
|
|
|
13
13
|
}),
|
|
14
14
|
);
|
|
15
15
|
|
|
16
|
-
program
|
|
17
|
-
.command('get-story-analysis')
|
|
18
|
-
.description('Get the analysis DSL for a story')
|
|
19
|
-
.requiredOption('-i, --identificationNumber <id>', 'Story identification number')
|
|
20
|
-
.action(
|
|
21
|
-
runProjectCommand<{ identificationNumber: string }>(async (options) => {
|
|
22
|
-
return WeScrumHelper.getStoryAnalysis(options.identificationNumber);
|
|
23
|
-
}),
|
|
24
|
-
);
|
|
25
|
-
|
|
26
16
|
program
|
|
27
17
|
.command('get-next-task')
|
|
28
18
|
.description('Get the next pending task for a story')
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { WeScrumHelper } from '@helpers';
|
|
2
|
+
import { runProjectCommand } from '@utils';
|
|
3
|
+
import { Command } from 'commander';
|
|
4
|
+
|
|
5
|
+
export function registerTaskTypeCommands(program: Command): void {
|
|
6
|
+
program
|
|
7
|
+
.command('get-task-types')
|
|
8
|
+
.description('Get the task types of the active project')
|
|
9
|
+
.action(
|
|
10
|
+
runProjectCommand(async () => {
|
|
11
|
+
return WeScrumHelper.getTaskTypes();
|
|
12
|
+
}),
|
|
13
|
+
);
|
|
14
|
+
|
|
15
|
+
program
|
|
16
|
+
.command('get-task-type-template')
|
|
17
|
+
.description('Get the template of a task type of the active project')
|
|
18
|
+
.requiredOption('-n, --name <name>', 'Exact name of the task type')
|
|
19
|
+
.action(
|
|
20
|
+
runProjectCommand<{ name: string }>(async (options) => {
|
|
21
|
+
return WeScrumHelper.getTaskTypeTemplate(options.name);
|
|
22
|
+
}),
|
|
23
|
+
);
|
|
24
|
+
}
|
package/src/hbs.d.ts
CHANGED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export type GuidelinesKind = 'analysis' | 'development' | 'tests';
|
|
2
|
+
|
|
3
|
+
const GUIDELINES_LABELS: Record<GuidelinesKind, string> = {
|
|
4
|
+
analysis: 'Analysis guidelines',
|
|
5
|
+
development: 'Development guidelines',
|
|
6
|
+
tests: 'Unit tests guidelines',
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* The read-only hint lines appended to the change descriptions of an analysis output.
|
|
11
|
+
* Each format must be matched by the corresponding pattern, so that the hints can be removed from a content sent back.
|
|
12
|
+
*/
|
|
13
|
+
export class ChangeHintHelper {
|
|
14
|
+
private static readonly patterns: RegExp[] = [
|
|
15
|
+
/^Threads: .+ — run `we-scrum get-change-threads --changeId "[^"]*"` to view them\.$/,
|
|
16
|
+
new RegExp(`^(${Object.values(GUIDELINES_LABELS).join('|')}): \`[^\`]*\`$`),
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
public static formatThreads(synthesis: string, changeId: string): string {
|
|
20
|
+
return `Threads: ${synthesis} — run \`we-scrum get-change-threads --changeId "${changeId}"\` to view them.`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
public static formatGuidelines(kind: GuidelinesKind, path: string): string {
|
|
24
|
+
return `${GUIDELINES_LABELS[kind]}: \`${path}\``;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/** Removes the hint lines from the descriptions of an analysis DSL. A description made of hints only is removed. */
|
|
28
|
+
public static removeFromDsl(dsl: string): string {
|
|
29
|
+
const result: string[] = [];
|
|
30
|
+
let description: string[] | null = null;
|
|
31
|
+
|
|
32
|
+
for (const line of dsl.split('\n')) {
|
|
33
|
+
if (line === ':::') {
|
|
34
|
+
if (description) {
|
|
35
|
+
result.push(...this.cleanDescriptionBlock(description));
|
|
36
|
+
description = null;
|
|
37
|
+
} else {
|
|
38
|
+
description = [];
|
|
39
|
+
}
|
|
40
|
+
} else {
|
|
41
|
+
(description ?? result).push(line);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
return result.join('\n');
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
private static cleanDescriptionBlock(lines: string[]): string[] {
|
|
49
|
+
const kept = lines.filter((line) => !this.patterns.some((pattern) => pattern.test(line.trimEnd())));
|
|
50
|
+
|
|
51
|
+
if (kept.length < lines.length) {
|
|
52
|
+
// The hints are separated from the description by blank lines
|
|
53
|
+
while (kept.length > 0 && !kept[kept.length - 1].trim()) kept.pop();
|
|
54
|
+
if (kept.length === 0) return [];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return [':::', ...kept, ':::'];
|
|
58
|
+
}
|
|
59
|
+
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -94,13 +94,15 @@ export class ProjectHelper {
|
|
|
94
94
|
|
|
95
95
|
private static installSkills(root: string): void {
|
|
96
96
|
if (!existsSync(join(root, '.claude'))) return;
|
|
97
|
-
for (const [
|
|
98
|
-
['develop-story', 'develop-story-skill'],
|
|
99
|
-
['review-analysis', 'review-analysis-skill'],
|
|
97
|
+
for (const [skill, fileName, template] of [
|
|
98
|
+
['develop-story', 'SKILL.md', 'develop-story-skill'],
|
|
99
|
+
['review-analysis', 'SKILL.md', 'review-analysis-skill'],
|
|
100
|
+
['analyse-story', 'SKILL.md', 'analyse-story-skill'],
|
|
101
|
+
['analyse-story', 'analysis-dsl.md', 'analysis-dsl'],
|
|
100
102
|
] as const) {
|
|
101
|
-
const skillDir = join(root, '.claude', 'skills',
|
|
103
|
+
const skillDir = join(root, '.claude', 'skills', skill);
|
|
102
104
|
mkdirSync(skillDir, { recursive: true });
|
|
103
|
-
writeFileSync(join(skillDir,
|
|
105
|
+
writeFileSync(join(skillDir, fileName), renderTemplate(template));
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
}
|
|
@@ -1,13 +1,17 @@
|
|
|
1
1
|
import Handlebars from 'handlebars';
|
|
2
|
-
import
|
|
2
|
+
import analyseStorySkill from '../../templates/analyse-story-skill.hbs';
|
|
3
|
+
import analysisDsl from '../../templates/analysis-dsl.md';
|
|
4
|
+
import analysisReviewCriteria from '../../templates/analysis-review-criteria.hbs';
|
|
3
5
|
import developStorySkill from '../../templates/develop-story-skill.hbs';
|
|
4
6
|
import getNextTaskBreakpoint from '../../templates/get-next-task-breakpoint.hbs';
|
|
5
7
|
import getNextTask from '../../templates/get-next-task.hbs';
|
|
6
8
|
import reviewAnalysisSkill from '../../templates/review-analysis-skill.hbs';
|
|
7
9
|
|
|
8
|
-
Handlebars.registerPartial('analysis-
|
|
10
|
+
Handlebars.registerPartial('analysis-review-criteria', analysisReviewCriteria);
|
|
9
11
|
|
|
10
12
|
const sources = {
|
|
13
|
+
'analyse-story-skill': analyseStorySkill,
|
|
14
|
+
'analysis-dsl': analysisDsl,
|
|
11
15
|
'develop-story-skill': developStorySkill,
|
|
12
16
|
'get-next-task': getNextTask,
|
|
13
17
|
'get-next-task-breakpoint': getNextTaskBreakpoint,
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import { _sortBy, assert, Command, ContributionOrigin, serialize, TypeHelper } from '@my-devkit/core';
|
|
1
|
+
import { _sortBy, assert, Command, ContributionOrigin, Logger, serialize, TypeHelper } from '@my-devkit/core';
|
|
2
2
|
import {
|
|
3
3
|
AddCommentToChangeThreadCommand,
|
|
4
|
+
BulkReorganizeStoryAnalysisCommand,
|
|
5
|
+
BulkUpdateStoryAnalysisCommand,
|
|
4
6
|
CreateChangeThreadCommand,
|
|
7
|
+
DeleteChangeCommand,
|
|
5
8
|
MarkEnumerationChangeAsDoneCommand,
|
|
6
9
|
MarkObjectChangeAsDoneCommand,
|
|
7
10
|
MarkRelationChangeAsDoneCommand,
|
|
@@ -16,7 +19,15 @@ import {
|
|
|
16
19
|
UpdateChangeThreadStatusCommand,
|
|
17
20
|
UpdateIterationCommand,
|
|
18
21
|
} from '@we-scrum/commands';
|
|
19
|
-
import {
|
|
22
|
+
import {
|
|
23
|
+
ChangeThreadStatus,
|
|
24
|
+
ChangeType,
|
|
25
|
+
ContentType,
|
|
26
|
+
DevelopmentPolicyMatchingRuleCriteria,
|
|
27
|
+
Operator,
|
|
28
|
+
ProgressStatus,
|
|
29
|
+
RouteMethod,
|
|
30
|
+
} from '@we-scrum/enums';
|
|
20
31
|
import {
|
|
21
32
|
DevelopmentPolicyModel,
|
|
22
33
|
ProjectChangeThreadModel,
|
|
@@ -28,18 +39,36 @@ import {
|
|
|
28
39
|
ProjectStorySectionModelRelationChange,
|
|
29
40
|
ProjectStorySectionModelRouteChange,
|
|
30
41
|
ProjectStorySectionModelTask,
|
|
42
|
+
ProjectTaskTypeModel,
|
|
31
43
|
} from '@we-scrum/models';
|
|
32
|
-
import {
|
|
44
|
+
import {
|
|
45
|
+
AnalysisDsl,
|
|
46
|
+
DevelopmentPolicyHelper,
|
|
47
|
+
HtmlToTextHelper,
|
|
48
|
+
StoryAnalysisReorganizationHelper,
|
|
49
|
+
StorySectionHelper,
|
|
50
|
+
stringifyAnalysisDslChange,
|
|
51
|
+
} from '@we-scrum/utils';
|
|
33
52
|
import { mkdirSync, rmSync, writeFileSync } from 'node:fs';
|
|
34
53
|
import { join } from 'node:path';
|
|
35
54
|
import { AttachmentHelper } from './attachment-helper';
|
|
36
55
|
import { AuthHelper } from './auth-helper';
|
|
56
|
+
import { ChangeHintHelper, GuidelinesKind } from './change-hint.helper';
|
|
37
57
|
import { FirebaseHelper } from './firebase-helper';
|
|
38
58
|
import { ProjectHelper } from './project-helper';
|
|
39
59
|
import { renderTemplate } from './template.helper';
|
|
40
60
|
|
|
41
61
|
const CHANGE_THREAD_STATUS_DISPLAY_ORDER = [ChangeThreadStatus.Open, ChangeThreadStatus.Resolved, ChangeThreadStatus.Archived];
|
|
42
62
|
|
|
63
|
+
const MATCHING_RULE_CRITERIA_WORDS: Record<DevelopmentPolicyMatchingRuleCriteria, string> = {
|
|
64
|
+
[DevelopmentPolicyMatchingRuleCriteria.TaskType]: 'task type',
|
|
65
|
+
[DevelopmentPolicyMatchingRuleCriteria.ObjectName]: 'object name',
|
|
66
|
+
[DevelopmentPolicyMatchingRuleCriteria.RouteMethod]: 'route method',
|
|
67
|
+
[DevelopmentPolicyMatchingRuleCriteria.FirstRelationObjectName]: 'first relation object name',
|
|
68
|
+
[DevelopmentPolicyMatchingRuleCriteria.SecondRelationObjectName]: 'second relation object name',
|
|
69
|
+
[DevelopmentPolicyMatchingRuleCriteria.ThirdRelationObjectName]: 'third relation object name',
|
|
70
|
+
};
|
|
71
|
+
|
|
43
72
|
export class WeScrumHelper {
|
|
44
73
|
private static readonly backendUrl = 'https://europe-west1-we-scrum-prod.cloudfunctions.net';
|
|
45
74
|
constructor(private userId: string) {}
|
|
@@ -239,7 +268,7 @@ export class WeScrumHelper {
|
|
|
239
268
|
const policies = await this.getDevelopmentPolicies();
|
|
240
269
|
this.getAllChanges(sections).forEach((change) => {
|
|
241
270
|
this.appendThreadsHint(change);
|
|
242
|
-
this.
|
|
271
|
+
this.appendGuidelinesHints(change, policies);
|
|
243
272
|
});
|
|
244
273
|
|
|
245
274
|
const ast = StorySectionHelper.mapSectionsToAnalysisAst(sections);
|
|
@@ -247,6 +276,105 @@ export class WeScrumHelper {
|
|
|
247
276
|
return AttachmentHelper.localize(AnalysisDsl.stringify(ast));
|
|
248
277
|
}
|
|
249
278
|
|
|
279
|
+
/** Creates or updates the single change described by the given DSL, and returns its id. */
|
|
280
|
+
public static async updateStoryAnalysis(identificationNumber: string, content: string): Promise<string> {
|
|
281
|
+
const dsl = content.replace(/\r\n/g, '\n');
|
|
282
|
+
this.assertSingleChangeDsl(dsl);
|
|
283
|
+
|
|
284
|
+
const story = await this.findStoryByIterationNumber(identificationNumber);
|
|
285
|
+
assert(!!story, `Story "${identificationNumber}" not found in the active project.`);
|
|
286
|
+
|
|
287
|
+
return this.post(
|
|
288
|
+
'project-management/bulk-update-story-analysis',
|
|
289
|
+
TypeHelper.transform(BulkUpdateStoryAnalysisCommand, {
|
|
290
|
+
storyId: story.storyId,
|
|
291
|
+
content: ChangeHintHelper.removeFromDsl(dsl),
|
|
292
|
+
}),
|
|
293
|
+
);
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
public static async reorganizeStoryAnalysis(identificationNumber: string, content: string): Promise<void> {
|
|
297
|
+
const { deletedChangeIds } = StoryAnalysisReorganizationHelper.parse(content);
|
|
298
|
+
assert(
|
|
299
|
+
deletedChangeIds.length === 0,
|
|
300
|
+
'"> delete:" lines are not supported: delete the changes one by one with "we-scrum delete-change --changeId <changeId>".',
|
|
301
|
+
);
|
|
302
|
+
|
|
303
|
+
const story = await this.findStoryByIterationNumber(identificationNumber);
|
|
304
|
+
assert(!!story, `Story "${identificationNumber}" not found in the active project.`);
|
|
305
|
+
|
|
306
|
+
await this.post(
|
|
307
|
+
'project-management/bulk-reorganize-story-analysis',
|
|
308
|
+
TypeHelper.transform(BulkReorganizeStoryAnalysisCommand, { storyId: story.storyId, content }),
|
|
309
|
+
);
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
public static async deleteChange(changeId: string): Promise<void> {
|
|
313
|
+
await this.post('project-management/delete-change', TypeHelper.transform(DeleteChangeCommand, { changeId }));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
public static async getTaskTypes(): Promise<string> {
|
|
317
|
+
const taskTypes = await this.findTaskTypes();
|
|
318
|
+
|
|
319
|
+
if (taskTypes.length === 0) {
|
|
320
|
+
return 'No task types in the active project.';
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
return taskTypes
|
|
324
|
+
.map((taskType) => {
|
|
325
|
+
const line = `- ${taskType.name}`;
|
|
326
|
+
if (!taskType.template?.trim()) return line;
|
|
327
|
+
|
|
328
|
+
return `${line}\n Template: available — run \`we-scrum get-task-type-template --name "${taskType.name}"\` to read it.`;
|
|
329
|
+
})
|
|
330
|
+
.join('\n');
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
public static async getTaskTypeTemplate(name: string): Promise<string> {
|
|
334
|
+
const taskType = this.requireTaskType(await this.findTaskTypes(), name);
|
|
335
|
+
|
|
336
|
+
return taskType.template?.trim() ? taskType.template : `Task type "${name}" has no template.`;
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
public static async getAnalysisGuidelinesIndex(): Promise<string> {
|
|
340
|
+
const [policies, taskTypes] = await Promise.all([this.getDevelopmentPolicies(), this.findTaskTypes()]);
|
|
341
|
+
const entries = _sortBy(
|
|
342
|
+
policies.filter((policy) => !!policy.analysisGuidelines && !!policy.slug),
|
|
343
|
+
(policy) => ChangeType.helper.members.indexOf(policy.changeType),
|
|
344
|
+
(policy) => policy.position,
|
|
345
|
+
).map(
|
|
346
|
+
(policy) =>
|
|
347
|
+
`- ${policy.changeType} — ${this.describeMatchingRules(policy, taskTypes)}: \`${this.getDevelopmentPolicyPaths(policy).analysisPath}\``,
|
|
348
|
+
);
|
|
349
|
+
|
|
350
|
+
return entries.length > 0 ? entries.join('\n') : 'No analysis guidelines in the active project.';
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
public static async getMatchingAnalysisGuidelines(
|
|
354
|
+
changeType: ChangeType,
|
|
355
|
+
options: { taskType?: string; objectName?: string; routeMethod?: RouteMethod; relationObjects?: string[] },
|
|
356
|
+
): Promise<string> {
|
|
357
|
+
// The matching rules reference the task types by id
|
|
358
|
+
const taskTypeId = options.taskType ? this.requireTaskType(await this.findTaskTypes(), options.taskType).taskTypeId : undefined;
|
|
359
|
+
const [firstObjectName, secondObjectName, thirdObjectName] = options.relationObjects ?? [];
|
|
360
|
+
|
|
361
|
+
const policy = DevelopmentPolicyHelper.getMatchingAnalysisPolicyByCriteria(
|
|
362
|
+
changeType,
|
|
363
|
+
{
|
|
364
|
+
[DevelopmentPolicyMatchingRuleCriteria.TaskType]: taskTypeId,
|
|
365
|
+
[DevelopmentPolicyMatchingRuleCriteria.ObjectName]: options.objectName,
|
|
366
|
+
[DevelopmentPolicyMatchingRuleCriteria.RouteMethod]: options.routeMethod,
|
|
367
|
+
[DevelopmentPolicyMatchingRuleCriteria.FirstRelationObjectName]: firstObjectName,
|
|
368
|
+
[DevelopmentPolicyMatchingRuleCriteria.SecondRelationObjectName]: secondObjectName,
|
|
369
|
+
[DevelopmentPolicyMatchingRuleCriteria.ThirdRelationObjectName]: thirdObjectName,
|
|
370
|
+
},
|
|
371
|
+
await this.getDevelopmentPolicies(),
|
|
372
|
+
);
|
|
373
|
+
const path = policy ? this.getDevelopmentPolicyPaths(policy).analysisPath : null;
|
|
374
|
+
|
|
375
|
+
return path ?? 'No analysis guidelines match this change.';
|
|
376
|
+
}
|
|
377
|
+
|
|
250
378
|
public static async getChangeThreads(changeId: string): Promise<string> {
|
|
251
379
|
const threads = await FirebaseHelper.getCollection<ProjectChangeThreadModel>(`/projects/${this.projectId}/change-threads`, {
|
|
252
380
|
where: [['changeId', '==', changeId]],
|
|
@@ -286,6 +414,26 @@ export class WeScrumHelper {
|
|
|
286
414
|
);
|
|
287
415
|
}
|
|
288
416
|
|
|
417
|
+
private static assertSingleChangeDsl(dsl: string): void {
|
|
418
|
+
const diagnostics = AnalysisDsl.validate(dsl).map((diagnostic) => ({
|
|
419
|
+
severity: diagnostic.severity,
|
|
420
|
+
message: AnalysisDsl.formatDiagnostic(dsl, diagnostic),
|
|
421
|
+
}));
|
|
422
|
+
|
|
423
|
+
// stderr: stdout is the command result
|
|
424
|
+
diagnostics.filter((d) => d.severity === 'warning').forEach((d) => Logger.warn(d.message));
|
|
425
|
+
|
|
426
|
+
const errors = diagnostics.filter((d) => d.severity === 'error').map((d) => d.message);
|
|
427
|
+
assert(errors.length === 0, `Invalid analysis DSL:\n${errors.join('\n')}`);
|
|
428
|
+
|
|
429
|
+
const { sections } = AnalysisDsl.parse(dsl);
|
|
430
|
+
const changeCount = sections.flatMap((section) => section.changes).length;
|
|
431
|
+
assert(
|
|
432
|
+
sections.length === 1 && changeCount === 1,
|
|
433
|
+
`Exactly one change in one section is expected (found ${changeCount} change(s) in ${sections.length} section(s)).`,
|
|
434
|
+
);
|
|
435
|
+
}
|
|
436
|
+
|
|
289
437
|
private static formatChangeThread(thread: ProjectChangeThreadModel): string {
|
|
290
438
|
const comments = thread.comments
|
|
291
439
|
.map((comment) => {
|
|
@@ -326,15 +474,27 @@ export class WeScrumHelper {
|
|
|
326
474
|
if (!synthesis) return;
|
|
327
475
|
|
|
328
476
|
const changeId = this.getChangeIdentifier(change);
|
|
329
|
-
|
|
330
|
-
change.description = change.description ? `${change.description}\n\n${hint}` : hint;
|
|
477
|
+
this.appendHint(change, ChangeHintHelper.formatThreads(synthesis, changeId));
|
|
331
478
|
}
|
|
332
479
|
|
|
333
|
-
|
|
334
|
-
|
|
480
|
+
/** A hint is only added for the guidelines having a body, as only those are synchronized to a file. */
|
|
481
|
+
private static appendGuidelinesHints(change: DevelopmentPolicyHelper.Change, policies: DevelopmentPolicyModel[]): void {
|
|
482
|
+
const policy = DevelopmentPolicyHelper.getMatchingDevelopmentPolicy(change, policies);
|
|
335
483
|
if (!policy) return;
|
|
336
484
|
|
|
337
|
-
const
|
|
485
|
+
const { analysisPath, guidelinesPath, unitTestsPath } = this.getDevelopmentPolicyPaths(policy);
|
|
486
|
+
const hints: { kind: GuidelinesKind; path: string; isAvailable: boolean }[] = [
|
|
487
|
+
{ kind: 'analysis', path: analysisPath, isAvailable: !!policy.analysisGuidelines },
|
|
488
|
+
{ kind: 'development', path: guidelinesPath, isAvailable: !!policy.codeGuidelines },
|
|
489
|
+
{ kind: 'tests', path: unitTestsPath, isAvailable: policy.areUnitTestsMandatory && !!policy.unitTestsGuidelines },
|
|
490
|
+
];
|
|
491
|
+
|
|
492
|
+
hints
|
|
493
|
+
.filter(({ path, isAvailable }) => !!path && isAvailable)
|
|
494
|
+
.forEach(({ kind, path }) => this.appendHint(change, ChangeHintHelper.formatGuidelines(kind, path)));
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
private static appendHint(change: DevelopmentPolicyHelper.Change, hint: string): void {
|
|
338
498
|
change.description = change.description ? `${change.description}\n\n${hint}` : hint;
|
|
339
499
|
}
|
|
340
500
|
|
|
@@ -344,6 +504,41 @@ export class WeScrumHelper {
|
|
|
344
504
|
]);
|
|
345
505
|
}
|
|
346
506
|
|
|
507
|
+
/** The task types of the active project, sorted by name. */
|
|
508
|
+
private static async findTaskTypes(): Promise<ProjectTaskTypeModel[]> {
|
|
509
|
+
const taskTypes = await FirebaseHelper.getCollection<ProjectTaskTypeModel>(`/projects/${this.projectId}/task-types`);
|
|
510
|
+
|
|
511
|
+
return _sortBy(taskTypes, (taskType) => taskType.name);
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
private static requireTaskType(taskTypes: ProjectTaskTypeModel[], name: string): ProjectTaskTypeModel {
|
|
515
|
+
const taskType = taskTypes.find((t) => t.name === name);
|
|
516
|
+
|
|
517
|
+
assert(
|
|
518
|
+
!!taskType,
|
|
519
|
+
`Task type "${name}" not found in the active project. Available task types: ${taskTypes.map((t) => `"${t.name}"`).join(', ')}.`,
|
|
520
|
+
);
|
|
521
|
+
|
|
522
|
+
return taskType;
|
|
523
|
+
}
|
|
524
|
+
|
|
525
|
+
private static describeMatchingRules(policy: DevelopmentPolicyModel, taskTypes: ProjectTaskTypeModel[]): string {
|
|
526
|
+
if (policy.changeType === ChangeType.Global) return 'applies to the whole analysis';
|
|
527
|
+
if (policy.matchingRules.length === 0) return 'any change of this type';
|
|
528
|
+
|
|
529
|
+
return policy.matchingRules
|
|
530
|
+
.map((rule) => {
|
|
531
|
+
const words = `${MATCHING_RULE_CRITERIA_WORDS[rule.criteria]} ${rule.operator.replace(/-/g, ' ')}`;
|
|
532
|
+
if (!Operator.helper.hasValue(rule.operator)) return words;
|
|
533
|
+
|
|
534
|
+
const isTaskType = rule.criteria === DevelopmentPolicyMatchingRuleCriteria.TaskType;
|
|
535
|
+
const value = isTaskType ? (taskTypes.find((t) => t.taskTypeId === rule.value)?.name ?? rule.value) : rule.value;
|
|
536
|
+
|
|
537
|
+
return `${words} "${value}"`;
|
|
538
|
+
})
|
|
539
|
+
.join(' and ');
|
|
540
|
+
}
|
|
541
|
+
|
|
347
542
|
private static async getStorySections(storyId: string) {
|
|
348
543
|
return FirebaseHelper.getCollection<ProjectStorySectionModel>(`projects/${this.projectId}/stories/${storyId}/sections`);
|
|
349
544
|
}
|
|
@@ -393,7 +588,8 @@ export class WeScrumHelper {
|
|
|
393
588
|
signal: AbortSignal.timeout(60 * 1000),
|
|
394
589
|
});
|
|
395
590
|
|
|
396
|
-
const body = (await response.json()) as { result: R };
|
|
591
|
+
const body = (await response.json().catch(() => ({}))) as { result: R; message?: string };
|
|
592
|
+
assert(response.ok, body.message ?? `Request failed with status ${response.status}`);
|
|
397
593
|
return body.result;
|
|
398
594
|
}
|
|
399
595
|
}
|
package/src/utils/index.ts
CHANGED
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { assert } from '@my-devkit/core';
|
|
2
|
+
import { text } from 'node:stream/consumers';
|
|
3
|
+
|
|
4
|
+
/** Returns the content given as option, or else the one piped to stdin. */
|
|
5
|
+
export async function readContent(content?: string): Promise<string> {
|
|
6
|
+
if (content !== undefined) return content;
|
|
7
|
+
|
|
8
|
+
assert(!process.stdin.isTTY, 'No content provided. Use --content or pipe it to stdin.');
|
|
9
|
+
|
|
10
|
+
return text(process.stdin);
|
|
11
|
+
}
|