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
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6b4cee2
commit 8423bd4
Showing
1 changed file
with
48 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); |