Skip to content

Commit cec30a0

Browse files
auto notify when auto submit is enabled
1 parent 31b3b49 commit cec30a0

File tree

3 files changed

+112
-7
lines changed

3 files changed

+112
-7
lines changed

dist/index.js

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57640,9 +57640,7 @@ async function GetAppId(project) {
5764057640
var _a, _b;
5764157641
await getOrCreateClient(project);
5764257642
const { data: response, error } = await appStoreConnectClient.api.AppsService.appsGetCollection({
57643-
query: {
57644-
'filter[bundleId]': [project.bundleId]
57645-
}
57643+
query: { 'filter[bundleId]': [project.bundleId] }
5764657644
});
5764757645
if (error) {
5764857646
checkAuthError(error);
@@ -57894,6 +57892,7 @@ async function UpdateTestDetails(project, whatsNew) {
5789457892
if (submitForReview) {
5789557893
core.info(`Submitting for review...`);
5789657894
await submitBetaBuildForReview(project, build);
57895+
await autoNotifyBetaUsers(project, build);
5789757896
}
5789857897
}
5789957898
async function submitBetaBuildForReview(project, build) {
@@ -57923,6 +57922,58 @@ async function submitBetaBuildForReview(project, build) {
5792357922
(0, utilities_1.log)(responseJson);
5792457923
core.info(`Beta build is ${response.data.attributes.betaReviewState}`);
5792557924
}
57925+
async function autoNotifyBetaUsers(project, build) {
57926+
var _a, _b;
57927+
await getOrCreateClient(project);
57928+
let buildBetaDetail = null;
57929+
if (!((_a = build.relationships) === null || _a === void 0 ? void 0 : _a.buildBetaDetail)) {
57930+
buildBetaDetail = await getBetaAppBuildSubmissionDetails(project, build);
57931+
}
57932+
else {
57933+
buildBetaDetail = build.relationships.buildBetaDetail.data;
57934+
}
57935+
if (!((_b = buildBetaDetail.attributes) === null || _b === void 0 ? void 0 : _b.autoNotifyEnabled)) {
57936+
buildBetaDetail.attributes.autoNotifyEnabled = true;
57937+
}
57938+
const payload = {
57939+
path: { id: buildBetaDetail.id },
57940+
body: {
57941+
data: {
57942+
id: buildBetaDetail.id,
57943+
type: 'buildBetaDetails',
57944+
attributes: {
57945+
autoNotifyEnabled: buildBetaDetail.attributes.autoNotifyEnabled
57946+
}
57947+
}
57948+
}
57949+
};
57950+
const { data: response, error } = await appStoreConnectClient.api.BuildBetaDetailsService.buildBetaDetailsUpdateInstance(payload);
57951+
if (error) {
57952+
checkAuthError(error);
57953+
throw new Error(`Error updating beta build details: ${JSON.stringify(error, null, 2)}`);
57954+
}
57955+
const responseJson = JSON.stringify(response, null, 2);
57956+
(0, utilities_1.log)(responseJson);
57957+
}
57958+
async function getBetaAppBuildSubmissionDetails(project, build) {
57959+
const payload = {
57960+
query: {
57961+
"filter[build]": [build.id],
57962+
limit: 1
57963+
}
57964+
};
57965+
const { data: response, error } = await appStoreConnectClient.api.BuildBetaDetailsService.buildBetaDetailsGetCollection(payload);
57966+
if (error) {
57967+
checkAuthError(error);
57968+
throw new Error(`Error fetching beta build details: ${JSON.stringify(error, null, 2)}`);
57969+
}
57970+
const responseJson = JSON.stringify(response, null, 2);
57971+
if (!response || !response.data || response.data.length === 0) {
57972+
throw new Error(`No beta build details found!`);
57973+
}
57974+
(0, utilities_1.log)(responseJson);
57975+
return response.data[0];
57976+
}
5792657977
function normalizeVersion(version) {
5792757978
return version.split('.').map(part => parseInt(part, 10).toString()).join('.');
5792857979
}

dist/index.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/AppStoreConnectClient.ts

Lines changed: 57 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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';
2023
import { log } from './utilities';
2124
import core = require('@actions/core');
@@ -55,9 +58,7 @@ function checkAuthError(error: any) {
5558
export 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+
346400
function normalizeVersion(version: string): string {
347401
return version.split('.').map(part => parseInt(part, 10).toString()).join('.');
348402
}

0 commit comments

Comments
 (0)