Skip to content

Commit

Permalink
improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
tecno14 committed Oct 10, 2021
1 parent 6bfa5c2 commit 8781da6
Show file tree
Hide file tree
Showing 7 changed files with 338 additions and 32 deletions.
118 changes: 118 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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.*
5 changes: 0 additions & 5 deletions Demo.js

This file was deleted.

16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -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```
3 changes: 3 additions & 0 deletions example.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const clone_all = require('./github_clone_all');

clone_all.username_clone_all('tecno14');
37 changes: 16 additions & 21 deletions clone_all.js → github_clone_all.js
Original file line number Diff line number Diff line change
@@ -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');
Expand All @@ -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;
}
});
Expand All @@ -80,8 +78,5 @@ function clone_all(username) {
callback(e);
});

// write data to request body
//req.write(post_data);
req.end();

}
Loading

0 comments on commit 8781da6

Please sign in to comment.