You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

41 lines
1.3 KiB

const express = require('express');
const rest = require('superagent');
const simpleGit = require('simple-git');
const fs = require('fs');
const app = express();
const giteaHost = 'git.adb.sh';
app.get('/', function (req, res) {
res.send('Hello World');
});
app.listen(3000);
let findRepos = setInterval(()=>{
rest.get(`https://${giteaHost}/api/v1/repos/search?q=${giteaHost}`).then(res=>{
console.log(res.text);
let content = JSON.parse(res.text);
content.data.forEach(repo=>{
if (!repo.name.match(/^(.*).git.adb.sh/)) return; //matches domain?
let namePattern = new RegExp(`^(.*.)|()${repo.owner.username}.${giteaHost}`);
if (!repo.name.match(namePattern)) return; //matches owner?
console.log(`found => ${repo.owner.username}.${giteaHost}`)
updateRepo(repo);
});
}).catch(console.error);
},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}`);
}
}