4 Commits

Author SHA1 Message Date
6032867a13 1.6.5
Some checks failed
Default (tags) / security (push) Successful in 57s
Default (tags) / test (push) Successful in 2m34s
Default (tags) / release (push) Failing after 1m34s
Default (tags) / metadata (push) Successful in 1m57s
2024-12-16 22:47:00 +01:00
b59bd82685 fix(CodeFeed): Fixed timestamp initialization and commit fetching timeframe 2024-12-16 22:46:59 +01:00
a43114ab61 1.6.4
Some checks failed
Default (tags) / security (push) Successful in 55s
Default (tags) / test (push) Successful in 2m16s
Default (tags) / release (push) Failing after 1m33s
Default (tags) / metadata (push) Successful in 1m58s
2024-12-14 22:53:42 +01:00
1e0ccec03e fix(core): Refactor fetch logic to use a unified fetchFunction for API calls 2024-12-14 22:53:42 +01:00
4 changed files with 36 additions and 26 deletions

View File

@ -1,5 +1,16 @@
# Changelog
## 2024-12-16 - 1.6.5 - fix(CodeFeed)
Fixed timestamp initialization and commit fetching timeframe
- Updated the lastRunTimestamp initialization default period from 24 hours to 7 days in CodeFeed constructor.
- Modified commit fetching logic to consider commits from the last 7 days instead of 24 hours in fetchRecentCommitsForRepo.
## 2024-12-14 - 1.6.4 - fix(core)
Refactor fetch logic to use a unified fetchFunction for API calls
- Consolidated API request logic in the CodeFeed class to use fetchFunction for improved maintainability.
## 2024-12-14 - 1.6.3 - fix(codefeed)
Refactor and fix formatting issues in the CodeFeed module

View File

