Skip to content

Commit

Permalink
[#1843] Fix authorship label LoC (#1854)
Browse files Browse the repository at this point in the history
The labels on top of the files in `c-authorship.vue` display the LoC of
all the files that the author has written to. This is not the intended
action.

Let us update the logic for this calculation to ensure that the labels
correctly display the LoC.
  • Loading branch information
zhoukerrr authored Jan 22, 2023
1 parent af7a05d commit 7dccf1f
Showing 1 changed file with 12 additions and 29 deletions.
41 changes: 12 additions & 29 deletions frontend/src/views/c-authorship.vue
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,12 @@ export default {
if (!files) {
files = await window.api.loadAuthorship(this.info.repo);
}
this.getRepoProps(repo);
const author = repo.users.find((user) => user.name === this.info.author);
if (author) {
this.authorDisplayName = author.displayName;
}
this.processFiles(files);
if (this.info.isRefresh) {
Expand All @@ -340,34 +345,6 @@ export default {
this.setInfoHash();
},
getRepoProps(repo) {
if (repo) {
let files = [];
if (this.info.isMergeGroup) {
files = repo.files;
} else {
const author = repo.users.find((user) => user.name === this.info.author);
if (author) {
this.authorDisplayName = author.displayName;
files = repo.files.filter((f) => !!f.authorContributionMap[author.name]);
}
}
this.updateTotalFileTypeContribution(files);
}
},
updateTotalFileTypeContribution(files) {
files.filter((f) => !f.isIgnored).forEach((f) => {
const lines = f.lines ? f.lines.length : 0;
const type = f.fileType;
if (this.filesLinesObj[type]) {
this.filesLinesObj[type] += lines;
} else {
this.filesLinesObj[type] = lines;
}
});
},
expandAll() {
this.selectedFiles.forEach((file) => {
file.active = true;
Expand Down Expand Up @@ -466,6 +443,12 @@ export default {
out.isIgnored = !!file.isIgnored;
out.isBinary = !!file.isBinary;
if (this.filesLinesObj[out.fileType]) {
this.filesLinesObj[out.fileType] += lineCnt;
} else {
this.filesLinesObj[out.fileType] = lineCnt;
}
if (!out.isBinary && !out.isIgnored) {
out.charCount = file.lines.reduce(
(count, line) => count + (line ? line.content.length : 0),
Expand Down

0 comments on commit 7dccf1f

Please sign in to comment.