-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from nicubarbaros/master
👌 Improve fetch response
- Loading branch information
Showing
1 changed file
with
23 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`); | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|