Github Add/Update/Delete File(s) on Branch with GraphQL

In input contents is base64 encoded and expectedHeadOid must match with last commit on branch referenced and operation will fails on mismatch:

{
  "input": {
    "branch": {
      "repositoryNameWithOwner": "gliptak/githubapitest1",
      "branchName": "my_branch"
    },
    "message": {
      "headline": "Hello from GraphQL!"
    },
    "fileChanges": {
      "additions": [
        {
          "path": "graphql.txt",
          "contents": "SGVsbG8gZnJvbSBHcmFwaFFMIQo="
        }
      ],
      "deletions": [
        {
          "path": "README.md"
        }
      ]
    },
    "expectedHeadOid": "74512c01ecaec77e38497d448d391065c07ce973"
  }
}

Mutation below updates branch with fileChanges listed:

mutation ($input: CreateCommitOnBranchInput!) {
  createCommitOnBranch(input: $input) {
    commit {
      url
    }
  }
}

and returns:

{
  "data": {
    "createCommitOnBranch": {
      "commit": {
        "oid": "dfeef335f3f622e090497d45e13ecaff5ca9470f",
        "changedFilesIfAvailable": 2
      }
    }
  }
}

Various other data elements can also be returned.

comments powered by Disqus

Related