@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,236 @@
|
|
|
1
|
+
// session start。Python の cli/commands/repo.py の create_branch の移植。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { findRepository, getFieldId, getOptionId, isRepositoryInProject } from '../domain/config.js';
|
|
4
|
+
import { ReferenceParseError, parseIssueReference } from '../domain/reference-parser.js';
|
|
5
|
+
import { pythonStringRepr } from '../domain/python-format.js';
|
|
6
|
+
import { repositoryFullName } from '../domain/repository-resolver.js';
|
|
7
|
+
import { displayReference } from '../domain/readiness.js';
|
|
8
|
+
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
9
|
+
import { decideStart, describeBaseMismatch } from '../domain/work-start.js';
|
|
10
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
11
|
+
import { readFlag } from '../infra/state-store.js';
|
|
12
|
+
import { createOutput } from './output.js';
|
|
13
|
+
import { defineCommand } from './command-definition.js';
|
|
14
|
+
import { commandHint, hinted, inputHint, joinHinted } from './command-hint.js';
|
|
15
|
+
import { requireActiveConfig, stopWith } from './command-stop.js';
|
|
16
|
+
import { kindOfFailure } from './failure.js';
|
|
17
|
+
import { createGitHubClient } from './github-client.js';
|
|
18
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
19
|
+
import { requireRepositoryMatch, resolveCurrentRepository } from './repository-match.js';
|
|
20
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
21
|
+
import { planWorkTarget, recordWorkTarget } from './work-target.js';
|
|
22
|
+
const START_PATH = ['session', 'start'];
|
|
23
|
+
/**
|
|
24
|
+
A-1. 作業ディレクトリの git remote のリポジトリが Issue のリポジトリと違えば、終了コード 2 で止める
|
|
25
|
+
*/
|
|
26
|
+
function rejectCwdRepositoryMismatch(out, owner, repository) {
|
|
27
|
+
const resolved = resolveCurrentRepository(process.cwd());
|
|
28
|
+
if (resolved?.source !== 'current-git')
|
|
29
|
+
return;
|
|
30
|
+
const current = resolved.repository;
|
|
31
|
+
if (current.owner === owner && current.repository === repository)
|
|
32
|
+
return;
|
|
33
|
+
stopWith(out, joinHinted([
|
|
34
|
+
`the repository of the work Issue (${owner}/${repository}) differs from `
|
|
35
|
+
+ `the CWD git remote (${repositoryFullName(current)})\n`
|
|
36
|
+
+ 'move to the worktree of the target repository and run again:\n'
|
|
37
|
+
+ `<project-root>/base/${repository}/ or <project-root>/<wtN>/${repository}/\n`
|
|
38
|
+
+ 'create one with /pecot-w:w-worktree-add only if the repository has no worktree\n'
|
|
39
|
+
+ 'to issue the command on purpose from outside the CWD (for example in a script), ',
|
|
40
|
+
hinted `give ${inputHint(START_PATH, 'allow_cross_repo')}`,
|
|
41
|
+
], ''), 'repo-mismatch', USAGE_EXIT_CODE);
|
|
42
|
+
}
|
|
43
|
+
/**
|
|
44
|
+
develop_branch を設定する直し方の行
|
|
45
|
+
*/
|
|
46
|
+
function developBranchGuide(owner, repository) {
|
|
47
|
+
return hinted `set it with: ${commandHint(['project', 'link'], { repo: `${owner}/${repository}`, develop_branch: 'develop' })}`;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
3. ベースブランチを決める(--base を先に、無ければ設定の develop_branch)
|
|
51
|
+
*/
|
|
52
|
+
function resolveBaseBranch(out, query) {
|
|
53
|
+
const { config, owner, repository, issueNumber, branch, base } = query;
|
|
54
|
+
if (base !== undefined && base !== '')
|
|
55
|
+
return base;
|
|
56
|
+
const developBranch = findRepository(config, owner, repository)?.develop_branch;
|
|
57
|
+
if (developBranch === undefined || developBranch === '') {
|
|
58
|
+
const withBase = commandHint(START_PATH, { issue_ref: `${owner}/${repository}/${String(issueNumber)}`, branch, base: 'main' });
|
|
59
|
+
stopWith(out, joinHinted([`develop_branch is not set for ${owner}/${repository}`, developBranchGuide(owner, repository), hinted `or give the base: ${withBase}`]), 'repo-setting-missing');
|
|
60
|
+
}
|
|
61
|
+
return developBranch;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
3.5. 着手の判定を読み、積む先を決める。blocked と読めないときは止める。依存関係を持たない GHES は、warning を出して判定なしで進める
|
|
65
|
+
*/
|
|
66
|
+
async function decideWorkStart(out, client, config, issue) {
|
|
67
|
+
const label = displayReference(issue, issue.repository);
|
|
68
|
+
const warnNotChecked = (reason) => {
|
|
69
|
+
out.warning(`readiness is not checked: ${reason}`);
|
|
70
|
+
};
|
|
71
|
+
const result = await readIssueReadinessIfSupported(client, config, issue, createReadinessCache(), warnNotChecked);
|
|
72
|
+
if (result === undefined)
|
|
73
|
+
return { kind: 'start' };
|
|
74
|
+
if (result.kind === 'unreadable') {
|
|
75
|
+
if (result.snapshot === undefined)
|
|
76
|
+
return stopWith(out, `could not read blocked-by of ${label}: ${result.reason}`, 'dependency-unreadable');
|
|
77
|
+
const isUnset = result.snapshot.developmentBranch === undefined || result.snapshot.developmentBranch === '';
|
|
78
|
+
const guide = isUnset ? [developBranchGuide(issue.repository.owner, issue.repository.repository)] : [];
|
|
79
|
+
return stopWith(out, joinHinted([`could not judge readiness of ${label}: ${result.reason}`, ...guide]), 'dependency-unreadable');
|
|
80
|
+
}
|
|
81
|
+
const decision = decideStart(result.readiness, result.prerequisites, issue);
|
|
82
|
+
return decision.kind === 'blocked' ? stopWith(out, decision.message, 'not-ready', USAGE_EXIT_CODE) : decision;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
A-2. .pecot-active が別の OPEN な Issue を指していれば、終了コード 2 で止める
|
|
86
|
+
*/
|
|
87
|
+
async function guardActiveOverwrite(out, client, issueReference) {
|
|
88
|
+
const existing = readFlag(FLAG_PECOT_ACTIVE) ?? '';
|
|
89
|
+
if (existing === '' || existing === issueReference)
|
|
90
|
+
return;
|
|
91
|
+
let existingReference;
|
|
92
|
+
try {
|
|
93
|
+
existingReference = parseIssueReference(existing);
|
|
94
|
+
}
|
|
95
|
+
catch (error) {
|
|
96
|
+
if (!(error instanceof ReferenceParseError))
|
|
97
|
+
throw error;
|
|
98
|
+
out.warning(`the content of .pecot-active (${pythonStringRepr(existing)}) is malformed; overwriting it`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const { repository, number } = existingReference;
|
|
102
|
+
const { state } = await client.getIssueSlim(repository.owner, repository.repository, number);
|
|
103
|
+
if (state === 'OPEN') {
|
|
104
|
+
stopWith(out, joinHinted([
|
|
105
|
+
`this worktree is already working on another Issue (${existing}, OPEN)\n`
|
|
106
|
+
+ 'overwriting .pecot-active could mix up the tasks\n'
|
|
107
|
+
+ 'finish the other Issue first, or create another worktree with '
|
|
108
|
+
+ '/pecot-w:w-worktree-add and run /pecot-w:w-active again in its session',
|
|
109
|
+
hinted `if it is stale and you want to overwrite it on purpose, give ${inputHint(START_PATH, 'force_overwrite_active')}`,
|
|
110
|
+
]), 'guard-blocked', USAGE_EXIT_CODE);
|
|
111
|
+
}
|
|
112
|
+
out.warning(state === 'CLOSED'
|
|
113
|
+
? `.pecot-active points to closed Issue ${existing}; overwriting it`
|
|
114
|
+
: `the state of ${existing} in .pecot-active is unexpected (${pythonStringRepr(state)}); overwriting it`);
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
7.5. プロジェクトアイテムのステータスを active にする(失敗は warning にとどめる)
|
|
118
|
+
*/
|
|
119
|
+
async function setIssueStatusActive(out, client, config, issue) {
|
|
120
|
+
const { owner, repository, number } = issue;
|
|
121
|
+
const target = `Issue ${owner}/${repository}/${String(number)} status active`;
|
|
122
|
+
try {
|
|
123
|
+
const itemId = await client.getItemIdByIssue(config.project.id, owner, repository, number);
|
|
124
|
+
if (itemId === undefined || itemId === '') {
|
|
125
|
+
out.warning(`could not set ${target}: the Issue is not on the project board`);
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
const fieldId = getFieldId(config, 'workflow');
|
|
129
|
+
const optionId = getOptionId(config, 'workflow', 'active');
|
|
130
|
+
if (fieldId === undefined || fieldId === '' || optionId === undefined || optionId === '') {
|
|
131
|
+
out.warning(`could not set ${target}: the workflow status field has no 'active' option`);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
await client.updateProjectItemField(config.project.id, itemId, fieldId, optionId);
|
|
135
|
+
out.done({ verb: 'set', target });
|
|
136
|
+
}
|
|
137
|
+
catch (error) {
|
|
138
|
+
// ブランチは作成済みなので、ステータスの失敗でコマンドは止めない
|
|
139
|
+
if (!(error instanceof GitHubAPIError))
|
|
140
|
+
throw error;
|
|
141
|
+
out.warning(`could not set ${target}: ${error.message}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
const sessionStartCommand = defineCommand({
|
|
145
|
+
path: START_PATH,
|
|
146
|
+
description: 'Create a branch linked to an Issue (shown in the Development section of the Issue)',
|
|
147
|
+
input: z.strictObject({
|
|
148
|
+
issue_ref: z.string().describe('Issue reference (owner/repo/123)'),
|
|
149
|
+
branch: z.string().describe('Name of the branch to create'),
|
|
150
|
+
base: z.string().optional().describe('Base branch (default: chosen by readiness, else develop_branch from the config)'),
|
|
151
|
+
checkout: z.boolean().default(true).describe('Kept for compatibility; has no effect'),
|
|
152
|
+
allow_cross_repo: z.boolean().default(false).describe('Allow the CWD repository to differ from the Issue ref (for scripts and runs outside the CWD)'),
|
|
153
|
+
force_overwrite_active: z.boolean().default(false).describe('Disable the .pecot-active overwrite guard (when sure it is stale)'),
|
|
154
|
+
dry_run: z.boolean().default(false).describe('Show what would be created and recorded without writing anything'),
|
|
155
|
+
}),
|
|
156
|
+
positional: ['issue_ref', 'branch'],
|
|
157
|
+
shortFlags: { base: '-b', allow_cross_repo: '-X', force_overwrite_active: '-F', dry_run: '-n' },
|
|
158
|
+
negations: { checkout: '--no-checkout' },
|
|
159
|
+
interactive: false,
|
|
160
|
+
run: async (input, io) => {
|
|
161
|
+
requireRepositoryMatch('reject', input.repo, io, process.cwd());
|
|
162
|
+
const out = createOutput(input.dry_run, io);
|
|
163
|
+
// 1. 設定取得
|
|
164
|
+
const config = requireActiveConfig(out);
|
|
165
|
+
// 2. issue_ref をパース(フル形式必須、基準リポは渡さない)
|
|
166
|
+
let issue;
|
|
167
|
+
try {
|
|
168
|
+
issue = parseIssueReference(input.issue_ref);
|
|
169
|
+
}
|
|
170
|
+
catch (error) {
|
|
171
|
+
if (!(error instanceof ReferenceParseError))
|
|
172
|
+
throw error;
|
|
173
|
+
return stopWith(out, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
174
|
+
}
|
|
175
|
+
const { owner, repository } = issue.repository;
|
|
176
|
+
const issueNumber = issue.number;
|
|
177
|
+
// A-1. 作業ディレクトリと Issue ref のリポジトリの整合チェック
|
|
178
|
+
if (!input.allow_cross_repo)
|
|
179
|
+
rejectCwdRepositoryMismatch(out, owner, repository);
|
|
180
|
+
const finalBranchName = `${input.branch}/${String(issueNumber)}`;
|
|
181
|
+
try {
|
|
182
|
+
const client = createGitHubClient(out, config.host);
|
|
183
|
+
// A-2. .pecot-active 上書きガード
|
|
184
|
+
if (!input.force_overwrite_active)
|
|
185
|
+
await guardActiveOverwrite(out, client, `${owner}/${repository}/${String(issueNumber)}`);
|
|
186
|
+
// 4. リポジトリがプロジェクトに含まれているか確認
|
|
187
|
+
if (!await isRepositoryInProject(config, owner, repository, client)) {
|
|
188
|
+
stopWith(out, `${owner}/${repository} is not in the project`, 'repo-not-in-project');
|
|
189
|
+
}
|
|
190
|
+
// 4.5. 着手の判定で base を選ぶ。--base は積む先と比べる
|
|
191
|
+
const decision = await decideWorkStart(out, client, config, issue);
|
|
192
|
+
const mismatch = describeBaseMismatch(input.base, decision, issue);
|
|
193
|
+
if (mismatch !== undefined)
|
|
194
|
+
stopWith(out, mismatch, 'invalid-input', USAGE_EXIT_CODE);
|
|
195
|
+
// 3. ベースブランチ決定(積まないときだけ、--base か設定の develop_branch を求める)
|
|
196
|
+
const baseBranch = decision.kind === 'stack' ? decision.branch : resolveBaseBranch(out, { config, owner, repository, issueNumber, branch: input.branch, base: input.base });
|
|
197
|
+
// 5. Issue Node ID とタイトル取得(タイトルはセッション名用)
|
|
198
|
+
const { id: issueNodeId, title: issueTitle } = await client.getIssueNodeIdAndTitle(owner, repository, issueNumber);
|
|
199
|
+
// 6. ベースブランチの commit SHA 取得
|
|
200
|
+
let baseSha;
|
|
201
|
+
try {
|
|
202
|
+
baseSha = await client.getBranchSha(owner, repository, baseBranch);
|
|
203
|
+
}
|
|
204
|
+
catch (error) {
|
|
205
|
+
if (error instanceof GitHubAPIError && decision.kind === 'stack') {
|
|
206
|
+
return stopWith(out, `base branch ${baseBranch} of ${displayReference(decision.issue, issue.repository)} not found: ${error.message}`, 'git-unresolved');
|
|
207
|
+
}
|
|
208
|
+
throw error;
|
|
209
|
+
}
|
|
210
|
+
const stackedNote = decision.kind === 'stack' ? ` (stacked on ${displayReference(decision.issue, issue.repository)})` : '';
|
|
211
|
+
if (input.dry_run) {
|
|
212
|
+
out.planned({ verb: 'create', target: `branch ${finalBranchName} in ${owner}/${repository} from ${baseBranch}${stackedNote}` });
|
|
213
|
+
out.planned({ verb: 'set', target: `Issue ${owner}/${repository}/${String(issueNumber)} status active` });
|
|
214
|
+
planWorkTarget(out, owner, repository, issueNumber);
|
|
215
|
+
return 0;
|
|
216
|
+
}
|
|
217
|
+
// 7. リンクブランチ作成(ブランチ名末尾に Issue 番号を自動付与)
|
|
218
|
+
const createdBranch = await client.createLinkedBranch(issueNodeId, baseSha, finalBranchName);
|
|
219
|
+
out.done({ verb: 'create', target: `branch ${createdBranch} in ${owner}/${repository} from ${baseBranch}${stackedNote}` });
|
|
220
|
+
// 7.5. プロジェクトアイテムのステータスを active に更新
|
|
221
|
+
await setIssueStatusActive(out, client, config, { owner, repository, number: issueNumber });
|
|
222
|
+
// 9. 作業対象を .pecot-active と .pecot-session-title に保存(hook の自動投稿とセッション名用)
|
|
223
|
+
recordWorkTarget(out, owner, repository, issueNumber, issueTitle, {
|
|
224
|
+
base: { branch: baseBranch, sha: baseSha, stackedOn: decision.kind === 'stack' ? decision.issue : undefined },
|
|
225
|
+
});
|
|
226
|
+
return 0;
|
|
227
|
+
}
|
|
228
|
+
catch (error) {
|
|
229
|
+
if (!(error instanceof GitHubAPIError))
|
|
230
|
+
throw error;
|
|
231
|
+
return stopWith(out, `could not create branch ${finalBranchName} in ${owner}/${repository}: ${error.message}`, kindOfFailure(error));
|
|
232
|
+
}
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
export const SESSION_START_COMMANDS = [sessionStartCommand];
|
|
236
|
+
//# sourceMappingURL=session-start.js.map
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { CommandDefinition } from './command-definition.js';
|
|
2
|
+
/**
|
|
3
|
+
session のグループのコマンド。start は session-start.ts、finish は session-finish.ts にある。並びは help の一覧に出る順
|
|
4
|
+
*/
|
|
5
|
+
export declare const SESSION_COMMANDS: readonly CommandDefinition[];
|
|
6
|
+
//# sourceMappingURL=session.d.ts.map
|
|
@@ -0,0 +1,214 @@
|
|
|
1
|
+
// session show・session restore。cli/commands/session.py の移植。
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
import { extractIssueNumberFromBranch } from '../domain/branch-name.js';
|
|
4
|
+
import { ConfigError } from '../domain/config.js';
|
|
5
|
+
import { PecotError } from '../domain/errors.js';
|
|
6
|
+
import { describeReadiness } from '../domain/readiness.js';
|
|
7
|
+
import { parseIssueReference, ReferenceParseError } from '../domain/reference-parser.js';
|
|
8
|
+
import { FLAG_PECOT_ACTIVE } from '../domain/state.js';
|
|
9
|
+
import { describeStackBase, pickBasePullRequest } from '../domain/work-start.js';
|
|
10
|
+
import { loadActiveConfig } from '../infra/config-store.js';
|
|
11
|
+
import { gitCurrentBranch, primaryRemoteRepository } from '../infra/git.js';
|
|
12
|
+
import { GitHubAPIError } from '../infra/github/errors.js';
|
|
13
|
+
import { hasFlag, readBaseRecord, readFlag } from '../infra/state-store.js';
|
|
14
|
+
import { defineCommand } from './command-definition.js';
|
|
15
|
+
import { FAILURE_EXIT_CODE } from './failure.js';
|
|
16
|
+
import { commandHint, hinted, placeholder } from './command-hint.js';
|
|
17
|
+
import { stopWith } from './command-stop.js';
|
|
18
|
+
import { directorySchema } from './directory-option.js';
|
|
19
|
+
import { createGitHubClient } from './github-client.js';
|
|
20
|
+
import { createReadinessCache, readIssueReadinessIfSupported } from './issue-readiness.js';
|
|
21
|
+
import { createOutput } from './output.js';
|
|
22
|
+
import { SESSION_FINISH_COMMANDS } from './session-finish.js';
|
|
23
|
+
import { SESSION_START_COMMANDS } from './session-start.js';
|
|
24
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
25
|
+
import { planWorkTarget, recordWorkTarget } from './work-target.js';
|
|
26
|
+
const ALL_FLAGS = [FLAG_PECOT_ACTIVE];
|
|
27
|
+
function collectFlagStatuses() {
|
|
28
|
+
return ALL_FLAGS.map((name) => {
|
|
29
|
+
const isSet = hasFlag(name);
|
|
30
|
+
return { name, isSet, content: isSet ? readFlag(name) ?? '' : '' };
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
// .pecot-active の Issue を GitHub から読んで、Markdown の行にする。読めなければ warning だけ出して undefined にする
|
|
34
|
+
async function readActiveIssue(statuses, output) {
|
|
35
|
+
const active = statuses.find(status => status.name === FLAG_PECOT_ACTIVE && status.isSet && status.content !== '');
|
|
36
|
+
if (active === undefined)
|
|
37
|
+
return undefined;
|
|
38
|
+
let reference;
|
|
39
|
+
try {
|
|
40
|
+
reference = parseIssueReference(active.content);
|
|
41
|
+
}
|
|
42
|
+
catch (error) {
|
|
43
|
+
if (error instanceof ReferenceParseError)
|
|
44
|
+
return undefined;
|
|
45
|
+
throw error;
|
|
46
|
+
}
|
|
47
|
+
let issue;
|
|
48
|
+
let config;
|
|
49
|
+
let client;
|
|
50
|
+
try {
|
|
51
|
+
config = loadActiveConfig();
|
|
52
|
+
if (config === undefined) {
|
|
53
|
+
output.warning('cannot read the active Issue: no active project');
|
|
54
|
+
return undefined;
|
|
55
|
+
}
|
|
56
|
+
client = createGitHubClient(output, config.host);
|
|
57
|
+
issue = await client.getIssueSlim(reference.repository.owner, reference.repository.repository, reference.number, 0);
|
|
58
|
+
}
|
|
59
|
+
catch (error) {
|
|
60
|
+
if (error instanceof ConfigError || error instanceof GitHubAPIError) {
|
|
61
|
+
output.warning(`cannot read the active Issue: ${error.message}`);
|
|
62
|
+
return undefined;
|
|
63
|
+
}
|
|
64
|
+
throw error;
|
|
65
|
+
}
|
|
66
|
+
const lines = ['', '## Active Issue', '', `#${String(issue.number)} ${issue.title} (${issue.state})`];
|
|
67
|
+
if (issue.body !== '')
|
|
68
|
+
lines.push('', issue.body);
|
|
69
|
+
return { reference, config, client, lines };
|
|
70
|
+
}
|
|
71
|
+
// 積んで着手した作業ディレクトリの `## Stack` の節。積んでいなければ空
|
|
72
|
+
async function stackLines(active, output) {
|
|
73
|
+
const reading = readBaseRecord();
|
|
74
|
+
if (reading.kind === 'malformed')
|
|
75
|
+
output.warning(`.pecot-base is malformed: ${reading.content}`);
|
|
76
|
+
if (reading.kind !== 'stacked')
|
|
77
|
+
return [];
|
|
78
|
+
const { record, stackedOn } = reading;
|
|
79
|
+
const { owner, repository } = stackedOn.repository;
|
|
80
|
+
let pullRequest;
|
|
81
|
+
try {
|
|
82
|
+
const found = await active.client.listPullRequestsByHead(owner, repository, record.branch);
|
|
83
|
+
pullRequest = pickBasePullRequest(found.pullRequests);
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
if (!(error instanceof GitHubAPIError))
|
|
87
|
+
throw error;
|
|
88
|
+
output.warning(`cannot read the PR of the base branch: ${error.message}`);
|
|
89
|
+
pullRequest = 'unknown';
|
|
90
|
+
}
|
|
91
|
+
const readiness = await readinessLines(active, output);
|
|
92
|
+
return ['', '## Stack', describeStackBase(record.branch, stackedOn, pullRequest), ...readiness];
|
|
93
|
+
}
|
|
94
|
+
// 着手中の Issue の判定が blocked のときだけ出す
|
|
95
|
+
async function readinessLines(active, output) {
|
|
96
|
+
const result = await readIssueReadinessIfSupported(active.client, active.config, active.reference, createReadinessCache());
|
|
97
|
+
if (result === undefined)
|
|
98
|
+
return [];
|
|
99
|
+
if (result.kind === 'unreadable') {
|
|
100
|
+
output.warning(`cannot judge readiness of the active Issue: ${result.reason}`);
|
|
101
|
+
return [];
|
|
102
|
+
}
|
|
103
|
+
const { readiness } = result;
|
|
104
|
+
return readiness?.kind === 'blocked' ? [`- readiness: ${describeReadiness(readiness, result.prerequisites, active.reference.repository)}`] : [];
|
|
105
|
+
}
|
|
106
|
+
const SESSION_SHOW = defineCommand({
|
|
107
|
+
path: ['session', 'show'],
|
|
108
|
+
description: 'Show the session flag state, branch information, and inferred Issue',
|
|
109
|
+
input: z.object({ directory: directorySchema }),
|
|
110
|
+
positional: [],
|
|
111
|
+
shortFlags: { directory: '-D' },
|
|
112
|
+
interactive: false,
|
|
113
|
+
run: async (input, io) => {
|
|
114
|
+
const output = createOutput(false, io);
|
|
115
|
+
const branch = gitCurrentBranch(input.directory);
|
|
116
|
+
const origin = primaryRemoteRepository(input.directory);
|
|
117
|
+
const issueNumber = branch === undefined ? undefined : extractIssueNumberFromBranch(branch);
|
|
118
|
+
const statuses = collectFlagStatuses();
|
|
119
|
+
const active = await readActiveIssue(statuses, output);
|
|
120
|
+
const lines = [
|
|
121
|
+
'# Session status',
|
|
122
|
+
'',
|
|
123
|
+
`- Branch: ${branch ?? 'unknown'}`,
|
|
124
|
+
`- Repository: ${origin === undefined ? 'unknown' : `${origin.owner}/${origin.repository}`}`,
|
|
125
|
+
`- Inferred Issue: ${issueNumber === undefined ? 'none' : `#${String(issueNumber)}`}`,
|
|
126
|
+
'',
|
|
127
|
+
'| Flag | State | Content |',
|
|
128
|
+
'|------|-------|---------|',
|
|
129
|
+
...statuses.map(status => `| ${status.name} | ${status.isSet ? 'set' : 'unset'} | ${status.content} |`),
|
|
130
|
+
...active?.lines ?? [],
|
|
131
|
+
...active === undefined ? [] : await stackLines(active, output),
|
|
132
|
+
];
|
|
133
|
+
output.data(lines.join('\n'));
|
|
134
|
+
return 0;
|
|
135
|
+
},
|
|
136
|
+
});
|
|
137
|
+
// セッション名に添える題名。設定が無いか API が失敗したときだけ空にする。設定が読めないなら ConfigError を伝える
|
|
138
|
+
async function fetchIssueTitle(owner, repository, number, output) {
|
|
139
|
+
try {
|
|
140
|
+
const config = loadActiveConfig();
|
|
141
|
+
if (config === undefined)
|
|
142
|
+
return '';
|
|
143
|
+
const issue = await createGitHubClient(output, config.host).getIssueSlim(owner, repository, number, 0);
|
|
144
|
+
return issue.title;
|
|
145
|
+
}
|
|
146
|
+
catch (error) {
|
|
147
|
+
if (error instanceof ConfigError)
|
|
148
|
+
throw error;
|
|
149
|
+
if (error instanceof PecotError)
|
|
150
|
+
return '';
|
|
151
|
+
throw error;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
// issue_ref が無いときの、ブランチ名と remote からの推定。決められなければ error を出して終了コード 1
|
|
155
|
+
function inferTarget(directory, output) {
|
|
156
|
+
const branch = gitCurrentBranch(directory);
|
|
157
|
+
if (branch === undefined) {
|
|
158
|
+
return stopWith(output, 'cannot read the branch name', 'git-unresolved', FAILURE_EXIT_CODE);
|
|
159
|
+
}
|
|
160
|
+
const number = extractIssueNumberFromBranch(branch);
|
|
161
|
+
if (number === undefined) {
|
|
162
|
+
return stopWith(output, hinted `cannot infer the Issue number from the branch name: ${branch}\nrun: ${commandHint(['session', 'restore'], { issue_ref: placeholder('owner/repo/N') })}`, 'git-unresolved', FAILURE_EXIT_CODE);
|
|
163
|
+
}
|
|
164
|
+
const origin = primaryRemoteRepository(directory);
|
|
165
|
+
const message = 'cannot read the repository information';
|
|
166
|
+
return origin === undefined ? stopWith(output, message, 'git-unresolved', FAILURE_EXIT_CODE) : { owner: origin.owner, repository: origin.repository, number };
|
|
167
|
+
}
|
|
168
|
+
// issue_ref の参照を分ける。形が誤っていれば error を出して終了コード 2
|
|
169
|
+
function parseTarget(issue, output) {
|
|
170
|
+
try {
|
|
171
|
+
const reference = parseIssueReference(issue);
|
|
172
|
+
return { owner: reference.repository.owner, repository: reference.repository.repository, number: reference.number };
|
|
173
|
+
}
|
|
174
|
+
catch (error) {
|
|
175
|
+
if (!(error instanceof ReferenceParseError))
|
|
176
|
+
throw error;
|
|
177
|
+
return stopWith(output, error.message, 'invalid-input', USAGE_EXIT_CODE);
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
const SESSION_RESTORE = defineCommand({
|
|
181
|
+
path: ['session', 'restore'],
|
|
182
|
+
description: 'Restore lost session flags (such as .pecot-active) from the branch information',
|
|
183
|
+
input: z.object({
|
|
184
|
+
issue_ref: z.string().optional().describe('Issue reference (owner/repo/number)'),
|
|
185
|
+
directory: directorySchema,
|
|
186
|
+
dry_run: z.boolean().default(false).describe('Show what would be recorded without writing anything'),
|
|
187
|
+
}),
|
|
188
|
+
positional: [],
|
|
189
|
+
shortFlags: { issue_ref: '-i', directory: '-D', dry_run: '-n' },
|
|
190
|
+
interactive: false,
|
|
191
|
+
run: async (input, io) => {
|
|
192
|
+
const output = createOutput(input.dry_run, io);
|
|
193
|
+
const target = input.issue_ref === undefined ? inferTarget(input.directory, output) : parseTarget(input.issue_ref, output);
|
|
194
|
+
let title;
|
|
195
|
+
try {
|
|
196
|
+
title = await fetchIssueTitle(target.owner, target.repository, target.number, output);
|
|
197
|
+
}
|
|
198
|
+
catch (error) {
|
|
199
|
+
if (!(error instanceof ConfigError))
|
|
200
|
+
throw error;
|
|
201
|
+
return stopWith(output, error.message, 'config-invalid', FAILURE_EXIT_CODE);
|
|
202
|
+
}
|
|
203
|
+
if (input.dry_run)
|
|
204
|
+
planWorkTarget(output, target.owner, target.repository, target.number);
|
|
205
|
+
else
|
|
206
|
+
recordWorkTarget(output, target.owner, target.repository, target.number, title, { failWithExit: true });
|
|
207
|
+
return 0;
|
|
208
|
+
},
|
|
209
|
+
});
|
|
210
|
+
/**
|
|
211
|
+
session のグループのコマンド。start は session-start.ts、finish は session-finish.ts にある。並びは help の一覧に出る順
|
|
212
|
+
*/
|
|
213
|
+
export const SESSION_COMMANDS = [...SESSION_START_COMMANDS, SESSION_SHOW, SESSION_RESTORE, ...SESSION_FINISH_COMMANDS];
|
|
214
|
+
//# sourceMappingURL=session.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandIo } from './command-definition.js';
|
|
2
|
+
import type { TrackerSyncInput } from './tracker-sync.js';
|
|
3
|
+
/**
|
|
4
|
+
tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
|
|
5
|
+
*/
|
|
6
|
+
export declare function runDependabotSync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
|
|
7
|
+
//# sourceMappingURL=tracker-sync-dependabot.d.ts.map
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
// `pecot tracker sync dependabot` の本体。移す元は cli/commands/dependabot.py。
|
|
2
|
+
// 判断を待つ dependabot の PR を、open の Tracker の一覧に反映する。載せる PR が無くなったら、一覧を none にして Tracker を閉じる。
|
|
3
|
+
import { buildTrackerTitle, checksLabel, DependabotPrError, parseTrackerPullRequestNumbers, planTracker, PR_LABEL, PRIORITY, renderTrackerBody, rollupState, TRACKER_PATTERN, waitingReasons, } from '../domain/dependabot-pull-requests.js';
|
|
4
|
+
import { jsonField } from '../domain/json.js';
|
|
5
|
+
import { findTracker } from '../domain/tracker-body.js';
|
|
6
|
+
import { requireNumber } from '../infra/github/payload.js';
|
|
7
|
+
import { CommandExit } from './command-definition.js';
|
|
8
|
+
import { stopWith } from './command-stop.js';
|
|
9
|
+
import { kindOfFailure } from './failure.js';
|
|
10
|
+
import { makeClient } from './github-client.js';
|
|
11
|
+
import { createIssue, putOnBoard } from './issue-board.js';
|
|
12
|
+
import { createOutput } from './output.js';
|
|
13
|
+
import { apiErrorDetail, isBodyUnchanged, loadTarget, todayUtc, warnExtraTrackers } from './tracker-sync.js';
|
|
14
|
+
function textOrEmpty(value) {
|
|
15
|
+
return typeof value === 'string' ? value : '';
|
|
16
|
+
}
|
|
17
|
+
function entryOf(pr) {
|
|
18
|
+
const number = jsonField(pr, 'number');
|
|
19
|
+
return {
|
|
20
|
+
number: requireNumber(number, 'number'),
|
|
21
|
+
title: textOrEmpty(jsonField(pr, 'title')),
|
|
22
|
+
url: textOrEmpty(jsonField(pr, 'url')),
|
|
23
|
+
reasons: [],
|
|
24
|
+
checks: checksLabel(rollupState(pr)),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function operationsFor(plan, tracker, title, isUnchanged) {
|
|
28
|
+
if (tracker === undefined) {
|
|
29
|
+
if (!plan.create)
|
|
30
|
+
return { create: [{ verb: 'skip', target: 'Tracker creation' }], rewrite: [], close: [] };
|
|
31
|
+
const created = [{ verb: 'create', target: `Tracker "${title}"` }];
|
|
32
|
+
for (const entry of plan.entries)
|
|
33
|
+
created.push({ verb: 'add', target: `PR #${String(entry.number)} to new Tracker (${entry.reasons.join(', ')})` });
|
|
34
|
+
return { create: created, rewrite: [], close: [] };
|
|
35
|
+
}
|
|
36
|
+
if (isUnchanged && !plan.close)
|
|
37
|
+
return { create: [], rewrite: [{ verb: 'unchanged', target: `Tracker #${String(tracker)}` }], close: [] };
|
|
38
|
+
const rewrite = plan.added.map(entry => ({ verb: 'add', target: `PR #${String(entry.number)} to Tracker #${String(tracker)} (${entry.reasons.join(', ')})` }));
|
|
39
|
+
for (const number of plan.removed)
|
|
40
|
+
rewrite.push({ verb: 'remove', target: `PR #${String(number)} from Tracker #${String(tracker)}` });
|
|
41
|
+
if (!isUnchanged && rewrite.length === 0)
|
|
42
|
+
rewrite.push({ verb: 'update', target: `Tracker #${String(tracker)} body` });
|
|
43
|
+
return { create: [], rewrite, close: plan.close ? [{ verb: 'close', target: `Tracker #${String(tracker)}` }] : [] };
|
|
44
|
+
}
|
|
45
|
+
// Tracker を作る・書き直す・閉じる・ボードに載せる。失敗の数を返す。
|
|
46
|
+
// eslint-disable-next-line @typescript-eslint/prefer-readonly-parameter-types -- GitHubClient は可変
|
|
47
|
+
async function applyChanges(out, input) {
|
|
48
|
+
const { client, config, owner, repository, plan, title, body, stages, number, isUnchanged } = input;
|
|
49
|
+
try {
|
|
50
|
+
if (number === undefined) {
|
|
51
|
+
if (!plan.create) {
|
|
52
|
+
for (const operation of stages.create)
|
|
53
|
+
out.done(operation);
|
|
54
|
+
return 0;
|
|
55
|
+
}
|
|
56
|
+
const issue = await createIssue(client, owner, repository, title, body, [PR_LABEL]);
|
|
57
|
+
for (const operation of stages.create)
|
|
58
|
+
out.done(operation);
|
|
59
|
+
await putOnBoard(client, config, owner, repository, requireNumber(issue['number'], 'number'), PRIORITY, { onlyIfEmpty: false });
|
|
60
|
+
return 0;
|
|
61
|
+
}
|
|
62
|
+
if (!isUnchanged) {
|
|
63
|
+
try {
|
|
64
|
+
await client.updateIssueBody(owner, repository, number, body);
|
|
65
|
+
}
|
|
66
|
+
catch (error) {
|
|
67
|
+
const detail = apiErrorDetail(error);
|
|
68
|
+
if (detail === undefined)
|
|
69
|
+
throw error;
|
|
70
|
+
// 本文が書き直されていないので、閉じずに次の実行でやり直す
|
|
71
|
+
out.error(`could not update Tracker #${String(number)} body: ${detail}`);
|
|
72
|
+
return 1;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
for (const operation of stages.rewrite)
|
|
76
|
+
out.done(operation);
|
|
77
|
+
const [closing] = stages.close;
|
|
78
|
+
if (closing !== undefined) {
|
|
79
|
+
try {
|
|
80
|
+
await client.closeIssue(owner, repository, number, 'completed');
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
const detail = apiErrorDetail(error);
|
|
84
|
+
if (detail === undefined)
|
|
85
|
+
throw error;
|
|
86
|
+
out.error(`could not close Tracker #${String(number)} after setting its list to none; will retry on the next run: ${detail}`);
|
|
87
|
+
return 1;
|
|
88
|
+
}
|
|
89
|
+
out.done(closing);
|
|
90
|
+
return 0;
|
|
91
|
+
}
|
|
92
|
+
// 作った後にボード登録が失敗した実行を直す。Status・Priority は空のときだけ入れる
|
|
93
|
+
await putOnBoard(client, config, owner, repository, number, PRIORITY, { onlyIfEmpty: true });
|
|
94
|
+
return 0;
|
|
95
|
+
}
|
|
96
|
+
catch (error) {
|
|
97
|
+
const detail = apiErrorDetail(error);
|
|
98
|
+
if (detail === undefined)
|
|
99
|
+
throw error;
|
|
100
|
+
out.error(`Tracker: ${detail}`);
|
|
101
|
+
return 1;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
tracker sync の source dependabot の本体。Tracker の Dependabot PRs waiting for a human decision の一覧を書き直す
|
|
106
|
+
*/
|
|
107
|
+
export async function runDependabotSync(input, io) {
|
|
108
|
+
const out = createOutput(input.dry_run, io);
|
|
109
|
+
const { config, owner, repository } = loadTarget(out, input.repo);
|
|
110
|
+
const client = makeClient(out, config);
|
|
111
|
+
let pullRequests;
|
|
112
|
+
let issues;
|
|
113
|
+
try {
|
|
114
|
+
pullRequests = await client.listOpenDependabotPullRequests(owner, repository);
|
|
115
|
+
issues = await client.listIssuesByLabel(owner, repository, PR_LABEL);
|
|
116
|
+
}
|
|
117
|
+
catch (error) {
|
|
118
|
+
const detail = apiErrorDetail(error);
|
|
119
|
+
if (detail === undefined)
|
|
120
|
+
throw error;
|
|
121
|
+
return stopWith(out, `could not list pull requests or issues: ${detail}`, kindOfFailure(error));
|
|
122
|
+
}
|
|
123
|
+
const { tracker, others } = findTracker(issues, TRACKER_PATTERN);
|
|
124
|
+
warnExtraTrackers(out, tracker, others);
|
|
125
|
+
const existingBody = tracker?.body;
|
|
126
|
+
let oldNumbers;
|
|
127
|
+
try {
|
|
128
|
+
oldNumbers = tracker === undefined ? undefined : parseTrackerPullRequestNumbers(existingBody);
|
|
129
|
+
}
|
|
130
|
+
catch (error) {
|
|
131
|
+
if (tracker === undefined || !(error instanceof DependabotPrError))
|
|
132
|
+
throw error;
|
|
133
|
+
return stopWith(out, `Tracker #${String(tracker.number)}: ${error.message}`, 'content-invalid');
|
|
134
|
+
}
|
|
135
|
+
const now = new Date();
|
|
136
|
+
const nodes = pullRequests;
|
|
137
|
+
const waiting = nodes.map(node => ({ node, reasons: waitingReasons(node, now) })).filter(item => item.reasons.length > 0);
|
|
138
|
+
out.count('open dependabot PRs', nodes.length);
|
|
139
|
+
out.count('PRs awaiting a decision', waiting.length);
|
|
140
|
+
out.count('PRs awaiting a decision without check results', waiting.filter(item => rollupState(item.node) === undefined).length);
|
|
141
|
+
const plan = planTracker(waiting.map(item => ({ ...entryOf(item.node), reasons: item.reasons })), oldNumbers);
|
|
142
|
+
const title = buildTrackerTitle(todayUtc(now));
|
|
143
|
+
const body = renderTrackerBody(plan.entries, existingBody);
|
|
144
|
+
const number = tracker?.number;
|
|
145
|
+
const isUnchanged = isBodyUnchanged(body, existingBody);
|
|
146
|
+
const stages = operationsFor(plan, number, title, isUnchanged);
|
|
147
|
+
for (const operation of [...stages.create, ...stages.rewrite, ...stages.close])
|
|
148
|
+
out.planned(operation);
|
|
149
|
+
if (input.dry_run)
|
|
150
|
+
return 0;
|
|
151
|
+
const failures = await applyChanges(out, { client, config, owner, repository, plan, title, body, stages, number, isUnchanged });
|
|
152
|
+
if (failures > 0)
|
|
153
|
+
throw new CommandExit(1, 'partial-failure');
|
|
154
|
+
return 0;
|
|
155
|
+
}
|
|
156
|
+
//# sourceMappingURL=tracker-sync-dependabot.js.map
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { CommandIo } from './command-definition.js';
|
|
2
|
+
import type { TrackerSyncInput } from './tracker-sync.js';
|
|
3
|
+
/**
|
|
4
|
+
tracker sync の source security の本体。Tracker の open security alerts の一覧を書き直す
|
|
5
|
+
*/
|
|
6
|
+
export declare function runSecuritySync(input: Readonly<TrackerSyncInput>, io: CommandIo): Promise<0>;
|
|
7
|
+
//# sourceMappingURL=tracker-sync-security.d.ts.map
|