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 { const githubApiUsername = this.configService.get('githubApiUsername') const response: AxiosResponse = await this.httpService.axiosRef.get(`https://api.github.com/repos/${githubApiUsername}/${repoName}/contents/README.md`, { auth: { username: this.configService.get('githubApiUsername'), password: this.configService.get('githubApiPassword') } }) const content: Content = response.data return content; } async getRepos(): Promise { const response: AxiosResponse = await this.httpService.axiosRef.get('https://api.github.com/user/repos', { auth: { username: this.configService.get('githubApiUsername'), password: this.configService.get('githubApiPassword') } }) const repos: Repo[] = response.data return repos; } }