Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Hannes Gustafsson <hnnsgstfssn@gmail.com>

Remove some uneeded comments
Simplify tests function

Address lint issue
  • Loading branch information
Oded-B committed Sep 12, 2024
1 parent 3c6c902 commit f79e70a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 12 deletions.
5 changes: 1 addition & 4 deletions internal/pkg/githubapi/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,15 +241,12 @@ func generateArgoCdDiffComments(diffCommentData DiffCommentData, githubCommentMa
// If the diff comment is too large, we'll split it into multiple comments, one per component
totalComponents := len(diffCommentData.DiffOfChangedComponents)
for i, singleComponentDiff := range diffCommentData.DiffOfChangedComponents {
// We take the diffCommentData and replace the DiffOfChangedComponents with a single component diff
componentTemplateData := diffCommentData
componentTemplateData.DiffOfChangedComponents = []argocd.DiffResult{singleComponentDiff}

// We also update the header to reflect the current component.
componentTemplateData.Header = fmt.Sprintf("Component %d/%d: %s (Split for comment size)", i+1, totalComponents, singleComponentDiff.ComponentPath)
err, templateOutput := executeTemplate("argoCdDiff", "argoCD-diff-pr-comment.gotmpl", componentTemplateData)
if err != nil {
return comments, fmt.Errorf("failed to generate ArgoCD diff comment template: %w", err)
return nil, fmt.Errorf("failed to generate ArgoCD diff comment template: %w", err)
}

// Even per component comments can be too large, in that case we'll just use the concise template
Expand Down
12 changes: 4 additions & 8 deletions internal/pkg/githubapi/github_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -192,10 +192,7 @@ func TestGenerateArgoCdDiffComments(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()
var diffCommentData DiffCommentData
err := readJSONFromFile(t, tc.diffCommentDataTestDataFileName, &diffCommentData)
if err != nil {
t.Errorf("Error reading test data file: %s", err)
}
readJSONFromFile(t, tc.diffCommentDataTestDataFileName, &diffCommentData)

result, err := generateArgoCdDiffComments(diffCommentData, tc.maxCommentLength)
if err != nil {
Expand All @@ -213,20 +210,19 @@ func TestGenerateArgoCdDiffComments(t *testing.T) {
}
}

func readJSONFromFile(t *testing.T, filename string, data interface{}) error {
func readJSONFromFile(t *testing.T, filename string, data interface{}) {
t.Helper()
// Read the JSON from the file
jsonData, err := os.ReadFile(filename)
if err != nil {
return err
t.Fatalf("Error loading test data file: %s", err)
}

// Unserialize the JSON into the provided struct
err = json.Unmarshal(jsonData, data)
if err != nil {
return err
t.Fatalf("Error unmarshalling JSON: %s", err)
}
return nil
}

func TestPrBody(t *testing.T) {
Expand Down

0 comments on commit f79e70a

Please sign in to comment.