@@ -26,7 +26,7 @@ def generateToken(self, issuer_id, key_id, private_key):
2626
2727 return encoded_token
2828
29- def uploadNotes (self , app_id , token , whats_new , build_number ):
29+ def uploadNotes (self , app_id , token , whats_new , build_number , platform ):
3030 # Create Header
3131 HEAD = {
3232 'Authorization' : 'Bearer ' + token
@@ -37,28 +37,40 @@ def uploadNotes(self, app_id, token, whats_new, build_number):
3737
3838 # Find builds
3939 versionId = ""
40- while versionId == "" :
40+ versionIdCounter = 0
41+ while versionId == "" and versionIdCounter < 100 :
4142
4243 print ("---Finding Build---" )
43- URL = BASE_URL + 'builds?filter[app]=' + app_id + '&filter[version]=' + build_number
44+ URL = BASE_URL + 'builds?filter[app]=' + app_id + '&filter[version]=' + build_number + '&filter[preReleaseVersion.platform]=' + platform
4445 r = requests .get (URL , params = {}, headers = HEAD )
4546 try :
46- versionId = r .json ()['data' ][0 ]['id' ]
47- except :
47+ data = r .json ()['data' ]
48+
49+ if len (data ) > 0 :
50+ versionId = data [0 ]['id' ]
51+ print (f"found versionId: { versionId } " )
52+
53+ except Exception as e :
54+ print (f"Error: { e } " )
4855 time .sleep (60 ) #wait for 60 seconds
56+
57+ versionIdCounter += 1
4958
5059 # Find localizations
5160 localizationId = ""
52- while localizationId == "" :
61+ localizationIdCounter = 0
62+ while localizationId == "" and localizationIdCounter < 100 :
5363
5464 print ("---Finding Localizations---" )
5565 URL = BASE_URL + 'builds/' + versionId + '/betaBuildLocalizations'
5666 r = requests .get (URL , params = {}, headers = HEAD )
5767 try :
5868 localizationId = r .json ()['data' ][0 ]['id' ]
59- except :
69+ except Exception as e :
70+ print (f"Error: { e } " )
6071 time .sleep (60 ) #wait for 60 seconds
61-
72+
73+ localizationIdCounter += 1
6274
6375 print ("---Update What's New---" )
6476 URL = BASE_URL + 'betaBuildLocalizations/' + localizationId
@@ -85,11 +97,13 @@ def main():
8597 whats_new = os .getenv ('WHATS_NEW' )
8698 build_number = os .getenv ('BUILD_NUMBER' )
8799
100+ platform = os .getenv ('PLATFORM' , 'IOS' )
101+
88102 print (f"Starting for build: { build_number } " )
89103
90104 service = UploadTestFlightReleaseNotes ()
91105 token = service .generateToken (issuer_id , key_id , private_key )
92- reason = service .uploadNotes (app_id , token , whats_new , build_number )
106+ reason = service .uploadNotes (app_id , token , whats_new , build_number , platform )
93107
94108 print (reason )
95109
0 commit comments