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

[solidjs-pod] Get all repositories from GitHub API#684 #845

Merged
merged 20 commits into from
Nov 17, 2022
Merged
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
6 changes: 6 additions & 0 deletions .github/workflows/ci-solidjs-tailwind.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@ jobs:

steps:
- uses: actions/checkout@v2
uses: pnpm/[email protected]
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
uses: pnpm/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: 'pnpm'
Expand All @@ -45,11 +47,13 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v2
uses: pnpm/[email protected]
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
uses: pnpm/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
Expand All @@ -75,11 +79,13 @@ jobs:

steps:
- uses: actions/checkout@v2
uses: pnpm/[email protected]
with:
fetch-depth: 0

- name: Use Node.js
uses: actions/setup-node@v2
uses: pnpm/[email protected]
with:
node-version: ${{ matrix.node-version }}
cache: "pnpm"
Expand Down
4 changes: 4 additions & 0 deletions solidjs-tailwind/src/components/Icons/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
export { default as TwitterIcon } from './TwitterIcon';
export { default as CaretIcon } from './caret';
export { default as CloseIcon } from './close';
export { default as CorrectIcon } from './correct';
export { default as RepoBookIcon } from './repo-book';
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
Switch,
Match,
} from 'solid-js';
import { CaretIcon, CloseIcon, CorrectIcon } from '../icons';
import { CaretIcon, CloseIcon, CorrectIcon } from '../Icons';

function clickOutside(el, accessor) {
const onClick = (e) => {
Expand Down
2 changes: 1 addition & 1 deletion solidjs-tailwind/src/components/RepoFilter/FilterText.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Show, splitProps } from 'solid-js';
import { CloseIcon } from '../icons';
import { CloseIcon } from '../Icons';

const modifyFilterTypeText = (filterText = 'test') => {
if (filterText.endsWith('s')) {
Expand Down
2 changes: 1 addition & 1 deletion solidjs-tailwind/src/components/RepoFilter/RepoFilter.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { mergeProps, Show } from 'solid-js';
import { RepoBookIcon } from '../icons';
import { RepoBookIcon } from '../Icons';
import { FILTER_TYPE_OPTIONS, SORT_OPTIONS } from './data';
import FilterDropdown from './FilterDropdown';
import FilterText from './FilterText';
Expand Down
1 change: 1 addition & 0 deletions solidjs-tailwind/src/components/icons/index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export { default as TwitterIcon } from './TwitterIcon';
export { default as CaretIcon } from './caret';
export { default as CloseIcon } from './close';
export { default as CorrectIcon } from './correct';
Expand Down
25 changes: 25 additions & 0 deletions solidjs-tailwind/src/services/api.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const FetchApi = ({ url, query, variables, headersOptions }) => {
return new Promise((resolve, reject) => {
fetch(url, {
method: 'POST',
headers: {
...headersOptions,
Accept: 'application/vnd.github+json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
query,
variables,
}),
})
.then((res) => res.json())
.then((result) => {
resolve(result);
})
.catch((error) => {
reject(error);
});
});
};

export default FetchApi;
55 changes: 55 additions & 0 deletions solidjs-tailwind/src/services/queries/all-repos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
export const USER_REPOS_QUERY = `
query UserRepos(
$username: String!
$afterCursor: String
$beforeCursor: String
$orderBy: RepositoryOrder
$first: Int
$last: Int
) {
owner: user(login: $username) {
repositories(
first: $first
last: $last
after: $afterCursor
before: $beforeCursor
orderBy: $orderBy
ownerAffiliations: [OWNER]
) {
nodes {
id
name
description
stargazerCount
forkCount
isArchived
isFork
primaryLanguage {
id
color
name
}
languages(first: 10, orderBy: { direction: ASC, field: SIZE }) {
nodes {
color
name
id
}
}
isPrivate
visibility
updatedAt
owner {
login
}
}
pageInfo {
endCursor
startCursor
hasNextPage
hasPreviousPage
}
}
}
}
`;
52 changes: 52 additions & 0 deletions solidjs-tailwind/src/services/user-repos.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { useAuth } from "../auth";
import FetchApi from "./api";
import { USER_REPOS_QUERY } from "./queries/all-repos";

const getUserRepos = async ({
url
}) => {
const { authStore } = useAuth();
const data = {
url,
query: USER_REPOS_QUERY,
variable: null,
headersOptions: {
authorization: `Bearer ${authStore.token}`,
}
}
const resp = await FetchApi(data);
const nodes = resp?.owner?.repositories?.nodes;
const pageInfo = resp?.owner?.repositories?.pageInfo;

if (!nodes) {
return undefined;
}
const repos = nodes?.reduce((acc, repo) => {
return repo
? [
...acc,
{
id: repo.id,
name: repo.name,
description: repo.description,
stargazerCount: repo.stargazerCount,
forkCount: repo.forkCount,
primaryLanguage: {
name: repo.primaryLanguage?.name,
color: repo.primaryLanguage?.color,
},
visibility: repo.visibility,
updatedAt: repo.updatedAt,
owner: repo.owner,
},
]
: acc;
}, []);

return {
pageInfo,
repos
};
};

export default getUserRepos;