Skip to content

Commit

Permalink
Fix typo and add logs
Browse files Browse the repository at this point in the history
  • Loading branch information
arthurvasconcelos committed Jul 10, 2023
1 parent 1619dd4 commit 139c89f
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
25 changes: 17 additions & 8 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.

12 changes: 11 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,14 +24,23 @@ async function run() {
if (newPrTitle) updateRequest.title = newPrTitle;
if (newPrBody) updateRequest.body = newPrBody;

if (!newPrTitle && !newPrBody) return;
core.info(`Request: \n${JSON.stringify(updateRequest)}.`);

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(error.name);
core.setFailed(error.name);
} else {
core.error('Something went wrong with the request.');
core.error(JSON.stringify(error));
}
}
}
Expand Down
14 changes: 7 additions & 7 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {RequestError} from '@octokit/types';

export function getInputs() {
return {
token: core.getInput('repo-token', {required: true}),
token: core.getInput('token', {required: true}),
title: core.getInput('title'),
titlePrefix: core.getInput('title-prefix'),
titleSuffix: core.getInput('title-suffix'),
Expand All @@ -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 @@ -39,18 +39,18 @@ export function updateBody(
): string | undefined {
const {body, bodyPrefix, bodySuffix, bodyConcatNewLine} = inputs;
const concatStrategy = bodyConcatNewLine ? '\n' : ' ';
core.info(`Current PR body: ${prBody}`);
core.info(`Current PR body: ${prBody}.`);

if (body || bodyPrefix || bodySuffix) {
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 139c89f

Please sign in to comment.