Skip to content

Commit df9d5cf

Browse files
committed
Require commit SHA for extension updates and propagate latest version SHA through update info and handlers
- when updating to latest, should still use sha, just like when installing specific version. this makes sha for updating required (it's always on the tags api reponse) - 'update extension' should accept params variable (object) ├── apps │ └── editor │ └── src │ ├── commands │ │ ├── check-for-updates-command.ts │ │ └── install-specific-version-command.ts │ ├── utils │ │ ├── check-for-updates.ts │ │ └── update-extension.ts │ └── views │ └── prompt │ ├── backend │ │ ├── message-handlers │ │ │ └── handle-update-extension.ts │ │ └── prompt-view-provider.ts │ ├── frontend │ │ └── Home │ │ └── Home.tsx │ └── types │ └── messages.ts ├── install.ps1 └── install.sh
1 parent a681175 commit df9d5cf

7 files changed

Lines changed: 23 additions & 11 deletions

File tree

‎apps/editor/src/commands/check-for-updates-command.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,11 @@ export const check_for_updates_command = (
1717
)
1818

1919
if (action === t('command.check-for-updates-command.action.update')) {
20-
update_extension()
20+
if (prompt_view_provider.update_info.latest_version_sha) {
21+
update_extension({
22+
commit_sha: prompt_view_provider.update_info.latest_version_sha
23+
})
24+
}
2125
}
2226
} else {
2327
vscode.window.showInformationMessage(

‎apps/editor/src/commands/install-specific-version-command.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,9 +159,9 @@ export const install_specific_version_command = () => {
159159

160160
quick_pick.onDidAccept(() => {
161161
const selected = quick_pick.selectedItems[0]
162-
if (selected) {
162+
if (selected && selected.sha) {
163163
quick_pick.hide()
164-
update_extension(selected.sha)
164+
update_extension({ commit_sha: selected.sha })
165165
}
166166
})
167167

‎apps/editor/src/utils/check-for-updates.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export const check_for_updates = async (
5656
return {
5757
is_available: true,
5858
latest_version,
59+
latest_version_sha: vscode_tag.commit?.sha,
5960
current_version_age_days: age_days
6061
}
6162
} else {
Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
11
import * as vscode from 'vscode'
22
import * as os from 'os'
33

4-
export const update_extension = (sha?: string) => {
4+
export const update_extension = (params: { commit_sha: string }) => {
55
const terminal = vscode.window.createTerminal('CWC Updater')
66
terminal.show()
77

8-
const uriScheme = vscode.env.uriScheme
8+
const uri_scheme = vscode.env.uriScheme
99
const lang = vscode.env.language
10-
const commitSha = sha || ''
1110

1211
if (os.platform() === 'win32') {
1312
terminal.sendText(
14-
`powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.ps1))) '${uriScheme}' '${lang}' '${commitSha}'"`
13+
`powershell -c "& ([scriptblock]::Create((irm https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.ps1))) '${uri_scheme}' '${lang}' '${params.commit_sha}'"`
1514
)
1615
} else {
1716
terminal.sendText(
18-
`curl -fsSL https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.sh | bash -s -- "${uriScheme}" "${lang}" "${commitSha}"`
17+
`curl -fsSL https://raw.githubusercontent.com/CodeWebChat/CWC/main/install.sh | bash -s -- "${uri_scheme}" "${lang}" "${params.commit_sha}"`
1918
)
2019
}
2120
}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { update_extension } from '@/utils/update-extension'
2+
import { PromptViewProvider } from '../prompt-view-provider'
23

3-
export const handle_update_extension = () => {
4-
update_extension()
4+
export const handle_update_extension = (
5+
prompt_view_provider: PromptViewProvider
6+
) => {
7+
if (prompt_view_provider.update_info.latest_version_sha) {
8+
update_extension({
9+
commit_sha: prompt_view_provider.update_info.latest_version_sha
10+
})
11+
}
512
}

‎apps/editor/src/views/prompt/backend/prompt-view-provider.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ export class PromptViewProvider implements vscode.WebviewViewProvider {
840840
} else if (message.command === 'CLEAR_COMPLETED_TASKS') {
841841
await handlers.handle_clear_completed_tasks(this)
842842
} else if (message.command === 'UPDATE_EXTENSION') {
843-
handlers.handle_update_extension()
843+
handlers.handle_update_extension(this)
844844
} else if (message.command === 'GET_UPDATE_INFO') {
845845
this.send_message({
846846
command: 'UPDATE_INFO',

‎apps/editor/src/views/prompt/types/messages.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,6 +458,7 @@ export interface SaveTasksMessage extends BaseMessage {
458458
export type UpdateInfo = {
459459
is_available: boolean
460460
latest_version?: string
461+
latest_version_sha?: string
461462
current_version_age_days?: number
462463
}
463464

0 commit comments

Comments
 (0)