bootstrap tests to fetch repo list

main
Dennis Wielepsky 2024-09-25 11:24:23 +02:00
parent 2003fc828a
commit f47d7b007f
4 changed files with 9591 additions and 7797 deletions

17286
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@ -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"
},

View File

@ -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;

View File

@ -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 },
]);
});
});