Coverage for scripts / get_participants.py: 0%

50 statements  

« prev     ^ index     » next       coverage.py v7.13.0, created at 2025-12-25 18:08 -0500

1#!/usr/bin/env python3 

2""" 

3Get request participants. 

4 

5Usage: 

6 python get_participants.py REQ-123 

7 python get_participants.py REQ-123 --output json 

8""" 

9 

10import sys 

11import os 

12import argparse 

13import json 

14from pathlib import Path 

15 

16sys.path.insert(0, str(Path(__file__).parent.parent.parent / 'shared' / 'scripts' / 'lib')) 

17 

18from config_manager import get_jira_client 

19from error_handler import print_error, JiraError 

20 

21 

22def get_participants_func(issue_key: str, start: int = 0, limit: int = 50, 

23 profile: str = None) -> dict: 

24 """ 

25 Get participants for a request. 

26 

27 Args: 

28 issue_key: Request issue key 

29 start: Starting index for pagination 

30 limit: Maximum results per page 

31 profile: JIRA profile to use 

32 

33 Returns: 

34 Participants data 

35 """ 

36 with get_jira_client(profile) as client: 

37 return client.get_request_participants(issue_key, start=start, limit=limit) 

38 

39 

40def main(): 

41 """Main entry point.""" 

42 parser = argparse.ArgumentParser( 

43 description='Get request participants', 

44 formatter_class=argparse.RawDescriptionHelpFormatter, 

45 epilog=""" 

46Examples: 

47 Get participants: 

48 %(prog)s REQ-123 

49 

50 JSON output: 

51 %(prog)s REQ-123 --output json 

52 

53 Pagination: 

54 %(prog)s REQ-123 --start 0 --limit 50 

55 """ 

56 ) 

57 

58 parser.add_argument('issue_key', 

59 help='Request issue key (e.g., REQ-123)') 

60 parser.add_argument('--start', type=int, default=0, 

61 help='Starting index for pagination (default: 0)') 

62 parser.add_argument('--limit', type=int, default=50, 

63 help='Maximum results per page (default: 50)') 

64 parser.add_argument('--output', choices=['text', 'json', 'csv'], default='text', 

65 help='Output format (default: text)') 

66 parser.add_argument('--count', action='store_true', 

67 help='Show only count') 

68 parser.add_argument('--profile', 

69 help='JIRA profile to use from config') 

70 

71 args = parser.parse_args() 

72 

73 try: 

74 data = get_participants_func( 

75 issue_key=args.issue_key, 

76 start=args.start, 

77 limit=args.limit, 

78 profile=args.profile 

79 ) 

80 

81 participants = data.get('values', []) 

82 

83 if args.count: 

84 print(len(participants)) 

85 return 0 

86 

87 if args.output == 'json': 

88 print(json.dumps(participants, indent=2)) 

89 elif args.output == 'csv': 

90 print("Email,DisplayName") 

91 for participant in participants: 

92 print(f"{participant.get('emailAddress','')},{participant.get('displayName','')}") 

93 else: 

94 if not participants: 

95 print(f"No participants for {args.issue_key}.") 

96 return 0 

97 

98 print(f"Participants for {args.issue_key}:\n") 

99 print(f"{'Email':<30} {'Display Name'}") 

100 print("-" * 60) 

101 for participant in participants: 

102 print(f"{participant.get('emailAddress',''):<30} {participant.get('displayName','')}") 

103 

104 print(f"\nTotal: {len(participants)} participant(s)") 

105 

106 return 0 

107 

108 except JiraError as e: 

109 print_error(f"Failed to get participants: {e}") 

110 return 1 

111 except Exception as e: 

112 print_error(f"Unexpected error: {e}") 

113 return 1 

114 

115 

116if __name__ == '__main__': 

117 sys.exit(main())