88 description : " Commit message"
99 default : " Commit from bot"
1010 required : true
11+ token :
12+ description : " GitHub token"
13+ required : true
1114runs :
1215 using : " composite"
1316 steps :
@@ -22,25 +25,51 @@ runs:
2225
2326 echo "::group::Commit files"
2427 if [ ${#FILES[@]} -gt 0 ]; then
25- cmd=("gh" "api" "graphql"
26- -F "githubRepository=${REPOSITORY}"
27- -F "branchName=${REF_NAME}"
28- -F "expectedHeadOid=$(git rev-parse HEAD)"
29- -F "commitMessage=${COMMIT_MESSAGE}")
28+ # Prepare the JSON payload
29+ JSON_PAYLOAD=$(cat <<EOF
30+ {
31+ "query": "$(cat .github/api/createCommitOnBranch.gql)",
32+ "variables": {
33+ "githubRepository": "${REPOSITORY}",
34+ "branchName": "${REF_NAME}",
35+ "expectedHeadOid": "$(git rev-parse HEAD)",
36+ "commitMessage": "${COMMIT_MESSAGE}",
37+ "files": [
38+ EOF
39+ )
3040
41+ FILES_ARRAY=""
3142 for file in "${FILES[@]}"; do
3243 if [ -f "$file" ]; then
3344 echo "${green}Adding file $file${reset}"
34- cmd+=(-F "files[][path]=$file" -F "files[][contents]=$(base64 -w0 "$file")")
45+ base64_content=$(base64 -w0 "$file")
46+ FILES_ARRAY+="{\"path\": \"$file\", \"contents\": \"$base64_content\"},"
3547 else
3648 echo "${red}File $file does not exist, skipping.${reset}"
3749 fi
3850 done
3951
40- cmd+=(-F "[email protected] /api/createCommitOnBranch.gql") 52+ # Remove the last comma if there are files
53+ if [ -n "$FILES_ARRAY" ]; then
54+ FILES_ARRAY=${FILES_ARRAY::-1} # Remove trailing comma
55+ fi
56+
57+ JSON_PAYLOAD+=$(cat <<EOF
58+ $FILES_ARRAY
59+ ]
60+ }
61+ }
62+ EOF
63+ )
64+
65+ echo "${green}${bold}Executing GraphQL query via curl:${reset} ${yellow}curl -X POST -H 'Authorization: bearer ***' -H 'Content-Type: application/json' -d '$JSON_PAYLOAD' https://api.github.com/graphql${reset}"
4166
42- echo "${green}${bold}Executing:${reset} ${yellow}${cmd[@]}${reset}"
43- "${cmd[@]}"
67+ # Actually execute the curl command
68+ curl -X POST \
69+ -H 'Authorization: bearer ${GH_TOKEN}' \
70+ -H 'Content-Type: application/json' \
71+ -d "$JSON_PAYLOAD" \
72+ https://api.github.com/graphql
4473 else
4574 echo "No files to commit."
4675 fi
5079 REF_NAME : ${{ github.ref_name }}
5180 FILES : ${{ inputs.files }}
5281 COMMIT_MESSAGE : ${{ inputs.commitMessage }}
82+ GH_TOKEN : ${{ inputs.token }}
0 commit comments