Skip to content

Commit

Permalink
chore: replace axios with fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
martinjagodic committed Aug 12, 2024
1 parent 390e037 commit 6f7df38
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 43 deletions.
17 changes: 9 additions & 8 deletions functions/publish.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const crypto = require('crypto');
const axios = require('axios');

const verifySignature = event => {
function verifySignature(event) {
const timestamp = Number(event.headers['x-slack-request-timestamp']);
const time = Math.floor(Date.now() / 1000);
if (time - timestamp > 60 * 5) {
Expand Down Expand Up @@ -29,7 +28,7 @@ const verifySignature = event => {
`Signatures don't match. Expected: '${expectedSignature}', actual: '${actualSignature}'`,
);
}
};
}

exports.handler = async function(event) {
try {
Expand Down Expand Up @@ -62,11 +61,13 @@ exports.handler = async function(event) {
if (expectedCommand && expectedCommand == command) {
const githubToken = process.env.GITHUB_TOKEN;
const repo = process.env.GITHUB_REPO;
await axios({
headers: { Authorization: `token ${githubToken}` },
method: 'post',
url: `https://api.github.com/repos/${repo}/dispatches`,
data: { event_type: 'on-demand-github-action' },
await fetch(`https://api.github.com/repos/${repo}/dispatches`, {
method: 'POST',
headers: {
'Authorization': `token ${githubToken}`,
'Content-Type': 'application/json'
},
body: JSON.stringify({ event_type: 'on-demand-github-action' })
});
const message = 'Dispatched event to GitHub';
return { status: 200, body: message };
Expand Down
67 changes: 33 additions & 34 deletions package-lock.json

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

1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"@typescript-eslint/eslint-plugin": "^5.0.0",
"@typescript-eslint/parser": "^5.0.0",
"all-contributors-cli": "^6.0.0",
"axios": "^1.6.0",
"babel-core": "^7.0.0-bridge.0",
"babel-eslint": "^11.0.0-beta.2",
"babel-jest": "^27.5.1",
Expand Down

0 comments on commit 6f7df38

Please sign in to comment.