forked from dougwaldron/jira-issues-importer
-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathjira-archive-component.sh
More file actions
executable file
·61 lines (47 loc) · 1.88 KB
/
jira-archive-component.sh
File metadata and controls
executable file
·61 lines (47 loc) · 1.88 KB
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
#!/usr/bin/env bash
set -e -o pipefail
# Script to archive a Jira component
# Usage: ./jira-archive-component.sh <component-name>
COMPONENT_NAME=$1
if [ -z "$COMPONENT_NAME" ]; then
echo "Error: Component name not specified"
echo "Usage: $0 <component-name>"
exit 1
fi
# Load environment variables
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
if [ -f "$SCRIPT_DIR/.env" ]; then
source "$SCRIPT_DIR/.env"
fi
# Validate required environment variables
if [ -z "$JIRA_MIGRATION_JIRA_URL" ] || [ -z "$JIRA_MIGRATION_JIRA_TOKEN" ] || [ -z "$JIRA_MIGRATION_JIRA_PROJECT_NAME" ]; then
echo "Error: Required environment variables not set"
echo "Please set JIRA_MIGRATION_JIRA_URL, JIRA_MIGRATION_JIRA_TOKEN, and JIRA_MIGRATION_JIRA_PROJECT_NAME"
exit 1
fi
JIRA_BASE_URL="$JIRA_MIGRATION_JIRA_URL"
JIRA_PROJECT="$JIRA_MIGRATION_JIRA_PROJECT_NAME"
echo "Looking up component ID for: $COMPONENT_NAME in project: $JIRA_PROJECT"
# Get component ID by name
COMPONENT_JSON=$(curl -s \
-H "Authorization: Bearer ${JIRA_MIGRATION_JIRA_TOKEN}" \
-H "Content-Type: application/json" \
"${JIRA_BASE_URL}/rest/api/2/project/${JIRA_PROJECT}/components")
COMPONENT_ID=$(echo "$COMPONENT_JSON" | jq -r ".[] | select(.name == \"${COMPONENT_NAME}\") | .id")
if [ -z "$COMPONENT_ID" ] || [ "$COMPONENT_ID" = "null" ]; then
echo "Error: Component '${COMPONENT_NAME}' not found in project ${JIRA_PROJECT}"
echo "Available components:"
echo "$COMPONENT_JSON" | jq -r '.[].name'
exit 1
fi
echo "Found component ID: $COMPONENT_ID"
echo "Archiving component: $COMPONENT_NAME (ID: $COMPONENT_ID)"
# Archive the component
curl -s \
-X PUT \
-H "Authorization: Bearer ${JIRA_MIGRATION_JIRA_TOKEN}" \
-H "Content-Type: application/json" \
"${JIRA_BASE_URL}/rest/api/2/component/${COMPONENT_ID}" \
--data '{"archived": true}'
echo ""
echo "✓ Component '${COMPONENT_NAME}' has been archived"