@pecot/workflow-mcp 0.0.0-stage → 5.0.0
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/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +12 -0
- package/cli/dist/commands/github-client.js +23 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +55 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +19 -0
- package/cli/dist/domain/errors.js +31 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-readout.d.ts +107 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +134 -0
- package/cli/dist/domain/pull-request.js +232 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +66 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +49 -0
- package/cli/dist/infra/config-store.js +121 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +74 -0
- package/cli/dist/infra/git.js +133 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +173 -0
- package/cli/dist/infra/github/client.js +576 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +47 -0
- package/cli/dist/infra/github/errors.js +42 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +129 -0
- package/cli/dist/infra/github/issues.js +273 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +45 -0
- package/cli/dist/infra/state-store.js +118 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +139 -0
- package/cli/dist/infra/worktree-links.js +433 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +128 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +181 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +67 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
// Issue の本文の `## Waits for merge` の節の読み書き(contracts/prerequisite-table.md の 3)。純関数だけを置く。
|
|
2
|
+
import { InvalidValueError } from './errors.js';
|
|
3
|
+
import { createIssueReference, issueReferenceKey, issueReferenceToString } from './reference-parser.js';
|
|
4
|
+
import { ValidationFailure } from './python-format.js';
|
|
5
|
+
import { createRepositoryReference, isSameRepository } from './repository-resolver.js';
|
|
6
|
+
export const WAITS_FOR_MERGE_HEADING = '## Waits for merge';
|
|
7
|
+
const LINE_PATTERN = /([^\n]*)(\n|$)/gu;
|
|
8
|
+
const SAME_REPOSITORY_REFERENCE = /^#(\d+)$/u;
|
|
9
|
+
const QUALIFIED_REFERENCE = /^([\w.-]+)\/([\w.-]+)#(\d+)$/u;
|
|
10
|
+
function splitLines(body) {
|
|
11
|
+
const lines = [];
|
|
12
|
+
for (const match of body.matchAll(LINE_PATTERN)) {
|
|
13
|
+
const [whole, content = '', newline = ''] = match;
|
|
14
|
+
if (whole === '')
|
|
15
|
+
break;
|
|
16
|
+
const hasCarriageReturn = newline !== '' && content.endsWith('\r');
|
|
17
|
+
lines.push({
|
|
18
|
+
text: hasCarriageReturn ? content.slice(0, -1) : content,
|
|
19
|
+
eol: hasCarriageReturn ? '\r\n' : newline,
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
return lines;
|
|
23
|
+
}
|
|
24
|
+
function joinLines(lines) {
|
|
25
|
+
return lines.map(line => line.text + line.eol).join('');
|
|
26
|
+
}
|
|
27
|
+
function lineEnding(body) {
|
|
28
|
+
return body.includes('\r\n') ? '\r\n' : '\n';
|
|
29
|
+
}
|
|
30
|
+
function locateSections(lines) {
|
|
31
|
+
const sections = [];
|
|
32
|
+
for (const [index, line] of lines.entries()) {
|
|
33
|
+
if (line.text !== WAITS_FOR_MERGE_HEADING)
|
|
34
|
+
continue;
|
|
35
|
+
const next = lines.findIndex((candidate, position) => position > index && candidate.text.startsWith('## '));
|
|
36
|
+
sections.push({ start: index, end: next === -1 ? lines.length : next });
|
|
37
|
+
}
|
|
38
|
+
return sections;
|
|
39
|
+
}
|
|
40
|
+
function formatReference(repository, reference) {
|
|
41
|
+
return isSameRepository(repository, reference.repository) ? `#${String(reference.number)}` : issueReferenceToString(reference);
|
|
42
|
+
}
|
|
43
|
+
function createReference(repository, digits) {
|
|
44
|
+
const number = Number(digits);
|
|
45
|
+
if (!Number.isSafeInteger(number))
|
|
46
|
+
return undefined;
|
|
47
|
+
try {
|
|
48
|
+
return createIssueReference(repository(), number);
|
|
49
|
+
}
|
|
50
|
+
catch (error) {
|
|
51
|
+
if (error instanceof ValidationFailure)
|
|
52
|
+
return undefined;
|
|
53
|
+
throw error;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function parseReference(raw, repository) {
|
|
57
|
+
const sameRepositoryNumber = SAME_REPOSITORY_REFERENCE.exec(raw)?.[1];
|
|
58
|
+
if (sameRepositoryNumber !== undefined)
|
|
59
|
+
return createReference(() => repository, sameRepositoryNumber);
|
|
60
|
+
const [, owner, name, qualifiedNumber] = QUALIFIED_REFERENCE.exec(raw) ?? [];
|
|
61
|
+
return owner === undefined || name === undefined || qualifiedNumber === undefined
|
|
62
|
+
? undefined
|
|
63
|
+
: createReference(() => createRepositoryReference(owner, name), qualifiedNumber);
|
|
64
|
+
}
|
|
65
|
+
function parseLine(text, repository) {
|
|
66
|
+
if (text.trim() === '')
|
|
67
|
+
return { kind: 'blank' };
|
|
68
|
+
if (!text.startsWith('- '))
|
|
69
|
+
return { kind: 'invalid', reason: `not a list item: ${text}` };
|
|
70
|
+
const rest = text.slice(2);
|
|
71
|
+
const separator = rest.indexOf(': ');
|
|
72
|
+
if (separator === -1)
|
|
73
|
+
return { kind: 'invalid', reason: `no ': ' separator: ${text}` };
|
|
74
|
+
const reference = parseReference(rest.slice(0, separator), repository);
|
|
75
|
+
if (reference === undefined)
|
|
76
|
+
return { kind: 'invalid', reason: `invalid issue reference: ${text}` };
|
|
77
|
+
const reason = rest.slice(separator + 2).trim();
|
|
78
|
+
return reason === '' ? { kind: 'invalid', reason: `empty reason: ${text}` } : { kind: 'entry', entry: { ref: reference, reason } };
|
|
79
|
+
}
|
|
80
|
+
function readSection(lines, section, repository) {
|
|
81
|
+
const entries = [];
|
|
82
|
+
const seen = new Set();
|
|
83
|
+
const sectionLines = lines.slice(section.start + 1, section.end);
|
|
84
|
+
for (const line of sectionLines) {
|
|
85
|
+
const parsed = parseLine(line.text, repository);
|
|
86
|
+
if (parsed.kind === 'blank')
|
|
87
|
+
continue;
|
|
88
|
+
if (parsed.kind === 'invalid')
|
|
89
|
+
return { kind: 'malformed', reason: parsed.reason };
|
|
90
|
+
const key = issueReferenceKey(parsed.entry.ref);
|
|
91
|
+
if (seen.has(key))
|
|
92
|
+
return { kind: 'malformed', reason: `duplicate reference: ${key}` };
|
|
93
|
+
seen.add(key);
|
|
94
|
+
entries.push(parsed.entry);
|
|
95
|
+
}
|
|
96
|
+
return { kind: 'ok', lines: entries };
|
|
97
|
+
}
|
|
98
|
+
function readBody(lines, repository) {
|
|
99
|
+
const sections = locateSections(lines);
|
|
100
|
+
const [section] = sections;
|
|
101
|
+
if (section === undefined)
|
|
102
|
+
return { readout: { kind: 'absent' }, section: undefined };
|
|
103
|
+
if (sections.length > 1)
|
|
104
|
+
return { readout: { kind: 'malformed', reason: `${WAITS_FOR_MERGE_HEADING} appears ${String(sections.length)} times` }, section };
|
|
105
|
+
return { readout: readSection(lines, section, repository), section };
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
本文から `## Waits for merge` の節を読む。repository は `#N` の参照が指すリポ(本文のある Issue のリポ)
|
|
109
|
+
*/
|
|
110
|
+
export function readWaitsForMerge(body, repository) {
|
|
111
|
+
return readBody(splitLines(body), repository).readout;
|
|
112
|
+
}
|
|
113
|
+
function requireWritable(body, repository) {
|
|
114
|
+
const lines = splitLines(body);
|
|
115
|
+
const { readout, section } = readBody(lines, repository);
|
|
116
|
+
if (readout.kind === 'malformed')
|
|
117
|
+
throw new InvalidValueError(`${WAITS_FOR_MERGE_HEADING} section is malformed: ${readout.reason}`);
|
|
118
|
+
return { lines, section, entries: readout.kind === 'ok' ? readout.lines : [] };
|
|
119
|
+
}
|
|
120
|
+
function sectionIndexes(section) {
|
|
121
|
+
return Array.from({ length: section.end - section.start - 1 }, (_, offset) => section.start + 1 + offset);
|
|
122
|
+
}
|
|
123
|
+
function entryIndex(lines, section, repository, reference) {
|
|
124
|
+
const key = issueReferenceKey(reference);
|
|
125
|
+
return sectionIndexes(section).find((index) => {
|
|
126
|
+
const parsed = parseLine(lines.at(index)?.text ?? '', repository);
|
|
127
|
+
return parsed.kind === 'entry' && issueReferenceKey(parsed.entry.ref) === key;
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
// 足す位置の行(無ければその手前の行)の改行に合わせる。末尾に改行の無い本文は、足した行も改行なしで終える
|
|
131
|
+
function insertAfter(lines, index, text, fallbackEol) {
|
|
132
|
+
const previous = lines.at(index);
|
|
133
|
+
const isAtEnd = previous?.eol === '';
|
|
134
|
+
const eol = lines.slice(0, index + 1).findLast(line => line.eol !== '')?.eol ?? fallbackEol;
|
|
135
|
+
const kept = lines.with(index, { text: previous?.text ?? '', eol });
|
|
136
|
+
return kept.toSpliced(index + 1, 0, { text, eol: isAtEnd ? '' : eol });
|
|
137
|
+
}
|
|
138
|
+
// 末尾の改行が無い本文へ足した節は、改行なしで終える。removeWaitsForMerge で外すと元の本文と同じになる
|
|
139
|
+
function appendSection(lines, text, eol) {
|
|
140
|
+
const last = lines.at(-1);
|
|
141
|
+
const isUnterminated = last?.eol === '';
|
|
142
|
+
const terminated = isUnterminated ? lines.with(lines.length - 1, { text: last.text, eol }) : lines;
|
|
143
|
+
const separator = terminated.length === 0 || terminated.at(-1)?.text === '' ? [] : [{ text: '', eol }];
|
|
144
|
+
return [...terminated, ...separator, { text: WAITS_FOR_MERGE_HEADING, eol }, { text: '', eol }, { text, eol: isUnterminated ? '' : eol }];
|
|
145
|
+
}
|
|
146
|
+
/**
|
|
147
|
+
前提の行を足す。同じ参照の行があれば理由を書き換える。節の外は変えない。節が読めないときは InvalidValueError
|
|
148
|
+
*/
|
|
149
|
+
export function upsertWaitsForMerge(body, repository, reference, reason) {
|
|
150
|
+
const trimmed = reason.trim();
|
|
151
|
+
if (trimmed === '' || /[\r\n]/u.test(trimmed))
|
|
152
|
+
throw new InvalidValueError('reason must be a single non-empty line');
|
|
153
|
+
const text = `- ${formatReference(repository, reference)}: ${trimmed}`;
|
|
154
|
+
const eol = lineEnding(body);
|
|
155
|
+
const { lines, section } = requireWritable(body, repository);
|
|
156
|
+
if (section === undefined)
|
|
157
|
+
return joinLines(appendSection(lines, text, eol));
|
|
158
|
+
const existing = entryIndex(lines, section, repository, reference);
|
|
159
|
+
if (existing !== undefined)
|
|
160
|
+
return joinLines(lines.with(existing, { text, eol: lines.at(existing)?.eol ?? eol }));
|
|
161
|
+
const contentIndexes = sectionIndexes(section).filter(index => lines.at(index)?.text.trim() !== '');
|
|
162
|
+
return joinLines(insertAfter(lines, contentIndexes.at(-1) ?? section.start, text, eol));
|
|
163
|
+
}
|
|
164
|
+
// 最後の行を消すときは、前の行の改行も落として末尾の形を保つ
|
|
165
|
+
function removeEntryLine(lines, index) {
|
|
166
|
+
const isLast = lines.at(index)?.eol === '';
|
|
167
|
+
const previous = lines.at(index - 1);
|
|
168
|
+
const kept = isLast && previous !== undefined ? lines.with(index - 1, { text: previous.text, eol: '' }) : lines;
|
|
169
|
+
return kept.toSpliced(index, 1);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
前提の行を外す。参照が無ければ本文をそのまま返す。行が無くなれば節ごと消す。節が読めないときは InvalidValueError
|
|
173
|
+
*/
|
|
174
|
+
export function removeWaitsForMerge(body, repository, reference) {
|
|
175
|
+
const { lines, section, entries } = requireWritable(body, repository);
|
|
176
|
+
if (section === undefined)
|
|
177
|
+
return body;
|
|
178
|
+
const index = entryIndex(lines, section, repository, reference);
|
|
179
|
+
if (index === undefined)
|
|
180
|
+
return body;
|
|
181
|
+
if (entries.length > 1)
|
|
182
|
+
return joinLines(removeEntryLine(lines, index));
|
|
183
|
+
// 節が本文の末尾なら、手前の空行(節との区切り)も一緒に消し、節が改行なしで終わっていれば手前の行も改行なしにする
|
|
184
|
+
const lastContent = lines.slice(0, section.start).findLastIndex(line => line.text.trim() !== '');
|
|
185
|
+
if (section.end !== lines.length)
|
|
186
|
+
return joinLines(lines.toSpliced(section.start, section.end - section.start));
|
|
187
|
+
const before = lines.slice(0, lastContent + 1);
|
|
188
|
+
const previous = before.at(-1);
|
|
189
|
+
const isUnterminated = lines.at(-1)?.eol === '';
|
|
190
|
+
return joinLines(previous !== undefined && isUnterminated ? [...before.slice(0, -1), { text: previous.text, eol: '' }] : before);
|
|
191
|
+
}
|
|
192
|
+
//# sourceMappingURL=prerequisites.js.map
|
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import type { SectionHeading } from './sections.js';
|
|
2
|
+
export declare const SCREENSHOT_MISSING_ERROR: string;
|
|
3
|
+
/**
|
|
4
|
+
本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
|
|
5
|
+
*/
|
|
6
|
+
export declare function extractClosingIssueNumbers(body: string): readonly number[];
|
|
7
|
+
/**
|
|
8
|
+
本文にその Issue 番号の参照が無ければ、末尾に `Closes #N` を足す。あればそのまま返す
|
|
9
|
+
*/
|
|
10
|
+
export declare function appendIssueCloseIfNeeded(body: string, issueNumber: number): string;
|
|
11
|
+
/**
|
|
12
|
+
本文に Issue 参照(`#N` か `owner/repo#N`)があるか
|
|
13
|
+
*/
|
|
14
|
+
export declare function hasIssueReference(body: string): boolean;
|
|
15
|
+
/**
|
|
16
|
+
リリース PR か。release テンプレート、または develop から release への PR
|
|
17
|
+
*/
|
|
18
|
+
export declare function isReleasePullRequest(template: string, base: string, head: string | undefined, developBranch: string | undefined, releaseBranch: string | undefined): boolean;
|
|
19
|
+
export interface PullRequestContentOptions {
|
|
20
|
+
readonly body: string;
|
|
21
|
+
readonly base: string;
|
|
22
|
+
readonly developBranch: string | undefined;
|
|
23
|
+
readonly releaseBranch: string | undefined;
|
|
24
|
+
readonly head: string | undefined;
|
|
25
|
+
readonly template: string;
|
|
26
|
+
readonly skipIssueReferenceCheck: boolean;
|
|
27
|
+
/**
|
|
28
|
+
Summary に画像が無い理由。正規化済みで、無ければ undefined
|
|
29
|
+
*/
|
|
30
|
+
readonly screenshot: string | undefined;
|
|
31
|
+
/**
|
|
32
|
+
テンプレートから取り出した必須の節。空なら節の検証をしない
|
|
33
|
+
*/
|
|
34
|
+
readonly requiredSections: readonly SectionHeading[];
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
PR の内容を検証し、エラーの文を返す(無ければ空)。ブランチ設定の欠けは、呼び出し側が先に止める
|
|
38
|
+
*/
|
|
39
|
+
export declare function validatePullRequestContent(options: Readonly<PullRequestContentOptions>): readonly string[];
|
|
40
|
+
export interface IssueSummary {
|
|
41
|
+
readonly number: number;
|
|
42
|
+
readonly title: string;
|
|
43
|
+
}
|
|
44
|
+
export interface PullRequestView {
|
|
45
|
+
readonly number: number;
|
|
46
|
+
readonly state: string;
|
|
47
|
+
readonly title: string;
|
|
48
|
+
readonly body: string;
|
|
49
|
+
readonly head_ref: string;
|
|
50
|
+
readonly base_ref: string;
|
|
51
|
+
readonly is_draft: boolean;
|
|
52
|
+
readonly mergeable: string;
|
|
53
|
+
readonly comments: number;
|
|
54
|
+
readonly closing_issues: readonly IssueSummary[];
|
|
55
|
+
readonly referenced_issues: readonly IssueSummary[];
|
|
56
|
+
}
|
|
57
|
+
export interface PullRequestSlimView extends PullRequestView {
|
|
58
|
+
readonly reviews: readonly {
|
|
59
|
+
readonly state: string;
|
|
60
|
+
readonly author: string | null;
|
|
61
|
+
}[];
|
|
62
|
+
}
|
|
63
|
+
export interface ReviewView {
|
|
64
|
+
readonly state: string;
|
|
65
|
+
readonly author: string | null;
|
|
66
|
+
readonly body: string;
|
|
67
|
+
readonly submitted_at: string | null;
|
|
68
|
+
}
|
|
69
|
+
export interface ReviewThreadView {
|
|
70
|
+
readonly is_resolved: boolean;
|
|
71
|
+
readonly path: string | null;
|
|
72
|
+
readonly line: number | null;
|
|
73
|
+
readonly comments: readonly {
|
|
74
|
+
readonly author: string | null;
|
|
75
|
+
readonly body: string;
|
|
76
|
+
readonly created_at: string | null;
|
|
77
|
+
}[];
|
|
78
|
+
}
|
|
79
|
+
export interface PullRequestWithReviewsView extends PullRequestView {
|
|
80
|
+
readonly reviews: readonly ReviewView[];
|
|
81
|
+
readonly review_threads: readonly ReviewThreadView[];
|
|
82
|
+
}
|
|
83
|
+
/**
|
|
84
|
+
`pr read` の既定の Markdown
|
|
85
|
+
*/
|
|
86
|
+
export declare function formatPullRequestMarkdown(pr: PullRequestSlimView): string;
|
|
87
|
+
/**
|
|
88
|
+
レビュー本文の節。レビューが無ければ空文字
|
|
89
|
+
*/
|
|
90
|
+
export declare function formatReviewsMarkdown(reviews: readonly ReviewView[]): string;
|
|
91
|
+
/**
|
|
92
|
+
行コメント(reviewThreads)の節。無ければ空文字
|
|
93
|
+
*/
|
|
94
|
+
export declare function formatReviewThreadsMarkdown(threads: readonly ReviewThreadView[]): string;
|
|
95
|
+
/**
|
|
96
|
+
`pr read --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
|
|
97
|
+
*/
|
|
98
|
+
export declare function formatPullRequestWithReviewsMarkdown(pr: PullRequestWithReviewsView, owner: string, repository: string): string;
|
|
99
|
+
export interface PreflightWarning {
|
|
100
|
+
readonly label: string;
|
|
101
|
+
readonly message: string;
|
|
102
|
+
readonly fixHint: string;
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
`git status` の出力に変更があるか。空・取得失敗の印・「nothing to commit」かつ「working tree clean」は無し
|
|
106
|
+
*/
|
|
107
|
+
export declare function hasStatusChanges(gitStatus: string): boolean;
|
|
108
|
+
/**
|
|
109
|
+
stash の一覧の文字列に、stash の項目があるか(「(no stash)」と取得失敗の印は無し)
|
|
110
|
+
*/
|
|
111
|
+
export declare function hasStashEntries(stashList: string): boolean;
|
|
112
|
+
export interface PushStatus {
|
|
113
|
+
readonly isPushed: boolean;
|
|
114
|
+
readonly message: string;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
ahead と behind のコミット数から、push の状態の文を作る
|
|
118
|
+
*/
|
|
119
|
+
export declare function describePushStatus(remote: string, branch: string, ahead: number, behind: number): PushStatus;
|
|
120
|
+
export interface PreflightFacts {
|
|
121
|
+
readonly gitStatus: string;
|
|
122
|
+
readonly stashList: string;
|
|
123
|
+
readonly isPushed: boolean;
|
|
124
|
+
readonly pushMessage: string;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
警告を、未 push・変更あり・stash ありの順で返す
|
|
128
|
+
*/
|
|
129
|
+
export declare function collectPreflightWarnings(facts: Readonly<PreflightFacts>): readonly PreflightWarning[];
|
|
130
|
+
/**
|
|
131
|
+
警告 1 行の文
|
|
132
|
+
*/
|
|
133
|
+
export declare function formatPreflightWarning(warning: PreflightWarning): string;
|
|
134
|
+
//# sourceMappingURL=pull-request.d.ts.map
|
|
@@ -0,0 +1,232 @@
|
|
|
1
|
+
// PR コマンドの入出力を持たない関数。本文の検証、Closes の抽出と追記、`pr read` の Markdown の整形、preflight の警告の判定。
|
|
2
|
+
// 引数の型は、infra/github/pulls.ts の返す値が構造として満たす形をここに持つ(domain は infra を import できない)。
|
|
3
|
+
import { parsePythonInteger, pythonRightStrip, pythonStrip, splitCodePoints, truncateCodePoints } from './python-format.js';
|
|
4
|
+
import { hasSummaryImage, validateBodyStyle, validateHeadingSummaries, validateSections } from './sections.js';
|
|
5
|
+
// Issue 参照(`#N`、URL 内のフラグメントは除く)。`owner/repo#N` の形も受ける
|
|
6
|
+
const ISSUE_REFERENCE_PATTERN = /(?:^|[^/])#\d+|[\w-]+\/[\w.-]+#\d+/u;
|
|
7
|
+
// Python の `\s`(str.isspace)と同じ空白
|
|
8
|
+
const PYTHON_SPACE = String.raw `[\t\n\v\f\r\u{1C}-\u{20}\u{85}\u{A0}\u{1680}\u{2000}-\u{200A}\u{2028}\u{2029}\u{202F}\u{205F}\u{3000}]`;
|
|
9
|
+
// GitHub が認識する close・fix・resolve と、それぞれの -s / -es / -d 付きの形。`owner/repo#N` の形も受ける
|
|
10
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- 固定の文字列から組み立てる
|
|
11
|
+
const CLOSING_KEYWORDS_PATTERN = new RegExp(String.raw `(?:close[sd]?|fix(?:e[sd])?|resolve[sd]?)${PYTHON_SPACE}+(?:[\w-]+/[\w.-]+)?#(\p{Nd}+)`, 'giu');
|
|
12
|
+
// stash の件数を数える行の区切り。str.splitlines と同じ。
|
|
13
|
+
// eslint-disable-next-line no-control-regex, security/detect-unsafe-regex -- 区切りの制御文字と誤検知
|
|
14
|
+
const LINE_BREAK = /\r\n|[\n\r\v\f\u{1C}-\u{1E}\u{85}\u{2028}\u{2029}]/u;
|
|
15
|
+
export const SCREENSHOT_MISSING_ERROR = 'Summary has no image and `screenshot` gives no reason to omit one. '
|
|
16
|
+
+ 'If the change alters a screen, Markdown the tool writes for GitHub, or CLI output text, '
|
|
17
|
+
+ 'take a screenshot and add it to Summary as ``. '
|
|
18
|
+
+ 'Otherwise, write the reason in the `screenshot` frontmatter field (`--screenshot` with `-m`)';
|
|
19
|
+
/**
|
|
20
|
+
本文の Closes / Fixes / Resolves に続く Issue 番号を、出てきた順に重複なしで返す
|
|
21
|
+
*/
|
|
22
|
+
export function extractClosingIssueNumbers(body) {
|
|
23
|
+
const numbers = [];
|
|
24
|
+
body.replaceAll(CLOSING_KEYWORDS_PATTERN, (matched, digits) => {
|
|
25
|
+
numbers.push(Number(parsePythonInteger(digits)));
|
|
26
|
+
return matched;
|
|
27
|
+
});
|
|
28
|
+
return [...new Set(numbers)];
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
本文にその Issue 番号の参照が無ければ、末尾に `Closes #N` を足す。あればそのまま返す
|
|
32
|
+
*/
|
|
33
|
+
export function appendIssueCloseIfNeeded(body, issueNumber) {
|
|
34
|
+
// URL 内のフラグメントは (^|[^/]) で除く。直後に数字が続くものは否定の先読みで除く
|
|
35
|
+
// eslint-disable-next-line security/detect-non-literal-regexp -- Issue 番号は整数
|
|
36
|
+
const pattern = new RegExp(String.raw `(^|[^/])#${String(issueNumber)}(?!\p{Nd})`, 'u');
|
|
37
|
+
return pattern.test(body) ? body : `${pythonRightStrip(body)}\n\nCloses #${String(issueNumber)}`;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
本文に Issue 参照(`#N` か `owner/repo#N`)があるか
|
|
41
|
+
*/
|
|
42
|
+
export function hasIssueReference(body) {
|
|
43
|
+
return ISSUE_REFERENCE_PATTERN.test(body);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
リリース PR か。release テンプレート、または develop から release への PR
|
|
47
|
+
*/
|
|
48
|
+
export function isReleasePullRequest(template, base, head, developBranch, releaseBranch) {
|
|
49
|
+
return template === 'release' || (releaseBranch !== undefined && releaseBranch !== '' && base === releaseBranch && head === developBranch);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
PR の内容を検証し、エラーの文を返す(無ければ空)。ブランチ設定の欠けは、呼び出し側が先に止める
|
|
53
|
+
*/
|
|
54
|
+
export function validatePullRequestContent(options) {
|
|
55
|
+
const { body, base, developBranch, releaseBranch, requiredSections } = options;
|
|
56
|
+
const errors = [];
|
|
57
|
+
const isRelease = isReleasePullRequest(options.template, base, options.head, developBranch, releaseBranch);
|
|
58
|
+
if (!isRelease && !options.skipIssueReferenceCheck && !hasIssueReference(body)) {
|
|
59
|
+
errors.push('PR body has no Issue reference `#N` (use `--no-issue-ref` for a PR not tied to an Issue)');
|
|
60
|
+
}
|
|
61
|
+
if (requiredSections.length > 0) {
|
|
62
|
+
const missing = validateSections(body, requiredSections);
|
|
63
|
+
if (missing.length > 0)
|
|
64
|
+
errors.push(`missing sections: ${missing.join(', ')}`);
|
|
65
|
+
const summaryErrors = validateHeadingSummaries(body, requiredSections);
|
|
66
|
+
if (summaryErrors.length > 0)
|
|
67
|
+
errors.push(`heading summary rule violations: ${summaryErrors.join(', ')}`);
|
|
68
|
+
}
|
|
69
|
+
const styleErrors = validateBodyStyle(body);
|
|
70
|
+
if (styleErrors.length > 0)
|
|
71
|
+
errors.push(`disallowed syntax: ${styleErrors.join(', ')}`);
|
|
72
|
+
if (!isRelease && (options.screenshot === undefined || options.screenshot === '') && !hasSummaryImage(body)) {
|
|
73
|
+
errors.push(SCREENSHOT_MISSING_ERROR);
|
|
74
|
+
}
|
|
75
|
+
if (isRelease) {
|
|
76
|
+
if (releaseBranch !== undefined && releaseBranch !== '' && base !== releaseBranch)
|
|
77
|
+
errors.push(`release PR base branch must be ${releaseBranch} (given: ${base})`);
|
|
78
|
+
}
|
|
79
|
+
else if (developBranch !== undefined && developBranch !== '' && base !== developBranch) {
|
|
80
|
+
errors.push(`base branch must be ${developBranch} (given: ${base})`);
|
|
81
|
+
}
|
|
82
|
+
return errors;
|
|
83
|
+
}
|
|
84
|
+
// ISO 8601 の先頭 10 文字(YYYY-MM-DD)。10 文字に満たなければ空
|
|
85
|
+
function datePart(timestamp) {
|
|
86
|
+
return timestamp !== null && splitCodePoints(timestamp).length >= 10 ? truncateCodePoints(timestamp, 10) : '';
|
|
87
|
+
}
|
|
88
|
+
function metaLine(pr) {
|
|
89
|
+
const parts = [`**State:** ${pr.state}`];
|
|
90
|
+
if (pr.is_draft)
|
|
91
|
+
parts.push('**Draft**');
|
|
92
|
+
if (pr.mergeable !== '')
|
|
93
|
+
parts.push(`**Mergeable:** ${pr.mergeable}`);
|
|
94
|
+
if (pr.comments > 0)
|
|
95
|
+
parts.push(`**Comments:** ${String(pr.comments)}`);
|
|
96
|
+
return parts.join(' | ');
|
|
97
|
+
}
|
|
98
|
+
function referencedIssueLine(issue) {
|
|
99
|
+
return ` - #${String(issue.number)}${issue.title === '' ? '' : ` ${issue.title}`}`;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
`pr read` の既定の Markdown
|
|
103
|
+
*/
|
|
104
|
+
export function formatPullRequestMarkdown(pr) {
|
|
105
|
+
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
106
|
+
if (pr.closing_issues.length > 0) {
|
|
107
|
+
lines.push('**Closing Issues:**', ...pr.closing_issues.map(issue => ` - #${String(issue.number)} ${issue.title}`), '');
|
|
108
|
+
}
|
|
109
|
+
if (pr.referenced_issues.length > 0) {
|
|
110
|
+
lines.push('**Referenced Issues:**', ...pr.referenced_issues.map(issue => referencedIssueLine(issue)), '');
|
|
111
|
+
}
|
|
112
|
+
if (pr.reviews.length > 0) {
|
|
113
|
+
lines.push('**Reviews:**', ...pr.reviews.map(review => ` - ${review.author ?? 'None'}: ${review.state}`), '');
|
|
114
|
+
}
|
|
115
|
+
lines.push('---', '', pr.body);
|
|
116
|
+
return lines.join('\n');
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
レビュー本文の節。レビューが無ければ空文字
|
|
120
|
+
*/
|
|
121
|
+
export function formatReviewsMarkdown(reviews) {
|
|
122
|
+
if (reviews.length === 0)
|
|
123
|
+
return '';
|
|
124
|
+
const lines = ['## Reviews', ''];
|
|
125
|
+
for (const review of reviews) {
|
|
126
|
+
const author = review.author === null || review.author === '' ? '(unknown)' : review.author;
|
|
127
|
+
const date = datePart(review.submitted_at);
|
|
128
|
+
lines.push(`### @${author} (${review.state})${date === '' ? '' : ` - ${date}`}`);
|
|
129
|
+
const body = pythonStrip(review.body);
|
|
130
|
+
if (body !== '')
|
|
131
|
+
lines.push('', body);
|
|
132
|
+
lines.push('');
|
|
133
|
+
}
|
|
134
|
+
return lines.join('\n');
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
行コメント(reviewThreads)の節。無ければ空文字
|
|
138
|
+
*/
|
|
139
|
+
export function formatReviewThreadsMarkdown(threads) {
|
|
140
|
+
if (threads.length === 0)
|
|
141
|
+
return '';
|
|
142
|
+
const lines = ['## Line Comments', ''];
|
|
143
|
+
for (const thread of threads) {
|
|
144
|
+
const path = thread.path === null || thread.path === '' ? '(unknown file)' : thread.path;
|
|
145
|
+
const lineInfo = thread.line === null || thread.line === 0 ? '' : `:${String(thread.line)}`;
|
|
146
|
+
lines.push(`### \`${path}${lineInfo}\` [${thread.is_resolved ? 'Resolved' : 'Open'}]`, '');
|
|
147
|
+
for (const comment of thread.comments) {
|
|
148
|
+
const author = comment.author === null || comment.author === '' ? '(unknown)' : comment.author;
|
|
149
|
+
const date = datePart(comment.created_at);
|
|
150
|
+
lines.push(`**@${author}**${date === '' ? '' : ` (${date})`}:`);
|
|
151
|
+
const body = pythonStrip(comment.body);
|
|
152
|
+
if (body !== '')
|
|
153
|
+
lines.push(...body.split('\n').map(line => `> ${line}`));
|
|
154
|
+
lines.push('');
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
return lines.join('\n');
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
`pr read --reviews` の Markdown。Issue ごとに詳細を見るコマンドを添え、レビュー本文と行コメントを続ける
|
|
161
|
+
*/
|
|
162
|
+
export function formatPullRequestWithReviewsMarkdown(pr, owner, repository) {
|
|
163
|
+
const lines = [`## PR #${String(pr.number)} ${pr.title}`, '', metaLine(pr), '', `**Branch:** \`${pr.head_ref}\` → \`${pr.base_ref}\``, ''];
|
|
164
|
+
const detailsLine = (issue) => ` → details: pecot issue read ${owner}/${repository}/${String(issue.number)}`;
|
|
165
|
+
if (pr.closing_issues.length > 0) {
|
|
166
|
+
lines.push('**Closing Issues:**');
|
|
167
|
+
for (const issue of pr.closing_issues)
|
|
168
|
+
lines.push(` - #${String(issue.number)} ${issue.title}`, detailsLine(issue));
|
|
169
|
+
lines.push('');
|
|
170
|
+
}
|
|
171
|
+
if (pr.referenced_issues.length > 0) {
|
|
172
|
+
lines.push('**Referenced Issues:**');
|
|
173
|
+
for (const issue of pr.referenced_issues)
|
|
174
|
+
lines.push(referencedIssueLine(issue), detailsLine(issue));
|
|
175
|
+
lines.push('');
|
|
176
|
+
}
|
|
177
|
+
lines.push('---', '', pr.body, '');
|
|
178
|
+
const reviews = formatReviewsMarkdown(pr.reviews);
|
|
179
|
+
if (reviews !== '')
|
|
180
|
+
lines.push('---', '', reviews);
|
|
181
|
+
const threads = formatReviewThreadsMarkdown(pr.review_threads);
|
|
182
|
+
if (threads !== '')
|
|
183
|
+
lines.push('---', '', threads);
|
|
184
|
+
return lines.join('\n');
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
`git status` の出力に変更があるか。空・取得失敗の印・「nothing to commit」かつ「working tree clean」は無し
|
|
188
|
+
*/
|
|
189
|
+
export function hasStatusChanges(gitStatus) {
|
|
190
|
+
const stripped = pythonStrip(gitStatus);
|
|
191
|
+
return stripped !== '' && stripped !== '(git status failed)' && !(gitStatus.includes('nothing to commit') && gitStatus.includes('working tree clean'));
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
stash の一覧の文字列に、stash の項目があるか(「(no stash)」と取得失敗の印は無し)
|
|
195
|
+
*/
|
|
196
|
+
export function hasStashEntries(stashList) {
|
|
197
|
+
return stashList !== '(no stash)' && !stashList.startsWith('(git stash');
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
ahead と behind のコミット数から、push の状態の文を作る
|
|
201
|
+
*/
|
|
202
|
+
export function describePushStatus(remote, branch, ahead, behind) {
|
|
203
|
+
if (ahead === 0 && behind === 0)
|
|
204
|
+
return { isPushed: true, message: `in sync with ${remote}/${branch}` };
|
|
205
|
+
if (behind === 0)
|
|
206
|
+
return { isPushed: false, message: `${String(ahead)} unpushed commits` };
|
|
207
|
+
if (ahead === 0)
|
|
208
|
+
return { isPushed: true, message: `${remote}/${branch} is ${String(behind)} commits ahead (pull recommended)` };
|
|
209
|
+
return { isPushed: false, message: `diverged: local is ${String(ahead)} commits ahead, ${remote}/${branch} is ${String(behind)} ahead` };
|
|
210
|
+
}
|
|
211
|
+
/**
|
|
212
|
+
警告を、未 push・変更あり・stash ありの順で返す
|
|
213
|
+
*/
|
|
214
|
+
export function collectPreflightWarnings(facts) {
|
|
215
|
+
const warnings = [];
|
|
216
|
+
if (!facts.isPushed)
|
|
217
|
+
warnings.push({ label: 'Push Status', message: facts.pushMessage, fixHint: 'git push' });
|
|
218
|
+
if (hasStatusChanges(facts.gitStatus))
|
|
219
|
+
warnings.push({ label: 'Git Status', message: 'modified or untracked files', fixHint: 'commit' });
|
|
220
|
+
if (hasStashEntries(facts.stashList)) {
|
|
221
|
+
const count = facts.stashList.split(LINE_BREAK).filter(line => pythonStrip(line) !== '').length;
|
|
222
|
+
warnings.push({ label: 'Stash List', message: `${String(count)} stash entries`, fixHint: 'check them' });
|
|
223
|
+
}
|
|
224
|
+
return warnings;
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
警告 1 行の文
|
|
228
|
+
*/
|
|
229
|
+
export function formatPreflightWarning(warning) {
|
|
230
|
+
return `${warning.label}: ${warning.message} (fix: ${warning.fixHint})`;
|
|
231
|
+
}
|
|
232
|
+
//# sourceMappingURL=pull-request.js.map
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import { InvalidValueError } from './errors.js';
|
|
2
|
+
export type JsonValue = string | number | boolean | null | readonly JsonValue[] | {
|
|
3
|
+
readonly [key: string]: JsonValue;
|
|
4
|
+
};
|
|
5
|
+
/**
|
|
6
|
+
universal newlines と同じ。`\r\n` と `\r` を `\n` に揃える(Python の text=True・read_text())
|
|
7
|
+
*/
|
|
8
|
+
export declare function normalizeNewlines(text: string): string;
|
|
9
|
+
/**
|
|
10
|
+
sorted() の str の並べ方に使う比較。UTF-16 の単位順で比べる(BMP 内では Python のコードポイント順と同じ)
|
|
11
|
+
*/
|
|
12
|
+
export declare function compareStrings(a: string, b: string): number;
|
|
13
|
+
/**
|
|
14
|
+
str.rstrip() と同じ
|
|
15
|
+
*/
|
|
16
|
+
export declare function pythonRightStrip(text: string): string;
|
|
17
|
+
/**
|
|
18
|
+
文字列をコードポイントに分ける。Python の len・スライスと同じ単位(UTF-16 の単位ではない)
|
|
19
|
+
*/
|
|
20
|
+
export declare function splitCodePoints(text: string): readonly string[];
|
|
21
|
+
/**
|
|
22
|
+
text[:limit] と同じ。コードポイント単位で切る
|
|
23
|
+
*/
|
|
24
|
+
export declare function truncateCodePoints(text: string, limit: number): string;
|
|
25
|
+
/**
|
|
26
|
+
str.strip() と同じ
|
|
27
|
+
*/
|
|
28
|
+
export declare function pythonStrip(text: string): string;
|
|
29
|
+
/**
|
|
30
|
+
repr(str) と同じ。引用符は、' を含み " を含まないときだけ "
|
|
31
|
+
*/
|
|
32
|
+
export declare function pythonStringRepr(text: string): string;
|
|
33
|
+
/**
|
|
34
|
+
repr(float) と同じ。指数表記になるのは、10 進の小数点位置が 16 を超える・-3 未満のとき
|
|
35
|
+
*/
|
|
36
|
+
export declare function pythonFloatRepr(value: number): string;
|
|
37
|
+
export declare function isJsonArray(value: JsonValue | undefined): value is readonly JsonValue[];
|
|
38
|
+
/**
|
|
39
|
+
JSON 値の repr。整数値の数は int、それ以外は float の書式にする
|
|
40
|
+
*/
|
|
41
|
+
export declare function pythonRepr(value: JsonValue): string;
|
|
42
|
+
/**
|
|
43
|
+
type(value).__name__ に当たる名前
|
|
44
|
+
*/
|
|
45
|
+
export declare function pythonTypeName(value: JsonValue | undefined): string;
|
|
46
|
+
/**
|
|
47
|
+
int(text) と同じ。前後の空白・符号・数字の間の `_`・Unicode の 10 進数字を受ける。
|
|
48
|
+
不正なら Python と同じ文の InvalidValueError ではなく undefined を返す(呼び出し側が文言を作る)
|
|
49
|
+
*/
|
|
50
|
+
export declare function parsePythonInteger(text: string): number | undefined;
|
|
51
|
+
export interface HttpStatusFailure {
|
|
52
|
+
readonly statusCode: number;
|
|
53
|
+
/**
|
|
54
|
+
応答の statusText。空ならそのまま空で出す(HTTP/1.1 の空の reason を空のまま出す Python の挙動)
|
|
55
|
+
*/
|
|
56
|
+
readonly statusText: string;
|
|
57
|
+
readonly url: string;
|
|
58
|
+
/**
|
|
59
|
+
Location ヘッダ。リダイレクトの状態(301・302・303・307・308)で、あるときだけ出る
|
|
60
|
+
*/
|
|
61
|
+
readonly location: string | undefined;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
2xx 以外の応答に対する、HTTP クライアントの raise_for_status の文
|
|
65
|
+
*/
|
|
66
|
+
export declare function formatHttpStatusError(failure: HttpStatusFailure): string;
|
|
67
|
+
export interface SystemFailure {
|
|
68
|
+
readonly code?: string | undefined;
|
|
69
|
+
readonly path?: string | undefined;
|
|
70
|
+
readonly dest?: string | undefined;
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
OSError の文(`[Errno 2] No such file or directory: 'x'`)。errno の code が表に無いときは undefined
|
|
74
|
+
*/
|
|
75
|
+
export declare function formatOsError(failure: SystemFailure): string | undefined;
|
|
76
|
+
export interface ValidationIssue {
|
|
77
|
+
/**
|
|
78
|
+
エラーの種類(`missing`・`string_type`・`value_error` など)
|
|
79
|
+
*/
|
|
80
|
+
readonly type: string;
|
|
81
|
+
readonly location: readonly (string | number)[];
|
|
82
|
+
/**
|
|
83
|
+
`Field required` のような本文
|
|
84
|
+
*/
|
|
85
|
+
readonly message: string;
|
|
86
|
+
/**
|
|
87
|
+
エラーになった値。無いこと(undefined)も区別して持つ
|
|
88
|
+
*/
|
|
89
|
+
readonly input: JsonValue | undefined;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
ValidationError の文。表題(モデル名)の後に、エラーごとに 3 行(場所・本文・案内 URL)が続く。
|
|
93
|
+
入力値の repr は、UTF-8 のバイト長が 50 を超えると省略する。
|
|
94
|
+
前 25 バイトと後ろ 24 バイトに収まる文字だけを残し、間を `...` でつなぐ
|
|
95
|
+
*/
|
|
96
|
+
export declare function formatValidationError(title: string, issues: readonly ValidationIssue[]): string;
|
|
97
|
+
/**
|
|
98
|
+
ValidationError に当たる例外。メッセージは formatValidationError の文
|
|
99
|
+
*/
|
|
100
|
+
export declare class ValidationFailure extends InvalidValueError {
|
|
101
|
+
readonly title: string;
|
|
102
|
+
readonly issues: readonly ValidationIssue[];
|
|
103
|
+
constructor(title: string, issues: readonly ValidationIssue[]);
|
|
104
|
+
}
|
|
105
|
+
//# sourceMappingURL=python-format.d.ts.map
|