-
Notifications
You must be signed in to change notification settings - Fork 511
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
setup GitHub repo automatically #955
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -82,13 +82,30 @@ def _render_nb(fn, cfg): | |
fn.write_text(txt) | ||
|
||
# %% ../nbs/09_API/12_cli.ipynb 11 | ||
def _update_repo_meta(cfg): | ||
"Enable gh pages and update the homepage and description in your GitHub repo." | ||
token=os.getenv('GITHUB_TOKEN') | ||
if token: | ||
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']) | ||
cmds.map(partial(run, ignore_ex=True)) | ||
api.enable_pages(branch='gh-pages') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If the repo is empty, we get a |
||
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. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We are able to update the homepage and description with ghapi! |
||
except HTTPError:print(f"Could not update the description & URL on the repo: {cfg.user}/{cfg.repo} using $GITHUB_TOKEN.\n" | ||
"Use a token with the correction permissions or perform these steps manually.") | ||
|
||
# %% ../nbs/09_API/12_cli.ipynb 12 | ||
@call_parse | ||
@delegates(nbdev_create_config) | ||
def nbdev_new(**kwargs): | ||
"Create an nbdev project." | ||
from ghapi.core import GhApi | ||
nbdev_create_config.__wrapped__(**kwargs) | ||
cfg = get_config() | ||
_update_repo_meta(cfg) | ||
|
||
path = Path() | ||
tag = GhApi().repos.get_latest_release('fastai', 'nbdev-template').tag_name | ||
|
@@ -108,7 +125,7 @@ def nbdev_new(**kwargs): | |
nbdev_export.__wrapped__() | ||
nbdev_readme.__wrapped__() | ||
|
||
# %% ../nbs/09_API/12_cli.ipynb 14 | ||
# %% ../nbs/09_API/12_cli.ipynb 15 | ||
@call_parse | ||
def chelp(): | ||
"Show help for all console scripts" | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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 plainfor
loop would be simpler and just as concise. Generallymap
is most useful for the situation where you want to return a list.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?