Skip to content

Commit

Permalink
feat: support users and users repos (#75)
Browse files Browse the repository at this point in the history
  • Loading branch information
Barbapapazes authored Jan 9, 2024
1 parent 6473e40 commit d03800b
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
45 changes: 45 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,49 @@ Multiple items can be separated by either `,` or `+` or ` ` (space). Each item c
}
```

### `/users/{username}`

Find one github user by username.

**Example:** https://ungh.cc/users/pi0

```json
{
"user": {
"id": 5158436,
"name": "Pooya Parsa",
"twitter": null,
"username": "pi0"
}
}
```

### `/users/{username}/repos`

Get user repositories.

**Example:** https://ungh.cc/users/pi0/repos

```json
{
"repos": [
{
"id": 674019467,
"name": "h3-on-edge",
"description": "⚡️ Edge workers with straming powered by unjs/h3",
"repo": "pi0/h3-on-edge",
"stars": 51,
"pushedAt": "2024-01-07T16:54:46Z",
"createdAt": "2023-08-03T00:53:31Z",
"updatedAt": "2024-01-04T17:20:53Z",
"watchers": 51,
"forks": 0,
"defaultBranch": "main"
}
]
}
```

### `/users/find/{query}`

Find one github user by email or other query.
Expand All @@ -273,6 +316,8 @@ Find one github user by email or other query.
{
"user": {
"id": 5158436,
"name": "Pooya Parsa",
"twitter": null,
"username": "pi0"
}
}
Expand Down
16 changes: 16 additions & 0 deletions routes/users/[name]/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import type { GithubUser } from "~types";

export default eventHandler(async (event) => {
const name = getRouterParam(event, "name");
const user = await ghFetch(`users/${name}`);

return {
user: <GithubUser>{
id: user.id,
username: user.login,
name: user.name,
twitter: user.twitter_username,
avatar: user.avatar_url,
},
};
});
28 changes: 28 additions & 0 deletions routes/users/[name]/repos.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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 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,
},
);

return {
repos,
};
});
3 changes: 3 additions & 0 deletions routes/users/find/[query].ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ export default eventHandler(async (event) => {
const user = <GithubUser>{
id: res.items[0].id,
username: res.items[0].login,
name: res.items[0].name,
twitter: res.items[0].twitter_username,
avatar: res.items[0].avatar_url,
};

return { user };
Expand Down
3 changes: 3 additions & 0 deletions types/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ export interface GithubOrg {
export interface GithubUser {
id: string;
username: string;
name: string;
twitter: string;
avatar: string;
}

export interface GithubContributor {
Expand Down

0 comments on commit d03800b

Please sign in to comment.