Skip to content

Commit

Permalink
Bitbucket compare changes fix for rename and removed file ops (#151)
Browse files Browse the repository at this point in the history
* fix bitbucket compare commits response in case of rename and delete ops
  • Loading branch information
mohitg0795 authored Feb 21, 2022
1 parent 8a8597d commit 2f3e807
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
10 changes: 9 additions & 1 deletion scm/driver/bitbucket/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,12 +210,20 @@ func convertDiffstats(from *diffstats) []*scm.Change {
}

func convertDiffstat(from *diffstat) *scm.Change {
return &scm.Change{
response := &scm.Change{
Path: from.New.Path,
Added: from.Status == "added",
Renamed: from.Status == "renamed",
Deleted: from.Status == "removed",
}

if (response.Renamed) {
response.PrevFilePath = from.Old.Path
} else if (response.Deleted) {
response.Path = from.Old.Path
}

return response
}

func convertCommitList(from *commits) []*scm.Commit {
Expand Down
48 changes: 48 additions & 0 deletions scm/driver/bitbucket/testdata/diffstat.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,54 @@
}
},
"type": "diffstat"
},
{
"status": "renamed",
"old": {
"path": "old-folder/CONTRIBUTING.md",
"type": "commit_file",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/atlaskit\/src\/dec26e0fe887167743c2b7e36531dedfeb6cd478\/CONTRIBUTING.md"
}
}
},
"lines_removed": 0,
"lines_added": 0,
"new": {
"path": "new-folder/CONTRIBUTING.md",
"type": "commit_file",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/atlaskit\/src\/425863f9dbe56d70c8dcdbf2e4e0805e85591fcc\/CONTRIBUTING.md"
}
}
},
"type": "diffstat"
},
{
"status": "removed",
"old": {
"path": "CONTRIBUTING.md",
"type": "commit_file",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/atlaskit\/src\/dec26e0fe887167743c2b7e36531dedfeb6cd478\/CONTRIBUTING.md"
}
}
},
"lines_removed": 15,
"lines_added": 0,
"new": {
"path": "",
"type": "commit_file",
"links": {
"self": {
"href": "https:\/\/api.bitbucket.org\/2.0\/repositories\/atlassian\/atlaskit\/src\/425863f9dbe56d70c8dcdbf2e4e0805e85591fcc\/CONTRIBUTING.md"
}
}
},
"type": "diffstat"
}
],
"page": 1,
Expand Down
13 changes: 13 additions & 0 deletions scm/driver/bitbucket/testdata/diffstat.json.golden
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,18 @@
"Added": false,
"Renamed": false,
"Deleted": false
},
{
"Path": "new-folder/CONTRIBUTING.md",
"Added": false,
"Renamed": true,
"Deleted": false,
"PrevFilePath": "old-folder/CONTRIBUTING.md"
},
{
"Path": "CONTRIBUTING.md",
"Added": false,
"Renamed": false,
"Deleted": true
}
]

0 comments on commit 2f3e807

Please sign in to comment.