This repository has been archived by the owner on Feb 27, 2024. It is now read-only.
forked from AsasInnab/pr-body-action
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
53 lines (45 loc) · 1.42 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
const core = require("@actions/core");
const github = require("@actions/github");
async function run() {
try {
const { context } = github;
const githubToken = core.getInput("GITHUB_TOKEN");
const newBody = core.getInput("body");
if (context.payload.pull_request == null) {
core.setFailed("No pull request found");
return;
}
if (!githubToken) {
core.setFailed("GITHUB_TOKEN input is required");
return;
}
if (!newBody) {
core.setFailed("body input is required");
return;
}
const { number: prNumber } = context.payload.pull_request;
const octokit = new github.GitHub(githubToken);
// Fetch the current pull request details
const { data: currentPR } = await octokit.pulls.get({
...context.repo,
pull_number: prNumber,
});
// Check if newBody already exists in the current description
if (currentPR.body.includes(newBody)) {
console.log("New body already exists in the current description. No update needed.");
return;
}
// Concatenate the new text to the existing description
const combinedBody = `${currentPR.body}\n\n${newBody}`;
// Update the pull request with the combined text
await octokit.pulls.update({
...context.repo,
pull_number: prNumber,
body: combinedBody,
});
} catch (error) {
core.setFailed(error.message);
}
}
// Call the asynchronous function
run();