setup GitHub repo automatically#955
Conversation
|
Check out this pull request on See visual diffs & provide feedback on Jupyter Notebooks. Powered by ReviewNB |
| from ghapi.core import GhApi | ||
| api = GhApi(owner=cfg.user, repo=cfg.repo, token=token) | ||
| try: # repo needs something in it before you can enable pages | ||
| cmds = L(['git add settings.ini', "git commit -m'add settings'", 'git config push.default current', 'git push']) |
There was a problem hiding this comment.
When you are first initializing a github repo, it cannot be empty before you enable pages. It has to contain at least one file. I don't love executing git commands on behalf of the user. Another alternative would be to commit an empty file, but that clutters the repo IMO.
Curious on what your opinions are here. I put this in its own try block because I suspect something could go wrong here and I don't want to disrupt the onboarding process.
There was a problem hiding this comment.
I think it's fine - whether we exec git for the user vs use ghapi for the user seems much the same afaict.
FYI I don't think map here is useful -- seems a plain for loop would be simpler and just as concise. Generally map is most useful for the situation where you want to return a list.
There was a problem hiding this comment.
At least until we release it, perhaps best not to have the try, so we can find out if there are errors, and if so, what errors come up?
| cmds.map(partial(run, ignore_ex=True)) | ||
| api.enable_pages(branch='gh-pages') | ||
| except HTTPError: print("Could not enable GitHub Pages automatically.") | ||
| try: api.repos.update(homepage=f'{cfg.doc_host}/{cfg.doc_baseurl}', description=cfg.description) |
There was a problem hiding this comment.
We are able to update the homepage and description with ghapi!
| try: # repo needs something in it before you can enable pages | ||
| cmds = L(['git add settings.ini', "git commit -m'add settings'", 'git config push.default current', 'git push']) | ||
| cmds.map(partial(run, ignore_ex=True)) | ||
| api.enable_pages(branch='gh-pages') |
There was a problem hiding this comment.
If the repo is empty, we get a 403 error: conflict if trying to enable pages. Depending on how you create your repo before initialiing nbdev this is problematic. This is why the git commit step exists above.
Enhancements Added
gh-pagesbranch (some slighly hacky things are required to make this happen see below comments).How this was tested
Creating a repo with the gh cli
gh repo create ntest --clone --public && cd ntest && nbdev_newnbdev_newagainnbdev_newagainCreating a repo with the Github web interface
nbdev_newIn each case, I verified that the description, url were updated and that pages are properly enabled.
cc: @jph00 @seeM