0

Since Github API didn't support get the branch contains commit (SHA) yet. So I found we can get the branch if we can parse HTML from URL https://github.com/:org/:repo/branch_commits/:sha. But currently, I can't connect to this URL (for a private repo) even though I have the credentials

        const url = `https://github.com/${org}/${repo}/branch_commits/${hash}`;
        const options = {
            method: 'GET',
            uri: url,
            headers: {
                "Authorization": token,
            }
        };
        request(options).then(result => {
            console.log(result);
        }).catch(err => {
            console.log(err);
        });

The result is 404 Not Found. Does anyone have an idea here?

Thanks!!

Iris Louis
  • 297
  • 6
  • 19

1 Answers1

0

You cannot use a personal access token to access the web interface. Moreover, you should not try to programmatically access the web interface, since that could break at any time, and it also makes you very likely to get blocked by automatic tooling.

Instead, you can use a personal access token to access the API, and search the history via the List Commits API to see if the commit you want is in the history. However, even this is very inefficient, and to answer your question, the most efficient way is to clone the repository and perform your queries there. You could perform a partial clone with the --filter=tree:0 flag to get only commits, which would be much cheaper than a normal clone.

bk2204
  • 64,793
  • 6
  • 84
  • 100
  • Yes, I thought about it too but for now, our application is checking on 5 repositories. I'm testing the performance of this one https://stackoverflow.com/questions/23899329/list-of-branches-a-commit-appears-on/23970412#23970412. Anyway, thank you for your answer. I will try with partial clone if the performance of "compare solution" is not good! – Iris Louis Sep 20 '21 at 01:48