diff --git a/README.md b/README.md index 63b4979..b1095a3 100644 --- a/README.md +++ b/README.md @@ -14,16 +14,19 @@ You can currently install this directly from git: ``` pip install git+https://github.com/sat28/githubcommit.git jupyter serverextension enable --py githubcommit -jupyter nbextension install --py githubcommit +jupyter nbextension install --py githubcommit --user ``` To enable this extension for all notebooks: ``` -jupyter nbextension enable --py githubcommit +jupyter nbextension enable githubcommit --user --py ``` ## Steps +I have made this short video in which I install the extension from scratch (click on the image)- + +[![Watch the video](https://i.ibb.co/7bk1bJ2/Webp-net-resizeimage.png)](https://www.youtube.com/watch?v=1XPSK1mxfgQ) * Install package using above commands * Create Git repo where notebooks will be pushed if not already exists and clone it in your `GIT_PARENT_DIR` diff --git a/env.sh b/env.sh index 7736e83..108f3d8 100644 --- a/env.sh +++ b/env.sh @@ -1,5 +1,5 @@ ####################### SSH KEY FOR GIT ################################### -ssh-keygen -t rsa && ssh-keygen -y -f ~/.ssh/id_rsa > ~/.ssh/id_rsa.pub && eval `ssh-agent -s` && ssh-add -k +eval `ssh-agent -s` && ssh-add -k ####################### To be added to git account settings ################ diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index c493b08..13228df 100644 --- a/githubcommit/handlers.py +++ b/githubcommit/handlers.py @@ -3,6 +3,7 @@ import os, json, git, urllib, requests from git import Repo, GitCommandError from subprocess import check_output +import subprocess class GitCommitHandler(IPythonHandler): @@ -32,6 +33,8 @@ def put(self): data = json.loads(self.request.body.decode('utf-8')) filename = urllib.parse.unquote(data['filename']) msg = data['msg'] + commit_only_source = data['commit_only_source'] + # get current directory (to return later) cwd = os.getcwd() @@ -54,8 +57,15 @@ def put(self): # commit current notebook # client will sent pathname containing git directory; append to git directory's parent try: - print(repo.git.add(str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename))) - print(repo.git.commit( a=True, m="{}\n\nUpdated {}".format(msg, filename) )) + if commit_only_source : + subprocess.run(['jupyter', 'nbconvert', '--to', 'script', str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename)]) + filename = str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename.replace('ipynb', 'py')) + else: + filename = str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename) + + print(repo.git.add(filename)) + print(repo.git.commit( a=False, m="{}\n\nUpdated {}".format(msg, filename) )) + except GitCommandError as e: print(e) self.error_and_return(cwd, "Could not commit changes to notebook: {}".format(git_dir_parent + filename)) diff --git a/githubcommit/static/main.js b/githubcommit/static/main.js index e5f25b4..23ce7d7 100644 --- a/githubcommit/static/main.js +++ b/githubcommit/static/main.js @@ -13,6 +13,9 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog, var input = $('') var div = $('
') + var checkbox = '' + + div.append(checkbox) div.append(p) .append(input) @@ -24,7 +27,8 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog, var filepath = window.location.pathname.match(re)[1]; var payload = { 'filename': filepath, - 'msg': input.val() + 'msg': input.val(), + 'commit_only_source': $("#commit_only_source").prop('checked') }; var settings = { url : '/git/commit', @@ -83,6 +87,7 @@ define(['base/js/namespace','base/js/dialog','jquery'],function(IPython, dialog, notebook:env.notebook, keyboard_manager: env.notebook.keyboard_manager, }) + } }