feat(core): Refactor TypeScript interfaces and improve module exports
This commit is contained in:
parent
470f4fe730
commit
5d0d125e43
@ -1,5 +1,12 @@
|
||||
# Changelog
|
||||
|
||||
## 2024-12-14 - 1.5.0 - feat(core)
|
||||
Refactor TypeScript interfaces and improve module exports
|
||||
|
||||
- Moved TypeScript interfaces to a dedicated file (ts/interfaces/index.ts).
|
||||
- Updated import/export structure to improve code readability and maintainability.
|
||||
- Enhanced the package.json to utilize a module exports field for better resolution.
|
||||
|
||||
## 2024-12-13 - 1.4.1 - fix(core)
|
||||
Corrected log formatting for commit information output in CodeFeed
|
||||
|
||||
|
@ -3,8 +3,10 @@
|
||||
"version": "1.4.1",
|
||||
"private": false,
|
||||
"description": "a module for creating feeds for code development",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"exports": {
|
||||
".": "./dist_ts/index.js",
|
||||
"./interfaces": "./dist_ts/interfaces/index.js"
|
||||
},
|
||||
"type": "module",
|
||||
"author": "Task Venture Capital GmbH",
|
||||
"license": "MIT",
|
||||
|
@ -3,6 +3,6 @@
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@foss.global/codefeed',
|
||||
version: '1.4.1',
|
||||
version: '1.5.0',
|
||||
description: 'a module for creating feeds for code development'
|
||||
}
|
||||
|
@ -1,3 +1,10 @@
|
||||
// module
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
export {
|
||||
interfaces,
|
||||
}
|
||||
|
||||
// @push.rocks
|
||||
import * as qenv from '@push.rocks/qenv';
|
||||
import * as smartnpm from '@push.rocks/smartnpm';
|
||||
|
66
ts/index.ts
66
ts/index.ts
@ -1,49 +1,5 @@
|
||||
import * as plugins from './codefeed.plugins.js';
|
||||
|
||||
interface RepositoryOwner {
|
||||
login: string;
|
||||
}
|
||||
|
||||
interface Repository {
|
||||
owner: RepositoryOwner;
|
||||
name: string;
|
||||
}
|
||||
|
||||
interface CommitAuthor {
|
||||
date: string;
|
||||
}
|
||||
|
||||
interface CommitDetail {
|
||||
message: string;
|
||||
author: CommitAuthor;
|
||||
}
|
||||
|
||||
interface Commit {
|
||||
sha: string;
|
||||
commit: CommitDetail;
|
||||
}
|
||||
|
||||
interface Tag {
|
||||
commit?: {
|
||||
sha?: string;
|
||||
};
|
||||
}
|
||||
|
||||
interface RepoSearchResponse {
|
||||
data: Repository[];
|
||||
}
|
||||
|
||||
export interface CommitResult {
|
||||
baseUrl: string;
|
||||
org: string;
|
||||
repo: string;
|
||||
timestamp: string;
|
||||
hash: string;
|
||||
commitMessage: string;
|
||||
tagged: boolean;
|
||||
publishedOnNpm: boolean;
|
||||
prettyAgoTime: string;
|
||||
}
|
||||
|
||||
export class CodeFeed {
|
||||
private baseUrl: string;
|
||||
@ -123,9 +79,9 @@ export class CodeFeed {
|
||||
/**
|
||||
* Fetch all repositories accessible to the token/user.
|
||||
*/
|
||||
private async fetchAllRepositories(): Promise<Repository[]> {
|
||||
private async fetchAllRepositories(): Promise<plugins.interfaces.Repository[]> {
|
||||
let page = 1;
|
||||
const allRepos: Repository[] = [];
|
||||
const allRepos: plugins.interfaces.Repository[] = [];
|
||||
|
||||
while (true) {
|
||||
const url = new URL(`${this.baseUrl}/api/v1/repos/search`);
|
||||
@ -140,7 +96,7 @@ export class CodeFeed {
|
||||
throw new Error(`Failed to fetch repositories: ${resp.statusText}`);
|
||||
}
|
||||
|
||||
const data: RepoSearchResponse = await resp.json();
|
||||
const data: plugins.interfaces.RepoSearchResponse = await resp.json();
|
||||
allRepos.push(...data.data);
|
||||
|
||||
if (data.data.length < 50) {
|
||||
@ -157,7 +113,7 @@ export class CodeFeed {
|
||||
*/
|
||||
private async fetchTags(owner: string, repo: string): Promise<Set<string>> {
|
||||
let page = 1;
|
||||
const tags: Tag[] = [];
|
||||
const tags: plugins.interfaces.Tag[] = [];
|
||||
|
||||
while (true) {
|
||||
const url = new URL(`${this.baseUrl}/api/v1/repos/${owner}/${repo}/tags`);
|
||||
@ -173,7 +129,7 @@ export class CodeFeed {
|
||||
throw new Error(`Failed to fetch tags for ${owner}/${repo}: ${resp.statusText}`);
|
||||
}
|
||||
|
||||
const data: Tag[] = await resp.json();
|
||||
const data: plugins.interfaces.Tag[] = await resp.json();
|
||||
tags.push(...data);
|
||||
|
||||
if (data.length < 50) {
|
||||
@ -195,10 +151,10 @@ export class CodeFeed {
|
||||
/**
|
||||
* Fetch commits from the last 24 hours for a repository.
|
||||
*/
|
||||
private async fetchRecentCommitsForRepo(owner: string, repo: string): Promise<Commit[]> {
|
||||
private async fetchRecentCommitsForRepo(owner: string, repo: string): Promise<plugins.interfaces.Commit[]> {
|
||||
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
|
||||
let page = 1;
|
||||
const recentCommits: Commit[] = [];
|
||||
const recentCommits: plugins.interfaces.Commit[] = [];
|
||||
|
||||
while (true) {
|
||||
const url = new URL(`${this.baseUrl}/api/v1/repos/${owner}/${repo}/commits`);
|
||||
@ -214,7 +170,7 @@ export class CodeFeed {
|
||||
throw new Error(`Failed to fetch commits for ${owner}/${repo}: ${resp.statusText}`);
|
||||
}
|
||||
|
||||
const data: Commit[] = await resp.json();
|
||||
const data: plugins.interfaces.Commit[] = await resp.json();
|
||||
if (data.length === 0) {
|
||||
break;
|
||||
}
|
||||
@ -237,10 +193,10 @@ export class CodeFeed {
|
||||
/**
|
||||
* Fetch all commits by querying all organizations.
|
||||
*/
|
||||
public async fetchAllCommitsFromInstance(): Promise<CommitResult[]> {
|
||||
public async fetchAllCommitsFromInstance(): Promise<plugins.interfaces.CommitResult[]> {
|
||||
const orgs = await this.fetchAllOrganizations();
|
||||
console.log(`Found ${orgs.length} organizations`);
|
||||
let allCommits: CommitResult[] = [];
|
||||
let allCommits: plugins.interfaces.CommitResult[] = [];
|
||||
|
||||
for (const orgName of orgs) {
|
||||
console.log(`Checking activity for organization: ${orgName}`);
|
||||
@ -284,7 +240,7 @@ export class CodeFeed {
|
||||
const commits = await this.fetchRecentCommitsForRepo(org, repo);
|
||||
|
||||
const commitResults = commits.map((c) => {
|
||||
const commit: CommitResult = {
|
||||
const commit: plugins.interfaces.CommitResult = {
|
||||
baseUrl: this.baseUrl,
|
||||
org,
|
||||
repo,
|
||||
|
44
ts/interfaces/index.ts
Normal file
44
ts/interfaces/index.ts
Normal file
@ -0,0 +1,44 @@
|
||||
export interface RepositoryOwner {
|
||||
login: string;
|
||||
}
|
||||
|
||||
export interface Repository {
|
||||
owner: RepositoryOwner;
|
||||
name: string;
|
||||
}
|
||||
|
||||
export interface CommitAuthor {
|
||||
date: string;
|
||||
}
|
||||
|
||||
export interface CommitDetail {
|
||||
message: string;
|
||||
author: CommitAuthor;
|
||||
}
|
||||
|
||||
export interface Commit {
|
||||
sha: string;
|
||||
commit: CommitDetail;
|
||||
}
|
||||
|
||||
export interface Tag {
|
||||
commit?: {
|
||||
sha?: string;
|
||||
};
|
||||
}
|
||||
|
||||
export interface RepoSearchResponse {
|
||||
data: Repository[];
|
||||
}
|
||||
|
||||
export interface CommitResult {
|
||||
baseUrl: string;
|
||||
org: string;
|
||||
repo: string;
|
||||
timestamp: string;
|
||||
hash: string;
|
||||
commitMessage: string;
|
||||
tagged: boolean;
|
||||
publishedOnNpm: boolean;
|
||||
prettyAgoTime: string;
|
||||
}
|
@ -8,7 +8,8 @@
|
||||
"esModuleInterop": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"baseUrl": ".",
|
||||
"paths": {}
|
||||
"paths": {
|
||||
}
|
||||
},
|
||||
"exclude": [
|
||||
"dist_*/**/*.d.ts"
|
||||
|
Loading…
Reference in New Issue
Block a user