|
6 | 6 | getGithubReadToken, |
7 | 7 | getGithubReleaseToken, |
8 | 8 | getGithubPullRequestToken, |
| 9 | + getGithubCommitToken, |
9 | 10 | type OctoStsToken, |
10 | 11 | } from './secrets.ts' |
11 | 12 | import { FetchError, fetchHandlingError, findError } from './executionUtils.ts' |
@@ -74,6 +75,26 @@ export function createPullRequest(mainBranch: string, labels?: string[]) { |
74 | 75 | return pullRequestUrl.trim() |
75 | 76 | } |
76 | 77 |
|
| 78 | +/** |
| 79 | + * Push the current HEAD commit to a new remote branch as a signed (Verified) commit, using |
| 80 | + * commit-headless to create it through the GitHub API instead of a plain `git push`. Since the |
| 81 | + * remote commit is re-signed, its SHA differs from the local one: `--reset` resets the local |
| 82 | + * branch to it, so callers (e.g. `gh pr create`) see it as fully pushed and don't attempt an |
| 83 | + * unsigned push of their own. |
| 84 | + */ |
| 85 | +export function pushSignedCommit(branch: string): void { |
| 86 | + // `--create-branch` has no default branch point, so `--head-sha` must be given explicitly: the |
| 87 | + // parent of HEAD, i.e. the commit the local branch was created from. |
| 88 | + const headSha = command`git rev-parse HEAD^`.run().trim() |
| 89 | + |
| 90 | + using token = getGithubCommitToken() |
| 91 | + command`commit-headless push -T DataDog/browser-sdk --branch ${branch} --create-branch --head-sha ${headSha} --reset` |
| 92 | + .withEnvironment({ GITHUB_TOKEN: token.value }) |
| 93 | + .withLogs() |
| 94 | + .run() |
| 95 | + command`git branch --set-upstream-to=origin/${branch} ${branch}`.run() |
| 96 | +} |
| 97 | + |
77 | 98 | export function getLastCommonCommit(baseBranch: string): string { |
78 | 99 | try { |
79 | 100 | command`git fetch --depth=100 origin ${baseBranch}`.run() |
|
0 commit comments