bootstrap tests to fetch repo list
parent
2003fc828a
commit
f47d7b007f
File diff suppressed because it is too large
Load Diff
|
@ -30,6 +30,7 @@
|
|||
},
|
||||
"devDependencies": {
|
||||
"@biomejs/biome": "1.9.2",
|
||||
"@kie/mock-github": "^3.0.0-beta.1",
|
||||
"esbuild": "0.24.0",
|
||||
"jest": "^29.7.0"
|
||||
},
|
||||
|
|
|
@ -1,3 +1,24 @@
|
|||
async function getRepositories(ocotokit, mirrorOptions) {}
|
||||
async function getRepositories(octokit, mirrorOptions) {
|
||||
const repos = await octokit
|
||||
.paginate("GET /users/:username/repos", { username: "jaedle" })
|
||||
.then(toRepositoryList);
|
||||
|
||||
if (mirrorOptions.skipForks) {
|
||||
return repos.filter((repo) => !repo.fork);
|
||||
}
|
||||
|
||||
return repos;
|
||||
}
|
||||
|
||||
function toRepositoryList(repositories) {
|
||||
return repositories.map((repository) => {
|
||||
return {
|
||||
name: repository.name,
|
||||
url: repository.clone_url,
|
||||
private: repository.private,
|
||||
fork: repository.fork,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
export default getRepositories;
|
||||
|
|
|
@ -1,14 +1,82 @@
|
|||
import { Moctokit } from "@kie/mock-github";
|
||||
import { Octokit } from "@octokit/rest";
|
||||
import { default as get } from "./get-github-repositories";
|
||||
|
||||
describe("get-github-repositories", () => {
|
||||
xit("fetches public repositories", async () => {
|
||||
const octokit = new Octokit({
|
||||
auth: null,
|
||||
it("fetches public repositories", async () => {
|
||||
const moctokit = new Moctokit();
|
||||
moctokit.rest.repos.listForUser({ username: "jaedle" }).reply({
|
||||
status: 200,
|
||||
data: [
|
||||
{
|
||||
name: "repo1",
|
||||
clone_url: "clone-url-of-repo1",
|
||||
private: false,
|
||||
fork: false,
|
||||
},
|
||||
{
|
||||
name: "repo2",
|
||||
clone_url: "clone-url-of-repo2",
|
||||
private: false,
|
||||
fork: true,
|
||||
},
|
||||
{
|
||||
name: "repo3",
|
||||
clone_url: "clone-url-of-repo3",
|
||||
private: false,
|
||||
fork: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const result = await get(octokit, undefined);
|
||||
const result = await get(new Octokit(), {
|
||||
username: "jaedle",
|
||||
privateRepositories: false,
|
||||
skipForks: false,
|
||||
});
|
||||
|
||||
expect(result).toEqual([]);
|
||||
expect(result).toEqual([
|
||||
{ name: "repo1", url: "clone-url-of-repo1", private: false, fork: false },
|
||||
{ name: "repo2", url: "clone-url-of-repo2", private: false, fork: true },
|
||||
{ name: "repo3", url: "clone-url-of-repo3", private: false, fork: false },
|
||||
]);
|
||||
});
|
||||
|
||||
it("skips forks if requested", async () => {
|
||||
const moctokit = new Moctokit();
|
||||
moctokit.rest.repos.listForUser({ username: "jaedle" }).reply({
|
||||
status: 200,
|
||||
data: [
|
||||
{
|
||||
name: "repo1",
|
||||
clone_url: "clone-url-of-repo1",
|
||||
private: false,
|
||||
fork: false,
|
||||
},
|
||||
{
|
||||
name: "repo2",
|
||||
clone_url: "clone-url-of-repo2",
|
||||
private: false,
|
||||
fork: true,
|
||||
},
|
||||
{
|
||||
name: "repo3",
|
||||
clone_url: "clone-url-of-repo3",
|
||||
private: false,
|
||||
fork: false,
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const result = await get(new Octokit(), {
|
||||
username: "jaedle",
|
||||
privateRepositories: false,
|
||||
skipForks: true,
|
||||
});
|
||||
|
||||
expect(result).toEqual([
|
||||
{ name: "repo1", url: "clone-url-of-repo1", private: false, fork: false },
|
||||
{ name: "repo3", url: "clone-url-of-repo3", private: false, fork: false },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue