MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / get_last_rendered_functionality

Function get_last_rendered_functionality

git_utils.py:438–485  ·  view source on GitHub ↗
(repo_path: Union[str, os.PathLike])

Source from the content-addressed store, hash-verified

436
437
438def get_last_rendered_functionality(repo_path: Union[str, os.PathLike]) -> tuple[Optional[str], Optional[str]]:
439 if not os.path.exists(repo_path):
440 return None, None
441
442 repo = Repo(repo_path)
443 grep_pattern = FUNCTIONAL_REQUIREMENT_FINISHED_COMMIT_MESSAGE.format(".*")
444 grep_pattern = grep_pattern.replace("[", "\\[").replace("]", "\\]")
445 commit_sha = repo.git.rev_list(repo.active_branch.name, "--grep", grep_pattern, "-n", "1")
446
447 if not commit_sha:
448 # Repo was interrupted during the first functionality, fallback to initial commit and provide only module name
449 grep_pattern = INITIAL_COMMIT_MESSAGE
450 grep_pattern = grep_pattern.replace("[", "\\[").replace("]", "\\]")
451 commit_sha = repo.git.rev_list(repo.active_branch.name, "--grep", grep_pattern, "-n", "1")
452 if not commit_sha:
453 raise InvalidGitRepositoryError("Git repository is in an invalid state. Initial commit could not be found.")
454
455 commit_message = repo.commit(commit_sha).message
456 if isinstance(commit_message, bytes):
457 commit_message = commit_message.decode("utf-8")
458
459 match = re.search(r"Module name:\s*(\S+)\n", commit_message)
460 if not match:
461 raise InvalidGitRepositoryError(
462 "Git repository is in an invalid state. Could not find module name in initial commit."
463 )
464
465 module_name = match.group(1)
466 return module_name, None
467
468 commit_message = repo.commit(commit_sha).message
469 if isinstance(commit_message, bytes):
470 commit_message = commit_message.decode("utf-8")
471
472 match = re.search(r"FRID\):(\S+) fully implemented", commit_message)
473 if not match:
474 raise InvalidGitRepositoryError(
475 "Git repository is in an invalid state. Could not find frid in finished commit."
476 )
477 frid = match.group(1)
478
479 match = re.search(r"Module name:\s*(\S+)\n", commit_message)
480 if not match:
481 raise InvalidGitRepositoryError(
482 "Git repository is in an invalid state. Could not find module name in finished commit."
483 )
484 module_name = match.group(1)
485 return module_name, frid

Calls 2

formatMethod · 0.45