@@ -16,6 +16,50 @@ const is_newer = (latest: string, current: string) => {
1616 return false
1717}
1818
19+ const get_version_age_days = async (
20+ version : string ,
21+ tag_name ?: string
22+ ) : Promise < number > => {
23+ const parts = version . split ( '.' )
24+ if ( parts . length >= 2 ) {
25+ const year = parseInt ( parts [ 0 ] , 10 )
26+ const mmdd = parts [ 1 ]
27+ if ( ! isNaN ( year ) && mmdd . length === 4 ) {
28+ const month = parseInt ( mmdd . substring ( 0 , 2 ) , 10 ) - 1
29+ const day = parseInt ( mmdd . substring ( 2 , 4 ) , 10 )
30+ if ( ! isNaN ( month ) && ! isNaN ( day ) ) {
31+ const version_date = Date . UTC ( year , month , day )
32+ const age_days = Math . floor (
33+ ( Date . now ( ) - version_date ) / ( 1000 * 60 * 60 * 24 )
34+ )
35+ return age_days >= 0 ? age_days : 0
36+ }
37+ }
38+ }
39+
40+ if ( tag_name ) {
41+ try {
42+ const res = await axios . get (
43+ `https://api.github.com/repos/CodeWebChat/CWC/commits/${ tag_name } ` ,
44+ { validateStatus : ( ) => true }
45+ )
46+ if ( res . status === 200 ) {
47+ const date = res . data . commit ?. committer ?. date
48+ if ( date ) {
49+ const age_days = Math . floor (
50+ ( Date . now ( ) - new Date ( date ) . getTime ( ) ) / ( 1000 * 60 * 60 * 24 )
51+ )
52+ return age_days >= 0 ? age_days : 0
53+ }
54+ }
55+ } catch ( e ) {
56+ console . error ( 'Failed to fetch commit date:' , e )
57+ }
58+ }
59+
60+ return Infinity
61+ }
62+
1963export const check_for_updates = async (
2064 provider : PromptViewProvider ,
2165 params ?: { force ?: boolean }
@@ -26,13 +70,17 @@ export const check_for_updates = async (
2670 provider . extension_context . extension . packageJSON . version
2771 if ( ! current_version ) return
2872
73+ const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
74+ const minimum_release_age = force
75+ ? 0
76+ : config . get < number > ( 'minimumReleaseAge' , 0 )
77+
2978 if ( ! force ) {
3079 const last_check = provider . extension_context . globalState . get < number > (
3180 state_keys . LAST_UPDATE_CHECK_TIMESTAMP_STATE_KEY ,
3281 0
3382 )
3483 const now = Date . now ( )
35- const config = vscode . workspace . getConfiguration ( 'codeWebChat' )
3684 const frequency = config . get < 'hourly' | 'daily' | 'weekly' | 'monthly' > (
3785 'updateCheckFrequency' ,
3886 'hourly'
@@ -73,7 +121,10 @@ export const check_for_updates = async (
73121 }
74122 }
75123
76- provider . update_info = await fetch_update_info ( current_version )
124+ provider . update_info = await fetch_update_info (
125+ current_version ,
126+ minimum_release_age
127+ )
77128
78129 provider . extension_context . globalState . update (
79130 state_keys . LAST_UPDATE_CHECK_TIMESTAMP_STATE_KEY ,
@@ -91,7 +142,8 @@ export const check_for_updates = async (
91142}
92143
93144const fetch_update_info = async (
94- current_version : string
145+ current_version : string ,
146+ minimum_release_age : number
95147) : Promise < UpdateInfo > => {
96148 if ( ! current_version ) return { is_available : false }
97149
@@ -106,38 +158,34 @@ const fetch_update_info = async (
106158 const tags = res . data
107159 if ( ! Array . isArray ( tags ) || tags . length === 0 ) break
108160
109- const vscode_tag = tags . find ( ( t : any ) => t . name ?. endsWith ( '-vscode' ) )
110- if ( vscode_tag ) {
111- const latest_version = vscode_tag . name . replace ( '-vscode' , '' )
112- if ( is_newer ( latest_version , current_version ) ) {
113- let age_days = 0
114- try {
115- const commit_res = await axios . get (
116- `https://api.github.com/repos/CodeWebChat/CWC/commits/${ current_version } -vscode` ,
117- { validateStatus : ( ) => true }
118- )
119- if ( commit_res . status === 200 ) {
120- const commit_data = commit_res . data
121- const date = commit_data . commit ?. committer ?. date
122- if ( date ) {
123- age_days = Math . floor (
124- ( Date . now ( ) - new Date ( date ) . getTime ( ) ) /
125- ( 1000 * 60 * 60 * 24 )
126- )
161+ for ( const tag of tags ) {
162+ if ( tag . name ?. endsWith ( '-vscode' ) ) {
163+ const latest_version = tag . name . replace ( '-vscode' , '' )
164+ if ( is_newer ( latest_version , current_version ) ) {
165+ if ( minimum_release_age > 0 ) {
166+ const tag_age_days = await get_version_age_days (
167+ latest_version ,
168+ tag . name
169+ )
170+ if ( tag_age_days < minimum_release_age ) {
171+ continue
127172 }
128173 }
129- } catch ( e ) {
130- console . error ( 'Failed to fetch commit date:' , e )
131- }
132174
133- return {
134- is_available : true ,
135- latest_version,
136- latest_version_tag : vscode_tag . name ,
137- current_version_age_days : age_days
175+ const current_version_age_days = await get_version_age_days (
176+ current_version ,
177+ `${ current_version } -vscode`
178+ )
179+
180+ return {
181+ is_available : true ,
182+ latest_version,
183+ latest_version_tag : tag . name ,
184+ current_version_age_days
185+ }
186+ } else {
187+ return { is_available : false }
138188 }
139- } else {
140- return { is_available : false }
141189 }
142190 }
143191 page ++
0 commit comments