Skip to content

Commit

Permalink
Refactor code
Browse files Browse the repository at this point in the history
  • Loading branch information
myteo committed Nov 21, 2019
1 parent c44839d commit b5abc13
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 29 deletions.
8 changes: 4 additions & 4 deletions frontend/src/static/js/v_authorship.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,20 +131,20 @@ window.vAuthorship = {

lines.forEach((line, lineCount) => {
const authored = (line.author && line.author.gitId === this.info.author);
const fullCredit = line.isFullCredit;
const { isFullCredit } = line;

if (authored !== lastState || lastId === -1
|| (authored && lastCreditState !== fullCredit)) {
|| (authored && isFullCredit !== lastCreditState)) {
segments.push({
authored,
fullCredit,
isFullCredit,
lines: [],
lineNumbers: [],
});

lastId += 1;
lastState = authored;
lastCreditState = fullCredit;
lastCreditState = isFullCredit;
}

const content = line.content || ' ';
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/tabs/segment.pug
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.segment(v-bind:class="{ untouched: !segment.authored, active: segment.lines.length < 5, fullCredit: segment.fullCredit }")
.segment(v-bind:class="{ untouched: !segment.authored, active: segment.lines.length < 5, fullCredit: segment.isFullCredit }")
.closer(v-if="!segment.authored && segment.lines.length > 4", v-on:click="loadCode()")
i.fas.fa-plus-circle.icon.open(v-bind:title="'Click to open code'")
i.fas.fa-chevron-circle-down.icon.hide(v-bind:title="'Click to hide code'")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,9 +219,9 @@ private static GitBlameLineInfo getGitBlameLineInfo(RepoConfiguration config, Ca
String authorName = blameResultLines[1].substring(AUTHOR_NAME_OFFSET);
String authorEmail = blameResultLines[2]
.substring(AUTHOR_EMAIL_OFFSET).replaceAll("<|>", "");
long timestamp = Long.parseLong(blameResultLines[3].substring(COMMIT_TIME_OFFSET)) * 1000;
long timestampMilliseconds = Long.parseLong(blameResultLines[3].substring(COMMIT_TIME_OFFSET)) * 1000;
Author author = config.getAuthor(authorName, authorEmail);

return new GitBlameLineInfo(commitHash, author, timestamp);
return new GitBlameLineInfo(commitHash, author, timestampMilliseconds);
}
}
2 changes: 1 addition & 1 deletion src/main/java/reposense/parser/ArgsParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private static ArgumentParser getArgumentParser() {
parser.addArgument(ANALYZE_AUTHORSHIP_FLAGS)
.dest(ANALYZE_AUTHORSHIP_FLAGS[0])
.action(Arguments.storeTrue())
.help("A flag to perform analysis for code authorship.");
.help("A flag to perform analysis of code authorship.");

parser.addArgument(VIEW_FLAGS)
.dest(VIEW_FLAGS[0])
Expand Down
4 changes: 2 additions & 2 deletions src/systemtest/java/reposense/ConfigSystemTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ private void generateReport(String inputDates)
repoConfigs, cliArguments.getSinceDate(), cliArguments.getUntilDate());

ReportGenerator.generateReposReport(repoConfigs, FT_TEMP_DIR, TEST_REPORT_GENERATED_TIME,
cliArguments.getSinceDate(), cliArguments.getUntilDate(),
cliArguments.isSinceDateProvided(), cliArguments.isUntilDateProvided(), false);
cliArguments.getSinceDate(), cliArguments.getUntilDate(), cliArguments.isSinceDateProvided(),
cliArguments.isUntilDateProvided(), cliArguments.isAuthorshipAnalyzed());
}

/**
Expand Down
21 changes: 2 additions & 19 deletions src/test/java/reposense/authorship/AuthorshipAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -110,16 +110,8 @@ public void analyzeAuthorship_matchesIgnoreGlob_success() {
fakeAuthor.appendIgnoreGlobList(Collections.singletonList("analyzeAuthorshipTest2.java"));
FileInfoAnalyzer.analyzeFile(config, fileInfoFull, true);

Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(1).getAuthor());
Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(2).getAuthor());
Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(3).getAuthor());
Assert.assertEquals(new Author(MINGYI_AUTHOR_NAME), fileInfoFull.getLine(4).getAuthor());

Assert.assertTrue(fileInfoFull.getLine(1).isFullCredit());
Assert.assertTrue(fileInfoFull.getLine(2).isFullCredit());
Assert.assertTrue(fileInfoFull.getLine(3).isFullCredit());

// Full credit given since previous author ignores the previous file name
Assert.assertEquals(new Author(MINGYI_AUTHOR_NAME), fileInfoFull.getLine(4).getAuthor());
Assert.assertTrue(fileInfoFull.getLine(4).isFullCredit());
}

Expand All @@ -128,18 +120,9 @@ public void analyzeAuthorship_sameAuthor_success() {
FileInfo fileInfoFull = generateAnalyzeAuthorshipTestFileInfo("analyzeAuthorshipTest1.java");
FileInfoAnalyzer.analyzeFile(config, fileInfoFull, true);

Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(1).getAuthor());
Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(2).getAuthor());
// Full credit given since current author is also the author of the previous version
Assert.assertEquals(new Author(FAKE_AUTHOR_NAME), fileInfoFull.getLine(3).getAuthor());
Assert.assertEquals(new Author(MINGYI_AUTHOR_NAME), fileInfoFull.getLine(4).getAuthor());

Assert.assertTrue(fileInfoFull.getLine(1).isFullCredit());
Assert.assertTrue(fileInfoFull.getLine(2).isFullCredit());

// Full credit given since previous author is also the current author
Assert.assertTrue(fileInfoFull.getLine(3).isFullCredit());

Assert.assertFalse(fileInfoFull.getLine(4).isFullCredit());
}

/**
Expand Down

0 comments on commit b5abc13

Please sign in to comment.