fedora-csb-system-manager
1#!/usr/bin/env bash
2# Convert Jira issue to org-mode format
3
4set -euo pipefail
5
6usage() {
7 cat <<EOF
8Usage: jira-to-org ISSUE-KEY [options]
9
10Convert Jira issue to org-mode format for denote notes.
11
12Options:
13 --template TYPE Template type: investigation, planning, discussion
14 --output FILE Output file (default: stdout)
15 -h, --help Show this help
16
17Examples:
18 jira-to-org SRVKP-1234
19 jira-to-org SRVKP-1234 --template investigation
20 jira-to-org SRVKP-1234 --output ~/notes/issue.org
21EOF
22 exit 1
23}
24
25ISSUE_KEY="${1:-}"
26TEMPLATE="basic"
27OUTPUT=""
28
29shift || true
30
31while [[ $# -gt 0 ]]; do
32 case "$1" in
33 --template)
34 TEMPLATE="$2"
35 shift 2
36 ;;
37 --output)
38 OUTPUT="$2"
39 shift 2
40 ;;
41 -h|--help)
42 usage
43 ;;
44 *)
45 echo "Unknown option: $1"
46 usage
47 ;;
48 esac
49done
50
51if [[ -z "$ISSUE_KEY" ]]; then
52 echo "Error: ISSUE-KEY required"
53 usage
54fi
55
56# Fetch issue details
57ISSUE_DATA=$(jira issue view "$ISSUE_KEY" --plain 2>/dev/null || {
58 echo "Error: Failed to fetch issue $ISSUE_KEY"
59 exit 1
60})
61
62# Extract fields (basic parsing - adjust based on actual output format)
63SUMMARY=$(echo "$ISSUE_DATA" | grep -A1 "^Summary:" | tail -1 | sed 's/^[[:space:]]*//')
64STATUS=$(echo "$ISSUE_DATA" | grep "Status:" | sed 's/.*Status:[[:space:]]*//' | awk '{print $1}')
65PRIORITY=$(echo "$ISSUE_DATA" | grep "Priority:" | sed 's/.*Priority:[[:space:]]*//' | awk '{print $1}')
66ASSIGNEE=$(echo "$ISSUE_DATA" | grep "Assignee:" | sed 's/.*Assignee:[[:space:]]*//')
67TYPE=$(echo "$ISSUE_DATA" | grep "Type:" | sed 's/.*Type:[[:space:]]*//' | awk '{print $1}')
68
69# Generate org-mode content based on template
70generate_org() {
71 cat <<EOF
72* $ISSUE_KEY: $SUMMARY
73
74:PROPERTIES:
75:JIRA: https://issues.redhat.com/browse/$ISSUE_KEY
76:JIRA_KEY: $ISSUE_KEY
77:JIRA_STATUS: $STATUS
78:JIRA_PRIORITY: $PRIORITY
79:JIRA_TYPE: $TYPE
80:CREATED: $(date '+[%Y-%m-%d %a %H:%M]')
81:END:
82
83[[https://issues.redhat.com/browse/$ISSUE_KEY][View in Jira]]
84
85** Issue Details
86- Status: $STATUS
87- Priority: $PRIORITY
88- Assignee: $ASSIGNEE
89- Type: $TYPE
90
91** Description
92EOF
93
94 # Add template-specific sections
95 case "$TEMPLATE" in
96 investigation)
97 cat <<'EOF'
98
99** Investigation
100*** Hypothesis
101
102
103*** Findings
104
105
106*** Root Cause
107
108
109** Solution
110*** Proposed Fix
111
112
113*** Testing Plan
114- [ ] Test case 1
115- [ ] Test case 2
116
117*** Implementation Notes
118
119
120** Related
121- Related issues:
122- PRs:
123- Documentation:
124EOF
125 ;;
126 planning)
127 cat <<'EOF'
128
129** Goals
130
131
132** Requirements
133*** Functional Requirements
134
135
136*** Non-Functional Requirements
137
138
139** Design
140*** Architecture
141
142
143*** Components
144
145
146** Implementation Plan
147*** Phase 1
148- [ ] Task 1
149- [ ] Task 2
150
151** Testing Strategy
152
153
154** Timeline
155| Phase | Start | End | Status |
156|-------+-------+-----+--------|
157| | | | |
158EOF
159 ;;
160 discussion)
161 cat <<'EOF'
162
163** Context
164
165
166** Discussion Points
167
168
169** Decisions
170
171
172** Action Items
173- [ ] Action 1
174- [ ] Action 2
175
176** Next Steps
177
178EOF
179 ;;
180 basic)
181 cat <<'EOF'
182
183** Notes
184
185
186** Tasks
187- [ ] Task 1
188
189** Related
190EOF
191 ;;
192 esac
193}
194
195# Output to file or stdout
196if [[ -n "$OUTPUT" ]]; then
197 generate_org > "$OUTPUT"
198 echo "Created org-mode note: $OUTPUT"
199else
200 generate_org
201fi