Skip to content

Commit

Permalink
feat(back): fix env dependency
Browse files Browse the repository at this point in the history
github token is not required
  • Loading branch information
wrujel committed May 2, 2023
1 parent 0c555a0 commit d03e0cb
Showing 1 changed file with 23 additions and 37 deletions.
60 changes: 23 additions & 37 deletions backend/src/app.service.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
/* eslint-disable prettier/prettier */
import { HttpService } from '@nestjs/axios';
import { Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { lastValueFrom, map } from 'rxjs';

const userUrl = 'https://api.github.com/users';
const reposUrl = 'https://api.github.com/repos';

@Injectable()
export class AppService {
constructor(private http: HttpService, private env: ConfigService) {}

bearerToken = this.env.get<string>('API_TOKEN');
header = {
Authorization: `Bearer ${this.bearerToken}`,
};
constructor(private http: HttpService) {}

getUser(user: string): Promise<any> {
const userUrl = 'https://api.github.com/users';
return lastValueFrom(
this.http.get<any>(`${userUrl}/${user}`, { headers: this.header }).pipe(
this.http.get<any>(`${userUrl}/${user}`).pipe(
map((res) => res.data),
map((data) => ({
name: data.name,
Expand All @@ -27,46 +24,35 @@ export class AppService {
}

getRepos(user: string): Promise<any> {
const userUrl = 'https://api.github.com/users';
return lastValueFrom(
this.http
.get<any>(`${userUrl}/${user}/repos`, { headers: this.header })
.pipe(
map((res) => res.data),
map((repos) => ({
repos: repos.map((repo) => {
return repo['name'];
}),
})),
),
this.http.get<any>(`${userUrl}/${user}/repos`).pipe(
map((res) => res.data),
map((repos) => ({
repos: repos.map((repo) => {
return repo['name'];
}),
})),
),
);
}

getBranches(user: string, repo: string): Promise<any> {
const branchUrl = 'https://api.github.com/repos';
return lastValueFrom(
this.http
.get<any>(`${branchUrl}/${user}/${repo}/branches`, {
headers: this.header,
})
.pipe(
map((res) => res.data),
map((branches) => ({
branches: branches.map((branch) => {
return branch['name'];
}),
})),
),
this.http.get<any>(`${reposUrl}/${user}/${repo}/branches`).pipe(
map((res) => res.data),
map((branches) => ({
branches: branches.map((branch) => {
return branch['name'];
}),
})),
),
);
}

getCommits(user: string, repo: string, branch: string): Promise<any> {
const commitUrl = 'https://api.github.com/repos';
return lastValueFrom(
this.http
.get<any>(`${commitUrl}/${user}/${repo}/commits?sha=${branch}`, {
headers: this.header,
})
.get<any>(`${reposUrl}/${user}/${repo}/commits?sha=${branch}`)
.pipe(
map((res) => res.data),
map((commits) => ({
Expand Down

0 comments on commit d03e0cb

Please sign in to comment.