1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
description: "Add bidirectional traceability between spec artifacts and source issue"
tools:
-
Add bidirectional traceability between spec artifacts and their source GitHub Issue. Creates links in both the spec file and the GitHub Issue.
$ARGUMENTS
Expected format: `<owner>/<repo>#<issue_number>` or just `#<issue_number>` (uses current repo)
Examples:
- -
1. 2.3.
Extract the repository owner, name, and issue number from the user input.
```bash
input="$ARGUMENTS"
if [[ "$input" =~ ^#([0-9]+)$ ]]; then
# Format: #123 (use current repo)
issue_number="${BASH_REMATCH[1]}"
repo_info=$(gh repo view --json nameWithOwner -q .nameWithOwner)
repo="$repo_owner/$repo_name"
echo "Linking to issue #$issue_number from $repo"
```
Check that the issue exists and is accessible.
```bash
issue_data=$(gh issue view "$issue_number" \
--repo "$repo" \
--json title,url,state)
if [ $? -ne 0 ]; then
echo "Error: Failed to fetch issue. Check repository access and issue number."
exit 1
fi
title=$(echo "$issue_data" | jq -r '.title')
url=$(echo "$issue_data" | jq -r '.url')
state=$(echo "$issue_data" | jq -r '.state')
echo "Found issue: $title"
```
Locate the spec file in the current feature directory.
```bash
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null)
if [[ "$current_branch" =~ ^[0-9]+-(.+)$ ]]; then
# Extract feature name from branch
feature_pattern="${current_branch}"
if [ -z "$feature_dir" ]; then
echo "Error: No feature directory found. Create a spec first."
exit 1
fi
feature_dir="${feature_dir%/}"
spec_file="$feature_dir/spec.md"
if [ ! -f "$spec_file" ]; then
echo "Error: Spec file not found at $spec_file"
exit 1
fi
echo "Found spec: $spec_file"
```
Update the spec file to include a reference to the source issue.
```bash
if grep -q "Source Issue.*$repo#$issue_number" "$spec_file"; then
echo "✓ Spec already linked to this issue"
else
# Add source issue link to spec frontmatter
# Find the first heading and insert before it
temp_file=$(mktemp)
# Read spec and add link after title
awk -v repo="$repo" -v num="$issue_number" -v url="$url" -v state="$state" '
' "$spec_file" > "$temp_file"
mv "$temp_file" "$spec_file"
echo "✓ Added issue link to spec"
fi
```
Create or update the `.issue-link` metadata file.
```bash
metadata_file="$feature_dir/.issue-link"
cat > "$metadata_file" <<EOF
repository: $repo
issue_number: $issue_number
issue_url: $url
linked_at: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
last_synced: $(date -u +"%Y-%m-%dT%H:%M:%SZ")
EOF
echo "✓ Created link metadata"
```
Add a comment to the GitHub Issue linking back to the spec.
```bash
current_branch=$(git rev-parse --abbrev-ref HEAD 2>/dev/null || echo "main")
current_commit=$(git rev-parse --short HEAD 2>/dev/null || echo "unknown")
repo_url=$(git config --get remote.origin.url 2>/dev/null | sed 's/\.git$//')
if [[ "$repo_url" =~ ^git@ ]]; then
if [[ "$repo_url" =~ github.com ]]; then
spec_url="$repo_url/blob/$current_branch/$spec_file"
else
spec_url="$spec_file"
fi
comment_body="## 📋 Spec-Driven Development
This issue has been imported into a specification document for structured development.
**Spec Location:** \`$spec_file\`
**Branch:** \`$current_branch\`
**Spec URL:** $spec_url
The spec will be kept in sync with this issue using the \`/speckit.github-issues.sync\` command.
*Generated by [Spec Kit GitHub Issues Extension](https://github.com/github/spec-kit)*"
gh issue comment "$issue_number" \
--repo "$repo" \
--body "$comment_body"
if [ $? -eq 0 ]; then
echo "✓ Added traceability comment to issue"
else
echo "⚠ Warning: Could not add comment to issue (may lack permissions)"
fi
```
Provide a summary of the linking operation.
```bash
echo ""
echo "Link Summary:"
echo " Issue: $repo#$issue_number"
echo " Title: $title"
echo " Spec: $spec_file"
echo " Metadata: $metadata_file"
echo ""
echo "Bidirectional traceability established:"
echo " ✓ Spec references issue"
echo " ✓ Issue references spec (via comment)"
echo ""
echo "Next steps:"
echo " • Use /speckit.github-issues.sync to keep spec updated with issue changes"
echo " • Continue with /speckit.plan to create implementation plan"
```
Load configuration from `.specify/extensions/github-issues/github-issues-config.yml`:
- --
- ----