diff --git a/.github/workflows/changelog-report.yml b/.github/workflows/changelog-report.yml index 3562e3b0a..65b8f4d2b 100644 --- a/.github/workflows/changelog-report.yml +++ b/.github/workflows/changelog-report.yml @@ -20,35 +20,35 @@ jobs: uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 with: ref: dev - sparse-checkout: + sparse-checkout: changelog/ - name: Install FOASCLI env: foascli_version: ${{ vars.FOASCLI_VERSION }} run: | - wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz - tar -xzvf foascli.tar.gz - pushd mongodb-foas-cli_* - echo "$(pwd)/bin" >> "${GITHUB_PATH}" - popd + wget https://github.com/mongodb/openapi/releases/download/v"${foascli_version}"/mongodb-foas-cli_"${foascli_version}"_linux_x86_64.tar.gz -O foascli.tar.gz + tar -xzvf foascli.tar.gz + pushd mongodb-foas-cli_* + echo "$(pwd)/bin" >> "${GITHUB_PATH}" + popd - name: Get Start and End Dates id: get-dates - env: + env: START_DATE: ${{ inputs.start_date }} END_DATE: ${{ inputs.end_date }} run: | start_date="${START_DATE}" if [[ -z "${START_DATE}" ]]; then echo "Start date not provided" - start_date=$(date -j -v-7d "+%Y-%m-%d") + start_date=$(date -d "-7 day" "+%Y-%m-%d") echo "Using 7 days ago as start date: ${start_date}" fi end_date="${END_DATE}" if [[ -z "${END_DATE}" ]]; then echo "End date not provided" - end_date=$(date -j -v-2d "+%Y-%m-%d") - echo "Using last Friday as end date: ${end_date}" + end_date=$(date -d "-2 day" "+%Y-%m-%d") + echo "Using ${end_date} as end date." fi echo start_date="${start_date}" >> "${GITHUB_OUTPUT}" @@ -63,10 +63,10 @@ jobs: - name: Upload entries for debugging uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a with: - name: changelog_entries_in_range - retention-days: 1 - path: | - entries.json + name: changelog_entries_in_range + retention-days: 1 + path: | + entries.json - name: Send Initial Slack Message id: send-initial-slack-message env: @@ -75,30 +75,33 @@ jobs: START_DATE: ${{ steps.get-dates.outputs.start_date }} END_DATE: ${{ steps.get-dates.outputs.end_date }} run: | - if < entries.json jq -e 'length == 0' > /dev/null; then - echo "No changelog entries found" - exit 0 - fi - - compatible_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == true)] | length' entries.json) - echo "compatible_changes=${compatible_changes}" - - breaking_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == false)] | length' entries.json) - echo "breaking_changes=${breaking_changes}" - - if [[ "${compatible_changes}" -eq 0 && "${breaking_changes}" -eq 0 ]]; then - echo "No changelog entries found" - exit 0 - fi - - message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ - -H 'Content-type: application/json' \ - --data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":"List of API changes (*cloud-dev*) from *'"${START_DATE}"'* to *'"${END_DATE}"'*.\n\n*Summary*:\n\n:large_green_circle: Backward Compatible Changes: *'"${compatible_changes}"'*\n:red_circle: Breaking Changes: *'"${breaking_changes}"'*","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') - - echo "message_id=${message_id}" - echo "message_id=${message_id}" >> "${GITHUB_OUTPUT}" - - sleep 2 # wait for 2 seconds to avoid slack rate limit + if < entries.json jq -e 'length == 0' > /dev/null; then + echo "No changelog entries found" + exit 0 + fi + + compatible_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == true)] | length' entries.json) + echo "compatible_changes=${compatible_changes}" + + breaking_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == false)] | length' entries.json) + echo "breaking_changes=${breaking_changes}" + + spec_corrections=$(jq '[.. | objects | select(has("hideFromChangelog") and .hideFromChangelog == true)] | length' entries.json) + echo "spec_corrections=${spec_corrections}" + + if [[ "${compatible_changes}" -eq 0 && "${breaking_changes}" -eq 0 ]]; then + echo "No changelog entries found" + exit 0 + fi + + message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \ + -H 'Content-type: application/json' \ + --data '{"channel":"'"${SLACK_CHANNEL_ID}"'","text":":aileaft: List of API changes (*cloud-dev*) from *'"${START_DATE}"'* to *'"${END_DATE}"'*.\n\n*Summary*:\n\n:large_green_circle: Backward Compatible Changes: *'"${compatible_changes}"'*\n\n:large_orange_circle: Spec Corrections: *'"${spec_corrections}"'*\n\n:red_circle: Breaking Changes: *'"${breaking_changes}"'*","parse": "full",}' https://slack.com/api/chat.postMessage | jq '.ts') + + echo "message_id=${message_id}" + echo "message_id=${message_id}" >> "${GITHUB_OUTPUT}" + + sleep 2 # wait for 2 seconds to avoid slack rate limit - name: Send Changelog Entries as Slack Thread id: send-changelog-entries env: diff --git a/tools/cli/internal/cli/changelog/convert/slack.go b/tools/cli/internal/cli/changelog/convert/slack.go index 7e98858fe..7be576e14 100644 --- a/tools/cli/internal/cli/changelog/convert/slack.go +++ b/tools/cli/internal/cli/changelog/convert/slack.go @@ -29,6 +29,7 @@ import ( const ( backwardCompatibleColor = "#47a249" notBackwardCompatibleColor = "#b51818" + specCorrectionColor = "#ffa500" parseFull = "full" attachmentTypeDefault = "default" batchSize = 100 @@ -122,10 +123,21 @@ func newMessagesFromAttachments(attachments []*Attachment, channelID, messageID } // orderAttachments orders the attachments by backward compatibility. -// The attachments that are not backward compatible are shown first. +// The attachments that are not backward compatible are shown first, then the spec corrections, and finally the backward compatible changes. func orderAttachments(attachments []*Attachment) []*Attachment { sort.Slice(attachments, func(i, j int) bool { - return attachments[i].Color == notBackwardCompatibleColor && attachments[j].Color != notBackwardCompatibleColor + if attachments[i].Color == attachments[j].Color { + return false + } + + if attachments[i].Color == notBackwardCompatibleColor { + return true + } + if attachments[i].Color == specCorrectionColor && attachments[j].Color == backwardCompatibleColor { + return true + } + + return false }) return attachments } @@ -143,7 +155,7 @@ func newAttachmentFromChange(version, method, path, changeType string, change *c return &Attachment{ Text: newAttachmentText(version, method, path, changeType, change.Code, change.Description, strconv.FormatBool(change.HideFromChangelog)), - Color: newColorFromBackwardCompatible(change.BackwardCompatible), + Color: newColorFromBackwardCompatible(change.BackwardCompatible, change.HideFromChangelog), AttachmentType: attachmentTypeDefault, } } @@ -154,7 +166,11 @@ func newAttachmentText(version, method, path, changeType, changeCode, change, hi version, hiddenFromChangelog, method, path, changeType, changeCode, change) } -func newColorFromBackwardCompatible(backwardCompatible bool) string { +func newColorFromBackwardCompatible(backwardCompatible, hideFromChangelog bool) string { + if hideFromChangelog { + return specCorrectionColor + } + if backwardCompatible { return backwardCompatibleColor } diff --git a/tools/cli/internal/cli/changelog/convert/slack_test.go b/tools/cli/internal/cli/changelog/convert/slack_test.go index 2674be9a3..d5c624ba6 100644 --- a/tools/cli/internal/cli/changelog/convert/slack_test.go +++ b/tools/cli/internal/cli/changelog/convert/slack_test.go @@ -186,24 +186,95 @@ func TestNewColorFromBackwardCompatible(t *testing.T) { tests := []struct { name string backwardCompatible bool + hideFromChangelog bool expectedColor string }{ { name: "Backward Compatible True", backwardCompatible: true, - expectedColor: "#47a249", + hideFromChangelog: false, + expectedColor: backwardCompatibleColor, }, { name: "Backward Compatible False", backwardCompatible: false, - expectedColor: "#b51818", + hideFromChangelog: false, + expectedColor: notBackwardCompatibleColor, + }, + { + name: "Hide from Changelog True", + backwardCompatible: true, + hideFromChangelog: true, + expectedColor: specCorrectionColor, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { - actual := newColorFromBackwardCompatible(tt.backwardCompatible) + actual := newColorFromBackwardCompatible(tt.backwardCompatible, tt.hideFromChangelog) assert.Equal(t, tt.expectedColor, actual) }) } } + +func TestOrderAttachments(t *testing.T) { + tests := []struct { + name string + attachments []*Attachment + expected []*Attachment + }{ + { + name: "Mixed Attachments", + attachments: []*Attachment{ + {Text: "Attachment 1", Color: backwardCompatibleColor}, + {Text: "Attachment 2", Color: notBackwardCompatibleColor}, + {Text: "Attachment 3", Color: specCorrectionColor}, + }, + expected: []*Attachment{ + {Text: "Attachment 2", Color: notBackwardCompatibleColor}, + {Text: "Attachment 3", Color: specCorrectionColor}, + {Text: "Attachment 1", Color: backwardCompatibleColor}, + }, + }, + { + name: "All Backward Compatible", + attachments: []*Attachment{ + {Text: "Attachment 1", Color: backwardCompatibleColor}, + {Text: "Attachment 2", Color: backwardCompatibleColor}, + }, + expected: []*Attachment{ + {Text: "Attachment 1", Color: backwardCompatibleColor}, + {Text: "Attachment 2", Color: backwardCompatibleColor}, + }, + }, + { + name: "All Not Backward Compatible", + attachments: []*Attachment{ + {Text: "Attachment 1", Color: notBackwardCompatibleColor}, + {Text: "Attachment 2", Color: notBackwardCompatibleColor}, + }, + expected: []*Attachment{ + {Text: "Attachment 1", Color: notBackwardCompatibleColor}, + {Text: "Attachment 2", Color: notBackwardCompatibleColor}, + }, + }, + { + name: "All Spec Corrections", + attachments: []*Attachment{ + {Text: "Attachment 1", Color: specCorrectionColor}, + {Text: "Attachment 2", Color: specCorrectionColor}, + }, + expected: []*Attachment{ + {Text: "Attachment 1", Color: specCorrectionColor}, + {Text: "Attachment 2", Color: specCorrectionColor}, + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + actual := orderAttachments(tt.attachments) + assert.Equal(t, tt.expected, actual) + }) + } +}