-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
119 lines (103 loc) · 2.89 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
const { Toolkit } = require("actions-toolkit");
const { GraphQLClient, gql } = require("graphql-request");
// Run your GitHub Action!
Toolkit.run(
async (tools) => {
const allowedStatuses = ["published"];
if (!allowedStatuses.includes(tools.context.payload.action)) {
return tools.exit.failure(
`Release status is not in '${allowedStatuses.join(", ")}'. Got '${
tools.context.payload.action
}'`
);
}
if (!process.env.NOTICEABLE_API_KEY) {
return tools.exit.failure(
`Missing 'NOTICEABLE_API_KEY' environment variable`
);
}
if (!process.env.NOTICEABLE_PROJECT_ID) {
return tools.exit.failure(
`Missing 'NOTICEABLE_PROJECT_ID' environment variable`
);
}
const release = tools.context.payload.release;
const repoName = tools.context.payload.repository.name;
let labels = tools.inputs.tags
.split(",")
.map((t) => t.trim())
.filter((t) => t);
// Use the title from the release, plus anything set in the environment
let title = release.name;
if (tools.inputs.release_prefix) {
title = tools.inputs.release_prefix + " " + title;
}
// Then the content
let content = release.body;
// Sometimes we don't want to link to the release (e.g. if it's a private repo)
if (!tools.inputs.disable_repo_link) {
content += "\n\n" + release.html_url;
}
// Any prereleases go in to a beta category
if (release.prerelease) {
labels.push("Beta");
}
let draft = false;
if (tools.inputs.draft) {
draft = true;
}
// Reformat labels to the format Noticeable needs them
labels = labels.map((l) => {
return { name: l };
});
// Now let's create the release
await createChangelogEntry(process.env.NOTICEABLE_API_KEY, {
project: process.env.NOTICEABLE_PROJECT_ID,
title,
content,
draft,
created: new Date(release.published_at).toISOString(),
labels,
});
return tools.exit.success("Changelog entry created");
},
{
event: "release",
}
);
async function createChangelogEntry(auth, variables) {
const endpoint = `https://api.noticeable.io/graphql`;
const graphQLClient = new GraphQLClient(endpoint, {
headers: {
authorization: `Apikey ${auth}`,
},
});
const mutation = gql`
mutation AddEntry(
$project: ID!
$title: String!
$content: String!
$draft: Boolean!
$created: DateTime!
$labels: [LabelInput]
) {
createPost(
input: {
projectId: $project
author: { fullName: "Vonage" }
content: $content
isDraft: $draft
labels: $labels
publicationTime: $created
title: $title
}
) {
post {
id
permalink
}
}
}
`;
return await graphQLClient.request(mutation, variables);
}