refactor(push): extract commitField helper to reduce duplication

This commit is contained in:
RhenCloud 2026-08-03 09:09:56 +08:00
parent 7ee1e5899f
commit e2022de4bc
No known key found for this signature in database
GPG key ID: A574A617378C4E0B

View file

@ -43,26 +43,24 @@ export function formatPush(
const fields: Array<{ name: string; value: string; inline?: boolean }> = [];
if (count <= 5) {
for (const c of commits) {
const commitField = (c: (typeof commits)[number]): { name: string; value: string } => {
const shortId = c.id?.slice(0, 7) ?? "???????";
const msg = c.message?.split("\n")[0].slice(0, 72) ?? t("common.no_message");
fields.push({
name: `\`${shortId}\``,
value: msg,
inline: false,
});
const name =
repo && c.id
? `[\`${shortId}\`](https://github.com/${repo}/commit/${c.id})`
: `\`${shortId}\``;
return { name, value: msg };
};
if (count <= 5) {
for (const c of commits) {
fields.push({ ...commitField(c), inline: false });
}
} else {
const first3 = commits.slice(0, 3);
for (const c of first3) {
const shortId = c.id?.slice(0, 7) ?? "???????";
const msg = c.message?.split("\n")[0].slice(0, 72) ?? t("common.no_message");
fields.push({
name: `\`${shortId}\``,
value: msg,
inline: false,
});
fields.push({ ...commitField(c), inline: false });
}
fields.push({
name: `\u200b`,