@@ -7,28 +7,50 @@ import { GitHubVariant, GitHubVersion } from "../util";
77 * Enumerates repository property names that have some meaning to us.
88 */
99export enum RepositoryPropertyName {
10+ DISABLE_OVERLAY = "github-codeql-disable-overlay" ,
1011 EXTRA_QUERIES = "github-codeql-extra-queries" ,
1112}
1213
14+ function isKnownPropertyName ( value : string ) : value is RepositoryPropertyName {
15+ return Object . values ( RepositoryPropertyName ) . includes (
16+ value as RepositoryPropertyName ,
17+ ) ;
18+ }
19+
20+ type AllRepositoryProperties = {
21+ [ RepositoryPropertyName . DISABLE_OVERLAY ] : boolean ;
22+ [ RepositoryPropertyName . EXTRA_QUERIES ] : string ;
23+ } ;
24+
25+ export type RepositoryProperties = Partial < AllRepositoryProperties > ;
26+
27+ const mapRepositoryProperties : {
28+ [ K in RepositoryPropertyName ] : ( value : string ) => AllRepositoryProperties [ K ] ;
29+ } = {
30+ [ RepositoryPropertyName . DISABLE_OVERLAY ] : ( value ) => value === "true" ,
31+ [ RepositoryPropertyName . EXTRA_QUERIES ] : ( value ) => value ,
32+ } ;
33+
34+ function setProperty < K extends RepositoryPropertyName > (
35+ properties : RepositoryProperties ,
36+ name : K ,
37+ value : string ,
38+ ) : void {
39+ properties [ name ] = mapRepositoryProperties [ name ] ( value ) ;
40+ }
41+
1342/**
1443 * A repository property has a name and a value.
1544 */
16- export interface RepositoryProperty {
45+ interface GitHubRepositoryProperty {
1746 property_name : string ;
1847 value : string ;
1948}
2049
2150/**
2251 * The API returns a list of `RepositoryProperty` objects.
2352 */
24- type GitHubPropertiesResponse = RepositoryProperty [ ] ;
25-
26- /**
27- * A partial mapping from `RepositoryPropertyName` to values.
28- */
29- export type RepositoryProperties = Partial <
30- Record < RepositoryPropertyName , string >
31- > ;
53+ export type GitHubPropertiesResponse = GitHubRepositoryProperty [ ] ;
3254
3355/**
3456 * Retrieves all known repository properties from the API.
@@ -62,7 +84,6 @@ export async function loadPropertiesFromApi(
6284 `Retrieved ${ remoteProperties . length } repository properties: ${ remoteProperties . map ( ( p ) => p . property_name ) . join ( ", " ) } ` ,
6385 ) ;
6486
65- const knownProperties = new Set ( Object . values ( RepositoryPropertyName ) ) ;
6687 const properties : RepositoryProperties = { } ;
6788 for ( const property of remoteProperties ) {
6889 if ( property . property_name === undefined ) {
@@ -71,10 +92,8 @@ export async function loadPropertiesFromApi(
7192 ) ;
7293 }
7394
74- if (
75- knownProperties . has ( property . property_name as RepositoryPropertyName )
76- ) {
77- properties [ property . property_name ] = property . value ;
95+ if ( isKnownPropertyName ( property . property_name ) ) {
96+ setProperty ( properties , property . property_name , property . value ) ;
7897 }
7998 }
8099
0 commit comments