Skip to content

Commit 776c924

Browse files
iFwucodexfuxiao
authored
fix(extension): stabilize update marker (#332)
Co-authored-by: Codex <noreply@openai.com> Co-authored-by: fuxiao <fuxiao@zyql.com>
1 parent 5d80b91 commit 776c924

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

extension/src/fetch.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@ import { window, workspace } from 'vscode'
44
import { getConfig } from './config'
55
import { FILE, MSG_PREFIX, URL_PREFIX } from './constants'
66

7+
const UPDATE_MARKER_FALLBACK = 'Last update from upstream'
8+
79
export async function fetchLatest() {
810
const repo = getConfig<string>('fileNestingUpdater.upstreamRepo')
911
const branch = getConfig<string>('fileNestingUpdater.upstreamBranch')
1012
const url = `${URL_PREFIX}/${repo}@${branch}/${FILE}`
1113
const md = await fetch(url).then(r => r.text())
1214
const content = (md.match(/```jsonc([\s\S]*?)```/) || [])[1] || ''
15+
const updated = content.match(/^\s*\/\/ updated (.+)$/m)?.[1]?.trim()
1316

1417
const json = `{${
1518
content
@@ -21,12 +24,15 @@ export async function fetchLatest() {
2124
}}`
2225

2326
const config = JSON.parse(json) || {}
24-
return config['explorer.fileNesting.patterns']
27+
return {
28+
patterns: config['explorer.fileNesting.patterns'],
29+
updated,
30+
}
2531
}
2632

2733
export async function fetchAndUpdate(ctx: ExtensionContext, prompt = true) {
2834
const config = workspace.getConfiguration()
29-
const patterns = await fetchLatest()
35+
const { patterns, updated } = await fetchLatest()
3036
let shouldUpdate = true
3137

3238
const oringalPatterns = { ...(config.get<object>('explorer.fileNesting.patterns') || {}) }
@@ -54,7 +60,9 @@ export async function fetchAndUpdate(ctx: ExtensionContext, prompt = true) {
5460
config.update('explorer.fileNesting.expand', false, true)
5561

5662
config.update('explorer.fileNesting.patterns', {
57-
'//': `Last update at ${new Date().toLocaleString()}`,
63+
'//': updated
64+
? `Last update at ${updated} UTC`
65+
: UPDATE_MARKER_FALLBACK,
5866
...patterns,
5967
}, true)
6068

0 commit comments

Comments
 (0)