Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions angular-ngrx-scss/src/app/accept.interceptor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Injectable } from '@angular/core';
import {
HttpEvent,
HttpHandler,
HttpInterceptor,
HttpRequest,
} from '@angular/common/http';
import { Observable } from 'rxjs';

@Injectable()
export class AcceptInterceptor implements HttpInterceptor {
intercept(
request: HttpRequest<unknown>,
next: HttpHandler,
): Observable<HttpEvent<unknown>> {
request = request.clone({
setHeaders: {
Accept: 'application/vnd.github.v3+json',
},
});

return next.handle(request);
}
}
6 changes: 6 additions & 0 deletions angular-ngrx-scss/src/app/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { AuthEffects } from './state/auth';
import { ProfileEffects } from './state/profile/profile.effects';
import { RepositoryEffects } from './state/repository/repository.effects';
import { UserEffects } from './state/user';
import { AcceptInterceptor } from './accept.interceptor';

@NgModule({
imports: [
Expand Down Expand Up @@ -42,6 +43,11 @@ import { UserEffects } from './state/user';
useClass: TokenInterceptor,
multi: true,
},
{
provide: HTTP_INTERCEPTORS,
useClass: AcceptInterceptor,
multi: true,
},
],
bootstrap: [AppComponent],
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ describe('OrganizationService', () => {
expect(httpSpy.get).toHaveBeenCalledWith(
'https://api.github.com/orgs/FakeCo/repos',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
params: new HttpParams({
fromObject: {
type: 'all',
Expand All @@ -120,9 +117,6 @@ describe('OrganizationService', () => {
expect(httpSpy.get).toHaveBeenCalledWith(
'https://api.github.com/orgs/OtherFakeCo/repos',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
params: new HttpParams({
fromObject: {
type: 'public',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ export class OrganizationService {
)}/repos`;

return this.http.get<OrganizationReposApiResponse>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
params: new HttpParams({
fromObject: { ...Object.assign(defaultParams, params) },
}),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -290,11 +290,6 @@ describe('RepositoryService', () => {

expect(httpClientSpy.get).toHaveBeenCalledOnceWith(
`https://api.github.com/repos/thisdot/starter.dev-github-showcases`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
done();
},
Expand Down Expand Up @@ -371,11 +366,6 @@ describe('RepositoryService', () => {

expect(httpClientSpy.get).toHaveBeenCalledOnceWith(
'https://api.github.com/repos/thisdot/starter.dev-github-showcases/contents/README.md',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
});
});
Expand All @@ -391,11 +381,6 @@ describe('RepositoryService', () => {

expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/repos/FakeCo/fake-repo/pulls/${MOCK_PULL_REQUEST_NUMBER}`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand All @@ -414,9 +399,7 @@ describe('RepositoryService', () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/search/issues?q=repo:FakeCo/fake-repo+type:pr+state:all`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
observe: 'response',
}),
);
},
Expand All @@ -439,11 +422,6 @@ describe('RepositoryService', () => {

expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/repos/FakeCo/fake-repo/issues/${MOCK_PULL_REQUEST_NUMBER}/comments`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand All @@ -460,9 +438,7 @@ describe('RepositoryService', () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
'https://api.github.com/search/issues?q=repo:FakeCo/fake-repo+type:issue+state:all',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
observe: 'response',
}),
);
},
Expand All @@ -482,9 +458,7 @@ describe('RepositoryService', () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
'https://api.github.com/search/issues?q=repo:FakeCo/fake-repo+type:issue+state:closed',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
observe: 'response',
}),
);
},
Expand All @@ -510,11 +484,6 @@ describe('RepositoryService', () => {
.toBe(1);
expect(httpClientSpy.get).toHaveBeenCalledOnceWith(
'https://api.github.com/repos/thisdot/starter.dev-github-showcases/pulls/1',
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
});
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,7 @@ export class RepositoryService {
const name = encodeURIComponent(repoName);
const url = `${environment.githubUrl}/repos/${owner}/${name}`;

return this.http.get<RepoApiResponse>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<RepoApiResponse>(url);
}

getRepositoryPullRequestsCount(
Expand All @@ -61,9 +57,6 @@ export class RepositoryService {
return this.http
.get<PullRequests>(url, {
observe: 'response',
headers: {
Accept: 'application/vnd.github.v3+json',
},
params: new HttpParams({
fromObject: {
state: 'open',
Expand Down Expand Up @@ -99,9 +92,6 @@ export class RepositoryService {
return this.http
.get(url, {
observe: 'response',
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
.pipe(
map((response) => {
Expand Down Expand Up @@ -137,11 +127,7 @@ export class RepositoryService {
const name = encodeURIComponent(repoName);
const url = `${environment.githubUrl}/repos/${owner}/${name}/milestones`;

return this.http.get<Milestone[]>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<Milestone[]>(url);
}

/**
Expand All @@ -158,11 +144,7 @@ export class RepositoryService {
const name = encodeURIComponent(repoName);
const url = `${environment.githubUrl}/repos/${owner}/${name}/labels`;

return this.http.get<IssueLabel[]>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<IssueLabel[]>(url);
}

/**
Expand All @@ -182,11 +164,7 @@ export class RepositoryService {
const pullId = encodeURIComponent(pullNumber);
const url = `${environment.githubUrl}/repos/${owner}/${name}/pulls/${pullId}`;

return this.http.get<PullRequest>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<PullRequest>(url);
}

/**
Expand All @@ -206,11 +184,7 @@ export class RepositoryService {
const pullId = encodeURIComponent(pullNumber);
const url = `${environment.githubUrl}/repos/${owner}/${name}/issues/${pullId}/comments`;

return this.http.get<IssueComments>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<IssueComments>(url);
}

/**
Expand Down Expand Up @@ -244,9 +218,6 @@ export class RepositoryService {
return this.http
.get(url, {
observe: 'response',
headers: {
Accept: 'application/vnd.github.v3+json',
},
})
.pipe(
map((response) => {
Expand Down Expand Up @@ -295,11 +266,7 @@ export class RepositoryService {
url += `?ref=${refPath}`;
}

return this.http.get<RepoContentsApiResponse[]>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<RepoContentsApiResponse[]>(url);
}

/**
Expand All @@ -326,11 +293,7 @@ export class RepositoryService {
url += `?ref=${refPath}`;
}

return this.http.get<FileContentsApiResponse>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<FileContentsApiResponse>(url);
}

/**
Expand All @@ -347,11 +310,7 @@ export class RepositoryService {
const name = encodeURIComponent(repoName);
const url = `${environment.githubUrl}/repos/${owner}/${name}/readme`;

return this.http.get<ReadmeApiResponse>(url, {
headers: {
Accept: 'application/vnd.github.v3+json',
},
});
return this.http.get<ReadmeApiResponse>(url);
}

private extractTotalFromLinkHeader(linkHeader: string | null): number {
Expand Down
23 changes: 0 additions & 23 deletions angular-ngrx-scss/src/app/user/services/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ describe('UserService', () => {

expect(httpClientSpy.get).toHaveBeenCalledOnceWith(
`https://api.github.com/user`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand Down Expand Up @@ -84,11 +79,6 @@ describe('UserService', () => {
next: () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/users/thisdot/orgs`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand Down Expand Up @@ -211,11 +201,6 @@ describe('UserService', () => {
next: () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/users/thisdot/repos`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand Down Expand Up @@ -339,9 +324,6 @@ describe('UserService', () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/users/thisdot/repos`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
params: new HttpParams({
fromObject: {
sort: 'updated',
Expand Down Expand Up @@ -369,11 +351,6 @@ describe('UserService', () => {
next: () => {
expect(httpClientSpy.get).toHaveBeenCalledWith(
`https://api.github.com/users/thisdot/gists`,
jasmine.objectContaining({
headers: {
Accept: 'application/vnd.github.v3+json',
},
}),
);
},
complete: done,
Expand Down
Loading