Skip to content

Commit

Permalink
Updated project creation request
Browse files Browse the repository at this point in the history
Signed-off-by: Deepankumar Loganathan <deepan0433@gmail.com>
  • Loading branch information
deepan10 committed Nov 7, 2024
1 parent 1e4c643 commit aa841dc
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 18 deletions.
6 changes: 6 additions & 0 deletions workspaces/blackduck/plugins/blackduck-common/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,12 @@
```ts
import { ResourcePermission } from '@backstage/plugin-permission-common';

// @public (undocumented)
export type BD_CREATE_PROJECT_API_RESPONSE = {
status: Number;
location?: String;
};

// @public (undocumented)
export type BD_PROJECT_DETAIL = {
name: string;
Expand Down
8 changes: 8 additions & 0 deletions workspaces/blackduck/plugins/blackduck-common/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,3 +93,11 @@ export type BD_VERSIONS_API_RESPONSE = {
appliedFilters: [];
_meta: META;
};

/**
* @public
*/
export type BD_CREATE_PROJECT_API_RESPONSE = {
status: Number;
location?: String;
};
7 changes: 4 additions & 3 deletions workspaces/blackduck/plugins/blackduck-node/report.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
> Do not edit this file. It is a report generated by [API Extractor](https://api-extractor.com/).
```ts
import { BD_CREATE_PROJECT_API_RESPONSE } from '@backstage-community/plugin-blackduck-common';
import { BD_REST_API_RESPONSE } from '@backstage-community/plugin-blackduck-common';
import { BD_VERSIONS_API_RESPONSE } from '@backstage-community/plugin-blackduck-common';
import { Config } from '@backstage/config';
Expand Down Expand Up @@ -36,9 +37,9 @@ export class BlackDuckRestApi {
createProject(
projectName: string,
projectVersion?: string,
phase?: string,
distribution?: string,
): Promise<any>;
versionPhase?: string,
versionDistribution?: string,
): Promise<BD_CREATE_PROJECT_API_RESPONSE>;
// (undocumented)
getProjects(name: string): Promise<BD_REST_API_RESPONSE>;
// (undocumented)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import {
BD_VERISON_DETAIL,
BD_VERSIONS_API_RESPONSE,
BD_PROJECTS_API_RESPONSE,
BD_CREATE_PROJECT_API_RESPONSE,
} from '@backstage-community/plugin-blackduck-common';

/**
Expand Down Expand Up @@ -173,21 +174,27 @@ export class BlackDuckRestApi {
public async createProject(
projectName: string,
projectVersion?: string,
phase: string = 'DEVELOPMENT',
distribution: string = 'INTERNAL',
): Promise<any> {
versionPhase: string = 'DEVELOPMENT',
versionDistribution: string = 'INTERNAL',
): Promise<BD_CREATE_PROJECT_API_RESPONSE> {
const create_project_api = `${this.host}/projects`;
const payload: any = {};
const versionRequest = projectVersion
? {
versionName: projectVersion,
phase: versionPhase,
distribution: versionDistribution,
}
: undefined;
const payload = { name: projectName, versionRequest };
// const payload: any = {};
payload.name = projectName;
if (projectVersion) {
payload.versionRequest = {
versionName: projectVersion,
phase: phase,
distribution: distribution,
phase: versionPhase,
distribution: versionDistribution,
};
}
this.logger.info(`Project ${JSON.stringify(payload)}`);

const res = await fetch(create_project_api, {
method: 'POST',
headers: {
Expand All @@ -204,6 +211,6 @@ export class BlackDuckRestApi {
throw new Error(`Unable to create project!`);
}

return res;
return { status: res.status, location: res.headers.get('Location')! };
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
"postpack": "backstage-cli package postpack"
},
"dependencies": {
"@backstage-community/plugin-blackduck-common": "workspace:^",
"@backstage-community/plugin-blackduck-node": "workspace:^",
"@backstage/backend-plugin-api": "^1.0.1",
"@backstage/plugin-scaffolder-node": "^0.4.9"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
BlackDuckRestApi,
BlackDuckConfig,
} from '@backstage-community/plugin-blackduck-node';
import { BD_CREATE_PROJECT_API_RESPONSE } from '@backstage-community/plugin-blackduck-common';

/**
* @public
Expand Down Expand Up @@ -109,18 +110,21 @@ export function createBlackduckProjectAction(

await blackDuckApi.auth();

await blackDuckApi.createProject(
projectName,
projectVersion,
versionPhase,
versionDistribution,
);
const res: BD_CREATE_PROJECT_API_RESPONSE =
await blackDuckApi.createProject(
projectName,
projectVersion,
versionPhase,
versionDistribution,
);

ctx.output('projectName', projectName);
ctx.output('projectVersion', projectVersion);
ctx.output('versionPhase', versionPhase);
ctx.output('versionDistribution', versionDistribution);
ctx.output('instanceName', instanceName);
ctx.output('status', `${res.status}`);
ctx.output('location', `${res.location}`);
},
});
}
1 change: 1 addition & 0 deletions workspaces/blackduck/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2849,6 +2849,7 @@ __metadata:
version: 0.0.0-use.local
resolution: "@backstage-community/plugin-scaffolder-backend-module-blackduck@workspace:plugins/scaffolder-backend-module-blackduck"
dependencies:
"@backstage-community/plugin-blackduck-common": "workspace:^"
"@backstage-community/plugin-blackduck-node": "workspace:^"
"@backstage/backend-common": ^0.24.0
"@backstage/backend-plugin-api": ^1.0.1
Expand Down

0 comments on commit aa841dc

Please sign in to comment.