1
1
async function loadWidget ( widgetSettings , organization , projectName ) {
2
- consoleLog ( `WidgetSettings inside loadWidget: ${ JSON . stringify ( widgetSettings ) } ` ) ;
3
- consoleLog ( `Running for organization [${ organization } ], projectName [${ projectName } ]` ) ;
2
+ consoleLog ( `WidgetSettings inside loadWidget: ${ JSON . stringify ( widgetSettings ) } ` )
3
+ consoleLog ( `Running for organization [${ organization } ], projectName [${ projectName } ]` )
4
4
5
5
// data contains a stringified json object, so we need to make a json object from it
6
- const data = JSON . parse ( widgetSettings . customSettings . data ) ;
6
+ const data = JSON . parse ( widgetSettings . customSettings . data )
7
7
8
8
// init with default values
9
9
let alerts = {
10
10
dependencyAlerts : 0 ,
11
11
secretAlerts : 0 ,
12
12
codeAlerts : 0
13
- } ;
14
- let linkBase = 'https://dev.azure.com' ;
13
+ }
14
+ let linkBase = 'https://dev.azure.com'
15
15
16
16
if ( data && data . repo ) {
17
- const repoName = data . repo ;
18
- const repoId = data . repoId ;
19
- consoleLog ( 'loaded repoName from widgetSettings: ' + repoName ) ;
17
+ const repoName = data . repo
18
+ const repoId = data . repoId
19
+ consoleLog ( 'loaded repoName from widgetSettings: ' + repoName )
20
20
21
21
// set the tile
22
- var title = $ ( 'h2.ghazdo-title' ) ;
23
- title . text ( `Security Alerts for ${ repoName } ` ) ;
24
- title . attr ( 'title' , repoName ) ;
25
- alerts = ( await getAlerts ( organization , projectName , repoId ) ) . values ;
26
- consoleLog ( 'alerts: ' + JSON . stringify ( alerts ) ) ;
22
+ var title = $ ( 'h2.ghazdo-title' )
23
+ title . text ( `Security Alerts for ${ repoName } ` )
24
+ title . attr ( 'title' , repoName )
25
+ alerts = ( await getAlerts ( organization , projectName , repoId ) ) . values
26
+ consoleLog ( 'alerts: ' + JSON . stringify ( alerts ) )
27
27
28
28
// GHAS is only available on the SaaS version, so we can hardcode the domain
29
- linkBase = `https://dev.azure.com/${ organization } /${ projectName } /_git/${ repoName } /alerts` ;
29
+ linkBase = `https://dev.azure.com/${ organization } /${ projectName } /_git/${ repoName } /alerts`
30
+
31
+ // set the color
32
+ const color = data . color ? data . color : '#68217a' // default to purple
33
+ const widget = document . getElementById ( 'GHAzDo-widget' )
34
+ widget . style . backgroundColor = `${ color } `
30
35
}
31
36
else {
32
37
consoleLog ( 'configuration is needed first, opening with empty values' ) ;
33
38
// set the tile to indicate config is needed
34
- var title = $ ( 'h2.ghazdo-title' ) ;
35
- title . text ( `Configure the widget to get Security Alerts` ) ;
39
+ var title = $ ( 'h2.ghazdo-title' )
40
+ title . text ( `Configure the widget to get Security Alerts` )
36
41
}
37
42
38
43
// set the alert counts
39
- var dependencyAlertCount = $ ( 'p.dependencyAlertCount' ) ;
40
- dependencyAlertCount . text ( alerts . dependencyAlerts ) ;
41
- const dependencyLinkValue = `${ linkBase } ?_t=dependencies` ;
42
- const dependencyLink = $ ( 'a.dependency-link' ) ;
43
- dependencyLink . attr ( 'href' , dependencyLinkValue ) ;
44
-
45
- var secretAlertCount = $ ( 'p.secretAlertCount' ) ;
46
- secretAlertCount . text ( alerts . secretAlerts ) ;
47
- const secretLinkValue = `${ linkBase } ?_t=secrets` ;
48
- const secretLink = $ ( 'a.secret-link' ) ;
49
- secretLink . attr ( 'href' , secretLinkValue ) ;
50
-
51
- var codeAlertCount = $ ( 'p.codeAlertCount' ) ;
52
- codeAlertCount . text ( alerts . codeAlerts ) ;
53
- const codeLinkValue = `${ linkBase } ?_t=codescanning` ;
54
- const codeLink = $ ( 'a.code-link' ) ;
55
- codeLink . attr ( 'href' , codeLinkValue ) ;
44
+ var dependencyAlertCount = $ ( 'p.dependencyAlertCount' )
45
+ dependencyAlertCount . text ( alerts . dependencyAlerts )
46
+ const dependencyLinkValue = `${ linkBase } ?_t=dependencies`
47
+ const dependencyLink = $ ( 'a.dependency-link' )
48
+ dependencyLink . attr ( 'href' , dependencyLinkValue )
49
+
50
+ var secretAlertCount = $ ( 'p.secretAlertCount' )
51
+ secretAlertCount . text ( alerts . secretAlerts )
52
+ const secretLinkValue = `${ linkBase } ?_t=secrets`
53
+ const secretLink = $ ( 'a.secret-link' )
54
+ secretLink . attr ( 'href' , secretLinkValue )
55
+
56
+ var codeAlertCount = $ ( 'p.codeAlertCount' )
57
+ codeAlertCount . text ( alerts . codeAlerts )
58
+ const codeLinkValue = `${ linkBase } ?_t=codescanning`
59
+ const codeLink = $ ( 'a.code-link' )
60
+ codeLink . attr ( 'href' , codeLinkValue )
56
61
}
0 commit comments