I have an application where I'm using the GitHub GraphQL mutation createCommitOnBranch to push commits to a repository. However when there are multiple requests for pushing commits to the repository, the API is returning an error stating that branch head is pointing to a different sha. This might be possible due to the stale branch HEAD being present in the request and the API expecting the most recent one.
Will a simple retry mechanism work in such kind of situations? Looking for suggestions in terms of best practices to manage concurrency related issues
Following is the sequence of operations being performed in my application:
- Fetch oid of the latest commit on master
query($repo_name: String!, $owner: String!){
repository(name: $repo_name, owner: $owner) {
defaultBranchRef {
target {
... on Commit {
history(first: 1) {
nodes {
oid
}
}
}
}
}
}
}
- Push commit using createCommitOnBranch mutation
variables = {
"input": {
"branch": {
"repositoryNameWithOwner": "owner/repo"
"branchName": "master"
}, "message": {"headline": commit_message},
"fileChanges": {"additions": [{"path": file_name, "contents":
base64_encoded_content}]}, "expectedHeadOid": oid
}
}
query = """
mutation($input: CreateCommitOnBranchInput!){
createCommitOnBranch(input: $input){
commit {
url
}
}
}
"""
Here is a truncated error message from the API - is at 7f2e12aea7f6gf3b18a986c7db46df639258fa39 but expected 0e860e073af5cb82bda63db42411391a55317304