1+ module . exports = async ( { github, context, backend, mobile, web } ) => {
2+ const owner = context . repo . owner ;
3+ const repo = context . repo . repo ;
4+ const pr = context . payload . pull_request ;
5+ const prNumber = pr . number ;
6+
7+ const statusEmoji = ( status ) => {
8+ if ( status === 'success' ) return '✅' ;
9+ if ( status === 'failure' ) return '❌' ;
10+ if ( status === 'skipped' ) return '⏭️' ;
11+ return '⚪' ;
12+ } ;
13+
14+ const statusLabel = ( status ) => {
15+ if ( status === 'skipped' ) return `${ statusEmoji ( status ) } Skipped — no changes detected` ;
16+ return `${ statusEmoji ( status ) } ${ status } ` ;
17+ } ;
18+
19+ const results = [ backend , mobile , web ] ;
20+ const allSkipped = results . every ( ( s ) => s === 'skipped' ) ;
21+ const anyFailure = results . some ( ( s ) => s === 'failure' ) ;
22+ const allPassed = results . every ( ( s ) => s === 'success' || s === 'skipped' ) ;
23+
24+ let title ;
25+ if ( allSkipped ) {
26+ title = '⏭️ No changes detected — all checks skipped' ;
27+ } else if ( anyFailure ) {
28+ title = '❌ Some checks failed' ;
29+ } else if ( allPassed ) {
30+ title = '✅ All checks passed' ;
31+ } else {
32+ title = '⚪ Checks completed' ;
33+ }
34+
35+ const timestamp = new Date ( ) . toUTCString ( ) ;
36+
37+ const body = `## CI Results — ${ title }
38+
39+ | Check | Status |
40+ |---|---|
41+ | 🖥️ Backend | ${ statusLabel ( backend ) } |
42+ | 📱 Mobile | ${ statusLabel ( mobile ) } |
43+ | 🌐 Web | ${ statusLabel ( web ) } |
44+
45+ > ⏭️ **Skipped** means no files were changed in that area — the check was not needed.
46+
47+ ---
48+ 🕐 Last updated: \`${ timestamp } \`` ;
49+
50+ const COMMENT_MARKER = '## CI Results —' ;
51+
52+ try {
53+ const comments = await github . paginate ( github . rest . issues . listComments , {
54+ owner,
55+ repo,
56+ issue_number : prNumber ,
57+ } ) ;
58+
59+ const existingComment = comments . find (
60+ ( c ) => c . body && c . body . startsWith ( COMMENT_MARKER )
61+ ) ;
62+
63+ if ( existingComment ) {
64+ await github . rest . issues . updateComment ( {
65+ owner,
66+ repo,
67+ comment_id : existingComment . id ,
68+ body,
69+ } ) ;
70+ console . log ( `Updated existing comment: ${ existingComment . id } ` ) ;
71+ } else {
72+ await github . rest . issues . createComment ( {
73+ owner,
74+ repo,
75+ issue_number : prNumber ,
76+ body,
77+ } ) ;
78+ console . log ( 'Created new CI results comment' ) ;
79+ }
80+ } catch ( error ) {
81+ console . error ( 'Failed to post comment:' , error ) ;
82+ }
83+ } ;
0 commit comments