Skip to content

Commit

Permalink
chore: update code
Browse files Browse the repository at this point in the history
  • Loading branch information
bytemain committed Feb 6, 2024
1 parent 305b379 commit 9d82a50
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 39 deletions.
13 changes: 4 additions & 9 deletions src/github/templates/prOrIssue.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import {
} from '../types';

import {
renderUserLink,
renderPrOrIssueTitleLink,
renderDeletedPrOrIssueTitleLink,
titleTpl,
Expand All @@ -31,14 +30,8 @@ export const NameBlock = {
[key in Name]: string;
};

function prettyStateReason(stateReason: string) {
function prettyIssueStateReason(stateReason: string) {
switch (stateReason) {
case 'off_topic':
return 'off topic';
case 'too_heated':
return 'too heated';
case 'resolved':
return 'resolved';
case 'not_planned':
return 'not planned';
default:
Expand Down Expand Up @@ -88,7 +81,9 @@ function render(
let textFirstLine = `{{sender | link:sender}} ${action} [${nameBlock}](${data.html_url})`;

if ((data as Issue).state_reason) {
textFirstLine += ` as ${prettyStateReason((data as Issue).state_reason!)}`;
textFirstLine += ` as ${prettyIssueStateReason(
(data as Issue).state_reason!,
)}`;
}

const text = textTpl(
Expand Down
45 changes: 15 additions & 30 deletions src/github/templates/utils.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { Repository } from '@octokit/webhooks-types';
import capitalize from 'lodash/capitalize';

import { StringBuilder } from '@/utils/string-builder';
Expand Down Expand Up @@ -113,38 +112,24 @@ export function renderAssigneeInfo(
return `> Assignees: ${assigneeNames} `;
}

interface ISenderBasic {
login: string;
html_url: string;
}

interface ITeamBasic {
name: string;
html_url: string;
}

export function renderRequestedReviewersInfo(
reviewers: (
| {
name: string;
html_url: string;
}
| {
login: string;
html_url: string;
}
)[],
reviewers: (ISenderBasic | ITeamBasic)[],
) {
const reviewerNames = reviewers
.map((v) =>
(
v as {
login: string;
html_url: string;
}
).login
? renderUserLink(
v as {
login: string;
html_url: string;
},
)
: renderTeamLink(
v as {
name: string;
html_url: string;
},
),
(v as ISenderBasic).login
? renderUserLink(v as ISenderBasic)
: renderTeamLink(v as ITeamBasic),
)
.join(', ');
return `> Requested reviewers: ${reviewerNames} `;
Expand Down Expand Up @@ -183,7 +168,7 @@ export function renderPrOrIssueBody(
const builder = new StringBuilder();

if (p.body) {
builder.add(`${useRef(p.body, bodyLimit)}`);
builder.add(useRef(p.body, bodyLimit));
}

return builder.build();
Expand Down

0 comments on commit 9d82a50

Please sign in to comment.