kaizensoze/node-github

My create file doesn't work

vydingding opened this issue · 3 comments

var GitHubApi = require("github");
var Assert = require("assert");

var github = new GitHubApi({
// required
version: "3.0.0",
// optional
debug: true,
protocol: "https",
host: "api.github.com",
pathPrefix: "",
timeout: 5000,
headers: {
"user-agent": "My-Cool-GitHub-App"
}
});
github.repos.createFile({

user: "vydingding",
repo: "166KATA",
path: "/master/",
message: "my commit message",
content: "hello.csv"

}, function(err, res) {

});

Error message is:
[error] { [Error: {"message":"Not Found","documentation_url":"https://developer.
github.com/v3/repos/contents/"}]
[error] message: '{"message":"Not Found","documentation_url":"https://develope
r.github.com/v3/repos/contents/"}',
[error] code: 404 } null vydingding

path should be the full relative path (including filename) and content should be the actual base 64 encoded contents of the file (https://www.base64encode.org/).

Here's a working example:

"use strict";

var Client = require("./../lib/index");
var testAuth = require("./../test_auth.json");

var github = new Client({
    debug: true
});

github.authenticate({
    type: "oauth",
    token: testAuth["token"]
});

github.repos.createFile({
    user: "kaizensoze",
    repo: "misc-scripts",
    path: "blah.txt",
    message: "blah blah",
    content: "YmxlZXAgYmxvb3A="
}, function(err, res) {
    console.log(err, res);
});

Is your intention to create a folder named master? If so, try

path: "master/hello.csv",
content: <base 64 encoded contents of hello.csv>

Otherwise, if you're referring to the branch, master is the default branch and doesn't need to be included.

Also keep in mind that even with those adjustments, it can still [misleadingly] return a 404 [instead of 403] if the repo is private and the auth method doesn't have access to private repos.

Thanks. It's working now. However, should the content always be base 64 or can it be text (strings) directly?

I think always base 64 but it'd be a quick test to try with a string.