@pecot/workflow-mcp 0.0.0-stage → 6.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 +184 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +227 -0
- package/cli/dist/commands/board-add.d.ts +3 -0
- package/cli/dist/commands/board-add.js +59 -0
- package/cli/dist/commands/board-judgment.d.ts +60 -0
- package/cli/dist/commands/board-judgment.js +144 -0
- package/cli/dist/commands/board-move.d.ts +3 -0
- package/cli/dist/commands/board-move.js +57 -0
- package/cli/dist/commands/board-readiness.d.ts +34 -0
- package/cli/dist/commands/board-readiness.js +108 -0
- package/cli/dist/commands/board-show.d.ts +3 -0
- package/cli/dist/commands/board-show.js +72 -0
- package/cli/dist/commands/board-sync.d.ts +3 -0
- package/cli/dist/commands/board-sync.js +111 -0
- package/cli/dist/commands/board-view.d.ts +62 -0
- package/cli/dist/commands/board-view.js +191 -0
- package/cli/dist/commands/board.d.ts +3 -0
- package/cli/dist/commands/board.js +12 -0
- package/cli/dist/commands/branch.d.ts +3 -0
- package/cli/dist/commands/branch.js +100 -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 +270 -0
- package/cli/dist/commands/command-definition.d.ts +150 -0
- package/cli/dist/commands/command-definition.js +105 -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-hint.d.ts +5 -0
- package/cli/dist/commands/command-hint.js +13 -0
- package/cli/dist/commands/command-stop.d.ts +21 -0
- package/cli/dist/commands/command-stop.js +31 -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-kind.d.ts +3 -0
- package/cli/dist/commands/failure-kind.js +34 -0
- package/cli/dist/commands/failure.d.ts +19 -0
- package/cli/dist/commands/failure.js +59 -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 +16 -0
- package/cli/dist/commands/github-client.js +33 -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 +50 -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 +71 -0
- package/cli/dist/commands/issue-board.js +122 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +215 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +786 -0
- package/cli/dist/commands/issue-dependency.d.ts +3 -0
- package/cli/dist/commands/issue-dependency.js +282 -0
- package/cli/dist/commands/issue-readiness.d.ts +94 -0
- package/cli/dist/commands/issue-readiness.js +218 -0
- package/cli/dist/commands/issue-reopen.d.ts +3 -0
- package/cli/dist/commands/issue-reopen.js +115 -0
- package/cli/dist/commands/issue-shared.d.ts +172 -0
- package/cli/dist/commands/issue-shared.js +426 -0
- package/cli/dist/commands/issue-show.d.ts +3 -0
- package/cli/dist/commands/issue-show.js +169 -0
- package/cli/dist/commands/issue.d.ts +3 -0
- package/cli/dist/commands/issue.js +13 -0
- package/cli/dist/commands/names.d.ts +42 -0
- package/cli/dist/commands/names.js +78 -0
- package/cli/dist/commands/output.d.ts +90 -0
- package/cli/dist/commands/output.js +194 -0
- package/cli/dist/commands/pr-waiting.d.ts +20 -0
- package/cli/dist/commands/pr-waiting.js +106 -0
- package/cli/dist/commands/pr.d.ts +22 -0
- package/cli/dist/commands/pr.js +852 -0
- package/cli/dist/commands/project-sync.d.ts +92 -0
- package/cli/dist/commands/project-sync.js +282 -0
- package/cli/dist/commands/project.d.ts +6 -0
- package/cli/dist/commands/project.js +714 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +30 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +353 -0
- package/cli/dist/commands/renamed-commands.d.ts +26 -0
- package/cli/dist/commands/renamed-commands.js +53 -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 +34 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/session-finish.d.ts +3 -0
- package/cli/dist/commands/session-finish.js +267 -0
- package/cli/dist/commands/session-start.d.ts +3 -0
- package/cli/dist/commands/session-start.js +236 -0
- package/cli/dist/commands/session.d.ts +6 -0
- package/cli/dist/commands/session.js +214 -0
- package/cli/dist/commands/tracker-sync-dependabot.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-dependabot.js +156 -0
- package/cli/dist/commands/tracker-sync-security.d.ts +7 -0
- package/cli/dist/commands/tracker-sync-security.js +153 -0
- package/cli/dist/commands/tracker-sync.d.ts +65 -0
- package/cli/dist/commands/tracker-sync.js +50 -0
- package/cli/dist/commands/tracker.d.ts +3 -0
- package/cli/dist/commands/tracker.js +18 -0
- package/cli/dist/commands/usage-error.d.ts +51 -0
- package/cli/dist/commands/usage-error.js +78 -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 +22 -0
- package/cli/dist/commands/work-target.js +82 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +339 -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/batch-plan.d.ts +73 -0
- package/cli/dist/domain/batch-plan.js +114 -0
- package/cli/dist/domain/blocked-by-change.d.ts +99 -0
- package/cli/dist/domain/blocked-by-change.js +101 -0
- package/cli/dist/domain/board-move.d.ts +90 -0
- package/cli/dist/domain/board-move.js +92 -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/command-hint.d.ts +85 -0
- package/cli/dist/domain/command-hint.js +148 -0
- package/cli/dist/domain/config.d.ts +219 -0
- package/cli/dist/domain/config.js +310 -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 +24 -0
- package/cli/dist/domain/errors.js +36 -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 +94 -0
- package/cli/dist/domain/format.js +234 -0
- package/cli/dist/domain/frontmatter.d.ts +137 -0
- package/cli/dist/domain/frontmatter.js +290 -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-order.d.ts +55 -0
- package/cli/dist/domain/issue-order.js +65 -0
- package/cli/dist/domain/issue-readout.d.ts +143 -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 +201 -0
- package/cli/dist/domain/pull-request.js +281 -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 +199 -0
- package/cli/dist/domain/readiness.js +391 -0
- package/cli/dist/domain/reference-parser.d.ts +51 -0
- package/cli/dist/domain/reference-parser.js +123 -0
- package/cli/dist/domain/release.d.ts +53 -0
- package/cli/dist/domain/release.js +65 -0
- package/cli/dist/domain/repository-policy.d.ts +38 -0
- package/cli/dist/domain/repository-policy.js +66 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +122 -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 +59 -0
- package/cli/dist/domain/state.js +95 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/work-start.d.ts +34 -0
- package/cli/dist/domain/work-start.js +49 -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 +72 -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 +53 -0
- package/cli/dist/infra/config-store.js +134 -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 +86 -0
- package/cli/dist/infra/git.js +145 -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 +178 -0
- package/cli/dist/infra/github/client.js +579 -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 +65 -0
- package/cli/dist/infra/github/errors.js +64 -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 +165 -0
- package/cli/dist/infra/github/issues.js +428 -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 +143 -0
- package/cli/dist/infra/github/projects.js +384 -0
- package/cli/dist/infra/github/pulls.d.ts +104 -0
- package/cli/dist/infra/github/pulls.js +217 -0
- package/cli/dist/infra/github/queries.d.ts +44 -0
- package/cli/dist/infra/github/queries.js +1031 -0
- package/cli/dist/infra/github/readout.d.ts +22 -0
- package/cli/dist/infra/github/readout.js +167 -0
- package/cli/dist/infra/github/repos.d.ts +86 -0
- package/cli/dist/infra/github/repos.js +168 -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 +54 -0
- package/cli/dist/infra/state-store.js +130 -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 +142 -0
- package/cli/dist/infra/worktree-links.js +440 -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 +185 -0
- package/cli/dist/infra/worktree.js +584 -0
- package/cli/dist/mcp/result.d.ts +61 -0
- package/cli/dist/mcp/result.js +96 -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 +142 -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 +195 -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 +74 -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/cli/templates/workflow/pecot-board-sync.yml +84 -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,391 @@
|
|
|
1
|
+
// Issue の着手の可否の判定と、フェーズの進め方(specs/024 の data-model.md の 2〜4)。I/O を持たない純関数だけを置く。
|
|
2
|
+
import { isEpicIssue } from './issue-kind.js';
|
|
3
|
+
import { issueReferenceKey } from './reference-parser.js';
|
|
4
|
+
import { isSameRepository, repositoryFullName } from './repository-resolver.js';
|
|
5
|
+
export const PENDING_COLUMN = 'Pending';
|
|
6
|
+
export const NEEDS_ATTENTION_LABEL = 'Needs Attention';
|
|
7
|
+
export const TRACKER_TITLE_PREFIX = '[Tracker]';
|
|
8
|
+
function openPullRequests(issue) {
|
|
9
|
+
return issue.pullRequests.filter(pullRequest => pullRequest.state === 'open');
|
|
10
|
+
}
|
|
11
|
+
export function isDone(issue) {
|
|
12
|
+
return issue.state === 'closed' && issue.pullRequests.some(pullRequest => pullRequest.state === 'merged');
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
open で、open の PR がちょうど 1 本あり、fork からでない。ドラフトも含む
|
|
16
|
+
*/
|
|
17
|
+
export function isInReview(issue) {
|
|
18
|
+
const open = openPullRequests(issue);
|
|
19
|
+
return issue.state === 'open' && open.length === 1 && open[0]?.isCrossRepository === false;
|
|
20
|
+
}
|
|
21
|
+
export function hasStarted(issue) {
|
|
22
|
+
return issue.branches.length > 0 || issue.pullRequests.length > 0;
|
|
23
|
+
}
|
|
24
|
+
function isPending(issue) {
|
|
25
|
+
return issue.column === PENDING_COLUMN;
|
|
26
|
+
}
|
|
27
|
+
// 列が Pending の前提は、人が後回しにしたものなので、PR があっても積む先にしない
|
|
28
|
+
function isStackable(issue) {
|
|
29
|
+
return isInReview(issue) && !isPending(issue);
|
|
30
|
+
}
|
|
31
|
+
function isStackBase(pullRequest) {
|
|
32
|
+
return pullRequest.state === 'open' && !pullRequest.isCrossRepository;
|
|
33
|
+
}
|
|
34
|
+
function notInReviewState(issue) {
|
|
35
|
+
if (isPending(issue))
|
|
36
|
+
return 'pending';
|
|
37
|
+
const open = openPullRequests(issue);
|
|
38
|
+
if (open.length > 1)
|
|
39
|
+
return 'multiple-prs';
|
|
40
|
+
if (open.length === 1)
|
|
41
|
+
return 'fork-pr';
|
|
42
|
+
return hasStarted(issue) ? 'started-without-pr' : 'not-started';
|
|
43
|
+
}
|
|
44
|
+
// 開発ブランチに届かない(途切れる・輪になる)列は undefined
|
|
45
|
+
function headsToDevelopment(start, byHead, developmentBranch) {
|
|
46
|
+
const reached = new Set([start.headRefName]);
|
|
47
|
+
let current = start;
|
|
48
|
+
while (current.baseRefName !== developmentBranch) {
|
|
49
|
+
const next = byHead.get(current.baseRefName);
|
|
50
|
+
if (next === undefined || reached.has(next.headRefName))
|
|
51
|
+
return undefined;
|
|
52
|
+
reached.add(next.headRefName);
|
|
53
|
+
current = next;
|
|
54
|
+
}
|
|
55
|
+
return reached;
|
|
56
|
+
}
|
|
57
|
+
// 済んでいない前提はすべて PR 中なので、open の PR がちょうど 1 本ある
|
|
58
|
+
// 辿る PR も、対象と同じリポのものだけにする
|
|
59
|
+
function findStackTarget(unfinished, input) {
|
|
60
|
+
const targetRepository = input.target.ref.repository;
|
|
61
|
+
const entries = unfinished.flatMap(({ issue }) => {
|
|
62
|
+
const [pullRequest] = openPullRequests(issue);
|
|
63
|
+
return pullRequest === undefined ? [] : { issue: issue.ref, pullRequest };
|
|
64
|
+
});
|
|
65
|
+
const byHead = new Map([...input.pullRequestsByHead].filter(([, pullRequest]) => isStackBase(pullRequest) && isSameRepository(pullRequest.repository, targetRepository)));
|
|
66
|
+
for (const { pullRequest } of entries)
|
|
67
|
+
byHead.set(pullRequest.headRefName, pullRequest);
|
|
68
|
+
for (const start of entries) {
|
|
69
|
+
const reached = headsToDevelopment(start.pullRequest, byHead, input.developmentBranch);
|
|
70
|
+
if (reached !== undefined && entries.every(other => reached.has(other.pullRequest.headRefName))) {
|
|
71
|
+
return { branch: start.pullRequest.headRefName, issue: start.issue };
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
return undefined;
|
|
75
|
+
}
|
|
76
|
+
function result(kind, fields) {
|
|
77
|
+
return { kind, stackOn: fields.stackOn, reason: fields.reason, needsReview: fields.needsReview, attention: fields.attention };
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
data-model.md の 3 の表を上から当てはめる。Epic と Tracker には判定を出さず undefined を返す
|
|
81
|
+
*/
|
|
82
|
+
export function judgeReadiness(input) {
|
|
83
|
+
const { target, prerequisites, cycle } = input;
|
|
84
|
+
if (target.kind !== 'task')
|
|
85
|
+
return undefined;
|
|
86
|
+
if (prerequisites === 'read-failed') {
|
|
87
|
+
return result('blocked', { reason: { code: 'unreadable' }, needsReview: false, attention: [] });
|
|
88
|
+
}
|
|
89
|
+
const unfinished = prerequisites.filter(({ issue }) => !isDone(issue));
|
|
90
|
+
const closedUnmerged = unfinished.filter(({ issue }) => issue.state === 'closed');
|
|
91
|
+
const isNeedsReview = closedUnmerged.length > 0;
|
|
92
|
+
const attention = unfinished.filter(({ issue }) => issue.label === NEEDS_ATTENTION_LABEL).map(({ issue }) => issue.ref);
|
|
93
|
+
const blocked = (reason) => result('blocked', { reason, needsReview: isNeedsReview, attention });
|
|
94
|
+
if (cycle !== undefined)
|
|
95
|
+
return blocked({ code: 'cycle', cycle });
|
|
96
|
+
if (isNeedsReview)
|
|
97
|
+
return blocked({ code: 'closed-unmerged', issues: closedUnmerged.map(({ issue }) => issue.ref) });
|
|
98
|
+
const waitsMerge = unfinished.filter(({ wait }) => wait === 'merge');
|
|
99
|
+
if (waitsMerge.length > 0) {
|
|
100
|
+
return blocked({ code: 'waits-merge', issues: waitsMerge.map(({ issue, reason }) => ({ issue: issue.ref, reason })) });
|
|
101
|
+
}
|
|
102
|
+
if (unfinished.length === 0)
|
|
103
|
+
return result('startable', { needsReview: isNeedsReview, attention });
|
|
104
|
+
// 前提の Issue か、その PR が別のリポにあると、積む先のブランチを対象のリポで引けない
|
|
105
|
+
const otherRepository = unfinished.filter(({ issue }) => !isSameRepository(issue.ref.repository, target.ref.repository)
|
|
106
|
+
|| (isInReview(issue) && openPullRequests(issue).some(pullRequest => !isSameRepository(pullRequest.repository, target.ref.repository))));
|
|
107
|
+
if (otherRepository.length > 0)
|
|
108
|
+
return blocked({ code: 'other-repository', issues: otherRepository.map(({ issue }) => issue.ref) });
|
|
109
|
+
const notInReview = unfinished.filter(({ issue }) => !isStackable(issue));
|
|
110
|
+
if (notInReview.length > 0) {
|
|
111
|
+
return blocked({ code: 'not-in-review', issues: notInReview.map(({ issue }) => ({ issue: issue.ref, state: notInReviewState(issue) })) });
|
|
112
|
+
}
|
|
113
|
+
const stackOn = findStackTarget(unfinished, input);
|
|
114
|
+
return stackOn === undefined
|
|
115
|
+
? blocked({ code: 'diverged', issues: unfinished.map(({ issue }) => issue.ref) })
|
|
116
|
+
: result('stackable', { stackOn, needsReview: isNeedsReview, attention });
|
|
117
|
+
}
|
|
118
|
+
// localeCompare は環境で順が変わるので、コード単位の順にする
|
|
119
|
+
function compareKeys(left, right) {
|
|
120
|
+
if (left < right)
|
|
121
|
+
return -1;
|
|
122
|
+
return left > right ? 1 : 0;
|
|
123
|
+
}
|
|
124
|
+
/**
|
|
125
|
+
キーから前提のキーへの辺の表から、輪を 1 つ返す。始点を末尾にも置き、始点は輪のキーの最小にする。
|
|
126
|
+
キーと辺をソートして探すので、入力の順に依らない。自分自身への辺は長さ 1 の輪になる
|
|
127
|
+
*/
|
|
128
|
+
export function findCycle(edges) {
|
|
129
|
+
const states = new Map();
|
|
130
|
+
const path = [];
|
|
131
|
+
const visit = (key) => {
|
|
132
|
+
states.set(key, 'visiting');
|
|
133
|
+
path.push(key);
|
|
134
|
+
const neighbors = (edges.get(key) ?? []).toSorted(compareKeys);
|
|
135
|
+
for (const next of neighbors) {
|
|
136
|
+
const state = states.get(next);
|
|
137
|
+
if (state === 'visiting') {
|
|
138
|
+
const loop = path.slice(path.indexOf(next));
|
|
139
|
+
const smallest = loop.indexOf(loop.toSorted(compareKeys).at(0) ?? next);
|
|
140
|
+
return [...loop.slice(smallest), ...loop.slice(0, smallest), loop.at(smallest) ?? next];
|
|
141
|
+
}
|
|
142
|
+
const found = state === undefined ? visit(next) : undefined;
|
|
143
|
+
if (found !== undefined)
|
|
144
|
+
return found;
|
|
145
|
+
}
|
|
146
|
+
path.pop();
|
|
147
|
+
states.set(key, 'done');
|
|
148
|
+
return undefined;
|
|
149
|
+
};
|
|
150
|
+
const roots = [...edges].map(([key]) => key).toSorted(compareKeys);
|
|
151
|
+
for (const key of roots) {
|
|
152
|
+
const found = states.has(key) ? undefined : visit(key);
|
|
153
|
+
if (found !== undefined)
|
|
154
|
+
return found;
|
|
155
|
+
}
|
|
156
|
+
return undefined;
|
|
157
|
+
}
|
|
158
|
+
function reachableThrough(start, stackEdges) {
|
|
159
|
+
const reached = new Set();
|
|
160
|
+
const pending = [start];
|
|
161
|
+
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
162
|
+
const nextKeys = stackEdges.get(key) ?? [];
|
|
163
|
+
for (const next of nextKeys) {
|
|
164
|
+
if (reached.has(next))
|
|
165
|
+
continue;
|
|
166
|
+
reached.add(next);
|
|
167
|
+
pending.push(next);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return reached;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
フェーズごとの進め方を、Issue の状態を見ずに前提の形と種類だけで決める。輪があれば進め方を出さず輪を返す
|
|
174
|
+
*/
|
|
175
|
+
export function planProgression(phases) {
|
|
176
|
+
const cycle = findCycle(new Map(phases.map(phase => [phase.key, phase.prerequisites.map(({ key }) => key)])));
|
|
177
|
+
if (cycle !== undefined)
|
|
178
|
+
return { kind: 'cycle', cycle };
|
|
179
|
+
const stackEdges = new Map(phases.map(phase => [phase.key, phase.prerequisites.filter(({ wait }) => wait === 'stack').map(({ key }) => key)]));
|
|
180
|
+
const progressions = new Map();
|
|
181
|
+
for (const phase of phases) {
|
|
182
|
+
const keys = phase.prerequisites.map(({ key }) => key);
|
|
183
|
+
if (keys.length === 0) {
|
|
184
|
+
progressions.set(phase.key, { kind: 'alone' });
|
|
185
|
+
}
|
|
186
|
+
else if (phase.prerequisites.some(({ wait }) => wait === 'merge')) {
|
|
187
|
+
progressions.set(phase.key, { kind: 'wait-merge' });
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
const top = keys.find((key) => {
|
|
191
|
+
const reached = reachableThrough(key, stackEdges);
|
|
192
|
+
return keys.every(other => other === key || reached.has(other));
|
|
193
|
+
});
|
|
194
|
+
progressions.set(phase.key, top === undefined ? { kind: 'join' } : { kind: 'stack', on: top });
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
return { kind: 'planned', progressions };
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
stack の積む先をたどった木の、根から葉までの道を、下から並べて返す。stack の無い根は道を作らないので、1 段だけの道は出ない
|
|
201
|
+
*/
|
|
202
|
+
export function stackChains(progressions) {
|
|
203
|
+
const children = new Map();
|
|
204
|
+
for (const [key, progression] of progressions) {
|
|
205
|
+
if (progression.kind === 'stack')
|
|
206
|
+
children.set(progression.on, [...children.get(progression.on) ?? [], key]);
|
|
207
|
+
}
|
|
208
|
+
const roots = [...children].map(([key]) => key).filter(key => progressions.get(key)?.kind !== 'stack');
|
|
209
|
+
const walk = (key, path) => {
|
|
210
|
+
const next = (children.get(key) ?? []).filter(child => !path.includes(child));
|
|
211
|
+
return next.length === 0 ? [path] : next.flatMap(child => walk(child, [...path, child]));
|
|
212
|
+
};
|
|
213
|
+
return roots.flatMap(root => walk(root, [root]));
|
|
214
|
+
}
|
|
215
|
+
/**
|
|
216
|
+
target から前提をたどって届く部分のグラフに findCycle をかけ、輪が target を含むときだけ返す。
|
|
217
|
+
別の Issue の輪に行き当たっただけの Issue には、輪を付けない
|
|
218
|
+
*/
|
|
219
|
+
export function cycleThrough(target, edges) {
|
|
220
|
+
const reached = new Set([target]);
|
|
221
|
+
const pending = [target];
|
|
222
|
+
for (let key = pending.pop(); key !== undefined; key = pending.pop()) {
|
|
223
|
+
const nextKeys = edges.get(key) ?? [];
|
|
224
|
+
for (const next of nextKeys) {
|
|
225
|
+
if (reached.has(next))
|
|
226
|
+
continue;
|
|
227
|
+
reached.add(next);
|
|
228
|
+
pending.push(next);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
const subgraph = new Map([...reached].map(key => [key, edges.get(key) ?? []]));
|
|
232
|
+
const cycle = findCycle(subgraph);
|
|
233
|
+
return cycle?.includes(target) === true ? cycle : undefined;
|
|
234
|
+
}
|
|
235
|
+
/**
|
|
236
|
+
判定の一覧(Issue のキー → 判定)から、stackChains に渡す進め方を作る。
|
|
237
|
+
stackable は積む先の Issue の上に積み、それ以外は単独として扱う
|
|
238
|
+
*/
|
|
239
|
+
export function progressionsFromReadiness(readiness) {
|
|
240
|
+
return new Map([...readiness].map(([key, judged]) => [
|
|
241
|
+
key,
|
|
242
|
+
judged.kind === 'stackable' && judged.stackOn !== undefined
|
|
243
|
+
? { kind: 'stack', on: issueReferenceKey(judged.stackOn.issue) }
|
|
244
|
+
: { kind: 'alone' },
|
|
245
|
+
]));
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
メッセージに出す Issue の表記。home と同じリポジトリは `#N`、別のリポジトリは `owner/repo#N`。home が無ければ常に `owner/repo#N`
|
|
249
|
+
*/
|
|
250
|
+
export function displayReference(reference, home) {
|
|
251
|
+
const number = `#${String(reference.number)}`;
|
|
252
|
+
return home !== undefined && isSameRepository(reference.repository, home) ? number : `${repositoryFullName(reference.repository)}${number}`;
|
|
253
|
+
}
|
|
254
|
+
const NOT_IN_REVIEW_TEXT = new Map([
|
|
255
|
+
['not-started', 'not started'],
|
|
256
|
+
['started-without-pr', 'no PR'],
|
|
257
|
+
['multiple-prs', 'multiple PRs'],
|
|
258
|
+
['fork-pr', 'PR from fork'],
|
|
259
|
+
['pending', 'in Pending'],
|
|
260
|
+
]);
|
|
261
|
+
/**
|
|
262
|
+
前提 1 件の状態の文。`done`・`closed without merge`・`in review`・`wait: merge — <理由>`、または積めない理由(not started など)
|
|
263
|
+
*/
|
|
264
|
+
export function describePrerequisiteState(prerequisite) {
|
|
265
|
+
const { issue, wait, reason } = prerequisite;
|
|
266
|
+
if (isDone(issue))
|
|
267
|
+
return 'done';
|
|
268
|
+
if (issue.state === 'closed')
|
|
269
|
+
return 'closed without merge';
|
|
270
|
+
if (wait === 'merge')
|
|
271
|
+
return reason === undefined ? 'wait: merge' : `wait: merge — ${reason}`;
|
|
272
|
+
const state = notInReviewState(issue);
|
|
273
|
+
return isStackable(issue) ? 'in review' : (NOT_IN_REVIEW_TEXT.get(state) ?? state);
|
|
274
|
+
}
|
|
275
|
+
function describeReason(reason, targetRepository) {
|
|
276
|
+
const show = (reference) => displayReference(reference, targetRepository);
|
|
277
|
+
switch (reason.code) {
|
|
278
|
+
case 'unreadable': {
|
|
279
|
+
return 'unreadable';
|
|
280
|
+
}
|
|
281
|
+
case 'waits-merge': {
|
|
282
|
+
return 'waits for merge';
|
|
283
|
+
}
|
|
284
|
+
case 'diverged': {
|
|
285
|
+
return 'not in one chain';
|
|
286
|
+
}
|
|
287
|
+
case 'closed-unmerged': {
|
|
288
|
+
return `closed without merge: ${reason.issues.map(issue => show(issue)).join(', ')}`;
|
|
289
|
+
}
|
|
290
|
+
case 'other-repository': {
|
|
291
|
+
return `other repository: ${reason.issues.map(issue => show(issue)).join(', ')}`;
|
|
292
|
+
}
|
|
293
|
+
case 'not-in-review': {
|
|
294
|
+
return `not in review: ${reason.issues.map(({ issue, state }) => `${show(issue)} (${NOT_IN_REVIEW_TEXT.get(state) ?? state})`).join(', ')}`;
|
|
295
|
+
}
|
|
296
|
+
case 'cycle': {
|
|
297
|
+
const prefix = `${repositoryFullName(targetRepository).toLowerCase()}#`;
|
|
298
|
+
return `cycle: ${reason.cycle.map(key => (key.startsWith(prefix) ? `#${key.slice(prefix.length)}` : key)).join(' -> ')}`;
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
/**
|
|
303
|
+
判定を 1 行の文にする。`startable`・`stackable on #N`・`blocked by #N, #M (<理由>)`。
|
|
304
|
+
blocked by の後には、済んでいない前提をすべて並べる。別のリポジトリの Issue は `owner/repo#N`
|
|
305
|
+
*/
|
|
306
|
+
export function describeReadiness(readiness, prerequisites, targetRepository) {
|
|
307
|
+
if (readiness.kind === 'startable')
|
|
308
|
+
return 'startable';
|
|
309
|
+
if (readiness.kind === 'stackable') {
|
|
310
|
+
return readiness.stackOn === undefined ? 'stackable' : `stackable on ${displayReference(readiness.stackOn.issue, targetRepository)}`;
|
|
311
|
+
}
|
|
312
|
+
const unfinished = prerequisites.filter(({ issue }) => !isDone(issue)).map(({ issue }) => displayReference(issue.ref, targetRepository));
|
|
313
|
+
const reason = readiness.reason === undefined ? '' : ` (${describeReason(readiness.reason, targetRepository)})`;
|
|
314
|
+
return `blocked${unfinished.length === 0 ? '' : ` by ${unfinished.join(', ')}`}${reason}`;
|
|
315
|
+
}
|
|
316
|
+
/**
|
|
317
|
+
読めなかった Issue の表示。列と札は動かさない
|
|
318
|
+
*/
|
|
319
|
+
export function describeUnknown(reason) {
|
|
320
|
+
return `unknown (${reason})`;
|
|
321
|
+
}
|
|
322
|
+
const LOWER_STATE = { OPEN: 'open', MERGED: 'merged', CLOSED: 'closed' };
|
|
323
|
+
function toPullRequest(readout) {
|
|
324
|
+
return {
|
|
325
|
+
repository: readout.repository,
|
|
326
|
+
number: readout.number,
|
|
327
|
+
state: LOWER_STATE[readout.state],
|
|
328
|
+
headRefName: readout.headRefName,
|
|
329
|
+
baseRefName: readout.baseRefName,
|
|
330
|
+
isDraft: readout.isDraft,
|
|
331
|
+
isCrossRepository: readout.isCrossRepository,
|
|
332
|
+
};
|
|
333
|
+
}
|
|
334
|
+
// 3 つの読み口で同じ PR を 1 本に数える。fork からの PR は、リンクしたブランチの読み口だけ捨てる
|
|
335
|
+
function collectPullRequests(readout) {
|
|
336
|
+
const sources = [
|
|
337
|
+
...readout.linkedBranches.flatMap(branch => branch.pullRequests).filter(pullRequest => !pullRequest.isCrossRepository),
|
|
338
|
+
...readout.closingPullRequests,
|
|
339
|
+
...readout.timelinePullRequests,
|
|
340
|
+
];
|
|
341
|
+
const seen = new Set();
|
|
342
|
+
return sources
|
|
343
|
+
.filter((source) => {
|
|
344
|
+
const key = issueReferenceKey({ repository: source.repository, number: source.number });
|
|
345
|
+
if (seen.has(key))
|
|
346
|
+
return false;
|
|
347
|
+
seen.add(key);
|
|
348
|
+
return true;
|
|
349
|
+
})
|
|
350
|
+
.map(source => toPullRequest(source));
|
|
351
|
+
}
|
|
352
|
+
function workKind(readout) {
|
|
353
|
+
if (isEpicIssue({ issue_type: readout.issueType, sub_issues_total: readout.subIssuesTotal }))
|
|
354
|
+
return 'epic';
|
|
355
|
+
return readout.title.startsWith(TRACKER_TITLE_PREFIX) ? 'tracker' : 'task';
|
|
356
|
+
}
|
|
357
|
+
function toFacts(readout, options) {
|
|
358
|
+
const valueOf = (fieldName) => readout.projectFieldValues.find(value => value.fieldName === fieldName)?.optionName;
|
|
359
|
+
return {
|
|
360
|
+
ref: { repository: readout.repository, number: readout.number },
|
|
361
|
+
state: LOWER_STATE[readout.state],
|
|
362
|
+
column: valueOf(options.columnFieldName),
|
|
363
|
+
label: valueOf(options.labelFieldName),
|
|
364
|
+
kind: workKind(readout),
|
|
365
|
+
branches: readout.linkedBranches.map(branch => branch.name),
|
|
366
|
+
pullRequests: collectPullRequests(readout),
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
/**
|
|
370
|
+
infra の読み取り結果を、判定の入力(Issue の実態)にまとめる。
|
|
371
|
+
本文の節が malformed なら前提をすべて merge にし、節にあって blocked by に無い組は mismatches に返す
|
|
372
|
+
*/
|
|
373
|
+
export function toIssueFacts(readout, section, options) {
|
|
374
|
+
const target = toFacts(readout.issue, options);
|
|
375
|
+
if (readout.blockedBy.kind === 'read-failed')
|
|
376
|
+
return { target, prerequisites: 'read-failed', mismatches: [] };
|
|
377
|
+
const lines = section.kind === 'ok' ? section.lines : [];
|
|
378
|
+
const reasons = new Map(lines.map(line => [issueReferenceKey(line.ref), line.reason]));
|
|
379
|
+
const prerequisites = readout.blockedBy.issues.map((blocker) => {
|
|
380
|
+
const issue = toFacts(blocker, options);
|
|
381
|
+
const reason = reasons.get(issueReferenceKey(issue.ref));
|
|
382
|
+
const wait = reason !== undefined || section.kind === 'malformed' ? 'merge' : 'stack';
|
|
383
|
+
return { issue, wait, reason };
|
|
384
|
+
});
|
|
385
|
+
const present = new Set(prerequisites.map(({ issue }) => issueReferenceKey(issue.ref)));
|
|
386
|
+
const mismatches = lines
|
|
387
|
+
.filter(line => !present.has(issueReferenceKey(line.ref)))
|
|
388
|
+
.map(line => ({ ref: line.ref, reason: line.reason }));
|
|
389
|
+
return { target, prerequisites, mismatches };
|
|
390
|
+
}
|
|
391
|
+
//# sourceMappingURL=readiness.js.map
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import type { HintedText } from './command-hint.js';
|
|
2
|
+
import { PecotError } from './errors.js';
|
|
3
|
+
import type { RepositoryReference } from './repository-resolver.js';
|
|
4
|
+
/**
|
|
5
|
+
参照のパースエラー。CLI 層で引数の誤りに変換する。元の入力を持つ
|
|
6
|
+
*/
|
|
7
|
+
export declare class ReferenceParseError extends PecotError {
|
|
8
|
+
readonly reference: string;
|
|
9
|
+
readonly hintedText: HintedText | undefined;
|
|
10
|
+
constructor(message: string | HintedText, reference: string, options?: Readonly<ErrorOptions>);
|
|
11
|
+
}
|
|
12
|
+
export interface IssueReference {
|
|
13
|
+
readonly repository: RepositoryReference;
|
|
14
|
+
readonly number: number;
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
番号が正の整数であることを検証して作る。Issue と PR は番号空間を共有する
|
|
18
|
+
*/
|
|
19
|
+
export declare function createIssueReference(repository: RepositoryReference, number: number): IssueReference;
|
|
20
|
+
export declare function issueReferenceToString(reference: IssueReference): string;
|
|
21
|
+
/**
|
|
22
|
+
リポ名の大文字小文字を区別しない、Issue / PR の同一判定用のキー
|
|
23
|
+
*/
|
|
24
|
+
export declare function issueReferenceKey(reference: IssueReference): string;
|
|
25
|
+
export declare function issueReferenceToCliReference(reference: IssueReference): string;
|
|
26
|
+
/**
|
|
27
|
+
Issue 参照を IssueReference にする。
|
|
28
|
+
`owner/repo/N` は主軸形式。`N` は短縮形で、baseRepository が要る。
|
|
29
|
+
形式が不正・短縮形で基準リポが無いときは ReferenceParseError。
|
|
30
|
+
repositoryFlag は --repo で短縮形を解決するコマンドか。true のときだけ error で --repo を案内する
|
|
31
|
+
*/
|
|
32
|
+
export declare function parseIssueReference(raw: string, baseRepository?: RepositoryReference, { repositoryFlag }?: {
|
|
33
|
+
readonly repositoryFlag?: boolean;
|
|
34
|
+
}): IssueReference;
|
|
35
|
+
/**
|
|
36
|
+
PR 参照を IssueReference にする。Issue と番号空間を共有するので parseIssueReference に委ねる
|
|
37
|
+
*/
|
|
38
|
+
export declare function parsePullRequestReference(raw: string, baseRepository?: RepositoryReference, options?: {
|
|
39
|
+
readonly repositoryFlag?: boolean;
|
|
40
|
+
}): IssueReference;
|
|
41
|
+
/**
|
|
42
|
+
`owner/repo` 形式の文字列を RepositoryReference にする。不正なら ReferenceParseError
|
|
43
|
+
*/
|
|
44
|
+
export declare function parseRepositoryReference(raw: string): RepositoryReference;
|
|
45
|
+
/**
|
|
46
|
+
PR 本文の Refs で参照された Issue 番号を集める。
|
|
47
|
+
受理形式は `Refs #N`・`Refs owner/repo#N`・`Refs owner/repo/N`(`Ref` も可、コロンは任意、大文字小文字は区別しない)。
|
|
48
|
+
owner/repo 付きの参照は、repository と一致(大文字小文字を区別しない)するものだけ採る
|
|
49
|
+
*/
|
|
50
|
+
export declare function extractReferencesIssueNumbers(body: string | undefined, repository: RepositoryReference): ReadonlySet<number>;
|
|
51
|
+
//# sourceMappingURL=reference-parser.d.ts.map
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
// Issue / PR 参照のパーサー。
|
|
2
|
+
//
|
|
3
|
+
// `owner/repo/N` 形式を IssueReference にする。短縮形 `N` は基準リポ(baseRepository)で補う。
|
|
4
|
+
// 参照の形式が不正なときの文は、Python の CLI が出していた文に揃える。
|
|
5
|
+
import { formatHinted, globalRepositoryHint, hinted, placeholder } from './command-hint.js';
|
|
6
|
+
import { PecotError, InvalidValueError } from './errors.js';
|
|
7
|
+
import { parsePythonInteger, ValidationFailure } from './python-format.js';
|
|
8
|
+
import { createRepositoryReference, parseOwnerRepository, repositoryFullName } from './repository-resolver.js';
|
|
9
|
+
/**
|
|
10
|
+
参照のパースエラー。CLI 層で引数の誤りに変換する。元の入力を持つ
|
|
11
|
+
*/
|
|
12
|
+
export class ReferenceParseError extends PecotError {
|
|
13
|
+
reference;
|
|
14
|
+
hintedText;
|
|
15
|
+
// message は CLI の形。出し先の形は hintedText から描き直す
|
|
16
|
+
constructor(message, reference, options) {
|
|
17
|
+
super(formatHinted(message, 'cli'), options);
|
|
18
|
+
this.reference = reference;
|
|
19
|
+
this.hintedText = typeof message === 'string' ? undefined : message;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
番号が正の整数であることを検証して作る。Issue と PR は番号空間を共有する
|
|
24
|
+
*/
|
|
25
|
+
export function createIssueReference(repository, number) {
|
|
26
|
+
if (number <= 0) {
|
|
27
|
+
throw new ValidationFailure('IssueRef', [{ type: 'greater_than', location: ['number'], message: 'Input should be greater than 0', input: number }]);
|
|
28
|
+
}
|
|
29
|
+
return Object.freeze({ repository, number });
|
|
30
|
+
}
|
|
31
|
+
export function issueReferenceToString(reference) {
|
|
32
|
+
return `${repositoryFullName(reference.repository)}#${String(reference.number)}`;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
リポ名の大文字小文字を区別しない、Issue / PR の同一判定用のキー
|
|
36
|
+
*/
|
|
37
|
+
export function issueReferenceKey(reference) {
|
|
38
|
+
return issueReferenceToString(reference).toLowerCase();
|
|
39
|
+
}
|
|
40
|
+
export function issueReferenceToCliReference(reference) {
|
|
41
|
+
return `${repositoryFullName(reference.repository)}/${String(reference.number)}`;
|
|
42
|
+
}
|
|
43
|
+
// Python の `$` は末尾の改行の手前にも一致する。`\d` は Unicode の 10 進数字に一致する
|
|
44
|
+
const FULL_REFERENCE_PATTERN = /^([^/]+)\/([^/]+)\/(\p{Nd}+)\n?$/u;
|
|
45
|
+
function integerOf(digits) {
|
|
46
|
+
const value = parsePythonInteger(digits);
|
|
47
|
+
if (value === undefined)
|
|
48
|
+
throw new InvalidValueError(`invalid literal for int() with base 10: ${digits}`);
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
function invalidFormat(raw) {
|
|
52
|
+
return new ReferenceParseError(`invalid reference: ${raw}\naccepted forms:\n - full: 'owner/repo/N'\n - short: 'N' (with a base repository)`, raw);
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
Issue 参照を IssueReference にする。
|
|
56
|
+
`owner/repo/N` は主軸形式。`N` は短縮形で、baseRepository が要る。
|
|
57
|
+
形式が不正・短縮形で基準リポが無いときは ReferenceParseError。
|
|
58
|
+
repositoryFlag は --repo で短縮形を解決するコマンドか。true のときだけ error で --repo を案内する
|
|
59
|
+
*/
|
|
60
|
+
export function parseIssueReference(raw, baseRepository, { repositoryFlag = false } = {}) {
|
|
61
|
+
if (/^\d+$/u.test(raw)) {
|
|
62
|
+
if (baseRepository === undefined) {
|
|
63
|
+
throw new ReferenceParseError(repositoryFlag
|
|
64
|
+
? hinted `the short form 'N' needs a base_repo: pass ${globalRepositoryHint(placeholder('owner/repo'))} or use the full form 'owner/repo/N'`
|
|
65
|
+
: 'the short form \'N\' is not accepted here: use the full form \'owner/repo/N\'', raw);
|
|
66
|
+
}
|
|
67
|
+
return createIssueReference(baseRepository, integerOf(raw));
|
|
68
|
+
}
|
|
69
|
+
const [, owner, repository, digits] = FULL_REFERENCE_PATTERN.exec(raw) ?? [];
|
|
70
|
+
if (owner === undefined || repository === undefined || digits === undefined)
|
|
71
|
+
throw invalidFormat(raw);
|
|
72
|
+
try {
|
|
73
|
+
return createIssueReference(createRepositoryReference(owner, repository), integerOf(digits));
|
|
74
|
+
}
|
|
75
|
+
catch (error) {
|
|
76
|
+
if (error instanceof InvalidValueError)
|
|
77
|
+
throw new ReferenceParseError(error.message, raw, { cause: error });
|
|
78
|
+
throw error;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
PR 参照を IssueReference にする。Issue と番号空間を共有するので parseIssueReference に委ねる
|
|
83
|
+
*/
|
|
84
|
+
export function parsePullRequestReference(raw, baseRepository, options = {}) {
|
|
85
|
+
return parseIssueReference(raw, baseRepository, options);
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
`owner/repo` 形式の文字列を RepositoryReference にする。不正なら ReferenceParseError
|
|
89
|
+
*/
|
|
90
|
+
export function parseRepositoryReference(raw) {
|
|
91
|
+
try {
|
|
92
|
+
return parseOwnerRepository(raw);
|
|
93
|
+
}
|
|
94
|
+
catch (error) {
|
|
95
|
+
if (error instanceof InvalidValueError)
|
|
96
|
+
throw new ReferenceParseError(error.message, raw, { cause: error });
|
|
97
|
+
throw error;
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
const REFS_PATTERN = /(?:^|\s)Refs?:?\s+(?:#(?<number>\p{Nd}+)|(?<owner>[\w.-]+)\/(?<repository>[\w.-]+)[#/](?<qualifiedNumber>\p{Nd}+))/gimu;
|
|
101
|
+
/**
|
|
102
|
+
PR 本文の Refs で参照された Issue 番号を集める。
|
|
103
|
+
受理形式は `Refs #N`・`Refs owner/repo#N`・`Refs owner/repo/N`(`Ref` も可、コロンは任意、大文字小文字は区別しない)。
|
|
104
|
+
owner/repo 付きの参照は、repository と一致(大文字小文字を区別しない)するものだけ採る
|
|
105
|
+
*/
|
|
106
|
+
export function extractReferencesIssueNumbers(body, repository) {
|
|
107
|
+
const numbers = new Set();
|
|
108
|
+
if (body === undefined || body === '')
|
|
109
|
+
return numbers;
|
|
110
|
+
const ownerKey = repository.owner.toLowerCase();
|
|
111
|
+
const repositoryKey = repository.repository.toLowerCase();
|
|
112
|
+
for (const match of body.matchAll(REFS_PATTERN)) {
|
|
113
|
+
const { number, owner, repository: matchedRepository, qualifiedNumber } = match.groups ?? {};
|
|
114
|
+
if (number !== undefined) {
|
|
115
|
+
numbers.add(integerOf(number));
|
|
116
|
+
}
|
|
117
|
+
else if (qualifiedNumber !== undefined && owner?.toLowerCase() === ownerKey && matchedRepository?.toLowerCase() === repositoryKey) {
|
|
118
|
+
numbers.add(integerOf(qualifiedNumber));
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
return numbers;
|
|
122
|
+
}
|
|
123
|
+
//# sourceMappingURL=reference-parser.js.map
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import { PecotError } from './errors.js';
|
|
2
|
+
import type { GitRunner } from './git-runner.js';
|
|
3
|
+
export declare class ReleaseError extends PecotError {
|
|
4
|
+
}
|
|
5
|
+
export interface PreflightResult {
|
|
6
|
+
readonly version: string;
|
|
7
|
+
readonly releaseNotes: string;
|
|
8
|
+
readonly developBranch: string;
|
|
9
|
+
readonly releaseBranch: string;
|
|
10
|
+
/**
|
|
11
|
+
release→develop の差分コミット数
|
|
12
|
+
*/
|
|
13
|
+
readonly diffCount: number;
|
|
14
|
+
/**
|
|
15
|
+
作成予定のタグ名(`v0.6.1` または `pecot-workflow-v0.6.1`)
|
|
16
|
+
*/
|
|
17
|
+
readonly tagName: string;
|
|
18
|
+
}
|
|
19
|
+
export interface PreflightOptions {
|
|
20
|
+
/**
|
|
21
|
+
エラー文に出す CHANGELOG.md のパス
|
|
22
|
+
*/
|
|
23
|
+
readonly changelogPath: string;
|
|
24
|
+
/**
|
|
25
|
+
CHANGELOG.md の内容。ファイルが無ければ undefined
|
|
26
|
+
*/
|
|
27
|
+
readonly changelogContent: string | undefined;
|
|
28
|
+
readonly developBranch: string;
|
|
29
|
+
readonly releaseBranch: string;
|
|
30
|
+
/**
|
|
31
|
+
リリースバージョン。省略すると CHANGELOG から検出する
|
|
32
|
+
*/
|
|
33
|
+
readonly version: string | undefined;
|
|
34
|
+
/**
|
|
35
|
+
タグの prefix(monorepo 用)。空でなければ `<prefix>-v<ver>`、省略か空なら `v<ver>`
|
|
36
|
+
*/
|
|
37
|
+
readonly tagPrefix: string | undefined;
|
|
38
|
+
/**
|
|
39
|
+
ls-remote と文に使う remote 名。省略すると origin
|
|
40
|
+
*/
|
|
41
|
+
readonly remote?: string | undefined;
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
base より head が進んでいる commit の数。GitHub の compare で数え、手元の ref は動かさない
|
|
45
|
+
*/
|
|
46
|
+
export type CountCommitsAhead = (base: string, head: string) => Promise<number>;
|
|
47
|
+
/**
|
|
48
|
+
リリース前チェックを実行する。
|
|
49
|
+
1. CHANGELOG.md の存在、2. バージョンの検出または検証、3. タグが無いこと(ローカル・リモート)、
|
|
50
|
+
4. release→develop の差分(countAhead)、5. リリースノートの抽出、の順に確かめる。失敗は ReleaseError
|
|
51
|
+
*/
|
|
52
|
+
export declare function runPreflight(options: PreflightOptions, git: GitRunner, countAhead: CountCommitsAhead): Promise<PreflightResult>;
|
|
53
|
+
//# sourceMappingURL=release.d.ts.map
|