Skip to content

Commit 9c9a907

Browse files
authored
feat: add Github star call-to-action after successful scans (#17)
- Display friendly message in table format after scan completion - Message only shown for table output, respects --quiet flag - Works for both regular and cloud scans - Encourages users to star repository on GitHub Tests: - Added 3 new test cases for star message display - Verified message appears in table format - Verified message is suppressed in quiet mode - Verified message doesn't appear in JSON/CycloneDX formats"
1 parent 136ef8a commit 9c9a907

File tree

2 files changed

+46
-0
lines changed

2 files changed

+46
-0
lines changed

src/ai_bom/cli.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,15 @@ def scan(
569569
console.print(f"[red]Error generating report: {e}[/red]")
570570
raise typer.Exit(EXIT_ERROR) from None
571571

572+
# Print friendly call-to-action if scan was successful and not in quiet mode
573+
if format == "table" and not quiet:
574+
console.print()
575+
star_msg = (
576+
"✨ Found ai-bom useful? "
577+
"Give us a star: https://github.com/Trusera/ai-bom ⭐"
578+
)
579+
console.print(f"[cyan]{star_msg}[/cyan]")
580+
572581
# Save to dashboard database if requested
573582
if save_dashboard:
574583
_save_to_dashboard(result, end_time - start_time, quiet=quiet)
@@ -762,6 +771,15 @@ def scan_cloud(
762771
console.print(f"[red]Error generating report: {exc}[/red]")
763772
raise typer.Exit(EXIT_ERROR) from None
764773

774+
# Print friendly call-to-action if scan was successful and not in quiet mode
775+
if format == "table" and not quiet:
776+
console.print()
777+
star_msg = (
778+
"✨ Found ai-bom useful? "
779+
"Give us a star: https://github.com/Trusera/ai-bom ⭐"
780+
)
781+
console.print(f"[cyan]{star_msg}[/cyan]")
782+
765783

766784
@app.command()
767785
def demo() -> None:

tests/test_cli.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,3 +220,31 @@ def test_no_color_env_var(monkeypatch):
220220
result = runner.invoke(app, ["scan", str(demo_path), "--format", "cyclonedx"])
221221
assert result.exit_code == 0
222222
# The console.no_color flag should be set when NO_COLOR is present
223+
224+
225+
def test_scan_star_message_in_table_format():
226+
"""Test that star message appears in table format."""
227+
demo_file = Path(__file__).parent.parent / "examples" / "demo-project" / "app.py"
228+
result = runner.invoke(app, ["scan", str(demo_file), "--format", "table"])
229+
assert result.exit_code == 0
230+
assert "Found ai-bom useful?" in result.output
231+
assert "https://github.com/Trusera/ai-bom" in result.output
232+
233+
234+
def test_scan_no_star_message_in_quiet_mode():
235+
"""Test that star message does not appear in quiet mode."""
236+
demo_file = Path(__file__).parent.parent / "examples" / "demo-project" / "app.py"
237+
result = runner.invoke(app, ["scan", str(demo_file), "--quiet"])
238+
assert result.exit_code == 0
239+
# Quiet mode should suppress the star message
240+
assert "Found ai-bom useful?" not in result.output or "https://github.com" not in result.output
241+
242+
243+
def test_scan_no_star_message_in_json_format():
244+
"""Test that star message does not appear in JSON format."""
245+
demo_file = Path(__file__).parent.parent / "examples" / "demo-project" / "app.py"
246+
result = runner.invoke(app, ["scan", str(demo_file), "--format", "json"])
247+
assert result.exit_code == 0
248+
# JSON format should only contain JSON output, not the star message
249+
data = json.loads(result.output)
250+
assert "bomFormat" in data # Valid CycloneDX JSON

0 commit comments

Comments
 (0)