Edit the drafted merge message before confirming
This commit is contained in:
+16
-7
@@ -1133,25 +1133,34 @@ export async function confirmMerge(taskId: string): Promise<void> {
|
||||
void showAlert(errorText(err));
|
||||
return;
|
||||
}
|
||||
await confirmThen(mergeQuestion(task.merge_title, target, coAuthors), "Merge", false, document.querySelector(".merge-button"), async () => {
|
||||
await post("/api/tasks/{taskId}/merge", { path: { taskId } });
|
||||
const title = h("input", { type: "text", value: task.merge_title, required: true, maxLength: 72, pattern: ".*\\S.*", class: "modal-field", ariaLabel: "Commit title" });
|
||||
const question = [h("p", { class: "modal-text" }, `Merge into ${target} as one commit titled:`), title];
|
||||
const trailers = mergeTrailers(coAuthors);
|
||||
if (trailers) {
|
||||
question.push(h("p", { class: "modal-text" }, trailers));
|
||||
}
|
||||
await confirmThen(question, "Merge", false, document.querySelector(".merge-button"), async () => {
|
||||
await post("/api/tasks/{taskId}/merge", { path: { taskId }, body: { merge_title: title.value } });
|
||||
});
|
||||
}
|
||||
|
||||
function mergeQuestion(title: string, target: string, coAuthors: Participant[]): string {
|
||||
const lines = [`Merge "${title}" into ${target}?`];
|
||||
function mergeTrailers(coAuthors: Participant[]): string {
|
||||
const lines: string[] = [];
|
||||
const credited = coAuthors.filter((p) => p.git_name && p.git_email);
|
||||
const missing = coAuthors.filter((p) => !p.git_name || !p.git_email);
|
||||
if (credited.length > 0) {
|
||||
lines.push("", "Co-authored-by:", ...credited.map((p) => ` ${p.git_name} <${p.git_email}>`));
|
||||
lines.push("Co-authored-by:", ...credited.map((p) => ` ${p.git_name} <${p.git_email}>`));
|
||||
}
|
||||
if (missing.length > 0) {
|
||||
lines.push("", "No git identity, so no trailer:", ...missing.map((p) => ` ${p.display_name} (${p.login})`));
|
||||
if (lines.length > 0) {
|
||||
lines.push("");
|
||||
}
|
||||
lines.push("No git identity, so no trailer:", ...missing.map((p) => ` ${p.display_name} (${p.login})`));
|
||||
}
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
async function confirmThen(question: string, action: string, danger: boolean, anchor: Element | null, act: () => Promise<void>) {
|
||||
async function confirmThen(question: string | Node[], action: string, danger: boolean, anchor: Element | null, act: () => Promise<void>) {
|
||||
if (!(await showConfirm(question, action, danger, anchor))) {
|
||||
return;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user