Skip to content

Commit 5ef6a72

Browse files
authored
Merge pull request #1367 from hongweiliu17/STONEINTG-1390
fix(STONEINTG-1390): use stricter string to search existing comment
2 parents 028646f + 774f0f8 commit 5ef6a72

File tree

4 files changed

+22
-17
lines changed

4 files changed

+22
-17
lines changed

git/github/github.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,9 @@ func (c *Client) GetExistingCheckRun(checkRuns []*ghapi.CheckRun, newCheckRun *C
430430
// GetExistingComment returns existing GitHub comment for the scenario of ref.
431431
func (c *Client) GetExistingCommentID(comments []*ghapi.IssueComment, componentName, scenarioName string) *int64 {
432432
for _, comment := range comments {
433-
if strings.Contains(*comment.Body, componentName) && strings.Contains(*comment.Body, scenarioName) {
433+
// get existing note by search "Integration test for componentName" and " scenario scenarioName " in report summary
434+
// GetExistingNoteID for gitlab comment has the similar logic
435+
if strings.Contains(*comment.Body, fmt.Sprintf("Integration test for %s ", componentName)) && strings.Contains(*comment.Body, fmt.Sprintf(" scenario %s ", scenarioName)) {
434436
c.logger.Info("found comment ID with a matching scenarioName", "scenarioName", scenarioName)
435437
return comment.ID
436438
}

git/github/github_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func (MockIssuesService) CreateComment(
114114
func (MockIssuesService) ListComments(ctx context.Context, owner string, repo string,
115115
number int, opts *ghapi.IssueListCommentsOptions) ([]*ghapi.IssueComment, *ghapi.Response, error) {
116116
var id int64 = 40
117-
var body = "Integration test for component component-sample snapshot snapshotName and scenario scenarioName"
117+
var body = "Integration test for component component-sample snapshot snapshotName and scenario scenarioName failed"
118118
issueComments := []*ghapi.IssueComment{{ID: &id, Body: &body}}
119119
return issueComments, nil, nil
120120
}
@@ -355,7 +355,7 @@ var _ = Describe("Client", func() {
355355
Expect(comments).NotTo(BeEmpty())
356356
Expect(statusCode).NotTo(BeNil())
357357

358-
commentID := client.GetExistingCommentID(comments, "component-sample", "scenarioName")
358+
commentID := client.GetExistingCommentID(comments, "component component-sample", "scenarioName")
359359
Expect(*commentID).To(Equal(int64(40)))
360360
})
361361

status/reporter_gitlab.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ func (r *GitLabReporter) GetExistingCommitStatus(commitStatuses []*gitlab.Commit
296296
// GetExistingNoteID returns existing GitLab note for the scenario of ref.
297297
func (r *GitLabReporter) GetExistingNoteID(notes []*gitlab.Note, scenarioName, componentName string) *int {
298298
for _, note := range notes {
299-
if strings.Contains(note.Body, componentName) && strings.Contains(note.Body, scenarioName) {
300-
r.logger.Info("found note ID with a matching componentName and scenarioName", "omponentName", componentName, "scenarioName", scenarioName, "noteID", &note.ID)
299+
// get existing note by search "Integration test for componentName" and " scenario scenarioName " in report summary
300+
// GetExistingCommentID for github comment has the similar logic
301+
if strings.Contains(note.Body, fmt.Sprintf("Integration test for %s ", componentName)) && strings.Contains(note.Body, fmt.Sprintf(" scenario %s ", scenarioName)) {
302+
r.logger.Info("found note ID with a matching componentName and scenarioName", "componentName", componentName, "scenarioName", scenarioName, "noteID", &note.ID)
301303
return &note.ID
302304
}
303305
}

status/reporter_gitlab_test.go

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ var _ = Describe("GitLabReporter", func() {
205205

206206
It("creates a commit status for snapshot with correct textual data", func() {
207207

208-
summary := "Integration test for snapshot snapshot-sample and scenario scenario1 failed"
208+
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 failed"
209209

210210
muxCommitStatusPost(mux, sourceProjectID, digest, summary)
211211
muxMergeNotes(mux, targetProjectID, mergeRequest, summary)
@@ -236,7 +236,7 @@ var _ = Describe("GitLabReporter", func() {
236236
Expect(err).To(Succeed())
237237
Expect(statusCode).To(Equal(0))
238238

239-
summary := "Integration test for snapshot snapshot-sample and scenario scenario1 failed"
239+
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 failed"
240240

241241
muxCommitStatusPost(mux, sourceProjectID, digest, summary)
242242

@@ -277,7 +277,7 @@ var _ = Describe("GitLabReporter", func() {
277277
})
278278

279279
It("does not create a commit status or comment for snapshot with existing matching checkRun in running state", func() {
280-
summary := "Integration test for snapshot snapshot-sample and scenario scenario1 is running"
280+
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 is running"
281281

282282
report := status.TestReport{
283283
FullName: "fullname/scenario1",
@@ -295,7 +295,7 @@ var _ = Describe("GitLabReporter", func() {
295295
})
296296

297297
It("can get an existing commitStatus that matches the report", func() {
298-
summary := "Integration test for snapshot snapshot-sample and scenario scenario1 failed"
298+
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 failed"
299299
report := status.TestReport{
300300
FullName: "fullname/scenario1",
301301
ScenarioName: "scenario1",
@@ -322,14 +322,15 @@ var _ = Describe("GitLabReporter", func() {
322322
})
323323

324324
It("can get an existing mergeRequest note that matches the report", func() {
325-
summary := "Integration test for snapshot snapshot-sample and scenario scenario1 failed"
325+
summary := "Integration test for component component-sample snapshot snapshot-sample and scenario scenario1 failed"
326326
report := status.TestReport{
327-
FullName: "fullname/scenario1",
328-
ScenarioName: "scenario1",
329-
SnapshotName: "snapshot-sample",
330-
Status: integrationteststatus.IntegrationTestStatusTestPassed,
331-
Summary: summary,
332-
Text: "detailed text here",
327+
FullName: "fullname/scenario1",
328+
ScenarioName: "scenario1",
329+
SnapshotName: "snapshot-sample",
330+
Status: integrationteststatus.IntegrationTestStatusTestPassed,
331+
Summary: summary,
332+
ComponentName: "component-sample",
333+
Text: "detailed text here",
333334
}
334335
comment, err := status.FormatComment(report.Summary, report.Text)
335336
Expect(err).ToNot(HaveOccurred())
@@ -341,8 +342,8 @@ var _ = Describe("GitLabReporter", func() {
341342
notes := []*gitlab.Note{
342343
&note,
343344
}
344-
existingNoteID := reporter.GetExistingNoteID(notes, report.ScenarioName, report.SnapshotName)
345345

346+
existingNoteID := reporter.GetExistingNoteID(notes, report.ScenarioName, status.GenerateComponentNameWithPrefix(report.ComponentName))
346347
Expect(*existingNoteID).To(Equal(note.ID))
347348
})
348349
})

0 commit comments

Comments
 (0)