Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Fix repos' update hooks of gitea service (which was moved around)
#!/usr/bin/env node
// XXX: This file MUST BE in the same folder as gitea.
// if "/opt/gitea/gitea web" starts the service
// then "/opt/gitea/fix_repos.js" is this file
// and "/opt/gitea/gitea-repositories" is the repos folder (default location)
const _fs = require('fs');
const _ROOT = __dirname;
const _REPO_ROOT = __dirname + '/gitea-repositories';
const _get_update_hook = function(path) {
let data = '';
data += '#!/usr/bin/env bash\n';
data += '"' + _ROOT + '/gitea" update $1 $2 $3 --config="' + _ROOT + '/custom/conf/app.ini"\n';
return data.trim();
};
_fs.readdir(_REPO_ROOT, (err, orgas) => {
orgas.forEach(orga => _fs.readdir(_REPO_ROOT + '/' + orga, (err, repos) => {
repos.filter(val => val.endsWith('.git')).forEach(repo => {
let path = _REPO_ROOT + '/' + orga + '/' + repo;
let data = _get_update_hook();
_fs.writeFile(path + '/hooks/update', data, 'utf8', (err) => {
if (err) console.log('failed to write ' + path);
});
});
}));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.