Coverage for scripts / get_kb_article.py: 31%
39 statements
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
« prev ^ index » next coverage.py v7.13.0, created at 2025-12-25 18:08 -0500
1#!/usr/bin/env python3
2"""
3Get Knowledge Base article details by ID.
5Retrieves full KB article content including title, body, and metadata.
6Useful for viewing documentation details.
8Usage:
9 get_kb_article.py --article-id 131073
10 get_kb_article.py --article-id 131073 --output json
11"""
13import argparse
14import sys
15import json
16from pathlib import Path
18# Add shared lib to path
19shared_lib_path = str(Path(__file__).parent.parent.parent.parent / 'shared' / 'scripts' / 'lib')
20if shared_lib_path not in sys.path:
21 sys.path.insert(0, shared_lib_path)
23from config_manager import get_jira_client
26def get_kb_article(article_id: str):
27 """
28 Get KB article details by ID.
30 Args:
31 article_id: KB article ID
33 Returns:
34 KB article details
35 """
36 with get_jira_client() as client:
37 return client.get_kb_article(article_id)
40def format_text(article: dict) -> str:
41 """Format KB article as human-readable text."""
42 output = [f"Knowledge Base Article: {article['title']}\n"]
44 if 'excerpt' in article:
45 excerpt = article['excerpt'].replace('<em>', '').replace('</em>', '')
46 output.append(f"Excerpt:\n{excerpt}\n")
48 if '_links' in article and 'self' in article['_links']:
49 output.append(f"URL: {article['_links']['self']}")
51 if 'source' in article:
52 output.append(f"Source: {article['source'].get('type', 'unknown')}")
54 return "\n".join(output)
57def format_json(article: dict) -> str:
58 """Format KB article as JSON."""
59 return json.dumps(article, indent=2)
62def main():
63 parser = argparse.ArgumentParser(
64 description="Get Knowledge Base article details",
65 formatter_class=argparse.RawDescriptionHelpFormatter,
66 epilog=__doc__
67 )
68 parser.add_argument('--article-id', required=True,
69 help='KB article ID')
70 parser.add_argument('--output', choices=['text', 'json'], default='text',
71 help='Output format (default: text)')
72 parser.add_argument('--profile', help='JIRA profile to use')
74 args = parser.parse_args()
76 try:
77 article = get_kb_article(args.article_id)
79 if args.output == 'json':
80 print(format_json(article))
81 else:
82 print(format_text(article))
84 except Exception as e:
85 print(f"Error getting KB article: {str(e)}", file=sys.stderr)
86 sys.exit(1)
89if __name__ == "__main__":
90 main()