Skip to content

Commit

Permalink
fix: Make string truncation unicode aware (#810)
Browse files Browse the repository at this point in the history
* fix: Make string truncation unicode aware

---------

Co-authored-by: Burak Yigit Kaya <[email protected]>
  • Loading branch information
BYK and Burak Yigit Kaya authored Jul 2, 2024
1 parent 6aad822 commit 8fd719a
Show file tree
Hide file tree
Showing 294 changed files with 2,327 additions and 3,040 deletions.
12 changes: 6 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,12 @@ jobs:
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v4

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: '18'

- name: yarn install
run: yarn install --immutable
Expand All @@ -71,7 +71,7 @@ jobs:
- name: test
run: yarn test:ci --coverage
- name: Codecov
uses: codecov/codecov-action@v3
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
- name: eslint
Expand Down Expand Up @@ -112,9 +112,9 @@ jobs:
fetch-depth: 0

- name: Setup node
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: '14'
node-version: '18'

- name: yarn install
run: yarn install --immutable
Expand Down
2,778 changes: 1,221 additions & 1,557 deletions .pnp.cjs

Large diffs are not rendered by default.

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/abab-npm-2.0.3-278ae51229-d3e4e4ff69.zip
Binary file not shown.
Binary file removed .yarn/cache/abab-npm-2.0.5-ae8d5b629e-0ec951b46d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/levn-npm-0.3.0-48d774b1c2-0d084a5242.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/psl-npm-1.8.0-226099d70e-6150048ed2.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/resolve-patch-b488a667f9-2443b94d34.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file removed .yarn/cache/tr46-npm-2.0.2-9a9c502938-2b2b3dfa6b.zip
Binary file not shown.
Binary file removed .yarn/cache/tr46-npm-2.1.0-00af583f4f-ffe6049b9d.zip
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
6 changes: 6 additions & 0 deletions jest.config.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
// eslint-disable-next-line
module.exports = {
// TODO: Remove the snapshotFormat override below and regen snapshots
// This is a remnant from the v29 upgrade
snapshotFormat: {
escapeString: true,
printBasicPrototype: true,
},
collectCoverageFrom: [
'**/*.ts',
'!test/**',
Expand Down
12 changes: 6 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,11 @@
"pg": "^8.5.1",
"source-map-support": "^0.5.21",
"tar": "^6.2.1",
"typescript": "^4.5.0"
"typescript": "^4.7.0"
},
"devDependencies": {
"@sentry/cli": "^2.20.1",
"@types/jest": "^27.0.3",
"@types/jest": "^29.0.0",
"@typescript-eslint/eslint-plugin": "^5.4.0",
"@typescript-eslint/parser": "^5.4.0",
"dotenv": "^16.0.3",
Expand All @@ -84,17 +84,17 @@
"eslint-plugin-prettier": "^4.0.0",
"eslint-plugin-simple-import-sort": "^7.0.0",
"husky": ">=4.3.0",
"jest": "27.3.1",
"jest-circus": "^27.3.1",
"jest": "^29.6.0",
"jest-circus": "^29.6.0",
"lint-staged": ">=10.5.4",
"lodash.clonedeep": "^4.5.0",
"lodash.merge": "^4.6.2",
"markdownlint-cli": "^0.27.1",
"nodemon": "^2.0.7",
"pino-pretty": "^4.5.0",
"prettier": "^2.4.1",
"ts-jest": "^27.0.7",
"ts-node": "^10.4.0"
"ts-jest": "^29.1.5",
"ts-node": "^10.8.1"
},
"resolutions": {
"set-value": ">=4.0.1"
Expand Down
2 changes: 1 addition & 1 deletion src/webhooks/pubsub/slackScores.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ describe('slackScores tests', function () {
├────────────────────────────────────────────────────────────────────┤
| <https://github.com/routing-repo/discussions/001|Discussion 1> | 3 |
| <https://github.com/routing-repo/discussions/002|Discussion 2> | 2 |
| <https://github.com/test-ttt-simple/discussions/003|Overflowing Discussion Title blahblahblahblahb...> | 1 |
| <https://github.com/test-ttt-simple/discussions/003|Overflowing Discussion Title blahblahblahblahbla…> | 1 |
└────────────────────────────────────────────────────────────────────┘
┌────────────────────────────────────────────────────────────────────┐
| Most Active Issues this Week │ # comments |
Expand Down
19 changes: 14 additions & 5 deletions src/webhooks/pubsub/slackScores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,19 +226,24 @@ export const sendGitHubActivityMetrics = async (
},
},
];

const segmentize = (text: string): string[] =>
Array.from(new Intl.Segmenter('en').segment(text)).map((s) => s.segment);

const addSpaces = (entry: string, column: string) => {
const entryLength = segmentize(entry).length;
if (column === 'discussion') {
return (
entry +
' '.repeat(
DISCUSSION_COLUMN_WIDTH + LESS_THAN_SIGN_LENGTH - entry.length
DISCUSSION_COLUMN_WIDTH + LESS_THAN_SIGN_LENGTH - entryLength
)
);
} else if (column === 'firstColumnItem') {
return entry + ' '.repeat(DISCUSSION_COLUMN_WIDTH - entry.length);
return entry + ' '.repeat(DISCUSSION_COLUMN_WIDTH - entryLength);
}
return (
' '.repeat(NUM_COMMENTS_COLUMN_WIDTH - entry.length - SPACE_LENGTH) +
' '.repeat(NUM_COMMENTS_COLUMN_WIDTH - entryLength - SPACE_LENGTH) +
entry +
' '
);
Expand Down Expand Up @@ -266,11 +271,15 @@ export const sendGitHubActivityMetrics = async (
);
scoreBoard += `| ${usernameText}| ${numCommentsText}|\n`;
} else {
// This is the correct char-by-char representation of a string that may have unicode chars
const segmentizedTitle = segmentize(itemInfo.title);
// Append less than sign here, because trailing spaces are ignored for text within the <> blocks for a hyperlink
const truncatedDiscussionTitle =
itemInfo.title.length <= DISCUSSION_COLUMN_WIDTH
segmentizedTitle.length <= DISCUSSION_COLUMN_WIDTH
? itemInfo.title + '>'
: `${itemInfo.title.slice(0, DISCUSSION_COLUMN_WIDTH - 4)}...> `;
: `${segmentizedTitle
.slice(0, DISCUSSION_COLUMN_WIDTH - 2)
.join('')}…> `;
const truncatedDiscussionTitleWithSpaces = addSpaces(
// Remove all instances of ` char from string
truncatedDiscussionTitle.replace(/`/g, ''),
Expand Down
5 changes: 3 additions & 2 deletions src/webhooks/pubsub/stalebot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,15 +158,16 @@ export const triggerStaleBot = async (org: GitHubOrg, now: moment.Moment) => {
(pullRequest) =>
!pullRequest.labels.some(
(label) =>
label === WORK_IN_PROGRESS_LABEL ||
(label as string) === WORK_IN_PROGRESS_LABEL ||
label.name === WORK_IN_PROGRESS_LABEL
)
);
// Unfortunately, octokit doesn't allow us to filter by labels when
// sending a GET request for pull requests, so we need to do this manually.
const stalePullRequests = pullRequestsToCheck.filter((pullRequest) =>
pullRequest.labels.some(
(label) => label === STALE_LABEL || label.name === STALE_LABEL
(label) =>
(label as string) === STALE_LABEL || label.name === STALE_LABEL
)
);
const activePullRequests = pullRequestsToCheck.filter(
Expand Down
4 changes: 3 additions & 1 deletion test/jest.tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"types": ["jest"]
"types": [
"jest"
]
}
}
8 changes: 5 additions & 3 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
{
"compilerOptions": {
"allowJs": false,
"lib": ["ES2020"],
"lib": ["ES2022"],
"module": "CommonJS",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"target": "ES2020",
"target": "ES2022",
"noImplicitReturns": true,
"noFallthroughCasesInSwitch": true,
"noUnusedLocals": true,
Expand All @@ -19,7 +19,9 @@
"resolveJsonModule": true,
"baseUrl": "./",
"paths": {
"_comment": ["⚠️ Keep this in sync with jest.config.ts and package.json. ⚠️ "],
"_comment": [
"⚠️ Keep this in sync with jest.config.ts and package.json. ⚠️ "
],
"@/*": ["src/*"],
"@api/*": ["src/api/*"],
"@test/*": ["test/*"],
Expand Down
Loading

0 comments on commit 8fd719a

Please sign in to comment.