From 8781da65bae4ee86ea8be9cb9cbe7234980aae27 Mon Sep 17 00:00:00 2001 From: TECNO <50276602+tecno14@users.noreply.github.com> Date: Sun, 10 Oct 2021 14:53:35 +0300 Subject: [PATCH] improvement --- .gitignore | 118 +++++++++++++++++++ Demo.js | 5 - README.md | 16 ++- example.js | 3 + clone_all.js => github_clone_all.js | 37 +++--- package-lock.json | 171 +++++++++++++++++++++++++++- package.json | 20 +++- 7 files changed, 338 insertions(+), 32 deletions(-) create mode 100644 .gitignore delete mode 100644 Demo.js create mode 100644 example.js rename clone_all.js => github_clone_all.js (68%) diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..943af75 --- /dev/null +++ b/.gitignore @@ -0,0 +1,118 @@ +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* +.pnpm-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +node_modules/ +jspm_packages/ + +# Snowpack dependency directory (https://snowpack.dev/) +web_modules/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Microbundle cache +.rpt2_cache/ +.rts2_cache_cjs/ +.rts2_cache_es/ +.rts2_cache_umd/ + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test +.env.production + +# parcel-bundler cache (https://parceljs.org/) +.cache +.parcel-cache + +# Next.js build output +.next +out + +# Nuxt.js build / generate output +.nuxt +dist + +# Gatsby files +.cache/ +# Comment in the public line in if your project uses Gatsby and not Next.js +# https://nextjs.org/blog/next-9-1#public-directory-support +# public + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ + +# TernJS port file +.tern-port + +# Stores VSCode versions used for testing VSCode extensions +.vscode-test + +# yarn v2 +.yarn/cache +.yarn/unplugged +.yarn/build-state.yml +.yarn/install-state.gz +.pnp.* \ No newline at end of file diff --git a/Demo.js b/Demo.js deleted file mode 100644 index 713bbfa..0000000 --- a/Demo.js +++ /dev/null @@ -1,5 +0,0 @@ -const ca = require('./clone_all'); - -ca.clone_all('GitHub_Username'); - -console.log('Done !!!!'); \ No newline at end of file diff --git a/README.md b/README.md index 6dcc1cf..9242fa8 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,16 @@ # CloneRepo - Clone All User Repositories from Github + Clone all user repositories from Github + + `using only username` + +``` +const clone_all = require('./github_clone_all'); + +clone_all.username_clone_all('tecno14'); +``` + +you can put this two line in `file.js` then run it: +```node file.js``` + +##Installation +```npm install @wael14/github_clone_all``` \ No newline at end of file diff --git a/example.js b/example.js new file mode 100644 index 0000000..5a77879 --- /dev/null +++ b/example.js @@ -0,0 +1,3 @@ +const clone_all = require('./github_clone_all'); + +clone_all.username_clone_all('tecno14'); \ No newline at end of file diff --git a/clone_all.js b/github_clone_all.js similarity index 68% rename from clone_all.js rename to github_clone_all.js index 3b31d04..29768f2 100644 --- a/clone_all.js +++ b/github_clone_all.js @@ -1,44 +1,41 @@ + // clone all github user repos // TECNO 2020 wael.had.sy@gmail.com // -------------------------------- -// ToDo - -// -------------------------------- - // How its work // 1- get user repos from github api -// 2- clone each one +// 2- clone each one in loop // -------------------------------- const https = require('https'); const shell = require('shelljs'); -module.exports.clone_all = function(username) { +module.exports.username_clone_all = function(username) { if(username) - clone_all(username); + username_clone_all(username); else - console.log("'username' required !!"); + console.log("'username' required !!"); + return; } -function clone_all(username) { +function username_clone_all(username) { + + console.log(`will clone all "${username}" repos ... enjoy`); var options = { hostname: "api.github.com", port: 443, //https - path: "/users/" + username + "/repos?per_page=9999", + path: `/users/${username}/repos?per_page=9999`, method: 'GET', headers: { 'content-type': 'application/json', 'User-Agent': 'Mozilla/5.0' } }; - - console.log(username); - //change to http for local testing var req = https.get(options, function(res) { res.setEncoding('utf8'); @@ -52,23 +49,24 @@ function clone_all(username) { res.on('end', function() { repos = JSON.parse(body); - console.log(repos.length + ' repo found !!'); + console.log(` (${repos.length}) repos found !!`); + //create user folder shell.mkdir(username); - shell.cd(username) for (var i = 0; i < repos.length; i++) { console.log((i + 1) + '- ' + repos[i].name); - shell.exec('git clone ' + repos[i].clone_url); + shell.exec(`git clone ${repos[i].clone_url} ./${username}/${repos[i].name}`); + console.log(repos[i].name + ' done'); console.log('--------------'); } + console.log('Done !!!!'); + if (res.statusCode != 200) { - //callback("Api call failed with response code " + res.statusCode); console.log("Api call failed with response code " + res.statusCode); return; } else { - //callback(null); return; } }); @@ -80,8 +78,5 @@ function clone_all(username) { callback(e); }); - // write data to request body - //req.write(post_data); req.end(); - } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 9bd7075..606643c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,9 +1,176 @@ { - "name": "clone_all", + "name": "@wael14/github_clone_all", "version": "1.0.0", - "lockfileVersion": 1, + "lockfileVersion": 2, "requires": true, + "packages": { + "": { + "name": "@wael14/github_clone_all", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@wael14/github_clone_all": "^1.0.0", + "shelljs": "^0.8.4" + } + }, + "node_modules/@wael14/github_clone_all": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@wael14/github_clone_all/-/github_clone_all-1.0.0.tgz", + "integrity": "sha512-wHGv9WF2Nmv0NWhhKFS/ak0jpbb4rkcN5El7Scn3FP52szN0k6QImg7dqLcDpYCcbysxe/Bv5uC9dAN5mxjo3Q==", + "dependencies": { + "shelljs": "^0.8.4" + } + }, + "node_modules/balanced-match": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", + "integrity": "sha1-ibTRmasr7kneFk6gK4nORi1xt2c=" + }, + "node_modules/brace-expansion": { + "version": "1.1.11", + "resolved": "https://registry.npmjs.org/brace-expansion/-/brace-expansion-1.1.11.tgz", + "integrity": "sha512-iCuPHDFgrHX7H2vEI/5xpz07zSHB00TpugqhmYtVmMO6518mCuRMoOYFldEBl0g187ufozdaHgWKcYFb61qGiA==", + "dependencies": { + "balanced-match": "^1.0.0", + "concat-map": "0.0.1" + } + }, + "node_modules/concat-map": { + "version": "0.0.1", + "resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz", + "integrity": "sha1-2Klr13/Wjfd5OnMDajug1UBdR3s=" + }, + "node_modules/fs.realpath": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/fs.realpath/-/fs.realpath-1.0.0.tgz", + "integrity": "sha1-FQStJSMVjKpA20onh8sBQRmU6k8=" + }, + "node_modules/glob": { + "version": "7.1.6", + "resolved": "https://registry.npmjs.org/glob/-/glob-7.1.6.tgz", + "integrity": "sha512-LwaxwyZ72Lk7vZINtNNrywX0ZuLyStrdDtabefZKAY5ZGJhVtgdznluResxNmPitE0SAO+O26sWTHeKSI2wMBA==", + "dependencies": { + "fs.realpath": "^1.0.0", + "inflight": "^1.0.4", + "inherits": "2", + "minimatch": "^3.0.4", + "once": "^1.3.0", + "path-is-absolute": "^1.0.0" + }, + "engines": { + "node": "*" + }, + "funding": { + "url": "https://github.com/sponsors/isaacs" + } + }, + "node_modules/inflight": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/inflight/-/inflight-1.0.6.tgz", + "integrity": "sha1-Sb1jMdfQLQwJvJEKEHW6gWW1bfk=", + "dependencies": { + "once": "^1.3.0", + "wrappy": "1" + } + }, + "node_modules/inherits": { + "version": "2.0.4", + "resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.4.tgz", + "integrity": "sha512-k/vGaX4/Yla3WzyMCvTQOXYeIHvqOKtnqBduzTHpzpQZzAskKMhZ2K+EnBiSM9zGSoIFeMpXKxa4dYeZIQqewQ==" + }, + "node_modules/interpret": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/interpret/-/interpret-1.4.0.tgz", + "integrity": "sha512-agE4QfB2Lkp9uICn7BAqoscw4SZP9kTE2hxiFI3jBPmXJfdqiahTbUuKGsMoN2GtqL9AxhYioAcVvgsb1HvRbA==", + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/minimatch": { + "version": "3.0.4", + "resolved": "https://registry.npmjs.org/minimatch/-/minimatch-3.0.4.tgz", + "integrity": "sha512-yJHVQEhyqPLUTgt9B83PXu6W3rx4MvvHvSUvToogpwoGDOUQ+yDrR0HRot+yOCdCO7u4hX3pWft6kWBBcqh0UA==", + "dependencies": { + "brace-expansion": "^1.1.7" + }, + "engines": { + "node": "*" + } + }, + "node_modules/once": { + "version": "1.4.0", + "resolved": "https://registry.npmjs.org/once/-/once-1.4.0.tgz", + "integrity": "sha1-WDsap3WWHUsROsF9nFC6753Xa9E=", + "dependencies": { + "wrappy": "1" + } + }, + "node_modules/path-is-absolute": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", + "integrity": "sha1-F0uSaHNVNP+8es5r9TpanhtcX18=", + "engines": { + "node": ">=0.10.0" + } + }, + "node_modules/path-parse": { + "version": "1.0.6", + "resolved": "https://registry.npmjs.org/path-parse/-/path-parse-1.0.6.tgz", + "integrity": "sha512-GSmOT2EbHrINBf9SR7CDELwlJ8AENk3Qn7OikK4nFYAu3Ote2+JYNVvkpAEQm3/TLNEJFD/xZJjzyxg3KBWOzw==" + }, + "node_modules/rechoir": { + "version": "0.6.2", + "resolved": "https://registry.npmjs.org/rechoir/-/rechoir-0.6.2.tgz", + "integrity": "sha1-hSBLVNuoLVdC4oyWdW70OvUOM4Q=", + "dependencies": { + "resolve": "^1.1.6" + }, + "engines": { + "node": ">= 0.10" + } + }, + "node_modules/resolve": { + "version": "1.17.0", + "resolved": "https://registry.npmjs.org/resolve/-/resolve-1.17.0.tgz", + "integrity": "sha512-ic+7JYiV8Vi2yzQGFWOkiZD5Z9z7O2Zhm9XMaTxdJExKasieFCr+yXZ/WmXsckHiKl12ar0y6XiXDx3m4RHn1w==", + "dependencies": { + "path-parse": "^1.0.6" + }, + "funding": { + "url": "https://github.com/sponsors/ljharb" + } + }, + "node_modules/shelljs": { + "version": "0.8.4", + "resolved": "https://registry.npmjs.org/shelljs/-/shelljs-0.8.4.tgz", + "integrity": "sha512-7gk3UZ9kOfPLIAbslLzyWeGiEqx9e3rxwZM0KE6EL8GlGwjym9Mrlx5/p33bWTu9YG6vcS4MBxYZDHYr5lr8BQ==", + "dependencies": { + "glob": "^7.0.0", + "interpret": "^1.0.0", + "rechoir": "^0.6.2" + }, + "bin": { + "shjs": "bin/shjs" + }, + "engines": { + "node": ">=4" + } + }, + "node_modules/wrappy": { + "version": "1.0.2", + "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz", + "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" + } + }, "dependencies": { + "@wael14/github_clone_all": { + "version": "1.0.0", + "resolved": "https://registry.npmjs.org/@wael14/github_clone_all/-/github_clone_all-1.0.0.tgz", + "integrity": "sha512-wHGv9WF2Nmv0NWhhKFS/ak0jpbb4rkcN5El7Scn3FP52szN0k6QImg7dqLcDpYCcbysxe/Bv5uC9dAN5mxjo3Q==", + "requires": { + "shelljs": "^0.8.4" + } + }, "balanced-match": { "version": "1.0.0", "resolved": "https://registry.npmjs.org/balanced-match/-/balanced-match-1.0.0.tgz", diff --git a/package.json b/package.json index 8374b84..da28686 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,28 @@ { - "name": "clone_all", + "name": "@wael14/github_clone_all", "version": "1.0.0", "description": "clone all github repos . tecno 2020 . wael.had.sy@gmail.com", "main": "app.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, - "author": " tecno 2020 . wael.had.sy@gmail.com", + "author": "tecno 2021 . wael.had.sy@gmail.com", "license": "ISC", "dependencies": { + "@wael14/github_clone_all": "^1.0.0", "shelljs": "^0.8.4" - } + }, + "repository": { + "type": "git", + "url": "git+https://github.com/tecno14/clone_all.git" + }, + "keywords": [ + "github", + "clone", + "repositories" + ], + "bugs": { + "url": "https://github.com/tecno14/clone_all/issues" + }, + "homepage": "https://github.com/tecno14/clone_all#readme" }