also looking at this
feat(touch): post the checkboxes the finishing-touch flow waits on
#1424
7 files
+149
-5
| @@ -144,6 +144,9 @@ export function getFinishingTouch(name: string): FinishingTouch { | ||
| 144 | 144 | return touch |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | /** Opens the offer block, so it can be found and replaced rather than repeated. */ | |
| 148 | export const TOUCH_OFFER_MARKER = '<!-- buddy:touches -->' | |
| 149 | ||
| 147 | 150 | /** |
| 148 | 151 | * Render the offer of available touches as checkbox markers. |
| 149 | 152 | * |
| @@ -161,7 +164,39 @@ export function renderTouchOffer(names: string[] = Object.keys(FINISHING_TOUCHES | ||
| 161 | 164 | if (lines.length === 0) |
| 162 | 165 | return '' |
| 163 | 166 | |
| 164 | return `<details><summary>Finishing touches</summary>\n\nTick one to have it run:\n\n${lines.join('\n')}\n\n</details>` | |
| 167 | return `${TOUCH_OFFER_MARKER}\n<details><summary>Finishing touches</summary>\n\nTick one to have it run:\n\n${lines.join('\n')}\n\n</details>` | |
| 168 | } | |
| 169 | ||
| 170 | /** | |
| 171 | * Whether a pull request body already carries the offer. | |
| 172 | * | |
| 173 | * Checked before appending, because the job that posts it runs on more than | |
| 174 | * one event and a body that accumulated the block twice would show a second | |
| 175 | * set of boxes that tick independently of the first. | |
| 176 | * | |
| 177 | * @param body - Pull request body | |
| 178 | */ | |
| 179 | export function hasTouchOffer(body: string | null | undefined): boolean { | |
| 180 | return Boolean(body?.includes(TOUCH_OFFER_MARKER)) | |
| 181 | } | |
| 182 | ||
| 183 | /** | |
| 184 | * Append the offer to a pull request body, once. | |
| 185 | * | |
| 186 | * @param body - Current body | |
| 187 | * @param names - Touches to offer | |
| 188 | * @returns The body with the offer, or unchanged when it already has one | |
| 189 | */ | |
| 190 | export function withTouchOffer(body: string | null | undefined, names?: string[]): string { | |
| 191 | const current = body ?? '' | |
| 192 | if (hasTouchOffer(current)) | |
| 193 | return current | |
| 194 | ||
| 195 | const offer = renderTouchOffer(names) | |
| 196 | if (!offer) | |
| 197 | return current | |
| 198 | ||
| 199 | return `${current.trimEnd()}\n\n${offer}\n` | |
| 165 | 200 | } |
| 166 | 201 | |
| 167 | 202 | /** Parse which touches a maintainer ticked. */ |