Skip to content

Commit b2dc825

Browse files
fix: resolve Linear team key to UUID and fail on errors
Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
1 parent 84aec35 commit b2dc825

File tree

1 file changed

+40
-3
lines changed

1 file changed

+40
-3
lines changed

.github/workflows/changelog-to-linear.yml

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,12 +111,12 @@ jobs:
111111
});
112112
}
113113
114-
async function createIssue(feature, version, date) {
114+
async function createIssue(feature, version, date, teamId) {
115115
const dueDate = new Date();
116116
dueDate.setDate(dueDate.getDate() + 7);
117117
118118
const input = {
119-
teamId: LINEAR_TEAM_ID,
119+
teamId: teamId,
120120
title: `[${version}] ${feature.title}`,
121121
description: `**From changelog (${date})**\n\n${feature.description || 'No additional description.'}\n\n---\n*Auto-created from changelog*`,
122122
dueDate: dueDate.toISOString().split('T')[0],
@@ -129,6 +129,20 @@ jobs:
129129
return makeLinearRequest(mutation, { input });
130130
}
131131
132+
async function getTeamId(teamKeyOrId) {
133+
// If it's already a UUID, return it
134+
const uuidRegex = /^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/i;
135+
if (uuidRegex.test(teamKeyOrId)) return teamKeyOrId;
136+
137+
// Otherwise, look up the team by key
138+
const query = `query { teams { nodes { id key name } } }`;
139+
const result = await makeLinearRequest(query, {});
140+
const team = result.teams?.nodes?.find(t => t.key === teamKeyOrId);
141+
if (!team) throw new Error(`Team with key "${teamKeyOrId}" not found`);
142+
console.log(`Resolved team key "${teamKeyOrId}" to UUID: ${team.id}`);
143+
return team.id;
144+
}
145+
132146
async function main() {
133147
if (!LINEAR_TEAM_ID) { console.error('LINEAR_TEAM_ID required'); process.exit(1); }
134148
@@ -140,16 +154,39 @@ jobs:
140154
141155
console.log(`Found ${changelog.features.length} features in ${changelog.version} (${changelog.date})`);
142156
157+
// Resolve team key to UUID if needed
158+
let teamId;
159+
try {
160+
teamId = await getTeamId(LINEAR_TEAM_ID);
161+
} catch (error) {
162+
console.error(`Failed to resolve team ID: ${error.message}`);
163+
process.exit(1);
164+
}
165+
166+
let successCount = 0;
167+
let errorCount = 0;
168+
143169
for (const feature of changelog.features) {
144170
try {
145-
const result = await createIssue(feature, changelog.version, changelog.date);
171+
const result = await createIssue(feature, changelog.version, changelog.date, teamId);
146172
if (result.issueCreate?.success) {
147173
console.log(`Created: ${result.issueCreate.issue.identifier} - ${result.issueCreate.issue.url}`);
174+
successCount++;
175+
} else {
176+
console.error(`Failed to create ticket for ${feature.title}: unexpected response`);
177+
errorCount++;
148178
}
149179
} catch (error) {
150180
console.error(`Error creating ticket for ${feature.title}: ${error.message}`);
181+
errorCount++;
151182
}
152183
}
184+
185+
console.log(`\nSummary: ${successCount} created, ${errorCount} failed`);
186+
if (errorCount > 0) {
187+
console.error('Some tickets failed to create');
188+
process.exit(1);
189+
}
153190
}
154191
main();
155192
EOF

0 commit comments

Comments
 (0)