Add Git validations for publishing tools (#1381)

This commit prevents tools from being published if the underlying Git
repository is unsynced with origin.
This commit is contained in:
Vini Brasil
2024-10-02 11:46:18 -03:00
committed by GitHub
parent 01329a01ab
commit dd0b622826
9 changed files with 235 additions and 53 deletions

View File

@@ -6,6 +6,7 @@ import subprocess
import tempfile
from crewai.cli.command import BaseCommand, PlusAPIMixin
from crewai.cli import git
from crewai.cli.utils import (
get_project_name,
get_project_description,
@@ -59,6 +60,17 @@ class ToolCommand(BaseCommand, PlusAPIMixin):
os.chdir(old_directory)
def publish(self, is_public: bool):
if not git.Repository().is_synced():
console.print(
"[bold red]Failed to publish tool.[/bold red]\n"
"Local changes need to be resolved before publishing. Please do the following:\n"
"* [bold]Commit[/bold] your changes.\n"
"* [bold]Push[/bold] to sync with the remote.\n"
"* [bold]Pull[/bold] the latest changes from the remote.\n"
"\nOnce your repository is up-to-date, retry publishing the tool."
)
raise SystemExit()
project_name = get_project_name(require=True)
assert isinstance(project_name, str)