@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,282 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/prefer-readonly-parameter-types -- 引数の型は readonly にできない */
|
|
2
|
+
// issue block / unblock。既存の Issue の前提(blocked by)と種類(stack / merge)を後から直し、判定・列・札・本文の節をそろえる。
|
|
3
|
+
import { z } from 'zod';
|
|
4
|
+
import { hasExpectedPrerequisites, decideBlock, decideUnblock, searchCycle } from '../domain/blocked-by-change.js';
|
|
5
|
+
import { decideBoardMove } from '../domain/board-move.js';
|
|
6
|
+
import { getOptionId } from '../domain/config.js';
|
|
7
|
+
import { describeReadiness, displayReference, hasStarted } from '../domain/readiness.js';
|
|
8
|
+
import { createIssueReference, issueReferenceKey } from '../domain/reference-parser.js';
|
|
9
|
+
import { createRepositoryReference } from '../domain/repository-resolver.js';
|
|
10
|
+
import { MAX_BLOCKED_BY } from '../infra/github/issues.js';
|
|
11
|
+
import { defineCommand } from './command-definition.js';
|
|
12
|
+
import { commandHint, hinted, inputHint, inputNameHint, joinHinted } from './command-hint.js';
|
|
13
|
+
import { requireActiveConfigPlain, stopWith } from './command-stop.js';
|
|
14
|
+
import { kindOfFailure } from './failure.js';
|
|
15
|
+
import { apiFailureMessage, createGitHubClient } from './github-client.js';
|
|
16
|
+
import { applyBoardMove } from './issue-board.js';
|
|
17
|
+
import { createReadinessCache, readIssueReadiness } from './issue-readiness.js';
|
|
18
|
+
import { ensureRepositoryInProject, ISSUE_REF_DESCRIPTION, parseIssueReferenceOrExit, runWithExit } from './issue-shared.js';
|
|
19
|
+
import { createOutput } from './output.js';
|
|
20
|
+
import { USAGE_EXIT_CODE } from './usage-error.js';
|
|
21
|
+
const CONTENT_EXIT_CODE = 3;
|
|
22
|
+
// たどる Issue の数の上限。大きな連鎖で止まらないことより、確かめずに付けないことを優先する
|
|
23
|
+
const MAX_CYCLE_ISSUES = 200;
|
|
24
|
+
const BLOCK_PATH = ['issue', 'block'];
|
|
25
|
+
function toReference(target) {
|
|
26
|
+
return createIssueReference(createRepositoryReference(target.owner, target.repository), target.number);
|
|
27
|
+
}
|
|
28
|
+
async function ensureLinked(out, config, client, { owner, repository }) {
|
|
29
|
+
await ensureRepositoryInProject(out, config, client, owner, repository, `repository ${owner}/${repository} is not in the project`);
|
|
30
|
+
}
|
|
31
|
+
async function wrapped(out, context, run) {
|
|
32
|
+
try {
|
|
33
|
+
return await run();
|
|
34
|
+
}
|
|
35
|
+
catch (error) {
|
|
36
|
+
return stopWith(out, `${context}: ${apiFailureMessage(error)}`, kindOfFailure(error));
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
function isOptionAvailable(config, field, key) {
|
|
40
|
+
const option = getOptionId(config, field, key);
|
|
41
|
+
return option !== undefined && option !== '';
|
|
42
|
+
}
|
|
43
|
+
function hintFor(value) {
|
|
44
|
+
return hinted `hint: run ${commandHint(['project', 'init'])} to add the ${value} option to the board`;
|
|
45
|
+
}
|
|
46
|
+
function boardMoveInput(judged, config, hasPrerequisites) {
|
|
47
|
+
const { target } = judged;
|
|
48
|
+
return {
|
|
49
|
+
eligible: target.state === 'open' && target.kind === 'task',
|
|
50
|
+
column: target.column,
|
|
51
|
+
label: target.label,
|
|
52
|
+
hasStarted: hasStarted(target),
|
|
53
|
+
hasPrerequisites,
|
|
54
|
+
readiness: judged.readiness,
|
|
55
|
+
// spec 023 が入るまで、札はこの機能が書いたものとして扱う
|
|
56
|
+
labelWrittenByAutomation: false,
|
|
57
|
+
available: {
|
|
58
|
+
blocked: isOptionAvailable(config, 'workflow', 'blocked'),
|
|
59
|
+
needsAttention: isOptionAvailable(config, 'status', 'needs_attention'),
|
|
60
|
+
todo: isOptionAvailable(config, 'status', 'todo'),
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
// 書いた内容が読み直しに出るまで 1 回だけ読み直す。GitHub は書いた直後の読み取りの一致を保証しない
|
|
65
|
+
async function readConfirmed(context, expected) {
|
|
66
|
+
const name = displayReference(context.target, context.home);
|
|
67
|
+
for (let attempt = 0; attempt < 2; attempt += 1) {
|
|
68
|
+
const result = await readIssueReadiness(context.client, context.config, context.target, createReadinessCache());
|
|
69
|
+
if (result.kind === 'unreadable')
|
|
70
|
+
return { failure: `could not judge readiness of ${name}: ${result.reason}` };
|
|
71
|
+
if (hasExpectedPrerequisites(result.prerequisites, expected))
|
|
72
|
+
return { judged: result };
|
|
73
|
+
}
|
|
74
|
+
return { failure: `could not confirm that GitHub reflects the blocked-by change of ${name}` };
|
|
75
|
+
}
|
|
76
|
+
// 書いた後の判定で、列と札を動かす。読めない・確かめられないときは動かさず warning にする(前提の変更は済んでいる)
|
|
77
|
+
async function moveBoard(context, expected, hasPrerequisites) {
|
|
78
|
+
const { out, client, config, home, target } = context;
|
|
79
|
+
const name = displayReference(target, home);
|
|
80
|
+
const read = await readConfirmed(context, expected);
|
|
81
|
+
if ('failure' in read) {
|
|
82
|
+
out.warning(`${read.failure}; the column and label of ${name} were not moved`);
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
const { judged } = read;
|
|
86
|
+
if (judged.readiness === undefined)
|
|
87
|
+
return;
|
|
88
|
+
const move = decideBoardMove(boardMoveInput(judged, config, hasPrerequisites));
|
|
89
|
+
if (move === undefined)
|
|
90
|
+
return;
|
|
91
|
+
const hasWrite = move.column !== undefined || move.label !== undefined;
|
|
92
|
+
let itemId = '';
|
|
93
|
+
try {
|
|
94
|
+
if (hasWrite)
|
|
95
|
+
itemId = await client.getItemIdByIssue(config.project.id, target.repository.owner, target.repository.repository, target.number) ?? '';
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
98
|
+
out.warning(`could not move ${name}: ${apiFailureMessage(error)}`);
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
if (hasWrite && itemId === '')
|
|
102
|
+
return;
|
|
103
|
+
const { missing } = await applyBoardMove(out, client, config, itemId, { ref: target, home }, move, describeReadiness(judged.readiness, judged.prerequisites, home));
|
|
104
|
+
for (const value of missing) {
|
|
105
|
+
out.warning(joinHinted([`the ${value} option is not on the board, so ${name} was not moved`, hintFor(value)]));
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
function keysOf(issues) {
|
|
109
|
+
return new Set(issues.map(issue => issueReferenceKey({ repository: issue.repository, number: issue.number })));
|
|
110
|
+
}
|
|
111
|
+
function checkBlockUsage(out, input, target, by) {
|
|
112
|
+
const reason = input.reason?.trim();
|
|
113
|
+
const reasonFlag = inputNameHint(BLOCK_PATH, 'reason');
|
|
114
|
+
const waitMerge = inputHint(BLOCK_PATH, 'wait', 'merge');
|
|
115
|
+
if (input.wait === 'merge' && (reason === undefined || reason === ''))
|
|
116
|
+
stopWith(out, hinted `${reasonFlag} is required with ${waitMerge}`, 'invalid-input', USAGE_EXIT_CODE);
|
|
117
|
+
if (input.wait === 'stack' && input.reason !== undefined)
|
|
118
|
+
stopWith(out, hinted `${reasonFlag} is only valid with ${waitMerge}`, 'invalid-input', USAGE_EXIT_CODE);
|
|
119
|
+
if (reason !== undefined && /[\r\n]/u.test(reason))
|
|
120
|
+
stopWith(out, hinted `${reasonFlag} must be a single line`, 'invalid-input', USAGE_EXIT_CODE);
|
|
121
|
+
if (issueReferenceKey(target) === issueReferenceKey(by)) {
|
|
122
|
+
const name = displayReference(target, target.repository);
|
|
123
|
+
stopWith(out, `blocked-by would form a cycle: ${name} -> ${name}`, 'dependency-rejected', USAGE_EXIT_CODE);
|
|
124
|
+
}
|
|
125
|
+
return reason;
|
|
126
|
+
}
|
|
127
|
+
async function checkNoCycle(context, byId) {
|
|
128
|
+
const { out, client, target, home } = context;
|
|
129
|
+
const result = await wrapped(out, `could not check blocked-by cycle of ${displayReference(target, home)}`, async () => await searchCycle({
|
|
130
|
+
target,
|
|
131
|
+
by: context.by,
|
|
132
|
+
byId,
|
|
133
|
+
read: async (ids) => await client.getBlockedByOfNodes(ids),
|
|
134
|
+
limit: MAX_CYCLE_ISSUES,
|
|
135
|
+
}));
|
|
136
|
+
if (result.kind === 'cycle')
|
|
137
|
+
stopWith(out, `blocked-by would form a cycle: ${result.path.map(reference => displayReference(reference, home)).join(' -> ')}`, 'dependency-rejected', USAGE_EXIT_CODE);
|
|
138
|
+
else if (result.kind === 'unverifiable')
|
|
139
|
+
stopWith(out, `could not check blocked-by cycle of ${displayReference(target, home)}: ${result.reason}`, 'dependency-unreadable');
|
|
140
|
+
}
|
|
141
|
+
async function runBlock(out, input) {
|
|
142
|
+
const config = requireActiveConfigPlain(out);
|
|
143
|
+
const targetIssue = parseIssueReferenceOrExit(out, input.repo, input.issue_ref);
|
|
144
|
+
const byIssue = parseIssueReferenceOrExit(out, input.repo, input.by);
|
|
145
|
+
const target = toReference(targetIssue);
|
|
146
|
+
const by = toReference(byIssue);
|
|
147
|
+
const reason = checkBlockUsage(out, input, target, by);
|
|
148
|
+
const client = createGitHubClient(out, config.host);
|
|
149
|
+
await ensureLinked(out, config, client, targetIssue);
|
|
150
|
+
const home = target.repository;
|
|
151
|
+
const context = { out, client, config, home, target, by };
|
|
152
|
+
const name = displayReference(target, home);
|
|
153
|
+
const byName = displayReference(by, home);
|
|
154
|
+
const read = await wrapped(out, `could not read blocked-by of ${name}`, async () => await client.getIssueBlockedByReferences(targetIssue.owner, targetIssue.repository, targetIssue.number));
|
|
155
|
+
if (read.blockedBy.kind === 'read-failed')
|
|
156
|
+
stopWith(out, `could not read blocked-by of ${name}: ${read.blockedBy.reason}`, 'dependency-unreadable');
|
|
157
|
+
const { issues, total } = read.blockedBy;
|
|
158
|
+
const linked = issues.find(issue => issueReferenceKey({ repository: issue.repository, number: issue.number }) === issueReferenceKey(by));
|
|
159
|
+
if (linked === undefined && total >= MAX_BLOCKED_BY)
|
|
160
|
+
stopWith(out, `${name} already has ${String(MAX_BLOCKED_BY)} blocked-by issues`, 'dependency-rejected');
|
|
161
|
+
const decision = decideBlock({ body: read.body, home, by, wait: input.wait, reason, isLinked: linked !== undefined });
|
|
162
|
+
if (decision.kind === 'malformed') {
|
|
163
|
+
stopWith(out, `Waits for merge of ${name} is malformed: ${decision.reason}; fix the section in the Issue body and run the command again`, 'content-invalid', CONTENT_EXIT_CODE);
|
|
164
|
+
}
|
|
165
|
+
else if (decision.kind === 'unchanged') {
|
|
166
|
+
out.planned({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
|
|
167
|
+
out.done({ verb: 'unchanged', target: `blocked-by ${byName} on ${name}` });
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
let byId = linked?.id;
|
|
171
|
+
if (decision.kind === 'add') {
|
|
172
|
+
byId = await wrapped(out, `could not read ${displayReference(by, home)}`, async () => await client.getIssueNodeId(byIssue.owner, byIssue.repository, byIssue.number));
|
|
173
|
+
await checkNoCycle(context, byId);
|
|
174
|
+
}
|
|
175
|
+
const operation = decision.kind === 'add'
|
|
176
|
+
? { verb: 'add', target: `blocked-by ${byName} to ${name}` }
|
|
177
|
+
: { verb: 'update', target: `blocked-by ${byName} on ${name} (wait: ${input.wait})` };
|
|
178
|
+
out.planned(operation);
|
|
179
|
+
if (input.dry_run)
|
|
180
|
+
return;
|
|
181
|
+
if (byId !== undefined && decision.kind === 'add') {
|
|
182
|
+
const blockingId = byId;
|
|
183
|
+
await wrapped(out, `could not add blocked-by ${byName} to ${name}`, async () => {
|
|
184
|
+
await client.addBlockedBy(read.id, blockingId);
|
|
185
|
+
});
|
|
186
|
+
out.done(operation);
|
|
187
|
+
}
|
|
188
|
+
if (decision.body !== read.body) {
|
|
189
|
+
const message = `could not update the body of ${name}${decision.kind === 'add' ? `; blocked-by ${byName} was added, run the command again to write the section` : ''}`;
|
|
190
|
+
await wrapped(out, message, async () => {
|
|
191
|
+
await client.updateIssueBody(targetIssue.owner, targetIssue.repository, targetIssue.number, decision.body);
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
if (decision.kind === 'update')
|
|
195
|
+
out.done(operation);
|
|
196
|
+
const keys = new Set([...keysOf(issues), issueReferenceKey(by)]);
|
|
197
|
+
await moveBoard(context, { keys, by, wait: { wait: input.wait, reason } }, true);
|
|
198
|
+
}
|
|
199
|
+
async function runUnblock(out, input) {
|
|
200
|
+
const config = requireActiveConfigPlain(out);
|
|
201
|
+
const targetIssue = parseIssueReferenceOrExit(out, input.repo, input.issue_ref);
|
|
202
|
+
const byIssue = parseIssueReferenceOrExit(out, input.repo, input.by);
|
|
203
|
+
const target = toReference(targetIssue);
|
|
204
|
+
const by = toReference(byIssue);
|
|
205
|
+
const client = createGitHubClient(out, config.host);
|
|
206
|
+
await ensureLinked(out, config, client, targetIssue);
|
|
207
|
+
const home = target.repository;
|
|
208
|
+
const context = { out, client, config, home, target, by };
|
|
209
|
+
const name = displayReference(target, home);
|
|
210
|
+
const byName = displayReference(by, home);
|
|
211
|
+
const read = await wrapped(out, `could not read blocked-by of ${name}`, async () => await client.getIssueBlockedByReferences(targetIssue.owner, targetIssue.repository, targetIssue.number));
|
|
212
|
+
if (read.blockedBy.kind === 'read-failed')
|
|
213
|
+
stopWith(out, `could not read blocked-by of ${name}: ${read.blockedBy.reason}`, 'dependency-unreadable');
|
|
214
|
+
const { issues, total } = read.blockedBy;
|
|
215
|
+
const linked = issues.find(issue => issueReferenceKey({ repository: issue.repository, number: issue.number }) === issueReferenceKey(by));
|
|
216
|
+
if (linked === undefined && total > issues.length)
|
|
217
|
+
stopWith(out, `could not read blocked-by of ${name}: ${String(issues.length)} of ${String(total)} issues were read`, 'dependency-unreadable');
|
|
218
|
+
const decision = decideUnblock({ body: read.body, home, by, isLinked: linked !== undefined });
|
|
219
|
+
if (linked === undefined || decision.kind === 'unchanged') {
|
|
220
|
+
out.planned({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
|
|
221
|
+
out.done({ verb: 'unchanged', target: `${name} is not blocked by ${byName}` });
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
const operation = { verb: 'remove', target: `blocked-by ${byName} from ${name}` };
|
|
225
|
+
out.planned(operation);
|
|
226
|
+
if (input.dry_run)
|
|
227
|
+
return;
|
|
228
|
+
await wrapped(out, `could not remove blocked-by ${byName} from ${name}`, async () => {
|
|
229
|
+
await client.removeBlockedBy(read.id, linked.id);
|
|
230
|
+
});
|
|
231
|
+
out.done(operation);
|
|
232
|
+
if (decision.malformedReason !== undefined) {
|
|
233
|
+
out.warning(`Waits for merge of ${name} is malformed: ${decision.malformedReason}; the section was not changed`);
|
|
234
|
+
}
|
|
235
|
+
else if (decision.body !== read.body) {
|
|
236
|
+
await wrapped(out, `could not update the body of ${name}; blocked-by ${byName} was removed`, async () => {
|
|
237
|
+
await client.updateIssueBody(targetIssue.owner, targetIssue.repository, targetIssue.number, decision.body);
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
const remaining = issues.filter(issue => issue.id !== linked.id);
|
|
241
|
+
// 人が別の理由で付けた札を、最後の前提を外しただけで戻さない
|
|
242
|
+
const hasPrerequisites = remaining.length > 0 || linked.state === 'CLOSED';
|
|
243
|
+
await moveBoard(context, { keys: keysOf(remaining), by, wait: undefined }, hasPrerequisites);
|
|
244
|
+
}
|
|
245
|
+
const ISSUE_BLOCK = defineCommand({
|
|
246
|
+
path: BLOCK_PATH,
|
|
247
|
+
description: 'Add a blocked-by (prerequisite) to an Issue, or change the wait kind and reason of an existing one',
|
|
248
|
+
input: z.object({
|
|
249
|
+
issue_ref: z.string().describe(`The waiting Issue. ${ISSUE_REF_DESCRIPTION}`),
|
|
250
|
+
by: z.string().describe('The Issue to wait for (`owner/repo/N`; another repository is allowed)'),
|
|
251
|
+
wait: z.enum(['stack', 'merge']).default('stack').describe('stack (build on its branch) or merge (wait until it is merged)'),
|
|
252
|
+
reason: z.string().optional().describe('Why it waits for the merge (required with --wait merge)'),
|
|
253
|
+
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
254
|
+
}),
|
|
255
|
+
positional: ['issue_ref'],
|
|
256
|
+
interactive: false,
|
|
257
|
+
run: async (input, io) => {
|
|
258
|
+
const out = createOutput(input.dry_run, io);
|
|
259
|
+
return await runWithExit(async () => {
|
|
260
|
+
await runBlock(out, input);
|
|
261
|
+
});
|
|
262
|
+
},
|
|
263
|
+
});
|
|
264
|
+
const ISSUE_UNBLOCK = defineCommand({
|
|
265
|
+
path: ['issue', 'unblock'],
|
|
266
|
+
description: 'Remove a blocked-by (prerequisite) from an Issue',
|
|
267
|
+
input: z.object({
|
|
268
|
+
issue_ref: z.string().describe(`The waiting Issue. ${ISSUE_REF_DESCRIPTION}`),
|
|
269
|
+
by: z.string().describe('The prerequisite Issue to remove (`owner/repo/N`; another repository is allowed)'),
|
|
270
|
+
dry_run: z.boolean().default(false).describe('Show what would change without writing anything'),
|
|
271
|
+
}),
|
|
272
|
+
positional: ['issue_ref'],
|
|
273
|
+
interactive: false,
|
|
274
|
+
run: async (input, io) => {
|
|
275
|
+
const out = createOutput(input.dry_run, io);
|
|
276
|
+
return await runWithExit(async () => {
|
|
277
|
+
await runUnblock(out, input);
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
});
|
|
281
|
+
export const ISSUE_DEPENDENCY_COMMANDS = [ISSUE_BLOCK, ISSUE_UNBLOCK];
|
|
282
|
+
//# sourceMappingURL=issue-dependency.js.map
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import type { ProjectConfig } from '../domain/config.js';
|
|
2
|
+
import type { JsonObject } from '../domain/json.js';
|
|
3
|
+
import type { FactsMismatch, IssueFacts, IssuePullRequest, Prerequisite, Readiness } from '../domain/readiness.js';
|
|
4
|
+
import type { IssueReference } from '../domain/reference-parser.js';
|
|
5
|
+
import type { GitHubClient } from '../infra/github/index.js';
|
|
6
|
+
/**
|
|
7
|
+
一覧の前提の件数から、個別に読む前提の件数を決める。件数が一覧に無ければ undefined(上限で読む)
|
|
8
|
+
*/
|
|
9
|
+
export declare function blockedByReadCount(listed: number | undefined): number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
head のブランチ名で引いた PR の取得結果を、1 回の実行の中で使い回す入れ物。キーは `owner/repo:head`
|
|
12
|
+
*/
|
|
13
|
+
export type ReadinessCache = Map<string, Promise<IssuePullRequest | undefined>>;
|
|
14
|
+
export declare function createReadinessCache(): ReadinessCache;
|
|
15
|
+
/**
|
|
16
|
+
前提まで読んだ Issue。判定の前の段階で、輪の検出に使う辺を取り出せる
|
|
17
|
+
*/
|
|
18
|
+
export interface IssueSnapshot {
|
|
19
|
+
readonly kind: 'snapshot';
|
|
20
|
+
readonly ref: IssueReference;
|
|
21
|
+
readonly title: string;
|
|
22
|
+
readonly target: IssueFacts;
|
|
23
|
+
/**
|
|
24
|
+
読めた前提。blockedBy の読み取りが失敗した Issue は、ここまで来ずに読めない理由で返る
|
|
25
|
+
*/
|
|
26
|
+
readonly prerequisites: readonly Prerequisite[];
|
|
27
|
+
/**
|
|
28
|
+
前提の title(issueReferenceKey → title)
|
|
29
|
+
*/
|
|
30
|
+
readonly titles: ReadonlyMap<string, string>;
|
|
31
|
+
readonly mismatches: readonly FactsMismatch[];
|
|
32
|
+
/**
|
|
33
|
+
本文の `## Waits for merge` の節が読めないときの理由
|
|
34
|
+
*/
|
|
35
|
+
readonly malformedReason: string | undefined;
|
|
36
|
+
readonly parent: IssueReference | undefined;
|
|
37
|
+
/**
|
|
38
|
+
対象のリポジトリの develop_branch。未設定なら undefined
|
|
39
|
+
*/
|
|
40
|
+
readonly developmentBranch: string | undefined;
|
|
41
|
+
}
|
|
42
|
+
export interface UnreadableIssue {
|
|
43
|
+
readonly kind: 'unreadable';
|
|
44
|
+
readonly reason: string;
|
|
45
|
+
/**
|
|
46
|
+
前提まで読めていたときの読み取り結果。判定だけが読めなかった(develop_branch が無い、PR の引き足しに失敗した)ときに付く
|
|
47
|
+
*/
|
|
48
|
+
readonly snapshot?: IssueSnapshot;
|
|
49
|
+
}
|
|
50
|
+
export interface JudgedIssue extends Omit<IssueSnapshot, 'developmentBranch' | 'kind'> {
|
|
51
|
+
readonly kind: 'judged';
|
|
52
|
+
/**
|
|
53
|
+
Epic と Tracker は undefined
|
|
54
|
+
*/
|
|
55
|
+
readonly readiness: Readiness | undefined;
|
|
56
|
+
}
|
|
57
|
+
export type IssueReadiness = JudgedIssue | UnreadableIssue;
|
|
58
|
+
/**
|
|
59
|
+
対象の Issue と前提を読む。API の失敗と blockedBy の読み取りの失敗は、読めない理由で返す。
|
|
60
|
+
DependenciesUnsupportedError は GitHubAPIError だが、対応しない GHES を呼ぶ側で見分けるため、そのまま投げる
|
|
61
|
+
*/
|
|
62
|
+
export declare function readIssueSnapshot(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, blockedByFirst?: number): Promise<IssueSnapshot | UnreadableIssue>;
|
|
63
|
+
/**
|
|
64
|
+
前提の無い Issue の読み取り結果。一覧の値から作るので、API は呼ばない
|
|
65
|
+
*/
|
|
66
|
+
export declare function snapshotWithoutPrerequisites(config: ProjectConfig, input: {
|
|
67
|
+
readonly title: string;
|
|
68
|
+
readonly target: IssueFacts;
|
|
69
|
+
readonly parent: IssueReference | undefined;
|
|
70
|
+
}): IssueSnapshot;
|
|
71
|
+
/**
|
|
72
|
+
Issue の前提の辺(対象のキー → 前提のキー)。輪の検出に使う
|
|
73
|
+
*/
|
|
74
|
+
export declare function prerequisiteKeys(snapshot: Readonly<IssueSnapshot>): readonly string[];
|
|
75
|
+
/**
|
|
76
|
+
前提を判定する。cycle は呼ぶ側が findCycle で求めた輪。
|
|
77
|
+
develop_branch が無いときと、PR の引き足しの API が失敗したときは、読み取り結果を添えた unreadable を返す。
|
|
78
|
+
DependenciesUnsupportedError はそのまま投げる。
|
|
79
|
+
前提の PR が開発ブランチに届かないときだけ、base のブランチを head に持つ PR を引き足して、判定をやり直す
|
|
80
|
+
*/
|
|
81
|
+
export declare function judgeSnapshot(client: Readonly<GitHubClient>, snapshot: Readonly<IssueSnapshot>, cache: ReadinessCache, cycle?: readonly string[]): Promise<IssueReadiness>;
|
|
82
|
+
/**
|
|
83
|
+
Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
|
|
84
|
+
*/
|
|
85
|
+
export declare function readIssueReadiness(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, cache: ReadinessCache, cycle?: readonly string[], blockedByFirst?: number): Promise<IssueReadiness>;
|
|
86
|
+
/**
|
|
87
|
+
JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
|
|
88
|
+
*/
|
|
89
|
+
export declare function readinessJson(readiness: Readonly<Readiness>, text: string): JsonObject;
|
|
90
|
+
/**
|
|
91
|
+
readIssueReadiness の、依存関係を持たない GHES を判定なしで通す形。GHES なら undefined を返し、onUnsupported に理由を渡す
|
|
92
|
+
*/
|
|
93
|
+
export declare function readIssueReadinessIfSupported(client: Readonly<GitHubClient>, config: ProjectConfig, reference: IssueReference, cache: ReadinessCache, onUnsupported?: (reason: string) => void): Promise<IssueReadiness | undefined>;
|
|
94
|
+
//# sourceMappingURL=issue-readiness.d.ts.map
|
|
@@ -0,0 +1,218 @@
|
|
|
1
|
+
// Issue の着手の可否の読み取り。前提を読み、判定する。board show と issue show が使う。
|
|
2
|
+
// 流れは getIssuePrerequisites → readWaitsForMerge → toIssueFacts → judgeReadiness。
|
|
3
|
+
import { findRepository, workflowFieldName } from '../domain/config.js';
|
|
4
|
+
import { JSON_NULL } from '../domain/json-null.js';
|
|
5
|
+
import { readWaitsForMerge } from '../domain/prerequisites.js';
|
|
6
|
+
import { judgeReadiness, toIssueFacts } from '../domain/readiness.js';
|
|
7
|
+
import { issueReferenceKey } from '../domain/reference-parser.js';
|
|
8
|
+
import { repositoryFullName } from '../domain/repository-resolver.js';
|
|
9
|
+
import { DependenciesUnsupportedError, GitHubAPIError } from '../infra/github/errors.js';
|
|
10
|
+
import { MAX_BLOCKED_BY } from '../infra/github/issues.js';
|
|
11
|
+
import { STATUS_FIELD_NAME } from './project-sync.js';
|
|
12
|
+
/**
|
|
13
|
+
順 8 で base をたどる段数の上限
|
|
14
|
+
*/
|
|
15
|
+
const MAX_STACK_TRACE_STEPS = 10;
|
|
16
|
+
/**
|
|
17
|
+
前提を読む件数の下限。一覧を読んでから足された前提も取りこぼさない
|
|
18
|
+
*/
|
|
19
|
+
const MIN_BLOCKED_BY_READ = 8;
|
|
20
|
+
/**
|
|
21
|
+
一覧の前提の件数から、個別に読む前提の件数を決める。件数が一覧に無ければ undefined(上限で読む)
|
|
22
|
+
*/
|
|
23
|
+
export function blockedByReadCount(listed) {
|
|
24
|
+
return listed === undefined ? undefined : Math.min(Math.max(listed, MIN_BLOCKED_BY_READ), MAX_BLOCKED_BY);
|
|
25
|
+
}
|
|
26
|
+
export function createReadinessCache() {
|
|
27
|
+
return new Map();
|
|
28
|
+
}
|
|
29
|
+
function unreadable(reason, snapshot) {
|
|
30
|
+
return snapshot === undefined ? { kind: 'unreadable', reason } : { kind: 'unreadable', reason, snapshot };
|
|
31
|
+
}
|
|
32
|
+
function titlesOf(readout) {
|
|
33
|
+
return readout.blockedBy.kind === 'ok' ? new Map(readout.blockedBy.issues.map(issue => [issueReferenceKey({ repository: issue.repository, number: issue.number }), issue.title])) : new Map();
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
対象の Issue と前提を読む。API の失敗と blockedBy の読み取りの失敗は、読めない理由で返す。
|
|
37
|
+
DependenciesUnsupportedError は GitHubAPIError だが、対応しない GHES を呼ぶ側で見分けるため、そのまま投げる
|
|
38
|
+
*/
|
|
39
|
+
export async function readIssueSnapshot(client, config, reference, blockedByFirst) {
|
|
40
|
+
const { owner, repository } = reference.repository;
|
|
41
|
+
let readout;
|
|
42
|
+
try {
|
|
43
|
+
readout = await client.getIssuePrerequisites(owner, repository, reference.number, config.project.id, {
|
|
44
|
+
columnFieldName: workflowFieldName(config),
|
|
45
|
+
labelFieldName: STATUS_FIELD_NAME,
|
|
46
|
+
}, blockedByFirst);
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
if (error instanceof GitHubAPIError && !(error instanceof DependenciesUnsupportedError))
|
|
50
|
+
return unreadable(error.message);
|
|
51
|
+
throw error;
|
|
52
|
+
}
|
|
53
|
+
const section = readWaitsForMerge(readout.issue.body, reference.repository);
|
|
54
|
+
const result = toIssueFacts(readout, section, { columnFieldName: workflowFieldName(config), labelFieldName: STATUS_FIELD_NAME });
|
|
55
|
+
if (result.prerequisites === 'read-failed') {
|
|
56
|
+
return unreadable(readout.blockedBy.kind === 'read-failed' ? readout.blockedBy.reason : 'could not read blocked-by');
|
|
57
|
+
}
|
|
58
|
+
const { parent } = readout.issue;
|
|
59
|
+
return {
|
|
60
|
+
kind: 'snapshot',
|
|
61
|
+
ref: reference,
|
|
62
|
+
title: readout.issue.title,
|
|
63
|
+
target: result.target,
|
|
64
|
+
prerequisites: result.prerequisites,
|
|
65
|
+
titles: titlesOf(readout),
|
|
66
|
+
mismatches: result.mismatches,
|
|
67
|
+
malformedReason: section.kind === 'malformed' ? section.reason : undefined,
|
|
68
|
+
parent: parent === null ? undefined : { repository: parent.repository, number: parent.number },
|
|
69
|
+
developmentBranch: findRepository(config, owner, repository)?.develop_branch,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
前提の無い Issue の読み取り結果。一覧の値から作るので、API は呼ばない
|
|
74
|
+
*/
|
|
75
|
+
export function snapshotWithoutPrerequisites(config, input) {
|
|
76
|
+
const { repository } = input.target.ref;
|
|
77
|
+
return {
|
|
78
|
+
kind: 'snapshot',
|
|
79
|
+
ref: input.target.ref,
|
|
80
|
+
title: input.title,
|
|
81
|
+
target: input.target,
|
|
82
|
+
prerequisites: [],
|
|
83
|
+
titles: new Map(),
|
|
84
|
+
mismatches: [],
|
|
85
|
+
malformedReason: undefined,
|
|
86
|
+
parent: input.parent,
|
|
87
|
+
developmentBranch: findRepository(config, repository.owner, repository.repository)?.develop_branch,
|
|
88
|
+
};
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
Issue の前提の辺(対象のキー → 前提のキー)。輪の検出に使う
|
|
92
|
+
*/
|
|
93
|
+
export function prerequisiteKeys(snapshot) {
|
|
94
|
+
return snapshot.prerequisites.map(({ issue }) => issueReferenceKey(issue.ref));
|
|
95
|
+
}
|
|
96
|
+
function toIssuePullRequest(readout) {
|
|
97
|
+
return {
|
|
98
|
+
repository: readout.repository,
|
|
99
|
+
number: readout.number,
|
|
100
|
+
state: readout.state === 'OPEN' ? 'open' : (readout.state === 'MERGED' ? 'merged' : 'closed'),
|
|
101
|
+
headRefName: readout.headRefName,
|
|
102
|
+
baseRefName: readout.baseRefName,
|
|
103
|
+
isDraft: readout.isDraft,
|
|
104
|
+
isCrossRepository: readout.isCrossRepository,
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
// head のブランチを持つ PR が、open で fork からでないものちょうど 1 本なら返す。2 本以上か続きがあれば足さない
|
|
108
|
+
async function lookUpByHead(client, repository, head) {
|
|
109
|
+
const found = await client.listPullRequestsByHead(repository.owner, repository.repository, head);
|
|
110
|
+
if (found.hasNextPage)
|
|
111
|
+
return undefined;
|
|
112
|
+
const candidates = found.pullRequests.map(pullRequest => toIssuePullRequest(pullRequest)).filter(pullRequest => pullRequest.state === 'open' && !pullRequest.isCrossRepository);
|
|
113
|
+
return candidates.length === 1 ? candidates[0] : undefined;
|
|
114
|
+
}
|
|
115
|
+
function cachedLookUp(client, cache, repository, head) {
|
|
116
|
+
const key = `${repositoryFullName(repository)}:${head}`.toLowerCase();
|
|
117
|
+
const cached = cache.get(key);
|
|
118
|
+
if (cached !== undefined)
|
|
119
|
+
return cached;
|
|
120
|
+
const pending = lookUpByHead(client, repository, head);
|
|
121
|
+
cache.set(key, pending);
|
|
122
|
+
return pending;
|
|
123
|
+
}
|
|
124
|
+
// 前提の open で fork からでない PR
|
|
125
|
+
function prerequisitePullRequests(prerequisites) {
|
|
126
|
+
return prerequisites.flatMap(({ issue }) => issue.pullRequests).filter(pullRequest => pullRequest.state === 'open' && !pullRequest.isCrossRepository);
|
|
127
|
+
}
|
|
128
|
+
// diverged の間、base のブランチを head に持つ PR を引き足して判定をやり直す
|
|
129
|
+
async function traceStacks(client, snapshot, cache, byHead, first, judge, branch) {
|
|
130
|
+
const { prerequisites } = snapshot;
|
|
131
|
+
let readiness = first;
|
|
132
|
+
const traced = new Set();
|
|
133
|
+
for (let step = 0; step < MAX_STACK_TRACE_STEPS && readiness?.reason?.code === 'diverged'; step += 1) {
|
|
134
|
+
const known = new Set([...prerequisitePullRequests(prerequisites), ...byHead.values()].map(pullRequest => pullRequest.headRefName));
|
|
135
|
+
const missing = [...prerequisitePullRequests(prerequisites), ...byHead.values()].filter(pullRequest => pullRequest.baseRefName !== branch && !known.has(pullRequest.baseRefName) && !traced.has(`${repositoryFullName(pullRequest.repository)}:${pullRequest.baseRefName}`.toLowerCase()));
|
|
136
|
+
if (missing.length === 0)
|
|
137
|
+
break;
|
|
138
|
+
for (const pullRequest of missing) {
|
|
139
|
+
traced.add(`${repositoryFullName(pullRequest.repository)}:${pullRequest.baseRefName}`.toLowerCase());
|
|
140
|
+
const base = await cachedLookUp(client, cache, pullRequest.repository, pullRequest.baseRefName);
|
|
141
|
+
if (base !== undefined)
|
|
142
|
+
byHead.set(base.headRefName, base);
|
|
143
|
+
}
|
|
144
|
+
readiness = judge();
|
|
145
|
+
}
|
|
146
|
+
return readiness;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
前提を判定する。cycle は呼ぶ側が findCycle で求めた輪。
|
|
150
|
+
develop_branch が無いときと、PR の引き足しの API が失敗したときは、読み取り結果を添えた unreadable を返す。
|
|
151
|
+
DependenciesUnsupportedError はそのまま投げる。
|
|
152
|
+
前提の PR が開発ブランチに届かないときだけ、base のブランチを head に持つ PR を引き足して、判定をやり直す
|
|
153
|
+
*/
|
|
154
|
+
export async function judgeSnapshot(client, snapshot, cache, cycle) {
|
|
155
|
+
const { developmentBranch, prerequisites, target } = snapshot;
|
|
156
|
+
const hasUnfinished = prerequisites.some(({ issue }) => !(issue.state === 'closed' && issue.pullRequests.some(pullRequest => pullRequest.state === 'merged')));
|
|
157
|
+
if (hasUnfinished && (developmentBranch === undefined || developmentBranch === '')) {
|
|
158
|
+
return unreadable(`develop_branch is not set for ${repositoryFullName(snapshot.ref.repository)}`, snapshot);
|
|
159
|
+
}
|
|
160
|
+
const branch = developmentBranch ?? '';
|
|
161
|
+
const byHead = new Map();
|
|
162
|
+
const judge = () => judgeReadiness({ target, prerequisites, cycle, pullRequestsByHead: byHead, developmentBranch: branch });
|
|
163
|
+
let readiness = judge();
|
|
164
|
+
try {
|
|
165
|
+
readiness = await traceStacks(client, snapshot, cache, byHead, readiness, judge, branch);
|
|
166
|
+
}
|
|
167
|
+
catch (error) {
|
|
168
|
+
if (error instanceof GitHubAPIError && !(error instanceof DependenciesUnsupportedError))
|
|
169
|
+
return unreadable(error.message, snapshot);
|
|
170
|
+
throw error;
|
|
171
|
+
}
|
|
172
|
+
return {
|
|
173
|
+
kind: 'judged',
|
|
174
|
+
ref: snapshot.ref,
|
|
175
|
+
title: snapshot.title,
|
|
176
|
+
target,
|
|
177
|
+
prerequisites,
|
|
178
|
+
titles: snapshot.titles,
|
|
179
|
+
mismatches: snapshot.mismatches,
|
|
180
|
+
malformedReason: snapshot.malformedReason,
|
|
181
|
+
parent: snapshot.parent,
|
|
182
|
+
readiness,
|
|
183
|
+
};
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
186
|
+
Issue 1 件の読み取りから判定までを通す。輪は呼ぶ側が渡す(issue show は輪を見ない)
|
|
187
|
+
*/
|
|
188
|
+
export async function readIssueReadiness(client, config, reference, cache, cycle, blockedByFirst) {
|
|
189
|
+
const snapshot = await readIssueSnapshot(client, config, reference, blockedByFirst);
|
|
190
|
+
return snapshot.kind === 'unreadable' ? snapshot : await judgeSnapshot(client, snapshot, cache, cycle);
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
JSON の出力に使う判定。reason は blocked のときだけの理由のコード、stackOn は積む先
|
|
194
|
+
*/
|
|
195
|
+
export function readinessJson(readiness, text) {
|
|
196
|
+
const { stackOn } = readiness;
|
|
197
|
+
return {
|
|
198
|
+
kind: readiness.kind,
|
|
199
|
+
stackOn: stackOn === undefined ? JSON_NULL : { number: stackOn.issue.number, repository: repositoryFullName(stackOn.issue.repository), branch: stackOn.branch },
|
|
200
|
+
reason: readiness.reason?.code ?? JSON_NULL,
|
|
201
|
+
text,
|
|
202
|
+
};
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
readIssueReadiness の、依存関係を持たない GHES を判定なしで通す形。GHES なら undefined を返し、onUnsupported に理由を渡す
|
|
206
|
+
*/
|
|
207
|
+
export async function readIssueReadinessIfSupported(client, config, reference, cache, onUnsupported) {
|
|
208
|
+
try {
|
|
209
|
+
return await readIssueReadiness(client, config, reference, cache);
|
|
210
|
+
}
|
|
211
|
+
catch (error) {
|
|
212
|
+
if (!(error instanceof DependenciesUnsupportedError))
|
|
213
|
+
throw error;
|
|
214
|
+
onUnsupported?.(error.message);
|
|
215
|
+
return undefined;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
//# sourceMappingURL=issue-readiness.js.map
|