-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
41 lines (34 loc) · 1.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
const core = require("@actions/core");
const github = require("@actions/github");
const createPost = require("./src/dev");
// Get DEV secret token
const secret = core.getInput("dev-to-secret");
var tagsString = core.getInput("tags");
// Getting tags
var tags = tagsString.split(",");
// Get the JSON webhook payload for the event that triggered the workflow
const payload = github.context.payload;
if (payload.action === "published") {
try {
// Prepare data
const data = JSON.stringify({
article: {
title: payload.release.name,
published: true,
body_markdown: payload.release.body,
tags: tags,
},
});
core.info("Publishing post on DEV...");
// Creating POST request to DEV.to API
createPost(data, secret);
// Get the JSON webhook payload for the event that triggered the workflow
// const payload = JSON.stringify(github.context.payload, undefined, 2);
// console.log(`The event payload: ${payload}`);
} catch (error) {
core.setFailed(error.message);
}
} else {
// Set failed
core.setFailed("The workflow can only be triggered on release event");
}