Skip to content

Commit

Permalink
Merge pull request #579 from dzcode-io/578-remove-old-interfacestypes…
Browse files Browse the repository at this point in the history
…entities

Remove old interfaces, types and entities
  • Loading branch information
ZibanPirate authored Apr 15, 2023
2 parents 6f8f6c3 + d224f3f commit 41f2576
Show file tree
Hide file tree
Showing 35 changed files with 314 additions and 455 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ yarn-error.log
.env

.husky
.ts-prunerc

dist
coverage
Expand Down
3 changes: 2 additions & 1 deletion api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,12 @@
"generate:bundle-info": "ts-node ../packages/tooling/bundle-info.ts",
"generate:sentry-release": "ts-node ../packages/tooling/sentry-release.ts api dist",
"lint": "yarn build && yarn lint:alone",
"lint:alone": "yarn lint:eslint . && yarn lint:prettier --check . && yarn lint:tsc",
"lint:alone": "yarn lint:eslint . && yarn lint:prettier --check . && yarn lint:tsc && yarn lint:ts-prune",
"lint:eslint": "eslint --config ../packages/tooling/.eslintrc.json --ignore-path ../packages/tooling/.eslintignore --report-unused-disable-directives",
"lint:fix": "yarn build && yarn lint:fix:alone",
"lint:fix:alone": "yarn lint:eslint --fix . && yarn lint:prettier --write .",
"lint:prettier": "prettier --config ../packages/tooling/.prettierrc --ignore-path ../packages/tooling/.prettierignore --loglevel warn",
"lint:ts-prune": "ts-node ../packages/tooling/setup-ts-prune.ts && ts-prune --error",
"lint:tsc": "tsc --noEmit",
"start": "node dist/app/index.js",
"start:dev": "ts-node ../packages/tooling/nodemon.ts @dzcode.io/api && nodemon dist/app/index.js",
Expand Down
56 changes: 34 additions & 22 deletions api/src/_test/mocks.ts
Original file line number Diff line number Diff line change
@@ -1,25 +1,37 @@
import { GithubUser } from "src/app/types/legacy";
/* eslint-disable camelcase */
import { GithubUser } from "src/github/types";

export const githubUserMock: GithubUser = {
avatar_url: "avatar_url", // eslint-disable-line camelcase
html_url: "html_url", // eslint-disable-line camelcase
id: 1,
login: "login",
type: "type",
};

export const githubUserMock2: GithubUser = {
avatar_url: "avatar_url2", // eslint-disable-line camelcase
html_url: "html_url2", // eslint-disable-line camelcase
id: 2,
login: "login2",
type: "type2",
};

export const githubUserMock3: GithubUser = {
avatar_url: "avatar_url3", // eslint-disable-line camelcase
html_url: "html_url3", // eslint-disable-line camelcase
id: 3,
login: "login3",
type: "type3",
login: "ZibanPirate",
id: 20110076,
node_id: "MDQ6VXNlcjIwMTEwMDc2",
avatar_url: "https://avatars.githubusercontent.com/u/20110076?v=4",
gravatar_id: "",
url: "https://api.github.com/users/ZibanPirate",
html_url: "https://github.com/ZibanPirate",
followers_url: "https://api.github.com/users/ZibanPirate/followers",
following_url: "https://api.github.com/users/ZibanPirate/following{/other_user}",
gists_url: "https://api.github.com/users/ZibanPirate/gists{/gist_id}",
starred_url: "https://api.github.com/users/ZibanPirate/starred{/owner}{/repo}",
subscriptions_url: "https://api.github.com/users/ZibanPirate/subscriptions",
organizations_url: "https://api.github.com/users/ZibanPirate/orgs",
repos_url: "https://api.github.com/users/ZibanPirate/repos",
events_url: "https://api.github.com/users/ZibanPirate/events{/privacy}",
received_events_url: "https://api.github.com/users/ZibanPirate/received_events",
type: "User",
site_admin: false,
name: "Zakaria Mansouri",
company: "@dzcode-io @avimedical",
blog: "zak.dzcode.io",
location: "Algeria",
email: "",
hireable: true,
bio: "One-man-army lone programmer",
twitter_username: "ZibanPirate",
public_repos: 18,
public_gists: 2,
followers: 130,
following: 92,
created_at: "2016-06-23T12:41:14Z",
updated_at: "2023-04-10T21:31:26Z",
};
1 change: 1 addition & 0 deletions api/src/app/endpoints.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { GetMilestonesResponseDto } from "src/milestone/types";
import { GetProjectsResponseDto } from "src/project/types";
import { GetTeamResponseDto } from "src/team/types";

