Skip to content

Commit

Permalink
Merge pull request #1 from nicubarbaros/master
Browse files Browse the repository at this point in the history
👌 Improve fetch response
  • Loading branch information
tommy-anderson authored Oct 13, 2021
2 parents 7ef0237 + 6727217 commit 1c7545b
Showing 1 changed file with 23 additions and 31 deletions.
54 changes: 23 additions & 31 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,34 @@
const core = require('@actions/core');
const core = require("@actions/core");
const fetch = require("node-fetch");

try {
const apiKey = core.getInput('apiKey')
const repoName = core.getInput('repoName')
const apiExtra = core.getInput('apiExtra')
const buttons = core.getInput('buttons')
const branch = core.getInput('branch')
const ref = core.getInput('ref')

const url = `https://webapp.io/api/v1/run/${repoName}?token=${apiKey}`
const payload =
{
const apiKey = core.getInput("apiKey");
const repoName = core.getInput("repoName");
const apiExtra = core.getInput("apiExtra");
const buttons = core.getInput("buttons");
const branch = core.getInput("branch");
const ref = core.getInput("ref");

const url = `https://webapp.io/api/v1/run/${repoName}?token=${apiKey}`;
const payload = {
method: "POST",
headers: {
'Content-Type': 'application/json'
"Content-Type": "application/json",
},
body: JSON.stringify({
'branch': branch,
'ref': ref,
'accept_buttons': buttons,
'extra': apiExtra,
branch: branch,
ref: ref,
accept_buttons: buttons,
extra: apiExtra,
}),
}

fetch(url,payload).then(res => res.json()).then(json => {
console.log(json)
if(json.status!=='ok'){
core.setFailed("POST returned something unexpected")
}
})

};

fetch(url, payload).then((response) => {
// Response object https://developer.mozilla.org/en-US/docs/Web/API/Response
if (!response.ok) {
core.setFailed("POST returned something unexpected");
}
});
} catch (error) {
core.setFailed(`Action failed with error ${error}`);
}






0 comments on commit 1c7545b

Please sign in to comment.