-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug-linear-update.js
More file actions
174 lines (151 loc) · 4.33 KB
/
debug-linear-update.js
File metadata and controls
174 lines (151 loc) · 4.33 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
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
#!/usr/bin/env node
/**
* Debug why Linear updates are failing
*/
import 'dotenv/config';
const API_KEY = process.env.LINEAR_OAUTH_TOKEN || process.env.STACKMEMORY_LINEAR_API_KEY || process.env.LINEAR_API_KEY;
if (!API_KEY) {
console.error('❌ LINEAR_OAUTH_TOKEN or LINEAR_API_KEY environment variable not set');
console.log('Please set LINEAR_OAUTH_TOKEN or LINEAR_API_KEY in your .env file or export it in your shell');
process.exit(1);
}
async function debugLinearUpdate() {
console.log('🔍 Debugging Linear update issues...\n');
// First, test basic API access
console.log('1. Testing API authentication:');
const testQuery = `
query TestAuth {
viewer {
id
email
}
}
`;
let response = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query: testQuery })
});
let result = await response.json();
console.log('Auth result:', JSON.stringify(result, null, 2));
// Get workflow states
console.log('\n2. Fetching workflow states:');
const statesQuery = `
query GetStates {
workflowStates {
nodes {
id
name
type
team {
id
key
}
}
}
}
`;
response = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query: statesQuery })
});
result = await response.json();
console.log('States:', JSON.stringify(result.data?.workflowStates?.nodes || [], null, 2));
// Try to get a specific task
console.log('\n3. Fetching specific task STA-279:');
const taskQuery = `
query GetIssue {
issue(id: "STA-279") {
id
identifier
title
state {
id
name
type
}
}
}
`;
response = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query: taskQuery })
});
result = await response.json();
console.log('Task result:', JSON.stringify(result, null, 2));
// If task exists, try to update it
if (result.data?.issue) {
const task = result.data.issue;
console.log('\n4. Attempting to update task:', task.identifier);
// Find Done state for the same team
const statesResponse = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ query: statesQuery })
});
const statesResult = await statesResponse.json();
const doneState = statesResult.data?.workflowStates?.nodes?.find(s =>
s.type === 'completed' && s.team?.key === 'STA'
);
if (!doneState) {
console.log('❌ Could not find Done state for STA team');
return;
}
console.log('Found Done state:', doneState.id, doneState.name);
const updateMutation = `
mutation UpdateIssue($issueId: String!, $stateId: String!) {
issueUpdate(
id: $issueId,
input: {
stateId: $stateId
}
) {
success
issue {
identifier
state {
name
}
}
}
}
`;
const updateResponse = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Authorization': `Bearer ${API_KEY}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({
query: updateMutation,
variables: {
issueId: task.id,
stateId: doneState.id
}
})
});
const updateResult = await updateResponse.json();
console.log('\nUpdate result:', JSON.stringify(updateResult, null, 2));
if (updateResult.errors) {
console.log('\n❌ Update failed with errors:', updateResult.errors);
} else if (updateResult.data?.issueUpdate?.success) {
console.log('\n✅ Update successful!');
}
}
}
// Run
debugLinearUpdate().catch(console.error);