@@ -1200,16 +1200,17 @@ function prepareForPublishing (task, build, onDone) {
1200
1200
1201
1201
const releaseNotes = [ ] ;
1202
1202
1203
- const changeLogVersionName = build . version . name + (
1204
- build . googlePlayTrack && build . googlePlayTrack !== 'production' ?
1205
- ' ' + build . googlePlayTrack :
1206
- ''
1207
- ) ;
1203
+ const changeLogVersionName = build . version . name ;
1208
1204
let changeLogText = changeLogVersionName + '\n\n' + 'https://t.me/tgx_android' ;
1209
1205
const fromToCommit = getFromToCommit ( build , true ) ;
1206
+ const viewSourceUrl = build . git . remoteUrl + '/tree/' + build . git . commit . long ;
1210
1207
if ( fromToCommit ) {
1208
+ const diffUrl = build . git . remoteUrl + '/compare/' + fromToCommit . commit_range ;
1211
1209
changeLogText += '\n\nChanges from ' + fromToCommit . from_version . name + ':\n' ;
1212
- changeLogText += build . git . remoteUrl + '/compare/' + fromToCommit . commit_range ;
1210
+ changeLogText += diffUrl ;
1211
+ build . fallbackReleaseNotes = diffUrl ;
1212
+ } else {
1213
+ build . fallbackReleaseNotes = 'This version is based on this source code: ' + viewSourceUrl ;
1213
1214
}
1214
1215
releaseNotes . push ( {
1215
1216
language : 'en-US' , // TODO more languages via translations.telegram.org
@@ -1395,7 +1396,9 @@ async function obtainHuaweiAccessToken () {
1395
1396
grant_type : 'client_credentials'
1396
1397
} ;
1397
1398
const response = await postHttp ( 'https://connect-api.cloud.huawei.com/api/oauth2/v1/token' , data , false , {
1398
- 'User-Agent' : 'Telegram-X-Publisher'
1399
+ headers : {
1400
+ 'User-Agent' : 'Telegram-X-Publisher'
1401
+ }
1399
1402
} ) ;
1400
1403
if ( response . statusCode < 200 || response . statusCode >= 300 ) {
1401
1404
console . error ( 'AGC auth failed' , response . statusCode , response . statusMessage , response . contentType , response . content ) ;
@@ -1475,14 +1478,15 @@ async function uploadHuaweiApk (build, targetFiles, accessToken, uploadUrl, auth
1475
1478
}
1476
1479
}
1477
1480
1478
- async function submitHuaweiUpdate ( build , targetFiles , accessToken , fileInfo ) {
1481
+ async function updateHuaweiAppFileInfo ( build , targetFiles , accessToken , fileInfo ) {
1479
1482
try {
1480
1483
const apiUrl = 'https://connect-api.cloud.huawei.com/api/publish/v2/app-file-info' +
1481
1484
'?appId=' + settings . huawei . app_id ;
1485
+ const fileName = build . version . name + '.' + build . git . commit . short + '.apk' ;
1482
1486
const data = {
1483
1487
fileType : 5 ,
1484
1488
files : [ {
1485
- fileName : build . version . name + '.' + build . git . commit . short + '.apk' ,
1489
+ fileName : fileName ,
1486
1490
// The typo in the second "URL" (ULR) is intended ...
1487
1491
fileDestUrl : fileInfo . fileDestUlr
1488
1492
} ]
@@ -1505,6 +1509,50 @@ async function submitHuaweiUpdate (build, targetFiles, accessToken, fileInfo) {
1505
1509
}
1506
1510
}
1507
1511
1512
+ async function updateHuaweiAppLanguageInfo ( accessToken , info ) {
1513
+ try {
1514
+ const apiUrl = 'https://connect-api.cloud.huawei.com/api/publish/v2/upload-url' +
1515
+ '?appId=' + settings . huawei . app_id ;
1516
+ const response = await postHttp ( apiUrl , info , false , {
1517
+ headers : {
1518
+ 'client_id' : settings . huawei . client_id ,
1519
+ 'Authorization' : 'Bearer ' + accessToken ,
1520
+ 'User-Agent' : 'Telegram-X-Publisher'
1521
+ }
1522
+ } ) ;
1523
+ if ( response . statusCode !== 200 ) {
1524
+ console . error ( 'AGC update langauge info failed' , response . statusCode , response . statusMessage , response . contentType , response . content ) ;
1525
+ return null ;
1526
+ }
1527
+ return JSON . parse ( response . content ) ;
1528
+ } catch ( e ) {
1529
+ console . error ( 'Unable to update AGC language info' , e ) ;
1530
+ return null ;
1531
+ }
1532
+ }
1533
+
1534
+ async function submitHuaweiAppUpdate ( accessToken ) {
1535
+ try {
1536
+ const apiUrl = 'https://connect-api.cloud.huawei.com/api/publish/v2/app-submit' +
1537
+ '?appId=' + settings . huawei . app_id ;
1538
+ const response = await postHttp ( apiUrl , info , false , {
1539
+ headers : {
1540
+ 'client_id' : settings . huawei . client_id ,
1541
+ 'Authorization' : 'Bearer ' + accessToken ,
1542
+ 'User-Agent' : 'Telegram-X-Publisher'
1543
+ }
1544
+ } ) ;
1545
+ if ( response . statusCode !== 200 ) {
1546
+ console . error ( 'AGC update langauge info failed' , response . statusCode , response . statusMessage , response . contentType , response . content ) ;
1547
+ return null ;
1548
+ }
1549
+ return JSON . parse ( response . content ) ;
1550
+ } catch ( e ) {
1551
+ console . error ( 'Unable to submit AGC app for review' , e ) ;
1552
+ return null ;
1553
+ }
1554
+ }
1555
+
1508
1556
function uploadToHuaweiAppGallery ( task , build , onDone ) {
1509
1557
( async ( ) => {
1510
1558
const targetFiles = build . files [ 'huawei' ] || build . files [ 'universal' ] ;
@@ -1534,19 +1582,50 @@ function uploadToHuaweiAppGallery (task, build, onDone) {
1534
1582
}
1535
1583
const fileInfo = uploadedFile . result . UploadFileRsp . fileInfoList [ 0 ] ;
1536
1584
1537
- // Step 4. Publish an update with the uploaded APK
1538
- const submittedUpdate = await submitHuaweiUpdate (
1585
+ // Step 4. Update file info
1586
+ const updatedFileInfo = await updateHuaweiAppFileInfo (
1539
1587
build ,
1540
1588
targetFiles ,
1541
1589
auth . access_token ,
1542
1590
fileInfo
1543
1591
) ;
1544
- if ( ! submittedUpdate ) {
1592
+ if ( ! updatedFileInfo ) {
1593
+ onDone ( 1 ) ;
1594
+ return ;
1595
+ }
1596
+
1597
+ // Step 5. Update change logs
1598
+ if ( build . releaseNotes && build . releaseNotes . length > 0 ) {
1599
+ for ( let index = 0 ; index < build . releaseNotes . length ; index ++ ) {
1600
+ const releaseNotes = build . releaseNotes [ index ] ;
1601
+ let changeLogText = releaseNotes . text ;
1602
+ if ( changeLogText . length > 500 ) {
1603
+ task . logPrivately ( releaseNotes . language + ' did not fit' ) ;
1604
+ changeLogText = build . fallbackReleaseNotes || '' ;
1605
+ }
1606
+ // lang String(64): Language. https://developer.huawei.com/consumer/en/doc/development/AppGallery-connect-References/agcapi-reference-langtype-0000001158245079
1607
+ // appName String(64): App name in a language. This parameter is mandatory when a language type is added.
1608
+ // appDesc String(8000): Full introduction in a language.
1609
+ // briefInfo String(80): Brief introduction in a language.
1610
+ // newFeatures String(500): New features in a language.
1611
+ await updateHuaweiAppLanguageInfo (
1612
+ auth . access_token , {
1613
+ lang : releaseNotes . language ,
1614
+ newFeatures : changeLogText
1615
+ } ) ;
1616
+ }
1617
+ }
1618
+
1619
+ // Step 6. Submit for review
1620
+ const submittedApp = await submitHuaweiAppUpdate (
1621
+ auth . access_token
1622
+ ) ;
1623
+ if ( ! submittedApp ) {
1545
1624
onDone ( 1 ) ;
1546
1625
return ;
1547
1626
}
1548
1627
1549
- console . log ( 'Successfully published Huawei AppGallery' , JSON . stringify ( submittedUpdate ) ) ;
1628
+ console . log ( 'Successfully published Huawei AppGallery' ) ;
1550
1629
onDone ( 0 ) ;
1551
1630
} ) ( ) ;
1552
1631
0 commit comments