-
Notifications
You must be signed in to change notification settings - Fork 45
136 lines (116 loc) · 4.6 KB
/
youtrack-export.yml
File metadata and controls
136 lines (116 loc) · 4.6 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
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
name: Export Issue to YouTrack
on:
issues:
types: [opened]
jobs:
export-to-youtrack:
name: Export to YouTrack
runs-on: ubuntu-latest
env:
YOUTRACK_URL: https://youtrack.jetbrains.com
YOUTRACK_TOKEN: ${{ secrets.YOUTRACK_TOKEN }}
steps:
- name: Map issue type
id: map-type
run: |
LABELS='${{ toJson(github.event.issue.labels.*.name) }}'
echo "GitHub labels: $LABELS"
if echo "$LABELS" | jq -e 'index("bug")' > /dev/null 2>&1; then
echo "yt_type=Bug" >> "$GITHUB_OUTPUT"
echo "Mapped to YouTrack type: Bug"
elif echo "$LABELS" | jq -e 'index("feature")' > /dev/null 2>&1; then
echo "yt_type=Feature" >> "$GITHUB_OUTPUT"
echo "Mapped to YouTrack type: Feature"
else
echo "yt_type=Task" >> "$GITHUB_OUTPUT"
echo "Mapped to YouTrack type: Task (default)"
fi
- name: Resolve github-issue tag ID
id: resolve-tag
run: |
TAG_ID=$(curl -sf \
-H "Authorization: Bearer $YOUTRACK_TOKEN" \
"$YOUTRACK_URL/api/tags?fields=id,name&query=github-issue" \
| jq -r '.[0].id')
if [ -z "$TAG_ID" ] || [ "$TAG_ID" = "null" ]; then
echo "Tag not found, creating..."
TAG_ID=$(curl -sf \
-X POST \
-H "Authorization: Bearer $YOUTRACK_TOKEN" \
-H "Content-Type: application/json" \
-d '{"name": "github-issue"}' \
"$YOUTRACK_URL/api/tags?fields=id" \
| jq -r '.id')
fi
echo "tag_id=$TAG_ID" >> "$GITHUB_OUTPUT"
echo "Resolved tag ID: $TAG_ID"
- name: Create YouTrack issue
id: create-issue
env:
ISSUE_TITLE: ${{ github.event.issue.title }}
ISSUE_BODY: ${{ github.event.issue.body }}
ISSUE_URL: ${{ github.event.issue.html_url }}
YT_TYPE: ${{ steps.map-type.outputs.yt_type }}
run: |
echo "Creating YouTrack issue for: $ISSUE_TITLE"
echo " Type: $YT_TYPE"
echo " Source: $ISSUE_URL"
DESCRIPTION="$(printf 'Original GitHub issue: %s\n\n---\n\n%s' "$ISSUE_URL" "$ISSUE_BODY")"
PAYLOAD=$(jq -n \
--arg summary "[GitHub] $ISSUE_TITLE" \
--arg description "$DESCRIPTION" \
--arg type "$YT_TYPE" \
'{
project: { shortName: "KRPC" },
summary: $summary,
description: $description,
customFields: [
{
name: "Type",
"$type": "SingleEnumIssueCustomField",
value: { name: $type }
},
{
name: "Scope",
"$type": "MultiEnumIssueCustomField",
value: [{ name: "Other" }]
}
]
}')
echo "Request payload:"
echo "$PAYLOAD" | jq .
RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST \
-H "Authorization: Bearer $YOUTRACK_TOKEN" \
-H "Content-Type: application/json" \
-d "$PAYLOAD" \
"$YOUTRACK_URL/api/issues?fields=idReadable")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | sed '$d')
echo "YouTrack API response (HTTP $HTTP_CODE): $BODY"
if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -ge 300 ]; then
echo "::error::Failed to create YouTrack issue (HTTP $HTTP_CODE): $BODY"
exit 1
fi
ISSUE_ID=$(echo "$BODY" | jq -r '.idReadable')
echo "issue_id=$ISSUE_ID" >> "$GITHUB_OUTPUT"
echo "Created YouTrack issue: $ISSUE_ID"
- name: Tag issue with github-issue
env:
ISSUE_ID: ${{ steps.create-issue.outputs.issue_id }}
TAG_ID: ${{ steps.resolve-tag.outputs.tag_id }}
run: |
echo "Tagging $ISSUE_ID with 'github-issue' (tag ID: $TAG_ID)..."
RESPONSE=$(curl -s -w "\n%{http_code}" \
-X POST \
-H "Authorization: Bearer $YOUTRACK_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"id\": \"$TAG_ID\"}" \
"$YOUTRACK_URL/api/issues/$ISSUE_ID/tags")
HTTP_CODE=$(echo "$RESPONSE" | tail -1)
BODY=$(echo "$RESPONSE" | sed '$d')
if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -ge 300 ]; then
echo "::error::Failed to tag issue $ISSUE_ID (HTTP $HTTP_CODE): $BODY"
exit 1
fi
echo "Tagged $ISSUE_ID with 'github-issue'"