Files
openclaw-taskboard/gitea-routes.js

142 lines
3.9 KiB
JavaScript

/**
* Gitea Routes Module
* Adds Gitea integration routes to Express app
*/
const GiteaIntegration = require('./gitea-integration.js');
function setupGiteaRoutes(app) {
// Initialize Gitea client
const giteaConfig = {
baseUrl: process.env.GITEA_URL || 'https://gitea.tophermayor.com',
token: process.env.GITEA_TOKEN,
owner: 'TopherMayor',
cacheTimeout: 30000
};
const gitea = new GiteaIntegration(giteaConfig);
// Gitea API routes
app.get('/api/gitea/swarm', async (req, res) => {
try {
const summary = await gitea.getSwarmSummary();
res.json(summary);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/reviews', async (req, res) => {
try {
const reviews = await gitea.getPendingReviews();
res.json(reviews);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/activity', async (req, res) => {
try {
const activity = await gitea.getRecentActivity();
res.json(activity);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/user', async (req, res) => {
try {
const user = await gitea.getUser();
res.json(user);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/repos/:repo', async (req, res) => {
try {
const repo = await gitea.getRepo(req.params.repo);
res.json(repo);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/repos/:repo/pulls', async (req, res) => {
try {
const state = req.query.state || 'open';
const prs = await gitea.getPullRequests(req.params.repo, state);
res.json(prs);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/repos/:repo/issues', async (req, res) => {
try {
const state = req.query.state || 'open';
const issues = await gitea.getIssues(req.params.repo, state);
res.json(issues);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/repos/:repo/commits', async (req, res) => {
try {
const branch = req.query.branch || 'main';
const limit = parseInt(req.query.limit) || 10;
const commits = await gitea.getCommits(req.params.repo, branch, limit);
res.json(commits);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.get('/api/gitea/repos/:repo/branches', async (req, res) => {
try {
const branches = await gitea.getBranches(req.params.repo);
res.json(branches);
} catch (error) {
res.status(500).json({ error: error.message });
}
});
app.post('/api/gitea/cache/clear', (req, res) => {
gitea.clearCache();
res.json({ success: true, message: 'Cache cleared' });
});
console.log('✅ Gitea integration loaded');
}
module.exports = { setupGiteaRoutes };
// PR Assignment endpoint
app.post('/api/gitea/prs/:repo/:number/assign', async (req, res) => {
const { repo, number } = req.params;
const { reviewer } = req.body;
try {
// In a real implementation, this would call Gitea API to assign reviewer
// For now, just log the assignment
console.log(`Assigning PR ${repo}#${number} to ${reviewer}`);
res.json({ success: true, message: `Assigned PR #${number} in ${repo} to ${reviewer}` });
} catch (error) {
res.status(500).json({ error: error.message });
}
});
// Get PR details with review status
app.get('/api/gitea/prs/:repo/:number', async (req, res) => {
const { repo, number } = req.params;
try {
const pr = await gitea.request(`/api/v1/repos/${giteaConfig.owner}/${repo}/pulls/${number}`);
res.json(pr);
} catch (error) {
res.status(500).json({ error: error.message });
}
});