mirror of
https://github.com/ReCloudStudio/WebHooker.git
synced 2026-09-22 16:11:29 +00:00
feat: add locales and tests for workflow_job, status, ping formatters
This commit is contained in:
parent
4f6b5929c1
commit
b14b9f0bde
4 changed files with 91 additions and 1 deletions
|
|
@ -170,6 +170,76 @@ describe("message title spec", () => {
|
||||||
expect(msg.fields![3].value).toBe("abc123d");
|
expect(msg.fields![3].value).toBe("abc123d");
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it("workflow_job shows job status, workflow, branch and commit", () => {
|
||||||
|
const job = {
|
||||||
|
html_url: "https://github.com/acme/widget/actions/runs/2/job/9",
|
||||||
|
name: "test",
|
||||||
|
status: "completed",
|
||||||
|
conclusion: "failure",
|
||||||
|
workflow_name: "CI",
|
||||||
|
head_branch: "main",
|
||||||
|
head_sha: "abc123def456",
|
||||||
|
};
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("workflow_job", { workflow_job: job, repository: repo, sender }),
|
||||||
|
);
|
||||||
|
expect(msg.title).toBe("acme/widget: Job test — failure");
|
||||||
|
expect(msg.fields![0].value).toBe("❌ failure");
|
||||||
|
expect(msg.fields![1].value).toBe("test");
|
||||||
|
expect(msg.fields![2].value).toBe("CI");
|
||||||
|
expect(msg.fields![3].value).toBe("`main`");
|
||||||
|
expect(msg.fields![4].value).toBe("`abc123d`");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("status shows context, state and commit", () => {
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("status", {
|
||||||
|
state: "pending",
|
||||||
|
context: "continuous-integration/travis-ci",
|
||||||
|
description: "The Travis CI build is in progress",
|
||||||
|
target_url: "https://travis-ci.org/acme/widget/builds/1",
|
||||||
|
sha: "abc123def456",
|
||||||
|
repository: repo,
|
||||||
|
sender,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(msg.title).toBe("acme/widget: continuous-integration/travis-ci — pending");
|
||||||
|
expect(msg.fields![0].value).toBe("⏳ pending");
|
||||||
|
expect(msg.fields![1].value).toBe("continuous-integration/travis-ci");
|
||||||
|
expect(msg.fields![2].value).toBe("`abc123d`");
|
||||||
|
expect(msg.fields![3].value).toBe("The Travis CI build is in progress");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("deployment shows environment, branch and commit", () => {
|
||||||
|
const deployment = {
|
||||||
|
environment: "production",
|
||||||
|
ref: "refs/heads/main",
|
||||||
|
sha: "abc123def456",
|
||||||
|
description: "Deploy request from octocat",
|
||||||
|
html_url: "https://github.com/acme/widget/deployments/1",
|
||||||
|
};
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("deployment", { deployment, repository: repo, sender }),
|
||||||
|
);
|
||||||
|
expect(msg.title).toBe("acme/widget: Deployment to `production` — created");
|
||||||
|
expect(msg.fields![0].value).toBe("🚀 created");
|
||||||
|
expect(msg.fields![1].value).toBe("production");
|
||||||
|
expect(msg.fields![2].value).toBe("`main`");
|
||||||
|
expect(msg.fields![3].value).toBe("`abc123d`");
|
||||||
|
});
|
||||||
|
|
||||||
|
it("ping shows the webhook confirmation", () => {
|
||||||
|
const msg = formatEvent(
|
||||||
|
route,
|
||||||
|
event("ping", { zen: "Keep it logically awesome.", hook_id: 1, repository: repo, sender }),
|
||||||
|
);
|
||||||
|
expect(msg.title).toBe("acme/widget: Webhook ping");
|
||||||
|
expect(msg.fields![0].value).toBe("1");
|
||||||
|
});
|
||||||
|
|
||||||
it("unknown events fall back to repo: event: action", () => {
|
it("unknown events fall back to repo: event: action", () => {
|
||||||
const msg = formatEvent(
|
const msg = formatEvent(
|
||||||
route,
|
route,
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ export function formatDeployment(
|
||||||
if (deployment.ref) {
|
if (deployment.ref) {
|
||||||
fields.push({
|
fields.push({
|
||||||
name: t("fields.branch_tag"),
|
name: t("fields.branch_tag"),
|
||||||
value: `\`${deployment.ref}\``,
|
value: `\`${deployment.ref.replace("refs/heads/", "")}\``,
|
||||||
inline: true,
|
inline: true,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -110,6 +110,15 @@ export const en = {
|
||||||
workflow_run: {
|
workflow_run: {
|
||||||
title: "{repo}: {name} — {conclusion}",
|
title: "{repo}: {name} — {conclusion}",
|
||||||
},
|
},
|
||||||
|
workflow_job: {
|
||||||
|
title: "{repo}: Job {name} — {conclusion}",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
title: "{repo}: {context} — {state}",
|
||||||
|
},
|
||||||
|
ping: {
|
||||||
|
title: "{repo}: Webhook ping",
|
||||||
|
},
|
||||||
release: {
|
release: {
|
||||||
action_release: "{emoji}**{action}** release `{tag}`",
|
action_release: "{emoji}**{action}** release `{tag}`",
|
||||||
title: "{repo}: {name}",
|
title: "{repo}: {name}",
|
||||||
|
|
|
||||||
|
|
@ -48,6 +48,8 @@ export const zh = {
|
||||||
status: "状态",
|
status: "状态",
|
||||||
run: "运行",
|
run: "运行",
|
||||||
job: "作业",
|
job: "作业",
|
||||||
|
workflow: "工作流",
|
||||||
|
context: "上下文",
|
||||||
duration: "耗时",
|
duration: "耗时",
|
||||||
type: "类型",
|
type: "类型",
|
||||||
name: "名称",
|
name: "名称",
|
||||||
|
|
@ -108,6 +110,15 @@ export const zh = {
|
||||||
workflow_run: {
|
workflow_run: {
|
||||||
title: "{repo}: {name} — {conclusion}",
|
title: "{repo}: {name} — {conclusion}",
|
||||||
},
|
},
|
||||||
|
workflow_job: {
|
||||||
|
title: "{repo}: 作业 {name} — {conclusion}",
|
||||||
|
},
|
||||||
|
status: {
|
||||||
|
title: "{repo}: {context} — {state}",
|
||||||
|
},
|
||||||
|
ping: {
|
||||||
|
title: "{repo}: Webhook ping",
|
||||||
|
},
|
||||||
release: {
|
release: {
|
||||||
action_release: "{emoji}**{action}** 发布 `{tag}`",
|
action_release: "{emoji}**{action}** 发布 `{tag}`",
|
||||||
title: "{repo}: {name}",
|
title: "{repo}: {name}",
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue