@@ -36,8 +36,11 @@ import {
3636 makeTelemetryDiagnostic ,
3737} from "./diagnostics" ;
3838import { EnvVar } from "./environment" ;
39- import { Feature , Features } from "./feature-flags" ;
40- import { loadPropertiesFromApi } from "./feature-flags/properties" ;
39+ import { Feature , FeatureEnablement , Features } from "./feature-flags" ;
40+ import {
41+ loadPropertiesFromApi ,
42+ RepositoryProperties ,
43+ } from "./feature-flags/properties" ;
4144import {
4245 checkInstallPython311 ,
4346 checkPacksForOverlayCompatibility ,
@@ -53,7 +56,7 @@ import {
5356 OverlayBaseDatabaseDownloadStats ,
5457 OverlayDatabaseMode ,
5558} from "./overlay-database-utils" ;
56- import { getRepositoryNwo } from "./repository" ;
59+ import { getRepositoryNwo , RepositoryNwo } from "./repository" ;
5760import { ToolsSource } from "./setup-codeql" ;
5861import {
5962 ActionName ,
@@ -87,6 +90,8 @@ import {
8790 checkActionVersion ,
8891 getErrorMessage ,
8992 BuildMode ,
93+ GitHubVersion ,
94+ Result ,
9095} from "./util" ;
9196import { checkWorkflow } from "./workflow" ;
9297
@@ -237,16 +242,12 @@ async function run(startedAt: Date) {
237242 ) ;
238243
239244 // Fetch the values of known repository properties that affect us.
240- const repositoryOwnerType = getOptionalInput ( "repository-owner-type" ) ;
241- logger . debug (
242- `Repository owner type is '${ repositoryOwnerType ?? "unknown" } '.` ,
245+ const repositoryProperties = await loadRepositoryProperties (
246+ repositoryNwo ,
247+ gitHubVersion ,
248+ features ,
249+ logger ,
243250 ) ;
244- const enableRepoProps =
245- repositoryOwnerType === "Organization" &&
246- ( await features . getValue ( Feature . UseRepositoryProperties ) ) ;
247- const repositoryProperties = enableRepoProps
248- ? await loadPropertiesFromApi ( gitHubVersion , logger , repositoryNwo )
249- : { } ;
250251
251252 // Create a unique identifier for this run.
252253 const jobRunUuid = uuidV4 ( ) ;
@@ -367,10 +368,26 @@ async function run(startedAt: Date) {
367368 githubVersion : gitHubVersion ,
368369 apiDetails,
369370 features,
370- repositoryProperties,
371+ repositoryProperties : repositoryProperties . orElse ( { } ) ,
371372 logger,
372373 } ) ;
373374
375+ if ( repositoryProperties . isError ( ) ) {
376+ addDiagnostic (
377+ config ,
378+ // Arbitrarily choose the first language. We could also choose all languages, but that
379+ // increases the risk of misinterpreting the data.
380+ config . languages [ 0 ] ,
381+ makeTelemetryDiagnostic (
382+ "codeql-action/repository-properties-load-failure" ,
383+ "Failed to load repository properties" ,
384+ {
385+ error : getErrorMessage ( repositoryProperties . value ) ,
386+ } ,
387+ ) ,
388+ ) ;
389+ }
390+
374391 await checkInstallPython311 ( config . languages , codeql ) ;
375392 } catch ( unwrappedError ) {
376393 const error = wrapError ( unwrappedError ) ;
@@ -779,6 +796,41 @@ async function run(startedAt: Date) {
779796 ) ;
780797}
781798
799+ async function loadRepositoryProperties (
800+ repositoryNwo : RepositoryNwo ,
801+ gitHubVersion : GitHubVersion ,
802+ features : FeatureEnablement ,
803+ logger : Logger ,
804+ ) : Promise < Result < RepositoryProperties , unknown > > {
805+ const repositoryOwnerType = getOptionalInput ( "repository-owner-type" ) ;
806+ if ( repositoryOwnerType === "User" ) {
807+ // Users cannot have repository properties, so skip the API call.
808+ logger . debug (
809+ "Skipping loading repository properties because the repository is owned by a user and " +
810+ "therefore cannot have repository properties." ,
811+ ) ;
812+ return Result . ok ( { } ) ;
813+ }
814+
815+ if ( ! ( await features . getValue ( Feature . UseRepositoryProperties ) ) ) {
816+ logger . debug (
817+ "Skipping loading repository properties because the UseRepositoryProperties feature flag is disabled." ,
818+ ) ;
819+ return Result . ok ( { } ) ;
820+ }
821+
822+ try {
823+ return Result . ok (
824+ await loadPropertiesFromApi ( gitHubVersion , logger , repositoryNwo ) ,
825+ ) ;
826+ } catch ( error ) {
827+ logger . warning (
828+ `Failed to load repository properties: ${ getErrorMessage ( error ) } ` ,
829+ ) ;
830+ return Result . error ( error ) ;
831+ }
832+ }
833+
782834function getTrapCachingEnabled ( ) : boolean {
783835 // If the workflow specified something always respect that
784836 const trapCaching = getOptionalInput ( "trap-caching" ) ;
0 commit comments