-
Notifications
You must be signed in to change notification settings - Fork 1
/
run.js
51 lines (41 loc) · 2.03 KB
/
run.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const core = require('@actions/core');
const { readSchemaFile, readReleaseNotes } = require('./readFile');
const updateSchemaFile = require('./updateSchemaFile');
const createNewVersion = require('./createNewVersion');
const getSchemaId = require("./getSchemaId");
async function run() {
try {
const postmanApiKey = core.getInput('postman-api-key');
const path = core.getInput('path-to-definition');
const apiId = core.getInput('api-id');
const fileName = core.getInput('api-path-to-file-name');
const versionName = core.getInput('version-name');
const releaseNotes = core.getInput('release-notes');
const releaseNotesFileName = core.getInput('release-notes-file-name');
core.info(`Inputs:`);
core.info(` path-to-definition: ${path}`);
core.info(` api-id: ${apiId}`);
core.info(` api-path-to-file-name: ${fileName}`);
core.info(` version-name: ${versionName}`);
core.info(` release-notes: ${releaseNotes}`);
core.info(` release-notes-file-name: ${releaseNotesFileName}`);
core.info(`Retrieving the Schema id from the API ...`);
const schemaId = await getSchemaId(postmanApiKey, apiId);
core.info(`Reading OpenAPI definition file ...`);
const openAPIFileContents = await readSchemaFile(path);
core.info(`Updating schema file ...`);
await updateSchemaFile(postmanApiKey, apiId, schemaId, openAPIFileContents, fileName);
core.info(`Reading Release notes from file or string ...`);
const releaseNotesContent = releaseNotesFileName ? await readReleaseNotes(releaseNotesFileName) : releaseNotes;
core.info(`Creating new version ...`);
const createdVersionId = await createNewVersion(postmanApiKey, apiId, schemaId, versionName, releaseNotesContent);
core.setOutput('createdVersionId', createdVersionId);
} catch (error) {
let message = error.message;
if (error.response) {
message = `${message}. Error code: ${error.response.status}. Error body: ${JSON.stringify(error.response.data)}`;
}
core.setFailed(message);
}
}
module.exports = run;