@@ -2,7 +2,7 @@ import express from 'express';
2
2
import createError from 'http-errors' ;
3
3
import badgen from 'badgen' ;
4
4
import { get_registry_info } from '../src/tools.js' ;
5
- import { get_distinct } from '../src/db.js' ;
5
+ import { get_distinct , get_package_info } from '../src/db.js' ;
6
6
7
7
const router = express . Router ( ) ;
8
8
@@ -88,4 +88,49 @@ router.get('/:package/badges/version', function(req, res, next) {
88
88
} ) ;
89
89
} ) ;
90
90
91
+ function check_result ( pkg ) {
92
+ let results = [ ] ;
93
+ if ( pkg . _failure || pkg . _status == 'failure' )
94
+ return 'FAILURE' ;
95
+ for ( var bin of pkg . _binaries ) {
96
+ if ( ! bin . check )
97
+ continue ; //ignore wasm
98
+ if ( bin . r < pkg . _rbuild )
99
+ continue //ignore oldrel
100
+ if ( bin . commit != pkg . _commit . id )
101
+ return 'FAILURE' //no binary for this commit?
102
+ results . push ( bin . check )
103
+ }
104
+ if ( results . includes ( 'ERROR' ) )
105
+ return 'ERROR'
106
+ if ( results . includes ( 'WARNING' ) )
107
+ return 'WARNING'
108
+ if ( results . includes ( 'NOTE' ) )
109
+ return 'NOTE'
110
+ return results . length ? 'OK' : 'FAILURE' ;
111
+ }
112
+
113
+ router . get ( '/:package/badges/checks' , function ( req , res , next ) {
114
+ var user = res . locals . universe ;
115
+ var pkg = req . params . package ;
116
+ var color = req . query . color ;
117
+ var badge = {
118
+ label : 'r-universe' ,
119
+ status : 'unavailable' ,
120
+ color : color || 'red' ,
121
+ style : req . query . style ,
122
+ scale : req . query . scale
123
+ } ;
124
+ return get_package_info ( pkg , user ) . then ( function ( x ) {
125
+ badge . status = check_result ( x ) ;
126
+ if ( badge . status == 'WARNING' ) {
127
+ badge . color = color || 'orange' ;
128
+ }
129
+ if ( badge . status == 'NOTE' || badge . status == 'OK' ) {
130
+ badge . color = color || 'green' ;
131
+ }
132
+ send_badge ( badge , user , res , x . _buildurl ) ;
133
+ } ) ;
134
+ } ) ;
135
+
91
136
export default router ;
0 commit comments