Skip to content

Commit

Permalink
Three fixes
Browse files Browse the repository at this point in the history
- Fixed a null pointer exception when running.
- Fixed ignoring of users when logins are used in the filter and the commit was on the main branch.
- Fixed parsing of multiple ignored users.
  • Loading branch information
koppor committed Jul 15, 2024
1 parent 2d278f5 commit 3fb6e11
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 6 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

## [2024-07-15]

### Fixed

- Fixed a null pointer exception when running. [#22](https://github.com/koppor/github-contributors-list/issues/22)
- Fixed ignoring of users when logins are used in the filter and the commit was on the main branch.
- Fixed parsing of multiple ignored users.

## [2024-04-26]

### Added
Expand Down Expand Up @@ -45,6 +53,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

Initial release.

[2024-07-15]: https://github.com/koppor/github-contributors-list/compare/2024-04-26...2024-07-15
[2024-04-26]: https://github.com/koppor/github-contributors-list/compare/2024-04-25...2024-04-26
[2024-04-25]: https://github.com/koppor/github-contributors-list/compare/2024-04-09...2024-04-25
[2024-04-09]: https://github.com/koppor/github-contributors-list/releases/tag/2024-04-09
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,12 @@ Usage: jbang gcl@koppor/github-contributors-list [-lhV] [--startrevision=<startC
-V, --version Print version information and exit.
```

Example:

```terminal
Usage: jbang gcl@koppor/github-contributors-list --repository JabRef/jabref c:\git-repositories\jabref --startrevision=v5.13 --endrevision=v5.15
```

At the end, non-found committers are listed.
The format is `<used name> <PR link> <commit link>`.
Example:
Expand All @@ -70,6 +76,10 @@ For instance, if a user first appears as "Co-authored-by:" and later as a pull r

In case of issues, try to delete `gcl.mv` to start with a fresh cache.

## FAQ

⚠ In case contributors are not ignored, please delete `gcl.mv` and try again. ⚠

## Implementation details

- `gcl.mv` is an [MVStore](https://www.h2database.com/html/mvstore.html) caching contributor information returned by GitHub's API.
Expand Down
38 changes: 32 additions & 6 deletions gcl.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//DEPS info.picocli:picocli:4.7.6
//DEPS one.util:streamex:0.8.2
//DEPS me.tongfei:progressbar:0.10.1
//DEPS org.jline:jline-terminal:3.26.2
//DEPS org.eclipse.collections:eclipse-collections:11.1.0

//DEPS org.tinylog:tinylog-api:2.7.0
Expand Down Expand Up @@ -89,13 +90,13 @@ public class gcl implements Callable<Integer> {
@Option(names = "--endrevision", description = "The last revision to check (tag or commit id). Included.")
private String endCommitRevStr;

@Option(names = "--repository", description = "The GitHub repository in the form owner/repostiory. E.g., JabRef/jabref")
@Option(names = "--repository", description = "The GitHub repository in the form owner/repository. E.g., JabRef/jabref")
private String ownerRepository;

@Option(names = "--cols", description = "Number of columns")
private Integer cols = 6;

@Option(names = "--filter")
@Option(names = "--filter", split = ",")
private List<String> ignoredUsers = List.of(
"allcontributors[bot]",
"dependabot[bot]",
Expand All @@ -105,7 +106,7 @@ public class gcl implements Callable<Integer> {
"renovate[bot]",
"renovate-bot");

@Option(names = "--filter-emails")
@Option(names = "--filter-emails", split = ",")
private List<String> ignoredEmails = List.of(
"49699333+dependabot[bot]@users.noreply.github.com",
"[email protected]",
Expand Down Expand Up @@ -388,9 +389,14 @@ private void addContributorFromRevCommit(RevCommit commit, MVMap<String, Contrib
ignored = true;
}

if (author.getLogin() != null && ignoredUsers.contains(author.getLogin())) {
Logger.trace("Ignored because of login: {}", contributor);
ignored = true;
}

if (!ignored) {
emailToContributor.put(commit.getAuthorIdent().getEmailAddress(), contributor);
contributors.add(contributor);
addContributor(contributor);
}
}
} catch (IOException e) {
Expand All @@ -401,6 +407,14 @@ private void addContributorFromRevCommit(RevCommit commit, MVMap<String, Contrib
analyzeRegularCommit(authorOfCommit, emailToContributor, gitHub, NO_PR, commit.getName(), commit.getFullMessage());
}

/**
* @implNote Separate method to allow for easier debugging for addition of contributors
*/
private boolean addContributor(Contributor contributor) {
Logger.trace("Adding {} to {]", contributor, contributors);
return contributors.add(contributor);
}

/**
* @param number the PR number
* @return false if the PR did not exist
Expand Down Expand Up @@ -455,6 +469,9 @@ private void analyzeRegularCommit(CoAuthor authorOfCommit, MVMap<String, Contrib
.forEach(contributors::add);
}

/**
* Converts contributors to a markdown table.
*/
private void printMarkdownSnippet() {
String heading = "|" + " |".repeat(cols);
System.out.println(heading);
Expand Down Expand Up @@ -527,16 +544,19 @@ private static String getFormattedSecondLine(Contributor contributor) {
private void storeContributorData(MVMap<String, Contributor> loginToContributor, MVMap<String, Contributor> emailToContributor, GHUser ghUser, String prCommitNumber) {
Logger.trace("Handling {}", ghUser);
String login = ghUser.getLogin();
Logger.trace("Login: {}", login);

if (ignoredUsers.contains(login)) {
Logger.trace("Ignored because of login {}", login);
return;
} else {
Logger.trace("Not ignored because of login {}", login);
}

Contributor contributor = loginToContributor.get(login);
Logger.trace("Found contributor {}", contributor);
if (contributor != null) {
contributors.add(contributor);
addContributor(contributor);
putIntoEmailToContributorMap(emailToContributor, ghUser, contributor);
return;
}
Expand All @@ -560,7 +580,7 @@ private void storeContributorData(MVMap<String, Contributor> loginToContributor,
Contributor newContributor = new Contributor(name, ghUser.getHtmlUrl().toString(), ghUser.getAvatarUrl(), prCommitNumber);
Logger.trace("Created new contributor {} based on PR data", newContributor);
loginToContributor.put(login, newContributor);
contributors.add(newContributor);
addContributor(newContributor);

putIntoEmailToContributorMap(emailToContributor, ghUser, newContributor);
}
Expand All @@ -581,6 +601,12 @@ private static void putIntoEmailToContributorMap(MVMap<String, Contributor> emai
emailToContributor.put(email, contributor);
}

/**
* Looks up the contributor data for the given co-author. If the co-author is already in the contributors set, the lookup is skipped.
* If the co-author is in the ignoredUsers or ignoredEmails lists, the lookup is skipped and an empty Optional is returned.
*
* @return an Optional with the contributor data if the lookup was successful, otherwise an empty Optional.
*/
private Optional<Contributor> lookupContributorData(MVMap<String, Contributor> emailToContributor, GitHub gitHub, String prNumber, String commitName, CoAuthor coAuthor) {
Logger.trace("Looking up {}", coAuthor);
if (alreadyChecked.contains(coAuthor)) {
Expand Down

0 comments on commit 3fb6e11

Please sign in to comment.