adding api
This commit is contained in:
39
api/src/github/github.service.ts
Normal file
39
api/src/github/github.service.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user