@pecot/workflow-mcp 6.0.0 → 7.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.
Files changed (84) hide show
  1. package/.claude-plugin/plugin.json +1 -1
  2. package/README.md +4 -57
  3. package/cli/dist/commands/board-add.js +11 -1
  4. package/cli/dist/commands/board-judgment.d.ts +12 -3
  5. package/cli/dist/commands/board-judgment.js +12 -6
  6. package/cli/dist/commands/board-move.js +9 -1
  7. package/cli/dist/commands/board-readiness.d.ts +3 -3
  8. package/cli/dist/commands/board-show.js +5 -2
  9. package/cli/dist/commands/board-sync.js +14 -5
  10. package/cli/dist/commands/board-view.d.ts +94 -5
  11. package/cli/dist/commands/board-view.js +119 -17
  12. package/cli/dist/commands/branch.js +12 -1
  13. package/cli/dist/commands/command-definition.d.ts +19 -2
  14. package/cli/dist/commands/command-definition.js +9 -0
  15. package/cli/dist/commands/failure-kind.d.ts +1 -1
  16. package/cli/dist/commands/failure-kind.js +1 -0
  17. package/cli/dist/commands/issue-board.d.ts +31 -3
  18. package/cli/dist/commands/issue-board.js +28 -4
  19. package/cli/dist/commands/issue-comment.js +19 -2
  20. package/cli/dist/commands/issue-create.js +90 -7
  21. package/cli/dist/commands/issue-dependency.js +32 -4
  22. package/cli/dist/commands/issue-readiness.d.ts +30 -2
  23. package/cli/dist/commands/issue-readiness.js +35 -0
  24. package/cli/dist/commands/issue-reopen.js +18 -3
  25. package/cli/dist/commands/issue-shared.d.ts +3 -3
  26. package/cli/dist/commands/issue-shared.js +3 -2
  27. package/cli/dist/commands/issue-show.js +78 -8
  28. package/cli/dist/commands/names.js +1 -0
  29. package/cli/dist/commands/output.d.ts +18 -2
  30. package/cli/dist/commands/output.js +16 -3
  31. package/cli/dist/commands/pr-merge.d.ts +3 -0
  32. package/cli/dist/commands/pr-merge.js +230 -0
  33. package/cli/dist/commands/pr-reference.d.ts +8 -0
  34. package/cli/dist/commands/pr-reference.js +30 -0
  35. package/cli/dist/commands/pr-restack.d.ts +6 -0
  36. package/cli/dist/commands/pr-restack.js +233 -0
  37. package/cli/dist/commands/pr-waiting.d.ts +41 -2
  38. package/cli/dist/commands/pr-waiting.js +74 -37
  39. package/cli/dist/commands/pr.d.ts +10 -6
  40. package/cli/dist/commands/pr.js +160 -67
  41. package/cli/dist/commands/project-sync.d.ts +10 -2
  42. package/cli/dist/commands/project-sync.js +7 -6
  43. package/cli/dist/commands/project.js +173 -16
  44. package/cli/dist/commands/registry.js +2 -0
  45. package/cli/dist/commands/release.js +67 -18
  46. package/cli/dist/commands/repository-match.js +7 -2
  47. package/cli/dist/commands/session-finish.js +128 -12
  48. package/cli/dist/commands/session-start.js +22 -6
  49. package/cli/dist/commands/session.js +121 -20
  50. package/cli/dist/commands/tracker-sync-dependabot.js +21 -4
  51. package/cli/dist/commands/tracker-sync-security.js +22 -4
  52. package/cli/dist/commands/tracker-sync.d.ts +30 -0
  53. package/cli/dist/commands/tracker-sync.js +15 -0
  54. package/cli/dist/commands/tracker.js +2 -0
  55. package/cli/dist/commands/work-target.d.ts +10 -2
  56. package/cli/dist/commands/work-target.js +6 -4
  57. package/cli/dist/commands/worktree.js +71 -5
  58. package/cli/dist/domain/issue-readout.d.ts +0 -4
  59. package/cli/dist/domain/pull-request.d.ts +1 -1
  60. package/cli/dist/domain/readiness.d.ts +17 -0
  61. package/cli/dist/domain/readiness.js +39 -2
  62. package/cli/dist/domain/restack.d.ts +62 -0
  63. package/cli/dist/domain/restack.js +53 -0
  64. package/cli/dist/domain/state.d.ts +39 -0
  65. package/cli/dist/domain/state.js +28 -1
  66. package/cli/dist/domain/work-start.d.ts +0 -4
  67. package/cli/dist/domain/work-start.js +0 -7
  68. package/cli/dist/infra/git.d.ts +64 -0
  69. package/cli/dist/infra/git.js +110 -0
  70. package/cli/dist/infra/github/pulls.d.ts +81 -2
  71. package/cli/dist/infra/github/pulls.js +116 -5
  72. package/cli/dist/infra/github/queries.d.ts +4 -1
  73. package/cli/dist/infra/github/queries.js +47 -32
  74. package/cli/dist/infra/github/readout.js +0 -33
  75. package/cli/dist/mcp/result.d.ts +63 -16
  76. package/cli/dist/mcp/result.js +106 -30
  77. package/cli/dist/mcp/server.js +37 -4
  78. package/cli/templates/comment/plan.md +2 -2
  79. package/cli/templates/comment/review-findings.md +3 -2
  80. package/cli/templates/issue/bug.md +13 -4
  81. package/cli/templates/issue/task.md +13 -4
  82. package/cli/templates/workflow/pecot-board-sync.yml +1 -1
  83. package/npm-shrinkwrap.json +2 -2
  84. package/package.json +1 -1
