@we-scrum/cli 6.11.5 → 6.11.21
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 +293 -80
- package/package.json +4 -3
- 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 +207 -10
- package/src/utils/index.ts +1 -0
- package/src/utils/read-content.ts +11 -0
- package/templates/analyse-story-skill.hbs +203 -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.21",
|
|
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": {
|
|
@@ -38,9 +39,9 @@
|
|
|
38
39
|
"tsup": "^8.5.1",
|
|
39
40
|
"typescript": "^6.0.3",
|
|
40
41
|
"@my-devkit/cli": "2.1.0",
|
|
41
|
-
"@we-scrum/commands": "1.0.0",
|
|
42
42
|
"@my-devkit/core": "1.0.0",
|
|
43
43
|
"@we-scrum/enums": "1.0.0",
|
|
44
|
+
"@we-scrum/commands": "1.0.0",
|
|
44
45
|
"@we-scrum/models": "1.0.0",
|
|
45
46
|
"@we-scrum/utils": "1.0.0"
|
|
46
47
|
},
|
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) {}
|
|
@@ -195,6 +224,7 @@ export class WeScrumHelper {
|
|
|
195
224
|
endDate: options.endDate ?? iteration.endDate,
|
|
196
225
|
capacity: options.capacity ?? iteration.capacity,
|
|
197
226
|
comment: options.comment ?? iteration.comment,
|
|
227
|
+
iterationType: iteration.iterationType,
|
|
198
228
|
}),
|
|
199
229
|
);
|
|
200
230
|
}
|
|
@@ -239,7 +269,7 @@ export class WeScrumHelper {
|
|
|
239
269
|
const policies = await this.getDevelopmentPolicies();
|
|
240
270
|
this.getAllChanges(sections).forEach((change) => {
|
|
241
271
|
this.appendThreadsHint(change);
|
|
242
|
-
this.
|
|
272
|
+
this.appendGuidelinesHints(change, policies);
|
|
243
273
|
});
|
|
244
274
|
|
|
245
275
|
const ast = StorySectionHelper.mapSectionsToAnalysisAst(sections);
|
|
@@ -247,6 +277,105 @@ export class WeScrumHelper {
|
|
|
247
277
|
return AttachmentHelper.localize(AnalysisDsl.stringify(ast));
|
|
248
278
|
}
|
|
249
279
|
|
|
280
|
+
/** Creates or updates the single change described by the given DSL, and returns its id. */
|
|
281
|
+
public static async updateStoryAnalysis(identificationNumber: string, content: string): Promise<string> {
|
|
282
|
+
const dsl = content.replace(/\r\n/g, '\n');
|
|
283
|
+
this.assertSingleChangeDsl(dsl);
|
|
284
|
+
|
|
285
|
+
const story = await this.findStoryByIterationNumber(identificationNumber);
|
|
286
|
+
assert(!!story, `Story "${identificationNumber}" not found in the active project.`);
|
|
287
|
+
|
|
288
|
+
return this.post(
|
|
289
|
+
'project-management/bulk-update-story-analysis',
|
|
290
|
+
TypeHelper.transform(BulkUpdateStoryAnalysisCommand, {
|
|
291
|
+
storyId: story.storyId,
|
|
292
|
+
content: ChangeHintHelper.removeFromDsl(dsl),
|
|
293
|
+
}),
|
|
294
|
+
);
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
public static async reorganizeStoryAnalysis(identificationNumber: string, content: string): Promise<void> {
|
|
298
|
+
const { deletedChangeIds } = StoryAnalysisReorganizationHelper.parse(content);
|
|
299
|
+
assert(
|
|
300
|
+
deletedChangeIds.length === 0,
|
|
301
|
+
'"> delete:" lines are not supported: delete the changes one by one with "we-scrum delete-change --changeId <changeId>".',
|
|
302
|
+
);
|
|
303
|
+
|
|
304
|
+
const story = await this.findStoryByIterationNumber(identificationNumber);
|
|
305
|
+
assert(!!story, `Story "${identificationNumber}" not found in the active project.`);
|
|
306
|
+
|
|
307
|
+
await this.post(
|
|
308
|
+
'project-management/bulk-reorganize-story-analysis',
|
|
309
|
+
TypeHelper.transform(BulkReorganizeStoryAnalysisCommand, { storyId: story.storyId, content }),
|
|
310
|
+
);
|
|
311
|
+
}
|
|
312
|
+
|
|
313
|
+
public static async deleteChange(changeId: string): Promise<void> {
|
|
314
|
+
await this.post('project-management/delete-change', TypeHelper.transform(DeleteChangeCommand, { changeId }));
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
public static async getTaskTypes(): Promise<string> {
|
|
318
|
+
const taskTypes = await this.findTaskTypes();
|
|
319
|
+
|
|
320
|
+
if (taskTypes.length === 0) {
|
|
321
|
+
return 'No task types in the active project.';
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return taskTypes
|
|
325
|
+
.map((taskType) => {
|
|
326
|
+
const line = `- ${taskType.name}`;
|
|
327
|
+
if (!taskType.template?.trim()) return line;
|
|
328
|
+
|
|
329
|
+
return `${line}\n Template: available — run \`we-scrum get-task-type-template --name "${taskType.name}"\` to read it.`;
|
|
330
|
+
})
|
|
331
|
+
.join('\n');
|
|
332
|
+
}
|
|
333
|
+
|
|
334
|
+
public static async getTaskTypeTemplate(name: string): Promise<string> {
|
|
335
|
+
const taskType = this.requireTaskType(await this.findTaskTypes(), name);
|
|
336
|
+
|
|
337
|
+
return taskType.template?.trim() ? taskType.template : `Task type "${name}" has no template.`;
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
public static async getAnalysisGuidelinesIndex(): Promise<string> {
|
|
341
|
+
const [policies, taskTypes] = await Promise.all([this.getDevelopmentPolicies(), this.findTaskTypes()]);
|
|
342
|
+
const entries = _sortBy(
|
|
343
|
+
policies.filter((policy) => !!policy.analysisGuidelines && !!policy.slug),
|
|
344
|
+
(policy) => ChangeType.helper.members.indexOf(policy.changeType),
|
|
345
|
+
(policy) => policy.position,
|
|
346
|
+
).map(
|
|
347
|
+
(policy) =>
|
|
348
|
+
`- ${policy.changeType} — ${this.describeMatchingRules(policy, taskTypes)}: \`${this.getDevelopmentPolicyPaths(policy).analysisPath}\``,
|
|
349
|
+
);
|
|
350
|
+
|
|
351
|
+
return entries.length > 0 ? entries.join('\n') : 'No analysis guidelines in the active project.';
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
public static async getMatchingAnalysisGuidelines(
|
|
355
|
+
changeType: ChangeType,
|
|
356
|
+
options: { taskType?: string; objectName?: string; routeMethod?: RouteMethod; relationObjects?: string[] },
|
|
357
|
+
): Promise<string> {
|
|
358
|
+
// The matching rules reference the task types by id
|
|
359
|
+
const taskTypeId = options.taskType ? this.requireTaskType(await this.findTaskTypes(), options.taskType).taskTypeId : undefined;
|
|
360
|
+
const [firstObjectName, secondObjectName, thirdObjectName] = options.relationObjects ?? [];
|
|
361
|
+
|
|
362
|
+
const policy = DevelopmentPolicyHelper.getMatchingAnalysisPolicyByCriteria(
|
|
363
|
+
changeType,
|
|
364
|
+
{
|
|
365
|
+
[DevelopmentPolicyMatchingRuleCriteria.TaskType]: taskTypeId,
|
|
366
|
+
[DevelopmentPolicyMatchingRuleCriteria.ObjectName]: options.objectName,
|
|
367
|
+
[DevelopmentPolicyMatchingRuleCriteria.RouteMethod]: options.routeMethod,
|
|
368
|
+
[DevelopmentPolicyMatchingRuleCriteria.FirstRelationObjectName]: firstObjectName,
|
|
369
|
+
[DevelopmentPolicyMatchingRuleCriteria.SecondRelationObjectName]: secondObjectName,
|
|
370
|
+
[DevelopmentPolicyMatchingRuleCriteria.ThirdRelationObjectName]: thirdObjectName,
|
|
371
|
+
},
|
|
372
|
+
await this.getDevelopmentPolicies(),
|
|
373
|
+
);
|
|
374
|
+
const path = policy ? this.getDevelopmentPolicyPaths(policy).analysisPath : null;
|
|
375
|
+
|
|
376
|
+
return path ?? 'No analysis guidelines match this change.';
|
|
377
|
+
}
|
|
378
|
+
|
|
250
379
|
public static async getChangeThreads(changeId: string): Promise<string> {
|
|
251
380
|
const threads = await FirebaseHelper.getCollection<ProjectChangeThreadModel>(`/projects/${this.projectId}/change-threads`, {
|
|
252
381
|
where: [['changeId', '==', changeId]],
|
|
@@ -286,6 +415,26 @@ export class WeScrumHelper {
|
|
|
286
415
|
);
|
|
287
416
|
}
|
|
288
417
|
|
|
418
|
+
private static assertSingleChangeDsl(dsl: string): void {
|
|
419
|
+
const diagnostics = AnalysisDsl.validate(dsl).map((diagnostic) => ({
|
|
420
|
+
severity: diagnostic.severity,
|
|
421
|
+
message: AnalysisDsl.formatDiagnostic(dsl, diagnostic),
|
|
422
|
+
}));
|
|
423
|
+
|
|
424
|
+
// stderr: stdout is the command result
|
|
425
|
+
diagnostics.filter((d) => d.severity === 'warning').forEach((d) => Logger.warn(d.message));
|
|
426
|
+
|
|
427
|
+
const errors = diagnostics.filter((d) => d.severity === 'error').map((d) => d.message);
|
|
428
|
+
assert(errors.length === 0, `Invalid analysis DSL:\n${errors.join('\n')}`);
|
|
429
|
+
|
|
430
|
+
const { sections } = AnalysisDsl.parse(dsl);
|
|
431
|
+
const changeCount = sections.flatMap((section) => section.changes).length;
|
|
432
|
+
assert(
|
|
433
|
+
sections.length === 1 && changeCount === 1,
|
|
434
|
+
`Exactly one change in one section is expected (found ${changeCount} change(s) in ${sections.length} section(s)).`,
|
|
435
|
+
);
|
|
436
|
+
}
|
|
437
|
+
|
|
289
438
|
private static formatChangeThread(thread: ProjectChangeThreadModel): string {
|
|
290
439
|
const comments = thread.comments
|
|
291
440
|
.map((comment) => {
|
|
@@ -326,15 +475,27 @@ export class WeScrumHelper {
|
|
|
326
475
|
if (!synthesis) return;
|
|
327
476
|
|
|
328
477
|
const changeId = this.getChangeIdentifier(change);
|
|
329
|
-
|
|
330
|
-
change.description = change.description ? `${change.description}\n\n${hint}` : hint;
|
|
478
|
+
this.appendHint(change, ChangeHintHelper.formatThreads(synthesis, changeId));
|
|
331
479
|
}
|
|
332
480
|
|
|
333
|
-
|
|
334
|
-
|
|
481
|
+
/** A hint is only added for the guidelines having a body, as only those are synchronized to a file. */
|
|
482
|
+
private static appendGuidelinesHints(change: DevelopmentPolicyHelper.Change, policies: DevelopmentPolicyModel[]): void {
|
|
483
|
+
const policy = DevelopmentPolicyHelper.getMatchingDevelopmentPolicy(change, policies);
|
|
335
484
|
if (!policy) return;
|
|
336
485
|
|
|
337
|
-
const
|
|
486
|
+
const { analysisPath, guidelinesPath, unitTestsPath } = this.getDevelopmentPolicyPaths(policy);
|
|
487
|
+
const hints: { kind: GuidelinesKind; path: string; isAvailable: boolean }[] = [
|
|
488
|
+
{ kind: 'analysis', path: analysisPath, isAvailable: !!policy.analysisGuidelines },
|
|
489
|
+
{ kind: 'development', path: guidelinesPath, isAvailable: !!policy.codeGuidelines },
|
|
490
|
+
{ kind: 'tests', path: unitTestsPath, isAvailable: policy.areUnitTestsMandatory && !!policy.unitTestsGuidelines },
|
|
491
|
+
];
|
|
492
|
+
|
|
493
|
+
hints
|
|
494
|
+
.filter(({ path, isAvailable }) => !!path && isAvailable)
|
|
495
|
+
.forEach(({ kind, path }) => this.appendHint(change, ChangeHintHelper.formatGuidelines(kind, path)));
|
|
496
|
+
}
|
|
497
|
+
|
|
498
|
+
private static appendHint(change: DevelopmentPolicyHelper.Change, hint: string): void {
|
|
338
499
|
change.description = change.description ? `${change.description}\n\n${hint}` : hint;
|
|
339
500
|
}
|
|
340
501
|
|
|
@@ -344,6 +505,41 @@ export class WeScrumHelper {
|
|
|
344
505
|
]);
|
|
345
506
|
}
|
|
346
507
|
|
|
508
|
+
/** The task types of the active project, sorted by name. */
|
|
509
|
+
private static async findTaskTypes(): Promise<ProjectTaskTypeModel[]> {
|
|
510
|
+
const taskTypes = await FirebaseHelper.getCollection<ProjectTaskTypeModel>(`/projects/${this.projectId}/task-types`);
|
|
511
|
+
|
|
512
|
+
return _sortBy(taskTypes, (taskType) => taskType.name);
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
private static requireTaskType(taskTypes: ProjectTaskTypeModel[], name: string): ProjectTaskTypeModel {
|
|
516
|
+
const taskType = taskTypes.find((t) => t.name === name);
|
|
517
|
+
|
|
518
|
+
assert(
|
|
519
|
+
!!taskType,
|
|
520
|
+
`Task type "${name}" not found in the active project. Available task types: ${taskTypes.map((t) => `"${t.name}"`).join(', ')}.`,
|
|
521
|
+
);
|
|
522
|
+
|
|
523
|
+
return taskType;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
private static describeMatchingRules(policy: DevelopmentPolicyModel, taskTypes: ProjectTaskTypeModel[]): string {
|
|
527
|
+
if (policy.changeType === ChangeType.Global) return 'applies to the whole analysis';
|
|
528
|
+
if (policy.matchingRules.length === 0) return 'any change of this type';
|
|
529
|
+
|
|
530
|
+
return policy.matchingRules
|
|
531
|
+
.map((rule) => {
|
|
532
|
+
const words = `${MATCHING_RULE_CRITERIA_WORDS[rule.criteria]} ${rule.operator.replace(/-/g, ' ')}`;
|
|
533
|
+
if (!Operator.helper.hasValue(rule.operator)) return words;
|
|
534
|
+
|
|
535
|
+
const isTaskType = rule.criteria === DevelopmentPolicyMatchingRuleCriteria.TaskType;
|
|
536
|
+
const value = isTaskType ? (taskTypes.find((t) => t.taskTypeId === rule.value)?.name ?? rule.value) : rule.value;
|
|
537
|
+
|
|
538
|
+
return `${words} "${value}"`;
|
|
539
|
+
})
|
|
540
|
+
.join(' and ');
|
|
541
|
+
}
|
|
542
|
+
|
|
347
543
|
private static async getStorySections(storyId: string) {
|
|
348
544
|
return FirebaseHelper.getCollection<ProjectStorySectionModel>(`projects/${this.projectId}/stories/${storyId}/sections`);
|
|
349
545
|
}
|
|
@@ -393,7 +589,8 @@ export class WeScrumHelper {
|
|
|
393
589
|
signal: AbortSignal.timeout(60 * 1000),
|
|
394
590
|
});
|
|
395
591
|
|
|
396
|
-
const body = (await response.json()) as { result: R };
|
|
592
|
+
const body = (await response.json().catch(() => ({}))) as { result: R; message?: string };
|
|
593
|
+
assert(response.ok, body.message ?? `Request failed with status ${response.status}`);
|
|
397
594
|
return body.result;
|
|
398
595
|
}
|
|
399
596
|
}
|
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
|
+
}
|