mirror of
https://github.com/jaedle/mirror-to-gitea.git
synced 2026-01-09 21:07:55 -05:00
bootstrap tests to fetch repo list
This commit is contained in:
17286
package-lock.json
generated
17286
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -30,6 +30,7 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@biomejs/biome": "1.9.2",
|
"@biomejs/biome": "1.9.2",
|
||||||
|
"@kie/mock-github": "^3.0.0-beta.1",
|
||||||
"esbuild": "0.24.0",
|
"esbuild": "0.24.0",
|
||||||
"jest": "^29.7.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;
|
export default getRepositories;
|
||||||
|
|||||||
@@ -1,14 +1,82 @@
|
|||||||
|
import { Moctokit } from "@kie/mock-github";
|
||||||
import { Octokit } from "@octokit/rest";
|
import { Octokit } from "@octokit/rest";
|
||||||
import { default as get } from "./get-github-repositories";
|
import { default as get } from "./get-github-repositories";
|
||||||
|
|
||||||
describe("get-github-repositories", () => {
|
describe("get-github-repositories", () => {
|
||||||
xit("fetches public repositories", async () => {
|
it("fetches public repositories", async () => {
|
||||||
const octokit = new Octokit({
|
const moctokit = new Moctokit();
|
||||||
auth: null,
|
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 },
|
||||||
|
]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user