-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathfetch-linear-status.js
More file actions
125 lines (103 loc) · 4.76 KB
/
fetch-linear-status.js
File metadata and controls
125 lines (103 loc) · 4.76 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
#!/usr/bin/env node
import 'dotenv/config';
import { LinearClient } from '@linear/sdk';
const API_KEY = process.env.LINEAR_API_KEY;
if (!API_KEY) {
console.error('❌ LINEAR_API_KEY not found in environment');
process.exit(1);
}
async function fetchLinearTasks() {
const client = new LinearClient({ apiKey: API_KEY });
try {
const me = await client.viewer;
console.log(`\n👤 Connected as: ${me.name || me.email}\n`);
// Get teams
const teams = await client.teams();
console.log(`📋 Teams: ${teams.nodes.map(t => t.key).join(', ')}\n`);
// Fetch all issues
const issues = await client.issues({
filter: {
state: {
name: { nin: ["Done", "Canceled"] }
}
},
orderBy: "priority"
});
// Group by state
const byState = {};
for (const issue of issues.nodes) {
const state = issue.state?.name || 'Unknown';
if (!byState[state]) byState[state] = [];
byState[state].push(issue);
}
// Display by state
const stateOrder = ['In Progress', 'Todo', 'Triage', 'Backlog', 'Unknown'];
for (const state of stateOrder) {
if (byState[state] && byState[state].length > 0) {
console.log(`📊 ${state.toUpperCase()} (${byState[state].length}):`);
// Show top 10 from each state
const topIssues = byState[state].slice(0, 10);
for (const issue of topIssues) {
const priority = issue.priority ? `[P${issue.priority}]` : '';
const assignee = issue.assignee ? `@${issue.assignee.name}` : '[Unassigned]';
const labels = issue.labels ? (await issue.labels()).nodes.map(l => l.name).join(', ') : '';
const labelStr = labels ? ` 🏷️ ${labels}` : '';
console.log(` • ${issue.identifier}: ${issue.title} ${priority} ${assignee}${labelStr}`);
}
if (byState[state].length > 10) {
console.log(` ... and ${byState[state].length - 10} more`);
}
console.log('');
}
}
// Summary stats
const total = issues.nodes.length;
const inProgress = byState['In Progress']?.length || 0;
const todo = byState['Todo']?.length || 0;
const triage = byState['Triage']?.length || 0;
console.log('📈 SUMMARY:');
console.log(` Total active issues: ${total}`);
console.log(` In Progress: ${inProgress}`);
console.log(` Todo: ${todo}`);
console.log(` Triage: ${triage}`);
// High priority items
console.log('\n🔥 HIGH PRIORITY ITEMS:');
const highPriority = issues.nodes
.filter(i => i.priority && i.priority <= 2)
.slice(0, 5);
for (const issue of highPriority) {
const state = issue.state?.name || 'Unknown';
const assignee = issue.assignee ? `@${issue.assignee.name}` : '[Unassigned]';
console.log(` • ${issue.identifier}: ${issue.title} [${state}] ${assignee}`);
}
// Suggested next tasks
console.log('\n💡 SUGGESTED NEXT TASKS:');
console.log('Based on priority and status, consider working on:');
// Find unassigned high priority or in-progress items
const suggestions = issues.nodes
.filter(i => {
const isHighPriority = i.priority && i.priority <= 2;
const isInProgress = i.state?.name === 'In Progress';
const isTodo = i.state?.name === 'Todo';
const isUnassigned = !i.assignee;
return (isHighPriority || isInProgress) && (isTodo || isInProgress);
})
.slice(0, 3);
if (suggestions.length > 0) {
for (const issue of suggestions) {
const state = issue.state?.name || 'Unknown';
const priority = issue.priority ? `P${issue.priority}` : 'No priority';
console.log(` 1. ${issue.identifier}: ${issue.title}`);
console.log(` Status: ${state}, Priority: ${priority}`);
console.log(` URL: https://linear.app/issue/${issue.identifier}`);
console.log('');
}
} else {
console.log(' No high-priority unassigned tasks found.');
}
} catch (error) {
console.error('Error fetching Linear tasks:', error.message);
process.exit(1);
}
}
fetchLinearTasks();