Skip to content
This repository has been archived by the owner on Feb 27, 2024. It is now read-only.

Commit

Permalink
add append
Browse files Browse the repository at this point in the history
  • Loading branch information
rahulpatidar0191 committed Jan 16, 2024
1 parent 6b4cee2 commit 8423bd4
Showing 1 changed file with 48 additions and 26 deletions.
74 changes: 48 additions & 26 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,53 @@
const core = require("@actions/core");
const github = require("@actions/github");

try {
const { context } = github;
const githubToken = core.getInput("GITHUB_TOKEN");
const body = 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 (!body) {
core.setFailed("body input is required");
return;
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);
}
}

const { number: prNumber } = context.payload.pull_request;
const octokit = new github.GitHub(githubToken);
octokit.pulls.update({
...context.repo,
pull_number: prNumber,
body
});
} catch (error) {
core.setFailed(error.message);
}
// Call the asynchronous function
run();

0 comments on commit 8423bd4

Please sign in to comment.