Skip to content

Commit a39d8d1

Browse files
Add File content as a separate field
1 parent c9e839d commit a39d8d1

File tree

2 files changed

+17
-17
lines changed

2 files changed

+17
-17
lines changed

pkg/utils/git/ado.go

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -162,14 +162,6 @@ func (c *AzureDevopsClient) FetchFileDiffs(ctx context.Context, repoName, repoOw
162162
continue
163163
}
164164

165-
// Azure does not track number of lines added, changed, or deleted so we default to the zero-value for these fields
166-
fileChange := GitPullRequestFileChanges{
167-
Filename: path,
168-
Additions: 0,
169-
Deletions: 0,
170-
Changes: 0,
171-
}
172-
173165
targetBranch := cleanBranchName(*pr.TargetRefName)
174166
sourceBranch := cleanBranchName(*pr.SourceRefName)
175167
getNewContentArgs := adogit.GetItemArgs{
@@ -189,13 +181,21 @@ func (c *AzureDevopsClient) FetchFileDiffs(ctx context.Context, repoName, repoOw
189181
continue
190182
}
191183

184+
// Azure does not track number of lines added, changed, or deleted so we default to the zero-value for these fields
185+
fileChange := GitPullRequestFileChanges{
186+
Filename: path,
187+
Additions: 0,
188+
Deletions: 0,
189+
Changes: 0,
190+
FileContent: newContent,
191+
}
192+
192193
switch *change.ChangeType {
193194
case adogit.VersionControlChangeTypeValues.Add:
194195
if newContentType == "base64Encoded" {
195196
fileChange.Patch = createPatch(path, path, "", placeholderBinaryContent)
196197
} else {
197-
patch := createPatch(path, path, "", newContent)
198-
fileChange.Patch = fmt.Sprintf("Added file content: %s", patch)
198+
fileChange.Patch = createPatch(path, path, "", newContent)
199199
}
200200

201201
case adogit.VersionControlChangeTypeValues.Edit, adogit.VersionControlChangeTypeValues.Delete:
@@ -221,8 +221,7 @@ func (c *AzureDevopsClient) FetchFileDiffs(ctx context.Context, repoName, repoOw
221221
if oldContentType == "base64Encoded" {
222222
oldContent = placeholderBinaryContent
223223
}
224-
patch := createPatch(path, path, oldContent, newContent)
225-
fileChange.Patch = fmt.Sprintf("New content of file: %s\nDiff of file: %s", newContent, patch)
224+
fileChange.Patch = createPatch(path, path, oldContent, newContent)
226225
}
227226
default:
228227
log.Printf("Unknown change type: %s", *change.ChangeType)

pkg/utils/git/git.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,12 @@ type GitPullRequest struct {
1515
}
1616

1717
type GitPullRequestFileChanges struct {
18-
Filename string `json:"filename"`
19-
Patch string `json:"patch"`
20-
Additions int `json:"additions"`
21-
Deletions int `json:"deletions"`
22-
Changes int `json:"changes"`
18+
Filename string `json:"filename"`
19+
Patch string `json:"patch"`
20+
Additions int `json:"additions"`
21+
Deletions int `json:"deletions"`
22+
Changes int `json:"changes"`
23+
FileContent string `json:"file_content"`
2324
}
2425

2526
type GitClient interface {

0 commit comments

Comments
 (0)