Skip to content

Commit

Permalink
♻️ refact(fetch): Use fetch instead of axios / Rename input (#9)
Browse files Browse the repository at this point in the history
  • Loading branch information
vvatelot authored Dec 9, 2022
1 parent adfa7d2 commit 439eab2
Show file tree
Hide file tree
Showing 88 changed files with 8,253 additions and 8,675 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ This action updates the OpenAPI documentation of an API that is hosted by RapidA

**Optional** Your RapidAPI API Key.

## `rapidapi-api-id`
## `rapidapi_api_id`

**Optional** Your RapidAPI API ID.

## `openapi-file`
## `openapi_file`

**Optional** The OpenAPI file you want to upload. Default `"openapi.json"`.

## `default-server-url`
## `default_server_url`

**Optional** You can provide a default server url. Default `""`.

Expand All @@ -40,7 +40,7 @@ jobs:
uses: vvatelot/[email protected]
with:
rapidapi-api-key: ${{ secrets.RAPIDAPI_API_KEY }}
rapidapi-api-id: ${{ secrets.RAPIDAPI_API_ID }}
openapi-file: "my-openapi.json"
rapidapi_api_id: ${{ secrets.RAPIDAPI_API_ID }}
openapi_file: "my-openapi.json"
default-url-server: "https://my.api.com:8001/"
```
8 changes: 4 additions & 4 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,19 @@ branding:
icon: "upload-cloud"
color: "blue"
inputs:
rapidapi-api-key:
rapidapi_api_key:
description: "Your RapiAPI API Key"
required: true
default: ""
rapidapi-api-id:
rapidapi_api_id:
description: "Your RapiAPI API ID"
required: true
default: ""
openapi-file:
openapi_file:
description: "Your OpenAPI file to use for update"
required: false
default: "openapi.json"
default-server-url:
default_server_url:
description: "You can provide a default server url"
required: false
default: ""
Expand Down
32 changes: 17 additions & 15 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@ const core = require("@actions/core");
const editJsonFile = require("edit-json-file");
const FormData = require("form-data");
const fs = require("fs");
const axios = require("axios");
const fetch = require('node-fetch');


try {
const rapidApiUrlHost = 'openapi-provisioning.p.rapidapi.com';
const rapidApiUrl =
"https://" + rapidApiUrlHost + "/v1/apis/" +
core.getInput("rapidapi-api-id");
const serverDefaultUrl = core.getInput("default-server-url");
const fileName = core.getInput("openapi-file");
const serverDefaultUrl = core.getInput("default_server_url");
const fileName = core.getInput("openapi_file");
const rapidapiApiKey = core.getInput("rapidapi_api_key");
const rapidapiApiId = core.getInput("rapidapi_api_id");
const rapidApiUrl = "https://" + rapidApiUrlHost + "/v1/apis/" + rapidapiApiId;

if (serverDefaultUrl != "") {
let file = editJsonFile(fileName);
Expand All @@ -25,21 +26,22 @@ try {

const options = {
method: 'PUT',
url: rapidApiUrl,
headers: {
'X-RapidAPI-Key': core.getInput("rapidapi-key"),
'X-RapidAPI-Key': rapidapiApiKey,
'X-RapidAPI-Host': rapidApiUrlHost,
...data.getHeaders()
},
data: data
body: data
};

axios.request(options).then(function () {
console.log("🎉 Open API Documentation updated to RapidAPI");
}).catch(function (error) {
console.log("🚨 Error when uploading Open API documentation to RapidAPI:")
core.setFailed(error);
})
fetch(rapidApiUrl, options)
.then(() => {
console.log("🎉 Open API Documentation successfuly updated to RapidAPI");
})
.catch((error) => {
console.log("🚨 Error when uploading Open API documentation to RapidAPI:")
core.setFailed(error);
});
} catch (error) {
console.log("🚨 Error when updating Open API documentation to RapidAPI:")
core.setFailed(error);
Expand Down
62 changes: 39 additions & 23 deletions node_modules/.package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 439eab2

Please sign in to comment.