eas-cli
Version:
EAS command line tool
47 lines (46 loc) • 2.11 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync = void 0;
const queries_1 = require("../branch/queries");
const errors_1 = require("../channel/errors");
const queries_2 = require("../channel/queries");
const ChannelQuery_1 = require("../graphql/queries/ChannelQuery");
async function getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync(graphqlClient, projectId, channelName) {
let branchInfo;
try {
const channel = await ChannelQuery_1.ChannelQuery.viewUpdateChannelAsync(graphqlClient, {
appId: projectId,
channelName,
});
if (channel.updateBranches.length === 1) {
const branch = channel.updateBranches[0];
branchInfo = { branchId: branch.id, branchName: branch.name };
}
else if (channel.updateBranches.length === 0) {
throw new Error("Channel has no branches associated with it. Run 'eas channel:edit' to map a branch");
}
else {
throw new Error(`Channel has multiple branches associated with it. Instead, use '--branch' instead of '--channel'`);
}
}
catch (error) {
if (!(error instanceof errors_1.ChannelNotFoundError)) {
throw error;
}
const { branch } = await (0, queries_1.ensureBranchExistsAsync)(graphqlClient, {
appId: projectId,
branchName: channelName,
});
const { updateChannel: { createUpdateChannelForApp: newChannel }, } = await (0, queries_2.createChannelOnAppAsync)(graphqlClient, {
appId: projectId,
channelName,
branchId: branch.id,
});
if (!newChannel) {
throw new Error(`Could not create channel with name ${channelName} on project with id ${projectId}`);
}
branchInfo = { branchId: branch.id, branchName: channelName };
}
return branchInfo;
}
exports.getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync = getBranchFromChannelNameAndCreateAndLinkIfNotExistsAsync;
;