Skip to content

Commit

Permalink
fix(build): add get configurations list step for build command
Browse files Browse the repository at this point in the history
  • Loading branch information
Alnyli07 committed Jan 29, 2024
1 parent 794aa46 commit 8dbe764
Show file tree
Hide file tree
Showing 6 changed files with 71 additions and 8 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
7 changes: 7 additions & 0 deletions src/core/command-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
uploadEnterpriseApp,
uploadEnterpriseAppVersion,
getEnterpriseDownloadLink,
getConfigurations,
} from "../services";
import { commandWriter, configWriter } from "./writer";

Expand Down Expand Up @@ -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);
Expand Down
21 changes: 21 additions & 0 deletions src/core/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
17 changes: 15 additions & 2 deletions src/core/interactive-runner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
getBuildsOfCommit,
getDistributionProfiles,
getEnvironmentVariableGroups,
getConfigurations,
} from "../services";
import { DefaultEnvironmentVariables, getConfigStore } from "../config";

Expand Down Expand Up @@ -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";
Expand All @@ -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;
}

Expand Down
16 changes: 11 additions & 5 deletions src/core/writer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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.");
Expand Down
15 changes: 14 additions & 1 deletion src/services/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 || "" });
Expand All @@ -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: "*/*",
Expand Down Expand Up @@ -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`, {
Expand Down

0 comments on commit 8dbe764

Please sign in to comment.