@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,143 @@
|
|
|
1
|
+
import type { JsonObject } from '../../domain/json.js';
|
|
2
|
+
import type { LinkedRepository } from '../../domain/config.js';
|
|
3
|
+
import type { FieldOptionInput } from '../../domain/field-options.js';
|
|
4
|
+
import type { BoardItem } from '../../domain/format.js';
|
|
5
|
+
import type { JsonValue } from '../../domain/python-format.js';
|
|
6
|
+
import type { GraphqlOutcome, PathPredicate } from './client.js';
|
|
7
|
+
import { ReposApi } from './repos.js';
|
|
8
|
+
/**
|
|
9
|
+
Issue のボードのアイテム。isArchived はアイテムのアーカイブで、Status の Archived とは別
|
|
10
|
+
*/
|
|
11
|
+
export interface IssueProjectItem {
|
|
12
|
+
readonly id: string;
|
|
13
|
+
readonly isArchived: boolean;
|
|
14
|
+
}
|
|
15
|
+
export interface ListProjectItemsOptions {
|
|
16
|
+
/**
|
|
17
|
+
取得する最大件数。省略または 0 なら全件
|
|
18
|
+
*/
|
|
19
|
+
readonly limit?: number | undefined;
|
|
20
|
+
/**
|
|
21
|
+
Archived を除外する。連続して 50 件 Archived が続いたら打ち切る
|
|
22
|
+
*/
|
|
23
|
+
readonly excludeArchived?: boolean | undefined;
|
|
24
|
+
/**
|
|
25
|
+
excludeArchived のとき、ステータスを見るフィールド名
|
|
26
|
+
*/
|
|
27
|
+
readonly workflowFieldName?: string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
Issue の依存関係に対応しない GHES で、足したフィールドを除いたクエリで読み直したときに呼ぶ
|
|
30
|
+
*/
|
|
31
|
+
readonly onLegacy?: (() => void) | undefined;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
SingleSelect フィールドの選択肢
|
|
35
|
+
*/
|
|
36
|
+
export type ProjectFieldOption = Readonly<{
|
|
37
|
+
name: string;
|
|
38
|
+
color: string;
|
|
39
|
+
description: string;
|
|
40
|
+
}>;
|
|
41
|
+
/**
|
|
42
|
+
プロジェクトへのリンクの結果。detail は GitHub の message をそのまま入れる(成功時は空文字列)
|
|
43
|
+
*/
|
|
44
|
+
export interface LinkResult {
|
|
45
|
+
readonly status: 'linked' | 'already_linked' | 'failed';
|
|
46
|
+
readonly detail: string;
|
|
47
|
+
}
|
|
48
|
+
export declare class ProjectsApi extends ReposApi {
|
|
49
|
+
private queryAsUser;
|
|
50
|
+
/**
|
|
51
|
+
Issue を読むクエリ。無い Issue・リポジトリの NOT_FOUND を GitHubNotFoundError にする
|
|
52
|
+
*/
|
|
53
|
+
protected queryIssue(query: string, variables: Readonly<Record<string, JsonValue>>): Promise<JsonObject>;
|
|
54
|
+
/**
|
|
55
|
+
queryIssue の、部分エラーを許す版
|
|
56
|
+
*/
|
|
57
|
+
protected queryIssueTolerating(query: string, variables: Readonly<Record<string, JsonValue>>, isTolerated: PathPredicate): Promise<GraphqlOutcome>;
|
|
58
|
+
/**
|
|
59
|
+
プロジェクトボードのアイテムを取得する(ページネーション対応)
|
|
60
|
+
*/
|
|
61
|
+
listProjectItems(projectId: string, options?: Readonly<ListProjectItemsOptions>): Promise<readonly JsonObject[]>;
|
|
62
|
+
/**
|
|
63
|
+
Issue をプロジェクトボードに追加し、作られたアイテムの ID を返す
|
|
64
|
+
*/
|
|
65
|
+
addToProject(projectId: string, contentId: string): Promise<string>;
|
|
66
|
+
/**
|
|
67
|
+
プロジェクトアイテムの SingleSelect フィールドの値を更新し、アイテムの ID を返す
|
|
68
|
+
*/
|
|
69
|
+
updateProjectItemField(projectId: string, itemId: string, fieldId: string, optionId: string): Promise<string>;
|
|
70
|
+
/**
|
|
71
|
+
アーカイブ済みのアイテムをボードに戻す
|
|
72
|
+
*/
|
|
73
|
+
unarchiveProjectItem(projectId: string, itemId: string): Promise<void>;
|
|
74
|
+
/**
|
|
75
|
+
プロジェクトボードからアイテムを削除し、削除したアイテムの ID を返す
|
|
76
|
+
*/
|
|
77
|
+
deleteProjectItem(projectId: string, itemId: string): Promise<string>;
|
|
78
|
+
/**
|
|
79
|
+
プロジェクトにリンクされたリポジトリの一覧。user 所有を先に試し、無ければ organization 所有を試す
|
|
80
|
+
*/
|
|
81
|
+
getLinkedRepositories(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
82
|
+
/**
|
|
83
|
+
リンクされたリポジトリの一覧(キャッシュ付き)。同じクライアントの中で同じ引数なら、2 回目以降はキャッシュを返す
|
|
84
|
+
*/
|
|
85
|
+
getLinkedRepositoriesCached(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
86
|
+
/**
|
|
87
|
+
RepositoryMembership(domain/config.ts)の実体。キャッシュ付きの一覧を返す
|
|
88
|
+
*/
|
|
89
|
+
linkedRepositories(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
90
|
+
/**
|
|
91
|
+
プロジェクト番号から GraphQL Node ID を取る。user 所有を先に試す。無ければ GitHubNotFoundError
|
|
92
|
+
*/
|
|
93
|
+
getProjectId(owner: string, projectNumber: number): Promise<string>;
|
|
94
|
+
/**
|
|
95
|
+
Issue 番号から、指定のプロジェクトの中のアイテム ID を取る。
|
|
96
|
+
Issue から直接引くので、全アイテムの走査は要らない。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
97
|
+
*/
|
|
98
|
+
getItemIdByIssue(projectId: string, owner: string, repository: string, issueNumber: number): Promise<string | undefined>;
|
|
99
|
+
/**
|
|
100
|
+
getItemIdByIssue と同じ引き方で、アイテムの ID とアーカイブ済みかを取る
|
|
101
|
+
*/
|
|
102
|
+
getIssueProjectItem(projectId: string, owner: string, repository: string, issueNumber: number): Promise<IssueProjectItem | undefined>;
|
|
103
|
+
/**
|
|
104
|
+
Issue 1 件の、指定のプロジェクトの項目を、readBoard の一覧の項目と同じ形で返す(札は含めない)。
|
|
105
|
+
workflow は進行の列の値で、空なら null。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
106
|
+
*/
|
|
107
|
+
getIssueBoardItem(projectId: string, owner: string, repository: string, issueNumber: number, workflowFieldName: string): Promise<BoardItem | undefined>;
|
|
108
|
+
/**
|
|
109
|
+
プロジェクトアイテムで値が入っている単一選択フィールドの ID を取る。アイテムが見つからなければ空
|
|
110
|
+
*/
|
|
111
|
+
getItemSetFieldIds(projectId: string, owner: string, repository: string, issueNumber: number, itemId: string): Promise<ReadonlySet<string>>;
|
|
112
|
+
/**
|
|
113
|
+
プロジェクトにリポジトリをリンクする。
|
|
114
|
+
リンクした(linked)、既にリンク済み(already_linked)、失敗(failed)のいずれも例外にせず結果で返す
|
|
115
|
+
*/
|
|
116
|
+
linkRepositoryToProject(owner: string, projectNumber: number, repositoryOwner: string, repositoryName: string): Promise<LinkResult>;
|
|
117
|
+
/**
|
|
118
|
+
オーナーのプロジェクト一覧(number・title・url・id)。user 所有を先に試す
|
|
119
|
+
*/
|
|
120
|
+
listProjects(owner: string, limit?: number): Promise<readonly JsonObject[]>;
|
|
121
|
+
/**
|
|
122
|
+
プロジェクトの情報(id・title・url・fields)。user 所有を先に試す。見つからなければ undefined
|
|
123
|
+
*/
|
|
124
|
+
getProjectFields(owner: string, projectNumber: number): Promise<JsonObject | undefined>;
|
|
125
|
+
/**
|
|
126
|
+
プロジェクトに SingleSelect フィールドを作り、作ったフィールド(id・name・options)を返す
|
|
127
|
+
*/
|
|
128
|
+
createProjectField(projectId: string, name: string, options: readonly ProjectFieldOption[]): Promise<JsonObject>;
|
|
129
|
+
/**
|
|
130
|
+
SingleSelect フィールドの選択肢を、渡した一覧に置き換え、更新後のフィールド(id・name・options)を返す。
|
|
131
|
+
既存の選択肢は id を付けて渡す(外すと選択肢が作り直され、カードの値が消える)
|
|
132
|
+
*/
|
|
133
|
+
updateProjectFieldOptions(fieldId: string, options: readonly FieldOptionInput[]): Promise<JsonObject>;
|
|
134
|
+
/**
|
|
135
|
+
オーナー(user か organization)の GraphQL Node ID。user を先に試し、無ければ GitHubNotFoundError
|
|
136
|
+
*/
|
|
137
|
+
getOwnerNodeId(owner: string): Promise<string>;
|
|
138
|
+
/**
|
|
139
|
+
GitHub Projects V2 を作り、作ったプロジェクト(id・number・title・url)を返す
|
|
140
|
+
*/
|
|
141
|
+
createProject(ownerId: string, title: string): Promise<JsonObject>;
|
|
142
|
+
}
|
|
143
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
// GitHub Projects (v2) 操作の API。cli/core/github/projects.py の移植。
|
|
2
|
+
// owner が user か organization かは分からないので、user のクエリを先に試し、失敗したら organization を試す。
|
|
3
|
+
import { isJsonObject, jsonField } from '../../domain/json.js';
|
|
4
|
+
import { JSON_NULL } from '../../domain/json-null.js';
|
|
5
|
+
import { asNotFoundError, GitHubAPIError, GitHubNotFoundError, isSchemaError } from './errors.js';
|
|
6
|
+
import { asArray, asObject, isTruthy, requireString, truthyNodes } from './payload.js';
|
|
7
|
+
import { MUTATION_ADD_TO_PROJECT, MUTATION_CREATE_PROJECT, MUTATION_CREATE_PROJECT_FIELD, MUTATION_DELETE_PROJECT_ITEM, MUTATION_UNARCHIVE_PROJECT_ITEM, MUTATION_LINK_PROJECT_REPOSITORY, MUTATION_UPDATE_PROJECT_FIELD, MUTATION_UPDATE_PROJECT_ITEM_FIELD, QUERY_GET_ISSUE_BOARD_ITEM, QUERY_GET_ISSUE_PROJECT_ITEMS, QUERY_GET_LINKED_REPOSITORIES_ORG, QUERY_GET_LINKED_REPOSITORIES_USER, QUERY_GET_ORG_NODE_ID, QUERY_GET_PROJECT_FIELDS_ORG, QUERY_GET_PROJECT_FIELDS_USER, QUERY_GET_PROJECT_ID_ORG, QUERY_GET_PROJECT_ID_USER, QUERY_GET_USER_NODE_ID, QUERY_LIST_PROJECT_ITEMS, QUERY_LIST_PROJECT_ITEMS_LEGACY, QUERY_LIST_PROJECTS_ORG, QUERY_LIST_PROJECTS_USER, } from './queries.js';
|
|
8
|
+
import { ReposApi } from './repos.js';
|
|
9
|
+
// 着手の判定に足したフィールドの名前が出るスキーマの失敗(`Field 'x' doesn't exist` と `Cannot query field "x"`)
|
|
10
|
+
const READINESS_FIELD_ERROR = /(?:Field '|field ")(?:issueType|subIssues|parent|blockedBy)['"]/u;
|
|
11
|
+
const MAX_ARCHIVED_CONSECUTIVE = 50;
|
|
12
|
+
const DEFAULT_PROJECT_LIMIT = 20;
|
|
13
|
+
function lowerText(value) {
|
|
14
|
+
return typeof value === 'string' ? value.toLowerCase() : '';
|
|
15
|
+
}
|
|
16
|
+
// ワークフローのフィールドの値が Archived か。そのフィールドが無ければ false
|
|
17
|
+
function isItemArchived(item, workflowFieldName) {
|
|
18
|
+
const target = workflowFieldName.toLowerCase();
|
|
19
|
+
const fieldValues = truthyNodes(jsonField(item, 'fieldValues'));
|
|
20
|
+
for (const node of fieldValues) {
|
|
21
|
+
if (lowerText(jsonField(jsonField(node, 'field'), 'name')) === target)
|
|
22
|
+
return lowerText(jsonField(node, 'name')) === 'archived';
|
|
23
|
+
}
|
|
24
|
+
return false;
|
|
25
|
+
}
|
|
26
|
+
// オブジェクトの要素だけを残す(null などは落とす)
|
|
27
|
+
function objectsOf(items) {
|
|
28
|
+
return items.filter(item => isJsonObject(item));
|
|
29
|
+
}
|
|
30
|
+
function linkedRepositoriesOf(project) {
|
|
31
|
+
return truthyNodes(jsonField(project, 'repositories')).map(node => ({
|
|
32
|
+
owner: requireString(jsonField(jsonField(node, 'owner'), 'login'), 'repositories.nodes.owner.login'),
|
|
33
|
+
name: requireString(jsonField(node, 'name'), 'repositories.nodes.name'),
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
36
|
+
export class ProjectsApi extends ReposApi {
|
|
37
|
+
// user のクエリ。GitHub の失敗は、認証エラーとレート制限も含めて undefined にし、org のクエリへ進む。
|
|
38
|
+
// Python と同じ動き
|
|
39
|
+
async queryAsUser(query, variables) {
|
|
40
|
+
try {
|
|
41
|
+
return await this.executeGraphql(query, variables);
|
|
42
|
+
}
|
|
43
|
+
catch (error) {
|
|
44
|
+
if (error instanceof GitHubAPIError)
|
|
45
|
+
return undefined;
|
|
46
|
+
throw error;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
Issue を読むクエリ。無い Issue・リポジトリの NOT_FOUND を GitHubNotFoundError にする
|
|
51
|
+
*/
|
|
52
|
+
async queryIssue(query, variables) {
|
|
53
|
+
try {
|
|
54
|
+
return await this.executeGraphql(query, variables);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
throw asNotFoundError(error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
queryIssue の、部分エラーを許す版
|
|
62
|
+
*/
|
|
63
|
+
async queryIssueTolerating(query, variables, isTolerated) {
|
|
64
|
+
try {
|
|
65
|
+
return await this.executeGraphqlTolerating(query, variables, isTolerated);
|
|
66
|
+
}
|
|
67
|
+
catch (error) {
|
|
68
|
+
throw asNotFoundError(error);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
プロジェクトボードのアイテムを取得する(ページネーション対応)
|
|
73
|
+
*/
|
|
74
|
+
async listProjectItems(projectId, options = {}) {
|
|
75
|
+
const { limit, excludeArchived = false, workflowFieldName = '', onLegacy } = options;
|
|
76
|
+
let query = QUERY_LIST_PROJECT_ITEMS;
|
|
77
|
+
let allItems = [];
|
|
78
|
+
let cursor = JSON_NULL;
|
|
79
|
+
let archivedConsecutive = 0;
|
|
80
|
+
for (;;) {
|
|
81
|
+
let result;
|
|
82
|
+
try {
|
|
83
|
+
result = await this.executeGraphql(query, { projectId, cursor });
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// 古い GHES は blockedBy などを知らない。足す前のクエリで先頭から読み直す
|
|
87
|
+
if (query === QUERY_LIST_PROJECT_ITEMS_LEGACY || !isSchemaError(error) || !READINESS_FIELD_ERROR.test(error.message))
|
|
88
|
+
throw error;
|
|
89
|
+
query = QUERY_LIST_PROJECT_ITEMS_LEGACY;
|
|
90
|
+
allItems = [];
|
|
91
|
+
cursor = JSON_NULL;
|
|
92
|
+
archivedConsecutive = 0;
|
|
93
|
+
onLegacy?.();
|
|
94
|
+
continue;
|
|
95
|
+
}
|
|
96
|
+
const node = jsonField(result, 'node');
|
|
97
|
+
if (!isTruthy(node))
|
|
98
|
+
break;
|
|
99
|
+
const itemsData = asObject(jsonField(node, 'items'));
|
|
100
|
+
const nodes = asArray(jsonField(itemsData, 'nodes'));
|
|
101
|
+
if (excludeArchived) {
|
|
102
|
+
for (const item of nodes) {
|
|
103
|
+
if (isItemArchived(item, workflowFieldName)) {
|
|
104
|
+
archivedConsecutive += 1;
|
|
105
|
+
}
|
|
106
|
+
else {
|
|
107
|
+
allItems.push(item);
|
|
108
|
+
archivedConsecutive = 0;
|
|
109
|
+
}
|
|
110
|
+
if (archivedConsecutive >= MAX_ARCHIVED_CONSECUTIVE)
|
|
111
|
+
return objectsOf(allItems);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
allItems.push(...nodes);
|
|
116
|
+
}
|
|
117
|
+
if (limit !== undefined && limit > 0 && allItems.length >= limit) {
|
|
118
|
+
allItems = allItems.slice(0, limit);
|
|
119
|
+
break;
|
|
120
|
+
}
|
|
121
|
+
const pageInfo = asObject(jsonField(itemsData, 'pageInfo'));
|
|
122
|
+
if (!isTruthy(pageInfo['hasNextPage']))
|
|
123
|
+
break;
|
|
124
|
+
// 次のページがあるのに cursor が無いと、先頭から取り直して終わらない
|
|
125
|
+
const endCursor = pageInfo['endCursor'];
|
|
126
|
+
if (typeof endCursor !== 'string')
|
|
127
|
+
throw new GitHubAPIError('could not get the cursor for the next page');
|
|
128
|
+
cursor = endCursor;
|
|
129
|
+
}
|
|
130
|
+
return objectsOf(allItems);
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
Issue をプロジェクトボードに追加し、作られたアイテムの ID を返す
|
|
134
|
+
*/
|
|
135
|
+
async addToProject(projectId, contentId) {
|
|
136
|
+
const result = await this.executeGraphql(MUTATION_ADD_TO_PROJECT, { projectId, contentId });
|
|
137
|
+
const item = jsonField(jsonField(result, 'addProjectV2ItemById'), 'item');
|
|
138
|
+
if (!isTruthy(item))
|
|
139
|
+
throw new GitHubAPIError('failed to add the item to the project');
|
|
140
|
+
return requireString(jsonField(item, 'id'), 'item.id');
|
|
141
|
+
}
|
|
142
|
+
/**
|
|
143
|
+
プロジェクトアイテムの SingleSelect フィールドの値を更新し、アイテムの ID を返す
|
|
144
|
+
*/
|
|
145
|
+
async updateProjectItemField(projectId, itemId, fieldId, optionId) {
|
|
146
|
+
const result = await this.executeGraphql(MUTATION_UPDATE_PROJECT_ITEM_FIELD, { projectId, itemId, fieldId, optionId });
|
|
147
|
+
const item = jsonField(jsonField(result, 'updateProjectV2ItemFieldValue'), 'projectV2Item');
|
|
148
|
+
if (!isTruthy(item))
|
|
149
|
+
throw new GitHubAPIError('failed to update the field');
|
|
150
|
+
return requireString(jsonField(item, 'id'), 'projectV2Item.id');
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
153
|
+
アーカイブ済みのアイテムをボードに戻す
|
|
154
|
+
*/
|
|
155
|
+
async unarchiveProjectItem(projectId, itemId) {
|
|
156
|
+
const result = await this.executeGraphql(MUTATION_UNARCHIVE_PROJECT_ITEM, { projectId, itemId });
|
|
157
|
+
if (!isTruthy(jsonField(jsonField(result, 'unarchiveProjectV2Item'), 'item')))
|
|
158
|
+
throw new GitHubAPIError('failed to unarchive the project item');
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
プロジェクトボードからアイテムを削除し、削除したアイテムの ID を返す
|
|
162
|
+
*/
|
|
163
|
+
async deleteProjectItem(projectId, itemId) {
|
|
164
|
+
const result = await this.executeGraphql(MUTATION_DELETE_PROJECT_ITEM, { projectId, itemId });
|
|
165
|
+
const deletedId = jsonField(jsonField(result, 'deleteProjectV2Item'), 'deletedItemId');
|
|
166
|
+
if (!isTruthy(deletedId))
|
|
167
|
+
throw new GitHubAPIError('failed to delete the project item');
|
|
168
|
+
return requireString(deletedId, 'deletedItemId');
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
プロジェクトにリンクされたリポジトリの一覧。user 所有を先に試し、無ければ organization 所有を試す
|
|
172
|
+
*/
|
|
173
|
+
async getLinkedRepositories(owner, projectNumber) {
|
|
174
|
+
const variables = { owner, projectNumber };
|
|
175
|
+
const userResult = await this.queryAsUser(QUERY_GET_LINKED_REPOSITORIES_USER, variables);
|
|
176
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
177
|
+
if (isTruthy(userProject))
|
|
178
|
+
return linkedRepositoriesOf(userProject);
|
|
179
|
+
const orgResult = await this.executeGraphql(QUERY_GET_LINKED_REPOSITORIES_ORG, variables);
|
|
180
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
181
|
+
return isTruthy(organizationProject) ? linkedRepositoriesOf(organizationProject) : [];
|
|
182
|
+
}
|
|
183
|
+
/**
|
|
184
|
+
リンクされたリポジトリの一覧(キャッシュ付き)。同じクライアントの中で同じ引数なら、2 回目以降はキャッシュを返す
|
|
185
|
+
*/
|
|
186
|
+
async getLinkedRepositoriesCached(owner, projectNumber) {
|
|
187
|
+
const cacheKey = `${owner}/${String(projectNumber)}`;
|
|
188
|
+
const cached = this.linkedRepositoriesCache.get(cacheKey);
|
|
189
|
+
if (cached !== undefined)
|
|
190
|
+
return cached;
|
|
191
|
+
const repositories = await this.getLinkedRepositories(owner, projectNumber);
|
|
192
|
+
this.linkedRepositoriesCache.set(cacheKey, repositories);
|
|
193
|
+
return repositories;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
RepositoryMembership(domain/config.ts)の実体。キャッシュ付きの一覧を返す
|
|
197
|
+
*/
|
|
198
|
+
async linkedRepositories(owner, projectNumber) {
|
|
199
|
+
return this.getLinkedRepositoriesCached(owner, projectNumber);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
プロジェクト番号から GraphQL Node ID を取る。user 所有を先に試す。無ければ GitHubNotFoundError
|
|
203
|
+
*/
|
|
204
|
+
async getProjectId(owner, projectNumber) {
|
|
205
|
+
const variables = { owner, projectNumber };
|
|
206
|
+
const userResult = await this.queryAsUser(QUERY_GET_PROJECT_ID_USER, variables);
|
|
207
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
208
|
+
if (isTruthy(userProject))
|
|
209
|
+
return requireString(jsonField(userProject, 'id'), 'projectV2.id');
|
|
210
|
+
const orgResult = await this.executeGraphql(QUERY_GET_PROJECT_ID_ORG, variables);
|
|
211
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
212
|
+
if (isTruthy(organizationProject))
|
|
213
|
+
return requireString(jsonField(organizationProject, 'id'), 'projectV2.id');
|
|
214
|
+
throw new GitHubNotFoundError(`project not found: ${owner}/projects/${String(projectNumber)}`);
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
Issue 番号から、指定のプロジェクトの中のアイテム ID を取る。
|
|
218
|
+
Issue から直接引くので、全アイテムの走査は要らない。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
219
|
+
*/
|
|
220
|
+
async getItemIdByIssue(projectId, owner, repository, issueNumber) {
|
|
221
|
+
const item = await this.getIssueProjectItem(projectId, owner, repository, issueNumber);
|
|
222
|
+
return item?.id;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
getItemIdByIssue と同じ引き方で、アイテムの ID とアーカイブ済みかを取る
|
|
226
|
+
*/
|
|
227
|
+
async getIssueProjectItem(projectId, owner, repository, issueNumber) {
|
|
228
|
+
const result = await this.queryIssue(QUERY_GET_ISSUE_PROJECT_ITEMS, { owner, repo: repository, number: issueNumber });
|
|
229
|
+
const repositoryNode = jsonField(result, 'repository');
|
|
230
|
+
if (!isTruthy(repositoryNode))
|
|
231
|
+
return undefined;
|
|
232
|
+
const issue = jsonField(repositoryNode, 'issue');
|
|
233
|
+
if (!isTruthy(issue))
|
|
234
|
+
return undefined;
|
|
235
|
+
const projectItems = truthyNodes(jsonField(issue, 'projectItems'));
|
|
236
|
+
for (const item of projectItems) {
|
|
237
|
+
if (jsonField(jsonField(item, 'project'), 'id') !== projectId)
|
|
238
|
+
continue;
|
|
239
|
+
return { id: requireString(jsonField(item, 'id'), 'projectItems.nodes.id'), isArchived: jsonField(item, 'isArchived') === true };
|
|
240
|
+
}
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
Issue 1 件の、指定のプロジェクトの項目を、readBoard の一覧の項目と同じ形で返す(札は含めない)。
|
|
245
|
+
workflow は進行の列の値で、空なら null。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
246
|
+
*/
|
|
247
|
+
async getIssueBoardItem(projectId, owner, repository, issueNumber, workflowFieldName) {
|
|
248
|
+
const result = await this.executeGraphql(QUERY_GET_ISSUE_BOARD_ITEM, { owner, repo: repository, number: issueNumber, workflowFieldName });
|
|
249
|
+
const issue = jsonField(jsonField(result, 'repository'), 'issue');
|
|
250
|
+
if (!isTruthy(issue))
|
|
251
|
+
return undefined;
|
|
252
|
+
const item = truthyNodes(jsonField(issue, 'projectItems')).find(node => jsonField(jsonField(node, 'project'), 'id') === projectId);
|
|
253
|
+
if (item === undefined)
|
|
254
|
+
return undefined;
|
|
255
|
+
const workflow = jsonField(jsonField(item, 'workflow'), 'name');
|
|
256
|
+
const owning = jsonField(issue, 'repository');
|
|
257
|
+
return {
|
|
258
|
+
id: requireString(jsonField(item, 'id'), 'projectItems.nodes.id'),
|
|
259
|
+
workflow: typeof workflow === 'string' ? workflow : JSON_NULL,
|
|
260
|
+
title: jsonField(issue, 'title') ?? '',
|
|
261
|
+
content: {
|
|
262
|
+
number: jsonField(issue, 'number') ?? JSON_NULL,
|
|
263
|
+
state: jsonField(issue, 'state') ?? JSON_NULL,
|
|
264
|
+
url: jsonField(issue, 'url') ?? JSON_NULL,
|
|
265
|
+
repository: `${requireString(jsonField(jsonField(owning, 'owner'), 'login'), 'issue.repository.owner.login')}/${requireString(jsonField(owning, 'name'), 'issue.repository.name')}`,
|
|
266
|
+
},
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
プロジェクトアイテムで値が入っている単一選択フィールドの ID を取る。アイテムが見つからなければ空
|
|
271
|
+
*/
|
|
272
|
+
async getItemSetFieldIds(projectId, owner, repository, issueNumber, itemId) {
|
|
273
|
+
const result = await this.queryIssue(QUERY_GET_ISSUE_PROJECT_ITEMS, { owner, repo: repository, number: issueNumber });
|
|
274
|
+
const issue = jsonField(jsonField(result, 'repository'), 'issue');
|
|
275
|
+
const fieldIds = new Set();
|
|
276
|
+
const items = truthyNodes(jsonField(issue, 'projectItems'));
|
|
277
|
+
for (const item of items) {
|
|
278
|
+
if (jsonField(item, 'id') !== itemId || jsonField(jsonField(item, 'project'), 'id') !== projectId)
|
|
279
|
+
continue;
|
|
280
|
+
const values = truthyNodes(jsonField(item, 'fieldValues'));
|
|
281
|
+
for (const value of values) {
|
|
282
|
+
const fieldId = jsonField(jsonField(value, 'field'), 'id');
|
|
283
|
+
if (typeof fieldId === 'string')
|
|
284
|
+
fieldIds.add(fieldId);
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return fieldIds;
|
|
288
|
+
}
|
|
289
|
+
/**
|
|
290
|
+
プロジェクトにリポジトリをリンクする。
|
|
291
|
+
リンクした(linked)、既にリンク済み(already_linked)、失敗(failed)のいずれも例外にせず結果で返す
|
|
292
|
+
*/
|
|
293
|
+
async linkRepositoryToProject(owner, projectNumber, repositoryOwner, repositoryName) {
|
|
294
|
+
try {
|
|
295
|
+
const projectId = await this.getProjectId(owner, projectNumber);
|
|
296
|
+
const repositoryId = await this.getRepositoryId(repositoryOwner, repositoryName);
|
|
297
|
+
const result = await this.executeGraphql(MUTATION_LINK_PROJECT_REPOSITORY, { projectId, repositoryId });
|
|
298
|
+
const linked = jsonField(jsonField(result, 'linkProjectV2ToRepository'), 'repository');
|
|
299
|
+
return isTruthy(linked) ? { status: 'linked', detail: '' } : { status: 'failed', detail: 'unexpected response' };
|
|
300
|
+
}
|
|
301
|
+
catch (error) {
|
|
302
|
+
if (error instanceof GitHubNotFoundError)
|
|
303
|
+
return { status: 'failed', detail: error.message };
|
|
304
|
+
if (error instanceof GitHubAPIError) {
|
|
305
|
+
const lowered = error.message.toLowerCase();
|
|
306
|
+
const isAlreadyLinked = lowered.includes('already linked') || lowered.includes('already exists');
|
|
307
|
+
return { status: isAlreadyLinked ? 'already_linked' : 'failed', detail: error.message };
|
|
308
|
+
}
|
|
309
|
+
throw error;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
オーナーのプロジェクト一覧(number・title・url・id)。user 所有を先に試す
|
|
314
|
+
*/
|
|
315
|
+
async listProjects(owner, limit = DEFAULT_PROJECT_LIMIT) {
|
|
316
|
+
const variables = { owner, first: limit };
|
|
317
|
+
const userResult = await this.queryAsUser(QUERY_LIST_PROJECTS_USER, variables);
|
|
318
|
+
const userProjects = jsonField(jsonField(userResult, 'user'), 'projectsV2');
|
|
319
|
+
if (isTruthy(userProjects))
|
|
320
|
+
return objectsOf(truthyNodes(userProjects));
|
|
321
|
+
const orgResult = await this.executeGraphql(QUERY_LIST_PROJECTS_ORG, variables);
|
|
322
|
+
const organizationProjects = jsonField(jsonField(orgResult, 'organization'), 'projectsV2');
|
|
323
|
+
return isTruthy(organizationProjects) ? objectsOf(truthyNodes(organizationProjects)) : [];
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
プロジェクトの情報(id・title・url・fields)。user 所有を先に試す。見つからなければ undefined
|
|
327
|
+
*/
|
|
328
|
+
async getProjectFields(owner, projectNumber) {
|
|
329
|
+
const variables = { owner, projectNumber };
|
|
330
|
+
const userResult = await this.queryAsUser(QUERY_GET_PROJECT_FIELDS_USER, variables);
|
|
331
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
332
|
+
if (isTruthy(userProject))
|
|
333
|
+
return asObject(userProject);
|
|
334
|
+
const orgResult = await this.executeGraphql(QUERY_GET_PROJECT_FIELDS_ORG, variables);
|
|
335
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
336
|
+
return isTruthy(organizationProject) ? asObject(organizationProject) : undefined;
|
|
337
|
+
}
|
|
338
|
+
/**
|
|
339
|
+
プロジェクトに SingleSelect フィールドを作り、作ったフィールド(id・name・options)を返す
|
|
340
|
+
*/
|
|
341
|
+
async createProjectField(projectId, name, options) {
|
|
342
|
+
const result = await this.executeGraphql(MUTATION_CREATE_PROJECT_FIELD, { projectId, name, options });
|
|
343
|
+
const created = jsonField(jsonField(result, 'createProjectV2Field'), 'projectV2Field');
|
|
344
|
+
if (!isTruthy(created))
|
|
345
|
+
throw new GitHubAPIError('failed to create the field');
|
|
346
|
+
return asObject(created);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
SingleSelect フィールドの選択肢を、渡した一覧に置き換え、更新後のフィールド(id・name・options)を返す。
|
|
350
|
+
既存の選択肢は id を付けて渡す(外すと選択肢が作り直され、カードの値が消える)
|
|
351
|
+
*/
|
|
352
|
+
async updateProjectFieldOptions(fieldId, options) {
|
|
353
|
+
const result = await this.executeGraphql(MUTATION_UPDATE_PROJECT_FIELD, { fieldId, options });
|
|
354
|
+
const updated = jsonField(jsonField(result, 'updateProjectV2Field'), 'projectV2Field');
|
|
355
|
+
if (!isTruthy(updated))
|
|
356
|
+
throw new GitHubAPIError('failed to update the field');
|
|
357
|
+
return asObject(updated);
|
|
358
|
+
}
|
|
359
|
+
/**
|
|
360
|
+
オーナー(user か organization)の GraphQL Node ID。user を先に試し、無ければ GitHubNotFoundError
|
|
361
|
+
*/
|
|
362
|
+
async getOwnerNodeId(owner) {
|
|
363
|
+
const userResult = await this.queryAsUser(QUERY_GET_USER_NODE_ID, { login: owner });
|
|
364
|
+
const userId = jsonField(jsonField(userResult, 'user'), 'id');
|
|
365
|
+
if (isTruthy(userId))
|
|
366
|
+
return requireString(userId, 'user.id');
|
|
367
|
+
const orgResult = await this.executeGraphql(QUERY_GET_ORG_NODE_ID, { login: owner });
|
|
368
|
+
const organizationId = jsonField(jsonField(orgResult, 'organization'), 'id');
|
|
369
|
+
if (isTruthy(organizationId))
|
|
370
|
+
return requireString(organizationId, 'organization.id');
|
|
371
|
+
throw new GitHubNotFoundError(`owner not found: ${owner}`);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
GitHub Projects V2 を作り、作ったプロジェクト(id・number・title・url)を返す
|
|
375
|
+
*/
|
|
376
|
+
async createProject(ownerId, title) {
|
|
377
|
+
const result = await this.executeGraphql(MUTATION_CREATE_PROJECT, { ownerId, title });
|
|
378
|
+
const project = jsonField(jsonField(result, 'createProjectV2'), 'projectV2');
|
|
379
|
+
if (!isTruthy(project))
|
|
380
|
+
throw new GitHubAPIError('failed to create the project');
|
|
381
|
+
return asObject(project);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
import type { JsonObject } from '../../domain/json.js';
|
|
2
|
+
import type { PullRequestsByHeadReadout } from '../../domain/issue-readout.js';
|
|
3
|
+
import { IssuesApi } from './issues.js';
|
|
4
|
+
export interface ClosingIssue {
|
|
5
|
+
readonly number: number;
|
|
6
|
+
readonly title: string;
|
|
7
|
+
}
|
|
8
|
+
export interface PullRequestBase {
|
|
9
|
+
readonly number: number;
|
|
10
|
+
readonly state: string;
|
|
11
|
+
readonly title: string;
|
|
12
|
+
readonly body: string;
|
|
13
|
+
readonly head_ref: string;
|
|
14
|
+
readonly base_ref: string;
|
|
15
|
+
readonly is_draft: boolean;
|
|
16
|
+
readonly mergeable: string;
|
|
17
|
+
readonly comments: number;
|
|
18
|
+
readonly closing_issues: readonly ClosingIssue[];
|
|
19
|
+
/**
|
|
20
|
+
PR 本文の Refs で参照された Issue のうち、closing_issues に無いもの。title は空文字
|
|
21
|
+
*/
|
|
22
|
+
readonly referenced_issues: readonly ClosingIssue[];
|
|
23
|
+
}
|
|
24
|
+
export interface PullRequestSlim extends PullRequestBase {
|
|
25
|
+
readonly reviews: readonly {
|
|
26
|
+
readonly state: string;
|
|
27
|
+
readonly author: string | null;
|
|
28
|
+
}[];
|
|
29
|
+
}
|
|
30
|
+
export interface PullRequestReview {
|
|
31
|
+
readonly state: string;
|
|
32
|
+
readonly author: string | null;
|
|
33
|
+
readonly body: string;
|
|
34
|
+
readonly submitted_at: string | null;
|
|
35
|
+
}
|
|
36
|
+
export interface ReviewThreadComment {
|
|
37
|
+
readonly author: string | null;
|
|
38
|
+
readonly body: string;
|
|
39
|
+
readonly created_at: string | null;
|
|
40
|
+
}
|
|
41
|
+
export interface ReviewThread {
|
|
42
|
+
readonly is_resolved: boolean;
|
|
43
|
+
readonly path: string | null;
|
|
44
|
+
readonly line: number | null;
|
|
45
|
+
readonly comments: readonly ReviewThreadComment[];
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
GitHub のスタック。pullRequests は下の段からの PR 番号
|
|
49
|
+
*/
|
|
50
|
+
export interface PullRequestStack {
|
|
51
|
+
readonly number: number;
|
|
52
|
+
readonly pullRequests: readonly number[];
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
Stacks API が求める X-GitHub-Api-Version(https://docs.github.com/en/rest/pulls/stacks)
|
|
56
|
+
*/
|
|
57
|
+
export declare const STACKS_API_VERSION = "2026-03-10";
|
|
58
|
+
export interface PullRequestWithReviews extends PullRequestBase {
|
|
59
|
+
readonly reviews: readonly PullRequestReview[];
|
|
60
|
+
readonly review_threads: readonly ReviewThread[];
|
|
61
|
+
}
|
|
62
|
+
export declare class PullsApi extends IssuesApi {
|
|
63
|
+
private fetchPullRequest;
|
|
64
|
+
/**
|
|
65
|
+
head のブランチ名で PR を引く(open・closed・merged。新しい順に先頭 20 件)。
|
|
66
|
+
20 件に収まらないときは hasNextPage が真。リポが無ければ GitHubNotFoundError
|
|
67
|
+
*/
|
|
68
|
+
listPullRequestsByHead(owner: string, repository: string, headReferenceName: string): Promise<PullRequestsByHeadReadout>;
|
|
69
|
+
/**
|
|
70
|
+
PR を作る
|
|
71
|
+
*/
|
|
72
|
+
createPullRequest(owner: string, repository: string, title: string, body: string, head: string, base: string, isDraft?: boolean): Promise<JsonObject>;
|
|
73
|
+
/**
|
|
74
|
+
PR の詳細を取る(GraphQL)。関連 Issue とレビューを 1 回のクエリで取る
|
|
75
|
+
*/
|
|
76
|
+
getPullRequestSlim(owner: string, repository: string, number: number): Promise<PullRequestSlim>;
|
|
77
|
+
/**
|
|
78
|
+
PR の詳細をレビュー情報付きで取る。getPullRequestSlim に、レビュー本文と行コメント(reviewThreads)を足したもの
|
|
79
|
+
*/
|
|
80
|
+
getPullRequestWithReviews(owner: string, repository: string, number: number): Promise<PullRequestWithReviews>;
|
|
81
|
+
/**
|
|
82
|
+
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash
|
|
83
|
+
*/
|
|
84
|
+
mergePullRequest(owner: string, repository: string, number: number, mergeMethod?: string): Promise<JsonObject>;
|
|
85
|
+
/**
|
|
86
|
+
その PR が入っているスタックを読む。入っていなければ undefined。
|
|
87
|
+
スタックの機能が無いリポは GitHubNotFoundError
|
|
88
|
+
*/
|
|
89
|
+
getStackOfPullRequest(owner: string, repository: string, pullRequestNumber: number): Promise<PullRequestStack | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
スタックを作る。pullRequestNumbers は下の段からの順
|
|
92
|
+
*/
|
|
93
|
+
createStack(owner: string, repository: string, pullRequestNumbers: readonly number[]): Promise<PullRequestStack>;
|
|
94
|
+
/**
|
|
95
|
+
既にあるスタックの一番上に PR を足す。pullRequestNumbers は下からの順
|
|
96
|
+
*/
|
|
97
|
+
addToStack(owner: string, repository: string, stackNumber: number, pullRequestNumbers: readonly number[]): Promise<PullRequestStack>;
|
|
98
|
+
/**
|
|
99
|
+
open の dependabot の PR を全件取る(GraphQL)。pullRequests に author の引数が無いので、全ページを辿ってから絞る。
|
|
100
|
+
GraphQL のノードをそのまま返す
|
|
101
|
+
*/
|
|
102
|
+
listOpenDependabotPullRequests(owner: string, repository: string): Promise<readonly JsonObject[]>;
|
|
103
|
+
}
|
|
104
|
+
//# sourceMappingURL=pulls.d.ts.map
|