From 3da14d6bfe40cc97d330e1f334719fe1bd25851b Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Mon, 13 Dec 2021 11:09:57 -0500 Subject: [PATCH 1/8] update cli template script to take commit msg as string --- abcclassroom/__main__.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/abcclassroom/__main__.py b/abcclassroom/__main__.py index b08aa42..4aed2c9 100644 --- a/abcclassroom/__main__.py +++ b/abcclassroom/__main__.py @@ -129,11 +129,10 @@ def new_template(): course_materials/release directory""", ) parser.add_argument( - "--custom-message", - action="store_true", - help="""Use a custom commit message for git. Will open the default - git text editor for entry (if not set, uses default message 'Initial - commit').""", + "--commit-message", + # action="store_true", + help="""Enter a commit message for git. If not set, uses default + message 'Initial commit').""", ) parser.add_argument( "--github", @@ -213,9 +212,14 @@ def update_template(): directory); merge = overwrite existing files add new files (Default = merge).""", ) + parser.add_argument( + "--commit-message", + # action="store_true", + help="""Enter a commit message for git. If not set, uses default + message 'Updating assignment').""", + ) args = parser.parse_args() # now set the additional args (so that it matches the keys in add_template # and we can use the same implementation methods) setattr(args, "github", True) - setattr(args, "custom_message", True) template.new_update_template(args) From 639029d2176935333d6cb7dbf22126a404c80ba2 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Mon, 13 Dec 2021 11:11:46 -0500 Subject: [PATCH 2/8] init_and_commit requires commit message, do not open editor --- abcclassroom/git.py | 29 ++--------------------------- 1 file changed, 2 insertions(+), 27 deletions(-) diff --git a/abcclassroom/git.py b/abcclassroom/git.py index 3d224f6..408ccb8 100644 --- a/abcclassroom/git.py +++ b/abcclassroom/git.py @@ -7,9 +7,6 @@ # methods that involve the GitHub API import subprocess -import sys - -from .utils import input_editor def check_git_ssh(): @@ -120,22 +117,6 @@ def repo_changed(directory): return bool(ret.stdout) -def get_commit_message(): - default_message = """ - # Please enter the commit message for your changes. Lines starting - # with '#' will be ignored, and an empty message aborts the commit. - # This message will be used as commit and Pull Request message.""" - message = input_editor(default_message) - message = "\n".join( - [ - line - for line in message.split("\n") - if not line.strip().startswith("#") - ] - ) - return message - - def commit_all_changes(directory, msg=None): """Run git add, git commit on a given directory. Checks git status first and does nothing if no changes. @@ -149,7 +130,7 @@ def commit_all_changes(directory, msg=None): print("No changes in repository {}; doing nothing".format(directory)) -def init_and_commit(directory, custom_message=False): +def init_and_commit(directory, commit_message): """Run git init, git add, git commit on given directory. Checks git status first and does nothing if no changes. """ @@ -159,13 +140,7 @@ def init_and_commit(directory, custom_message=False): git_init(directory) _master_branch_to_main(directory) if repo_changed(directory): - message = "Initial commit" - if custom_message: - message = get_commit_message() - if not message: - print("Empty commit message, exiting.") - sys.exit(1) # sys is undefined - ask karen about this - commit_all_changes(directory, message) + commit_all_changes(directory, commit_message) else: print("No changes to local repository.") From 2af95832926e86207530975b074995dce8f264f9 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Mon, 13 Dec 2021 11:13:01 -0500 Subject: [PATCH 3/8] take commit msg as argument, diff defaults for add and update --- abcclassroom/template.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/abcclassroom/template.py b/abcclassroom/template.py index 56a8885..9eafe4f 100644 --- a/abcclassroom/template.py +++ b/abcclassroom/template.py @@ -34,7 +34,7 @@ def new_update_template(args): create_template( mode=args.mode, push_to_github=args.github, - custom_message=args.custom_message, + commit_message=args.commit_message, assignment_name=args.assignment, ) except FileNotFoundError as fnfe: @@ -46,7 +46,10 @@ def new_update_template(args): def create_template( - assignment_name, mode="fail", push_to_github=False, custom_message=False + assignment_name, + mode="fail", + push_to_github=False, + commit_message="Initial commit", ): """ Classroom package function that creates or updates an assignment template @@ -70,8 +73,10 @@ def create_template( push_to_github : boolean True if you want to push to GH mode : merge, fail - custom message : boolean (default = False) - True if you want to push to github. + commit_message : string + Sets a custom git commit message. For new templates, default is + "Initial commit" and for updating templates, default is + "Updating assignment" assignment_name : string name of the assignment """ @@ -112,7 +117,7 @@ def create_template( ) # Create the local git repository and commit changes - abcgit.init_and_commit(template_repo_path, custom_message) + abcgit.init_and_commit(template_repo_path, commit_message) # Create / append assignment entry in config - this should only happen if # the assignment above exists... From 616c51fe95582f1316a43bd445b5c161ef95c796 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Mon, 13 Dec 2021 11:13:42 -0500 Subject: [PATCH 4/8] update tests for changes in commit message handling --- .../tests/test_assignment_template.py | 35 +++++++++++++++---- abcclassroom/tests/test_git.py | 3 +- 2 files changed, 30 insertions(+), 8 deletions(-) diff --git a/abcclassroom/tests/test_assignment_template.py b/abcclassroom/tests/test_assignment_template.py index b49681c..665f4ca 100644 --- a/abcclassroom/tests/test_assignment_template.py +++ b/abcclassroom/tests/test_assignment_template.py @@ -20,9 +20,7 @@ def test_create_template(course_structure_assignment): course_dir = Path(config["course_directory"]) templates_dir = Path(config["template_dir"]) - abctemplate.create_template( - assignment_name, push_to_github=False, custom_message=False - ) + abctemplate.create_template(assignment_name, push_to_github=False) expected_template_dir = Path( course_dir, templates_dir, "{}-template".format(assignment_name) @@ -40,9 +38,32 @@ def test_create_template_no_assignment(sample_course_structure): with pytest.raises( FileNotFoundError, match="Oops, it looks like the assignment" ): - abctemplate.create_template( - "assignment_test", push_to_github=False, custom_message=False - ) + abctemplate.create_template("assignment_test", push_to_github=False) + + +def test_create_custom_commit_message(course_structure_assignment): + """ + Test that top-level create_template uses a custom commit message + if provided. + """ + config, assignment_name, release_path = course_structure_assignment + course_dir = Path(config["course_directory"]) + templates_dir = Path(config["template_dir"]) + + abctemplate.create_template( + assignment_name, + mode="delete", + push_to_github=False, + commit_message="Custom commit message", + ) + + expected_template_dir = Path( + course_dir, templates_dir, "{}-template".format(assignment_name) + ) + assert expected_template_dir.exists() + + git_return = abcgit._call_git("log", directory=expected_template_dir) + assert "Custom commit" in git_return.stdout def test_create_template_dir(course_structure_assignment): @@ -132,7 +153,7 @@ def test_create_template_dir_move_git_dir(course_structure_assignment): # create a file in the template dir, init a git repo and commit testfile = Path(template_path, "file1.txt") testfile.touch() - abcgit.init_and_commit(template_path, False) + abcgit.init_and_commit(template_path, "commit message") assert Path(template_path, ".git").exists() template_path = abctemplate.create_template_dir( diff --git a/abcclassroom/tests/test_git.py b/abcclassroom/tests/test_git.py index 023dd14..93053e6 100644 --- a/abcclassroom/tests/test_git.py +++ b/abcclassroom/tests/test_git.py @@ -13,7 +13,8 @@ def test_init_and_commit(default_config, tmp_path): repo_dir.mkdir() a_file = Path(repo_dir, "testfile.txt") a_file.write_text("Some text") - abcgit.init_and_commit(repo_dir) + commit_message = "changing some things" + abcgit.init_and_commit(repo_dir, commit_message) assert Path(repo_dir, ".git").exists() git_return = abcgit._call_git("log", directory=repo_dir) assert git_return.stdout.startswith("commit") From 68d41ca066f1f2d41f6924c69e104e08593b3326 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Mon, 13 Dec 2021 11:15:10 -0500 Subject: [PATCH 5/8] update changelog --- CHANGELOG.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.rst b/CHANGELOG.rst index 7ca6874..6b1c8fd 100644 --- a/CHANGELOG.rst +++ b/CHANGELOG.rst @@ -8,6 +8,7 @@ The format is based on `Keep a Changelog ` [unreleased] ------------ +- Rather than opening text editor for commit message, allow user to provide custom message as command line arg; changes name of command line arg to 'commit_message' from 'custom_message' (@kcranston, #466) - Remove old unused code from before the big redirection (@kcranston, #449, #465) - Reoganize github module into smaller chunks (@kcranston, #447) - Check for working ssh keys before git commands that connect to github (@kcranston, #366) From 0f96bcbda9dab2554b5971d1887cf731cc6d03de Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Wed, 9 Feb 2022 20:08:10 -0500 Subject: [PATCH 6/8] add default commit messages to template scripts --- abcclassroom/__main__.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/abcclassroom/__main__.py b/abcclassroom/__main__.py index 943c275..9c3fdbf 100644 --- a/abcclassroom/__main__.py +++ b/abcclassroom/__main__.py @@ -137,7 +137,7 @@ def new_template(): ) parser.add_argument( "--commit-message", - # action="store_true", + default="Initial commit", help="""Enter a commit message for git. If not set, uses default message 'Initial commit').""", ) @@ -158,7 +158,6 @@ def new_template(): (Default = fail).""", ) args = parser.parse_args() - template.new_update_template(args) @@ -221,7 +220,7 @@ def update_template(): ) parser.add_argument( "--commit-message", - # action="store_true", + default="Updating assignment", help="""Enter a commit message for git. If not set, uses default message 'Updating assignment').""", ) From f05441d4a37cfcbd3b08416506b9e58ed57f0922 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Wed, 9 Feb 2022 20:09:28 -0500 Subject: [PATCH 7/8] minor typo in error message --- abcclassroom/template.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/abcclassroom/template.py b/abcclassroom/template.py index 9eafe4f..35978aa 100644 --- a/abcclassroom/template.py +++ b/abcclassroom/template.py @@ -102,7 +102,7 @@ def create_template( except FileNotFoundError as e: print(e) raise FileNotFoundError( - "Oops, it looks like the assignment - {} - does not exist" + "Oops, it looks like the assignment - {} - does not exist " "in the location that I expected it: \n{}. \nDid " "you spell the assignment name correctly and is there a " "directory at this path?".format(assignment_name, release_path) From fac61965bbf73990fe22d0e7dd4142b6bb758e00 Mon Sep 17 00:00:00 2001 From: Karen Cranston Date: Wed, 9 Feb 2022 20:18:57 -0500 Subject: [PATCH 8/8] updating docs for git commit messages --- docs/api/abcclassroom.auth.rst | 4 ++++ docs/api/abcclassroom.git.rst | 4 ++++ docs/api/abcclassroom.rst | 2 ++ docs/manage-assignments/new_assignment.rst | 25 +++++++--------------- 4 files changed, 18 insertions(+), 17 deletions(-) create mode 100644 docs/api/abcclassroom.auth.rst create mode 100644 docs/api/abcclassroom.git.rst diff --git a/docs/api/abcclassroom.auth.rst b/docs/api/abcclassroom.auth.rst new file mode 100644 index 0000000..1da142c --- /dev/null +++ b/docs/api/abcclassroom.auth.rst @@ -0,0 +1,4 @@ +.. automodule:: abcclassroom.auth + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/abcclassroom.git.rst b/docs/api/abcclassroom.git.rst new file mode 100644 index 0000000..3e199a9 --- /dev/null +++ b/docs/api/abcclassroom.git.rst @@ -0,0 +1,4 @@ +.. automodule:: abcclassroom.git + :members: + :undoc-members: + :show-inheritance: diff --git a/docs/api/abcclassroom.rst b/docs/api/abcclassroom.rst index b9b9909..97724cc 100644 --- a/docs/api/abcclassroom.rst +++ b/docs/api/abcclassroom.rst @@ -12,9 +12,11 @@ Submodules .. toctree:: :maxdepth: 4 + abcclassroom.auth abcclassroom.clone abcclassroom.config abcclassroom.feedback + abcclassroom.git abcclassroom.github abcclassroom.quickstart abcclassroom.roster diff --git a/docs/manage-assignments/new_assignment.rst b/docs/manage-assignments/new_assignment.rst index be205e5..fc6fce7 100644 --- a/docs/manage-assignments/new_assignment.rst +++ b/docs/manage-assignments/new_assignment.rst @@ -113,23 +113,13 @@ A few notes about how this works: Text Editors and Git Commit Messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The default commit message used when you run -``abc-new-template `` is **initial commit**. A text editor -will not open in this case. +``abc-new-template `` is "Initial commit". For +``abc-update-template`` the default message is "Updating assignment". -When you run ``abc-update-template`` the text editor that is specified in your -system configuration settings will open up. If you do not have a text editor -specified, VIM will open as a default. +If you want to provide a custom commit message, use the ``--commit-message`` +flag with either script, and provide a message after the flag, e.g.:: -If you wish to use nano instead you can run the following in your terminal:: - - export EDITOR=nano - -.. note:: - Right now if you try to use an editor like atom that launches outside of the - terminal, abc-classroom will currently fail and return a message saying - **empty commit message** . This may be fixed in the future but for now we - suggest that you use a terminal based editor for your default when using - abc-classroom. + abc-update-template assignment1 --commit-message "adding new notebook" @@ -153,8 +143,7 @@ Run ``abc-new-template -h`` to see the options. The output is reproduced below:: optional arguments: -h, --help show this help message and exit - --custom-message Use a custom commit message for git. Will open the - default git text editor for entry (if not set, uses + --commit-message Provide a custom commit message for git (if not set, uses default message 'Initial commit'). --github Also perform the GitHub operations (create remote repo on GitHub and push to remote (by default, only does @@ -201,6 +190,8 @@ is reproduced here:: optional arguments: -h, --help show this help message and exit + --commit-message Provide a custom commit message for git (if not set, uses + default message 'Updating assignment'). --mode {delete,merge} What to do with existing contents of template directory. Choices are: delete = remove contents