// ts-prune-ignore-next
export interface Endpoints {
"api:Articles": {
response: GetArticlesResponseDto;
Expand Down
81 changes: 0 additions & 81 deletions api/src/app/types/legacy.ts

This file was deleted.

26 changes: 8 additions & 18 deletions api/src/article/controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Controller, Get, Param } from "routing-controllers";
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
import { GithubUser } from "src/app/types/legacy";
import { DataService } from "src/data/service";
import { GithubService } from "src/github/service";
import { GithubUser } from "src/github/types";
import { Service } from "typedi";

import { GetArticleResponseDto, GetArticlesResponseDto } from "./types";
Expand Down Expand Up @@ -42,24 +42,19 @@ export class ArticleController {
const authors = await Promise.all(
article.authors.map(async (author) => {
const githubUser = await this.githubService.getUser({ username: author });
return {
id: `github/${githubUser.id}`,
name: githubUser.login,
link: githubUser.html_url,
image: githubUser.avatar_url,
};
return this.githubService.githubUserToAccountEntity(githubUser);
}),
);

const contributorsBatches = await Promise.all([
const committersBatches = await Promise.all([
// current place for data:
this.githubService.listContributors({
this.githubService.listPathCommitters({
owner: "dzcode-io",
repository: "dzcode.io",
path: `data/models/articles/${slug}`,
}),
// also check old place for data, to not lose contribution effort:
this.githubService.listContributors({
this.githubService.listPathCommitters({
owner: "dzcode-io",
repository: "dzcode.io",
path: `data/articles/${slug}`,
Expand All @@ -69,8 +64,8 @@ export class ArticleController {
// filter and sort contributors:
const uniqUsernames: Record<string, number> = {};
const contributors: GetArticleResponseDto["article"]["contributors"] = [
...contributorsBatches[0],
...contributorsBatches[1],
...committersBatches[0],
...committersBatches[1],
]
.reduce<GithubUser[]>((pV, cV) => {
if (uniqUsernames[cV.login]) {
Expand All @@ -82,12 +77,7 @@ export class ArticleController {
}
}, [])
.sort((a, b) => uniqUsernames[b.login] - uniqUsernames[a.login])
.map((contributor) => ({
id: `github/${contributor.id}`,
name: contributor.login,
link: contributor.html_url,
image: contributor.avatar_url,
}))
.map((committer) => this.githubService.githubUserToAccountEntity(committer))
.filter(({ id }) => !authors.find((author) => author.id === id));

return {
Expand Down
71 changes: 0 additions & 71 deletions api/src/contribution/mock.ts

This file was deleted.

26 changes: 8 additions & 18 deletions api/src/documentation/controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { Controller, Get, Param } from "routing-controllers";
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
import { GithubUser } from "src/app/types/legacy";
import { DataService } from "src/data/service";
import { GithubService } from "src/github/service";
import { GithubUser } from "src/github/types";
import { Service } from "typedi";

import { GetADocumentationResponseDto, GetDocumentationResponseDto } from "./types";
Expand Down Expand Up @@ -44,24 +44,19 @@ export class DocumentationController {
const authors = await Promise.all(
documentation.authors.map(async (author) => {
const githubUser = await this.githubService.getUser({ username: author });
return {
id: `github/${githubUser.id}`,
name: githubUser.login,
link: githubUser.html_url,
image: githubUser.avatar_url,
};
return this.githubService.githubUserToAccountEntity(githubUser);
}),
);

const contributorsBatches = await Promise.all([
const committersBatches = await Promise.all([
// current place for data:
this.githubService.listContributors({
this.githubService.listPathCommitters({
owner: "dzcode-io",
repository: "dzcode.io",
path: `data/models/documentation/${slug}`,
}),
// also check old place for data, to not lose contribution effort:
this.githubService.listContributors({
this.githubService.listPathCommitters({
owner: "dzcode-io",
repository: "dzcode.io",
path: `data/documentation/${slug}`,
Expand All @@ -71,8 +66,8 @@ export class DocumentationController {
// filter and sort contributors:
const uniqUsernames: Record<string, number> = {};
const contributors: GetADocumentationResponseDto["documentation"]["contributors"] = [
...contributorsBatches[0],
...contributorsBatches[1],
...committersBatches[0],
...committersBatches[1],
]
.reduce<GithubUser[]>((pV, cV) => {
if (uniqUsernames[cV.login]) {
Expand All @@ -84,12 +79,7 @@ export class DocumentationController {
}
}, [])
.sort((a, b) => uniqUsernames[b.login] - uniqUsernames[a.login])
.map((contributor) => ({
id: `github/${contributor.id}`,
name: contributor.login,
link: contributor.html_url,
image: contributor.avatar_url,
}))
.map((contributor) => this.githubService.githubUserToAccountEntity(contributor))
.filter(({ id }) => !authors.find((author) => author.id === id));

return {
Expand Down
Loading

0 comments on commit 41f2576

Please sign in to comment.