Skip to content

Commit

Permalink
Adding log messages
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvasconcelos committed Jul 10, 2023
1 parent 1619dd4 commit f04d980
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
17 changes: 11 additions & 6 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.

8 changes: 7 additions & 1 deletion src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import {getInputs, updateTitle, updateBody, isRequestError} from './utils';

async function run() {
try {
core.info('Starting...');
const inputs = getInputs();
const prTitle: string = github.context.payload.pull_request?.title ?? '';
const prBody: string = github.context.payload.pull_request?.body ?? '';
Expand All @@ -23,12 +24,17 @@ async function run() {
if (newPrTitle) updateRequest.title = newPrTitle;
if (newPrBody) updateRequest.body = newPrBody;

if (!newPrTitle && !newPrBody) return;
if (!newPrTitle && !newPrBody) {
core.warning('No changes made to PR title or body. Exiting.');
return;
}

const octokit = github.getOctokit(inputs.token);
await octokit.request(requestEndpoint, updateRequest);
core.info('PR updated successfully.');
} catch (error) {
if (isRequestError(error)) {
core.error('Something went wrong with the request.');
core.error(error.name);
core.setFailed(error.name);
}
Expand Down
10 changes: 5 additions & 5 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,18 @@ export function updateTitle(
prTitle: string
): string | undefined {
const {title, titlePrefix, titleSuffix} = inputs;
core.info(`Current PR title: ${prTitle}`);
core.info(`Current PR title: ${prTitle}.`);

if (title || titlePrefix || titleSuffix) {
const newTitle = [titlePrefix, title || prTitle, titleSuffix]
.filter(Boolean)
.join(' ');
core.info(`New title: ${newTitle}`);
core.info(`New title: ${newTitle}.`);
core.setOutput('new-title', newTitle);
return newTitle;
}

core.warning('No updates were made to PR title');
core.warning('No updates were made to PR title.');
}

export function updateBody(
Expand All @@ -45,12 +45,12 @@ export function updateBody(
const newBody = [bodyPrefix, body || prBody, bodySuffix]
.filter(Boolean)
.join(concatStrategy);
core.info(`New body: ${newBody}`);
core.info(`New body: ${newBody}.`);
core.setOutput('new-body', newBody);
return newBody;
}

core.warning('No updates were made to PR body');
core.warning('No updates were made to PR body.');
}

export function isRequestError(error: unknown): error is RequestError {
Expand Down

0 comments on commit f04d980

Please sign in to comment.