From fe17e7e765983477cdf3cf3572426c98f490e54b Mon Sep 17 00:00:00 2001 From: matthieu-pa Date: Thu, 5 Apr 2018 18:02:38 +0900 Subject: [PATCH 1/9] GIT_PARENT_DIR fix --- README.md | 4 ++-- env.sh | 4 ++-- githubcommit/handlers.py | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 4ad0747..63b4979 100644 --- a/README.md +++ b/README.md @@ -26,8 +26,8 @@ jupyter nbextension enable --py githubcommit ## Steps * Install package using above commands -* Create Git repo where notebooks will be pushed if not already exists and clone it in home directory -* Clone this repo as well in home directory +* Create Git repo where notebooks will be pushed if not already exists and clone it in your `GIT_PARENT_DIR` +* Clone this repo as well in your `GIT_PARENT_DIR` directory * Replace the values in env.sh present in this repo itself * Run the command - source ~/githubcommit/env.sh * Configure ssh key (present in ~/.ssh/id_rsa.pub or specified location) in github account diff --git a/env.sh b/env.sh index 497dea7..7736e83 100644 --- a/env.sh +++ b/env.sh @@ -23,7 +23,7 @@ export GIT_REMOTE_UPSTREAM=$GIT_USER_UPSTREAM/$GIT_REPO_NAME ####################### Git Repo where notebooks will be pushed ############ -cd ~ && git clone $GIT_REMOTE_URL_HTTPS +cd $GIT_PARENT_DIR && git clone $GIT_REMOTE_URL_HTTPS @@ -34,4 +34,4 @@ fi echo 'c.NotebookApp.disable_check_xsrf = True' >> ~/.jupyter/jupyter_notebook_config.py -cp ~/githubcommit/config ~/.ssh/config \ No newline at end of file +cp $GIT_PARENT_DIR/githubcommit/config ~/.ssh/config diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index b84d0d3..c493b08 100644 --- a/githubcommit/handlers.py +++ b/githubcommit/handlers.py @@ -54,7 +54,7 @@ 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.path.expanduser('~') + "/" + os.environ.get('GIT_REPO_NAME') + filename))) + 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) )) except GitCommandError as e: print(e) From 35a9627b01113cade698fc9b8444539feef4d532 Mon Sep 17 00:00:00 2001 From: mita Date: Sat, 3 Nov 2018 11:47:31 +0900 Subject: [PATCH 2/9] convert commit file from .ipynb to .py To commit only source code, convert .ipynb to .py --- githubcommit/handlers.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index c493b08..c61e2ed 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): @@ -54,8 +55,9 @@ 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) )) + subprocess.run(['jupyter', 'nbconvert', '--to', 'script', str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename)]) + print(repo.git.add(str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename.replace('ipynb', 'py')))) + print(repo.git.commit( a=True, m="{}\n\nUpdated {}".format(msg, filename.replace('ipynb', 'py')))) except GitCommandError as e: print(e) self.error_and_return(cwd, "Could not commit changes to notebook: {}".format(git_dir_parent + filename)) From 13323e758dc6b5b10ff9e377b3be6d48c5a0cff9 Mon Sep 17 00:00:00 2001 From: mita Date: Sat, 3 Nov 2018 11:51:32 +0900 Subject: [PATCH 3/9] Don't override exsisting ssh key pair --- env.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ################ From 15e03e852f4a735019fe1fd243610bf52166971e Mon Sep 17 00:00:00 2001 From: mita Date: Sat, 3 Nov 2018 21:40:31 +0900 Subject: [PATCH 4/9] make commit file selectable by checkbox user will be able to select whether commit ipynb or source only --- githubcommit/handlers.py | 12 +++++++++--- githubcommit/static/main.js | 7 ++++++- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index c61e2ed..e88f285 100644 --- a/githubcommit/handlers.py +++ b/githubcommit/handlers.py @@ -33,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() @@ -55,9 +57,13 @@ def put(self): # commit current notebook # client will sent pathname containing git directory; append to git directory's parent try: - subprocess.run(['jupyter', 'nbconvert', '--to', 'script', str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename)]) - print(repo.git.add(str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + filename.replace('ipynb', 'py')))) - print(repo.git.commit( a=True, m="{}\n\nUpdated {}".format(msg, filename.replace('ipynb', 'py')))) + 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')) + + print(repo.git.add(str(os.environ.get('GIT_PARENT_DIR') + "/" + os.environ.get('GIT_REPO_NAME') + 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, }) + } } From 26c7f8fbe075ca6a1c6fca27f260342986638a97 Mon Sep 17 00:00:00 2001 From: sachin235 Date: Wed, 3 Jun 2020 11:01:24 +0530 Subject: [PATCH 5/9] Update Readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 63b4979..15b25bc 100644 --- a/README.md +++ b/README.md @@ -14,13 +14,13 @@ 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 From 1718b2ed78c97a8542084dc48b53550ddcd60b9d Mon Sep 17 00:00:00 2001 From: Shaleen Date: Tue, 22 Sep 2020 22:52:32 +0530 Subject: [PATCH 6/9] Fixed filename bug --- githubcommit/handlers.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index e88f285..2867cf6 100644 --- a/githubcommit/handlers.py +++ b/githubcommit/handlers.py @@ -61,7 +61,7 @@ def put(self): 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')) - print(repo.git.add(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: From f0091e6b06ff753ba40f14fa97c8ba17d2326466 Mon Sep 17 00:00:00 2001 From: Shaleen Date: Tue, 22 Sep 2020 23:15:03 +0530 Subject: [PATCH 7/9] Corrected filename when commit to source not selected. --- githubcommit/handlers.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/githubcommit/handlers.py b/githubcommit/handlers.py index 2867cf6..13228df 100644 --- a/githubcommit/handlers.py +++ b/githubcommit/handlers.py @@ -60,7 +60,9 @@ def put(self): 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) )) From 7c80d94f5f1f5d9ec4ec2634031d4d7e65896a0f Mon Sep 17 00:00:00 2001 From: Shaleen Date: Wed, 23 Sep 2020 20:23:18 +0530 Subject: [PATCH 8/9] Added the installation video link in readme --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 15b25bc..06bed06 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,9 @@ 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://youtu.be/vKx_4zFvOi8) * 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` From 12d1dcba808d68148a6232bbbe202d4a327d3ce1 Mon Sep 17 00:00:00 2001 From: Shaleen Anand Taneja Date: Sat, 24 Jul 2021 18:12:55 +0530 Subject: [PATCH 9/9] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 06bed06..b1095a3 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ 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://youtu.be/vKx_4zFvOi8) +[![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`