Skip to content

Commit

Permalink
git_info: Add get_latest_commit function #57
Browse files Browse the repository at this point in the history
Implement in all scripts
  • Loading branch information
astrochun committed Sep 29, 2020
1 parent ccde086 commit 9264182
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 24 deletions.
12 changes: 0 additions & 12 deletions requiam/get_branch_name.py

This file was deleted.

27 changes: 27 additions & 0 deletions requiam/git_info.py
Original file line number Diff line number Diff line change
@@ -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
9 changes: 6 additions & 3 deletions scripts/add_grouper_groups
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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
"""
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions scripts/get_org_code_numbers
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -39,13 +39,15 @@ 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
membership based on organization codes.

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
"""
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions scripts/script_run
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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.
Expand All @@ -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
"""
Expand All @@ -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)
Expand Down
9 changes: 6 additions & 3 deletions scripts/user_update
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
"""
Expand All @@ -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)
Expand Down

0 comments on commit 9264182

Please sign in to comment.