Initial commit #11
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: fmt | |
on: | |
# NOTE: Need to run on a PR so that the ${{ github.head_ref }} (branch) is non-null | |
pull_request: | |
types: | |
- opened | |
- synchronize | |
- reopened | |
jobs: | |
fmt-code: | |
runs-on: ubuntu-latest | |
permissions: | |
# Give the default GITHUB_TOKEN write permission to commit and push the | |
# added or changed files to the repository. | |
contents: write | |
steps: | |
- uses: actions/checkout@v4 | |
# Include the pull request ref in the checkout action to prevent merge commit | |
# https://github.com/actions/checkout?tab=readme-ov-file#checkout-pull-request-head-commit-instead-of-merge-commit | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Setup git | |
run: echo ${{ github.head_ref || github.ref_name }} | |
- name: Create Commit on Branch using GraphQL API | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
# Define GraphQL mutation | |
mutation=' | |
mutation($input: CreateCommitOnBranchInput!) { | |
createCommitOnBranch(input: $input) { | |
commit { | |
url | |
} | |
} | |
} | |
' | |
# Define the input payload for the mutation | |
branch="feature/signed-commits-testing" # Update with your target branch | |
message="Automated commit via GraphQL" | |
filePath="README.md" # Update with the file you want to modify | |
fileContent="This is an automated update." | |
# Create the payload for the mutation | |
payload=$(jq -n \ | |
--arg branch "$branch" \ | |
--arg message "$message" \ | |
--arg filePath "$filePath" \ | |
--arg fileContent "$fileContent" \ | |
'{ | |
"query": $mutation, | |
"variables": { | |
"input": { | |
"branch": { "repositoryName": "house-of-fun", "ownerName": "ep-93", "branchName": $branch }, | |
"message": $message, | |
"fileChanges": { | |
"additions": [{ | |
"path": $filePath, | |
"contents": $fileContent | |
}] | |
} | |
} | |
} | |
}' | |
) | |
# Make the API call | |
curl -X POST \ | |
-H "Authorization: bearer $GITHUB_TOKEN" \ | |
-H "Content-Type: application/json" \ | |
-d "$payload" \ | |
https://api.github.com/graphql |