Skip to content

Commit 1790097

Browse files
authoredSep 3, 2024
CLOUDP-269299: Update changelog-report to list the spec correction changes (#212)
1 parent 80ea6e3 commit 1790097

File tree

3 files changed

+135
-45
lines changed

3 files changed

+135
-45
lines changed
 

‎.github/workflows/changelog-report.yml

+41-38
Original file line numberDiff line numberDiff line change
@@ -20,35 +20,35 @@ jobs:
2020
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332
2121
with:
2222
ref: dev
23-
sparse-checkout:
23+
sparse-checkout:
2424
changelog/
2525
- name: Install FOASCLI
2626
env:
2727
foascli_version: ${{ vars.FOASCLI_VERSION }}
2828
run: |
29-
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
30-
tar -xzvf foascli.tar.gz
31-
pushd mongodb-foas-cli_*
32-
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
33-
popd
29+
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
30+
tar -xzvf foascli.tar.gz
31+
pushd mongodb-foas-cli_*
32+
echo "$(pwd)/bin" >> "${GITHUB_PATH}"
33+
popd
3434
- name: Get Start and End Dates
3535
id: get-dates
36-
env:
36+
env:
3737
START_DATE: ${{ inputs.start_date }}
3838
END_DATE: ${{ inputs.end_date }}
3939
run: |
4040
start_date="${START_DATE}"
4141
if [[ -z "${START_DATE}" ]]; then
4242
echo "Start date not provided"
43-
start_date=$(date -j -v-7d "+%Y-%m-%d")
43+
start_date=$(date -d "-7 day" "+%Y-%m-%d")
4444
echo "Using 7 days ago as start date: ${start_date}"
4545
fi
4646
4747
end_date="${END_DATE}"
4848
if [[ -z "${END_DATE}" ]]; then
4949
echo "End date not provided"
50-
end_date=$(date -j -v-2d "+%Y-%m-%d")
51-
echo "Using last Friday as end date: ${end_date}"
50+
end_date=$(date -d "-2 day" "+%Y-%m-%d")
51+
echo "Using ${end_date} as end date."
5252
fi
5353
5454
echo start_date="${start_date}" >> "${GITHUB_OUTPUT}"
@@ -63,10 +63,10 @@ jobs:
6363
- name: Upload entries for debugging
6464
uses: actions/upload-artifact@834a144ee995460fba8ed112a2fc961b36a5ec5a
6565
with:
66-
name: changelog_entries_in_range
67-
retention-days: 1
68-
path: |
69-
entries.json
66+
name: changelog_entries_in_range
67+
retention-days: 1
68+
path: |
69+
entries.json
7070
- name: Send Initial Slack Message
7171
id: send-initial-slack-message
7272
env:
@@ -75,30 +75,33 @@ jobs:
7575
START_DATE: ${{ steps.get-dates.outputs.start_date }}
7676
END_DATE: ${{ steps.get-dates.outputs.end_date }}
7777
run: |
78-
if < entries.json jq -e 'length == 0' > /dev/null; then
79-
echo "No changelog entries found"
80-
exit 0
81-
fi
82-
83-
compatible_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == true)] | length' entries.json)
84-
echo "compatible_changes=${compatible_changes}"
85-
86-
breaking_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == false)] | length' entries.json)
87-
echo "breaking_changes=${breaking_changes}"
88-
89-
if [[ "${compatible_changes}" -eq 0 && "${breaking_changes}" -eq 0 ]]; then
90-
echo "No changelog entries found"
91-
exit 0
92-
fi
93-
94-
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
95-
-H 'Content-type: application/json' \
96-
--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')
97-
98-
echo "message_id=${message_id}"
99-
echo "message_id=${message_id}" >> "${GITHUB_OUTPUT}"
100-
101-
sleep 2 # wait for 2 seconds to avoid slack rate limit
78+
if < entries.json jq -e 'length == 0' > /dev/null; then
79+
echo "No changelog entries found"
80+
exit 0
81+
fi
82+
83+
compatible_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == true)] | length' entries.json)
84+
echo "compatible_changes=${compatible_changes}"
85+
86+
breaking_changes=$(jq '[.. | objects | select(has("backwardCompatible") and .backwardCompatible == false)] | length' entries.json)
87+
echo "breaking_changes=${breaking_changes}"
88+
89+
spec_corrections=$(jq '[.. | objects | select(has("hideFromChangelog") and .hideFromChangelog == true)] | length' entries.json)
90+
echo "spec_corrections=${spec_corrections}"
91+
92+
if [[ "${compatible_changes}" -eq 0 && "${breaking_changes}" -eq 0 ]]; then
93+
echo "No changelog entries found"
94+
exit 0
95+
fi
96+
97+
message_id=$(curl -X POST -H 'Authorization: Bearer '"${SLACK_BEARER_TOKEN}" \
98+
-H 'Content-type: application/json' \
99+
--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')
100+
101+
echo "message_id=${message_id}"
102+
echo "message_id=${message_id}" >> "${GITHUB_OUTPUT}"
103+
104+
sleep 2 # wait for 2 seconds to avoid slack rate limit
102105
- name: Send Changelog Entries as Slack Thread
103106
id: send-changelog-entries
104107
env:

‎tools/cli/internal/cli/changelog/convert/slack.go

+20-4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ import (
2929
const (
3030
backwardCompatibleColor = "#47a249"
3131
notBackwardCompatibleColor = "#b51818"
32+
specCorrectionColor = "#ffa500"
3233
parseFull = "full"
3334
attachmentTypeDefault = "default"
3435
batchSize = 100
@@ -122,10 +123,21 @@ func newMessagesFromAttachments(attachments []*Attachment, channelID, messageID
122123
}
123124

124125
// orderAttachments orders the attachments by backward compatibility.
125-
// The attachments that are not backward compatible are shown first.
126+
// The attachments that are not backward compatible are shown first, then the spec corrections, and finally the backward compatible changes.
126127
func orderAttachments(attachments []*Attachment) []*Attachment {
127128
sort.Slice(attachments, func(i, j int) bool {
128-
return attachments[i].Color == notBackwardCompatibleColor && attachments[j].Color != notBackwardCompatibleColor
129+
if attachments[i].Color == attachments[j].Color {
130+
return false
131+
}
132+
133+
if attachments[i].Color == notBackwardCompatibleColor {
134+
return true
135+
}
136+
if attachments[i].Color == specCorrectionColor && attachments[j].Color == backwardCompatibleColor {
137+
return true
138+
}
139+
140+
return false
129141
})
130142
return attachments
131143
}
@@ -143,7 +155,7 @@ func newAttachmentFromChange(version, method, path, changeType string, change *c
143155
return &Attachment{
144156
Text: newAttachmentText(version, method, path, changeType, change.Code, change.Description,
145157
strconv.FormatBool(change.HideFromChangelog)),
146-
Color: newColorFromBackwardCompatible(change.BackwardCompatible),
158+
Color: newColorFromBackwardCompatible(change.BackwardCompatible, change.HideFromChangelog),
147159
AttachmentType: attachmentTypeDefault,
148160
}
149161
}
@@ -154,7 +166,11 @@ func newAttachmentText(version, method, path, changeType, changeCode, change, hi
154166
version, hiddenFromChangelog, method, path, changeType, changeCode, change)
155167
}
156168

157-
func newColorFromBackwardCompatible(backwardCompatible bool) string {
169+
func newColorFromBackwardCompatible(backwardCompatible, hideFromChangelog bool) string {
170+
if hideFromChangelog {
171+
return specCorrectionColor
172+
}
173+
158174
if backwardCompatible {
159175
return backwardCompatibleColor
160176
}

‎tools/cli/internal/cli/changelog/convert/slack_test.go

+74-3
Original file line numberDiff line numberDiff line change
@@ -186,24 +186,95 @@ func TestNewColorFromBackwardCompatible(t *testing.T) {
186186
tests := []struct {
187187
name string
188188
backwardCompatible bool
189+
hideFromChangelog bool
189190
expectedColor string
190191
}{
191192
{
192193
name: "Backward Compatible True",
193194
backwardCompatible: true,
194-
expectedColor: "#47a249",
195+
hideFromChangelog: false,
196+
expectedColor: backwardCompatibleColor,
195197
},
196198
{
197199
name: "Backward Compatible False",
198200
backwardCompatible: false,
199-
expectedColor: "#b51818",
201+
hideFromChangelog: false,
202+
expectedColor: notBackwardCompatibleColor,
203+
},
204+
{
205+
name: "Hide from Changelog True",
206+
backwardCompatible: true,
207+
hideFromChangelog: true,
208+
expectedColor: specCorrectionColor,
200209
},
201210
}
202211

203212
for _, tt := range tests {
204213
t.Run(tt.name, func(t *testing.T) {
205-
actual := newColorFromBackwardCompatible(tt.backwardCompatible)
214+
actual := newColorFromBackwardCompatible(tt.backwardCompatible, tt.hideFromChangelog)
206215
assert.Equal(t, tt.expectedColor, actual)
207216
})
208217
}
209218
}
219+
220+
func TestOrderAttachments(t *testing.T) {
221+
tests := []struct {
222+
name string
223+
attachments []*Attachment
224+
expected []*Attachment
225+
}{
226+
{
227+
name: "Mixed Attachments",
228+
attachments: []*Attachment{
229+
{Text: "Attachment 1", Color: backwardCompatibleColor},
230+
{Text: "Attachment 2", Color: notBackwardCompatibleColor},
231+
{Text: "Attachment 3", Color: specCorrectionColor},
232+
},
233+
expected: []*Attachment{
234+
{Text: "Attachment 2", Color: notBackwardCompatibleColor},
235+
{Text: "Attachment 3", Color: specCorrectionColor},
236+
{Text: "Attachment 1", Color: backwardCompatibleColor},
237+
},
238+
},
239+
{
240+
name: "All Backward Compatible",
241+
attachments: []*Attachment{
242+
{Text: "Attachment 1", Color: backwardCompatibleColor},
243+
{Text: "Attachment 2", Color: backwardCompatibleColor},
244+
},
245+
expected: []*Attachment{
246+
{Text: "Attachment 1", Color: backwardCompatibleColor},
247+
{Text: "Attachment 2", Color: backwardCompatibleColor},
248+
},
249+
},
250+
{
251+
name: "All Not Backward Compatible",
252+
attachments: []*Attachment{
253+
{Text: "Attachment 1", Color: notBackwardCompatibleColor},
254+
{Text: "Attachment 2", Color: notBackwardCompatibleColor},
255+
},
256+
expected: []*Attachment{
257+
{Text: "Attachment 1", Color: notBackwardCompatibleColor},
258+
{Text: "Attachment 2", Color: notBackwardCompatibleColor},
259+
},
260+
},
261+
{
262+
name: "All Spec Corrections",
263+
attachments: []*Attachment{
264+
{Text: "Attachment 1", Color: specCorrectionColor},
265+
{Text: "Attachment 2", Color: specCorrectionColor},
266+
},
267+
expected: []*Attachment{
268+
{Text: "Attachment 1", Color: specCorrectionColor},
269+
{Text: "Attachment 2", Color: specCorrectionColor},
270+
},
271+
},
272+
}
273+
274+
for _, tt := range tests {
275+
t.Run(tt.name, func(t *testing.T) {
276+
actual := orderAttachments(tt.attachments)
277+
assert.Equal(t, tt.expected, actual)
278+
})
279+
}
280+
}

0 commit comments

Comments
 (0)