mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2026-01-27 12:50:54 +03:00
mirror: show github timestamps in metadata
This commit is contained in:
@@ -12,6 +12,7 @@ import { createMirrorJob } from "./helpers";
|
|||||||
import { db, organizations, repositories } from "./db";
|
import { db, organizations, repositories } from "./db";
|
||||||
import { eq, and } from "drizzle-orm";
|
import { eq, and } from "drizzle-orm";
|
||||||
import { decryptConfigTokens } from "./utils/config-encryption";
|
import { decryptConfigTokens } from "./utils/config-encryption";
|
||||||
|
import { formatDateShort } from "./utils";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get organization configuration including destination override
|
* Helper function to get organization configuration including destination override
|
||||||
@@ -1646,11 +1647,15 @@ export const mirrorGitRepoIssuesToGitea = async ({
|
|||||||
.join(", ")} on GitHub.`
|
.join(", ")} on GitHub.`
|
||||||
: "";
|
: "";
|
||||||
|
|
||||||
|
const issueAuthor = issue.user?.login ?? "unknown";
|
||||||
|
const issueCreatedOn = formatDateShort(issue.created_at);
|
||||||
|
const issueOriginHeader = `Originally created by @${issueAuthor} on GitHub${
|
||||||
|
issueCreatedOn ? ` (${issueCreatedOn})` : ""
|
||||||
|
}.`;
|
||||||
|
|
||||||
const issuePayload: any = {
|
const issuePayload: any = {
|
||||||
title: issue.title,
|
title: issue.title,
|
||||||
body: `Originally created by @${
|
body: `${issueOriginHeader}${originalAssignees}\n\n${issue.body ?? ""}`,
|
||||||
issue.user?.login
|
|
||||||
} on GitHub.${originalAssignees}\n\n${issue.body || ""}`,
|
|
||||||
closed: issue.state === "closed",
|
closed: issue.state === "closed",
|
||||||
labels: giteaLabelIds,
|
labels: giteaLabelIds,
|
||||||
};
|
};
|
||||||
@@ -1690,10 +1695,16 @@ export const mirrorGitRepoIssuesToGitea = async ({
|
|||||||
await processWithRetry(
|
await processWithRetry(
|
||||||
sortedComments,
|
sortedComments,
|
||||||
async (comment) => {
|
async (comment) => {
|
||||||
|
const commenter = comment.user?.login ?? "unknown";
|
||||||
|
const commentDate = formatDateShort(comment.created_at);
|
||||||
|
const commentHeader = `@${commenter} commented on GitHub${
|
||||||
|
commentDate ? ` (${commentDate})` : ""
|
||||||
|
}:`;
|
||||||
|
|
||||||
await httpPost(
|
await httpPost(
|
||||||
`${config.giteaConfig!.url}/api/v1/repos/${giteaOwner}/${repoName}/issues/${createdIssue.data.number}/comments`,
|
`${config.giteaConfig!.url}/api/v1/repos/${giteaOwner}/${repoName}/issues/${createdIssue.data.number}/comments`,
|
||||||
{
|
{
|
||||||
body: `@${comment.user?.login} commented on GitHub:\n\n${comment.body}`,
|
body: `${commentHeader}\n\n${comment.body ?? ""}`,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Authorization: `token ${decryptedConfig.giteaConfig!.token}`,
|
Authorization: `token ${decryptedConfig.giteaConfig!.token}`,
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { describe, test, expect } from "bun:test";
|
import { describe, test, expect } from "bun:test";
|
||||||
import { jsonResponse, formatDate, truncate, safeParse, parseErrorMessage, showErrorToast } from "./utils";
|
import { jsonResponse, formatDate, formatDateShort, truncate, safeParse, parseErrorMessage, showErrorToast } from "./utils";
|
||||||
|
|
||||||
describe("jsonResponse", () => {
|
describe("jsonResponse", () => {
|
||||||
test("creates a Response with JSON content", () => {
|
test("creates a Response with JSON content", () => {
|
||||||
@@ -65,6 +65,18 @@ describe("formatDate", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("formatDateShort", () => {
|
||||||
|
test("returns formatted date when input is provided", () => {
|
||||||
|
const formatted = formatDateShort("2014-10-20T15:32:10Z");
|
||||||
|
expect(formatted).toBe("Oct 20, 2014");
|
||||||
|
});
|
||||||
|
|
||||||
|
test("returns undefined when date is missing", () => {
|
||||||
|
expect(formatDateShort(null)).toBeUndefined();
|
||||||
|
expect(formatDateShort(undefined)).toBeUndefined();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
describe("truncate", () => {
|
describe("truncate", () => {
|
||||||
test("truncates a string that exceeds the length", () => {
|
test("truncates a string that exceeds the length", () => {
|
||||||
const str = "This is a long string that needs truncation";
|
const str = "This is a long string that needs truncation";
|
||||||
|
|||||||
@@ -29,6 +29,15 @@ export function formatDate(date?: Date | string | null): string {
|
|||||||
}).format(new Date(date));
|
}).format(new Date(date));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function formatDateShort(date?: Date | string | null): string | undefined {
|
||||||
|
if (!date) return undefined;
|
||||||
|
return new Intl.DateTimeFormat("en-US", {
|
||||||
|
year: "numeric",
|
||||||
|
month: "short",
|
||||||
|
day: "numeric",
|
||||||
|
}).format(new Date(date));
|
||||||
|
}
|
||||||
|
|
||||||
export function formatLastSyncTime(date: Date | string | null): string {
|
export function formatLastSyncTime(date: Date | string | null): string {
|
||||||
if (!date) return "Never";
|
if (!date) return "Never";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user