@@ -16,6 +16,9 @@ import {
1616 BuildsBetaGroupsCreateToManyRelationshipData ,
1717 BetaGroup ,
1818 BetaAppReviewSubmissionsCreateInstanceData ,
19+ BuildBetaDetailsGetCollectionData ,
20+ BuildBetaDetailsUpdateInstanceData ,
21+ BuildBetaDetail ,
1922} from '@rage-against-the-pixel/app-store-connect-api/dist/app_store_connect_api' ;
2023import { log } from './utilities' ;
2124import core = require( '@actions/core' ) ;
@@ -55,9 +58,7 @@ function checkAuthError(error: any) {
5558export async function GetAppId ( project : XcodeProject ) : Promise < string > {
5659 await getOrCreateClient ( project ) ;
5760 const { data : response , error } = await appStoreConnectClient . api . AppsService . appsGetCollection ( {
58- query : {
59- 'filter[bundleId]' : [ project . bundleId ]
60- }
61+ query : { 'filter[bundleId]' : [ project . bundleId ] }
6162 } ) ;
6263 if ( error ) {
6364 checkAuthError ( error ) ;
@@ -312,6 +313,7 @@ export async function UpdateTestDetails(project: XcodeProject, whatsNew: string)
312313 if ( submitForReview ) {
313314 core . info ( `Submitting for review...` ) ;
314315 await submitBetaBuildForReview ( project , build ) ;
316+ await autoNotifyBetaUsers ( project , build ) ;
315317 }
316318}
317319
@@ -343,6 +345,58 @@ async function submitBetaBuildForReview(project: XcodeProject, build: Build): Pr
343345 core . info ( `Beta build is ${ response . data . attributes . betaReviewState } ` ) ;
344346}
345347
348+ async function autoNotifyBetaUsers ( project : XcodeProject , build : Build ) : Promise < void > {
349+ await getOrCreateClient ( project ) ;
350+ let buildBetaDetail : BuildBetaDetail = null ;
351+ if ( ! build . relationships ?. buildBetaDetail ) {
352+ buildBetaDetail = await getBetaAppBuildSubmissionDetails ( project , build ) ;
353+ } else {
354+ buildBetaDetail = build . relationships . buildBetaDetail . data ;
355+ }
356+ if ( ! buildBetaDetail . attributes ?. autoNotifyEnabled ) {
357+ buildBetaDetail . attributes . autoNotifyEnabled = true ;
358+ }
359+ const payload : BuildBetaDetailsUpdateInstanceData = {
360+ path : { id : buildBetaDetail . id } ,
361+ body : {
362+ data : {
363+ id : buildBetaDetail . id ,
364+ type : 'buildBetaDetails' ,
365+ attributes : {
366+ autoNotifyEnabled : buildBetaDetail . attributes . autoNotifyEnabled
367+ }
368+ }
369+ }
370+ } ;
371+ const { data : response , error } = await appStoreConnectClient . api . BuildBetaDetailsService . buildBetaDetailsUpdateInstance ( payload ) ;
372+ if ( error ) {
373+ checkAuthError ( error ) ;
374+ throw new Error ( `Error updating beta build details: ${ JSON . stringify ( error , null , 2 ) } ` ) ;
375+ }
376+ const responseJson = JSON . stringify ( response , null , 2 ) ;
377+ log ( responseJson ) ;
378+ }
379+
380+ async function getBetaAppBuildSubmissionDetails ( project : XcodeProject , build : Build ) : Promise < BuildBetaDetail > {
381+ const payload : BuildBetaDetailsGetCollectionData = {
382+ query : {
383+ "filter[build]" : [ build . id ] ,
384+ limit : 1
385+ }
386+ } ;
387+ const { data : response , error } = await appStoreConnectClient . api . BuildBetaDetailsService . buildBetaDetailsGetCollection ( payload ) ;
388+ if ( error ) {
389+ checkAuthError ( error ) ;
390+ throw new Error ( `Error fetching beta build details: ${ JSON . stringify ( error , null , 2 ) } ` ) ;
391+ }
392+ const responseJson = JSON . stringify ( response , null , 2 ) ;
393+ if ( ! response || ! response . data || response . data . length === 0 ) {
394+ throw new Error ( `No beta build details found!` ) ;
395+ }
396+ log ( responseJson ) ;
397+ return response . data [ 0 ] ;
398+ }
399+
346400function normalizeVersion ( version : string ) : string {
347401 return version . split ( '.' ) . map ( part => parseInt ( part , 10 ) . toString ( ) ) . join ( '.' ) ;
348402}
0 commit comments