@@ -21,23 +21,34 @@ const config = {
21
21
sendSince : new Date ( "2025-08-02T00:00:00Z" ) . toISOString ( ) , // only send notifications for releases after this date (UTC)
22
22
} ;
23
23
24
- type GithubReleaseNotificationTask = {
24
+ const coreVersionPattern = / U p d a t e C o m f y U I c o r e t o ( v \S + ) / ;
25
+ export type GithubReleaseNotificationTask = {
25
26
url : string ; // github release url
26
27
version ?: string ; // released version, e.g. v1.0.0, v2.0.0-beta.1
28
+ coreVersion ?: string ; // for desktop repo, match /Update ComfyUI core to (v\S+)/
27
29
createdAt : Date ;
28
30
releasedAt ?: Date ;
29
31
isStable ?: boolean ; // true if the release is stable, false if it's a pre-release
30
32
status : "draft" | "prerelease" | "stable" ;
31
33
32
- // drafted/pre-release message
34
+ // when it's drafting/pre-release
35
+ slackMessageDrafting ?: {
36
+ text : string ;
37
+ channel : string ;
38
+ url ?: string ; // set after sent
39
+ } ;
40
+
41
+ // send when it's stable, will reply the drafting url if there are one
33
42
slackMessage ?: {
34
43
text : string ;
35
44
channel : string ;
36
45
url ?: string ; // set after sent
37
46
} ;
38
47
} ;
39
48
40
- const GithubReleaseNotificationTask = db . collection < GithubReleaseNotificationTask > ( "GithubReleaseNotificationTask" ) ;
49
+ export const GithubReleaseNotificationTask = db . collection < GithubReleaseNotificationTask > (
50
+ "GithubReleaseNotificationTask" ,
51
+ ) ;
41
52
await GithubReleaseNotificationTask . createIndex ( { url : 1 } , { unique : true } ) ;
42
53
const save = async ( task : { url : string } & Partial < GithubReleaseNotificationTask > ) =>
43
54
( await GithubReleaseNotificationTask . findOneAndUpdate (
@@ -80,9 +91,13 @@ async function runGithubDesktopReleaseNotificationTask() {
80
91
status : status ,
81
92
isStable : status == "stable" ,
82
93
version : release . tag_name ,
94
+ coreVersion : ( release . body || release . body_text ) ?. match ( coreVersionPattern ) ?. [ 1 ] ,
83
95
createdAt : new Date ( release . created_at || DIE ( "no created_at in release, " + JSON . stringify ( release ) ) ) ,
84
96
releasedAt : ! release . published_at ? undefined : new Date ( release . published_at ) ,
85
97
} ) ;
98
+ const coreTask = ! task . coreVersion
99
+ ? undefined
100
+ : await GithubReleaseNotificationTask . findOne ( { version : task . coreVersion } ) ;
86
101
87
102
if ( + task . createdAt ! < + new Date ( config . sendSince ) ) return task ; // skip releases before the sendSince date
88
103
@@ -95,17 +110,29 @@ async function runGithubDesktopReleaseNotificationTask() {
95
110
. replace ( "{status}" , task . status ) ,
96
111
} ;
97
112
98
- const anyExistedMsg = task . slackMessage ;
113
+ // upsert drafting message if new/changed
114
+ const shouldSendDraftingMessage = ! task . isStable || task . slackMessageDrafting ?. url ;
115
+ if ( shouldSendDraftingMessage && task . slackMessage ?. text ?. trim ( ) !== newSlackMessage . text . trim ( ) ) {
116
+ task = await save ( {
117
+ url,
118
+ slackMessage : await upsertSlackMessage ( {
119
+ ...newSlackMessage ,
120
+ replyUrl : coreTask ?. slackMessageDrafting ?. url ,
121
+ } ) ,
122
+ } ) ;
123
+ }
99
124
100
- // upsert message if new/changed
101
- const shouldSendMessage = task . isStable || anyExistedMsg ?. url ;
102
- if ( shouldSendMessage && anyExistedMsg ?. text ?. trim ( ) !== newSlackMessage . text . trim ( ) ) {
103
- console . log (
104
- anyExistedMsg ?. text !== newSlackMessage . text ,
105
- JSON . stringify ( anyExistedMsg ?. text ) ,
106
- JSON . stringify ( newSlackMessage . text ) ,
107
- ) ;
108
- task = await save ( { url, slackMessage : await upsertSlackMessage ( newSlackMessage ) } ) ;
125
+ // upsert stable message if new/changed
126
+ const shouldSendMessage = task . isStable || task . slackMessage ?. url ;
127
+ if ( shouldSendMessage && task . slackMessage ?. text ?. trim ( ) !== newSlackMessage . text . trim ( ) ) {
128
+ task = await save ( {
129
+ url,
130
+ slackMessage : await upsertSlackMessage ( {
131
+ ...newSlackMessage ,
132
+ replyUrl :
133
+ coreTask ?. slackMessageDrafting ?. url || coreTask ?. slackMessage ?. url || task . slackMessageDrafting ?. url ,
134
+ } ) ,
135
+ } ) ;
109
136
}
110
137
return task ;
111
138
} )
0 commit comments