Skip to content

Commit a945ece

Browse files
committed
remove unused functions
1 parent 530ac6d commit a945ece

1 file changed

Lines changed: 0 additions & 205 deletions

File tree

scripts/automated_ingestion/eessi_task.py

Lines changed: 0 additions & 205 deletions
Original file line numberDiff line numberDiff line change
@@ -219,178 +219,6 @@ def _determine_sequence_numbers_including_task_file(self, repo: str, pr: str) ->
219219
return {}
220220
return sequence_numbers
221221

222-
@log_function_entry_exit()
223-
def _find_highest_number(self, str_list: List[str]) -> int:
224-
"""
225-
Find the highest number in a list of strings.
226-
"""
227-
# Convert all strings to integers
228-
int_list = [int(num) for num in str_list]
229-
return max(int_list)
230-
231-
@log_function_entry_exit()
232-
def _get_sequence_number_for_task_file(self) -> int:
233-
"""
234-
Get the sequence number this task is assigned to at the moment.
235-
NOTE, should only be called if the task is actually assigned to a sequence number.
236-
"""
237-
repo_name = self.description.get_repo_name()
238-
pr_number = self.description.get_pr_number()
239-
sequence_numbers = self._determine_sequence_numbers_including_task_file(repo_name, pr_number)
240-
if len(sequence_numbers) == 0:
241-
raise ValueError("Found no sequence numbers at all")
242-
else:
243-
# get all entries with value True, there should be only one, so we return the first one
244-
sequence_numbers_true = [key for key, value in sequence_numbers.items() if value is True]
245-
if len(sequence_numbers_true) == 0:
246-
raise ValueError("Found no sequence numbers that include the task file for task %s",
247-
self.description)
248-
else:
249-
return sequence_numbers_true[0]
250-
251-
@log_function_entry_exit()
252-
def _get_current_sequence_number(self, sequence_numbers: Dict[int, bool] = None) -> int:
253-
"""
254-
Get the current sequence number based on the sequence numbers.
255-
If sequence_numbers is not provided, we determine the sequence numbers from the task description.
256-
"""
257-
if sequence_numbers is None:
258-
repo_name = self.description.get_repo_name()
259-
pr_number = self.description.get_pr_number()
260-
sequence_numbers = self._determine_sequence_numbers_including_task_file(repo_name, pr_number)
261-
if len(sequence_numbers) == 0:
262-
return 0
263-
return self._find_highest_number(sequence_numbers.keys())
264-
265-
@log_function_entry_exit()
266-
def _get_fixed_sequence_number(self) -> int:
267-
"""
268-
Get a fixed sequence number.
269-
"""
270-
return 11
271-
272-
@log_function_entry_exit()
273-
def _find_staging_pr(self) -> Tuple[Optional[PullRequest], Optional[str], Optional[int]]:
274-
"""
275-
Find the staging PR for the task.
276-
TODO: arg sequence number --> make function simpler
277-
"""
278-
repo_name = self.description.get_repo_name()
279-
pr_number = self.description.get_pr_number()
280-
try:
281-
sequence_number = self._get_sequence_number_for_task_file()
282-
except ValueError:
283-
# no sequence number found, so we return None
284-
log_message(LoggingScope.ERROR, "ERROR", "no sequence number found for task '%s'", self.description)
285-
return None, None, None
286-
except Exception as err:
287-
# some other error
288-
log_message(LoggingScope.ERROR, "ERROR", "error finding staging PR for task '%s': '%s'",
289-
self.description, err)
290-
return None, None, None
291-
branch_name = f"{repo_name.replace('/', '-')}-PR-{pr_number}-SEQ-{sequence_number}"
292-
if branch_name in [branch.name for branch in self.git_repo.get_branches()]:
293-
find_pr = [pr for pr in self.git_repo.get_pulls(head=branch_name, state="all")]
294-
if find_pr:
295-
pr = find_pr.pop(0)
296-
return pr, branch_name, sequence_number
297-
else:
298-
return None, branch_name, sequence_number
299-
else:
300-
return None, None, None
301-
302-
@log_function_entry_exit()
303-
def _create_staging_pr(self, sequence_number: int) -> Tuple[PullRequest, str]:
304-
"""
305-
Create a staging PR for the task.
306-
NOTE, SHALL only be called if no staging PR for the task exists yet.
307-
"""
308-
repo_name = self.description.get_repo_name()
309-
pr_number = self.description.get_pr_number()
310-
branch_name = f"{repo_name.replace('/', '-')}-PR-{pr_number}-SEQ-{sequence_number}"
311-
default_branch_name = self.git_repo.default_branch
312-
pr = self.git_repo.create_pull(title=f"Add task for {repo_name} PR {pr_number} seq {sequence_number}",
313-
body=f"Add task for {repo_name} PR {pr_number} seq {sequence_number}",
314-
head=branch_name, base=default_branch_name)
315-
return pr, branch_name
316-
317-
@log_function_entry_exit()
318-
def _find_state(self) -> EESSITaskState:
319-
"""
320-
Determine the state of the task based on the task description metadata.
321-
322-
Returns:
323-
The state of the task.
324-
"""
325-
# obtain repo and pr from metadata
326-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "finding state of task '%s'", self.description.task_object)
327-
repo = self.description.get_repo_name()
328-
pr = self.description.get_pr_number()
329-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "repo: '%s', pr: '%s'", repo, pr)
330-
331-
# obtain all sequence numbers in repo/pr dir which include a state file for this task
332-
sequence_numbers = self._determine_sequence_numbers_including_task_file(repo, pr)
333-
if len(sequence_numbers) == 0:
334-
# no sequence numbers found, so we return NEW_TASK
335-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "no sequence numbers found, state: NEW_TASK")
336-
return EESSITaskState.NEW_TASK
337-
# we got at least one sequence number
338-
# if one value for a sequence number is True, we can determine the state from the file in the directory
339-
sequence_including_task = [key for key, value in sequence_numbers.items() if value is True]
340-
if len(sequence_including_task) == 0:
341-
# no sequence number includes the task file, so we return NEW_TASK
342-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO",
343-
"no sequence number includes the task file, state: NEW_TASK")
344-
return EESSITaskState.NEW_TASK
345-
# we got at least one sequence number which includes the task file
346-
# we can determine the state from the filename in the directory
347-
# NOTE, we use the first element in sequence_including_task (there should be only one)
348-
# we ignore other elements in sequence_including_task
349-
sequence_number = sequence_including_task[0]
350-
task_file_name = self.description.get_task_file_name()
351-
metadata_file_state_path_prefix = f"{repo}/{pr}/{sequence_number}/{task_file_name}."
352-
state = self._get_state_for_metadata_file_prefix(metadata_file_state_path_prefix, sequence_number)
353-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "state: '%s'", state)
354-
return state
355-
356-
@log_function_entry_exit()
357-
def _get_state_for_metadata_file_prefix(self, metadata_file_state_path_prefix: str,
358-
sequence_number: int) -> EESSITaskState:
359-
"""
360-
Get the state from the file in the metadata_file_state_path_prefix.
361-
"""
362-
# depending on the state of the deployment (NEW_TASK, PAYLOAD_STAGED, PULL_REQUEST, APPROVED, REJECTED,
363-
# INGESTED, DONE)
364-
# we need to check the task file in the default branch or in the branch corresponding to the sequence number
365-
directory_part = os.path.dirname(metadata_file_state_path_prefix)
366-
repo_name = self.description.get_repo_name()
367-
pr_number = self.description.get_pr_number()
368-
default_branch_name = self.git_repo.default_branch
369-
branch_name = f"{repo_name.replace('/', '-')}-PR-{pr_number}-SEQ-{sequence_number}"
370-
all_branch_names = [branch.name for branch in self.git_repo.get_branches()]
371-
states = []
372-
for branch in [default_branch_name, branch_name]:
373-
if branch in all_branch_names:
374-
# first get all files in directory part of metadata_file_state_path_prefix
375-
files = self._list_directory_contents(directory_part, branch)
376-
# check if any of the files has metadata_file_state_path_prefix as prefix
377-
for file in files:
378-
if file.path.startswith(metadata_file_state_path_prefix):
379-
# get state from file name taking only the suffix
380-
state = EESSITaskState.from_string(file.name.split(".")[-1])
381-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "state: '%s'", state)
382-
states.append(state)
383-
if len(states) == 0:
384-
# did not find any file with metadata_file_state_path_prefix as prefix
385-
log_message(LoggingScope.TASK_OPS, "INFO", "did not find any file with prefix '%s'",
386-
metadata_file_state_path_prefix)
387-
return EESSITaskState.NEW_TASK
388-
# sort the states and return the last one
389-
states.sort()
390-
state = states[-1]
391-
log_message(LoggingScope.TASK_OPS_DETAILS, "INFO", "state: '%s'", state)
392-
return state
393-
394222
@log_function_entry_exit()
395223
def _list_directory_contents(self, directory_path: str, branch_name: str = None) -> List[Any]:
396224
"""
@@ -920,39 +748,6 @@ def _determine_feature_branch_name(self) -> str:
920748
org, repo, pr, seq, _ = pull_request_dir.split("/")
921749
return f"{org}-{repo}-PR-{pr}-SEQ-{seq}"
922750

923-
@log_function_entry_exit()
924-
def _sync_task_state_file(self, source_branch: str, target_branch: str):
925-
"""Update task state file from source to target branch"""
926-
task_pointer_file = self.description.task_object.remote_file_path
927-
pull_request_dir = self._read_pull_request_dir_from_file(task_pointer_file, self.git_repo.default_branch)
928-
task_state_file_path = f"{pull_request_dir}/TaskState"
929-
930-
try:
931-
# get content from source branch
932-
source_content = self.git_repo.get_contents(task_state_file_path, ref=source_branch)
933-
934-
# get current file in target branch
935-
target_file = self.git_repo.get_contents(task_state_file_path, ref=target_branch)
936-
937-
# update if content is different
938-
if source_content.sha != target_file.sha:
939-
result = self.git_repo.update_file(
940-
path=task_state_file_path,
941-
message=f"Sync {task_state_file_path} from {source_branch} to {target_branch}",
942-
content=source_content.decoded_content,
943-
sha=target_file.sha,
944-
branch=target_branch
945-
)
946-
log_message(LoggingScope.TASK_OPS, "INFO", "Updated '%s'", task_state_file_path)
947-
return result
948-
else:
949-
log_message(LoggingScope.TASK_OPS, "INFO", "No changes needed for '%s'", task_state_file_path)
950-
return None
951-
952-
except Exception as err:
953-
log_message(LoggingScope.TASK_OPS, "ERROR", "Error syncing task state file: '%s'", err)
954-
return None
955-
956751
@log_function_entry_exit()
957752
def _update_task_states(self, next_state: EESSITaskState, default_branch_name: str,
958753
approved_state: EESSITaskState, feature_branch_name: str):

0 commit comments

Comments
 (0)