@pecot/workflow-mcp 6.0.0 → 7.0.1-dev.19
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 +1 -1
- package/README.md +5 -58
- package/cli/dist/commands/board-add.js +11 -1
- package/cli/dist/commands/board-judgment.d.ts +12 -3
- package/cli/dist/commands/board-judgment.js +12 -6
- package/cli/dist/commands/board-move.js +9 -1
- package/cli/dist/commands/board-readiness.d.ts +3 -3
- package/cli/dist/commands/board-show.js +5 -2
- package/cli/dist/commands/board-sync.js +14 -5
- package/cli/dist/commands/board-view.d.ts +94 -5
- package/cli/dist/commands/board-view.js +119 -17
- package/cli/dist/commands/branch.js +11 -17
- package/cli/dist/commands/command-definition.d.ts +19 -2
- package/cli/dist/commands/command-definition.js +9 -0
- package/cli/dist/commands/failure-kind.d.ts +1 -1
- package/cli/dist/commands/failure-kind.js +1 -0
- package/cli/dist/commands/issue-board.d.ts +31 -3
- package/cli/dist/commands/issue-board.js +28 -4
- package/cli/dist/commands/issue-comment.js +19 -2
- package/cli/dist/commands/issue-create.js +96 -17
- package/cli/dist/commands/issue-dependency.js +51 -14
- package/cli/dist/commands/issue-readiness.d.ts +30 -2
- package/cli/dist/commands/issue-readiness.js +35 -0
- package/cli/dist/commands/issue-reopen.js +18 -3
- package/cli/dist/commands/issue-shared.d.ts +11 -5
- package/cli/dist/commands/issue-shared.js +25 -6
- package/cli/dist/commands/issue-show.js +78 -8
- package/cli/dist/commands/names.d.ts +1 -1
- package/cli/dist/commands/names.js +3 -3
- package/cli/dist/commands/output.d.ts +18 -2
- package/cli/dist/commands/output.js +16 -3
- package/cli/dist/commands/pr-merge.d.ts +3 -0
- package/cli/dist/commands/pr-merge.js +225 -0
- package/cli/dist/commands/pr-reference.d.ts +8 -0
- package/cli/dist/commands/pr-reference.js +30 -0
- package/cli/dist/commands/pr-restack.d.ts +6 -0
- package/cli/dist/commands/pr-restack.js +231 -0
- package/cli/dist/commands/pr-waiting.d.ts +41 -2
- package/cli/dist/commands/pr-waiting.js +74 -37
- package/cli/dist/commands/pr.d.ts +10 -6
- package/cli/dist/commands/pr.js +214 -111
- package/cli/dist/commands/project-sync.d.ts +10 -2
- package/cli/dist/commands/project-sync.js +7 -6
- package/cli/dist/commands/project.js +174 -17
- package/cli/dist/commands/registry.js +2 -0
- package/cli/dist/commands/release.js +67 -18
- package/cli/dist/commands/renamed-commands.js +0 -1
- package/cli/dist/commands/repository-match.js +7 -2
- package/cli/dist/commands/restack-reading.d.ts +45 -0
- package/cli/dist/commands/restack-reading.js +29 -0
- package/cli/dist/commands/session-finish.js +132 -28
- package/cli/dist/commands/session-start.js +31 -60
- package/cli/dist/commands/session.js +119 -135
- package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
- package/cli/dist/commands/tracker-sync-security.js +22 -4
- package/cli/dist/commands/tracker-sync.d.ts +30 -0
- package/cli/dist/commands/tracker-sync.js +15 -0
- package/cli/dist/commands/tracker.js +2 -0
- package/cli/dist/commands/work-target.d.ts +14 -9
- package/cli/dist/commands/work-target.js +19 -19
- package/cli/dist/commands/worktree.js +71 -5
- package/cli/dist/domain/branch-name.d.ts +7 -0
- package/cli/dist/domain/branch-name.js +23 -1
- package/cli/dist/domain/command-hint.d.ts +1 -1
- package/cli/dist/domain/issue-readout.d.ts +0 -4
- package/cli/dist/domain/pull-request.d.ts +20 -3
- package/cli/dist/domain/pull-request.js +25 -9
- package/cli/dist/domain/readiness.d.ts +17 -0
- package/cli/dist/domain/readiness.js +39 -2
- package/cli/dist/domain/restack.d.ts +66 -0
- package/cli/dist/domain/restack.js +57 -0
- package/cli/dist/domain/state.d.ts +41 -12
- package/cli/dist/domain/state.js +30 -14
- package/cli/dist/domain/work-start.d.ts +0 -4
- package/cli/dist/domain/work-start.js +0 -7
- package/cli/dist/infra/git.d.ts +69 -0
- package/cli/dist/infra/git.js +117 -0
- package/cli/dist/infra/github/pulls.d.ts +81 -2
- package/cli/dist/infra/github/pulls.js +116 -5
- package/cli/dist/infra/github/queries.d.ts +4 -1
- package/cli/dist/infra/github/queries.js +47 -32
- package/cli/dist/infra/github/readout.js +0 -33
- package/cli/dist/infra/paths.d.ts +1 -3
- package/cli/dist/infra/paths.js +2 -45
- package/cli/dist/infra/state-store.d.ts +3 -8
- package/cli/dist/infra/state-store.js +6 -24
- package/cli/dist/mcp/result.d.ts +63 -16
- package/cli/dist/mcp/result.js +106 -30
- package/cli/dist/mcp/server.js +37 -4
- package/cli/templates/comment/plan.md +2 -2
- package/cli/templates/comment/review-findings.md +3 -2
- package/cli/templates/issue/bug.md +13 -4
- package/cli/templates/issue/task.md +13 -4
- package/cli/templates/workflow/pecot-board-sync.yml +3 -2
- package/npm-shrinkwrap.json +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,19 @@
|
|
|
1
1
|
import type { JsonObject } from '../../domain/json.js';
|
|
2
2
|
import type { PullRequestsByHeadReadout } from '../../domain/issue-readout.js';
|
|
3
3
|
import { IssuesApi } from './issues.js';
|
|
4
|
+
/**
|
|
5
|
+
base のブランチ名で引いた、同じリポの開いている PR
|
|
6
|
+
*/
|
|
7
|
+
export interface PullRequestsByBase {
|
|
8
|
+
readonly pullRequests: readonly {
|
|
9
|
+
readonly number: number;
|
|
10
|
+
readonly headRefName: string;
|
|
11
|
+
}[];
|
|
12
|
+
/**
|
|
13
|
+
先頭の件数に収まらず、続きがあるか
|
|
14
|
+
*/
|
|
15
|
+
readonly hasNextPage: boolean;
|
|
16
|
+
}
|
|
4
17
|
export interface ClosingIssue {
|
|
5
18
|
readonly number: number;
|
|
6
19
|
readonly title: string;
|
|
@@ -55,6 +68,51 @@ export interface PullRequestStack {
|
|
|
55
68
|
Stacks API が求める X-GitHub-Api-Version(https://docs.github.com/en/rest/pulls/stacks)
|
|
56
69
|
*/
|
|
57
70
|
export declare const STACKS_API_VERSION = "2026-03-10";
|
|
71
|
+
/**
|
|
72
|
+
pr merge が読む PR の状態
|
|
73
|
+
*/
|
|
74
|
+
export interface PullRequestForMerge {
|
|
75
|
+
readonly number: number;
|
|
76
|
+
readonly state: string;
|
|
77
|
+
readonly isDraft: boolean;
|
|
78
|
+
readonly baseRefName: string;
|
|
79
|
+
readonly headRefOid: string;
|
|
80
|
+
readonly isMergeQueueEnabled: boolean;
|
|
81
|
+
readonly isInMergeQueue: boolean;
|
|
82
|
+
}
|
|
83
|
+
declare const ASYNC_MERGE_STATUSES: readonly ['pending', 'merged', 'enqueued', 'failed'];
|
|
84
|
+
export type AsyncMergeStatus = typeof ASYNC_MERGE_STATUSES[number];
|
|
85
|
+
/**
|
|
86
|
+
非同期のマージの結果。uuid は pending のときだけ、message は details.message
|
|
87
|
+
*/
|
|
88
|
+
export interface AsyncMergeResult {
|
|
89
|
+
readonly status: AsyncMergeStatus;
|
|
90
|
+
readonly uuid?: string;
|
|
91
|
+
readonly message?: string;
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
非同期のマージの要求への応答。accepted は 200・202、rejected は 400、conflict は 409
|
|
95
|
+
*/
|
|
96
|
+
export type AsyncMergeRequestOutcome = {
|
|
97
|
+
readonly outcome: 'accepted';
|
|
98
|
+
readonly result: AsyncMergeResult;
|
|
99
|
+
} | {
|
|
100
|
+
readonly outcome: 'rejected';
|
|
101
|
+
readonly message: string;
|
|
102
|
+
} | {
|
|
103
|
+
readonly outcome: 'conflict';
|
|
104
|
+
readonly uuid?: string;
|
|
105
|
+
};
|
|
106
|
+
export interface AsyncMergeOptions {
|
|
107
|
+
/**
|
|
108
|
+
読んだ head の SHA。読んだ後に push された PR をマージしない
|
|
109
|
+
*/
|
|
110
|
+
readonly sha: string;
|
|
111
|
+
/**
|
|
112
|
+
base が merge queue を使うか。使うときはマージの方法の値を渡さない
|
|
113
|
+
*/
|
|
114
|
+
readonly mergeQueue: boolean;
|
|
115
|
+
}
|
|
58
116
|
export interface PullRequestWithReviews extends PullRequestBase {
|
|
59
117
|
readonly reviews: readonly PullRequestReview[];
|
|
60
118
|
readonly review_threads: readonly ReviewThread[];
|
|
@@ -67,6 +125,11 @@ export declare class PullsApi extends IssuesApi {
|
|
|
67
125
|
*/
|
|
68
126
|
listPullRequestsByHead(owner: string, repository: string, headReferenceName: string): Promise<PullRequestsByHeadReadout>;
|
|
69
127
|
/**
|
|
128
|
+
base のブランチ名で開いている PR を引き、同じリポの PR だけを返す(古い順に先頭 20 件)。
|
|
129
|
+
20 件に収まらないときは hasNextPage が真。リポが無ければ GitHubNotFoundError
|
|
130
|
+
*/
|
|
131
|
+
listPullRequestsByBase(owner: string, repository: string, baseReferenceName: string): Promise<PullRequestsByBase>;
|
|
132
|
+
/**
|
|
70
133
|
PR を作る
|
|
71
134
|
*/
|
|
72
135
|
createPullRequest(owner: string, repository: string, title: string, body: string, head: string, base: string, isDraft?: boolean): Promise<JsonObject>;
|
|
@@ -79,9 +142,24 @@ export declare class PullsApi extends IssuesApi {
|
|
|
79
142
|
*/
|
|
80
143
|
getPullRequestWithReviews(owner: string, repository: string, number: number): Promise<PullRequestWithReviews>;
|
|
81
144
|
/**
|
|
82
|
-
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash
|
|
145
|
+
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash。
|
|
146
|
+
sha を渡すと、head がその SHA でなければ GitHub が 409 で拒む
|
|
147
|
+
*/
|
|
148
|
+
mergePullRequest(owner: string, repository: string, number: number, mergeMethod?: string, sha?: string): Promise<JsonObject>;
|
|
149
|
+
/**
|
|
150
|
+
pr merge の判断に使う PR の状態を読む(GraphQL)。
|
|
151
|
+
merge queue の項目を持たない GHES は、項目なしのクエリで読み直し、どちらも false にする
|
|
152
|
+
*/
|
|
153
|
+
getPullRequestForMerge(owner: string, repository: string, number: number): Promise<PullRequestForMerge>;
|
|
154
|
+
/**
|
|
155
|
+
非同期のマージを頼む(https://docs.github.com/en/rest/pulls/pulls#merge-a-pull-request-asynchronously)。
|
|
156
|
+
403・422 などは handleHttpError の例外
|
|
157
|
+
*/
|
|
158
|
+
requestAsyncMerge(owner: string, repository: string, number: number, options: Readonly<AsyncMergeOptions>): Promise<AsyncMergeRequestOutcome>;
|
|
159
|
+
/**
|
|
160
|
+
非同期のマージの結果を読む。結果が消えていれば(24 時間で消える)undefined
|
|
83
161
|
*/
|
|
84
|
-
|
|
162
|
+
getAsyncMergeResult(owner: string, repository: string, number: number, uuid: string): Promise<AsyncMergeResult | undefined>;
|
|
85
163
|
/**
|
|
86
164
|
その PR が入っているスタックを読む。入っていなければ undefined。
|
|
87
165
|
スタックの機能が無いリポは GitHubNotFoundError
|
|
@@ -101,4 +179,5 @@ export declare class PullsApi extends IssuesApi {
|
|
|
101
179
|
*/
|
|
102
180
|
listOpenDependabotPullRequests(owner: string, repository: string): Promise<readonly JsonObject[]>;
|
|
103
181
|
}
|
|
182
|
+
export {};
|
|
104
183
|
//# sourceMappingURL=pulls.d.ts.map
|
|
@@ -4,16 +4,49 @@ import { isJsonObject, jsonField } from '../../domain/json.js';
|
|
|
4
4
|
import { JSON_NULL } from '../../domain/json-null.js';
|
|
5
5
|
import { extractReferencesIssueNumbers } from '../../domain/reference-parser.js';
|
|
6
6
|
import { isJsonArray } from '../../domain/python-format.js';
|
|
7
|
-
import { GitHubAPIError, GitHubNotFoundError } from './errors.js';
|
|
7
|
+
import { GitHubAPIError, GitHubNotFoundError, isSchemaError } from './errors.js';
|
|
8
8
|
import { IssuesApi } from './issues.js';
|
|
9
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';
|
|
10
|
+
import { QUERY_GET_PULL_REQUEST_FOR_MERGE, QUERY_GET_PULL_REQUEST_FOR_MERGE_WITHOUT_QUEUE, QUERY_GET_PULL_REQUEST_SLIM, QUERY_GET_PULL_REQUEST_WITH_REVIEWS, QUERY_LIST_OPEN_PULL_REQUESTS, QUERY_LIST_PULL_REQUESTS_BY_BASE, QUERY_LIST_PULL_REQUESTS_BY_HEAD } from './queries.js';
|
|
11
11
|
import { readPullRequests } from './readout.js';
|
|
12
12
|
import { repositoryPath } from './rest-path.js';
|
|
13
13
|
/**
|
|
14
14
|
Stacks API が求める X-GitHub-Api-Version(https://docs.github.com/en/rest/pulls/stacks)
|
|
15
15
|
*/
|
|
16
16
|
export const STACKS_API_VERSION = '2026-03-10';
|
|
17
|
+
const MERGE_QUEUE_FIELD_ERROR = /(?:Field '|field ")(?:isMergeQueueEnabled|isInMergeQueue)['"]/u;
|
|
18
|
+
// eslint-disable-next-line no-restricted-syntax -- 配列から型を作るための as const
|
|
19
|
+
const ASYNC_MERGE_STATUSES = ['pending', 'merged', 'enqueued', 'failed'];
|
|
20
|
+
function requiresBoolean(value, path) {
|
|
21
|
+
return typeof value === 'boolean' ? value : throwMalformed(path);
|
|
22
|
+
}
|
|
23
|
+
function isAsyncMergeStatus(value) {
|
|
24
|
+
return ASYNC_MERGE_STATUSES.some(status => status === value);
|
|
25
|
+
}
|
|
26
|
+
function readAsyncMergeResult(value) {
|
|
27
|
+
const status = jsonField(value, 'status');
|
|
28
|
+
if (!isAsyncMergeStatus(status))
|
|
29
|
+
throwMalformed(`mergeAsync.status (${typeof status === 'string' ? status : JSON.stringify(status)})`);
|
|
30
|
+
const details = jsonField(value, 'details');
|
|
31
|
+
const uuid = jsonField(details, 'uuid');
|
|
32
|
+
const message = jsonField(details, 'message');
|
|
33
|
+
if (status === 'pending' && typeof uuid !== 'string')
|
|
34
|
+
throwMalformed('mergeAsync.details.uuid');
|
|
35
|
+
return {
|
|
36
|
+
status,
|
|
37
|
+
...status === 'pending' && typeof uuid === 'string' && { uuid },
|
|
38
|
+
...typeof message === 'string' && { message },
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
// 文書は 400・409 の本文の形を示していないので、JSON でなくても止めない
|
|
42
|
+
function bodyOrUndefined(response) {
|
|
43
|
+
try {
|
|
44
|
+
return response.json();
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
17
50
|
function readStack(value) {
|
|
18
51
|
if (!isJsonObject(value))
|
|
19
52
|
throwMalformed('stack');
|
|
@@ -100,6 +133,23 @@ export class PullsApi extends IssuesApi {
|
|
|
100
133
|
};
|
|
101
134
|
}
|
|
102
135
|
/**
|
|
136
|
+
base のブランチ名で開いている PR を引き、同じリポの PR だけを返す(古い順に先頭 20 件)。
|
|
137
|
+
20 件に収まらないときは hasNextPage が真。リポが無ければ GitHubNotFoundError
|
|
138
|
+
*/
|
|
139
|
+
async listPullRequestsByBase(owner, repository, baseReferenceName) {
|
|
140
|
+
const result = await this.executeGraphql(QUERY_LIST_PULL_REQUESTS_BY_BASE, { owner, repo: repository, baseRefName: baseReferenceName });
|
|
141
|
+
const repositoryNode = jsonField(result, 'repository');
|
|
142
|
+
if (!isTruthy(repositoryNode))
|
|
143
|
+
throw new GitHubNotFoundError(`repository not found: ${owner}/${repository}`);
|
|
144
|
+
const connection = jsonField(repositoryNode, 'pullRequests');
|
|
145
|
+
return {
|
|
146
|
+
pullRequests: readPullRequests(truthyNodes(connection))
|
|
147
|
+
.filter(pullRequest => !pullRequest.isCrossRepository)
|
|
148
|
+
.map(pullRequest => ({ number: pullRequest.number, headRefName: pullRequest.headRefName })),
|
|
149
|
+
hasNextPage: jsonField(jsonField(connection, 'pageInfo'), 'hasNextPage') === true,
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
/**
|
|
103
153
|
PR を作る
|
|
104
154
|
*/
|
|
105
155
|
async createPullRequest(owner, repository, title, body, head, base, isDraft = false) {
|
|
@@ -146,12 +196,73 @@ export class PullsApi extends IssuesApi {
|
|
|
146
196
|
};
|
|
147
197
|
}
|
|
148
198
|
/**
|
|
149
|
-
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash
|
|
199
|
+
PR をマージする。mergeMethod は merge・squash・rebase。既定は squash。
|
|
200
|
+
sha を渡すと、head がその SHA でなければ GitHub が 409 で拒む
|
|
150
201
|
*/
|
|
151
|
-
async mergePullRequest(owner, repository, number, mergeMethod = 'squash') {
|
|
202
|
+
async mergePullRequest(owner, repository, number, mergeMethod = 'squash', sha) {
|
|
152
203
|
return this.restObject('PUT', `${repositoryPath(owner, repository)}/pulls/${String(number)}/merge`, {
|
|
153
|
-
json: { merge_method: mergeMethod },
|
|
204
|
+
json: sha === undefined ? { merge_method: mergeMethod } : { merge_method: mergeMethod, sha },
|
|
205
|
+
});
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
pr merge の判断に使う PR の状態を読む(GraphQL)。
|
|
209
|
+
merge queue の項目を持たない GHES は、項目なしのクエリで読み直し、どちらも false にする
|
|
210
|
+
*/
|
|
211
|
+
async getPullRequestForMerge(owner, repository, number) {
|
|
212
|
+
let pullRequest;
|
|
213
|
+
let hasQueueFields = true;
|
|
214
|
+
try {
|
|
215
|
+
pullRequest = await this.fetchPullRequest(QUERY_GET_PULL_REQUEST_FOR_MERGE, owner, repository, number);
|
|
216
|
+
}
|
|
217
|
+
catch (error) {
|
|
218
|
+
if (!isSchemaError(error) || !MERGE_QUEUE_FIELD_ERROR.test(error.message))
|
|
219
|
+
throw error;
|
|
220
|
+
pullRequest = await this.fetchPullRequest(QUERY_GET_PULL_REQUEST_FOR_MERGE_WITHOUT_QUEUE, owner, repository, number);
|
|
221
|
+
hasQueueFields = false;
|
|
222
|
+
}
|
|
223
|
+
return {
|
|
224
|
+
number: requireNumber(jsonField(pullRequest, 'number'), 'pullRequest.number'),
|
|
225
|
+
state: requireString(jsonField(pullRequest, 'state'), 'pullRequest.state'),
|
|
226
|
+
isDraft: requiresBoolean(jsonField(pullRequest, 'isDraft'), 'pullRequest.isDraft'),
|
|
227
|
+
baseRefName: requireString(jsonField(pullRequest, 'baseRefName'), 'pullRequest.baseRefName'),
|
|
228
|
+
headRefOid: requireString(jsonField(pullRequest, 'headRefOid'), 'pullRequest.headRefOid'),
|
|
229
|
+
isMergeQueueEnabled: hasQueueFields && requiresBoolean(jsonField(pullRequest, 'isMergeQueueEnabled'), 'pullRequest.isMergeQueueEnabled'),
|
|
230
|
+
isInMergeQueue: hasQueueFields && requiresBoolean(jsonField(pullRequest, 'isInMergeQueue'), 'pullRequest.isInMergeQueue'),
|
|
231
|
+
};
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
非同期のマージを頼む(https://docs.github.com/en/rest/pulls/pulls#merge-a-pull-request-asynchronously)。
|
|
235
|
+
403・422 などは handleHttpError の例外
|
|
236
|
+
*/
|
|
237
|
+
async requestAsyncMerge(owner, repository, number, options) {
|
|
238
|
+
const response = await this.restRequest('PUT', `${repositoryPath(owner, repository)}/pulls/${String(number)}/merge-async`, {
|
|
239
|
+
json: options.mergeQueue ? { sha: options.sha } : { sha: options.sha, merge_method: 'squash' },
|
|
240
|
+
apiVersion: STACKS_API_VERSION,
|
|
241
|
+
});
|
|
242
|
+
if (response.statusCode === 400) {
|
|
243
|
+
const message = jsonField(bodyOrUndefined(response), 'message');
|
|
244
|
+
return { outcome: 'rejected', message: typeof message === 'string' ? message : response.text };
|
|
245
|
+
}
|
|
246
|
+
if (response.statusCode === 409) {
|
|
247
|
+
const uuid = jsonField(jsonField(bodyOrUndefined(response), 'details'), 'uuid');
|
|
248
|
+
return typeof uuid === 'string' ? { outcome: 'conflict', uuid } : { outcome: 'conflict' };
|
|
249
|
+
}
|
|
250
|
+
if (!response.isSuccess)
|
|
251
|
+
this.handleHttpError(response);
|
|
252
|
+
return { outcome: 'accepted', result: readAsyncMergeResult(response.json()) };
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
非同期のマージの結果を読む。結果が消えていれば(24 時間で消える)undefined
|
|
256
|
+
*/
|
|
257
|
+
async getAsyncMergeResult(owner, repository, number, uuid) {
|
|
258
|
+
const response = await this.restRequest('GET', `${repositoryPath(owner, repository)}/pulls/${String(number)}/merge-async/${encodeURIComponent(uuid)}`, {
|
|
259
|
+
apiVersion: STACKS_API_VERSION,
|
|
154
260
|
});
|
|
261
|
+
if (response.statusCode === 404)
|
|
262
|
+
return undefined;
|
|
263
|
+
if (!response.isSuccess)
|
|
264
|
+
this.handleHttpError(response);
|
|
265
|
+
return readAsyncMergeResult(response.json());
|
|
155
266
|
}
|
|
156
267
|
/**
|
|
157
268
|
その PR が入っているスタックを読む。入っていなければ undefined。
|
|
@@ -30,13 +30,16 @@ export declare const QUERY_GET_ISSUE_SLIM: string;
|
|
|
30
30
|
export declare const QUERY_GET_ISSUE_SLIM_WITHOUT_BLOCKED_BY: string;
|
|
31
31
|
export declare const QUERY_GET_SUB_ISSUES_PAGE = "query ($owner: String!, $repo: String!, $number: Int!, $after: String!) {\n repository(owner: $owner, name: $repo) {\n issue(number: $number) {\n subIssues(first: 100, after: $after) {\n nodes {\n number\n state\n title\n }\n pageInfo {\n hasNextPage\n endCursor\n }\n }\n }\n }\n}";
|
|
32
32
|
export declare const QUERY_GET_PULL_REQUEST_SLIM = "query ($owner: String!, $repo: String!, $number: Int!) {\n repository(owner: $owner, name: $repo) {\n pullRequest(number: $number) {\n number\n state\n title\n body\n headRefName\n baseRefName\n isDraft\n mergeable\n comments {\n totalCount\n }\n closingIssuesReferences(first: 10) {\n nodes {\n number\n title\n }\n }\n reviews(first: 10) {\n nodes {\n state\n author {\n login\n }\n }\n }\n }\n }\n}";
|
|
33
|
+
export declare const QUERY_GET_PULL_REQUEST_FOR_MERGE = "query ($owner: String!, $repo: String!, $number: Int!) {\n repository(owner: $owner, name: $repo) {\n pullRequest(number: $number) {\n number\n state\n isDraft\n baseRefName\n headRefOid\n isMergeQueueEnabled\n isInMergeQueue\n }\n }\n}";
|
|
34
|
+
export declare const QUERY_GET_PULL_REQUEST_FOR_MERGE_WITHOUT_QUEUE = "query ($owner: String!, $repo: String!, $number: Int!) {\n repository(owner: $owner, name: $repo) {\n pullRequest(number: $number) {\n number\n state\n isDraft\n baseRefName\n headRefOid\n }\n }\n}";
|
|
33
35
|
export declare const QUERY_GET_PULL_REQUEST_WITH_REVIEWS = "query ($owner: String!, $repo: String!, $number: Int!) {\n repository(owner: $owner, name: $repo) {\n pullRequest(number: $number) {\n number\n state\n title\n body\n headRefName\n baseRefName\n isDraft\n mergeable\n comments {\n totalCount\n }\n closingIssuesReferences(first: 10) {\n nodes {\n number\n title\n }\n }\n reviews(first: 20) {\n nodes {\n state\n body\n author {\n login\n }\n submittedAt\n }\n }\n reviewThreads(first: 50) {\n nodes {\n isResolved\n path\n line\n comments(first: 10) {\n nodes {\n author {\n login\n }\n body\n createdAt\n }\n }\n }\n }\n }\n }\n}";
|
|
34
36
|
export declare const QUERY_LIST_OPEN_PULL_REQUESTS = "query ($owner: String!, $repo: String!, $after: String) {\n repository(owner: $owner, name: $repo) {\n pullRequests(\n first: 25\n states: OPEN\n after: $after\n orderBy: { field: CREATED_AT, direction: ASC }\n ) {\n pageInfo {\n hasNextPage\n endCursor\n }\n nodes {\n number\n title\n url\n createdAt\n author {\n __typename\n login\n }\n isInMergeQueue\n autoMergeRequest {\n enabledAt\n }\n mergeable\n baseRef {\n target {\n ... on Commit {\n committedDate\n }\n }\n }\n firstCommits: commits(first: 1) {\n nodes {\n commit {\n message\n signature {\n isValid\n }\n author {\n user {\n login\n }\n }\n }\n }\n }\n headCommits: commits(last: 1) {\n nodes {\n commit {\n statusCheckRollup {\n state\n }\n }\n }\n }\n lastForcePush: timelineItems(last: 1, itemTypes: [HEAD_REF_FORCE_PUSHED_EVENT]) {\n nodes {\n ... on HeadRefForcePushedEvent {\n createdAt\n }\n }\n }\n lastDequeue: timelineItems(last: 1, itemTypes: [REMOVED_FROM_MERGE_QUEUE_EVENT]) {\n nodes {\n ... on RemovedFromMergeQueueEvent {\n createdAt\n }\n }\n }\n }\n }\n }\n}";
|
|
35
37
|
export declare const QUERY_HAS_ADD_BLOCKED_BY_INPUT = "{\n __type(name: \"AddBlockedByInput\") {\n name\n }\n}";
|
|
36
38
|
export declare const MUTATION_ADD_BLOCKED_BY = "mutation ($issueId: ID!, $blockingIssueId: ID!) {\n addBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockingIssueId }) {\n issue {\n number\n }\n blockingIssue {\n number\n }\n }\n}";
|
|
37
39
|
export declare const MUTATION_REMOVE_BLOCKED_BY = "mutation ($issueId: ID!, $blockingIssueId: ID!) {\n removeBlockedBy(input: { issueId: $issueId, blockingIssueId: $blockingIssueId }) {\n issue {\n number\n }\n blockingIssue {\n number\n }\n }\n}";
|
|
38
|
-
export declare const QUERY_GET_ISSUE_PREREQUISITES = "query ($owner: String!, $repo: String!, $number: Int!, $columnFieldName: String!, $labelFieldName: String!, $blockedByFirst: Int!) {\n repository(owner: $owner, name: $repo) {\n issue(number: $number) {\n ...PrerequisiteIssueFields\n body\n parent {\n number\n repository {\n owner {\n login\n }\n name\n }\n }\n blockedBy(first: $blockedByFirst) {\n totalCount\n nodes {\n ...PrerequisiteIssueFields\n }\n }\n }\n }\n}\n\nfragment PrerequisiteIssueFields on Issue {\n id\n number\n state\n title\n repository {\n owner {\n login\n }\n name\n }\n issueType {\n name\n }\n subIssues(first: 1) {\n totalCount\n }\n projectItems(first: 20, includeArchived: false) {\n totalCount\n nodes {\n project {\n id\n }\n column: fieldValueByName(name: $columnFieldName) {\n ...SingleSelectValueFields\n }\n label: fieldValueByName(name: $labelFieldName) {\n ...SingleSelectValueFields\n }\n }\n }\n linkedBranches(first: 10) {\n totalCount\n nodes {\n ref {\n name\n associatedPullRequests(first: 10) {\n totalCount\n nodes {\n ...PullRequestFields\n }\n }\n }\n }\n }\n closedByPullRequestsReferences(first: 10, includeClosedPrs: true) {\n totalCount\n nodes {\n ...PullRequestFields\n }\n }\n
|
|
40
|
+
export declare const QUERY_GET_ISSUE_PREREQUISITES = "query ($owner: String!, $repo: String!, $number: Int!, $columnFieldName: String!, $labelFieldName: String!, $blockedByFirst: Int!) {\n repository(owner: $owner, name: $repo) {\n issue(number: $number) {\n ...PrerequisiteIssueFields\n body\n parent {\n number\n repository {\n owner {\n login\n }\n name\n }\n }\n blockedBy(first: $blockedByFirst) {\n totalCount\n nodes {\n ...PrerequisiteIssueFields\n }\n }\n }\n }\n}\n\nfragment PrerequisiteIssueFields on Issue {\n id\n number\n state\n title\n repository {\n owner {\n login\n }\n name\n }\n issueType {\n name\n }\n subIssues(first: 1) {\n totalCount\n }\n projectItems(first: 20, includeArchived: false) {\n totalCount\n nodes {\n project {\n id\n }\n column: fieldValueByName(name: $columnFieldName) {\n ...SingleSelectValueFields\n }\n label: fieldValueByName(name: $labelFieldName) {\n ...SingleSelectValueFields\n }\n }\n }\n linkedBranches(first: 10) {\n totalCount\n nodes {\n ref {\n name\n associatedPullRequests(first: 10) {\n totalCount\n nodes {\n ...PullRequestFields\n }\n }\n }\n }\n }\n closedByPullRequestsReferences(first: 10, includeClosedPrs: true) {\n totalCount\n nodes {\n ...PullRequestFields\n }\n }\n}\n\nfragment SingleSelectValueFields on ProjectV2ItemFieldValue {\n ... on ProjectV2ItemFieldSingleSelectValue {\n name\n optionId\n field {\n ... on ProjectV2SingleSelectField {\n id\n }\n }\n }\n}\n\nfragment PullRequestFields on PullRequest {\n number\n state\n headRefName\n baseRefName\n isDraft\n isCrossRepository\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
39
41
|
export declare const QUERY_LIST_PULL_REQUESTS_BY_HEAD = "query ($owner: String!, $repo: String!, $headRefName: String!) {\n repository(owner: $owner, name: $repo) {\n pullRequests(\n headRefName: $headRefName\n states: [OPEN, CLOSED, MERGED]\n first: 20\n orderBy: { field: CREATED_AT, direction: DESC }\n ) {\n pageInfo {\n hasNextPage\n }\n nodes {\n ...PullRequestFields\n }\n }\n }\n}\n\nfragment PullRequestFields on PullRequest {\n number\n state\n headRefName\n baseRefName\n isDraft\n isCrossRepository\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
42
|
+
export declare const QUERY_LIST_PULL_REQUESTS_BY_BASE = "query ($owner: String!, $repo: String!, $baseRefName: String!) {\n repository(owner: $owner, name: $repo) {\n pullRequests(\n baseRefName: $baseRefName\n states: [OPEN]\n first: 20\n orderBy: { field: CREATED_AT, direction: ASC }\n ) {\n pageInfo {\n hasNextPage\n }\n nodes {\n ...PullRequestFields\n }\n }\n }\n}\n\nfragment PullRequestFields on PullRequest {\n number\n state\n headRefName\n baseRefName\n isDraft\n isCrossRepository\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
40
43
|
export declare const QUERY_GET_ISSUE_BLOCKED_BY_REFERENCES = "query ($owner: String!, $repo: String!, $number: Int!, $blockedByFirst: Int!) {\n repository(owner: $owner, name: $repo) {\n issue(number: $number) {\n id\n body\n blockedBy(first: $blockedByFirst) {\n totalCount\n nodes {\n ...BlockedByReferenceFields\n }\n }\n }\n }\n}\n\nfragment BlockedByReferenceFields on Issue {\n id\n number\n state\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
41
44
|
export declare const QUERY_GET_BLOCKED_BY_OF_NODES = "query ($ids: [ID!]!, $blockedByFirst: Int!) {\n nodes(ids: $ids) {\n ... on Issue {\n id\n blockedBy(first: $blockedByFirst) {\n totalCount\n nodes {\n ...BlockedByReferenceFields\n }\n }\n }\n }\n}\n\nfragment BlockedByReferenceFields on Issue {\n id\n number\n state\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
42
45
|
export declare const QUERY_GET_ISSUE_BLOCKING_REFERENCES = "query ($owner: String!, $repo: String!, $number: Int!, $blockingFirst: Int!) {\n repository(owner: $owner, name: $repo) {\n issue(number: $number) {\n blocking(first: $blockingFirst) {\n totalCount\n nodes {\n ...BlockedByReferenceFields\n }\n }\n }\n }\n}\n\nfragment BlockedByReferenceFields on Issue {\n id\n number\n state\n repository {\n owner {\n login\n }\n name\n }\n}";
|
|
@@ -624,6 +624,32 @@ export const QUERY_GET_PULL_REQUEST_SLIM = `query ($owner: String!, $repo: Strin
|
|
|
624
624
|
}
|
|
625
625
|
}
|
|
626
626
|
}`;
|
|
627
|
+
// pr merge が読む PR の状態。GetPullRequestSlim を変えずに、マージの判断に要る項目だけを読む
|
|
628
|
+
export const QUERY_GET_PULL_REQUEST_FOR_MERGE = `query ($owner: String!, $repo: String!, $number: Int!) {
|
|
629
|
+
repository(owner: $owner, name: $repo) {
|
|
630
|
+
pullRequest(number: $number) {
|
|
631
|
+
number
|
|
632
|
+
state
|
|
633
|
+
isDraft
|
|
634
|
+
baseRefName
|
|
635
|
+
headRefOid
|
|
636
|
+
isMergeQueueEnabled
|
|
637
|
+
isInMergeQueue
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}`;
|
|
641
|
+
// 上のクエリから merge queue の項目を除いたもの。その項目を持たない GHES で読み直すのに使う
|
|
642
|
+
export const QUERY_GET_PULL_REQUEST_FOR_MERGE_WITHOUT_QUEUE = `query ($owner: String!, $repo: String!, $number: Int!) {
|
|
643
|
+
repository(owner: $owner, name: $repo) {
|
|
644
|
+
pullRequest(number: $number) {
|
|
645
|
+
number
|
|
646
|
+
state
|
|
647
|
+
isDraft
|
|
648
|
+
baseRefName
|
|
649
|
+
headRefOid
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
}`;
|
|
627
653
|
// PR詳細取得(レビュー詳細付き - --reviews オプション用)
|
|
628
654
|
export const QUERY_GET_PULL_REQUEST_WITH_REVIEWS = `query ($owner: String!, $repo: String!, $number: Int!) {
|
|
629
655
|
repository(owner: $owner, name: $repo) {
|
|
@@ -846,37 +872,6 @@ const PREREQUISITE_ISSUE_FIELDS = `fragment PrerequisiteIssueFields on Issue {
|
|
|
846
872
|
...PullRequestFields
|
|
847
873
|
}
|
|
848
874
|
}
|
|
849
|
-
timelineItems(
|
|
850
|
-
itemTypes: [CONNECTED_EVENT, DISCONNECTED_EVENT, CROSS_REFERENCED_EVENT]
|
|
851
|
-
first: 20
|
|
852
|
-
) {
|
|
853
|
-
totalCount
|
|
854
|
-
nodes {
|
|
855
|
-
__typename
|
|
856
|
-
... on ConnectedEvent {
|
|
857
|
-
subject {
|
|
858
|
-
... on PullRequest {
|
|
859
|
-
...PullRequestFields
|
|
860
|
-
}
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
... on DisconnectedEvent {
|
|
864
|
-
subject {
|
|
865
|
-
... on PullRequest {
|
|
866
|
-
...PullRequestFields
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
}
|
|
870
|
-
... on CrossReferencedEvent {
|
|
871
|
-
willCloseTarget
|
|
872
|
-
source {
|
|
873
|
-
... on PullRequest {
|
|
874
|
-
...PullRequestFields
|
|
875
|
-
}
|
|
876
|
-
}
|
|
877
|
-
}
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
875
|
}`;
|
|
881
876
|
const SINGLE_SELECT_VALUE_FIELDS = `fragment SingleSelectValueFields on ProjectV2ItemFieldValue {
|
|
882
877
|
... on ProjectV2ItemFieldSingleSelectValue {
|
|
@@ -889,7 +884,7 @@ const SINGLE_SELECT_VALUE_FIELDS = `fragment SingleSelectValueFields on ProjectV
|
|
|
889
884
|
}
|
|
890
885
|
}
|
|
891
886
|
}`;
|
|
892
|
-
// Issue と、その前提(blockedBy)を 1 回で読む。PR は
|
|
887
|
+
// Issue と、その前提(blockedBy)を 1 回で読む。PR は 2 つの読み口(リンクしたブランチと Development 欄)から集める
|
|
893
888
|
export const QUERY_GET_ISSUE_PREREQUISITES = `query ($owner: String!, $repo: String!, $number: Int!, $columnFieldName: String!, $labelFieldName: String!, $blockedByFirst: Int!) {
|
|
894
889
|
repository(owner: $owner, name: $repo) {
|
|
895
890
|
issue(number: $number) {
|
|
@@ -938,6 +933,26 @@ export const QUERY_LIST_PULL_REQUESTS_BY_HEAD = `query ($owner: String!, $repo:
|
|
|
938
933
|
}
|
|
939
934
|
}
|
|
940
935
|
|
|
936
|
+
${PULL_REQUEST_FIELDS}`;
|
|
937
|
+
// base のブランチ名で開いている PR を引く(古い順)
|
|
938
|
+
export const QUERY_LIST_PULL_REQUESTS_BY_BASE = `query ($owner: String!, $repo: String!, $baseRefName: String!) {
|
|
939
|
+
repository(owner: $owner, name: $repo) {
|
|
940
|
+
pullRequests(
|
|
941
|
+
baseRefName: $baseRefName
|
|
942
|
+
states: [OPEN]
|
|
943
|
+
first: 20
|
|
944
|
+
orderBy: { field: CREATED_AT, direction: ASC }
|
|
945
|
+
) {
|
|
946
|
+
pageInfo {
|
|
947
|
+
hasNextPage
|
|
948
|
+
}
|
|
949
|
+
nodes {
|
|
950
|
+
...PullRequestFields
|
|
951
|
+
}
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
}
|
|
955
|
+
|
|
941
956
|
${PULL_REQUEST_FIELDS}`;
|
|
942
957
|
const BLOCKED_BY_REFERENCE_FIELDS = `fragment BlockedByReferenceFields on Issue {
|
|
943
958
|
id
|
|
@@ -64,37 +64,6 @@ function readProjectFieldValues(issue, projectId, fieldNames) {
|
|
|
64
64
|
: [])
|
|
65
65
|
.filter(value => value !== undefined);
|
|
66
66
|
}
|
|
67
|
-
function pullRequestKey(pullRequest) {
|
|
68
|
-
return `${pullRequest.repository.owner}/${pullRequest.repository.repository}#${String(pullRequest.number)}`;
|
|
69
|
-
}
|
|
70
|
-
function applyTimelineEvent(entries, event, issueNumber) {
|
|
71
|
-
const type = jsonField(event, '__typename');
|
|
72
|
-
if (type === 'CrossReferencedEvent') {
|
|
73
|
-
const pullRequest = readPullRequest(jsonField(event, 'source'));
|
|
74
|
-
if (pullRequest === undefined)
|
|
75
|
-
return entries;
|
|
76
|
-
const isRelated = jsonField(event, 'willCloseTarget') === true || pullRequest.headRefName.endsWith(`/${String(issueNumber)}`);
|
|
77
|
-
return isRelated ? [...entries, { key: pullRequestKey(pullRequest), pullRequest, isConnection: false }] : entries;
|
|
78
|
-
}
|
|
79
|
-
if (type !== 'ConnectedEvent' && type !== 'DisconnectedEvent')
|
|
80
|
-
return entries;
|
|
81
|
-
const pullRequest = readPullRequest(jsonField(event, 'subject'));
|
|
82
|
-
if (pullRequest === undefined)
|
|
83
|
-
return entries;
|
|
84
|
-
const key = pullRequestKey(pullRequest);
|
|
85
|
-
return type === 'ConnectedEvent'
|
|
86
|
-
? [...entries, { key, pullRequest, isConnection: true }]
|
|
87
|
-
: entries.filter(entry => !(entry.isConnection && entry.key === key));
|
|
88
|
-
}
|
|
89
|
-
// ConnectedEvent は、後で同じ PR の DisconnectedEvent が無いものだけ採る。
|
|
90
|
-
// CrossReferencedEvent は、本文やコメントで触れただけの PR を除くため、閉じる参照か head が `/<Issue 番号>` で終わるものだけ採る
|
|
91
|
-
function readTimelinePullRequests(issue, issueNumber) {
|
|
92
|
-
const events = truthyNodes(jsonField(issue, 'timelineItems'));
|
|
93
|
-
let entries = [];
|
|
94
|
-
for (const event of events)
|
|
95
|
-
entries = applyTimelineEvent(entries, event, issueNumber);
|
|
96
|
-
return entries.map(entry => entry.pullRequest);
|
|
97
|
-
}
|
|
98
67
|
export function readIssue(issue, projectId, fieldNames) {
|
|
99
68
|
const issueType = jsonField(jsonField(issue, 'issueType'), 'name');
|
|
100
69
|
const number = requireNumber(jsonField(issue, 'number'), 'issue.number');
|
|
@@ -109,7 +78,6 @@ export function readIssue(issue, projectId, fieldNames) {
|
|
|
109
78
|
projectFieldValues: readProjectFieldValues(issue, projectId, fieldNames),
|
|
110
79
|
linkedBranches: readLinkedBranches(issue),
|
|
111
80
|
closingPullRequests: readPullRequests(truthyNodes(jsonField(issue, 'closedByPullRequestsReferences'))),
|
|
112
|
-
timelinePullRequests: readTimelinePullRequests(issue, number),
|
|
113
81
|
};
|
|
114
82
|
}
|
|
115
83
|
// 件数が totalCount に足りない connection の説明。足りていれば undefined
|
|
@@ -128,7 +96,6 @@ function connectionShortfalls(issue) {
|
|
|
128
96
|
shortfall(linkedBranches, 'linkedBranches', where),
|
|
129
97
|
...truthyNodes(linkedBranches).map(branch => shortfall(jsonField(jsonField(branch, 'ref'), 'associatedPullRequests'), 'associatedPullRequests', where)),
|
|
130
98
|
shortfall(jsonField(issue, 'closedByPullRequestsReferences'), 'closedByPullRequestsReferences', where),
|
|
131
|
-
shortfall(jsonField(issue, 'timelineItems'), 'timelineItems', where),
|
|
132
99
|
].filter(reason => reason !== undefined);
|
|
133
100
|
}
|
|
134
101
|
/**
|
|
@@ -32,9 +32,7 @@ export interface ProjectRootOptions {
|
|
|
32
32
|
/**
|
|
33
33
|
プロジェクトルートを取得する。
|
|
34
34
|
1. CLAUDE_PROJECT_DIR があれば使う(テスト上書き用)。
|
|
35
|
-
2.
|
|
36
|
-
worktree の .pecot/work は base への symlink で、そこでは git toplevel が base になる。
|
|
37
|
-
3. なければ git rev-parse --show-toplevel で解決する(GIT_* を除いて実行する)。
|
|
35
|
+
2. なければ git rev-parse --show-toplevel で解決する(GIT_* を除いて実行する)。
|
|
38
36
|
|
|
39
37
|
どれも得られなければ ProjectRootNotFoundError
|
|
40
38
|
*/
|
package/cli/dist/infra/paths.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/* eslint-disable security/detect-non-literal-fs-filename -- パスは呼び出し側が決める。ここは解決と予約だけ */
|
|
2
2
|
// pecot リポジトリ基準のパス解決。`.pecot/` 配下のパス定義の唯一の置き場。
|
|
3
3
|
// projectRoot() でプロジェクトルートを解決し、一時ファイルの出力先を固定する。
|
|
4
|
-
import { closeSync,
|
|
4
|
+
import { closeSync, mkdirSync, openSync, realpathSync, unlinkSync } from 'node:fs';
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import { PecotError, ProjectRootNotFoundError } from '../domain/errors.js';
|
|
7
7
|
import { gitToplevel } from './git.js';
|
|
@@ -55,42 +55,6 @@ export function resolveRealPath(target) {
|
|
|
55
55
|
throw error;
|
|
56
56
|
}
|
|
57
57
|
}
|
|
58
|
-
/**
|
|
59
|
-
cwd がセッションの worktree の .pecot/work の実体配下なら、その worktree を返す。
|
|
60
|
-
セッション開始時の SessionStart hook が PECOT_SESSION_PROJECT_DIR に書いた値を起点にする。git は呼ばない。
|
|
61
|
-
hooks の project-root.sh と同じ判定を使う。cwd の文字列が `.pecot/work` で終わるか `.pecot/work/` を含み、実体が起点の .pecot/work の実体配下にある。
|
|
62
|
-
かつ途中に `.git` を持つディレクトリ(入れ子の git リポ)が無いときだけ対象にする
|
|
63
|
-
*/
|
|
64
|
-
function sessionWorkOwner(cwd) {
|
|
65
|
-
const sessionDirectory = process.env['PECOT_SESSION_PROJECT_DIR'];
|
|
66
|
-
if (sessionDirectory === undefined || sessionDirectory === '')
|
|
67
|
-
return undefined;
|
|
68
|
-
// 安価な文字列の判定を、realpath の解決より先に行う
|
|
69
|
-
if (!(cwd.endsWith(`/${WORK_DIR}`) || cwd.includes(`/${WORK_DIR}/`)))
|
|
70
|
-
return undefined;
|
|
71
|
-
let workReal;
|
|
72
|
-
let cwdReal;
|
|
73
|
-
try {
|
|
74
|
-
workReal = resolveRealPath(path.join(sessionDirectory, WORK_DIR));
|
|
75
|
-
cwdReal = resolveRealPath(cwd);
|
|
76
|
-
}
|
|
77
|
-
catch (error) {
|
|
78
|
-
if (hasErrorCode(error))
|
|
79
|
-
return undefined;
|
|
80
|
-
throw error;
|
|
81
|
-
}
|
|
82
|
-
if (cwdReal !== workReal && !cwdReal.startsWith(`${workReal}/`))
|
|
83
|
-
return undefined;
|
|
84
|
-
for (let directory = cwdReal;; directory = path.dirname(directory)) {
|
|
85
|
-
if (directory === workReal)
|
|
86
|
-
break;
|
|
87
|
-
if (existsSync(path.join(directory, '.git')))
|
|
88
|
-
return undefined;
|
|
89
|
-
if (path.dirname(directory) === directory)
|
|
90
|
-
break;
|
|
91
|
-
}
|
|
92
|
-
return resolveRealPath(sessionDirectory);
|
|
93
|
-
}
|
|
94
58
|
function currentDirectory(options) {
|
|
95
59
|
try {
|
|
96
60
|
return options.cwd ?? process.cwd();
|
|
@@ -105,9 +69,7 @@ function currentDirectory(options) {
|
|
|
105
69
|
/**
|
|
106
70
|
プロジェクトルートを取得する。
|
|
107
71
|
1. CLAUDE_PROJECT_DIR があれば使う(テスト上書き用)。
|
|
108
|
-
2.
|
|
109
|
-
worktree の .pecot/work は base への symlink で、そこでは git toplevel が base になる。
|
|
110
|
-
3. なければ git rev-parse --show-toplevel で解決する(GIT_* を除いて実行する)。
|
|
72
|
+
2. なければ git rev-parse --show-toplevel で解決する(GIT_* を除いて実行する)。
|
|
111
73
|
|
|
112
74
|
どれも得られなければ ProjectRootNotFoundError
|
|
113
75
|
*/
|
|
@@ -116,11 +78,6 @@ export function projectRoot(options = {}) {
|
|
|
116
78
|
if (fromEnvironment !== undefined && fromEnvironment !== '')
|
|
117
79
|
return normalizePath(fromEnvironment);
|
|
118
80
|
const cwd = currentDirectory(options);
|
|
119
|
-
if (cwd !== undefined) {
|
|
120
|
-
const sessionRoot = sessionWorkOwner(cwd);
|
|
121
|
-
if (sessionRoot !== undefined)
|
|
122
|
-
return sessionRoot;
|
|
123
|
-
}
|
|
124
81
|
// git push 等のフック内では GIT_DIR 等が設定され、作業ディレクトリの代わりに参照される。
|
|
125
82
|
// そのため GIT_* を除いて作業ディレクトリ基準で解決する
|
|
126
83
|
const toplevel = gitToplevel({ cwd, stripGitEnvironment: true });
|
|
@@ -11,7 +11,7 @@ export interface StateDirectoryOptions {
|
|
|
11
11
|
export declare function getStateDirectory(options?: Readonly<StateDirectoryOptions>): string;
|
|
12
12
|
/**
|
|
13
13
|
作業ディレクトリ `.pecot/work/<Issue番号>/` を作って返す。
|
|
14
|
-
|
|
14
|
+
ブランチを作るとき(session start)に呼ぶ。
|
|
15
15
|
作れないとき(プロジェクトルート不明・OS のエラー)は undefined。作業フロー自体は止めない
|
|
16
16
|
*/
|
|
17
17
|
export declare function ensureWorkDirectory(issueReference: string): string | undefined;
|
|
@@ -24,11 +24,6 @@ export declare function touchFlag(flagName: string): void;
|
|
|
24
24
|
*/
|
|
25
25
|
export declare function removeFlag(flagName: string): void;
|
|
26
26
|
/**
|
|
27
|
-
実投稿成功時にスラッシュコマンド免除フラグを消費(削除)する。
|
|
28
|
-
投稿自体は成功しているため、フラグ解決の失敗(git リポ外等)でコマンドを失敗させない
|
|
29
|
-
*/
|
|
30
|
-
export declare function consumeFlag(flagName: string): void;
|
|
31
|
-
/**
|
|
32
27
|
通常のファイルとして存在するか
|
|
33
28
|
*/
|
|
34
29
|
export declare function hasFlag(flagName: string): boolean;
|
|
@@ -47,8 +42,8 @@ export declare function writeBaseRecord(record: Readonly<BaseRecord>): void;
|
|
|
47
42
|
*/
|
|
48
43
|
export declare function readBaseRecord(): BaseReading;
|
|
49
44
|
/**
|
|
50
|
-
|
|
45
|
+
セッション名のキャッシュ(.pecot-session-title)を書く。
|
|
51
46
|
issueReference の末尾が整数でなければ InvalidValueError で、何も書かない
|
|
52
47
|
*/
|
|
53
|
-
export declare function
|
|
48
|
+
export declare function writeSessionTitle(issueReference: string, title: string): void;
|
|
54
49
|
//# sourceMappingURL=state-store.d.ts.map
|
|
@@ -4,8 +4,8 @@ import { closeSync, mkdirSync, openSync, statSync, unlinkSync, utimesSync, write
|
|
|
4
4
|
import path from 'node:path';
|
|
5
5
|
import { ProjectRootNotFoundError } from '../domain/errors.js';
|
|
6
6
|
import { pythonStrip } from '../domain/python-format.js';
|
|
7
|
-
import {
|
|
8
|
-
import { OsError, hasErrorCode, isFileNotFound
|
|
7
|
+
import { FLAG_PECOT_BASE, FLAG_PECOT_SESSION_TITLE, formatBaseRecord, interpretBaseRecord, planWorkTarget, workDirectoryName } from '../domain/state.js';
|
|
8
|
+
import { OsError, hasErrorCode, isFileNotFound } from './os-error.js';
|
|
9
9
|
import { projectRoot, STATE_DIR, WORK_DIR } from './paths.js';
|
|
10
10
|
import { readTextFile } from './text-file.js';
|
|
11
11
|
/**
|
|
@@ -19,7 +19,7 @@ export function getStateDirectory(options = {}) {
|
|
|
19
19
|
}
|
|
20
20
|
/**
|
|
21
21
|
作業ディレクトリ `.pecot/work/<Issue番号>/` を作って返す。
|
|
22
|
-
|
|
22
|
+
ブランチを作るとき(session start)に呼ぶ。
|
|
23
23
|
作れないとき(プロジェクトルート不明・OS のエラー)は undefined。作業フロー自体は止めない
|
|
24
24
|
*/
|
|
25
25
|
export function ensureWorkDirectory(issueReference) {
|
|
@@ -59,22 +59,6 @@ export function removeFlag(flagName) {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
/**
|
|
62
|
-
実投稿成功時にスラッシュコマンド免除フラグを消費(削除)する。
|
|
63
|
-
投稿自体は成功しているため、フラグ解決の失敗(git リポ外等)でコマンドを失敗させない
|
|
64
|
-
*/
|
|
65
|
-
export function consumeFlag(flagName) {
|
|
66
|
-
try {
|
|
67
|
-
removeFlag(flagName);
|
|
68
|
-
}
|
|
69
|
-
catch (error) {
|
|
70
|
-
// 握るのは OS の失敗とプロジェクトルート不明だけ。投稿は成功しているので、後始末の失敗でコマンドを失敗させない。
|
|
71
|
-
// プログラムの誤り(TypeError など)は握らない
|
|
72
|
-
if (error instanceof ProjectRootNotFoundError || isSystemCallError(error))
|
|
73
|
-
return;
|
|
74
|
-
throw error;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
/**
|
|
78
62
|
通常のファイルとして存在するか
|
|
79
63
|
*/
|
|
80
64
|
export function hasFlag(flagName) {
|
|
@@ -119,12 +103,10 @@ export function readBaseRecord() {
|
|
|
119
103
|
return interpretBaseRecord(readFlag(FLAG_PECOT_BASE));
|
|
120
104
|
}
|
|
121
105
|
/**
|
|
122
|
-
|
|
106
|
+
セッション名のキャッシュ(.pecot-session-title)を書く。
|
|
123
107
|
issueReference の末尾が整数でなければ InvalidValueError で、何も書かない
|
|
124
108
|
*/
|
|
125
|
-
export function
|
|
126
|
-
|
|
127
|
-
writeFlag(FLAG_PECOT_ACTIVE, target.active);
|
|
128
|
-
writeFlag(FLAG_PECOT_SESSION_TITLE, target.sessionTitle);
|
|
109
|
+
export function writeSessionTitle(issueReference, title) {
|
|
110
|
+
writeFlag(FLAG_PECOT_SESSION_TITLE, planWorkTarget(issueReference, title));
|
|
129
111
|
}
|
|
130
112
|
//# sourceMappingURL=state-store.js.map
|