Skip to content

Commit

Permalink
Merge pull request #3 from yuri-val/dev
Browse files Browse the repository at this point in the history
🔧 Enhance PR description handling and improve variable naming
  • Loading branch information
yuri-val authored Oct 26, 2024
2 parents b5f4d81 + 85e8454 commit d9ead25
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 10 deletions.
27 changes: 22 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34509,13 +34509,13 @@ async function run() {
const diffOutput = execSync(`git diff origin/${baseRef} origin/${headRef}`, { encoding: 'utf8' });

// Generate the PR description
const description = await generateDescription(diffOutput, openaiApiKey, openaiModel, temperature);
const generatedDescription = await generateDescription(diffOutput, openaiApiKey, openaiModel, temperature);

// Update the PR
await updatePRDescription(githubToken, context, prNumber, description);
await updatePRDescription(githubToken, context, prNumber, generatedDescription);

core.setOutput('pr_number', prNumber.toString());
core.setOutput('description', description);
core.setOutput('description', generatedDescription);
console.log(`Successfully updated PR #${prNumber} description.`);
} catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -34566,14 +34566,31 @@ ${diffOutput}`;
return description;
}

async function updatePRDescription(githubToken, context, prNumber, description) {
async function updatePRDescription(githubToken, context, prNumber, generatedDescription) {
const octokit = github.getOctokit(githubToken);

// Fetch the current PR description
const { data: pullRequest } = await octokit.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});

let newDescription = pullRequest.body || '';

// Append the generated description
if (newDescription) {
newDescription += '\n\n';
newDescription += '---\n\n';
}
newDescription += generatedDescription;

// Update the PR with the new description
await octokit.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: description,
body: newDescription,
});
}

Expand Down
27 changes: 22 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ async function run() {
const diffOutput = execSync(`git diff origin/${baseRef} origin/${headRef}`, { encoding: 'utf8' });

// Generate the PR description
const description = await generateDescription(diffOutput, openaiApiKey, openaiModel, temperature);
const generatedDescription = await generateDescription(diffOutput, openaiApiKey, openaiModel, temperature);

// Update the PR
await updatePRDescription(githubToken, context, prNumber, description);
await updatePRDescription(githubToken, context, prNumber, generatedDescription);

core.setOutput('pr_number', prNumber.toString());
core.setOutput('description', description);
core.setOutput('description', generatedDescription);
console.log(`Successfully updated PR #${prNumber} description.`);
} catch (error) {
core.setFailed(error.message);
Expand Down Expand Up @@ -90,14 +90,31 @@ ${diffOutput}`;
return description;
}

async function updatePRDescription(githubToken, context, prNumber, description) {
async function updatePRDescription(githubToken, context, prNumber, generatedDescription) {
const octokit = github.getOctokit(githubToken);

// Fetch the current PR description
const { data: pullRequest } = await octokit.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
});

let newDescription = pullRequest.body || '';

// Append the generated description
if (newDescription) {
newDescription += '\n\n';
newDescription += '---\n\n';
}
newDescription += generatedDescription;

// Update the PR with the new description
await octokit.rest.pulls.update({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: prNumber,
body: description,
body: newDescription,
});
}

Expand Down

0 comments on commit d9ead25

Please sign in to comment.