Skip to content

Instantly share code, notes, and snippets.

@uurtech
Created March 25, 2024 07:50
Show Gist options
  • Save uurtech/769cbfcc9f24f2e229cbe531abd8a6d9 to your computer and use it in GitHub Desktop.
Save uurtech/769cbfcc9f24f2e229cbe531abd8a6d9 to your computer and use it in GitHub Desktop.
const { spawn } = require('child_process');
module.exports.slackCommandHandler = async (event) => {
const { text } = event.body;
const deployWorkflow = spawn('curl', [
'-X', 'POST',
'-H', 'Authorization: token YOUR_GITHUB_TOKEN',
'-H', 'Accept: application/vnd.github.v3+json',
'https://api.github.com/repos/your_username/your_repo/actions/workflows/your_workflow_dispatch.yml/dispatches',
'-d', `{"ref":"${text}"}`,
]);
deployWorkflow.stdout.on('data', (data) => {
console.log(`stdout: ${data}`);
});
deployWorkflow.stderr.on('data', (data) => {
console.error(`stderr: ${data}`);
});
deployWorkflow.on('close', (code) => {
console.log(`child process exited with code ${code}`);
});
return {
statusCode: 200,
body: JSON.stringify({
message: `Deployment process has started for branch: ${text}`,
}),
};
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment