mirror of
https://github.com/RayLabsHQ/gitea-mirror.git
synced 2025-12-06 11:36:44 +03:00
fix: Sort releases by published_at instead of created_at
This commit is contained in:
@@ -1,40 +1,22 @@
|
|||||||
import {
|
import {
|
||||||
and,
|
repoStatusEnum,
|
||||||
eq,
|
|
||||||
} from 'drizzle-orm';
|
|
||||||
|
|
||||||
import type { Config } from '@/types/config';
|
|
||||||
import { membershipRoleEnum } from '@/types/organizations';
|
|
||||||
import {
|
|
||||||
type RepositoryVisibility,
|
type RepositoryVisibility,
|
||||||
type RepoStatus,
|
type RepoStatus,
|
||||||
repoStatusEnum,
|
} from "@/types/Repository";
|
||||||
} from '@/types/Repository';
|
import { membershipRoleEnum } from "@/types/organizations";
|
||||||
import { Octokit } from '@octokit/rest';
|
import { Octokit } from "@octokit/rest";
|
||||||
|
import type { Config } from "@/types/config";
|
||||||
import {
|
import type { Organization, Repository } from "./db/schema";
|
||||||
db,
|
import { httpPost, httpGet, httpDelete, httpPut, httpPatch } from "./http-client";
|
||||||
organizations,
|
import { createMirrorJob } from "./helpers";
|
||||||
repositories,
|
import { db, organizations, repositories } from "./db";
|
||||||
} from './db';
|
import { eq, and } from "drizzle-orm";
|
||||||
import type {
|
import { decryptConfigTokens } from "./utils/config-encryption";
|
||||||
Organization,
|
import { formatDateShort } from "./utils";
|
||||||
Repository,
|
|
||||||
} from './db/schema';
|
|
||||||
import { createMirrorJob } from './helpers';
|
|
||||||
import {
|
|
||||||
httpDelete,
|
|
||||||
httpGet,
|
|
||||||
httpPatch,
|
|
||||||
httpPost,
|
|
||||||
httpPut,
|
|
||||||
} from './http-client';
|
|
||||||
import {
|
import {
|
||||||
parseRepositoryMetadataState,
|
parseRepositoryMetadataState,
|
||||||
serializeRepositoryMetadataState,
|
serializeRepositoryMetadataState,
|
||||||
} from './metadata-state';
|
} from "./metadata-state";
|
||||||
import { formatDateShort } from './utils';
|
|
||||||
import { decryptConfigTokens } from './utils/config-encryption';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Helper function to get organization configuration including destination override
|
* Helper function to get organization configuration including destination override
|
||||||
@@ -2011,7 +1993,11 @@ export async function mirrorGitHubReleasesToGitea({
|
|||||||
let skippedCount = 0;
|
let skippedCount = 0;
|
||||||
|
|
||||||
const getReleaseTimestamp = (release: typeof releases.data[number]) => {
|
const getReleaseTimestamp = (release: typeof releases.data[number]) => {
|
||||||
const sourceDate = release.created_at ?? release.published_at ?? "";
|
// Use published_at first (when the release was published on GitHub)
|
||||||
|
// Fall back to created_at (when the git tag was created) only if published_at is missing
|
||||||
|
// This matches GitHub's sorting behavior and handles cases where multiple tags
|
||||||
|
// point to the same commit but have different publish dates
|
||||||
|
const sourceDate = release.published_at ?? release.created_at ?? "";
|
||||||
const timestamp = sourceDate ? new Date(sourceDate).getTime() : 0;
|
const timestamp = sourceDate ? new Date(sourceDate).getTime() : 0;
|
||||||
return Number.isFinite(timestamp) ? timestamp : 0;
|
return Number.isFinite(timestamp) ? timestamp : 0;
|
||||||
};
|
};
|
||||||
@@ -2023,10 +2009,14 @@ export async function mirrorGitHubReleasesToGitea({
|
|||||||
.slice(0, releaseLimit)
|
.slice(0, releaseLimit)
|
||||||
.sort((a, b) => getReleaseTimestamp(a) - getReleaseTimestamp(b));
|
.sort((a, b) => getReleaseTimestamp(a) - getReleaseTimestamp(b));
|
||||||
|
|
||||||
console.log(`[Releases] Processing ${releasesToProcess.length} releases in chronological order (oldest to newest)`);
|
console.log(`[Releases] Processing ${releasesToProcess.length} releases in chronological order (oldest to newest by published date)`);
|
||||||
releasesToProcess.forEach((rel, idx) => {
|
releasesToProcess.forEach((rel, idx) => {
|
||||||
const date = new Date(rel.published_at || rel.created_at);
|
const publishedDate = new Date(rel.published_at || rel.created_at);
|
||||||
console.log(`[Releases] ${idx + 1}. ${rel.tag_name} - Originally published: ${date.toISOString()}`);
|
const createdDate = new Date(rel.created_at);
|
||||||
|
const dateInfo = rel.published_at !== rel.created_at
|
||||||
|
? `published ${publishedDate.toISOString()} (tag created ${createdDate.toISOString()})`
|
||||||
|
: `published ${publishedDate.toISOString()}`;
|
||||||
|
console.log(`[Releases] ${idx + 1}. ${rel.tag_name} - ${dateInfo}`);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check if existing releases in Gitea are in the wrong order
|
// Check if existing releases in Gitea are in the wrong order
|
||||||
@@ -2116,9 +2106,21 @@ export async function mirrorGitHubReleasesToGitea({
|
|||||||
|
|
||||||
// Prepare release body with GitHub original date header
|
// Prepare release body with GitHub original date header
|
||||||
const githubPublishedDate = release.published_at || release.created_at;
|
const githubPublishedDate = release.published_at || release.created_at;
|
||||||
const githubDateHeader = githubPublishedDate
|
const githubTagCreatedDate = release.created_at;
|
||||||
? `> 📅 **Originally published on GitHub:** ${new Date(githubPublishedDate).toUTCString()}\n\n`
|
|
||||||
: '';
|
let githubDateHeader = '';
|
||||||
|
if (githubPublishedDate) {
|
||||||
|
githubDateHeader = `> 📅 **Originally published on GitHub:** ${new Date(githubPublishedDate).toUTCString()}`;
|
||||||
|
|
||||||
|
// If the tag was created on a different date than the release was published,
|
||||||
|
// show both dates (helps with repos that create multiple tags from the same commit)
|
||||||
|
if (release.published_at && release.created_at && release.published_at !== release.created_at) {
|
||||||
|
githubDateHeader += `\n> 🏷️ **Git tag created:** ${new Date(githubTagCreatedDate).toUTCString()}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
githubDateHeader += '\n\n';
|
||||||
|
}
|
||||||
|
|
||||||
const originalReleaseNote = release.body || "";
|
const originalReleaseNote = release.body || "";
|
||||||
const releaseNote = githubDateHeader + originalReleaseNote;
|
const releaseNote = githubDateHeader + originalReleaseNote;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user