From 926418263362606916d403415f9afd8075e57543 Mon Sep 17 00:00:00 2001 From: Chun Ly Date: Tue, 29 Sep 2020 13:35:05 -0700 Subject: [PATCH] git_info: Add get_latest_commit function #57 Implement in all scripts --- requiam/get_branch_name.py | 12 ------------ requiam/git_info.py | 27 +++++++++++++++++++++++++++ scripts/add_grouper_groups | 9 ++++++--- scripts/get_org_code_numbers | 9 ++++++--- scripts/script_run | 9 ++++++--- scripts/user_update | 9 ++++++--- 6 files changed, 51 insertions(+), 24 deletions(-) delete mode 100644 requiam/get_branch_name.py create mode 100644 requiam/git_info.py diff --git a/requiam/get_branch_name.py b/requiam/get_branch_name.py deleted file mode 100644 index 135ff203..00000000 --- a/requiam/get_branch_name.py +++ /dev/null @@ -1,12 +0,0 @@ -from pathlib import Path - - -def get_active_branch_name(input_path="."): - - head_dir = Path(input_path) / ".git" / "HEAD" - with head_dir.open("r") as f: - content = f.read().splitlines() - - for line in content: - if line[0:4] == "ref:": - return line.partition("refs/heads/")[2] diff --git a/requiam/git_info.py b/requiam/git_info.py new file mode 100644 index 00000000..8feb11cf --- /dev/null +++ b/requiam/git_info.py @@ -0,0 +1,27 @@ +from pathlib import Path + + +def get_active_branch_name(input_path="."): + + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() + + for line in content: + if line[0:4] == "ref:": + return line.partition("refs/heads/")[2] + + +def get_latest_commit(input_path="."): + + head_dir = Path(input_path) / ".git" / "HEAD" + with head_dir.open("r") as f: + content = f.read().splitlines() + + for line in content: + if line[0:4] == "ref:": + head_path = Path(f".git/{line.partition(' ')[2]}") + with head_path.open('r') as g: + commit = g.read().splitlines() + + return commit[0], commit[0][:7] # full and short hash diff --git a/scripts/add_grouper_groups b/scripts/add_grouper_groups index cebf6130..7ca1e3c1 100644 --- a/scripts/add_grouper_groups +++ b/scripts/add_grouper_groups @@ -19,7 +19,7 @@ from requiam import TimerClass # Version and branch info from requiam import __version__ -from requiam.get_branch_name import get_active_branch_name +from requiam.git_info import get_active_branch_name, get_latest_commit from requiam import __file__ as library_path today = date.today() @@ -119,6 +119,7 @@ if __name__ == '__main__': args = parser.parse_args() branch_name = get_active_branch_name(library_root_path) + git_commit, git_short_commit = get_latest_commit(library_root_path) banner_message = f""" This is the command-line tool to create Grouper groups for main themes, sub-portals, and quotas. @@ -129,6 +130,7 @@ if __name__ == '__main__': ReQUIAM active branch: {branch_name} ReQUIAM version: {__version__} + ReQUIAM commit hash: {git_short_commit} Created by Chun Ly Issues/Suggestions? Submit a GitHub ticket: https://github.com/ualibraries/ReQUIAM/issues/new/choose """ @@ -151,8 +153,9 @@ if __name__ == '__main__': log.info("*************************************") log.info("Started add_grouper_group script ... ") - log.info(f"ReQUIAM active branch: {branch_name}") - log.info(f"ReQUIAM version: {__version__}") + log.debug(f"ReQUIAM active branch: {branch_name}") + log.debug(f"ReQUIAM version: {__version__} ({git_short_commit})") + log.debug(f"ReQUIAM commit hash: {git_commit}") cred_err = 0 vargs = vars(args) diff --git a/scripts/get_org_code_numbers b/scripts/get_org_code_numbers index e6c023d9..b7d4ad5f 100644 --- a/scripts/get_org_code_numbers +++ b/scripts/get_org_code_numbers @@ -18,7 +18,7 @@ from requiam import TimerClass # Version and branch info from requiam import __version__ -from requiam.get_branch_name import get_active_branch_name +from requiam.git_info import get_active_branch_name, get_latest_commit from requiam import __file__ as library_path today = date.today() @@ -39,6 +39,7 @@ if __name__ == '__main__': args = parser.parse_args() branch_name = get_active_branch_name(library_root_path) + git_commit, git_short_commit = get_latest_commit(library_root_path) banner_message = f""" This is the command-line tool that queries EDS to retrieve UAL patron @@ -46,6 +47,7 @@ if __name__ == '__main__': ReQUIAM active branch: {branch_name} ReQUIAM version: {__version__} + ReQUIAM commit hash: {git_short_commit} Created by Chun Ly Issues? Submit a GitHub ticket: https://github.com/ualibraries/ReQUIAM/issues/new """ @@ -68,8 +70,9 @@ if __name__ == '__main__': log.info("****************************************") log.info("Started get_org_code_numbers script ... ") - log.info(f"ReQUIAM active branch: {branch_name}") - log.info(f"ReQUIAM version: {__version__}") + log.debug(f"ReQUIAM active branch: {branch_name}") + log.debug(f"ReQUIAM version: {__version__} ({git_short_commit})") + log.debug(f"ReQUIAM commit hash: {git_commit}") cred_err = 0 vargs = vars(args) diff --git a/scripts/script_run b/scripts/script_run index 0185c0f7..1b3e7908 100644 --- a/scripts/script_run +++ b/scripts/script_run @@ -22,7 +22,7 @@ from requiam import manual_override # Version and branch info from requiam import __version__ -from requiam.get_branch_name import get_active_branch_name +from requiam.git_info import get_active_branch_name, get_latest_commit from requiam import __file__ as library_path today = date.today() @@ -58,6 +58,7 @@ if __name__ == '__main__': args = parser.parse_args() branch_name = get_active_branch_name(library_root_path) + git_commit, git_short_commit = get_latest_commit(library_root_path) banner_message = f""" This is the command-line tool that automates Grouper patron management. @@ -67,6 +68,7 @@ if __name__ == '__main__': ReQUIAM active branch: {branch_name} ReQUIAM version: {__version__} + ReQUIAM commit hash: {git_short_commit} Created by Chun Ly Issues? Submit a GitHub ticket: https://github.com/ualibraries/ReQUIAM/issues/new """ @@ -90,8 +92,9 @@ if __name__ == '__main__': log.info("******************************") log.info("Started script_run script ... ") - log.info(f"ReQUIAM active branch: {branch_name}") - log.info(f"ReQUIAM version: {__version__}") + log.debug(f"ReQUIAM active branch: {branch_name}") + log.debug(f"ReQUIAM version: {__version__} ({git_short_commit})") + log.debug(f"ReQUIAM commit hash: {git_commit}") cred_err = 0 vargs = vars(args) diff --git a/scripts/user_update b/scripts/user_update index d1a9b36c..33eb098e 100644 --- a/scripts/user_update +++ b/scripts/user_update @@ -17,7 +17,7 @@ from requiam.grouper_admin import GrouperAPI # Version and branch info from requiam import __version__ -from requiam.get_branch_name import get_active_branch_name +from requiam.git_info import get_active_branch_name, get_latest_commit from requiam import __file__ as library_path today = date.today() @@ -55,12 +55,14 @@ if __name__ == '__main__': args = parser.parse_args() branch_name = get_active_branch_name(library_root_path) + git_commit, git_short_commit = get_latest_commit(library_root_path) banner_message = f""" This is the command-line tool that enable manual updates to Grouper membership. ReQUIAM active branch: {branch_name} ReQUIAM version: {__version__} + ReQUIAM commit hash: {git_short_commit} Created by Chun Ly Issues? Submit a GitHub ticket: https://github.com/ualibraries/ReQUIAM/issues/new """ @@ -83,8 +85,9 @@ if __name__ == '__main__': log.info("*******************************") log.info("Started user_update script ... ") - log.info(f"ReQUIAM active branch: {branch_name}") - log.info(f"ReQUIAM version: {__version__}") + log.debug(f"ReQUIAM active branch: {branch_name}") + log.debug(f"ReQUIAM version: {__version__} ({git_short_commit})") + log.debug(f"ReQUIAM commit hash: {git_commit}") cred_err = 0 vargs = vars(args)