As mentioned in "GitHub API - write to repo", you would need to create a blob.
You can see an example in KnpLabs/php-github-api/test/Github/Tests/Api/GitData/BlobsTest.php#L53-L68
(I am using KnpLabs/php-github-api
, since ornicar/php-github-api
is deprecated and refers to it)
/**
* @test
*/
public function shouldCreateBlob()
{
$expectedValue = array('blob' => 'some data');
$data = array('content' => 'some cotent', 'encoding' => 'utf8');
$api = $this->getApiMock();
$api->expects($this->once())
->method('post')
->with('repos/l3l0/l3l0repo/git/blobs', $data)
->will($this->returnValue($expectedValue));
$this->assertEquals($expectedValue, $api->create('l3l0', 'l3l0repo', $data));
}
There is no filename yet: you upload content;
To create a file though, as shown in this example, you would still need to:
- get the SHA the current master branch points to
- fetch the tree this SHA belongs to
- create a new tree object with the new blob, based on the old tree
- create a new commit object using the new tree and point its parent to the current master
- finally update the heads/master reference to point to the new commit