Skip to content

Commit

Permalink
Modify merge in 'update.commit.interactions'
Browse files Browse the repository at this point in the history
The merge now always keeps all commit interactions, even if there is no
commit data for them (for example if the commits were made by deleted
users). Also introduced a warning if that happens. Case is tested with
new part in 'test-data.R'

Signed-off-by: Leo Sendelbach <[email protected]>
  • Loading branch information
Leo-Send committed Feb 27, 2024
1 parent 63f2737 commit 8148614
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 5 deletions.
33 changes: 32 additions & 1 deletion tests/test-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -540,5 +540,36 @@ test_that("Compare two ProjectData Objects with commit.interactions", {
commit.data[["hash"]][[5]] = 1
proj.data.one$set.commits(commit.data)

expect_false(isTRUE(all.equal(proj.data.one$get.commit.interactions(), proj.data.two$get.commit.interactions())))
expect_false(isTRUE(all.equal(proj.data.one$get.commit.interactions(),
proj.data.two$get.commit.interactions())))

## set commit list of one project data to empty and test that last
## two rows of result data frame are empty
proj.data.two$set.commits(create.empty.commits.list())

## create empty data frame of correct size
commit.interactions.data.expected = data.frame(matrix(nrow = 4, ncol = 8))
## assure that the correct type is used
for(i in seq_len(8)) {
commit.interactions.data.expected[[i]] = as.character(commit.interactions.data.expected[[i]])
}
## set everything except for authors as expected
colnames(commit.interactions.data.expected) = c("commit.hash", "base.hash", "func", "file",
"base.func", "base.file", "base.author",
"interacting.author")
commit.interactions.data.expected[["commit.hash"]] =
c("0a1a5c523d835459c42f33e863623138555e2526",
"418d1dc4929ad1df251d2aeb833dd45757b04a6f",
"5a5ec9675e98187e1e92561e1888aa6f04faa338",
"d01921773fae4bed8186b0aa411d6a2f7a6626e6")
commit.interactions.data.expected[["base.hash"]] =
c("3a0ed78458b3976243db6829f63eba3eead26774",
"0a1a5c523d835459c42f33e863623138555e2526",
"72c8dd25d3dd6d18f46e2b26a5f5b1e2e8dc28d0",
"0a1a5c523d835459c42f33e863623138555e2526")
commit.interactions.data.expected[["func"]] = c("test2.c", "test2.c", "test.c", "test2.c")
commit.interactions.data.expected[["file"]] = c("test2.c", "test2.c", "test.c", "test2.c")
commit.interactions.data.expected[["base.func"]] = c("test2.c", "test2.c", "test.c", "test2.c")
commit.interactions.data.expected[["base.file"]] = c("test2.c", "test2.c", "test.c", "test2.c")
expect_equal(proj.data.two$get.commit.interactions(), commit.interactions.data.expected)
})
15 changes: 11 additions & 4 deletions util-data.R
Original file line number Diff line number Diff line change
Expand Up @@ -420,11 +420,11 @@ ProjectData = R6::R6Class("ProjectData",

## remove existing columns named 'base.author' and 'interaction.author'
indices.to.remove = which("base.author" == colnames(private$commit.interactions))
if (length(indices.to.remove)>0) {
if (length(indices.to.remove) > 0) {
private$commit.interactions = private$commit.interactions[, -indices.to.remove]
}
indices.to.remove = which("interacting.author" == colnames(private$commit.interactions))
if (length(indices.to.remove)>0) {
if (length(indices.to.remove) > 0) {
private$commit.interactions = private$commit.interactions[, -indices.to.remove]
}

Expand All @@ -435,17 +435,24 @@ ProjectData = R6::R6Class("ProjectData",

## merge commit interactions with commits and change colnames to avoid duplicates
commit.interaction.data = merge(private$commit.interactions, commit.data.subset,
by.x = "base.hash", by.y = "hash")
by.x = "base.hash", by.y = "hash", all.x = TRUE)

author.index = match("author.name", colnames(commit.interaction.data))
colnames(commit.interaction.data)[[author.index]] = "base.author"

commit.interaction.data = merge(commit.interaction.data, commit.data.subset,
by.x = "commit.hash", by.y = "hash")
by.x = "commit.hash", by.y = "hash", all.x = TRUE)

author.index = match("author.name", colnames(commit.interaction.data))
colnames(commit.interaction.data)[[author.index]] = "interacting.author"

## warning if we have interactions without authors
if (anyNA(commit.interaction.data[["base.author"]]) ||
anyNA(commit.interaction.data[["interacting.author"]])) {
logging::logwarn("There are authors in the commit-interactions that are not in the commit data!
This results in the commit-interactions having empty entries.
To clean up these entries, call cleanup.commit.interactions.")
}
private$commit.interactions = commit.interaction.data

},
Expand Down

0 comments on commit 8148614

Please sign in to comment.