Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#944] Fix wrong credit information inherited by annotated author #2060

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
075d34d
[#2027] Fix date range bug (#2034)
jq1836 Sep 24, 2023
0c80ee6
[#2039] Update cypress minimum requirement to 12.15.0 (#2041)
chan-j-d Sep 30, 2023
46409aa
[#1936] Migrate c-segment.vue to typescript (#2035)
jq1836 Sep 30, 2023
43828fd
[#1936] Migrate load-font-awesome-icons.js to typescript (#2040)
jq1836 Sep 30, 2023
d4e2272
[#2045] Fix cypress zoom feature test (#2047)
jq1836 Oct 4, 2023
a8c3f00
[#1936] Migrate random-color-gen.js to typescript (#2043)
jq1836 Oct 4, 2023
93e850f
[#1936] Migrate c-segment-collection.vue to typescript (#2036)
jq1836 Oct 4, 2023
0d1cd99
[#1936] Migrate c-resizer.vue to typescript (#2038)
jq1836 Oct 4, 2023
6292688
Bump zod from 3.20.6 to 3.22.3 in /frontend (#2048)
dependabot[bot] Oct 4, 2023
7bc056a
Bump @cypress/request and cypress in /frontend/cypress (#2042)
dependabot[bot] Oct 4, 2023
0c4045d
[#1936] Migrate c-ramp.vue to typescript (#2037)
jq1836 Oct 11, 2023
174ecc5
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Oct 20, 2023
e200e5e
Give partial credit if annotated author is not the same as the blame
SkyBlaise99 Oct 20, 2023
00cf40d
[#2054] Fix zoom view bug (#2055)
jq1836 Oct 28, 2023
4dae85d
[#1936] Migrate repo-sorter.js to typescript (#2052)
jq1836 Oct 28, 2023
7450425
[#1936] Migrate safari_date.js to typescript (#2053)
jq1836 Oct 28, 2023
056fa5f
Remove frontend JS lint (#2063)
jq1836 Oct 28, 2023
54596ed
[#1929] Add dynamic positioning support for tooltips (#2056)
pratham31012002 Nov 7, 2023
a187d9c
Add test cases for annotated author overriding last author's credit
SkyBlaise99 Nov 7, 2023
58b7002
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Nov 7, 2023
b296b83
revert merge from master
SkyBlaise99 Nov 7, 2023
4ce6545
revert merge from master 58b70025
SkyBlaise99 Nov 7, 2023
f29dc16
[#1928] Fix tooltip zIndex such that it doesn't occlude next file tit…
pratham31012002 Nov 8, 2023
e42c14e
[#1726] Update GitHub-specific references in codebase and docs (#2050)
chan-j-d Nov 8, 2023
4bd05a7
Trigger workflow
SkyBlaise99 Nov 8, 2023
950c912
Merge branch 'master' into 944-analyze-authorship
SkyBlaise99 Nov 8, 2023
a46d423
Revert "Merge branch 'master' into 944-analyze-authorship"
SkyBlaise99 Nov 8, 2023
bba556d
fix frontend test failing
SkyBlaise99 Nov 8, 2023
4d7d3aa
Merge branch '944-analyze-authorship' into 944-analyze-authorship
SkyBlaise99 Nov 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/reposense/authorship/FileInfoAnalyzer.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ public FileResult analyzeTextFile(RepoConfiguration config, FileInfo fileInfo, b
aggregateBlameAuthorModifiedAndDateInfo(config, fileInfo, shouldAnalyzeAuthorship);
fileInfo.setFileType(config.getFileType(fileInfo.getPath()));

AnnotatorAnalyzer.aggregateAnnotationAuthorInfo(fileInfo, config.getAuthorConfig());
AnnotatorAnalyzer.aggregateAnnotationAuthorInfo(fileInfo, config.getAuthorConfig(), shouldAnalyzeAuthorship);

if (!config.getAuthorList().isEmpty() && fileInfo.isAllAuthorsIgnored(config.getAuthorList())) {
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ public class AnnotatorAnalyzer {
*
* @param fileInfo FileInfo to be further analyzed with author annotations.
* @param authorConfig AuthorConfiguration for current analysis.
* @param shouldAnalyzeAuthorship whether credit info needs to be overwritten.
*/
public static void aggregateAnnotationAuthorInfo(FileInfo fileInfo, AuthorConfiguration authorConfig) {
public static void aggregateAnnotationAuthorInfo(FileInfo fileInfo, AuthorConfiguration authorConfig,
boolean shouldAnalyzeAuthorship) {
Optional<Author> currentAnnotatedAuthor = Optional.empty();
Path filePath = Paths.get(fileInfo.getPath());
for (LineInfo lineInfo : fileInfo.getLines()) {
Expand All @@ -60,15 +62,15 @@ public static void aggregateAnnotationAuthorInfo(FileInfo fileInfo, AuthorConfig
boolean isUnknownAuthorSegment = !currentAnnotatedAuthor.isPresent() && !newAnnotatedAuthor.isPresent();

if (isEndOfAnnotatedSegment) {
lineInfo.setAuthor(currentAnnotatedAuthor.get());
lineInfo.updateAuthorAndCredit(currentAnnotatedAuthor.get(), shouldAnalyzeAuthorship);
currentAnnotatedAuthor = Optional.empty();
} else if (isUnknownAuthorSegment) {
currentAnnotatedAuthor = Optional.of(Author.UNKNOWN_AUTHOR);
} else {
currentAnnotatedAuthor = newAnnotatedAuthor.filter(author -> !author.isIgnoringFile(filePath));
}
}
currentAnnotatedAuthor.ifPresent(lineInfo::setAuthor);
currentAnnotatedAuthor.ifPresent(author -> lineInfo.updateAuthorAndCredit(author, shouldAnalyzeAuthorship));
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/main/java/reposense/authorship/model/LineInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,21 @@ public void setIsFullCredit(boolean isFullCredit) {
this.isFullCredit = isFullCredit;
}

/**
* If {@code newAuthor} is not the same as current author, then {@code newAuthor} will get partial credit.
* Else nothing happens since the 2 authors are the same, the credit info is retained.
* {@code isFullCredit} is only updated if {@code shouldAnalyzeAuthorship} is set to True.
*/
public void updateAuthorAndCredit(Author newAuthor, boolean shouldAnalyzeAuthorship) {
if (!author.equals(newAuthor)) {
author = newAuthor;

if (shouldAnalyzeAuthorship) {
isFullCredit = false;
}
}
}

@Override
public boolean equals(Object other) {
if (this == other) {
Expand Down
24 changes: 23 additions & 1 deletion src/test/java/reposense/authorship/AuthorshipAnalyzerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,15 @@

public class AuthorshipAnalyzerTest extends GitTestTemplate {
private static final LocalDateTime SINCE_DATE = TestUtil.getSinceDate(2018, Month.JANUARY.getValue(), 1);
private static final LocalDateTime UNTIL_DATE = TestUtil.getUntilDate(2019, Month.DECEMBER.getValue(), 1);
private static final LocalDateTime UNTIL_DATE = TestUtil.getUntilDate(2023, Month.DECEMBER.getValue(), 1);
private static final String TEST_FILENAME = "analyzeAuthorshipTest.java";
private static final String TEST1_FILENAME = "analyzeAuthorshipTest1.java";
private static final String TEST2_FILENAME = "analyzeAuthorshipTest2.java";
private static final String TEST3_FILENAME = "analyzeAuthorshipTest3.java";
private static final String BRANCH_NAME = "945-FileAnalyzerTest-analyzeAuthorship";
private static final CommitHash IGNORE_HASH = new CommitHash("f874c0992645bed626de2113659ce48d7a2233dd");
private static final Author MINGYI_AUTHOR = new Author(MINGYI_AUTHOR_NAME);
private static final Author SHICHEN_AUTHOR = new Author(SHICHEN_AUTHOR_NAME);

private RepoConfiguration config;

Expand All @@ -43,6 +45,7 @@ public void before() throws Exception {

config.addAuthorNamesToAuthorMapEntry(FAKE_AUTHOR, FAKE_AUTHOR_NAME);
config.addAuthorNamesToAuthorMapEntry(MINGYI_AUTHOR, MINGYI_AUTHOR_NAME);
config.addAuthorNamesToAuthorMapEntry(SHICHEN_AUTHOR, SHICHEN_AUTHOR_NAME);
}

@Test
Expand Down Expand Up @@ -147,6 +150,25 @@ public void analyzeAuthorship_sameAuthor_success() {
Assertions.assertTrue(fileInfo.getLine(3).isFullCredit());
}

@Test
public void analyzeAuthorship_annotatedAuthorOverride_success() {
FileInfo fileInfo = analyzeTextFile(TEST3_FILENAME);

// Line 1 - 4 is annotated to ming yi (myteo)
// Partial credit given since the blamed author is not the same as the annotated author
for (int i = 1; i <= 4; i++) {
Assertions.assertEquals(MINGYI_AUTHOR, fileInfo.getLine(i).getAuthor());
Assertions.assertFalse(fileInfo.getLine(i).isFullCredit());
}

// Line 5 - 8 is annotated to shi chen (SkyBlaise)
// Full credit is inherited since the blamed author is the same as the annotated author
for (int i = 5; i <= 8; i++) {
Assertions.assertEquals(SHICHEN_AUTHOR, fileInfo.getLine(i).getAuthor());
Assertions.assertTrue(fileInfo.getLine(i).isFullCredit());
}
}

private FileInfo analyzeTextFile(String relativePath) {
FileInfoExtractor fileInfoExtractor = new FileInfoExtractor();
FileInfo fileInfo = fileInfoExtractor.generateFileInfo(config, relativePath);
Expand Down
1 change: 1 addition & 0 deletions src/test/java/reposense/template/GitTestTemplate.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ public class GitTestTemplate {
protected static final String EUGENE_AUTHOR_NAME = "eugenepeh";
protected static final String YONG_AUTHOR_NAME = "Yong Hao TENG";
protected static final String MINGYI_AUTHOR_NAME = "myteo";
protected static final String SHICHEN_AUTHOR_NAME = "SkyBlaise";
protected static final String JAMES_AUTHOR_NAME = "jamessspanggg";
protected static final String JAMES_ALTERNATIVE_AUTHOR_NAME = "James Pang";
protected static final String JINYAO_AUTHOR_NAME = "jylee-git";
Expand Down
Loading