Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Commit

Permalink
[cli] fix publish:rollback
Browse files Browse the repository at this point in the history
fix tsc

changes after testing

pr feedback

implementation nits
  • Loading branch information
quinlanj committed Apr 3, 2020
1 parent 12f8517 commit 9bc45bc
Show file tree
Hide file tree
Showing 3 changed files with 359 additions and 144 deletions.
130 changes: 12 additions & 118 deletions packages/expo-cli/src/commands/publish-info.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,17 @@ import { Api, ApiV2, FormData, Project, UserManager } from '@expo/xdl';
import dateFormat from 'dateformat';

import * as table from './utils/cli-table';
import {
DetailOptions,
HistoryOptions,
Publication,
getPublicationDetailAsync,
getPublishHistoryAsync,
printPublicationDetailAsync,
} from './utils/PublishUtils';

const HORIZ_CELL_WIDTH_SMALL = 15;
const HORIZ_CELL_WIDTH_BIG = 40;
const VERSION = 2;

type HistoryOptions = {
releaseChannel?: string;
count?: number;
platform?: 'android' | 'ios';
raw?: boolean;
};

type DetailOptions = {
publishId?: string;
raw?: boolean;
};

type Publication = {
fullName: string;
channel: string;
channelId: string;
publicationId: string;
appVersion: string;
sdkVersion: string;
publishedTime: string;
platform: 'android' | 'ios';
};

