From cb3cdc809d38d37c9c6f2f2124dfbeaa4af6f901 Mon Sep 17 00:00:00 2001 From: Futrime Date: Sat, 3 Feb 2024 17:50:33 +0800 Subject: [PATCH] feat: remove `source` field from `tooth.json` --- CHANGELOG.md | 8 ++++++-- lib/github_bot.ts | 7 +++---- lib/metadata.ts | 4 ---- lib/rawmetadata.ts | 1 - lib/schema.ts | 3 +-- models/tooth_version.ts | 13 ++++--------- routes/search/teeth.ts | 11 +++++------ routes/teeth.ts | 5 ++--- 8 files changed, 21 insertions(+), 31 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 91a6be9..cc17c13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). -## [Unreleased] +## [0.8.0] - 2024-02-03 + +### Changed + +- Remove `source` field from `tooth.json`. ## [0.7.0] - 2024-01-19 @@ -71,7 +75,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Basic functionality. -[unreleased]: https://github.com/lippkg/lip-index/compare/v0.7.0...HEAD +[0.8.0]: https://github.com/lippkg/lip-index/compare/v0.7.0...v0.8.0 [0.7.0]: https://github.com/lippkg/lip-index/compare/v0.6.0...v0.7.0 [0.6.0]: https://github.com/lippkg/lip-index/compare/v0.5.0...v0.6.0 [0.5.0]: https://github.com/lippkg/lip-index/compare/v0.4.0...v0.5.0 diff --git a/lib/github_bot.ts b/lib/github_bot.ts index 251a8eb..e4e89c5 100644 --- a/lib/github_bot.ts +++ b/lib/github_bot.ts @@ -137,7 +137,7 @@ async function fetchVersion( throw new Error(`failed to fetch metadata: ${err.message}`); }); - const sourceRepoInfo = await getRepository(octokit, repoOwner, repoName); + const repoInfo = await getRepository(octokit, repoOwner, repoName); await toothVersionModel.upsert({ repoOwner, @@ -150,9 +150,8 @@ async function fetchVersion( author: metadata.author, tags: metadata.tags, avatarUrl: metadata.avatarUrl, - source: metadata.source, - sourceRepoCreatedAt: sourceRepoInfo.createdAt, - sourceRepoStarCount: sourceRepoInfo.starCount, + repoCreatedAt: repoInfo.createdAt, + starCount: repoInfo.starCount, updatedAt: new Date(), }); diff --git a/lib/metadata.ts b/lib/metadata.ts index e68b554..691a4f2 100644 --- a/lib/metadata.ts +++ b/lib/metadata.ts @@ -35,10 +35,6 @@ export class Metadata { get avatarUrl(): string|undefined { return this.raw.info.avatar_url; } - - get source(): string { - return this.raw.info.source ?? this.raw.tooth; - } } function validateRawMetadata(raw: RawMetadata) { diff --git a/lib/rawmetadata.ts b/lib/rawmetadata.ts index de16627..9a30266 100644 --- a/lib/rawmetadata.ts +++ b/lib/rawmetadata.ts @@ -5,6 +5,5 @@ export interface RawMetadata { info: { name: string; description: string; author: string; tags: string[]; avatar_url?: string; - source?: string; } } diff --git a/lib/schema.ts b/lib/schema.ts index fa1145f..e02ab78 100644 --- a/lib/schema.ts +++ b/lib/schema.ts @@ -14,8 +14,7 @@ export const JSON_SCHEMA = { 'type': 'array', 'items': {'type': 'string', 'pattern': '^[a-zA-Z0-9-]+$'} }, - 'avatar_url': {'type': 'string'}, - 'source': {'type': 'string'} + 'avatar_url': {'type': 'string'} }, 'required': ['name', 'description', 'author', 'tags'] }, diff --git a/models/tooth_version.ts b/models/tooth_version.ts index 524252c..fd19ecb 100644 --- a/models/tooth_version.ts +++ b/models/tooth_version.ts @@ -14,10 +14,9 @@ export class ToothVersionModel extends Model< declare author: string; declare tags: string[]; declare avatarUrl: string|null; - declare source: string; - declare sourceRepoCreatedAt: Date; - declare sourceRepoStarCount: number; + declare repoCreatedAt: Date; + declare starCount: number; declare updatedAt: Date; } @@ -65,15 +64,11 @@ export function createToothVersionModel(sequelize: Sequelize): avatarUrl: { type: DataTypes.STRING, }, - source: { - type: DataTypes.STRING, - allowNull: false, - }, - sourceRepoCreatedAt: { + repoCreatedAt: { type: DataTypes.DATE, allowNull: false, }, - sourceRepoStarCount: { + starCount: { type: DataTypes.INTEGER, allowNull: false, }, diff --git a/routes/search/teeth.ts b/routes/search/teeth.ts index 996591b..b9d46d0 100644 --- a/routes/search/teeth.ts +++ b/routes/search/teeth.ts @@ -26,8 +26,8 @@ const ORDER_MAP = { }; const SORT_MAP = { - starCount: 'sourceRepoStarCount', - createdAt: 'sourceRepoCreatedAt', + starCount: 'starCount', + createdAt: 'repoCreatedAt', updatedAt: 'releasedAt', }; @@ -55,7 +55,7 @@ router.get( ...params.queryList.map( (_, index) => ({ [sequelize.Op.like]: sequelize.literal( - `CONCAT("repoOwner", ' ', "repoName", ' ', name, ' ', description, ' ', author, ' ', array_to_string(tags, ' '), ' ', source) ILIKE :searchTerm${ + `CONCAT("repoOwner", ' ', "repoName", ' ', name, ' ', description, ' ', author, ' ', array_to_string(tags, ' ')) ILIKE :searchTerm${ index}`), })), { @@ -91,9 +91,8 @@ router.get( author: item.author, tags: item.tags, avatarUrl: item.avatarUrl, - source: item.source, - sourceRepoCreatedAt: item.sourceRepoCreatedAt.toISOString(), - sourceRepoStarCount: item.sourceRepoStarCount, + repoCreatedAt: item.repoCreatedAt.toISOString(), + starCount: item.starCount, })), }, }); diff --git a/routes/teeth.ts b/routes/teeth.ts index 1534be9..d1bc89f 100644 --- a/routes/teeth.ts +++ b/routes/teeth.ts @@ -58,9 +58,8 @@ router.get( author: item.author, tags: item.tags, avatarUrl: item.avatarUrl, - source: item.source, - sourceRepoCreatedAt: item.sourceRepoCreatedAt.toISOString(), - sourceRepoStarCount: item.sourceRepoStarCount, + repoCreatedAt: item.repoCreatedAt.toISOString(), + starCount: item.starCount, versions: versions.map((version) => ({ version: version.version.version,