Skip to content

Commit

Permalink
WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvasconcelos committed Jul 10, 2023
1 parent ebcf36a commit 360ca32
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 13 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
# - uses: kognity/pr-update-action@master
with:
token: ${{ secrets.GITHUB_TOKEN }}
title: My new PR Title
title-prefix: PFX-999
title-suffix: "[BOT]"
body: My new PR Body
# title: My new PR Title
# title-prefix: PFX-999
# title-suffix: "[BOT]"
# body: My new PR Body
body-prefix: Some prefix on the body
body-suffix: Some suffix on the body
12 changes: 8 additions & 4 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ async function run() {
if (newPrTitle) updateRequest.title = newPrTitle;
if (newPrBody) updateRequest.body = newPrBody;

core.info(`Request: \n${JSON.stringify(updateRequest)}.`);
core.info(`Request: \n${JSON.stringify(updateRequest, null, 4)}.`);

if (!newPrTitle && !newPrBody) {
core.warning('No changes made to PR title or body. Exiting.');
Expand Down
19 changes: 16 additions & 3 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,28 @@ export function updateBody(
inputs: ReturnType<typeof getInputs>,
prBody: string
): string | undefined {
const {body, bodyPrefix, bodySuffix, bodyConcatNewLine} = inputs;
const {
body: bodyLines,
bodyPrefix: bodyPrefixLines,
bodySuffix: bodySuffixLines,
bodyConcatNewLine,
} = inputs;
const body = bodyLines.join('\n').trim();
const bodyPrefix = bodyPrefixLines.join('\n').trim();
const bodySuffix = bodySuffixLines.join('\n').trim();
const concatStrategy = bodyConcatNewLine ? '\n' : ' ';
core.info(`Current PR body: ${prBody}.`);
core.info(`Current PR body: \n${prBody}.`);
core.warning(
`This should be false, and the value is: ${JSON.stringify(
body || bodyPrefix || bodySuffix
)}.`
);

if (body || bodyPrefix || bodySuffix) {
const newBody = [bodyPrefix, body || prBody, bodySuffix]
.filter(Boolean)
.join(concatStrategy);
core.info(`New body: ${newBody}.`);
core.info(`New body: \n${newBody}`);
core.setOutput('new-body', newBody);
return newBody;
}
Expand Down

0 comments on commit 360ca32

Please sign in to comment.