clone and fetch/reset repos

master
adb 4 years ago
parent d169a6c2b4
commit 645766109a

@ -1,17 +1,20 @@
const express = require('express'); const express = require('express');
const rest = require('superagent'); const rest = require('superagent');
const simpleGit = require('simple-git');
const fs = require('fs');
const app = express();
const giteaHost = 'git.adb.sh'; const giteaHost = 'git.adb.sh';
const app = express();
app.get('/', function (req, res) { app.get('/', function (req, res) {
res.send('Hello World'); res.send('Hello World');
}); });
app.listen(3000); app.listen(3000);
let updateRepos = setInterval(()=>{ let findRepos = setInterval(()=>{
rest.get('https://git.adb.sh/api/v1/repos/search?q=git.adb.sh').then(res=>{ rest.get(`https://${giteaHost}/api/v1/repos/search?q=${giteaHost}`).then(res=>{
console.log(res.text); console.log(res.text);
let content = JSON.parse(res.text); let content = JSON.parse(res.text);
content.data.forEach(repo=>{ content.data.forEach(repo=>{
@ -19,7 +22,20 @@ let updateRepos = setInterval(()=>{
let namePattern = new RegExp(`^(.*.)|()${repo.owner.username}.${giteaHost}`); let namePattern = new RegExp(`^(.*.)|()${repo.owner.username}.${giteaHost}`);
if (!repo.name.match(namePattern)) return; //matches owner? if (!repo.name.match(namePattern)) return; //matches owner?
console.log(`found => ${repo.owner.username}.${giteaHost}`) console.log(`found => ${repo.owner.username}.${giteaHost}`)
updateRepo(repo);
}); });
}).catch(console.error); }).catch(console.error);
},1000); },5*1000);
function updateRepo(repo){
if (!fs.existsSync(`./repoStorage/${repo.name}`)){
let git = simpleGit(`./repoStorage/`);
git.clone(repo.clone_url);
console.log(`clone ${repo.name}`);
}else{
let git = simpleGit(`./repoStorage/`);
git.fetch(repo.clone_url);
git.reset('hard');
console.log(`fetch/reset ${repo.name}`);
}
}
Loading…
Cancel
Save