Skip to content

Commit 41f2576

Browse files
authored
Merge pull request #579 from dzcode-io/578-remove-old-interfacestypesentities
Remove old interfaces, types and entities
2 parents 6f8f6c3 + d224f3f commit 41f2576

File tree

35 files changed

+314
-455
lines changed

35 files changed

+314
-455
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ yarn-error.log
99
.env
1010

1111
.husky
12+
.ts-prunerc
1213

1314
dist
1415
coverage

api/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,12 @@
7474
"generate:bundle-info": "ts-node ../packages/tooling/bundle-info.ts",
7575
"generate:sentry-release": "ts-node ../packages/tooling/sentry-release.ts api dist",
7676
"lint": "yarn build && yarn lint:alone",
77-
"lint:alone": "yarn lint:eslint . && yarn lint:prettier --check . && yarn lint:tsc",
77+
"lint:alone": "yarn lint:eslint . && yarn lint:prettier --check . && yarn lint:tsc && yarn lint:ts-prune",
7878
"lint:eslint": "eslint --config ../packages/tooling/.eslintrc.json --ignore-path ../packages/tooling/.eslintignore --report-unused-disable-directives",
7979
"lint:fix": "yarn build && yarn lint:fix:alone",
8080
"lint:fix:alone": "yarn lint:eslint --fix . && yarn lint:prettier --write .",
8181
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --loglevel warn",
82+
"lint:ts-prune": "ts-node ../packages/tooling/setup-ts-prune.ts && ts-prune --error",
8283
"lint:tsc": "tsc --noEmit",
8384
"start": "node dist/app/index.js",
8485
"start:dev": "ts-node ../packages/tooling/nodemon.ts @dzcode.io/api && nodemon dist/app/index.js",

api/src/_test/mocks.ts

Lines changed: 34 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,37 @@
1-
import { GithubUser } from "src/app/types/legacy";
1+
/* eslint-disable camelcase */
2+
import { GithubUser } from "src/github/types";
23

34
export const githubUserMock: GithubUser = {
4-
avatar_url: "avatar_url", // eslint-disable-line camelcase
5-
html_url: "html_url", // eslint-disable-line camelcase
6-
id: 1,
7-
login: "login",
8-
type: "type",
9-
};
10-
11-
export const githubUserMock2: GithubUser = {
12-
avatar_url: "avatar_url2", // eslint-disable-line camelcase
13-
html_url: "html_url2", // eslint-disable-line camelcase
14-
id: 2,
15-
login: "login2",
16-
type: "type2",
17-
};
18-
19-
export const githubUserMock3: GithubUser = {
20-
avatar_url: "avatar_url3", // eslint-disable-line camelcase
21-
html_url: "html_url3", // eslint-disable-line camelcase
22-
id: 3,
23-
login: "login3",
24-
type: "type3",
5+
login: "ZibanPirate",
6+
id: 20110076,
7+
node_id: "MDQ6VXNlcjIwMTEwMDc2",
8+
avatar_url: "https://avatars.githubusercontent.com/u/20110076?v=4",
9+
gravatar_id: "",
10+
url: "https://api.github.com/users/ZibanPirate",
11+
html_url: "https://github.com/ZibanPirate",
12+
followers_url: "https://api.github.com/users/ZibanPirate/followers",
13+
following_url: "https://api.github.com/users/ZibanPirate/following{/other_user}",
14+
gists_url: "https://api.github.com/users/ZibanPirate/gists{/gist_id}",
15+
starred_url: "https://api.github.com/users/ZibanPirate/starred{/owner}{/repo}",
16+
subscriptions_url: "https://api.github.com/users/ZibanPirate/subscriptions",
17+
organizations_url: "https://api.github.com/users/ZibanPirate/orgs",
18+
repos_url: "https://api.github.com/users/ZibanPirate/repos",
19+
events_url: "https://api.github.com/users/ZibanPirate/events{/privacy}",
20+
received_events_url: "https://api.github.com/users/ZibanPirate/received_events",
21+
type: "User",
22+
site_admin: false,
23+
name: "Zakaria Mansouri",
24+
company: "@dzcode-io @avimedical",
25+
blog: "zak.dzcode.io",
26+
location: "Algeria",
27+
email: "",
28+
hireable: true,
29+
bio: "One-man-army lone programmer",
30+
twitter_username: "ZibanPirate",
31+
public_repos: 18,
32+
public_gists: 2,
33+
followers: 130,
34+
following: 92,
35+
created_at: "2016-06-23T12:41:14Z",
36+
updated_at: "2023-04-10T21:31:26Z",
2537
};

api/src/app/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { GetMilestonesResponseDto } from "src/milestone/types";
55
import { GetProjectsResponseDto } from "src/project/types";
66
import { GetTeamResponseDto } from "src/team/types";
77

