Skip to content

Commit

Permalink
Merge pull request #316 from dzcode-io/refactor/changed_printWidth_fr…
Browse files Browse the repository at this point in the history
…om_80_to_100

changed printWidth from 80 to 100
  • Loading branch information
khalilmansouri authored Jul 3, 2021
2 parents 31701c8 + 66031d2 commit 896f182
Show file tree
Hide file tree
Showing 61 changed files with 199 additions and 619 deletions.
2 changes: 1 addition & 1 deletion api/.prettierrc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"singleQuote": false,
"printWidth": 80,
"printWidth": 100,
"trailingComma": "all",
"endOfLine": "auto"
}
23 changes: 5 additions & 18 deletions api/oracle-cloud/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@ console.log("⚙️ Preparing files ...");
// root
fse.copySync("../package.json", "./oracle-cloud/build/package.json");
// common
fse.copySync(
"../common/package.json",
"./oracle-cloud/build/common/package.json",
);
fse.copySync("../common/package.json", "./oracle-cloud/build/common/package.json");
fse.copySync("../common/dist", "./oracle-cloud/build/common/dist");
// data
fse.copySync("../data/package.json", "./oracle-cloud/build/data/package.json");
Expand All @@ -20,10 +17,7 @@ fse.copySync("../data/models", "./oracle-cloud/build/data/models");
// api
fse.copySync("./package.json", "./oracle-cloud/build/api/package.json");
fse.copySync("./dist", "./oracle-cloud/build/api/dist");
fse.copySync(
"./oracle-cloud/docker-compose.yml",
"./oracle-cloud/build/docker-compose.yml",
);
fse.copySync("./oracle-cloud/docker-compose.yml", "./oracle-cloud/build/docker-compose.yml");
fse.copySync("./oracle-cloud/Dockerfile", "./oracle-cloud/build/Dockerfile");
console.log("✅ files copied\n");

Expand All @@ -32,9 +26,7 @@ const isProduction = process.argv.includes("production");
console.log("⚙️ Deploying to", isProduction ? "Production" : "Staging", "...");

let logs;
const sshServer = isProduction
? process.env.SSH_ADDRESS_PRD
: process.env.SSH_ADDRESS_STG;
const sshServer = isProduction ? process.env.SSH_ADDRESS_PRD : process.env.SSH_ADDRESS_STG;
const appPath = "~/app";
const sshPrefix = "ssh -o StrictHostKeyChecking=no " + sshServer + " ";

Expand All @@ -61,17 +53,12 @@ logs = cp.execSync(sshPrefix + '"rm -f -r ' + appPath + '"');
logs = cp.execSync(sshPrefix + '"mkdir ' + appPath + '"');

console.log("⤴️ Uploading new code ...");
logs = cp.execSync(
"rsync -r oracle-cloud/build/* " + sshServer + ":" + appPath,
);
logs = cp.execSync("rsync -r oracle-cloud/build/* " + sshServer + ":" + appPath);
console.log("✅ New code uploaded.");

console.log("\n⚙️ Starting up the app");
logs = cp.execSync(
sshPrefix +
'"docker-compose -f ' +
appPath +
'/docker-compose.yml up -d --build"',
sshPrefix + '"docker-compose -f ' + appPath + '/docker-compose.yml up -d --build"',
);
console.log(String(logs));
console.log("✅ Deployment successful.");
10 changes: 2 additions & 8 deletions api/src/app/controllers/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,7 @@ export const listRepositories = async (req: Request, res: Response) => {
}
};