export default (program: any) => {
program
Expand All @@ -46,52 +30,10 @@ export default (program: any) => {
parseInt
)
.option('-p, --platform <ios|android>', 'Filter by platform, android or ios.')
.option('-s, --sdk-version <version>', 'Filter by sdk version e.g. 35.0.0')
.option('-r, --raw', 'Produce some raw output.')
.asyncActionProjectDir(async (projectDir: string, options: HistoryOptions) => {
if (options.count && (isNaN(options.count) || options.count < 1 || options.count > 100)) {
throw new Error('-n must be a number between 1 and 100 inclusive');
}

// TODO(ville): handle the API result for not authenticated user instead of checking upfront
const user = await UserManager.ensureLoggedInAsync();
const { exp } = getConfig(projectDir, {
skipSDKVersionRequirement: true,
});

let result: any;
if (process.env.EXPO_LEGACY_API === 'true') {
// TODO(ville): move request from multipart/form-data to JSON once supported by the endpoint.
let formData = new FormData();
formData.append('queryType', 'history');
if (exp.owner) {
formData.append('owner', exp.owner);
}
formData.append('slug', await Project.getSlugAsync(projectDir));
formData.append('version', VERSION);
if (options.releaseChannel) {
formData.append('releaseChannel', options.releaseChannel);
}
if (options.count) {
formData.append('count', options.count);
}
if (options.platform) {
formData.append('platform', options.platform);
}

result = await Api.callMethodAsync('publishInfo', [], 'post', null, {
formData,
});
} else {
const api = ApiV2.clientForUser(user);
result = await api.postAsync('publish/history', {
owner: exp.owner,
slug: await Project.getSlugAsync(projectDir),
version: VERSION,
releaseChannel: options.releaseChannel,
count: options.count,
platform: options.platform,
});
}
const result = await getPublishHistoryAsync(projectDir, options);

if (options.raw) {
console.log(JSON.stringify(result));
Expand Down Expand Up @@ -151,55 +93,7 @@ export default (program: any) => {
throw new Error('--publish-id must be specified.');
}

// TODO(ville): handle the API result for not authenticated user instead of checking upfront
const user = await UserManager.ensureLoggedInAsync();
const { exp } = getConfig(projectDir, {
skipSDKVersionRequirement: true,
});
const slug = await Project.getSlugAsync(projectDir);

let result: any;
if (process.env.EXPO_LEGACY_API === 'true') {
let formData = new FormData();
formData.append('queryType', 'details');

if (exp.owner) {
formData.append('owner', exp.owner);
}
formData.append('publishId', options.publishId);
formData.append('slug', slug);

result = await Api.callMethodAsync('publishInfo', null, 'post', null, {
formData,
});
} else {
const api = ApiV2.clientForUser(user);
result = await api.postAsync('publish/details', {
owner: exp.owner,
publishId: options.publishId,
slug,
});
}

if (options.raw) {
console.log(JSON.stringify(result));
return;
}

if (result.queryResult) {
let queryResult = result.queryResult;
let manifest = queryResult.manifest;
delete queryResult.manifest;

// Print general release info
let generalTableString = table.printTableJson(queryResult, 'Release Description');
console.log(generalTableString);

// Print manifest info
let manifestTableString = table.printTableJson(manifest, 'Manifest Details');
console.log(manifestTableString);
} else {
throw new Error('No records found matching your query.');
}
const detail = await getPublicationDetailAsync(projectDir, options);
await printPublicationDetailAsync(detail, options);
});
};
68 changes: 42 additions & 26 deletions packages/expo-cli/src/commands/publish-modify.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
import ora from 'ora';
import { getConfig } from '@expo/config';
import { ApiV2, Project, UserManager } from '@expo/xdl';
import { Command } from 'commander';
import log from '../log';
import prompt from '../prompt';
import * as table from '../commands/utils/cli-table';
import {
Publication,
RollbackOptions,
getPublicationDetailAsync,
getPublishHistoryAsync,
printPublicationDetailAsync,
rollbackPublicationFromChannelAsync,
setPublishToChannelAsync,
} from './utils/PublishUtils';

export default function(program: Command) {
program
Expand All @@ -27,14 +39,11 @@ export default function(program: Command) {
if (!options.publishId) {
throw new Error('You must specify a publish id. You can find ids using publish:history.');
}
const user = await UserManager.ensureLoggedInAsync();
const api = ApiV2.clientForUser(user);
try {
let result = await api.postAsync('publish/set', {
releaseChannel: options.releaseChannel,
publishId: options.publishId,
slug: await Project.getSlugAsync(projectDir),
});
const result = await setPublishToChannelAsync(
projectDir,
options as { releaseChannel: string; publishId: string }
);
let tableString = table.printTableJson(
result.queryResult,
'Channel Set Status ',
Expand All @@ -50,28 +59,35 @@ export default function(program: Command) {
.command('publish:rollback [project-dir]')
.alias('pr')
.description('Rollback an update to a channel.')
.option('--channel-id <channel-id>', 'The channel id to rollback in the channel. (Required)')
.option('--channel-id <channel-id>', 'This flag is deprecated.')
.option('-c, --release-channel <channel-name>', 'The channel to rollback from. (Required)')
.option('-s, --sdk-version <version>', 'The sdk version to rollback. (Required)')
.option('-p, --platform <ios|android>', 'The platform to rollback.')
.asyncActionProjectDir(
async (projectDir: string, options: { channelId?: string }): Promise<void> => {
if (!options.channelId) {
throw new Error('You must specify a channel id. You can find ids using publish:history.');
async (
projectDir: string,
options: {
releaseChannel?: string;
sdkVersion?: string;
platform?: string;
channelId?: string;
}
const user = await UserManager.getCurrentUserAsync();
const api = ApiV2.clientForUser(user);
try {
let result = await api.postAsync('publish/rollback', {
channelId: options.channelId,
slug: await Project.getSlugAsync(projectDir),
});
let tableString = table.printTableJson(
result.queryResult,
'Channel Rollback Status ',
'SUCCESS'
);
console.log(tableString);
} catch (e) {
log.error(e);
): Promise<void> => {
if (options.channelId) {
throw new Error('This flag is deprecated');
}
if (!options.releaseChannel) {
throw new Error('You must specify a release channel.');
}
if (!options.sdkVersion) {
throw new Error('You must specify an sdk version.');
}
if (options.platform) {
if (options.platform !== 'android' && options.platform !== 'ios') {
throw new Error('Platform must be either android or ios');
}
}
await rollbackPublicationFromChannelAsync(projectDir, options as RollbackOptions);
}
);
}
Loading

0 comments on commit 9bc45bc

Please sign in to comment.