You've already forked dynamic-badges-action
✨ Apply clang-format
This commit is contained in:
53
index.js
53
index.js
@@ -17,30 +17,30 @@ try {
|
|||||||
'Authorization': 'token ' + core.getInput('auth'),
|
'Authorization': 'token ' + core.getInput('auth'),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return doRequest(updateGistOptions, data)
|
return doRequest(updateGistOptions, data)
|
||||||
}
|
}
|
||||||
|
|
||||||
function doRequest(options, data) {
|
function doRequest(options, data) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const req = http.request(options, (res) => {
|
const req = http.request(options, (res) => {
|
||||||
res.setEncoding('utf8');
|
res.setEncoding('utf8');
|
||||||
let responseBody = '';
|
let responseBody = '';
|
||||||
|
|
||||||
res.on('data', (chunk) => {
|
res.on('data', (chunk) => {
|
||||||
responseBody += chunk;
|
responseBody += chunk;
|
||||||
});
|
});
|
||||||
|
|
||||||
res.on('end', () => {
|
res.on('end', () => {
|
||||||
const { statusCode, statusMessage } = res;
|
const {statusCode, statusMessage} = res;
|
||||||
resolve({ statusCode, statusMessage, body: JSON.parse(responseBody) });
|
resolve({statusCode, statusMessage, body: JSON.parse(responseBody)});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
req.on('error', (err) => {
|
req.on('error', (err) => {
|
||||||
reject(err);
|
reject(err);
|
||||||
});
|
});
|
||||||
|
|
||||||
req.write(data)
|
req.write(data)
|
||||||
req.end();
|
req.end();
|
||||||
});
|
});
|
||||||
@@ -56,8 +56,8 @@ try {
|
|||||||
message: core.getInput('message')
|
message: core.getInput('message')
|
||||||
};
|
};
|
||||||
|
|
||||||
const updateIfChanged = core.getInput('updateIfChanged');
|
const updateIfChanged = core.getInput('updateIfChanged');
|
||||||
|
|
||||||
// Compute the message color based on the given inputs.
|
// Compute the message color based on the given inputs.
|
||||||
const color = core.getInput('color');
|
const color = core.getInput('color');
|
||||||
const valColorRange = core.getInput('valColorRange');
|
const valColorRange = core.getInput('valColorRange');
|
||||||
@@ -70,7 +70,7 @@ try {
|
|||||||
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
|
if (minColorRange != '' && maxColorRange != '' && valColorRange != '') {
|
||||||
const max = parseFloat(maxColorRange);
|
const max = parseFloat(maxColorRange);
|
||||||
const min = parseFloat(minColorRange);
|
const min = parseFloat(minColorRange);
|
||||||
let val = parseFloat(valColorRange);
|
let val = parseFloat(valColorRange);
|
||||||
|
|
||||||
if (val < min) val = min;
|
if (val < min) val = min;
|
||||||
if (val > max) val = max;
|
if (val > max) val = max;
|
||||||
@@ -151,10 +151,9 @@ try {
|
|||||||
|
|
||||||
// For the POST request, the above content is set as file contents for the
|
// For the POST request, the above content is set as file contents for the
|
||||||
// given filename.
|
// given filename.
|
||||||
const request = JSON.stringify({
|
const request =
|
||||||
files: {[filename]: {content: JSON.stringify(content)}}
|
JSON.stringify({files: {[filename]: {content: JSON.stringify(content)}}});
|
||||||
});
|
|
||||||
|
|
||||||
if (updateIfChanged == 'true') {
|
if (updateIfChanged == 'true') {
|
||||||
const getGistOptions = {
|
const getGistOptions = {
|
||||||
host: 'api.github.com',
|
host: 'api.github.com',
|
||||||
@@ -166,20 +165,22 @@ try {
|
|||||||
'Authorization': 'token ' + core.getInput('auth'),
|
'Authorization': 'token ' + core.getInput('auth'),
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
doRequest(getGistOptions, JSON.stringify({})).then(oldGist => {
|
doRequest(getGistOptions, JSON.stringify({})).then(oldGist => {
|
||||||
if (oldGist.statusCode < 200 || oldGist.statusCode >= 400) {
|
if (oldGist.statusCode < 200 || oldGist.statusCode >= 400) {
|
||||||
// print the error, but don't fail the action
|
// print the error, but don't fail the action
|
||||||
console.log(
|
console.log(
|
||||||
'Failed to get gist, response status code: ' + oldGist.statusCode +
|
'Failed to get gist, response status code: ' + oldGist.statusCode +
|
||||||
', status message: ' + oldGist.statusMessage);
|
', status message: ' + oldGist.statusMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (oldGist && oldGist.body && oldGist.body.files && oldGist.body.files[filename]) {
|
if (oldGist && oldGist.body && oldGist.body.files &&
|
||||||
|
oldGist.body.files[filename]) {
|
||||||
const oldContent = oldGist.body.files[filename].content;
|
const oldContent = oldGist.body.files[filename].content;
|
||||||
|
|
||||||
if (oldContent === JSON.stringify(content)) {
|
if (oldContent === JSON.stringify(content)) {
|
||||||
console.log(`Content did not change, not updating gist at ${filename}`);
|
console.log(
|
||||||
|
`Content did not change, not updating gist at ${filename}`);
|
||||||
shouldUpdate = false;
|
shouldUpdate = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -194,8 +195,8 @@ try {
|
|||||||
updatingGist(request).then(res => {
|
updatingGist(request).then(res => {
|
||||||
if (res.statusCode < 200 || res.statusCode >= 400) {
|
if (res.statusCode < 200 || res.statusCode >= 400) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
'Failed to create gist, response status code: ' + res.statusCode +
|
'Failed to create gist, response status code: ' +
|
||||||
', status message: ' + res.statusMessage);
|
res.statusCode + ', status message: ' + res.statusMessage);
|
||||||
} else {
|
} else {
|
||||||
console.log('Success!');
|
console.log('Success!');
|
||||||
}
|
}
|
||||||
@@ -206,8 +207,8 @@ try {
|
|||||||
updatingGist(request).then(res => {
|
updatingGist(request).then(res => {
|
||||||
if (res.statusCode < 200 || res.statusCode >= 400) {
|
if (res.statusCode < 200 || res.statusCode >= 400) {
|
||||||
core.setFailed(
|
core.setFailed(
|
||||||
'Failed to create gist, response status code: ' + res.statusCode +
|
'Failed to create gist, response status code: ' + res.statusCode +
|
||||||
', status message: ' + res.statusMessage);
|
', status message: ' + res.statusMessage);
|
||||||
} else {
|
} else {
|
||||||
console.log('Success!');
|
console.log('Success!');
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user