Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support github repo language #107

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
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
30 changes: 17 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,15 @@ GitHub repository information.
"id": 313641207,
"name": "h3",
"repo": "unjs/h3",
"description": "Minimal h(ttp) framework built for high performance and portability ⚡️",
"description": "⚡️ Minimal H(TTP) framework built for high performance and portability ",
"createdAt": "2020-11-17T14:15:44Z",
"updatedAt": "2022-11-05T21:38:43Z",
"pushedAt": "2022-11-06T06:48:23Z",
"stars": 1168,
"watchers": 1168,
"forks": 59,
"defaultBranch": "main"
"updatedAt": "2024-11-09T15:43:41Z",
"pushedAt": "2024-11-07T10:48:51Z",
"stars": 3665,
"watchers": 16,
"forks": 218,
"defaultBranch": "main",
"language": "TypeScript"
}
}
```
Expand Down Expand Up @@ -235,11 +236,13 @@ GitHub organization repositories overview.
"repo": "unjs/redirect-ssl",
"description": "Connect/Express middleware to enforce https using is-https",
"createdAt": "2017-07-19T19:04:11Z",
"updatedAt": "2022-09-22T09:47:25Z",
"pushedAt": "2022-04-08T20:29:48Z",
"stars": 93,
"watchers": 93,
"forks": 14
"updatedAt": "2024-10-18T12:48:35Z",
"pushedAt": "2024-04-29T10:13:46Z",
"stars": 100,
"watchers": 100,
"forks": 15,
"defaultBranch": "main",
"language": "TypeScript"
}
]
}
Expand Down Expand Up @@ -300,7 +303,8 @@ Get user repositories.
"updatedAt": "2024-01-04T17:20:53Z",
"watchers": 51,
"forks": 0,
"defaultBranch": "main"
"defaultBranch": "main",
"language": "TypeScript"
}
]
}
Expand Down
49 changes: 25 additions & 24 deletions routes/orgs/[owner]/repos.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,30 @@
import type { GithubRepo } from "~types";
import type {GithubRepo} from "~types";

export default eventHandler(async (event) => {
// TODO: Do pagination
const rawRepos = await ghFetch(
`orgs/${event.context.params.owner}/repos?per_page=100`,
);
// TODO: Do pagination
const rawRepos = await ghFetch(
`orgs/${event.context.params.owner}/repos?per_page=100`,
);

const repos = rawRepos.map(
(rawRepo) =>
<GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.watchers,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
},
);
const repos = rawRepos.map(
(rawRepo) =>
<GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.watchers,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
language: rawRepo.language
},
);

return {
repos,
};
return {
repos,
};
});
41 changes: 21 additions & 20 deletions routes/repos/[owner]/[repo]/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,25 @@
import type { GithubRepo } from "~types";
import type {GithubRepo} from "~types";

export default eventHandler(async (event) => {
const rawRepo = await ghRepo(
`${event.context.params.owner}/${event.context.params.repo}`,
);
const repo = <GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.subscribers_count,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
};
const rawRepo = await ghRepo(
`${event.context.params.owner}/${event.context.params.repo}`,
);
const repo = <GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.subscribers_count,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
language: rawRepo.language
};

return {
repo,
};
return {
repo,
};
});
47 changes: 24 additions & 23 deletions routes/users/[name]/repos.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
import type { GithubRepo } from "~types";
import type {GithubRepo} from "~types";

export default eventHandler(async (event) => {
const name = getRouterParam(event, "name");
// TODO: Do pagination
const rawRepos = await ghFetch(`users/${name}/repos?per_page=100`);
const name = getRouterParam(event, "name");
// TODO: Do pagination
const rawRepos = await ghFetch(`users/${name}/repos?per_page=100`);

const repos = rawRepos.map(
(rawRepo) =>
<GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.watchers,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
},
);
const repos = rawRepos.map(
(rawRepo) =>
<GithubRepo>{
id: rawRepo.id,
name: rawRepo.name,
repo: rawRepo.full_name,
description: rawRepo.description,
createdAt: rawRepo.created_at,
updatedAt: rawRepo.updated_at,
pushedAt: rawRepo.pushed_at,
stars: rawRepo.stargazers_count,
watchers: rawRepo.watchers,
forks: rawRepo.forks,
defaultBranch: rawRepo.default_branch,
language: rawRepo.language
},
);

return {
repos,
};
return {
repos,
};
});
1 change: 1 addition & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export interface GithubRepo {
watchers: number;
forks: number;
defaultBranch: string;
language: string;
}

export interface GithubOrg {
Expand Down