Skip to content

Commit 8227719

Browse files
authored
fix: use dedicated vouched branch to avoid branch protection (#379)
1 parent 20dab0b commit 8227719

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

.github/workflows/vouch-check.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,15 @@ jobs:
5959
}
6060
}
6161
62-
// Check the VOUCHED.td file. Read from the default branch, NOT the
63-
// PR branch — the PR author could add themselves in their fork.
62+
// Check the VOUCHED.td file on the dedicated "vouched" branch.
63+
// NOT the PR branch — the PR author could add themselves in their fork.
6464
let vouched = false;
6565
try {
6666
const { data } = await github.rest.repos.getContent({
6767
owner: context.repo.owner,
6868
repo: context.repo.repo,
6969
path: '.github/VOUCHED.td',
70-
ref: context.payload.repository.default_branch,
70+
ref: 'vouched',
7171
});
7272
const content = Buffer.from(data.content, 'base64').toString('utf-8');
7373
const usernames = content

.github/workflows/vouch-command.yml

Lines changed: 28 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,33 @@ jobs:
7575
// --- Read VOUCHED.td ---
7676
7777
const filePath = '.github/VOUCHED.td';
78-
const branch = context.payload.repository.default_branch;
78+
const branch = 'vouched';
79+
80+
// Ensure the "vouched" branch exists. If not, create it from main.
81+
try {
82+
await github.rest.repos.getBranch({
83+
owner: context.repo.owner,
84+
repo: context.repo.repo,
85+
branch,
86+
});
87+
} catch (e) {
88+
if (e.status === 404) {
89+
console.log('Creating "vouched" branch from main.');
90+
const { data: mainRef } = await github.rest.git.getRef({
91+
owner: context.repo.owner,
92+
repo: context.repo.repo,
93+
ref: `heads/${context.payload.repository.default_branch}`,
94+
});
95+
await github.rest.git.createRef({
96+
owner: context.repo.owner,
97+
repo: context.repo.repo,
98+
ref: 'refs/heads/vouched',
99+
sha: mainRef.object.sha,
100+
});
101+
} else {
102+
throw e;
103+
}
104+
}
79105
80106
let currentContent = '';
81107
let sha = '';
@@ -89,7 +115,7 @@ jobs:
89115
currentContent = Buffer.from(data.content, 'base64').toString('utf-8');
90116
sha = data.sha;
91117
} catch (e) {
92-
console.log(`Could not read VOUCHED.td: ${e.message}`);
118+
console.log(`Could not read VOUCHED.td on "${branch}" branch: ${e.message}`);
93119
return;
94120
}
95121

0 commit comments

Comments
 (0)