@ -1,6 +1,6 @@
{
"name": "@foss.global/codefeed",
"version": "1.6.3",
"version": "1.6.5",
"private": false,
"description": "The @foss.global/codefeed module is designed for generating feeds from Gitea repositories, enhancing development workflows by processing commit data and repository activities.",
"exports": {

View File

@ -3,6 +3,6 @@
*/
export const commitinfo = {
name: '@foss.global/codefeed',
version: '1.6.3',
version: '1.6.5',
description: 'The @foss.global/codefeed module is designed for generating feeds from Gitea repositories, enhancing development workflows by processing commit data and repository activities.'
}

View File

@ -12,7 +12,7 @@ export class CodeFeed {
this.baseUrl = baseUrl;
this.token = token;
this.lastRunTimestamp =
lastRunTimestamp || new Date(Date.now() - 24 * 60 * 60 * 1000).toISOString();
lastRunTimestamp || new Date(Date.now() - 7 * 24 * 60 * 60 * 1000).toISOString();
console.log('CodeFeed initialized with last run timestamp:', this.lastRunTimestamp);
}
@ -20,13 +20,13 @@ export class CodeFeed {
* Load the changelog directly from the Gitea repository.
*/
private async loadChangelogFromRepo(owner: string, repo: string): Promise<void> {
const url = `${this.baseUrl}/api/v1/repos/${owner}/${repo}/contents/changelog.md`;
const url = `/api/v1/repos/${owner}/${repo}/contents/changelog.md`;
const headers: Record<string, string> = {};
if (this.token) {
headers['Authorization'] = `token ${this.token}`;
}
const response = await fetch(url, { headers });
const response = await this.fetchFunction(url, { headers });
if (!response.ok) {
console.error(
@ -80,8 +80,8 @@ export class CodeFeed {
}
private async fetchAllOrganizations(): Promise<string[]> {
const url = `${this.baseUrl}/api/v1/orgs`;
const response = await fetch(url, {
const url = `/api/v1/orgs`;
const response = await this.fetchFunction(url, {
headers: this.token ? { Authorization: `token ${this.token}` } : {},
});
@ -99,14 +99,14 @@ export class CodeFeed {
}): Promise<any[]> {
let rssUrl: string;
if (optionsArg.orgName && !optionsArg.repoName) {
rssUrl = `${this.baseUrl}/${optionsArg.orgName}.atom`;
rssUrl = `/${optionsArg.orgName}.atom`;
} else if (optionsArg.orgName && optionsArg.repoName) {
rssUrl = `${this.baseUrl}/${optionsArg.orgName}/${optionsArg.repoName}.atom`;
rssUrl = `/${optionsArg.orgName}/${optionsArg.repoName}.atom`;
} else {
throw new Error('Invalid arguments provided to fetchOrgRssFeed.');
}
const response = await fetch(rssUrl);
const response = await this.fetchFunction(rssUrl, {});
if (!response.ok) {
throw new Error(
`Failed to fetch RSS feed for organization ${optionsArg.orgName}/${optionsArg.repoName}: ${response.statusText}`
@ -135,11 +135,9 @@ export class CodeFeed {
const allRepos: plugins.interfaces.IRepository[] = [];
while (true) {
const url = new URL(`${this.baseUrl}/api/v1/repos/search`);
url.searchParams.set('limit', '50');
url.searchParams.set('page', page.toString());
const url = `/api/v1/repos/search?limit=50&page=${page.toString()}`;
const resp = await fetch(url.href, {
const resp = await this.fetchFunction(url, {
headers: this.token ? { Authorization: `token ${this.token}` } : {},
});
@ -164,17 +162,15 @@ export class CodeFeed {
const tags: plugins.interfaces.ITag[] = [];
while (true) {
const url = new URL(`${this.baseUrl}/api/v1/repos/${owner}/${repo}/tags`);
url.searchParams.set('limit', '50');
url.searchParams.set('page', page.toString());
const url = `/api/v1/repos/${owner}/${repo}/tags?limit=50&page=${page.toString()}`;
const resp = await fetch(url.href, {
const resp = await this.fetchFunction(url, {
headers: this.token ? { Authorization: `token ${this.token}` } : {},
});
if (!resp.ok) {
console.error(
`Failed to fetch tags for ${owner}/${repo}: ${resp.status} ${resp.statusText} at ${url.href}`
`Failed to fetch tags for ${owner}/${repo}: ${resp.status} ${resp.statusText} at ${url}`
);
throw new Error(`Failed to fetch tags for ${owner}/${repo}: ${resp.statusText}`);
}
@ -202,22 +198,20 @@ export class CodeFeed {
owner: string,
repo: string
): Promise<plugins.interfaces.ICommit[]> {
const twentyFourHoursAgo = new Date(Date.now() - 24 * 60 * 60 * 1000);
const commitTimeframe = new Date(Date.now() - (7 * 24 * 60 * 60 * 1000));
let page = 1;
const recentCommits: plugins.interfaces.ICommit[] = [];
while (true) {
const url = new URL(`${this.baseUrl}/api/v1/repos/${owner}/${repo}/commits`);
url.searchParams.set('limit', '50');
url.searchParams.set('page', page.toString());
const url = `/api/v1/repos/${owner}/${repo}/commits?limit=50&page=${page.toString()}`;
const resp = await fetch(url.href, {
const resp = await this.fetchFunction(url, {
headers: this.token ? { Authorization: `token ${this.token}` } : {},
});
if (!resp.ok) {
console.error(
`Failed to fetch commits for ${owner}/${repo}: ${resp.status} ${resp.statusText} at ${url.href}`
`Failed to fetch commits for ${owner}/${repo}: ${resp.status} ${resp.statusText} at ${url}`
);
throw new Error(`Failed to fetch commits for ${owner}/${repo}: ${resp.statusText}`);
}
@ -229,7 +223,7 @@ export class CodeFeed {
for (const commit of data) {
const commitDate = new Date(commit.commit.author.date);
if (commitDate > twentyFourHoursAgo) {
if (commitDate > commitTimeframe) {
recentCommits.push(commit);
} else {
return recentCommits;
@ -369,4 +363,9 @@ export class CodeFeed {
return allCommits;
}
public async fetchFunction(urlArg: string, optionsArg: RequestInit): Promise<Response> {
const response = await fetch(`${this.baseUrl}${urlArg}`, optionsArg);
return response;
}
}