Skip to content

Commit ed5bcbf

Browse files
authored
feat: create GitHub autolink (#79)
1 parent 15130e8 commit ed5bcbf

File tree

2 files changed

+42
-9
lines changed

2 files changed

+42
-9
lines changed

create-github-autolink.sh

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/usr/bin/env bash
2+
3+
set -e -o pipefail
4+
5+
# Run this over repository to add GitHub autolink: https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/managing-repository-settings/configuring-autolinks-to-reference-external-resources
6+
7+
: "${JIRA_MIGRATION_JIRA_PROJECT_NAME:? Missing Jira project name (e.g., JENKINS)}"
8+
: "${JIRA_MIGRATION_REDIRECTION_SERVICE? Missing URL of the redirection service (e.g., https://issue-redirect.jenkins.io)}"
9+
: "${JIRA_MIGRATION_CREATE_GITHUB_AUTOLINK:=false}"
10+
11+
OWNER=${1:-timja-org}
12+
REPO=${2:-jenkins-gh-issues-poc-11-04}
13+
14+
# Check for required commands
15+
if ! command -v gh >/dev/null 2>&1; then
16+
echo "Error: 'gh' is required but not installed on this system." >&2
17+
echo "Install it first. On macOS: brew install gh" >&2
18+
exit 1
19+
fi
20+
21+
github_repo="${OWNER}/${REPO}"
22+
23+
if [[ "${JIRA_MIGRATION_CREATE_GITHUB_AUTOLINK}" == "true" ]]; then
24+
gh repo autolink create "${JIRA_MIGRATION_JIRA_PROJECT_NAME}-" "${JIRA_MIGRATION_REDIRECTION_SERVICE}/${JIRA_MIGRATION_JIRA_PROJECT_NAME}-<num>" --numeric --repo "${github_repo}"
25+
else
26+
echo "JIRA_MIGRATION_CREATE_GITHUB_AUTOLINK set to 'false', no GitHub autolink created."
27+
fi

orchestrate-migration.sh

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@ REQUIRED_VARS=(
5757
"JIRA_MIGRATION_JIRA_TOKEN"
5858
"JIRA_MIGRATION_GITHUB_NAME"
5959
"JIRA_MIGRATION_GITHUB_ACCESS_TOKEN"
60+
"JIRA_MIGRATION_CREATE_GITHUB_AUTOLINK"
6061
)
6162

6263
for var in "${REQUIRED_VARS[@]}"; do
@@ -170,13 +171,13 @@ process_component() {
170171

171172
# Step 1: Fetch issues from Jira
172173
log ""
173-
log "Step 1/9: Fetching issues from Jira..."
174+
log "Step 1/10: Fetching issues from Jira..."
174175
python3 ./fetch_issues.py
175176
validate_file "jira_output/result-0.xml" "Jira issues XML"
176177

177178
# Step 2: Concatenate XML results
178179
log ""
179-
log "Step 2/9: Concatenating XML results..."
180+
log "Step 2/10: Concatenating XML results..."
180181
./concatenate-xml-results.sh
181182
validate_file "jira_output/combined.xml" "Combined XML"
182183

@@ -186,43 +187,48 @@ process_component() {
186187

187188
# Step 3: Retrieve watchers and remote links
188189
log ""
189-
log "Step 3/9: Retrieving watchers and remote links..."
190+
log "Step 3/10: Retrieving watchers and remote links..."
190191
./retrieve-watchers-and-remotelinks.sh
191192
validate_file "combined-remotelinks.txt" "Remote links"
192193

193194
# Step 4: Enable GitHub Issues on repository
194195
log ""
195-
log "Step 4/9: Enabling GitHub Issues on repository..."
196+
log "Step 4/10: Enabling GitHub Issues on repository..."
196197
gh api -X PATCH "repos/$github_owner/$github_repo" --field has_issues=true || true
197198
log "✓ GitHub Issues enabled (or already enabled)"
198199

199200
# Step 5: Import issues to GitHub
200201
log ""
201-
log "Step 5/9: Importing issues to GitHub..."
202+
log "Step 5/10: Importing issues to GitHub..."
202203
python3 -u ./main.py
203204
validate_file "jira-keys-to-github-id_${JIRA_MIGRATION_CURRENT_DATETIME}.txt" "Jira-to-GitHub mapping"
204205

205206
# Step 6: Post-process epics
206207
log ""
207-
log "Step 6/9: Post-processing epic relationships..."
208+
log "Step 6/10: Post-processing epic relationships..."
208209
./post_process_epics.sh "$github_owner" "$github_repo"
209210

210211
# Step 7: Post-process issue types
211212
log ""
212-
log "Step 7/9: Post-processing issue types..."
213+
log "Step 7/10: Post-processing issue types..."
213214
./post_process_issues.sh "$github_owner" "$github_repo"
214215

215216
# Step 8: Add comments to Jira issues
216217
log ""
217-
log "Step 8/9: Adding migration comments to Jira..."
218+
log "Step 8/10: Adding migration comments to Jira..."
218219
export JIRA_GITHUB_MAPPING_FILE="jira-keys-to-github-id_${JIRA_MIGRATION_CURRENT_DATETIME}.txt"
219220
./jira-commenter.sh
220221

221222
# Step 9: Archive Jira component
222223
log ""
223-
log "Step 9/9: Archiving Jira component..."
224+
log "Step 9/10: Archiving Jira component..."
224225
./jira-archive-component.sh "$component"
225226

227+
# Step 10: Create GitHub autolink
228+
log ""
229+
log "Step 10/10: Creating GitHub autolink..."
230+
./create-github-autolink.sh "$github_owner" "$github_repo"
231+
226232
# Archive outputs
227233
log ""
228234
archive_component_outputs "$component"

0 commit comments

Comments
 (0)