@@ -18,45 +18,10 @@ if [ -z "$GITHUB_REPOSITORY" ] || [ -z "$BOT_TOKEN" ]; then
1818 exit 1
1919fi
2020
21- createCommitAPICall () {
22- commit=" ${1:- HEAD} "
23- cat - << 'EOF '
24- mutation ($repo: String! $branch: String!, $parent: GitObjectID!, $commit_title: String!, $commit_body: String) {
25- createCommitOnBranch(input: {
26- branch: {
27- repositoryNameWithOwner: $repo,
28- branchName: $branch
29- },
30- message: {
31- headline: $commit_title,
32- body: $commit_body
33- },
34- expectedHeadOid: $parent,
35- fileChanges: {
36- additions: [
37- EOF
38- git show " $commit " --diff-filter=d --name-only --format= | while read -r FILE; do
39- printf " { path: "
40- node -p ' JSON.stringify(process.argv[1])' " $FILE "
41- printf " , contents: \" "
42- base64 -w 0 -i " $FILE "
43- echo " \" },"
44- done
45- echo ' ], deletions: ['
46- git show " $commit " --diff-filter=D --name-only --format= | while read -r FILE; do
47- node -p ' " " + JSON.stringify(process.argv[1]) + ","' " $FILE "
48- done
49- cat - << 'EOF '
50- ]
51- }
52- }) {
53- commit {
54- url
55- }
56- }
57- }
58- EOF
59- }
21+ if ! command -v node || ! command -v gh || ! command -v git || ! command -v awk; then
22+ echo " Missing required dependencies"
23+ exit 1
24+ fi
6025
6126git node release --prepare --skipBranchDiff --yes --releaseDate " $RELEASE_DATE "
6227
@@ -85,20 +50,77 @@ PR_URL="$(gh api \
8550 " /repos/${GITHUB_REPOSITORY} /pulls" \
8651 -f " title=$TITLE " -f " body=$TEMP_BODY " -f " head=$HEAD_BRANCH " -f " base=v$RELEASE_LINE .x" ) "
8752
88- # Push the release commit to the proposal branch
89- createCommitAPICall HEAD | node --input-type=module -e ' console.log(JSON.stringify({
90- query: Buffer.concat(await process.stdin.toArray()).toString(),
91- variables: {
92- repo: process.argv[1],
93- branch: process.argv[2],
94- parent: process.argv[3],
95- commit_title: process.argv[4],
96- commit_body: process.argv[5]
97- }
98- }))' \
53+ # Push the release commit to the proposal branch using `BOT_TOKEN` from the env
54+ node --input-type=module - \
9955 " $GITHUB_REPOSITORY " \
10056 " $HEAD_BRANCH " \
10157 " $HEAD_SHA " \
10258 " $( git log -1 HEAD --format=%s || true) " \
103- " $( git log -1 HEAD --format=%b | sed " s|PR-URL: TODO|PR-URL: $PR_URL |" || true) " \
104- | curl -fS -H " Authorization: bearer ${BOT_TOKEN} " -X POST --data @- https://api.github.com/graphql
59+ " $( git log -1 HEAD --format=%b | awk -v PR_URL=" $PR_URL " ' {sub(/^PR-URL: TODO$/, "PR-URL: " PR_URL)} 1' || true) " \
60+ " $( git show HEAD --diff-filter=d --name-only --format= || true) " \
61+ " $( git show HEAD --diff-filter=D --name-only --format= || true) " \
62+ << 'EOF '
63+ const [,,
64+ repo,
65+ branch,
66+ parentCommitSha,
67+ commit_title,
68+ commit_body,
69+ modifiedOrAddedFiles,
70+ deletedFiles,
71+ ] = process.argv;
72+
73+ import { readFileSync } from 'node:fs';
74+ import util from 'node:util';
75+
76+ const query = `
77+ mutation ($repo: String! $branch: String!, $parentCommitSha: GitObjectID!, $changes: FileChanges!, $commit_title: String!, $commit_body: String) {
78+ createCommitOnBranch(input: {
79+ branch: {
80+ repositoryNameWithOwner: $repo,
81+ branchName: $branch
82+ },
83+ message: {
84+ headline: $commit_title,
85+ body: $commit_body
86+ },
87+ expectedHeadOid: $parentCommitSha,
88+ fileChanges: $changes
89+ }) {
90+ commit {
91+ url
92+ }
93+ }
94+ }
95+ `;
96+ const response = await fetch('https://api.github.com/graphql', {
97+ method: 'POST',
98+ headers: {
99+ 'Authorization': `bearer ${process.env.BOT_TOKEN}`,
100+ },
101+ body: JSON.stringify({
102+ query,
103+ variables: {
104+ repo,
105+ branch,
106+ parentCommitSha,
107+ commit_title,
108+ commit_body,
109+ changes: {
110+ additions: modifiedOrAddedFiles.split('\n').filter(Boolean)
111+ .map(path => ({ path, contents: readFileSync(path).toString('base64') })),
112+ deletions: deletedFiles.split('\n').filter(Boolean),
113+ }
114+ },
115+ })
116+ });
117+ if (!response.ok) {
118+ console.log({statusCode: response.statusCode, status: response.status});
119+ process.exitCode ||= 1;
120+ }
121+ const data = await response.json();
122+ if (data.errors?.length) {
123+ throw new Error('Endpoint returned an error', { cause: data });
124+ }
125+ console.log(util.inspect(data, { depth: Infinity }));
126+ EOF
0 commit comments