diff --git a/server/lib/formatters/push.ts b/server/lib/formatters/push.ts index b252597..57a8863 100644 --- a/server/lib/formatters/push.ts +++ b/server/lib/formatters/push.ts @@ -25,8 +25,30 @@ export function formatPush( const baseUrl = repoBaseUrl(payload, repo); const forced = payload.forced as boolean | undefined; const created = payload.created as boolean | undefined; + const deleted = payload.deleted as boolean | undefined; const em = (e: string): string => emojiPrefix(e, showEmoji); + // A branch/tag deletion pushed via `git push --delete` arrives as a push + // event with `deleted: true` and no commits — render it like the `delete` + // event instead of a confusing "0 commits pushed". + if (deleted) { + const refType = isTagPush ? "tag" : "branch"; + return buildMessage( + { + author, + title: t("events.delete.title", { + repo: repo ?? t("common.repository"), + emoji: em(isTagPush ? "🏷️" : "🌿"), + type: refType, + ref: isTagPush ? tagLink(baseUrl, rawRef, ref) : branchLink(baseUrl, rawRef, ref), + }), + color: GITHUB_COLORS.delete, + }, + t, + repo, + ); + } + const descriptionParts: string[] = []; if (forced) { diff --git a/tests/formatter.test.ts b/tests/formatter.test.ts index ad3855e..a402dca 100644 --- a/tests/formatter.test.ts +++ b/tests/formatter.test.ts @@ -299,6 +299,28 @@ describe("group emoji toggle", () => { expect(msg.description).not.toContain("🔗"); }); + it("push with deleted:true renders as a branch deletion", () => { + const msg = formatEvent( + route, + event("push", { + ref: "refs/heads/dependabot/npm_and_yarn/multi-e1b34b8be3", + before: "abcd1234ef", + after: "0000000000000000000000000000000000000000", + created: false, + forced: false, + deleted: true, + commits: [], + repository: repo, + sender, + }), + ); + expect(msg.title).toBe( + "acme/widget: 🌿 Deleted branch [`dependabot/npm_and_yarn/multi-e1b34b8be3`](https://github.com/acme/widget/tree/dependabot/npm_and_yarn/multi-e1b34b8be3)", + ); + expect(msg.description).toBeUndefined(); + expect(msg.fields).toBeUndefined(); + }); + it("push commit renders linked short hash with plain-text message", () => { const msg = formatEvent( route,