octonode icon indicating copy to clipboard operation
octonode copied to clipboard

createReference syntax and example is misleading

Open richsong opened this issue 5 years ago • 1 comments

This should be an easy fix and I think it could be helpful for user looking to create a new branch.

createReference is passed three arguments: ghrepo.createReference('master', '18293abcd72', callback);

The first argument should be the new branch name. The second argument should be the SHA-1 hash value of the commit to branch off.

A better example would be as follows:

    // get the latest commit
    ghrepo.commits((err, status, body, headers) => {
        if (err) { console.log('err', err) }
        if (status) {
            // for some reason status is an array of object that contains our commits.
            // status[0] is the latest commit and we pass it to createReference
            ghrepo.createReference('newBranchName', status[0].sha, (err, status, body, headers) => {
                // do your stuff here
            });
        }
    });

I was also inspecting the definition of createReference on line 340 for repo.js and it looks correct! In my personal opinion, the example within the documentation is slightly misleading. I had to dive into the definition and source other examples to get a better understanding.

If you approve, I could create a PR for this.

richsong avatar Nov 04 '19 22:11 richsong

Sure, go ahead.

pksunkara avatar Nov 05 '19 21:11 pksunkara