|
75 | 75 | // --- Read VOUCHED.td --- |
76 | 76 |
|
77 | 77 | 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 | + } |
79 | 105 |
|
80 | 106 | let currentContent = ''; |
81 | 107 | let sha = ''; |
|
89 | 115 | currentContent = Buffer.from(data.content, 'base64').toString('utf-8'); |
90 | 116 | sha = data.sha; |
91 | 117 | } 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}`); |
93 | 119 | return; |
94 | 120 | } |
95 | 121 |
|
|
0 commit comments