Refactored code in terms of subprocess for git functionality.
This commit is contained in:
@ -105,7 +105,7 @@ def first_initialize_metadata_review(hdf5_file_path, reviewer_attrs):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
def second_submit_metadata_review(filename_path, reviewer_attrs):
|
def second_submit_metadata_review(review_yaml_file_path, reviewer_attrs):
|
||||||
"""
|
"""
|
||||||
Once you're done reviewing the yaml representation of hdf5 file in review folder.
|
Once you're done reviewing the yaml representation of hdf5 file in review folder.
|
||||||
Change the review status to complete and save (add and commit) modified .yalm and .txt files in the project by
|
Change the review status to complete and save (add and commit) modified .yalm and .txt files in the project by
|
||||||
@ -118,29 +118,63 @@ def second_submit_metadata_review(filename_path, reviewer_attrs):
|
|||||||
|
|
||||||
initials = reviewer_attrs['initials']
|
initials = reviewer_attrs['initials']
|
||||||
branch_name = '-'.join([reviewer_attrs['type'],'review','by',initials])
|
branch_name = '-'.join([reviewer_attrs['type'],'review','by',initials])
|
||||||
|
|
||||||
if any([status in get_review_status(filename_path) for status in ['under review','submitted']]):
|
|
||||||
filename_path_tail, filename_path_head = os.path.split(filename_path)
|
|
||||||
filename, ext = os.path.splitext(filename_path_head)
|
|
||||||
# TODO:
|
|
||||||
with open(os.path.join("review/",filename+"-review_status"+TXT_EXT),'a') as f:
|
|
||||||
f.write('\nsubmitted')
|
|
||||||
|
|
||||||
# TODO: replace with subprocess + git
|
# TODO: replace with subprocess + git
|
||||||
checkout_review_branch(repo_obj, branch_name)
|
checkout_review_branch(repo_obj, branch_name)
|
||||||
|
|
||||||
status_dict = repo_obj.status()
|
|
||||||
for filepath, file_status in status_dict.items():
|
|
||||||
# Identify keys associated to review files and stage them
|
|
||||||
if ('review/'+filename in filepath) and (file_status == pygit.GIT_STATUS_WT_MODIFIED):
|
|
||||||
# Stage changes
|
|
||||||
repo_obj.index.add(filepath)
|
|
||||||
|
|
||||||
author = config_file.author #default_signature
|
#if any([status in get_review_status(filename_path) for status in ['under review','submitted']]):
|
||||||
committer = config_file.committer
|
# filename_path_tail, filename_path_head = os.path.split(filename_path)
|
||||||
message = "Submitted metadata review."
|
# filename, ext = os.path.splitext(filename_path_head)
|
||||||
tree = repo_obj.index.write_tree()
|
# # TODO:
|
||||||
oid = repo_obj.create_commit('HEAD', author, committer, message, tree, [repo_obj.head.peel().oid])
|
|
||||||
|
|
||||||
|
##
|
||||||
|
status_command = ['git','status']
|
||||||
|
add_command = lambda add_list: ['git','add'] + add_list
|
||||||
|
commit_command = lambda message: ['git','commit','-m', message]
|
||||||
|
#push_command = lambda repository,refspec: ['git','push',repository,refspec]
|
||||||
|
|
||||||
|
status = subprocess.run(status_command,capture_output=True,check=True)
|
||||||
|
|
||||||
|
files_to_add_list = []
|
||||||
|
for line in status.stdout.splitlines():
|
||||||
|
# conver line from bytes to str
|
||||||
|
tmp = line.decode("utf-8")
|
||||||
|
if 'modified' in tmp and review_yaml_file_path in tmp:
|
||||||
|
files_to_add_list.append(tmp.split()[1])
|
||||||
|
##
|
||||||
|
|
||||||
|
review_yaml_file_path_tail, review_yaml_file_path_head = os.path.split(review_yaml_file_path)
|
||||||
|
filename, ext = os.path.splitext(review_yaml_file_path_head)
|
||||||
|
if files_to_add_list:
|
||||||
|
review_status_file_path = os.path.join("review/",filename+"-review_status"+TXT_EXT)
|
||||||
|
with open(review_status_file_path,'a') as f:
|
||||||
|
f.write('\nsubmitted')
|
||||||
|
|
||||||
|
files_to_add_list.append(review_status_file_path)
|
||||||
|
|
||||||
|
result = subprocess.run(add_command(files_to_add_list),capture_output=True,check=True)
|
||||||
|
message = 'Submitted metadata review.'
|
||||||
|
commit_output = subprocess.run(commit_command(message),capture_output=True,check=True)
|
||||||
|
|
||||||
|
for line in commit_output.stdout.splitlines():
|
||||||
|
print(line.decode('utf-8'))
|
||||||
|
else:
|
||||||
|
print('Nothing to commit.')
|
||||||
|
|
||||||
|
|
||||||
|
#status_dict = repo_obj.status()
|
||||||
|
#for filepath, file_status in status_dict.items():
|
||||||
|
# Identify keys associated to review files and stage them
|
||||||
|
# if ('review/'+filename in filepath) and (file_status == pygit.GIT_STATUS_WT_MODIFIED):
|
||||||
|
# Stage changes
|
||||||
|
# repo_obj.index.add(filepath)
|
||||||
|
|
||||||
|
#author = config_file.author #default_signature
|
||||||
|
#committer = config_file.committer
|
||||||
|
#message = "Submitted metadata review."
|
||||||
|
#tree = repo_obj.index.write_tree()
|
||||||
|
#oid = repo_obj.create_commit('HEAD', author, committer, message, tree, [repo_obj.head.peel().oid])
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user