Skip to content

Commit

Permalink
Implement filters
Browse files Browse the repository at this point in the history
  • Loading branch information
RobertoBochet committed Nov 4, 2024
1 parent 0fc5486 commit 9a2702f
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/index.mjs
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import { Octokit } from "@octokit/rest";
import { minimatch } from "minimatch";
import PQueue from "p-queue";
import * as request from "superagent";
import request from "superagent";
import { configuration } from "./configuration.mjs";

async function getGithubRepositories(
username,
token,
mirrorPrivateRepositories,
mirrorForks,
include,
exclude,
) {
const octokit = new Octokit({
auth: token || null,
Expand Down Expand Up @@ -38,6 +41,12 @@ async function getGithubRepositories(
repositories = repositories.filter((repository) => !repository.fork);
}

repositories = repositories.filter(
(repository) =>
include.some((f) => minimatch(repository.name, f)) &&
!exclude.some((f) => minimatch(repository.name, f)),
);

return repositories;
}

Expand Down Expand Up @@ -136,12 +145,16 @@ async function main() {
console.log(` - GITEA_TOKEN: ${config.gitea.token ? "****" : ""}`);
console.log(` - SKIP_FORKS: ${config.github.skipForks}`);
console.log(` - DRY_RUN: ${config.dryRun}`);
console.log(` - INCLUDE: ${config.include}`);
console.log(` - EXCLUDE: ${config.exclude}`);

const githubRepositories = await getGithubRepositories(
config.github.username,
config.github.token,
config.github.privateRepositories,
!config.github.skipForks,
config.include,
config.exclude,
);

console.log(`Found ${githubRepositories.length} repositories on github`);
Expand Down

0 comments on commit 9a2702f

Please sign in to comment.