@@ -1,6 +1,8 @@
1
1
  // git コマンド実行の唯一の窓口。git の subprocess 呼び出しはすべて runGit を経由する。
2
2
  // 値を返す helper(gitToplevel 等)は、失敗時に undefined を返す。
3
3
  import { spawnSync } from 'node:child_process';
4
+ import { existsSync } from 'node:fs';
5
+ import path from 'node:path';
4
6
  import { parseRemoteUrl } from '../domain/git-url.js';
5
7
  import { BaseError, InvalidValueError } from '../domain/errors.js';
6
8
  import { normalizeNewlines, pythonRepr, pythonStrip } from '../domain/python-format.js';
@@ -142,4 +144,112 @@ export function remoteRepository(cwd, remote) {
142
144
  throw error;
143
145
  }
144
146
  }
147
+ // 端末で尋ねさせない。ssh は GIT_SSH_COMMAND で BatchMode にすると利用者の GIT_SSH と core.sshCommand を上書きするので、askpass を失敗させる
148
+ export const NON_INTERACTIVE_GIT = { GIT_TERMINAL_PROMPT: '0', SSH_ASKPASS: 'false', SSH_ASKPASS_REQUIRE: 'force' };
149
+ // fetch・push は、認証の入力を待たずに、この時間で諦める
150
+ const REMOTE_TIMEOUT_MILLISECONDS = 60_000;
151
+ const PEEL_TO_COMMIT = '^{commit}';
152
+ /**
153
+ `git fetch <remote>`。失敗・時間切れは succeeded が false
154
+ */
155
+ export function fetchRemote(cwd, remote) {
156
+ const result = runGit(['fetch', remote], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
157
+ return { succeeded: result.exitCode === 0, stderr: result.stderr };
158
+ }
159
+ /**
160
+ ref の指すコミットの SHA。無ければ undefined
161
+ */
162
+ export function resolveCommit(cwd, reference) {
163
+ return runForValue(['rev-parse', '--verify', '--quiet', `${reference}${PEEL_TO_COMMIT}`], { cwd });
164
+ }
165
+ /**
166
+ 2 つの ref の merge-base の SHA。共通の祖先が無ければ undefined
167
+ */
168
+ export function mergeBase(cwd, a, b) {
169
+ return runForValue(['merge-base', a, b], { cwd });
170
+ }
171
+ // 失敗の後に rebase の途中なら衝突、ほかの失敗は GitCommandError
172
+ function rebaseOutcome(cwd, arguments_, environment) {
173
+ const result = runGit(arguments_, { cwd, env: environment });
174
+ if (result.exitCode === 0)
175
+ return 'done';
176
+ if (isRebaseInProgress(cwd))
177
+ return 'conflict';
178
+ throw new GitCommandError(arguments_, result);
179
+ }
180
+ /**
181
+ `git rebase --onto <newBase> <oldBase>`。利用者の rebase.updateRefs に関わらず、ほかのブランチは書き換えない
182
+ */
183
+ export function rebaseOnto(cwd, newBase, oldBase) {
184
+ const arguments_ = ['rebase', '--no-update-refs', '--onto', newBase, oldBase];
185
+ // 既に途中なら git は始めずに失敗する。その失敗を衝突と読まない
186
+ if (isRebaseInProgress(cwd))
187
+ throw new GitCommandError(arguments_, runGit(arguments_, { cwd }));
188
+ return rebaseOutcome(cwd, arguments_);
189
+ }
190
+ /**
191
+ 衝突を解いた後の `git rebase --continue`。コミットの文の編集は開かない
192
+ */
193
+ export function continueRebase(cwd) {
194
+ return rebaseOutcome(cwd, ['rebase', '--continue'], { ...NON_INTERACTIVE_GIT, GIT_EDITOR: 'true' });
195
+ }
196
+ export function abortRebase(cwd) {
197
+ runGit(['rebase', '--abort'], { cwd, check: true });
198
+ }
199
+ /**
200
+ rebase の途中か。worktree では .git がファイルなので、git に場所を尋ねる
201
+ */
202
+ export function isRebaseInProgress(cwd) {
203
+ const output = runGit(['rev-parse', '--git-path', 'rebase-merge', '--git-path', 'rebase-apply'], { cwd, check: true }).stdout;
204
+ // eslint-disable-next-line security/detect-non-literal-fs-filename -- git が返した git ディレクトリの中のパス
205
+ return output.split('\n').filter(line => line !== '').some(line => existsSync(path.resolve(cwd, line)));
206
+ }
207
+ /**
208
+ 衝突が残っているファイルの一覧
209
+ */
210
+ export function conflictedFiles(cwd) {
211
+ return runGit(['diff', '--name-only', '--diff-filter=U'], { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
212
+ }
213
+ /**
214
+ remoteBranch にあり、local に同じ変更(patch-id)の無いコミットの SHA。excluded から届くコミットは除く
215
+ */
216
+ export function remoteOnlyChanges(cwd, local, remoteBranch, excluded) {
217
+ const arguments_ = ['rev-list', '--right-only', '--cherry-pick', '--no-merges', `${local}...${remoteBranch}`, ...excluded.map(reference => `^${reference}`), '--'];
218
+ return runGit(arguments_, { cwd, check: true }).stdout.split('\n').filter(line => line !== '');
219
+ }
220
+ /**
221
+ 2 つの ref の木が同じか
222
+ */
223
+ export function hasSameTree(cwd, a, b) {
224
+ const arguments_ = ['diff', '--quiet', a, b, '--'];
225
+ const result = runGit(arguments_, { cwd });
226
+ if (result.exitCode === 0)
227
+ return true;
228
+ if (result.exitCode === 1)
229
+ return false;
230
+ throw new GitCommandError(arguments_, result);
231
+ }
232
+ export function resetHardTo(cwd, reference) {
233
+ runGit(['reset', '--quiet', '--hard', reference], { cwd, check: true });
234
+ }
235
+ /**
236
+ remote の branch が expectedSha のときだけ、手元の branch で置き換える。拒まれたか失敗したら stderr を返す
237
+ */
238
+ export function pushWithLease(cwd, remote, branch, expectedSha) {
239
+ const result = runGit(['push', `--force-with-lease=${branch}:${expectedSha}`, remote, branch], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: REMOTE_TIMEOUT_MILLISECONDS });
240
+ return result.exitCode === 0 ? { pushed: true } : { pushed: false, stderr: result.stderr };
241
+ }
242
+ // ls-remote は、ref が無いと終了コード 2 を返す
243
+ const LS_REMOTE_NOT_FOUND = 2;
244
+ const LS_REMOTE_TIMEOUT_MILLISECONDS = 10_000;
245
+ /**
246
+ remote の branch の先頭の SHA を、追跡参照を更新せずに尋ねる。無ければ sha が undefined。届かないか時間切れなら isReachable が false
247
+ */
248
+ export function remoteBranchHead(cwd, remote, branch) {
249
+ const listed = runGit(['ls-remote', '--exit-code', remote, `refs/heads/${branch}`], { cwd, env: NON_INTERACTIVE_GIT, timeoutMilliseconds: LS_REMOTE_TIMEOUT_MILLISECONDS });
250
+ if (listed.exitCode === LS_REMOTE_NOT_FOUND)
251
+ return { isReachable: true, sha: undefined };
252
+ const [sha] = listed.exitCode === 0 ? listed.stdout.split(/\s/u, 1) : [];
253
+ return sha === undefined || sha === '' ? { isReachable: false } : { isReachable: true, sha };
254
+ }
145
255
  //# sourceMappingURL=git.js.map
@@ -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
- mergePullRequest(owner: string, repository: string, number: number, mergeMethod?: string): Promise<JsonObject>;
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 timelineItems(\n itemTypes: [CONNECTED_EVENT, DISCONNECTED_EVENT, CROSS_REFERENCED_EVENT]\n first: 20\n ) {\n totalCount\n nodes {\n __typename\n ... on ConnectedEvent {\n subject {\n ... on PullRequest {\n ...PullRequestFields\n }\n }\n }\n ... on DisconnectedEvent {\n subject {\n ... on PullRequest {\n ...PullRequestFields\n }\n }\n }\n ... on CrossReferencedEvent {\n willCloseTarget\n source {\n ... on PullRequest {\n ...PullRequestFields\n }\n }\n }\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}";
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 は 3 つの読み口から集める
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
  /**