Skip to content

Commit d229718

Browse files
committed
Fix signature for no body.
1 parent a2fd1bf commit d229718

File tree

2 files changed

+14
-18
lines changed

2 files changed

+14
-18
lines changed

dist/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -2946,7 +2946,6 @@ module.exports.wrap = wrap;
29462946
const axios = __webpack_require__(545);
29472947
const crypto = __webpack_require__(417);
29482948
const core = __webpack_require__(186);
2949-
29502949
const hmacSecret = core.getInput('hmacSecret');
29512950

29522951
if (!hmacSecret || hmacSecret === "" || hmacSecret.trim() === "") {
@@ -2960,9 +2959,11 @@ if (hmacSecret.length < 32) {
29602959

29612960
const createHmacSignature = body => {
29622961
const hmac = crypto.createHmac("sha256", hmacSecret);
2963-
const bodySignature = hmac.update(JSON.stringify(body)).digest("hex");
2964-
2965-
return `${bodySignature}`;
2962+
if (body === "") {
2963+
return hmac.digest("hex");
2964+
} else {
2965+
return hmac.update(JSON.stringify(body)).digest("hex");
2966+
}
29662967
};
29672968

29682969
function isJsonString(str) {
@@ -2976,21 +2977,18 @@ function isJsonString(str) {
29762977

29772978
const url = core.getInput('url');
29782979
const dataInput = core.getInput('data');
2979-
29802980
const data = isJsonString(dataInput) ? JSON.parse(dataInput) : dataInput;
2981-
2982-
29832981
const signature = createHmacSignature(data);
29842982

29852983
axios.post(url, data, {
29862984
headers: {
29872985
"X-Hub-Signature": signature,
29882986
"X-Hub-SHA": process.env.GITHUB_SHA
29892987
}
2990-
}).then(function (res) {
2988+
}).then(function () {
29912989
core.info(`Webhook sent sucessfully`)
29922990
}).catch(function (error) {
2993-
core.setFailed(`Request failed with status code ${error.response.status}!`);
2991+
core.setFailed(`Request failed with status code ${error.response.status}`);
29942992
});
29952993

29962994
/***/ }),

src/index.js

+7-9
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const axios = require("axios");
22
const crypto = require("crypto");
33
const core = require('@actions/core');
4-
54
const hmacSecret = core.getInput('hmacSecret');
65

76
if (!hmacSecret || hmacSecret === "" || hmacSecret.trim() === "") {
@@ -15,9 +14,11 @@ if (hmacSecret.length < 32) {
1514

1615
const createHmacSignature = body => {
1716
const hmac = crypto.createHmac("sha256", hmacSecret);
18-
const bodySignature = hmac.update(JSON.stringify(body)).digest("hex");
19-
20-
return `${bodySignature}`;
17+
if (body === "") {
18+
return hmac.digest("hex");
19+
} else {
20+
return hmac.update(JSON.stringify(body)).digest("hex");
21+
}
2122
};
2223

2324
function isJsonString(str) {
@@ -31,19 +32,16 @@ function isJsonString(str) {
3132

3233
const url = core.getInput('url');
3334
const dataInput = core.getInput('data');
34-
3535
const data = isJsonString(dataInput) ? JSON.parse(dataInput) : dataInput;
36-
37-
3836
const signature = createHmacSignature(data);
3937

4038
axios.post(url, data, {
4139
headers: {
4240
"X-Hub-Signature": signature,
4341
"X-Hub-SHA": process.env.GITHUB_SHA
4442
}
45-
}).then(function (res) {
43+
}).then(function () {
4644
core.info(`Webhook sent sucessfully`)
4745
}).catch(function (error) {
48-
core.setFailed(`Request failed with status code ${error.response.status}!`);
46+
core.setFailed(`Request failed with status code ${error.response.status}`);
4947
});

0 commit comments

Comments
 (0)