@pecot/workflow-mcp 0.0.0-stage → 5.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.claude-plugin/plugin.json +8 -0
- package/LICENSE +21 -0
- package/README.md +126 -2
- package/bin/pecot-workflow-mcp.mjs +10 -0
- package/cli/dist/cli.d.ts +26 -0
- package/cli/dist/cli.js +222 -0
- package/cli/dist/commands/cell-table.d.ts +3 -0
- package/cli/dist/commands/cell-table.js +495 -0
- package/cli/dist/commands/command-binding.d.ts +26 -0
- package/cli/dist/commands/command-binding.js +266 -0
- package/cli/dist/commands/command-definition.d.ts +136 -0
- package/cli/dist/commands/command-definition.js +101 -0
- package/cli/dist/commands/command-help.d.ts +8 -0
- package/cli/dist/commands/command-help.js +173 -0
- package/cli/dist/commands/command-stop.d.ts +19 -0
- package/cli/dist/commands/command-stop.js +30 -0
- package/cli/dist/commands/dependabot.d.ts +3 -0
- package/cli/dist/commands/dependabot.js +165 -0
- package/cli/dist/commands/directory-option.d.ts +7 -0
- package/cli/dist/commands/directory-option.js +48 -0
- package/cli/dist/commands/failure.d.ts +13 -0
- package/cli/dist/commands/failure.js +33 -0
- package/cli/dist/commands/fuzzy.d.ts +7 -0
- package/cli/dist/commands/fuzzy.js +79 -0
- package/cli/dist/commands/github-client.d.ts +12 -0
- package/cli/dist/commands/github-client.js +23 -0
- package/cli/dist/commands/global-options.d.ts +25 -0
- package/cli/dist/commands/global-options.js +83 -0
- package/cli/dist/commands/help-layout.d.ts +40 -0
- package/cli/dist/commands/help-layout.js +117 -0
- package/cli/dist/commands/help.d.ts +8 -0
- package/cli/dist/commands/help.js +55 -0
- package/cli/dist/commands/input-schema.d.ts +14 -0
- package/cli/dist/commands/input-schema.js +56 -0
- package/cli/dist/commands/issue-board.d.ts +38 -0
- package/cli/dist/commands/issue-board.js +62 -0
- package/cli/dist/commands/issue-comment.d.ts +3 -0
- package/cli/dist/commands/issue-comment.js +196 -0
- package/cli/dist/commands/issue-create.d.ts +3 -0
- package/cli/dist/commands/issue-create.js +329 -0
- package/cli/dist/commands/issue-project.d.ts +3 -0
- package/cli/dist/commands/issue-project.js +176 -0
- package/cli/dist/commands/issue-quick.d.ts +3 -0
- package/cli/dist/commands/issue-quick.js +126 -0
- package/cli/dist/commands/issue-read.d.ts +3 -0
- package/cli/dist/commands/issue-read.js +80 -0
- package/cli/dist/commands/issue-shared.d.ts +159 -0
- package/cli/dist/commands/issue-shared.js +419 -0
- package/cli/dist/commands/issue.d.ts +4 -0
- package/cli/dist/commands/issue.js +15 -0
- package/cli/dist/commands/names.d.ts +9 -0
- package/cli/dist/commands/names.js +16 -0
- package/cli/dist/commands/output.d.ts +78 -0
- package/cli/dist/commands/output.js +187 -0
- package/cli/dist/commands/pr.d.ts +3 -0
- package/cli/dist/commands/pr.js +933 -0
- package/cli/dist/commands/project-info.d.ts +48 -0
- package/cli/dist/commands/project-info.js +181 -0
- package/cli/dist/commands/project-sync.d.ts +91 -0
- package/cli/dist/commands/project-sync.js +273 -0
- package/cli/dist/commands/project.d.ts +5 -0
- package/cli/dist/commands/project.js +677 -0
- package/cli/dist/commands/registry.d.ts +6 -0
- package/cli/dist/commands/registry.js +27 -0
- package/cli/dist/commands/release.d.ts +10 -0
- package/cli/dist/commands/release.js +414 -0
- package/cli/dist/commands/repository-display.d.ts +3 -0
- package/cli/dist/commands/repository-display.js +7 -0
- package/cli/dist/commands/repository-match.d.ts +14 -0
- package/cli/dist/commands/repository-match.js +33 -0
- package/cli/dist/commands/repository.d.ts +5 -0
- package/cli/dist/commands/repository.js +265 -0
- package/cli/dist/commands/rich-panel.d.ts +22 -0
- package/cli/dist/commands/rich-panel.js +295 -0
- package/cli/dist/commands/security.d.ts +3 -0
- package/cli/dist/commands/security.js +164 -0
- package/cli/dist/commands/session.d.ts +3 -0
- package/cli/dist/commands/session.js +161 -0
- package/cli/dist/commands/tracker-sync.d.ts +58 -0
- package/cli/dist/commands/tracker-sync.js +53 -0
- package/cli/dist/commands/usage-error.d.ts +47 -0
- package/cli/dist/commands/usage-error.js +72 -0
- package/cli/dist/commands/value-types.d.ts +46 -0
- package/cli/dist/commands/value-types.js +94 -0
- package/cli/dist/commands/work-target.d.ts +13 -0
- package/cli/dist/commands/work-target.js +41 -0
- package/cli/dist/commands/worktree.d.ts +3 -0
- package/cli/dist/commands/worktree.js +335 -0
- package/cli/dist/domain/api-error-detail.d.ts +10 -0
- package/cli/dist/domain/api-error-detail.js +25 -0
- package/cli/dist/domain/branch-name.d.ts +5 -0
- package/cli/dist/domain/branch-name.js +10 -0
- package/cli/dist/domain/changelog.d.ts +43 -0
- package/cli/dist/domain/changelog.js +107 -0
- package/cli/dist/domain/config.d.ts +215 -0
- package/cli/dist/domain/config.js +300 -0
- package/cli/dist/domain/dependabot-pull-requests.d.ts +82 -0
- package/cli/dist/domain/dependabot-pull-requests.js +338 -0
- package/cli/dist/domain/dependabot-source.d.ts +51 -0
- package/cli/dist/domain/dependabot-source.js +4 -0
- package/cli/dist/domain/dependabot.d.ts +47 -0
- package/cli/dist/domain/dependabot.js +88 -0
- package/cli/dist/domain/errors.d.ts +19 -0
- package/cli/dist/domain/errors.js +31 -0
- package/cli/dist/domain/field-options.d.ts +31 -0
- package/cli/dist/domain/field-options.js +44 -0
- package/cli/dist/domain/format.d.ts +47 -0
- package/cli/dist/domain/format.js +168 -0
- package/cli/dist/domain/frontmatter.d.ts +122 -0
- package/cli/dist/domain/frontmatter.js +264 -0
- package/cli/dist/domain/git-runner.d.ts +10 -0
- package/cli/dist/domain/git-runner.js +4 -0
- package/cli/dist/domain/git-url.d.ts +17 -0
- package/cli/dist/domain/git-url.js +30 -0
- package/cli/dist/domain/issue-kind.d.ts +16 -0
- package/cli/dist/domain/issue-kind.js +16 -0
- package/cli/dist/domain/issue-readout.d.ts +107 -0
- package/cli/dist/domain/issue-readout.js +4 -0
- package/cli/dist/domain/json-null.d.ts +2 -0
- package/cli/dist/domain/json-null.js +5 -0
- package/cli/dist/domain/json.d.ts +21 -0
- package/cli/dist/domain/json.js +47 -0
- package/cli/dist/domain/prerequisites.d.ts +32 -0
- package/cli/dist/domain/prerequisites.js +192 -0
- package/cli/dist/domain/pull-request.d.ts +134 -0
- package/cli/dist/domain/pull-request.js +232 -0
- package/cli/dist/domain/python-format.d.ts +105 -0
- package/cli/dist/domain/python-format.js +304 -0
- package/cli/dist/domain/readiness.d.ts +172 -0
- package/cli/dist/domain/readiness.js +280 -0
- package/cli/dist/domain/reference-parser.d.ts +49 -0
- package/cli/dist/domain/reference-parser.js +119 -0
- package/cli/dist/domain/release.d.ts +49 -0
- package/cli/dist/domain/release.js +72 -0
- package/cli/dist/domain/repository-policy.d.ts +32 -0
- package/cli/dist/domain/repository-policy.js +65 -0
- package/cli/dist/domain/repository-resolver.d.ts +57 -0
- package/cli/dist/domain/repository-resolver.js +119 -0
- package/cli/dist/domain/sections.d.ts +69 -0
- package/cli/dist/domain/sections.js +514 -0
- package/cli/dist/domain/security-alerts-source.d.ts +29 -0
- package/cli/dist/domain/security-alerts-source.js +4 -0
- package/cli/dist/domain/security-alerts.d.ts +52 -0
- package/cli/dist/domain/security-alerts.js +107 -0
- package/cli/dist/domain/security-tracker.d.ts +115 -0
- package/cli/dist/domain/security-tracker.js +353 -0
- package/cli/dist/domain/state.d.ts +29 -0
- package/cli/dist/domain/state.js +56 -0
- package/cli/dist/domain/tracker-body.d.ts +70 -0
- package/cli/dist/domain/tracker-body.js +65 -0
- package/cli/dist/domain/yaml-document.d.ts +5 -0
- package/cli/dist/domain/yaml-document.js +206 -0
- package/cli/dist/infra/authored-notes.d.ts +37 -0
- package/cli/dist/infra/authored-notes.js +66 -0
- package/cli/dist/infra/changelog-file.d.ts +19 -0
- package/cli/dist/infra/changelog-file.js +43 -0
- package/cli/dist/infra/child-stdin.d.ts +4 -0
- package/cli/dist/infra/child-stdin.js +8 -0
- package/cli/dist/infra/config-store.d.ts +49 -0
- package/cli/dist/infra/config-store.js +121 -0
- package/cli/dist/infra/diagnostics.d.ts +9 -0
- package/cli/dist/infra/diagnostics.js +2 -0
- package/cli/dist/infra/file-kind.d.ts +9 -0
- package/cli/dist/infra/file-kind.js +26 -0
- package/cli/dist/infra/frontmatter-file.d.ts +14 -0
- package/cli/dist/infra/frontmatter-file.js +30 -0
- package/cli/dist/infra/git.d.ts +74 -0
- package/cli/dist/infra/git.js +133 -0
- package/cli/dist/infra/github/auth.d.ts +60 -0
- package/cli/dist/infra/github/auth.js +158 -0
- package/cli/dist/infra/github/client.d.ts +173 -0
- package/cli/dist/infra/github/client.js +576 -0
- package/cli/dist/infra/github/dependabot-source.d.ts +13 -0
- package/cli/dist/infra/github/dependabot-source.js +33 -0
- package/cli/dist/infra/github/errors.d.ts +47 -0
- package/cli/dist/infra/github/errors.js +42 -0
- package/cli/dist/infra/github/index.d.ts +13 -0
- package/cli/dist/infra/github/index.js +19 -0
- package/cli/dist/infra/github/issues.d.ts +129 -0
- package/cli/dist/infra/github/issues.js +273 -0
- package/cli/dist/infra/github/payload.d.ts +44 -0
- package/cli/dist/infra/github/payload.js +80 -0
- package/cli/dist/infra/github/projects.d.ts +108 -0
- package/cli/dist/infra/github/projects.js +303 -0
- package/cli/dist/infra/github/pulls.d.ts +80 -0
- package/cli/dist/infra/github/pulls.js +161 -0
- package/cli/dist/infra/github/queries.d.ts +36 -0
- package/cli/dist/infra/github/queries.js +883 -0
- package/cli/dist/infra/github/readout.d.ts +18 -0
- package/cli/dist/infra/github/readout.js +156 -0
- package/cli/dist/infra/github/repos.d.ts +68 -0
- package/cli/dist/infra/github/repos.js +137 -0
- package/cli/dist/infra/github/rest-path.d.ts +14 -0
- package/cli/dist/infra/github/rest-path.js +31 -0
- package/cli/dist/infra/github/security-alerts-source.d.ts +15 -0
- package/cli/dist/infra/github/security-alerts-source.js +73 -0
- package/cli/dist/infra/gitignore-spec.d.ts +36 -0
- package/cli/dist/infra/gitignore-spec.js +235 -0
- package/cli/dist/infra/nx-scope.d.ts +51 -0
- package/cli/dist/infra/nx-scope.js +182 -0
- package/cli/dist/infra/os-error.d.ts +24 -0
- package/cli/dist/infra/os-error.js +38 -0
- package/cli/dist/infra/paths.d.ts +88 -0
- package/cli/dist/infra/paths.js +234 -0
- package/cli/dist/infra/state-store.d.ts +45 -0
- package/cli/dist/infra/state-store.js +118 -0
- package/cli/dist/infra/template-store.d.ts +15 -0
- package/cli/dist/infra/template-store.js +34 -0
- package/cli/dist/infra/text-file.d.ts +12 -0
- package/cli/dist/infra/text-file.js +33 -0
- package/cli/dist/infra/worktree-copy.d.ts +24 -0
- package/cli/dist/infra/worktree-copy.js +95 -0
- package/cli/dist/infra/worktree-links.d.ts +139 -0
- package/cli/dist/infra/worktree-links.js +433 -0
- package/cli/dist/infra/worktree-setup.d.ts +21 -0
- package/cli/dist/infra/worktree-setup.js +41 -0
- package/cli/dist/infra/worktree.d.ts +174 -0
- package/cli/dist/infra/worktree.js +567 -0
- package/cli/dist/mcp/result.d.ts +33 -0
- package/cli/dist/mcp/result.js +52 -0
- package/cli/dist/mcp/serve.d.ts +51 -0
- package/cli/dist/mcp/serve.js +183 -0
- package/cli/dist/mcp/server.d.ts +21 -0
- package/cli/dist/mcp/server.js +128 -0
- package/cli/dist/mcp/session-directory.d.ts +26 -0
- package/cli/dist/mcp/session-directory.js +84 -0
- package/cli/dist/package.json +1 -0
- package/cli/dist/version.d.ts +17 -0
- package/cli/dist/version.js +42 -0
- package/cli/templates/comment/merge-diff.md +34 -0
- package/cli/templates/comment/plan.md +181 -0
- package/cli/templates/comment/precede-notify.md +33 -0
- package/cli/templates/comment/review-findings.md +42 -0
- package/cli/templates/comment/review-resolution.md +48 -0
- package/cli/templates/issue/bug.md +63 -0
- package/cli/templates/issue/epic.md +54 -0
- package/cli/templates/issue/task-implement.md +67 -0
- package/cli/templates/issue/task.md +48 -0
- package/cli/templates/issue/tracker.md +48 -0
- package/cli/templates/pr/create.md +123 -0
- package/cli/templates/pr/release.md +56 -0
- package/hooks/lib/core/pecot-gitignore-ensure.sh +48 -0
- package/npm-shrinkwrap.json +83 -0
- package/package.json +22 -4
|
@@ -0,0 +1,108 @@
|
|
|
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 { ReposApi } from './repos.js';
|
|
5
|
+
export interface ListProjectItemsOptions {
|
|
6
|
+
/**
|
|
7
|
+
取得する最大件数。省略または 0 なら全件
|
|
8
|
+
*/
|
|
9
|
+
readonly limit?: number | undefined;
|
|
10
|
+
/**
|
|
11
|
+
Archived を除外する。連続して 50 件 Archived が続いたら打ち切る
|
|
12
|
+
*/
|
|
13
|
+
readonly excludeArchived?: boolean | undefined;
|
|
14
|
+
/**
|
|
15
|
+
excludeArchived のとき、ステータスを見るフィールド名
|
|
16
|
+
*/
|
|
17
|
+
readonly workflowFieldName?: string | undefined;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
SingleSelect フィールドの選択肢
|
|
21
|
+
*/
|
|
22
|
+
export type ProjectFieldOption = Readonly<{
|
|
23
|
+
name: string;
|
|
24
|
+
color: string;
|
|
25
|
+
description: string;
|
|
26
|
+
}>;
|
|
27
|
+
/**
|
|
28
|
+
プロジェクトへのリンクの結果。detail は GitHub の message をそのまま入れる(成功時は空文字列)
|
|
29
|
+
*/
|
|
30
|
+
export interface LinkResult {
|
|
31
|
+
readonly status: 'linked' | 'already_linked' | 'failed';
|
|
32
|
+
readonly detail: string;
|
|
33
|
+
}
|
|
34
|
+
export declare class ProjectsApi extends ReposApi {
|
|
35
|
+
private queryAsUser;
|
|
36
|
+
/**
|
|
37
|
+
プロジェクトボードのアイテムを取得する(ページネーション対応)
|
|
38
|
+
*/
|
|
39
|
+
listProjectItems(projectId: string, options?: Readonly<ListProjectItemsOptions>): Promise<readonly JsonObject[]>;
|
|
40
|
+
/**
|
|
41
|
+
Issue をプロジェクトボードに追加し、作られたアイテムの ID を返す
|
|
42
|
+
*/
|
|
43
|
+
addToProject(projectId: string, contentId: string): Promise<string>;
|
|
44
|
+
/**
|
|
45
|
+
プロジェクトアイテムの SingleSelect フィールドの値を更新し、アイテムの ID を返す
|
|
46
|
+
*/
|
|
47
|
+
updateProjectItemField(projectId: string, itemId: string, fieldId: string, optionId: string): Promise<string>;
|
|
48
|
+
/**
|
|
49
|
+
プロジェクトボードからアイテムを削除し、削除したアイテムの ID を返す
|
|
50
|
+
*/
|
|
51
|
+
deleteProjectItem(projectId: string, itemId: string): Promise<string>;
|
|
52
|
+
/**
|
|
53
|
+
プロジェクトにリンクされたリポジトリの一覧。user 所有を先に試し、無ければ organization 所有を試す
|
|
54
|
+
*/
|
|
55
|
+
getLinkedRepositories(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
56
|
+
/**
|
|
57
|
+
リンクされたリポジトリの一覧(キャッシュ付き)。同じクライアントの中で同じ引数なら、2 回目以降はキャッシュを返す
|
|
58
|
+
*/
|
|
59
|
+
getLinkedRepositoriesCached(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
60
|
+
/**
|
|
61
|
+
RepositoryMembership(domain/config.ts)の実体。キャッシュ付きの一覧を返す
|
|
62
|
+
*/
|
|
63
|
+
linkedRepositories(owner: string, projectNumber: number): Promise<readonly LinkedRepository[]>;
|
|
64
|
+
/**
|
|
65
|
+
プロジェクト番号から GraphQL Node ID を取る。user 所有を先に試す。無ければ GitHubNotFoundError
|
|
66
|
+
*/
|
|
67
|
+
getProjectId(owner: string, projectNumber: number): Promise<string>;
|
|
68
|
+
/**
|
|
69
|
+
Issue 番号から、指定のプロジェクトの中のアイテム ID を取る。
|
|
70
|
+
Issue から直接引くので、全アイテムの走査は要らない。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
71
|
+
*/
|
|
72
|
+
getItemIdByIssue(projectId: string, owner: string, repository: string, issueNumber: number): Promise<string | undefined>;
|
|
73
|
+
/**
|
|
74
|
+
プロジェクトアイテムで値が入っている単一選択フィールドの ID を取る。アイテムが見つからなければ空
|
|
75
|
+
*/
|
|
76
|
+
getItemSetFieldIds(projectId: string, owner: string, repository: string, issueNumber: number, itemId: string): Promise<ReadonlySet<string>>;
|
|
77
|
+
/**
|
|
78
|
+
プロジェクトにリポジトリをリンクする。
|
|
79
|
+
リンクした(linked)、既にリンク済み(already_linked)、失敗(failed)のいずれも例外にせず結果で返す
|
|
80
|
+
*/
|
|
81
|
+
linkRepositoryToProject(owner: string, projectNumber: number, repositoryOwner: string, repositoryName: string): Promise<LinkResult>;
|
|
82
|
+
/**
|
|
83
|
+
オーナーのプロジェクト一覧(number・title・url・id)。user 所有を先に試す
|
|
84
|
+
*/
|
|
85
|
+
listProjects(owner: string, limit?: number): Promise<readonly JsonObject[]>;
|
|
86
|
+
/**
|
|
87
|
+
プロジェクトの情報(id・title・url・fields)。user 所有を先に試す。見つからなければ undefined
|
|
88
|
+
*/
|
|
89
|
+
getProjectFields(owner: string, projectNumber: number): Promise<JsonObject | undefined>;
|
|
90
|
+
/**
|
|
91
|
+
プロジェクトに SingleSelect フィールドを作り、作ったフィールド(id・name・options)を返す
|
|
92
|
+
*/
|
|
93
|
+
createProjectField(projectId: string, name: string, options: readonly ProjectFieldOption[]): Promise<JsonObject>;
|
|
94
|
+
/**
|
|
95
|
+
SingleSelect フィールドの選択肢を、渡した一覧に置き換え、更新後のフィールド(id・name・options)を返す。
|
|
96
|
+
既存の選択肢は id を付けて渡す(外すと選択肢が作り直され、カードの値が消える)
|
|
97
|
+
*/
|
|
98
|
+
updateProjectFieldOptions(fieldId: string, options: readonly FieldOptionInput[]): Promise<JsonObject>;
|
|
99
|
+
/**
|
|
100
|
+
オーナー(user か organization)の GraphQL Node ID。user を先に試し、無ければ GitHubNotFoundError
|
|
101
|
+
*/
|
|
102
|
+
getOwnerNodeId(owner: string): Promise<string>;
|
|
103
|
+
/**
|
|
104
|
+
GitHub Projects V2 を作り、作ったプロジェクト(id・number・title・url)を返す
|
|
105
|
+
*/
|
|
106
|
+
createProject(ownerId: string, title: string): Promise<JsonObject>;
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=projects.d.ts.map
|
|
@@ -0,0 +1,303 @@
|
|
|
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 { GitHubAPIError, GitHubNotFoundError } 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_LINK_PROJECT_REPOSITORY, MUTATION_UPDATE_PROJECT_FIELD, MUTATION_UPDATE_PROJECT_ITEM_FIELD, 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_PROJECTS_ORG, QUERY_LIST_PROJECTS_USER, } from './queries.js';
|
|
8
|
+
import { ReposApi } from './repos.js';
|
|
9
|
+
const MAX_ARCHIVED_CONSECUTIVE = 50;
|
|
10
|
+
const DEFAULT_PROJECT_LIMIT = 20;
|
|
11
|
+
function lowerText(value) {
|
|
12
|
+
return typeof value === 'string' ? value.toLowerCase() : '';
|
|
13
|
+
}
|
|
14
|
+
// ワークフローのフィールドの値が Archived か。そのフィールドが無ければ false
|
|
15
|
+
function isItemArchived(item, workflowFieldName) {
|
|
16
|
+
const target = workflowFieldName.toLowerCase();
|
|
17
|
+
const fieldValues = truthyNodes(jsonField(item, 'fieldValues'));
|
|
18
|
+
for (const node of fieldValues) {
|
|
19
|
+
if (lowerText(jsonField(jsonField(node, 'field'), 'name')) === target)
|
|
20
|
+
return lowerText(jsonField(node, 'name')) === 'archived';
|
|
21
|
+
}
|
|
22
|
+
return false;
|
|
23
|
+
}
|
|
24
|
+
// オブジェクトの要素だけを残す(null などは落とす)
|
|
25
|
+
function objectsOf(items) {
|
|
26
|
+
return items.filter(item => isJsonObject(item));
|
|
27
|
+
}
|
|
28
|
+
function linkedRepositoriesOf(project) {
|
|
29
|
+
return truthyNodes(jsonField(project, 'repositories')).map(node => ({
|
|
30
|
+
owner: requireString(jsonField(jsonField(node, 'owner'), 'login'), 'repositories.nodes.owner.login'),
|
|
31
|
+
name: requireString(jsonField(node, 'name'), 'repositories.nodes.name'),
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
export class ProjectsApi extends ReposApi {
|
|
35
|
+
// user のクエリ。GitHub の失敗は、認証エラーとレート制限も含めて undefined にし、org のクエリへ進む。
|
|
36
|
+
// Python と同じ動き
|
|
37
|
+
async queryAsUser(query, variables) {
|
|
38
|
+
try {
|
|
39
|
+
return await this.executeGraphql(query, variables);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
if (error instanceof GitHubAPIError)
|
|
43
|
+
return undefined;
|
|
44
|
+
throw error;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
プロジェクトボードのアイテムを取得する(ページネーション対応)
|
|
49
|
+
*/
|
|
50
|
+
async listProjectItems(projectId, options = {}) {
|
|
51
|
+
const { limit, excludeArchived = false, workflowFieldName = '' } = options;
|
|
52
|
+
let allItems = [];
|
|
53
|
+
let cursor = JSON_NULL;
|
|
54
|
+
let archivedConsecutive = 0;
|
|
55
|
+
for (;;) {
|
|
56
|
+
const result = await this.executeGraphql(QUERY_LIST_PROJECT_ITEMS, { projectId, cursor });
|
|
57
|
+
const node = jsonField(result, 'node');
|
|
58
|
+
if (!isTruthy(node))
|
|
59
|
+
break;
|
|
60
|
+
const itemsData = asObject(jsonField(node, 'items'));
|
|
61
|
+
const nodes = asArray(jsonField(itemsData, 'nodes'));
|
|
62
|
+
if (excludeArchived) {
|
|
63
|
+
for (const item of nodes) {
|
|
64
|
+
if (isItemArchived(item, workflowFieldName)) {
|
|
65
|
+
archivedConsecutive += 1;
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
allItems.push(item);
|
|
69
|
+
archivedConsecutive = 0;
|
|
70
|
+
}
|
|
71
|
+
if (archivedConsecutive >= MAX_ARCHIVED_CONSECUTIVE)
|
|
72
|
+
return objectsOf(allItems);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
else {
|
|
76
|
+
allItems.push(...nodes);
|
|
77
|
+
}
|
|
78
|
+
if (limit !== undefined && limit > 0 && allItems.length >= limit) {
|
|
79
|
+
allItems = allItems.slice(0, limit);
|
|
80
|
+
break;
|
|
81
|
+
}
|
|
82
|
+
const pageInfo = asObject(jsonField(itemsData, 'pageInfo'));
|
|
83
|
+
if (!isTruthy(pageInfo['hasNextPage']))
|
|
84
|
+
break;
|
|
85
|
+
// 次のページがあるのに cursor が無いと、先頭から取り直して終わらない
|
|
86
|
+
const endCursor = pageInfo['endCursor'];
|
|
87
|
+
if (typeof endCursor !== 'string')
|
|
88
|
+
throw new GitHubAPIError('could not get the cursor for the next page');
|
|
89
|
+
cursor = endCursor;
|
|
90
|
+
}
|
|
91
|
+
return objectsOf(allItems);
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
Issue をプロジェクトボードに追加し、作られたアイテムの ID を返す
|
|
95
|
+
*/
|
|
96
|
+
async addToProject(projectId, contentId) {
|
|
97
|
+
const result = await this.executeGraphql(MUTATION_ADD_TO_PROJECT, { projectId, contentId });
|
|
98
|
+
const item = jsonField(jsonField(result, 'addProjectV2ItemById'), 'item');
|
|
99
|
+
if (!isTruthy(item))
|
|
100
|
+
throw new GitHubAPIError('failed to add the item to the project');
|
|
101
|
+
return requireString(jsonField(item, 'id'), 'item.id');
|
|
102
|
+
}
|
|
103
|
+
/**
|
|
104
|
+
プロジェクトアイテムの SingleSelect フィールドの値を更新し、アイテムの ID を返す
|
|
105
|
+
*/
|
|
106
|
+
async updateProjectItemField(projectId, itemId, fieldId, optionId) {
|
|
107
|
+
const result = await this.executeGraphql(MUTATION_UPDATE_PROJECT_ITEM_FIELD, { projectId, itemId, fieldId, optionId });
|
|
108
|
+
const item = jsonField(jsonField(result, 'updateProjectV2ItemFieldValue'), 'projectV2Item');
|
|
109
|
+
if (!isTruthy(item))
|
|
110
|
+
throw new GitHubAPIError('failed to update the field');
|
|
111
|
+
return requireString(jsonField(item, 'id'), 'projectV2Item.id');
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
プロジェクトボードからアイテムを削除し、削除したアイテムの ID を返す
|
|
115
|
+
*/
|
|
116
|
+
async deleteProjectItem(projectId, itemId) {
|
|
117
|
+
const result = await this.executeGraphql(MUTATION_DELETE_PROJECT_ITEM, { projectId, itemId });
|
|
118
|
+
const deletedId = jsonField(jsonField(result, 'deleteProjectV2Item'), 'deletedItemId');
|
|
119
|
+
if (!isTruthy(deletedId))
|
|
120
|
+
throw new GitHubAPIError('failed to delete the project item');
|
|
121
|
+
return requireString(deletedId, 'deletedItemId');
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
プロジェクトにリンクされたリポジトリの一覧。user 所有を先に試し、無ければ organization 所有を試す
|
|
125
|
+
*/
|
|
126
|
+
async getLinkedRepositories(owner, projectNumber) {
|
|
127
|
+
const variables = { owner, projectNumber };
|
|
128
|
+
const userResult = await this.queryAsUser(QUERY_GET_LINKED_REPOSITORIES_USER, variables);
|
|
129
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
130
|
+
if (isTruthy(userProject))
|
|
131
|
+
return linkedRepositoriesOf(userProject);
|
|
132
|
+
const orgResult = await this.executeGraphql(QUERY_GET_LINKED_REPOSITORIES_ORG, variables);
|
|
133
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
134
|
+
return isTruthy(organizationProject) ? linkedRepositoriesOf(organizationProject) : [];
|
|
135
|
+
}
|
|
136
|
+
/**
|
|
137
|
+
リンクされたリポジトリの一覧(キャッシュ付き)。同じクライアントの中で同じ引数なら、2 回目以降はキャッシュを返す
|
|
138
|
+
*/
|
|
139
|
+
async getLinkedRepositoriesCached(owner, projectNumber) {
|
|
140
|
+
const cacheKey = `${owner}/${String(projectNumber)}`;
|
|
141
|
+
const cached = this.linkedRepositoriesCache.get(cacheKey);
|
|
142
|
+
if (cached !== undefined)
|
|
143
|
+
return cached;
|
|
144
|
+
const repositories = await this.getLinkedRepositories(owner, projectNumber);
|
|
145
|
+
this.linkedRepositoriesCache.set(cacheKey, repositories);
|
|
146
|
+
return repositories;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
RepositoryMembership(domain/config.ts)の実体。キャッシュ付きの一覧を返す
|
|
150
|
+
*/
|
|
151
|
+
async linkedRepositories(owner, projectNumber) {
|
|
152
|
+
return this.getLinkedRepositoriesCached(owner, projectNumber);
|
|
153
|
+
}
|
|
154
|
+
/**
|
|
155
|
+
プロジェクト番号から GraphQL Node ID を取る。user 所有を先に試す。無ければ GitHubNotFoundError
|
|
156
|
+
*/
|
|
157
|
+
async getProjectId(owner, projectNumber) {
|
|
158
|
+
const variables = { owner, projectNumber };
|
|
159
|
+
const userResult = await this.queryAsUser(QUERY_GET_PROJECT_ID_USER, variables);
|
|
160
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
161
|
+
if (isTruthy(userProject))
|
|
162
|
+
return requireString(jsonField(userProject, 'id'), 'projectV2.id');
|
|
163
|
+
const orgResult = await this.executeGraphql(QUERY_GET_PROJECT_ID_ORG, variables);
|
|
164
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
165
|
+
if (isTruthy(organizationProject))
|
|
166
|
+
return requireString(jsonField(organizationProject, 'id'), 'projectV2.id');
|
|
167
|
+
throw new GitHubNotFoundError(`project not found: ${owner}/projects/${String(projectNumber)}`);
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
Issue 番号から、指定のプロジェクトの中のアイテム ID を取る。
|
|
171
|
+
Issue から直接引くので、全アイテムの走査は要らない。Issue やリポジトリが無い、またはプロジェクトに無ければ undefined
|
|
172
|
+
*/
|
|
173
|
+
async getItemIdByIssue(projectId, owner, repository, issueNumber) {
|
|
174
|
+
const result = await this.executeGraphql(QUERY_GET_ISSUE_PROJECT_ITEMS, { owner, repo: repository, number: issueNumber });
|
|
175
|
+
const repositoryNode = jsonField(result, 'repository');
|
|
176
|
+
if (!isTruthy(repositoryNode))
|
|
177
|
+
return undefined;
|
|
178
|
+
const issue = jsonField(repositoryNode, 'issue');
|
|
179
|
+
if (!isTruthy(issue))
|
|
180
|
+
return undefined;
|
|
181
|
+
const projectItems = truthyNodes(jsonField(issue, 'projectItems'));
|
|
182
|
+
for (const item of projectItems) {
|
|
183
|
+
if (jsonField(jsonField(item, 'project'), 'id') === projectId)
|
|
184
|
+
return requireString(jsonField(item, 'id'), 'projectItems.nodes.id');
|
|
185
|
+
}
|
|
186
|
+
return undefined;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
プロジェクトアイテムで値が入っている単一選択フィールドの ID を取る。アイテムが見つからなければ空
|
|
190
|
+
*/
|
|
191
|
+
async getItemSetFieldIds(projectId, owner, repository, issueNumber, itemId) {
|
|
192
|
+
const result = await this.executeGraphql(QUERY_GET_ISSUE_PROJECT_ITEMS, { owner, repo: repository, number: issueNumber });
|
|
193
|
+
const issue = jsonField(jsonField(result, 'repository'), 'issue');
|
|
194
|
+
const fieldIds = new Set();
|
|
195
|
+
const items = truthyNodes(jsonField(issue, 'projectItems'));
|
|
196
|
+
for (const item of items) {
|
|
197
|
+
if (jsonField(item, 'id') !== itemId || jsonField(jsonField(item, 'project'), 'id') !== projectId)
|
|
198
|
+
continue;
|
|
199
|
+
const values = truthyNodes(jsonField(item, 'fieldValues'));
|
|
200
|
+
for (const value of values) {
|
|
201
|
+
const fieldId = jsonField(jsonField(value, 'field'), 'id');
|
|
202
|
+
if (typeof fieldId === 'string')
|
|
203
|
+
fieldIds.add(fieldId);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
return fieldIds;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
プロジェクトにリポジトリをリンクする。
|
|
210
|
+
リンクした(linked)、既にリンク済み(already_linked)、失敗(failed)のいずれも例外にせず結果で返す
|
|
211
|
+
*/
|
|
212
|
+
async linkRepositoryToProject(owner, projectNumber, repositoryOwner, repositoryName) {
|
|
213
|
+
try {
|
|
214
|
+
const projectId = await this.getProjectId(owner, projectNumber);
|
|
215
|
+
const repositoryId = await this.getRepositoryId(repositoryOwner, repositoryName);
|
|
216
|
+
const result = await this.executeGraphql(MUTATION_LINK_PROJECT_REPOSITORY, { projectId, repositoryId });
|
|
217
|
+
const linked = jsonField(jsonField(result, 'linkProjectV2ToRepository'), 'repository');
|
|
218
|
+
return isTruthy(linked) ? { status: 'linked', detail: '' } : { status: 'failed', detail: 'unexpected response' };
|
|
219
|
+
}
|
|
220
|
+
catch (error) {
|
|
221
|
+
if (error instanceof GitHubNotFoundError)
|
|
222
|
+
return { status: 'failed', detail: error.message };
|
|
223
|
+
if (error instanceof GitHubAPIError) {
|
|
224
|
+
const lowered = error.message.toLowerCase();
|
|
225
|
+
const isAlreadyLinked = lowered.includes('already linked') || lowered.includes('already exists');
|
|
226
|
+
return { status: isAlreadyLinked ? 'already_linked' : 'failed', detail: error.message };
|
|
227
|
+
}
|
|
228
|
+
throw error;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
オーナーのプロジェクト一覧(number・title・url・id)。user 所有を先に試す
|
|
233
|
+
*/
|
|
234
|
+
async listProjects(owner, limit = DEFAULT_PROJECT_LIMIT) {
|
|
235
|
+
const variables = { owner, first: limit };
|
|
236
|
+
const userResult = await this.queryAsUser(QUERY_LIST_PROJECTS_USER, variables);
|
|
237
|
+
const userProjects = jsonField(jsonField(userResult, 'user'), 'projectsV2');
|
|
238
|
+
if (isTruthy(userProjects))
|
|
239
|
+
return objectsOf(truthyNodes(userProjects));
|
|
240
|
+
const orgResult = await this.executeGraphql(QUERY_LIST_PROJECTS_ORG, variables);
|
|
241
|
+
const organizationProjects = jsonField(jsonField(orgResult, 'organization'), 'projectsV2');
|
|
242
|
+
return isTruthy(organizationProjects) ? objectsOf(truthyNodes(organizationProjects)) : [];
|
|
243
|
+
}
|
|
244
|
+
/**
|
|
245
|
+
プロジェクトの情報(id・title・url・fields)。user 所有を先に試す。見つからなければ undefined
|
|
246
|
+
*/
|
|
247
|
+
async getProjectFields(owner, projectNumber) {
|
|
248
|
+
const variables = { owner, projectNumber };
|
|
249
|
+
const userResult = await this.queryAsUser(QUERY_GET_PROJECT_FIELDS_USER, variables);
|
|
250
|
+
const userProject = jsonField(jsonField(userResult, 'user'), 'projectV2');
|
|
251
|
+
if (isTruthy(userProject))
|
|
252
|
+
return asObject(userProject);
|
|
253
|
+
const orgResult = await this.executeGraphql(QUERY_GET_PROJECT_FIELDS_ORG, variables);
|
|
254
|
+
const organizationProject = jsonField(jsonField(orgResult, 'organization'), 'projectV2');
|
|
255
|
+
return isTruthy(organizationProject) ? asObject(organizationProject) : undefined;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
プロジェクトに SingleSelect フィールドを作り、作ったフィールド(id・name・options)を返す
|
|
259
|
+
*/
|
|
260
|
+
async createProjectField(projectId, name, options) {
|
|
261
|
+
const result = await this.executeGraphql(MUTATION_CREATE_PROJECT_FIELD, { projectId, name, options });
|
|
262
|
+
const created = jsonField(jsonField(result, 'createProjectV2Field'), 'projectV2Field');
|
|
263
|
+
if (!isTruthy(created))
|
|
264
|
+
throw new GitHubAPIError('failed to create the field');
|
|
265
|
+
return asObject(created);
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
SingleSelect フィールドの選択肢を、渡した一覧に置き換え、更新後のフィールド(id・name・options)を返す。
|
|
269
|
+
既存の選択肢は id を付けて渡す(外すと選択肢が作り直され、カードの値が消える)
|
|
270
|
+
*/
|
|
271
|
+
async updateProjectFieldOptions(fieldId, options) {
|
|
272
|
+
const result = await this.executeGraphql(MUTATION_UPDATE_PROJECT_FIELD, { fieldId, options });
|
|
273
|
+
const updated = jsonField(jsonField(result, 'updateProjectV2Field'), 'projectV2Field');
|
|
274
|
+
if (!isTruthy(updated))
|
|
275
|
+
throw new GitHubAPIError('failed to update the field');
|
|
276
|
+
return asObject(updated);
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
オーナー(user か organization)の GraphQL Node ID。user を先に試し、無ければ GitHubNotFoundError
|
|
280
|
+
*/
|
|
281
|
+
async getOwnerNodeId(owner) {
|
|
282
|
+
const userResult = await this.queryAsUser(QUERY_GET_USER_NODE_ID, { login: owner });
|
|
283
|
+
const userId = jsonField(jsonField(userResult, 'user'), 'id');
|
|
284
|
+
if (isTruthy(userId))
|
|
285
|
+
return requireString(userId, 'user.id');
|
|
286
|
+
const orgResult = await this.executeGraphql(QUERY_GET_ORG_NODE_ID, { login: owner });
|
|
287
|
+
const organizationId = jsonField(jsonField(orgResult, 'organization'), 'id');
|
|
288
|
+
if (isTruthy(organizationId))
|
|
289
|
+
return requireString(organizationId, 'organization.id');
|
|
290
|
+
throw new GitHubNotFoundError(`owner not found: ${owner}`);
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
GitHub Projects V2 を作り、作ったプロジェクト(id・number・title・url)を返す
|
|
294
|
+
*/
|
|
295
|
+
async createProject(ownerId, title) {
|
|
296
|
+
const result = await this.executeGraphql(MUTATION_CREATE_PROJECT, { ownerId, title });
|
|
297
|
+
const project = jsonField(jsonField(result, 'createProjectV2'), 'projectV2');
|
|
298
|
+
if (!isTruthy(project))
|
|
299
|
+
throw new GitHubAPIError('failed to create the project');
|
|
300
|
+
return asObject(project);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
//# sourceMappingURL=projects.js.map
|
|
@@ -0,0 +1,80 @@
|
|
|
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
|
+
export interface PullRequestWithReviews extends PullRequestBase {
|
|
48
|
+
readonly reviews: readonly PullRequestReview[];
|
|
49
|
+
readonly review_threads: readonly ReviewThread[];
|
|
50
|
+
}
|
|
51
|
+
export declare class PullsApi extends IssuesApi {
|
|
52
|
+
private fetchPullRequest;
|
|
53
|
+
/**
|
|
54
|
+
head のブランチ名で PR を引く(open・closed・merged。新しい順に先頭 20 件)。
|
|
55
|
+
20 件に収まらないときは hasNextPage が真。リポが無ければ GitHubNotFoundError
|
|
56
|
+
*/
|
|
57
|
+
listPullRequestsByHead(owner: string, repository: string, headReferenceName: string): Promise<PullRequestsByHeadReadout>;
|
|
58
|
+
/**
|
|
59
|
+
PR を作る
|
|
60
|
+
*/
|
|
61
|
+
createPullRequest(owner: string, repository: string, title: string, body: string, head: string, base: string, isDraft?: boolean): Promise<JsonObject>;
|
|
62
|
+
/**
|
|
63
|
+
PR の詳細を取る(GraphQL)。関連 Issue とレビューを 1 回のクエリで取る
|
|
64
|
+
*/
|
|
65
|
+
getPullRequestSlim(owner: string, repository: string, number: number): Promise<PullRequestSlim>;
|
|
66
|
+
/**
|
|
67
|
+
PR の詳細をレビュー情報付きで取る。getPullRequestSlim に、レビュー本文と行コメント(reviewThreads)を足したもの
|
|
68
|
+
*/
|
|
69
|
+
getPullRequestWithReviews(owner: string, repository: string, number: number): Promise<PullRequestWithReviews>;
|
|
70
|
+
/**
|
|
71
|
+
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash
|
|
72
|
+
*/
|
|
73
|
+
mergePullRequest(owner: string, repository: string, number: number, mergeMethod?: string): Promise<JsonObject>;
|
|
74
|
+
/**
|
|
75
|
+
open の dependabot の PR を全件取る(GraphQL)。pullRequests に author の引数が無いので、全ページを辿ってから絞る。
|
|
76
|
+
GraphQL のノードをそのまま返す
|
|
77
|
+
*/
|
|
78
|
+
listOpenDependabotPullRequests(owner: string, repository: string): Promise<readonly JsonObject[]>;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=pulls.d.ts.map
|
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
// Pull Request 操作の API。cli/core/github/pulls.py の移植。
|
|
2
|
+
// 返す値のキー名は、Python の辞書と同じ snake_case にする(CLI の JSON 出力がそのまま使う)。
|
|
3
|
+
import { isJsonObject, jsonField } from '../../domain/json.js';
|
|
4
|
+
import { JSON_NULL } from '../../domain/json-null.js';
|
|
5
|
+
import { extractReferencesIssueNumbers } from '../../domain/reference-parser.js';
|
|
6
|
+
import { isJsonArray } from '../../domain/python-format.js';
|
|
7
|
+
import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
|
|
8
|
+
import { IssuesApi } from './issues.js';
|
|
9
|
+
import { asObject, isTruthy, numberOrNull, requireNumber, requireString, requireValue, stringOrNull, throwMalformed, truthyNodes } from './payload.js';
|
|
10
|
+
import { QUERY_GET_PULL_REQUEST_SLIM, QUERY_GET_PULL_REQUEST_WITH_REVIEWS, QUERY_LIST_OPEN_PULL_REQUESTS, QUERY_LIST_PULL_REQUESTS_BY_HEAD } from './queries.js';
|
|
11
|
+
import { readPullRequests } from './readout.js';
|
|
12
|
+
import { repositoryPath } from './rest-path.js';
|
|
13
|
+
// author がある場合だけ login を読む。author が無い(削除されたユーザーなど)、または login が空なら null
|
|
14
|
+
function loginOrNull(author) {
|
|
15
|
+
const login = jsonField(author, 'login');
|
|
16
|
+
return isTruthy(login) ? stringOrNull(login) : JSON_NULL;
|
|
17
|
+
}
|
|
18
|
+
function formatPullRequestBase(pullRequest, owner, repository) {
|
|
19
|
+
const closingIssues = truthyNodes(jsonField(pullRequest, 'closingIssuesReferences')).map(issue => ({
|
|
20
|
+
number: requireNumber(jsonField(issue, 'number'), 'closingIssue.number'),
|
|
21
|
+
title: requireString(jsonField(issue, 'title'), 'closingIssue.title'),
|
|
22
|
+
}));
|
|
23
|
+
// Refs #XXX(本文から抽出)。Closing Issues と重複しないものだけ
|
|
24
|
+
const closingNumbers = new Set(closingIssues.map(issue => issue.number));
|
|
25
|
+
const body = jsonField(pullRequest, 'body');
|
|
26
|
+
const referenced = extractReferencesIssueNumbers(typeof body === 'string' ? body : undefined, { owner, repository });
|
|
27
|
+
const referencedIssues = [...referenced].filter(number => !closingNumbers.has(number)).toSorted((a, b) => a - b).map(number => ({ number, title: '' }));
|
|
28
|
+
const isDraft = jsonField(pullRequest, 'isDraft');
|
|
29
|
+
return {
|
|
30
|
+
number: requireNumber(jsonField(pullRequest, 'number'), 'pullRequest.number'),
|
|
31
|
+
state: requireString(jsonField(pullRequest, 'state'), 'pullRequest.state'),
|
|
32
|
+
title: requireString(jsonField(pullRequest, 'title'), 'pullRequest.title'),
|
|
33
|
+
body: requireString(body, 'pullRequest.body'),
|
|
34
|
+
head_ref: requireString(jsonField(pullRequest, 'headRefName'), 'pullRequest.headRefName'),
|
|
35
|
+
base_ref: requireString(jsonField(pullRequest, 'baseRefName'), 'pullRequest.baseRefName'),
|
|
36
|
+
is_draft: typeof isDraft === 'boolean' ? isDraft : throwMalformed('pullRequest.isDraft'),
|
|
37
|
+
mergeable: requireString(jsonField(pullRequest, 'mergeable'), 'pullRequest.mergeable'),
|
|
38
|
+
comments: requireNumber(jsonField(jsonField(pullRequest, 'comments'), 'totalCount'), 'pullRequest.comments.totalCount'),
|
|
39
|
+
closing_issues: closingIssues,
|
|
40
|
+
referenced_issues: referencedIssues,
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function isDependabotAuthor(node) {
|
|
44
|
+
if (!isJsonObject(node))
|
|
45
|
+
return false;
|
|
46
|
+
const author = jsonField(node, 'author');
|
|
47
|
+
return jsonField(author, '__typename') === 'Bot' && jsonField(author, 'login') === 'dependabot';
|
|
48
|
+
}
|
|
49
|
+
function requiredTextOrEmpty(value) {
|
|
50
|
+
return isTruthy(value) ? requireString(value, 'text') : '';
|
|
51
|
+
}
|
|
52
|
+
export class PullsApi extends IssuesApi {
|
|
53
|
+
// PR の取得クエリを実行し、pullRequest ノードを返す
|
|
54
|
+
async fetchPullRequest(query, owner, repository, number) {
|
|
55
|
+
const result = await this.executeGraphql(query, { owner, repo: repository, number });
|
|
56
|
+
const repositoryNode = jsonField(result, 'repository');
|
|
57
|
+
if (!isTruthy(repositoryNode))
|
|
58
|
+
throw new GitHubNotFoundError(`repository not found: ${owner}/${repository}`);
|
|
59
|
+
const pullRequest = jsonField(repositoryNode, 'pullRequest');
|
|
60
|
+
if (!isTruthy(pullRequest))
|
|
61
|
+
throw new GitHubNotFoundError(`PR not found: ${owner}/${repository}/${String(number)}`);
|
|
62
|
+
return requireValue(pullRequest, 'pullRequest');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
head のブランチ名で PR を引く(open・closed・merged。新しい順に先頭 20 件)。
|
|
66
|
+
20 件に収まらないときは hasNextPage が真。リポが無ければ GitHubNotFoundError
|
|
67
|
+
*/
|
|
68
|
+
async listPullRequestsByHead(owner, repository, headReferenceName) {
|
|
69
|
+
const result = await this.executeGraphql(QUERY_LIST_PULL_REQUESTS_BY_HEAD, { owner, repo: repository, headRefName: headReferenceName });
|
|
70
|
+
const repositoryNode = jsonField(result, 'repository');
|
|
71
|
+
if (!isTruthy(repositoryNode))
|
|
72
|
+
throw new GitHubNotFoundError(`repository not found: ${owner}/${repository}`);
|
|
73
|
+
const connection = jsonField(repositoryNode, 'pullRequests');
|
|
74
|
+
return {
|
|
75
|
+
pullRequests: readPullRequests(truthyNodes(connection)),
|
|
76
|
+
hasNextPage: jsonField(jsonField(connection, 'pageInfo'), 'hasNextPage') === true,
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
PR を作る
|
|
81
|
+
*/
|
|
82
|
+
async createPullRequest(owner, repository, title, body, head, base, isDraft = false) {
|
|
83
|
+
return this.restObject('POST', `${repositoryPath(owner, repository)}/pulls`, {
|
|
84
|
+
json: { title, body, head, base, draft: isDraft },
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
PR の詳細を取る(GraphQL)。関連 Issue とレビューを 1 回のクエリで取る
|
|
89
|
+
*/
|
|
90
|
+
async getPullRequestSlim(owner, repository, number) {
|
|
91
|
+
const pullRequest = await this.fetchPullRequest(QUERY_GET_PULL_REQUEST_SLIM, owner, repository, number);
|
|
92
|
+
return {
|
|
93
|
+
...formatPullRequestBase(pullRequest, owner, repository),
|
|
94
|
+
reviews: truthyNodes(jsonField(pullRequest, 'reviews')).map(review => ({
|
|
95
|
+
state: requireString(jsonField(review, 'state'), 'review.state'),
|
|
96
|
+
author: isTruthy(jsonField(review, 'author')) ? requireString(jsonField(jsonField(review, 'author'), 'login'), 'review.author.login') : JSON_NULL,
|
|
97
|
+
})),
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
PR の詳細をレビュー情報付きで取る。getPullRequestSlim に、レビュー本文と行コメント(reviewThreads)を足したもの
|
|
102
|
+
*/
|
|
103
|
+
async getPullRequestWithReviews(owner, repository, number) {
|
|
104
|
+
const pullRequest = await this.fetchPullRequest(QUERY_GET_PULL_REQUEST_WITH_REVIEWS, owner, repository, number);
|
|
105
|
+
return {
|
|
106
|
+
...formatPullRequestBase(pullRequest, owner, repository),
|
|
107
|
+
reviews: truthyNodes(jsonField(pullRequest, 'reviews')).map(review => ({
|
|
108
|
+
state: requireString(jsonField(review, 'state'), 'review.state'),
|
|
109
|
+
author: loginOrNull(jsonField(review, 'author')),
|
|
110
|
+
body: requiredTextOrEmpty(jsonField(review, 'body')),
|
|
111
|
+
submitted_at: stringOrNull(jsonField(review, 'submittedAt')),
|
|
112
|
+
})),
|
|
113
|
+
review_threads: truthyNodes(jsonField(pullRequest, 'reviewThreads')).map(thread => ({
|
|
114
|
+
is_resolved: jsonField(thread, 'isResolved') === true,
|
|
115
|
+
path: stringOrNull(jsonField(thread, 'path')),
|
|
116
|
+
line: numberOrNull(jsonField(thread, 'line')),
|
|
117
|
+
comments: truthyNodes(jsonField(thread, 'comments')).map(comment => ({
|
|
118
|
+
author: loginOrNull(jsonField(comment, 'author')),
|
|
119
|
+
body: requiredTextOrEmpty(jsonField(comment, 'body')),
|
|
120
|
+
created_at: stringOrNull(jsonField(comment, 'createdAt')),
|
|
121
|
+
})),
|
|
122
|
+
})),
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash
|
|
127
|
+
*/
|
|
128
|
+
async mergePullRequest(owner, repository, number, mergeMethod = 'squash') {
|
|
129
|
+
return this.restObject('PUT', `${repositoryPath(owner, repository)}/pulls/${String(number)}/merge`, {
|
|
130
|
+
json: { merge_method: mergeMethod },
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
open の dependabot の PR を全件取る(GraphQL)。pullRequests に author の引数が無いので、全ページを辿ってから絞る。
|
|
135
|
+
GraphQL のノードをそのまま返す
|
|
136
|
+
*/
|
|
137
|
+
async listOpenDependabotPullRequests(owner, repository) {
|
|
138
|
+
const nodes = [];
|
|
139
|
+
let after = JSON_NULL;
|
|
140
|
+
for (;;) {
|
|
141
|
+
const result = await this.executeGraphql(QUERY_LIST_OPEN_PULL_REQUESTS, { owner, repo: repository, after });
|
|
142
|
+
const connection = jsonField(jsonField(result, 'repository'), 'pullRequests');
|
|
143
|
+
// null を PR 0 件と読むと、sync が待つ PR は無いと判断して Tracker を閉じてしまう
|
|
144
|
+
if (!isJsonObject(connection))
|
|
145
|
+
throw new GitHubAPIError('the PR list response has no repository.pullRequests');
|
|
146
|
+
const pageNodes = jsonField(connection, 'nodes');
|
|
147
|
+
if (!isJsonArray(pageNodes))
|
|
148
|
+
throw new GitHubAPIError('nodes in the PR list response is not an array');
|
|
149
|
+
nodes.push(...pageNodes.filter(node => isTruthy(node)));
|
|
150
|
+
const pageInfo = asObject(jsonField(connection, 'pageInfo'));
|
|
151
|
+
if (!isTruthy(pageInfo['hasNextPage']))
|
|
152
|
+
break;
|
|
153
|
+
const cursor = pageInfo['endCursor'];
|
|
154
|
+
if (typeof cursor !== 'string' || cursor === '')
|
|
155
|
+
throw new GitHubAPIError('the next page of the PR list has no endCursor');
|
|
156
|
+
after = cursor;
|
|
157
|
+
}
|
|
158
|
+
return nodes.filter(node => isDependabotAuthor(node));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
//# sourceMappingURL=pulls.js.map
|