mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
fix(push): render created tags/branches as create events instead of 0 commits
This commit is contained in:
parent
5c31b573d3
commit
cc8bb4182f
4 changed files with 36 additions and 2 deletions
|
|
@ -20,6 +20,10 @@ Check in order:
|
||||||
- The user must run `/gh login` first and the OAuth secrets (`GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`, `BASE_URL`) must be configured.
|
- The user must run `/gh login` first and the OAuth secrets (`GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`, `BASE_URL`) must be configured.
|
||||||
- Slash commands sync from the scheduled trigger every 5 minutes; global registration can take ~1 hour to propagate.
|
- Slash commands sync from the scheduled trigger every 5 minutes; global registration can take ~1 hour to propagate.
|
||||||
|
|
||||||
|
## I created a tag/branch but got a "0 commits" push message
|
||||||
|
|
||||||
|
Creating a tag or an empty branch via `git push` arrives as a push event with `created: true` and no commits — since the event carries the `created` flag, it is rendered as a normal `create` message. If you still see "0 commits", the payload's `created` flag was absent (e.g. an old or non-conforming delivery).
|
||||||
|
|
||||||
## I deleted a branch but got a "0 commits" push message
|
## I deleted a branch but got a "0 commits" push message
|
||||||
|
|
||||||
Branch deletions via `git push --delete` arrive as push events with `deleted: true` — they are rendered as a normal delete message. If you still see "0 commits", the payload's `deleted` flag was absent (e.g. an old delivery).
|
Branch deletions via `git push --delete` arrive as push events with `deleted: true` — they are rendered as a normal delete message. If you still see "0 commits", the payload's `deleted` flag was absent (e.g. an old delivery).
|
||||||
|
|
|
||||||
|
|
@ -20,6 +20,10 @@
|
||||||
- 用户需先执行 `/gh login`,且 OAuth 密钥(`GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`、`BASE_URL`)已配置。
|
- 用户需先执行 `/gh login`,且 OAuth 密钥(`GITHUB_CLIENT_ID` / `GITHUB_CLIENT_SECRET`、`BASE_URL`)已配置。
|
||||||
- 斜杠命令由定时任务每 5 分钟同步;全局注册可能需要约 1 小时传播。
|
- 斜杠命令由定时任务每 5 分钟同步;全局注册可能需要约 1 小时传播。
|
||||||
|
|
||||||
|
## 创建标签/分支后收到"0 个提交"的推送消息
|
||||||
|
|
||||||
|
通过 `git push` 创建标签或空分支时,事件以 `created: true` 且无提交的 push 事件到达——由于载荷带有 `created` 标志,会被渲染为正常的创建消息。若仍看到"0 个提交",说明载荷中缺少 `created` 标志(例如旧或不合规的投递)。
|
||||||
|
|
||||||
## 删除分支后收到"0 个提交"的推送消息
|
## 删除分支后收到"0 个提交"的推送消息
|
||||||
|
|
||||||
通过 `git push --delete` 删除分支时,事件以 `deleted: true` 的 push 事件到达——会被渲染为正常的删除消息。若仍看到"0 个提交",说明载荷中缺少 `deleted` 标志(例如旧投递)。
|
通过 `git push --delete` 删除分支时,事件以 `deleted: true` 的 push 事件到达——会被渲染为正常的删除消息。若仍看到"0 个提交",说明载荷中缺少 `deleted` 标志(例如旧投递)。
|
||||||
|
|
|
||||||
|
|
@ -57,6 +57,28 @@ export function formatPush(
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// A newly-created branch/tag pushed via `git push` arrives as a push event
|
||||||
|
// with `created: true` and no commits — render it like the `create` event
|
||||||
|
// instead of a confusing "0 commits pushed".
|
||||||
|
if (created && count === 0) {
|
||||||
|
const refType = isTagPush ? "tag" : "branch";
|
||||||
|
const cleanRef = rawRef.replace("refs/heads/", "").replace("refs/tags/", "");
|
||||||
|
return buildMessage(
|
||||||
|
{
|
||||||
|
author,
|
||||||
|
title: t("events.create.title", {
|
||||||
|
repo: repo ?? t("common.repository"),
|
||||||
|
emoji: em(isTagPush ? "🏷️" : "🌿"),
|
||||||
|
type: refType,
|
||||||
|
ref: isTagPush ? tagLink(baseUrl, cleanRef) : branchLink(baseUrl, cleanRef),
|
||||||
|
}),
|
||||||
|
color: GITHUB_COLORS.create,
|
||||||
|
},
|
||||||
|
t,
|
||||||
|
repo,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
const descLines: string[] = [];
|
const descLines: string[] = [];
|
||||||
|
|
||||||
if (forced) {
|
if (forced) {
|
||||||
|
|
|
||||||
|
|
@ -459,7 +459,7 @@ describe("limits and localization", () => {
|
||||||
expect(msg.description).toBe(`${link} ${"x".repeat(MAX_COMMIT_SUBJECT)}`);
|
expect(msg.description).toBe(`${link} ${"x".repeat(MAX_COMMIT_SUBJECT)}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("tag push created mentions the tag", () => {
|
it("tag push created renders as a tag creation", () => {
|
||||||
const msg = formatEvent(
|
const msg = formatEvent(
|
||||||
route,
|
route,
|
||||||
event("push", {
|
event("push", {
|
||||||
|
|
@ -472,7 +472,11 @@ describe("limits and localization", () => {
|
||||||
sender,
|
sender,
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
expect(msg.description).toBe("🆕 Tag created");
|
expect(msg.title).toBe(
|
||||||
|
"acme/widget: 🏷️ Created tag [`v1.0`](https://github.com/acme/widget/releases/tag/v1.0)",
|
||||||
|
);
|
||||||
|
expect(msg.color).toBe(4176208);
|
||||||
|
expect(msg.description).toBeUndefined();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("commit_comment without a commit id omits the sha", () => {
|
it("commit_comment without a commit id omits the sha", () => {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue