-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathlinear-task-review.js
More file actions
237 lines (203 loc) · 6.57 KB
/
linear-task-review.js
File metadata and controls
237 lines (203 loc) · 6.57 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
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
#!/usr/bin/env node
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import dotenv from 'dotenv';
const __dirname = path.dirname(fileURLToPath(import.meta.url));
dotenv.config({
path: path.join(__dirname, '..', '.env'),
silent: true
});
async function queryLinear(query, variables = {}) {
const response = await fetch('https://api.linear.app/graphql', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': process.env.STACKMEMORY_LINEAR_API_KEY || process.env.LINEAR_API_KEY
},
body: JSON.stringify({ query, variables })
});
const data = await response.json();
if (data.errors) {
throw new Error(data.errors[0].message);
}
return data.data;
}
async function reviewTasks() {
console.log('📋 LINEAR TASK REVIEW\n' + '='.repeat(50));
try {
// Get viewer info
const viewerData = await queryLinear(`
query {
viewer {
name
email
}
}
`);
console.log(`👤 Logged in as: ${viewerData.viewer.name || viewerData.viewer.email}\n`);
// Get all active issues
const issuesData = await queryLinear(`
query {
issues(
filter: {
state: { type: { in: ["started", "unstarted"] } }
}
orderBy: updatedAt
first: 100
) {
nodes {
identifier
title
priority
priorityLabel
createdAt
updatedAt
state {
name
type
}
assignee {
name
email
}
labels {
nodes {
name
color
}
}
estimate
url
}
}
}
`);
const issues = issuesData.issues.nodes;
// Group by state
const byState = {};
issues.forEach(issue => {
const stateName = issue.state.name;
if (!byState[stateName]) byState[stateName] = [];
byState[stateName].push(issue);
});
// Priority mapping
const priorityLabels = {
0: '🔴 No Priority',
1: '🔴 Urgent',
2: '🟠 High',
3: '🟡 Medium',
4: '🔵 Low'
};
// Display by state
const stateOrder = ['In Progress', 'Todo', 'Triage', 'Backlog'];
stateOrder.forEach(state => {
if (byState[state] && byState[state].length > 0) {
console.log(`\n📊 ${state.toUpperCase()} (${byState[state].length} tasks)`);
console.log('-'.repeat(50));
byState[state]
.sort((a, b) => (a.priority || 5) - (b.priority || 5))
.slice(0, 10)
.forEach(issue => {
const priority = priorityLabels[issue.priority] || '⚪ None';
const assignee = issue.assignee ? `👤 ${issue.assignee.name}` : '👤 Unassigned';
const labels = issue.labels.nodes.map(l => l.name).join(', ');
const labelStr = labels ? ` [${labels}]` : '';
console.log(`\n ${issue.identifier}: ${issue.title}`);
console.log(` ${priority} | ${assignee}${labelStr}`);
console.log(` 📎 ${issue.url}`);
});
if (byState[state].length > 10) {
console.log(`\n ... and ${byState[state].length - 10} more tasks`);
}
}
});
// Summary statistics
console.log('\n' + '='.repeat(50));
console.log('📈 SUMMARY STATISTICS\n');
const inProgress = byState['In Progress']?.length || 0;
const todo = byState['Todo']?.length || 0;
const triage = byState['Triage']?.length || 0;
const backlog = byState['Backlog']?.length || 0;
console.log(` 🏃 In Progress: ${inProgress}`);
console.log(` 📝 Todo: ${todo}`);
console.log(` 🔍 Triage: ${triage}`);
console.log(` 📦 Backlog: ${backlog}`);
console.log(` 📊 Total Active: ${issues.length}`);
// High priority items
const urgent = issues.filter(i => i.priority === 1);
const high = issues.filter(i => i.priority === 2);
if (urgent.length > 0) {
console.log('\n🚨 URGENT PRIORITY TASKS:');
urgent.forEach(issue => {
const state = issue.state.name;
const assignee = issue.assignee?.name || 'Unassigned';
console.log(` • ${issue.identifier}: ${issue.title} [${state}] - ${assignee}`);
});
}
if (high.length > 0) {
console.log('\n🔥 HIGH PRIORITY TASKS:');
high.slice(0, 5).forEach(issue => {
const state = issue.state.name;
const assignee = issue.assignee?.name || 'Unassigned';
console.log(` • ${issue.identifier}: ${issue.title} [${state}] - ${assignee}`);
});
}
// Recommendations
console.log('\n' + '='.repeat(50));
console.log('💡 RECOMMENDED NEXT ACTIONS:\n');
// Find tasks to work on
const recommendations = [];
// 1. In-progress tasks that need completion
const myInProgress = issues.filter(i =>
i.state.name === 'In Progress' &&
(!i.assignee || i.assignee.name === viewerData.viewer.name)
);
if (myInProgress.length > 0) {
recommendations.push({
reason: '🏃 Continue in-progress work',
tasks: myInProgress.slice(0, 2)
});
}
// 2. High priority unassigned todos
const highPriorityTodos = issues.filter(i =>
i.state.name === 'Todo' &&
i.priority <= 2 &&
!i.assignee
);
if (highPriorityTodos.length > 0) {
recommendations.push({
reason: '🔥 High priority unassigned tasks',
tasks: highPriorityTodos.slice(0, 2)
});
}
// 3. Any todo tasks
const todoTasks = issues.filter(i =>
i.state.name === 'Todo' &&
!i.assignee
);
if (todoTasks.length > 0 && recommendations.length < 2) {
recommendations.push({
reason: '📝 Available todo tasks',
tasks: todoTasks.slice(0, 2)
});
}
if (recommendations.length > 0) {
recommendations.forEach(rec => {
console.log(rec.reason);
rec.tasks.forEach(task => {
const priority = priorityLabels[task.priority] || '⚪ None';
console.log(` └─ ${task.identifier}: ${task.title}`);
console.log(` ${priority} | ${task.url}`);
});
console.log('');
});
} else {
console.log('✅ No immediate tasks requiring attention');
}
} catch (error) {
console.error('❌ Error:', error.message);
process.exit(1);
}
}
reviewTasks();