Skip to content

Instantly share code, notes, and snippets.

@zaverden
Created February 26, 2022 16:49
Show Gist options
  • Save zaverden/f74127caa23e979c847066f4f1b97bbe to your computer and use it in GitHub Desktop.
Save zaverden/f74127caa23e979c847066f4f1b97bbe to your computer and use it in GitHub Desktop.

get list of repos from API

Script to clone/fetch all repos in the list

// @ts-check
const { spawnSync } = require("child_process");
const { existsSync, mkdirSync } = require("fs");
const { resolve: resolvePath } = require("path");

const { HOME } = process.env;
const base = resolvePath(HOME, "dev");

const urls = [
  // "git@github.com:zaverden/dns-as-code.git",
  // "git@github.com:zaverden/dnscontrol.git",
];

for (const url of urls) {
  processing(url)
}

function processing(url) {
  // git@github.com:zaverden/esbuild-plugin-postcss.git
  const [, service, ...path] = url.replace(/\.git$/, "").split(/\@|\:|\//);

  // ~/dev/github.com/zaverden/esbuild-plugin-postcss
  const repoPath = resolvePath(base, service, ...path);
  if (!existsSync(repoPath)) {
    mkdirSync(repoPath, { recursive: true });
    console.log(`repo folder is created: ${repoPath}`);

    spawnSync("git", ["clone", url, repoPath], {
      stdio: "inherit",
    });
  } else {
    console.log(`Fetching ${url}`);
    spawnSync("git", ["fetch", "--all", "--force", "--prune", "--prune-tags"], {
      stdio: "inherit",
      cwd: repoPath,
    });
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment