-
Notifications
You must be signed in to change notification settings - Fork 71
Expand file tree
/
Copy pathactions.ts
More file actions
120 lines (109 loc) · 3.34 KB
/
actions.ts
File metadata and controls
120 lines (109 loc) · 3.34 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
import { open } from "@opensrc/deno-open"
import {
fetchIssueDetails,
getIssueIdentifier,
getStartedState,
getTeamKey,
updateIssueState,
} from "./linear.ts"
import { getOption } from "../config.ts"
import { encodeBase64 } from "@std/encoding/base64"
import { getNoIssueFoundMessage, startVcsWork } from "./vcs.ts"
import { gql } from "../__codegen__/gql.ts"
import { getGraphQLClient } from "./graphql.ts"
export async function openIssuePage(
providedId?: string,
options: { app?: boolean; web?: boolean } = {},
) {
const issueId = await getIssueIdentifier(providedId)
if (!issueId) {
console.error(getNoIssueFoundMessage())
Deno.exit(1)
}
const workspace = getOption("workspace")
if (!workspace) {
console.error(
"workspace is not set via command line, configuration file, or environment.",
)
Deno.exit(1)
}
const url = `https://linear.app/${workspace}/issue/${issueId}`
const destination = options.app ? "Linear.app" : "web browser"
console.log(`Opening ${url} in ${destination}`)
await open(url, options.app ? { app: { name: "Linear" } } : undefined)
}
export async function openProjectPage(
projectId: string,
options: { app?: boolean; web?: boolean } = {},
) {
const workspace = getOption("workspace")
if (!workspace) {
console.error(
"workspace is not set via command line, configuration file, or environment.",
)
Deno.exit(1)
}
const url = `https://linear.app/${workspace}/project/${projectId}`
const destination = options.app ? "Linear.app" : "web browser"
console.log(`Opening ${url} in ${destination}`)
await open(url, options.app ? { app: { name: "Linear" } } : undefined)
}
export async function openTeamAssigneeView(
options: { app?: boolean; team?: string } = {},
) {
const teamId = options.team ?? getTeamKey()
if (!teamId) {
console.error(
"Could not determine team id from configuration or directory name.",
)
Deno.exit(1)
}
let workspace = getOption("workspace")
if (!workspace) {
const client = getGraphQLClient()
const viewerQuery = gql(`
query GetViewerWorkspace {
viewer {
organization {
urlKey
}
}
}
`)
const result = await client.request(viewerQuery)
workspace = result.viewer.organization.urlKey
}
const filterObj = {
"and": [{ "assignee": { "or": [{ "isMe": { "eq": true } }] } }],
}
const filter = encodeBase64(JSON.stringify(filterObj)).replace(/=/g, "")
const url =
`https://linear.app/${workspace}/team/${teamId}/active?filter=${filter}`
await open(url, options.app ? { app: { name: "Linear" } } : undefined)
}
export async function startWorkOnIssue(
issueId: string,
teamId: string,
gitSourceRef?: string,
customBranchName?: string,
) {
const { branchName: defaultBranchName } = await fetchIssueDetails(
issueId,
true,
)
const branchName = customBranchName || defaultBranchName
// Start VCS work (git or jj)
await startVcsWork(issueId, branchName, gitSourceRef)
// Update issue state
try {
const state = await getStartedState(teamId)
if (!issueId) {
console.error("No issue ID resolved")
Deno.exit(1)
}
await updateIssueState(issueId, state.id)
console.log(`✓ Issue state updated to '${state.name}'`)
} catch (error) {
console.error("Failed to update issue state:", error)
}
}