From d24eda0835764f88e5583c4668275a38544a56aa Mon Sep 17 00:00:00 2001 From: jaychang99 Date: Wed, 24 Jul 2024 20:51:54 +0900 Subject: [PATCH 1/5] chore: update openapi-diff-node to v2.0.0 (description support) --- package-lock.json | 8 ++++---- package.json | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/package-lock.json b/package-lock.json index f6376ef..0b92f80 100644 --- a/package-lock.json +++ b/package-lock.json @@ -12,7 +12,7 @@ "@actions/core": "^1.10.1", "@slack/web-api": "^7.3.1", "markdown-it": "^14.1.0", - "openapi-diff-node": "1.1.0" + "openapi-diff-node": "2.0.0" }, "devDependencies": { "@jest/globals": "^29.7.0", @@ -5862,9 +5862,9 @@ } }, "node_modules/openapi-diff-node": { - "version": "1.1.0", - "resolved": "https://registry.npmjs.org/openapi-diff-node/-/openapi-diff-node-1.1.0.tgz", - "integrity": "sha512-eolLUj8pnJmBhaKFVIOyvuy0p7/kZepRQAQAzSvR/tvUYIxGfYbuJsyhLB1PksY2cuhyDP9zYetLwbHJznA/ig==" + "version": "2.0.0", + "resolved": "https://registry.npmjs.org/openapi-diff-node/-/openapi-diff-node-2.0.0.tgz", + "integrity": "sha512-afi99lJmxlm22tPQcwpn9AvG9QRoUQ6ncXOW+ROabJTuw9t6jjJaB+ese/p9ekZ5OONmqRuf9rwx3BRMnJQLOA==" }, "node_modules/openapi-types": { "version": "12.1.3", diff --git a/package.json b/package.json index 8c8f2c9..6f37ff5 100644 --- a/package.json +++ b/package.json @@ -76,7 +76,7 @@ "@actions/core": "^1.10.1", "@slack/web-api": "^7.3.1", "markdown-it": "^14.1.0", - "openapi-diff-node": "1.1.0" + "openapi-diff-node": "2.0.0" }, "devDependencies": { "@jest/globals": "^29.7.0", From ca5467df1f5f704f8dd0f3c0a785e376c5abb889 Mon Sep 17 00:00:00 2001 From: jaychang99 Date: Wed, 24 Jul 2024 20:52:16 +0900 Subject: [PATCH 2/5] feat(Slack): add description for API endpoint in slack messages --- src/services/slack.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/services/slack.ts b/src/services/slack.ts index 3ba56b6..a5f54ad 100644 --- a/src/services/slack.ts +++ b/src/services/slack.ts @@ -78,6 +78,7 @@ export class Slack { diff: DiffOutputItem ): Promise { const endpoint = `${diff.method.toUpperCase()}: ${diff.path}` + const description = diff.description const changedParameters = this._getUnchangedItems(diff.queryParams) const changedRequestBody = this._getUnchangedItems(diff.requestBody) @@ -150,6 +151,10 @@ export class Slack { type: 'mrkdwn', text: `*${translate('endpoint.singular')}:*\n ${endpoint}` }, + { + type: 'mrkdwn', + text: `*${translate('description')}:*\n ${description}` + }, { type: 'mrkdwn', text: `*${translate('repository')}: *\n Date: Wed, 24 Jul 2024 20:58:31 +0900 Subject: [PATCH 3/5] fix(Slack): add whitespace between enums --- src/services/slack.ts | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/services/slack.ts b/src/services/slack.ts index a5f54ad..742ace1 100644 --- a/src/services/slack.ts +++ b/src/services/slack.ts @@ -320,11 +320,22 @@ export class Slack { for (const changeLog of param.changeLogs) { const { field, oldValue, newValue } = changeLog + let oldValueText = oldValue + let newValueText = newValue + + if (Array.isArray(oldValue)) { + oldValueText = oldValue.join(', ') + } + + if (Array.isArray(newValue)) { + newValueText = newValue.join(', ') + } + changeLogElementList.push({ type: 'text', text: `${field} ${translate( 'status.modified' - )}: ${oldValue} -> ${newValue}` + )}: ${oldValueText} -> ${newValueText}` }) } From a19a1f1e90e1495402ffeeec31f86aa301b64f8a Mon Sep 17 00:00:00 2001 From: jaychang99 Date: Wed, 24 Jul 2024 21:41:59 +0900 Subject: [PATCH 4/5] feat(Slack): improve readability of changed properties --- src/locale/en-us.ts | 6 +++- src/locale/ko-kr.ts | 6 +++- src/services/slack.ts | 76 +++++++++++++++++++++++++++++++++++++------ src/types/locale.ts | 4 +++ 4 files changed, 80 insertions(+), 12 deletions(-) diff --git a/src/locale/en-us.ts b/src/locale/en-us.ts index 67ddbee..3f5f211 100644 --- a/src/locale/en-us.ts +++ b/src/locale/en-us.ts @@ -26,5 +26,9 @@ export const LOCALE_EN_US: Locale = { description: 'description', required: 'required', - example: 'example' + example: 'example', + + 'changed.before': 'Before', + 'changed.after': 'After', + 'properties.changed': 'Properties changed' } diff --git a/src/locale/ko-kr.ts b/src/locale/ko-kr.ts index 443f57e..3d3c15f 100644 --- a/src/locale/ko-kr.ts +++ b/src/locale/ko-kr.ts @@ -26,5 +26,9 @@ export const LOCALE_KO_KR: Locale = { description: '설명', required: '필수여부', - example: '예시' + example: '예시', + + 'changed.before': '변경 전', + 'changed.after': '변경 후', + 'properties.changed': '변경된 속성' } diff --git a/src/services/slack.ts b/src/services/slack.ts index 742ace1..dd61d49 100644 --- a/src/services/slack.ts +++ b/src/services/slack.ts @@ -314,12 +314,48 @@ export class Slack { }) } + const changeLogElementList: RichTextList[] = [] + if (param.changeLogs.length > 0) { - const changeLogElementList: RichTextElement[] = [] + changeLogElementList.push({ + type: 'rich_text_list', + style: 'bullet', + indent: 0, + border: 1, + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: translate('properties.changed') + } + ] + } + ] + }) for (const changeLog of param.changeLogs) { const { field, oldValue, newValue } = changeLog + changeLogElementList.push({ + type: 'rich_text_list', + style: 'bullet', + indent: 1, + border: 1, + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: field + } + ] + } + ] + }) + let oldValueText = oldValue let newValueText = newValue @@ -332,17 +368,32 @@ export class Slack { } changeLogElementList.push({ - type: 'text', - text: `${field} ${translate( - 'status.modified' - )}: ${oldValueText} -> ${newValueText}` + type: 'rich_text_list', + style: 'bullet', + indent: 2, + border: 1, + elements: [ + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: `${translate('changed.before')}: \n${oldValueText}` + } + ] + }, + { + type: 'rich_text_section', + elements: [ + { + type: 'text', + text: `${translate('changed.after')}: \n${newValueText}` + } + ] + } + ] }) } - - descriptionElements.push({ - type: 'rich_text_section', - elements: changeLogElementList - }) } const description: RichTextList = { @@ -365,6 +416,11 @@ export class Slack { elements.push(statusAndEndpoint) elements.push(description) + + if (changeLogElementList.length > 0) { + elements.push(...changeLogElementList) + } + elements.push(newline) } diff --git a/src/types/locale.ts b/src/types/locale.ts index 004bf36..4cf46c8 100644 --- a/src/types/locale.ts +++ b/src/types/locale.ts @@ -25,4 +25,8 @@ export interface Locale { description: string required: string example: string + + 'changed.before': string + 'changed.after': string + 'properties.changed': string } From 6cf2b96248f46cf717457ca6882aa21d00c4f3be Mon Sep 17 00:00:00 2001 From: jaychang99 Date: Wed, 24 Jul 2024 21:50:30 +0900 Subject: [PATCH 5/5] fix(Slack): exception handling for empty arrays in params --- src/locale/en-us.ts | 4 +++- src/locale/ko-kr.ts | 4 +++- src/services/slack.ts | 12 ++++++++++-- src/types/locale.ts | 2 ++ 4 files changed, 18 insertions(+), 4 deletions(-) diff --git a/src/locale/en-us.ts b/src/locale/en-us.ts index 3f5f211..4946a71 100644 --- a/src/locale/en-us.ts +++ b/src/locale/en-us.ts @@ -30,5 +30,7 @@ export const LOCALE_EN_US: Locale = { 'changed.before': 'Before', 'changed.after': 'After', - 'properties.changed': 'Properties changed' + 'properties.changed': 'Properties changed', + + 'empty.array': 'Not specified' } diff --git a/src/locale/ko-kr.ts b/src/locale/ko-kr.ts index 3d3c15f..5775d35 100644 --- a/src/locale/ko-kr.ts +++ b/src/locale/ko-kr.ts @@ -30,5 +30,7 @@ export const LOCALE_KO_KR: Locale = { 'changed.before': '변경 전', 'changed.after': '변경 후', - 'properties.changed': '변경된 속성' + 'properties.changed': '변경된 속성', + + 'empty.array': '없음' } diff --git a/src/services/slack.ts b/src/services/slack.ts index dd61d49..da34297 100644 --- a/src/services/slack.ts +++ b/src/services/slack.ts @@ -360,11 +360,19 @@ export class Slack { let newValueText = newValue if (Array.isArray(oldValue)) { - oldValueText = oldValue.join(', ') + if (oldValue.length > 0) { + oldValueText = oldValue.join(', ') + } else { + oldValueText = `(${translate('empty.array')})` + } } if (Array.isArray(newValue)) { - newValueText = newValue.join(', ') + if (newValue.length > 0) { + newValueText = newValue.join(', ') + } else { + newValueText = `(${translate('empty.array')})` + } } changeLogElementList.push({ diff --git a/src/types/locale.ts b/src/types/locale.ts index 4cf46c8..9272e31 100644 --- a/src/types/locale.ts +++ b/src/types/locale.ts @@ -29,4 +29,6 @@ export interface Locale { 'changed.before': string 'changed.after': string 'properties.changed': string + + 'empty.array': string }