|
|
|
@ -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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|