Skip to content
This repository was archived by the owner on Apr 13, 2020. It is now read-only.

Commit b7ab8fc

Browse files
introspection cmds should consume new refactored package (#359)
* Consuming new spektate package * Dashboard command * Remove -it Co-authored-by: Dennis Seah <dennis.seah@gmail.com>
1 parent 0f725cd commit b7ab8fc

File tree

5 files changed

+83
-56
lines changed

5 files changed

+83
-56
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@
8888
"open": "^6.4.0",
8989
"shelljs": "^0.8.3",
9090
"simple-git": "^1.126.0",
91-
"spektate": "^0.1.19",
91+
"spektate": "^1.0.0",
9292
"ssh-url": "^0.1.5",
9393
"uuid": "^3.3.3",
9494
"winston": "^3.2.1"

src/commands/deployment/dashboard.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ export const launchDashboard = async (
143143
"--rm",
144144
...(await getEnvVars(config)),
145145
"-p",
146-
port + ":80",
146+
port + ":5000",
147147
dockerRepository
148148
]);
149149
return containerId;
@@ -192,6 +192,10 @@ export const getEnvVars = async (config: IConfigYaml): Promise<string[]> => {
192192
"REACT_APP_SOURCE_REPO_ACCESS_TOKEN=" +
193193
config.azure_devops!.access_token
194194
);
195+
envVars.push("-e");
196+
envVars.push(
197+
"REACT_APP_MANIFEST_ACCESS_TOKEN=" + config.azure_devops!.access_token
198+
);
195199
}
196200
} else {
197201
logger.warn(
@@ -204,6 +208,11 @@ export const getEnvVars = async (config: IConfigYaml): Promise<string[]> => {
204208
"REACT_APP_SOURCE_REPO_ACCESS_TOKEN=" +
205209
config.introspection!.azure!.source_repo_access_token
206210
);
211+
envVars.push("-e");
212+
envVars.push(
213+
"REACT_APP_MANIFEST_ACCESS_TOKEN=" +
214+
config.introspection!.azure!.source_repo_access_token
215+
);
207216
}
208217

209218
const manifestRepo = extractManifestRepositoryInformation(config);

src/commands/deployment/get.test.ts

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
import path from "path";
2-
import Deployment from "spektate/lib/Deployment";
3-
import { AzureDevOpsRepo } from "spektate/lib/repository/AzureDevOpsRepo";
4-
import { GitHub } from "spektate/lib/repository/GitHub";
2+
import { duration, IDeployment, status } from "spektate/lib/IDeployment";
3+
import * as Deployment from "spektate/lib/IDeployment";
4+
import { IAzureDevOpsRepo } from "spektate/lib/repository/IAzureDevOpsRepo";
5+
import * as AzureDevOpsRepo from "spektate/lib/repository/IAzureDevOpsRepo";
6+
import { IGitHub } from "spektate/lib/repository/IGitHub";
7+
import * as GitHub from "spektate/lib/repository/IGitHub";
58
import { ITag } from "spektate/lib/repository/Tag";
69
import { loadConfiguration } from "../../config";
710
import { deepClone } from "../../lib/util";
@@ -66,30 +69,32 @@ const data = require("./mocks/data.json");
6669
const fakeDeployments = data;
6770
// tslint:disable-next-line: no-var-requires
6871
const fakeClusterSyncs = require("./mocks/cluster-sync.json");
69-
const mockedDeps: Deployment[] = fakeDeployments.data.map((dep: Deployment) => {
70-
return new Deployment(
71-
dep.deploymentId,
72-
dep.commitId,
73-
dep.hldCommitId || "",
74-
dep.imageTag,
75-
dep.timeStamp,
76-
dep.environment,
77-
dep.service,
78-
dep.manifestCommitId,
79-
dep.srcToDockerBuild,
80-
dep.dockerToHldRelease,
81-
dep.hldToManifestBuild
82-
);
83-
});
72+
const mockedDeps: IDeployment[] = fakeDeployments.data.map(
73+
(dep: IDeployment) => {
74+
return {
75+
commitId: dep.commitId,
76+
deploymentId: dep.deploymentId,
77+
dockerToHldRelease: dep.dockerToHldRelease,
78+
environment: dep.environment,
79+
hldCommitId: dep.hldCommitId || "",
80+
hldToManifestBuild: dep.hldToManifestBuild,
81+
imageTag: dep.imageTag,
82+
manifestCommitId: dep.manifestCommitId,
83+
service: dep.service,
84+
srcToDockerBuild: dep.srcToDockerBuild,
85+
timeStamp: dep.timeStamp
86+
};
87+
}
88+
);
8489

8590
const mockedClusterSyncs: ITag[] = fakeClusterSyncs.data.map((sync: ITag) => {
8691
return sync;
8792
});
8893
jest
89-
.spyOn(GitHub.prototype, "getManifestSyncState")
94+
.spyOn(GitHub, "getManifestSyncState")
9095
.mockReturnValue(Promise.resolve(mockedClusterSyncs));
9196
jest
92-
.spyOn(AzureDevOpsRepo.prototype, "getManifestSyncState")
97+
.spyOn(AzureDevOpsRepo, "getManifestSyncState")
9398
.mockReturnValue(Promise.resolve(mockedClusterSyncs));
9499

95100
let initObject: IInitObject;
@@ -277,14 +282,14 @@ describe("Watch get deployments", () => {
277282

278283
describe("Introspect deployments", () => {
279284
test("verify basic fields are defined", () => {
280-
mockedDeps.forEach((deployment: Deployment) => {
281-
const dep = deployment as Deployment;
285+
mockedDeps.forEach((deployment: IDeployment) => {
286+
const dep = deployment as IDeployment;
282287

283288
// Make sure the basic fields are defined
284289
expect(dep.deploymentId).not.toBe("");
285290
expect(dep.service).not.toBe("");
286-
expect(dep.duration()).not.toBe("");
287-
expect(dep.status()).not.toBe("");
291+
expect(duration(dep)).not.toBe("");
292+
expect(status(dep)).not.toBe("");
288293
expect(dep.environment).not.toBe("");
289294
expect(dep.timeStamp).not.toBe("");
290295

@@ -327,7 +332,7 @@ describe("Print deployments", () => {
327332
const matchItems = table!.filter(field => field[2] === deployment[2]);
328333
expect(matchItems).toHaveLength(1); // one matching row
329334

330-
(matchItems[0] as Deployment[]).forEach((field, i) => {
335+
(matchItems[0] as IDeployment[]).forEach((field, i) => {
331336
expect(field).toEqual(deployment[i]);
332337
});
333338
expect(matchItems[0]).toHaveLength(14);

src/commands/deployment/get.ts

Lines changed: 38 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,20 @@
11
import Table from "cli-table";
22
import commander from "commander";
3-
import Deployment from "spektate/lib/Deployment";
3+
import {
4+
duration,
5+
getDeploymentsBasedOnFilters,
6+
IDeployment,
7+
status as getDeploymentStatus
8+
} from "spektate/lib/IDeployment";
49
import AzureDevOpsPipeline from "spektate/lib/pipeline/AzureDevOpsPipeline";
5-
import { AzureDevOpsRepo } from "spektate/lib/repository/AzureDevOpsRepo";
6-
import { GitHub } from "spektate/lib/repository/GitHub";
7-
import { IRepository } from "spektate/lib/repository/Repository";
10+
import {
11+
getManifestSyncState as getAzureManifestSyncState,
12+
IAzureDevOpsRepo
13+
} from "spektate/lib/repository/IAzureDevOpsRepo";
14+
import {
15+
getManifestSyncState as getGithubManifestSyncState,
16+
IGitHub
17+
} from "spektate/lib/repository/IGitHub";
818
import { ITag } from "spektate/lib/repository/Tag";
919
import { Config } from "../../config";
1020
import { build as buildCmd, exit as exitCmd } from "../../lib/commandBuilder";
@@ -152,10 +162,10 @@ export const processOutputFormat = (outputFormat: string): OUTPUT_FORMAT => {
152162
export const getDeployments = (
153163
initObj: IInitObject,
154164
values: IValidatedOptions
155-
): Promise<Deployment[]> => {
165+
): Promise<IDeployment[]> => {
156166
const config = initObj.config;
157167
const syncStatusesPromise = getClusterSyncStatuses(initObj);
158-
const deploymentsPromise = Deployment.getDeploymentsBasedOnFilters(
168+
const deploymentsPromise = getDeploymentsBasedOnFilters(
159169
config.introspection!.azure!.account_name!,
160170
initObj.key,
161171
config.introspection!.azure!.table_name!,
@@ -172,8 +182,8 @@ export const getDeployments = (
172182
);
173183
return new Promise((resolve, reject) => {
174184
Promise.all([deploymentsPromise, syncStatusesPromise])
175-
.then((tuple: [Deployment[] | undefined, ITag[] | undefined]) => {
176-
const deployments: Deployment[] | undefined = tuple[0];
185+
.then((tuple: [IDeployment[] | undefined, ITag[] | undefined]) => {
186+
const deployments: IDeployment[] | undefined = tuple[0];
177187
const syncStatuses: ITag[] | undefined = tuple[1];
178188
if (values.outputFormat === OUTPUT_FORMAT.JSON) {
179189
// tslint:disable-next-line: no-console
@@ -212,14 +222,15 @@ export const getClusterSyncStatuses = (
212222
const manifestUrlSplit = config.azure_devops?.manifest_repository.split(
213223
"/"
214224
);
215-
const manifestRepo: IRepository = new AzureDevOpsRepo(
216-
manifestUrlSplit[3],
217-
manifestUrlSplit[4],
218-
manifestUrlSplit[6],
225+
const manifestRepo: IAzureDevOpsRepo = {
226+
org: manifestUrlSplit[3],
227+
project: manifestUrlSplit[4],
228+
repo: manifestUrlSplit[6]
229+
};
230+
getAzureManifestSyncState(
231+
manifestRepo,
219232
config.azure_devops.access_token
220-
);
221-
manifestRepo
222-
.getManifestSyncState()
233+
)
223234
.then((syncCommits: ITag[]) => {
224235
resolve(syncCommits);
225236
})
@@ -233,13 +244,15 @@ export const getClusterSyncStatuses = (
233244
const manifestUrlSplit = config.azure_devops?.manifest_repository.split(
234245
"/"
235246
);
236-
const manifestRepo: IRepository = new GitHub(
237-
manifestUrlSplit[3],
238-
manifestUrlSplit[4],
247+
const manifestRepo: IGitHub = {
248+
reponame: manifestUrlSplit[4],
249+
username: manifestUrlSplit[3]
250+
};
251+
252+
getGithubManifestSyncState(
253+
manifestRepo,
239254
config.azure_devops.access_token
240-
);
241-
manifestRepo
242-
.getManifestSyncState()
255+
)
243256
.then((syncCommits: ITag[]) => {
244257
resolve(syncCommits);
245258
})
@@ -330,7 +343,7 @@ export const watchGetDeployments = async (
330343
* @param outputFormat output format: normal | wide | json
331344
*/
332345
export const printDeployments = (
333-
deployments: Deployment[] | undefined,
346+
deployments: IDeployment[] | undefined,
334347
outputFormat: OUTPUT_FORMAT,
335348
limit?: number,
336349
syncStatuses?: ITag[] | undefined
@@ -440,8 +453,8 @@ export const printDeployments = (
440453
: ""
441454
);
442455
if (outputFormat === OUTPUT_FORMAT.WIDE) {
443-
row.push(deployment.duration() + " mins");
444-
row.push(deployment.status());
456+
row.push(duration(deployment) + " mins");
457+
row.push(getDeploymentStatus(deployment));
445458
row.push(deployment.manifestCommitId || "-");
446459
row.push(
447460
deployment.hldToManifestBuild &&
@@ -481,7 +494,7 @@ export const printDeployments = (
481494
* @param syncStatuses list of sync statuses for manifest
482495
*/
483496
export const getClusterSyncStatusForDeployment = (
484-
deployment: Deployment,
497+
deployment: IDeployment,
485498
syncStatuses: ITag[]
486499
): ITag | undefined => {
487500
return syncStatuses.find(tag => tag.commit === deployment.manifestCommitId);

yarn.lock

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6011,10 +6011,10 @@ spdx-license-ids@^3.0.0:
60116011
resolved "https://registry.yarnpkg.com/spdx-license-ids/-/spdx-license-ids-3.0.5.tgz#3694b5804567a458d3c8045842a6358632f62654"
60126012
integrity sha512-J+FWzZoynJEXGphVIS+XEh3kFSjZX/1i9gFBaWQcB+/tmpe2qUsSBABpcxqxnAxFdiUFEgAX1bjYGQvIZmoz9Q==
60136013

6014-
spektate@^0.1.19:
6015-
version "0.1.19"
6016-
resolved "https://registry.yarnpkg.com/spektate/-/spektate-0.1.19.tgz#5118d0a17761285fd5624bbd214665e0d9124772"
6017-
integrity sha512-gQqdZagNAc9ssFuXUpMI1JZZGCCKZSZKbGS2z6btqi6EsCtlKnl107pHdQcU0kpgXRlmWaZeKvqa6Rmb7HMiRw==
6014+
spektate@^1.0.0:
6015+
version "1.0.0"
6016+
resolved "https://registry.yarnpkg.com/spektate/-/spektate-1.0.0.tgz#91d841724a19c66bb4c3d82e58eb3cb0468b77b5"
6017+
integrity sha512-QY8Nd4LhN5bcOpEPoNPig+JLEi2/INyjtPLXZ/t7o92pOa3b3FWbc4XULvcITpA9hsR4XbxPSax6ErKX+xtDfg==
60186018
dependencies:
60196019
axios "^0.19.0"
60206020
azure-storage "^2.10.3"

0 commit comments

Comments
 (0)