export const listPullRequestsByRepository = async (
req: Request,
res: Response,
) => {
export const listPullRequestsByRepository = async (req: Request, res: Response) => {
try {
const pullRequests = await Github.listPullRequests({
owner: "dzcode-io",
Expand Down Expand Up @@ -47,10 +44,7 @@ export const listStarsByRepository = async (req: Request, res: Response) => {
}
};

export const listStargazersByRepository = async (
req: Request,
res: Response,
) => {
export const listStargazersByRepository = async (req: Request, res: Response) => {
try {
const Stargazers = await Github.listStargazers({
owner: "dzcode-io",
Expand Down
6 changes: 1 addition & 5 deletions api/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,7 @@ useContainer(Container);

// Create the app:
export const routingControllersOptions = {
controllers: [
ContributionController,
ContributorController,
GithubUserController,
],
controllers: [ContributionController, ContributorController, GithubUserController],
middlewares: [
// middlewares:
SecurityMiddleware,
Expand Down
12 changes: 2 additions & 10 deletions api/src/app/middlewares/error.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
import {
ExpressErrorMiddlewareInterface,
Middleware,
} from "routing-controllers";
import { ExpressErrorMiddlewareInterface, Middleware } from "routing-controllers";
import { ErrorRequestHandler } from "express";
import { GeneralResponseDto } from "@dzcode.io/common/dist/types/api-responses";
import { LoggerService } from "../../logger/service";
Expand All @@ -12,12 +9,7 @@ import { Service } from "typedi";
export class ErrorMiddleware implements ExpressErrorMiddlewareInterface {
constructor(private loggerService: LoggerService) {}

error: ErrorRequestHandler<never, GeneralResponseDto, unknown> = (
err,
req,
res,
next,
) => {
error: ErrorRequestHandler<never, GeneralResponseDto, unknown> = (err, req, res, next) => {
// Logs error
this.loggerService.error({
message: "Internal Server Error",
Expand Down
118 changes: 26 additions & 92 deletions api/src/app/services/github/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@
import { ListContributorsResponse } from "../../../github/types";
import axios from "axios";

export const listOrganizationRepositories = async ({
org,
}: {
org: string;
}) => {
export const listOrganizationRepositories = async ({ org }: { org: string }) => {
try {
const response = await axios.get(
`https://api.github.com/orgs/${org}/repos`,
);
const response = await axios.get(`https://api.github.com/orgs/${org}/repos`);

return response.data;
} catch (error) {
Expand All @@ -20,23 +14,14 @@ export const listOrganizationRepositories = async ({
}
};

export const listPullRequests = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listPullRequests = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
`https://api.github.com/repos/${owner}/${repo}/pulls`,
{
params: {
state: "all",
per_page: 10,
},
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/pulls`, {
params: {
state: "all",
per_page: 10,
},
);
});

return response.data;
} catch (error) {
Expand Down Expand Up @@ -78,17 +63,9 @@ export const listContributors = async ({
}
};

export const listStars = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listStars = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
` https://api.github.com/repos/${owner}/${repo}`,
);
const response = await axios.get(` https://api.github.com/repos/${owner}/${repo}`);

return response.data;
} catch (error) {
Expand All @@ -107,16 +84,13 @@ export const listStargazers = async ({
page: number;
}) => {
try {
const response = await axios.get(
`https://api.github.com/repos/${owner}/${repo}/stargazers`,
{
params: {
state: "all",
per_page: 100,
page: page,
},
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}/stargazers`, {
params: {
state: "all",
per_page: 100,
page: page,
},
);
});

return response.data;
} catch (error) {
Expand All @@ -125,86 +99,46 @@ export const listStargazers = async ({
}
};

export const listBranches = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listBranches = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
` https://api.github.com/repos/${owner}/${repo}/branches`,
);
const response = await axios.get(` https://api.github.com/repos/${owner}/${repo}/branches`);
return response.data;
} catch (error) {
console.log("listBranches ERROR =>", error.response.data);
return null;
}
};
export const listCommits = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listCommits = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
` https://api.github.com/repos/${owner}/${repo}/commits`,
);
const response = await axios.get(` https://api.github.com/repos/${owner}/${repo}/commits`);
return response.data;
} catch (error) {
console.log("listCommits ERROR =>", error.response.data);
return null;
}
};

export const listForks = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listForks = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
` https://api.github.com/repos/${owner}/${repo}`,
);
const response = await axios.get(` https://api.github.com/repos/${owner}/${repo}`);
return response.data;
} catch (error) {
console.log("listForks =>", error.response.data);
return null;
}
};
export const listIssues = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listIssues = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
`https://api.github.com/repos/${owner}/${repo}`,
);
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}`);
return response.data;
} catch (error) {
console.log("listIssues =>", error.response.data);
return null;
}
};
export const listWatchers = async ({
owner,
repo,
}: {
owner: string;
repo: string;
}) => {
export const listWatchers = async ({ owner, repo }: { owner: string; repo: string }) => {
try {
const response = await axios.get(
`https://api.github.com/repos/${owner}/${repo}`,
);
const response = await axios.get(`https://api.github.com/repos/${owner}/${repo}`);
return response.data;
} catch (error) {
console.log("listWatchers =>", error.response.data);
Expand Down
3 changes: 1 addition & 2 deletions api/src/config/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ export class ConfigService {
if (errors.length > 0)
throw new Error(
`⚠️ Errors in .env file in the following keys:${errors.reduce(
(pV, cV) =>
(pV += "\n" + cV.property + " : " + JSON.stringify(cV.constraints)),
(pV, cV) => (pV += "\n" + cV.property + " : " + JSON.stringify(cV.constraints)),
"",
)}`,
);
Expand Down
14 changes: 4 additions & 10 deletions api/src/contribution/controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,27 +10,21 @@ import { Service } from "typedi";
@Service()
@Controller("/Contributions")
export class ContributionController {
constructor(
private readonly contributionRepository: ContributionRepository,
) {}
constructor(private readonly contributionRepository: ContributionRepository) {}

@Get("/")
@OpenAPI({
summary:
"Return a list of contributions for all projects listed in dzcode.io",
summary: "Return a list of contributions for all projects listed in dzcode.io",
})
@ResponseSchema(GetContributionsResponseDto)
public async getContributions(
@QueryParams() { labels, languages, projects }: GetContributionsQueryDto,
): Promise<GetContributionsResponseDto> {
const { contributions, filters } = await this.contributionRepository.find(
(contribution) =>
(labels.length === 0 ||
labels.some((label) => contribution.labels.includes(label))) &&
(labels.length === 0 || labels.some((label) => contribution.labels.includes(label))) &&
(languages.length === 0 ||
languages.some((language) =>
contribution.languages.includes(language),
)) &&
languages.some((language) => contribution.languages.includes(language))) &&
(projects.length === 0 ||
projects.some((project) => {
return contribution.project.slug === project;
Expand Down
11 changes: 2 additions & 9 deletions api/src/contribution/mock.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import {
ContributionEntity,
FilterEntity,
OptionEntity,
} from "@dzcode.io/common/dist/types";
import { ContributionEntity, FilterEntity, OptionEntity } from "@dzcode.io/common/dist/types";
import { lorem } from "faker";

export const generateContributionMock = (index: number): ContributionEntity => {
Expand Down Expand Up @@ -33,10 +29,7 @@ export const bulkGenerateContributionMock = (from: number, to: number) => {
{ label: "Label", name: "labels", options: [] },
];

const pushUniqueOption = (
options: OptionEntity[],
filterOptions: OptionEntity[],
) => {
const pushUniqueOption = (options: OptionEntity[], filterOptions: OptionEntity[]) => {
const uniqueOptions = options.filter(
(_option) => !filterOptions.some(({ name }) => _option.name === name),
);
Expand Down
Loading

0 comments on commit 896f182

Please sign in to comment.