Files
noahspan-root/api/src/github/github.service.ts
2025-02-10 18:55:08 -06:00

40 lines
1.3 KiB
TypeScript

import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { HttpService } from '@nestjs/axios';
import { AxiosResponse } from 'axios';
import { Repo } from './github-repo.interface';
import { Content } from './github-content.interface';
@Injectable()
export class GitHubApiService {
constructor(
private readonly configService: ConfigService,
private readonly httpService: HttpService
) {}
async getReadMeContent(repoName: string): Promise<Content> {
const githubApiUsername = this.configService.get<string>('githubApiUsername')
const response: AxiosResponse = await this.httpService.axiosRef.get(`https://api.github.com/repos/${githubApiUsername}/${repoName}/contents/README.md`, {
auth: {
username: this.configService.get<string>('githubApiUsername'),
password: this.configService.get<string>('githubApiPassword')
}
})
const content: Content = response.data
return content;
}
async getRepos(): Promise<Repo[]> {
const response: AxiosResponse = await this.httpService.axiosRef.get('https://api.github.com/user/repos', {
auth: {
username: this.configService.get<string>('githubApiUsername'),
password: this.configService.get<string>('githubApiPassword')
}
})
const repos: Repo[] = response.data
return repos;
}
}