From 8dbe764279f96bf854ede7fb1baed068b625e261 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ali=20Tu=C4=9Frul=20P=C4=B1nar?= Date: Mon, 29 Jan 2024 12:46:57 +0300 Subject: [PATCH] fix(build): add get configurations list step for build command --- README.md | 3 +++ src/core/command-runner.ts | 7 +++++++ src/core/commands.ts | 21 +++++++++++++++++++++ src/core/interactive-runner.ts | 17 +++++++++++++++-- src/core/writer.ts | 16 +++++++++++----- src/services/index.ts | 15 ++++++++++++++- 6 files changed, 71 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index 7b69545..6eb9fba 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,9 @@ Below is the list of commands currently supported by Appcircle CLI: | `appcircle listBuildProfiles` | Get the list of build profiles | | `appcircle listDistributionProfiles` | Get the list of distribution profiles | | `appcircle listBuildProfileWorkflows [--profileId]` | Get the list of workflows for the profile | +| `appcircle listBuildProfileConfigurations [--profileId]` | Get the list of configurations for the profile | +| `appcircle listBuildProfileBuildsOfCommit [--profileId]` | Get the list of commits of branch | +| `appcircle listBuildProfileBuildsOfCommit [--profileId]` | Get the list of builds of a commit | | `appcircle build [--profileId] [--branch] [--workflow]` | Start a new build | | `appcircle download [--path] [--commitId] [--buildId]` | Download the artifact under the selected path | | `appcircle upload [--app] [--message] [--profileId]` | Upload your app binary to selected distribution profile | diff --git a/src/core/command-runner.ts b/src/core/command-runner.ts index c551f7b..4d7182d 100644 --- a/src/core/command-runner.ts +++ b/src/core/command-runner.ts @@ -41,6 +41,7 @@ import { uploadEnterpriseApp, uploadEnterpriseAppVersion, getEnterpriseDownloadLink, + getConfigurations, } from "../services"; import { commandWriter, configWriter } from "./writer"; @@ -121,6 +122,12 @@ export const runCommand = async (command: ProgramCommand) => { commandWriter(CommandTypes.LIST_BUILD_PROFILE_WORKFLOWS, responseData); break; } + case CommandTypes.LIST_BUILD_PROFILE_CONFIGURATIONS: { + responseData = await getConfigurations(params); + commandWriter(CommandTypes.LIST_BUILD_PROFILE_CONFIGURATIONS, responseData); + break; + } + case CommandTypes.LIST_BUILD_PROFILE_COMMITS: { responseData = await getCommits(params); commandWriter(CommandTypes.LIST_BUILD_PROFILE_COMMITS, responseData); diff --git a/src/core/commands.ts b/src/core/commands.ts index d484d8e..4922ede 100644 --- a/src/core/commands.ts +++ b/src/core/commands.ts @@ -14,6 +14,7 @@ export enum CommandTypes { LIST_BUILD_PROFILES = "listBuildProfiles", LIST_BUILD_PROFILE_BRANCHES = "listBuildProfileBranches", LIST_BUILD_PROFILE_WORKFLOWS = "listBuildProfileWorkflows", + LIST_BUILD_PROFILE_CONFIGURATIONS = "listBuildProfileConfigurations", LIST_BUILD_PROFILE_COMMITS = "listBuildProfileCommits", LIST_BUILD_PROFILE_BUILDS_OF_COMMIT = "listBuildProfileBuildsOfCommit", LIST_DISTRIBUTION_PROFILES = "listDistributionProfiles", @@ -99,6 +100,18 @@ export const Commands: { }, ], }, + { + command: CommandTypes.LIST_BUILD_PROFILE_CONFIGURATIONS, + description: "Get list of configurations of a build profile", + params: [ + { + name: "profileId", + description: "Build profile ID", + type: CommandParameterTypes.SELECT, + valueType: "uuid", + }, + ], + }, { command: CommandTypes.LIST_BUILD_PROFILE_COMMITS, description: "Get list of commits of a branch", @@ -175,6 +188,14 @@ export const Commands: { required: false, params: [], }, + { + name: "configurationId", + description: "Configuration ID [Optional]", + type: CommandParameterTypes.SELECT, + valueType: "uuid", + required: false, + params: [], + }, { name: "workflowId", description: "Workflow ID", diff --git a/src/core/interactive-runner.ts b/src/core/interactive-runner.ts index d78f81b..5ebf8e8 100644 --- a/src/core/interactive-runner.ts +++ b/src/core/interactive-runner.ts @@ -18,6 +18,7 @@ import { getBuildsOfCommit, getDistributionProfiles, getEnvironmentVariableGroups, + getConfigurations, } from "../services"; import { DefaultEnvironmentVariables, getConfigStore } from "../config"; @@ -237,7 +238,7 @@ export const runCommandsInteractively = async () => { spinner.text = "Enterprise Versions fetched"; spinner.succeed(); } else if (param.name === "workflowId") { - const spinner = ora("Workflow fetching").start(); + const spinner = ora("Workflows fetching").start(); const workflows = await getWorkflows({ profileId: params.profileId || "" }); if (!workflows || workflows.length === 0) { spinner.text = "No workflows available"; @@ -248,7 +249,19 @@ export const runCommandsInteractively = async () => { param.params = workflows.map((workflow: any) => ({ name: workflow.id, message: `${workflow.id} (${workflow.workflowName})` })); spinner.text = "Workflows fetched"; spinner.succeed(); - } else if (param.name === "value" && params.isSecret) { + } else if (param.name === "configurationId") { + const spinner = ora("Configurations fetching").start(); + const configurations = await getConfigurations({ profileId: params.profileId || "" }); + if (!configurations || configurations.length === 0) { + spinner.text = "No configurations available"; + spinner.fail(); + return; + } + //@ts-ignore + param.params = configurations.map((configurations: any) => ({ name: configurations.item1.id, message: `${configurations.item1.id} (${configurations.item1.configurationName})` })); + spinner.text = "Configurations fetched"; + spinner.succeed(); + }else if (param.name === "value" && params.isSecret) { param.type = CommandParameterTypes.PASSWORD; } diff --git a/src/core/writer.ts b/src/core/writer.ts index a6f49ca..17f9974 100644 --- a/src/core/writer.ts +++ b/src/core/writer.ts @@ -5,10 +5,7 @@ import moment from "moment"; import { getConsoleOutputType } from "../config"; const writersMap: { [key in CommandTypes]: (data: any) => void } = { - - [CommandTypes.CONFIG]: (data: any) => { - - }, + [CommandTypes.CONFIG]: (data: any) => {}, [CommandTypes.LOGIN]: (data: any) => { console.log(chalk.italic(`export AC_ACCESS_TOKEN="${data.access_token}"\n`)); console.info( @@ -51,11 +48,20 @@ const writersMap: { [key in CommandTypes]: (data: any) => void } = { console.table( data.map((workflow: any) => ({ "Workflow Id": workflow.id, - "Workflow Name": workflow.workflowName, + "Workflow Name": workflow.configurationName, "Last Used": workflow.lastUsedTime ? moment(workflow.lastUsedTime).calendar() : "No previous builds", })) ); }, + [CommandTypes.LIST_BUILD_PROFILE_CONFIGURATIONS]: (data: any) => { + console.table( + data.map((configuration: any) => ({ + "Configuration Id": configuration.item1.id, + "Configuration Name": configuration.item1.configurationName, + "Update Date": configuration.item1.updateDate ? moment(configuration.item1.updateDate).calendar() : "No updated before", + })) + ); + }, [CommandTypes.LIST_BUILD_PROFILE_COMMITS]: (data: any) => { if (data.length === 0) { console.info("No commits available."); diff --git a/src/services/index.ts b/src/services/index.ts index db869db..e63a52c 100644 --- a/src/services/index.ts +++ b/src/services/index.ts @@ -118,6 +118,8 @@ export async function startBuild( let branchId = options.branchId || ""; let workflowId = options.workflowId || ""; let commitId = options.commitId || ""; + let configurationId = options.configurationId || ""; + if (!branchId && options.branch) { const branchesRes = await getBranches({ profileId: options.profileId || "" }); @@ -133,7 +135,11 @@ export async function startBuild( const allCommitsByBranchId = await getCommits({ branchId }); commitId = allCommitsByBranchId[0].id; } - const buildResponse = await appcircleApi.post(`build/v2/commits/${commitId}?workflowId=${workflowId}`, qs.stringify({ sample: "test" }), { + if (!configurationId) { + const allConfigurations = await getConfigurations({ profileId: options.profileId || "" }); + configurationId = allConfigurations[0].item1.id; + } + const buildResponse = await appcircleApi.post(`build/v2/commits/${commitId}?${qs.stringify({ action: 'build', workflowId, configurationId })}`, '{}', { headers: { ...getHeaders(), accept: "*/*", @@ -282,6 +288,13 @@ export async function getWorkflows(options: OptionsType<{ profileId: string }>) return workflowResponse.data; } +export async function getConfigurations(options: OptionsType<{ profileId: string }>) { + const configurationsResponse = await appcircleApi.get(`build/v2/profiles/${options.profileId}/configurations`, { + headers: getHeaders(), + }); + return configurationsResponse.data; +} + /* export async function getBuildTaskStatus(options: OptionsType<{ latestCommitId: string; taskId: string }>) { const taskStatus = await appcircleApi.get(`build/v2/commits/${options.latestCommitId}/builds/${options.taskId}/status`, {