Skip to content
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,10 @@ jobs:
statuses: write
checks: write
steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v2
- uses: actions/setup-node@v3
with:
cache: 'npm'
node-version: 16
Expand All @@ -55,7 +55,7 @@ jobs:
- run: npm run test
name: 'Run the tests'
env:
OCTOPUS_HOST: ${{ env.SERVER_URL }}
OCTOPUS_URL: ${{ env.SERVER_URL }}
OCTOPUS_API_KEY: ${{ env.ADMIN_API_KEY }}
- uses: dorny/test-reporter@v1
if: success() || failure()
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import type { ProjectResource } from "@octopusdeploy/message-contracts";
// environment variables
//
// OCTOPUS_API_KEY: the API key used to connect to an instance of Octopus Deploy
// OCTOPUS_HOST: the host instance of Octopus Deploy
// OCTOPUS_URL: the host instance of Octopus Deploy
// OCTOPUS_SPACE: the space to target API commands in Octopus Deploy

// assume conventional configuration via environment variables
Expand Down
18 changes: 14 additions & 4 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ export default class ApiClient<TResource> {
this.adapter = new AxiosAdapter<TResource>();
}

async execute() {
async execute(useCamelCase: boolean = false) {
try {
const response = await this.adapter.execute(this.options);
this.handleSuccess(response);
this.handleSuccess(response, useCamelCase);
} catch (error: unknown) {
if (error instanceof AdapterError) {
this.handleError(error);
Expand All @@ -30,7 +30,7 @@ export default class ApiClient<TResource> {
}
}

private handleSuccess = (response: AdapterResponse<TResource>) => {
private handleSuccess = (response: AdapterResponse<TResource>, useCamelCase: boolean) => {
if (this.options.onResponseCallback) {
const details: ResponseDetails = {
method: this.options.method as any,
Expand All @@ -47,7 +47,17 @@ export default class ApiClient<TResource> {
} else {
responseText = JSON.stringify(response.data);
if (responseText && responseText.length > 0) {
responseText = JSON.parse(responseText);
responseText = JSON.parse(responseText, (_, val) => {
if (val === null || val === undefined || Array.isArray(val) || typeof val !== "object" || !useCamelCase) {
return val;
}
return Object.entries(val).reduce((a, [key, val]) => {
const b = a as any;
const field = key[0].toLowerCase() + key.substring(1);
b[field] = val;
return a;
}, {});
});
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ describe("client", () => {
test("connects using space id", async () => {
const clientConfiguration: ClientConfiguration = {
apiKey: process.env["OCTOPUS_API_KEY"] || "",
apiUri: process.env["OCTOPUS_HOST"] || "",
apiUri: process.env["OCTOPUS_URL"] || "",
space: "Spaces-1",
autoConnect: true
autoConnect: true,
};

const client = await Client.create(clientConfiguration);
Expand All @@ -26,9 +26,9 @@ describe("client", () => {
test("connects using space name", async () => {
const clientConfiguration: ClientConfiguration = {
apiKey: process.env["OCTOPUS_API_KEY"] || "",
apiUri: process.env["OCTOPUS_HOST"] || "",
apiUri: process.env["OCTOPUS_URL"] || "",
space: "Default",
autoConnect: true
autoConnect: true,
};

const client = await Client.create(clientConfiguration);
Expand All @@ -38,11 +38,11 @@ describe("client", () => {
test("throws with invalid space", async () => {
const clientConfiguration: ClientConfiguration = {
apiKey: process.env["OCTOPUS_API_KEY"] || "",
apiUri: process.env["OCTOPUS_HOST"] || "",
apiUri: process.env["OCTOPUS_URL"] || "",
space: "NonExistent",
autoConnect: true
autoConnect: true,
};

await expect(Client.create(clientConfiguration)).rejects.toThrow();
})
});
});
9 changes: 7 additions & 2 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,11 @@ export class Client {
this.errorSubscriptions.notifyAll(details);
}

do<TReturn>(path: string, command?: any, args?: RouteArgs): Promise<TReturn> {
const url = this.resolveUrlWithSpaceId(path, args);
return this.dispatchRequest("POST", url, command, true) as Promise<TReturn>;
}

post<TReturn>(path: string, resource?: any, args?: RouteArgs): Promise<TReturn> {
const url = this.resolveUrlWithSpaceId(path, args);
return this.dispatchRequest("POST", url, resource) as Promise<TReturn>;
Expand Down Expand Up @@ -404,7 +409,7 @@ export class Client {
return link;
}

private dispatchRequest(method: any, url: string, requestBody?: any) {
private dispatchRequest(method: any, url: string, requestBody?: any, useCamelCase: boolean = false) {
return new Promise((resolve, reject) => {
new ApiClient({
configuration: this.configuration,
Expand All @@ -419,7 +424,7 @@ export class Client {
onRequestCallback: (r) => this.onRequest(r),
onResponseCallback: (r) => this.onResponse(r),
onErrorResponseCallback: (r) => this.onErrorResponse(r),
}).execute();
}).execute(useCamelCase);
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/clientConfiguration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export interface ClientConfiguration {

export function processConfiguration(configuration?: ClientConfiguration): ClientConfiguration {
const apiKey = process.env[EnvironmentVariables.ApiKey] || "";
const host = process.env[EnvironmentVariables.Host] || "";
const host = process.env[EnvironmentVariables.URL] || "";
const space = process.env[EnvironmentVariables.Space] || "";

if (!configuration) {
Expand Down
2 changes: 1 addition & 1 deletion src/environmentVariables.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const EnvironmentVariables = {
ApiKey: "OCTOPUS_API_KEY",
Host: "OCTOPUS_HOST",
URL: "OCTOPUS_URL",
Proxy: "OCTOPUS_PROXY",
ProxyPassword: "OCTOPUS_PROXY_PASSWORD",
ProxyUsername: "OCTOPUS_PROXY_USERNAME",
Expand Down
81 changes: 0 additions & 81 deletions src/operations/createRelease/channel-version-rule-tester.ts

This file was deleted.

Loading