8+
// ts-prune-ignore-next
89
export interface Endpoints {
910
"api:Articles": {
1011
response: GetArticlesResponseDto;

api/src/app/types/legacy.ts

Lines changed: 0 additions & 81 deletions
This file was deleted.

api/src/article/controller.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Controller, Get, Param } from "routing-controllers";
22
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
3-
import { GithubUser } from "src/app/types/legacy";
43
import { DataService } from "src/data/service";
54
import { GithubService } from "src/github/service";
5+
import { GithubUser } from "src/github/types";
66
import { Service } from "typedi";
77

88
import { GetArticleResponseDto, GetArticlesResponseDto } from "./types";
@@ -42,24 +42,19 @@ export class ArticleController {
4242
const authors = await Promise.all(
4343
article.authors.map(async (author) => {
4444
const githubUser = await this.githubService.getUser({ username: author });
45-
return {
46-
id: `github/${githubUser.id}`,
47-
name: githubUser.login,
48-
link: githubUser.html_url,
49-
image: githubUser.avatar_url,
50-
};
45+
return this.githubService.githubUserToAccountEntity(githubUser);
5146
}),
5247
);
5348

54-
const contributorsBatches = await Promise.all([
49+
const committersBatches = await Promise.all([
5550
// current place for data:
56-
this.githubService.listContributors({
51+
this.githubService.listPathCommitters({
5752
owner: "dzcode-io",
5853
repository: "dzcode.io",
5954
path: `data/models/articles/${slug}`,
6055
}),
6156
// also check old place for data, to not lose contribution effort:
62-
this.githubService.listContributors({
57+
this.githubService.listPathCommitters({
6358
owner: "dzcode-io",
6459
repository: "dzcode.io",
6560
path: `data/articles/${slug}`,
@@ -69,8 +64,8 @@ export class ArticleController {
6964
// filter and sort contributors:
7065
const uniqUsernames: Record<string, number> = {};
7166
const contributors: GetArticleResponseDto["article"]["contributors"] = [
72-
...contributorsBatches[0],
73-
...contributorsBatches[1],
67+
...committersBatches[0],
68+
...committersBatches[1],
7469
]
7570
.reduce<GithubUser[]>((pV, cV) => {
7671
if (uniqUsernames[cV.login]) {
@@ -82,12 +77,7 @@ export class ArticleController {
8277
}
8378
}, [])
8479
.sort((a, b) => uniqUsernames[b.login] - uniqUsernames[a.login])
85-
.map((contributor) => ({
86-
id: `github/${contributor.id}`,
87-
name: contributor.login,
88-
link: contributor.html_url,
89-
image: contributor.avatar_url,
90-
}))
80+
.map((committer) => this.githubService.githubUserToAccountEntity(committer))
9181
.filter(({ id }) => !authors.find((author) => author.id === id));
9282

9383
return {

api/src/contribution/mock.ts

Lines changed: 0 additions & 71 deletions
This file was deleted.

api/src/documentation/controller.ts

Lines changed: 8 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { Controller, Get, Param } from "routing-controllers";
22
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
3-
import { GithubUser } from "src/app/types/legacy";
43
import { DataService } from "src/data/service";
54
import { GithubService } from "src/github/service";
5+
import { GithubUser } from "src/github/types";
66
import { Service } from "typedi";
77

88
import { GetADocumentationResponseDto, GetDocumentationResponseDto } from "./types";
@@ -44,24 +44,19 @@ export class DocumentationController {
4444
const authors = await Promise.all(
4545
documentation.authors.map(async (author) => {
4646
const githubUser = await this.githubService.getUser({ username: author });
47-
return {
48-
id: `github/${githubUser.id}`,
49-
name: githubUser.login,
50-
link: githubUser.html_url,
51-
image: githubUser.avatar_url,
52-
};
47+
return this.githubService.githubUserToAccountEntity(githubUser);
5348
}),
5449
);
5550

56-
const contributorsBatches = await Promise.all([
51+
const committersBatches = await Promise.all([
5752
// current place for data:
58-
this.githubService.listContributors({
53+
this.githubService.listPathCommitters({
5954
owner: "dzcode-io",
6055
repository: "dzcode.io",
6156
path: `data/models/documentation/${slug}`,
6257
}),
6358
// also check old place for data, to not lose contribution effort:
64-
this.githubService.listContributors({
59+
this.githubService.listPathCommitters({
6560
owner: "dzcode-io",
6661
repository: "dzcode.io",
6762
path: `data/documentation/${slug}`,
@@ -71,8 +66,8 @@ export class DocumentationController {
7166
// filter and sort contributors:
7267
const uniqUsernames: Record<string, number> = {};
7368
const contributors: GetADocumentationResponseDto["documentation"]["contributors"] = [
74-
...contributorsBatches[0],
75-
...contributorsBatches[1],
69+
...committersBatches[0],
70+
...committersBatches[1],
7671
]
7772
.reduce<GithubUser[]>((pV, cV) => {
7873
if (uniqUsernames[cV.login]) {
@@ -84,12 +79,7 @@ export class DocumentationController {
8479
}
8580
}, [])
8681
.sort((a, b) => uniqUsernames[b.login] - uniqUsernames[a.login])
87-
.map((contributor) => ({
88-
id: `github/${contributor.id}`,
89-
name: contributor.login,
90-
link: contributor.html_url,
91-
image: contributor.avatar_url,
92-
}))
82+
.map((contributor) => this.githubService.githubUserToAccountEntity(contributor))
9383
.filter(({ id }) => !authors.find((author) => author.id === id));
9484

9585
return {

0 commit comments

Comments
 (0)