Files
the-nexus/gitea-branch-protection.js
Groq Agent 463a5afd65
Some checks failed
Deploy Nexus / deploy (push) Has been cancelled
CI / test (pull_request) Failing after 6s
CI / validate (pull_request) Failing after 3s
[groq] [QA][POLICY] Branch Protection + Mandatory Review Policy for All Repos (#918) (#994)
2026-04-07 09:12:57 +00:00

76 lines
2.4 KiB
JavaScript

const GiteaApiUrl = 'https://forge.alexanderwhitestone.com/api/v1';
const token = process.env.GITEA_TOKEN; // Should be stored securely in environment variables
const repos = ['hermes-agent', 'the-nexus', 'timmy-home', 'timmy-config'];
const branchProtectionSettings = {
enablePush: false,
enableMerge: true,
requiredApprovals: 1,
dismissStaleApprovals: true,
requiredStatusChecks: true,
blockForcePush: true,
blockDelete: true
// Special handling for the-nexus (CI disabled)
};
async function applyBranchProtection(repo) {
try {
const response = await fetch(`${giteaApiUrl}/repos/Timmy_Foundation/${repo}/branches/main/protection`, {
method: 'POST',
headers: {
'Authorization': `token ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
...branchProtectionSettings,
// Special handling for the-nexus (CI disabled)
requiredStatusChecks: repo === 'the-nexus' ? false : true
})
});
if (!response.ok) {
throw new Error(`Failed to apply branch protection to ${repo}: ${await response.text()}`);
}
console.log(`✅ Branch protection applied to ${repo}`);
} catch (error) {
console.error(`❌ Error applying branch protection to ${repo}: ${error.message}`);
}
}
async function applyBranchProtection(repo) {
try {
const response = await fetch(`${giteaApiUrl}/repos/Timmy_Foundation/${repo}/branches/main/protection`, {
method: 'POST',
headers: {
'Authorization': `token ${token}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
...branchProtectionSettings,
requiredApprovals: repo === 'hermes-agent' ? 2 : 1,
requiredStatusChecks: repo === 'the-nexus' ? false : true
})
});
if (!response.ok) {
throw new Error(`Failed to apply branch protection to ${repo}: ${await response.text()}`);
}
console.log(`✅ Branch protection applied to ${repo}`);
} catch (error) {
console.error(`❌ Error applying branch protection to ${repo}: ${error.message}`);
}
}
async function setupAllBranchProtections() {
console.log('🚀 Applying branch protections to all repositories...');
for (const repo of repos) {
await applyBranchProtection(repo);
}
console.log('✅ All branch protections applied successfully');
}
// Run the setup
setupAllBranchProtections();