also looking at this
fix(review): persist review state where it is read back
#1405
6 files
+176
-14
| @@ -63,6 +63,28 @@ export function parseReviewState(body: string | null | undefined): ReviewState | | ||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | /** | |
| 67 | * Replace the review-state marker in a pull request body. | |
| 68 | * | |
| 69 | * The marker has to live on the pull request itself: `parseReviewState` reads | |
| 70 | * `pr.body` and nothing else, so state written anywhere else — a review | |
| 71 | * summary, a comment — is written and never read back. | |
| 72 | * | |
| 73 | * @param body - Current pull request body | |
| 74 | * @param state - State to store | |
| 75 | * @returns The body with exactly one, current, marker | |
| 76 | * @example | |
| 77 | * ```ts | |
| 78 | * await provider.updatePullRequest(number, { | |
| 79 | * body: upsertReviewState(pr.body, { reviewedSha, fingerprints, reviewedAt }), | |
| 80 | * }) | |
| 81 | * ``` | |
| 82 | */ | |
| 83 | export function upsertReviewState(body: string | null | undefined, state: Omit<ReviewState, 'schemaVersion'>): string { | |
| 84 | const withoutMarker = (body ?? '').replace(MARKER_REGEX, '').trimEnd() | |
| 85 | return `${withoutMarker}\n\n${serializeReviewState(state)}` | |
| 86 | } | |
| 87 | ||
| 66 | 88 | /** |
| 67 | 89 | * Whether a pull request needs reviewing. |
| 68 | 90 | * |