Skip to content
Closed
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
3 changes: 2 additions & 1 deletion api/src/app/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import Container from "typedi";
import { ContributorController } from "../contributor/controller";
import { DocsMiddleware } from "./middlewares/docs";
import { ErrorMiddleware } from "./middlewares/error";
import { GitHubController } from "../github/controller";
import { LoggerMiddleware } from "./middlewares/logger";
import { LoggerService } from "../logger/service";
import { SecurityMiddleware } from "./middlewares/security";
Expand All @@ -18,7 +19,7 @@ useContainer(Container);

// Create the app:
export const routingControllersOptions = {
controllers: [ContributorController],
controllers: [ContributorController, GitHubController],
middlewares: [
// middlewares:
SecurityMiddleware,
Expand Down
27 changes: 27 additions & 0 deletions api/src/github/controller.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Controller, Get } from "routing-controllers";
import { OpenAPI, ResponseSchema } from "routing-controllers-openapi";
import { GetRepositoriesResponseDto } from "./types";
import { GithubService } from "../github/service";
import { Service } from "typedi";

@Service()
@Controller("/Github")
export class GitHubController {
constructor(private readonly githubService: GithubService) {}
@Get("/Repositories")
@OpenAPI({
summary: "Return a list of repositories for dzcode-id",
})
@ResponseSchema(GetRepositoriesResponseDto)
public async getRepositories(): Promise<GetRepositoriesResponseDto> {
const repositories = await this.githubService.listOrganizationRepositories({
org: "dzcode-io",
});

if (!repositories) throw Error();

return {
repositories,
};
}
}
18 changes: 16 additions & 2 deletions api/src/github/service.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
import { GeneralGithubQuery, ListContributorsResponse } from "./types";
import {
GeneralGithubQuery,
GitHubRepositoriesApiReponse,
ListContributorsResponse,
ListOrganizationRepositoriesInput,
} from "./types";

import { Service } from "typedi";
import axios from "axios";

@Service()
export class GithubService {
private apiURL = "https://api.github.com";

public listContributors = async ({
owner,
repo,
Expand All @@ -28,5 +35,12 @@ export class GithubService {
return contributors;
};

private apiURL = "https://api.github.com";
public listOrganizationRepositories = async ({
org,
}: ListOrganizationRepositoriesInput) => {
const response = await axios.get<GitHubRepositoriesApiReponse>(
`https://api.github.com/orgs/${org}/repos`,
);
return response.data;
};
}
116 changes: 116 additions & 0 deletions api/src/github/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { GeneralResponseDto } from "../app/types";
import { GithubUser } from "@dzcode.io/common/dist/types";
import { ValidateNested } from "class-validator";

export type ListContributorsResponse = Array<{
author: GithubUser;
Expand All @@ -10,3 +12,117 @@ export interface GeneralGithubQuery {
repo: string;
path: string;
}

export interface ListOrganizationRepositoriesInput {
org: string;
}

export type GitHubRepositoriesApiReponse = Array<GitHubRepositoryApiData>;

/* eslint-disable camelcase */
export interface GitHubRepositoryApiData {
id: number;
node_id: string;
name: string;
full_name: string;
private: boolean;
owner: {
login: string;
id: number;
node_id: string;
avatar_url: string;
gravatar_id: string;
url: string;
html_url: string;
followers_url: string;
following_url: string;
gists_url: string;
starred_url: string;
subscriptions_url: string;
organizations_url: string;
repos_url: string;
events_url: string;
received_events_url: string;
type: string;
site_admin: boolean;
};
html_url: string;
description: string;
fork: boolean;
url: string;
forks_url: string;
keys_url: string;
collaborators_url: string;
teams_url: string;
hooks_url: string;
issue_events_url: string;
events_url: string;
assignees_url: string;
branches_url: string;
tags_url: string;
blobs_url: string;
git_tags_url: string;
git_refs_url: string;
trees_url: string;
statuses_url: string;
languages_url: string;
stargazers_url: string;
contributors_url: string;
subscribers_url: string;
subscription_url: string;
commits_url: string;
git_commits_url: string;
comments_url: string;
issue_comment_url: string;
contents_url: string;
compare_url: string;
merges_url: string;
archive_url: string;
downloads_url: string;
issues_url: string;
pulls_url: string;
milestones_url: string;
notifications_url: string;
labels_url: string;
releases_url: string;
deployments_url: string;
created_at: string;
updated_at: string;
pushed_at: string;
git_url: string;
ssh_url: string;
clone_url: string;
svn_url: string;
homepage: string;
size: number;
stargazers_count: number;
watchers_count: number;
language: string;
has_issues: boolean;
has_projects: boolean;
has_downloads: boolean;
has_wiki: boolean;
has_pages: boolean;
forks_count: number;
mirror_url: string;
archived: boolean;
disabled: boolean;
open_issues_count: number;
license: {
key: string;
name: string;
spdx_id: string;
url: string;
node_id: string;
};
forks: number;
open_issues: number;
watchers: number;
default_branch: string;
permissions: { admin: boolean; push: boolean; pull: boolean };
}

export class GetRepositoriesResponseDto extends GeneralResponseDto {
@ValidateNested({ each: true })
repositories?: GitHubRepositoriesApiReponse;
}