javascript 克隆一个GitHub用户的所有公共要点。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 克隆一个GitHub用户的所有公共要点。相关的知识,希望对你有一定的参考价值。

#!/usr/bin/env node

//	clone all repos
function cloneAll() {
	for (i = 0; i < repos.length; i++) {
		console.log('Cloning ' + repos[i].description);
		exec("git clone " + repos[i].url);
	}
}

//	retrieve new page of gists
function readPage(err, res, body) {
	var gists = JSON.parse(body);

	//	break if no gists found
	if (!gists || !gists.length === 0) {
		console.log("No gists to clone");
		process.exit();
	//	populate array with found gists
	} else {
		for (var i = 0; i < gists.length; i++) {
			repos.push({description: gists[i].description, url: gists[i].html_url});
		};
		//	clone repos if last page
		if (gists.length < 30) {
			cloneAll();
		//	turn page and rerun callback if not last page
		} else {
			page++;
			options.url = "https://api.github.com/users/" + username + "/gists?page=" + page;
			setTimeout(function() {
				request(options, readPage);
			}, 2000);
		}
	}
};

//	break if no username given
if (process.argv.length < 3) {
	console.log("Missing username argument");
	process.exit();
//	set global variables and run first request
} else {
	var username = process.argv[2];
	var request = require("request");
	var exec = require("child_process").exec;
	var endOfGists = false;
	var page = 1;
	var repos = [];
	var options = {
		url: "https://api.github.com/users/" + username + "/gists?page=" + page,
		headers: {
			"User-Agent": "node request"
		}
	};

	request(options, readPage);
}

以上是关于javascript 克隆一个GitHub用户的所有公共要点。的主要内容,如果未能解决你的问题,请参考以下文章

无法克隆私有存储库 github:身份验证失败

python 克隆或更新所有用户的要点#backup #github #gists #management

github的本地克隆与上传

在 Python 中从克隆的 GitHub 存储库创建 Zip 存档

将克隆的项目上传到自己的github

gitlab怎么克隆最新版本