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

Add CI #9

Merged
merged 16 commits into from
Apr 25, 2024
52 changes: 52 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
on: [pull_request]

jobs:
check:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'
show-progress: 'false'
- uses: actions/cache@v4
with:
path: /root/.jbang
key: $-jbang-$
restore-keys: |
$-jbang-
- name: jbang
uses: jbangdev/[email protected]
with:
script: gcl.java
env:
GITHUB_OAUTH: ${{ secrets.GITHUB_TOKEN }}
lint:
runs-on: ubuntu-latest
steps:
- name: checkout
uses: actions/checkout@v4
with:
show-progress: 'false'
- name: markdownlint
uses: DavidAnson/markdownlint-cli2-action@v16
with:
globs: |
*.md
- name: Lint CHANGELOG.md
run: |
# Install jbang
curl -Ls https://sh.jbang.dev | bash -s - app setup
export PATH=$PATH:$HOME/.jbang/bin

# run heylogs verification
jbang com.github.nbbrd.heylogs:heylogs-cli:0.7.2:bin check CHANGELOG.md > heylogs.txt || true

# improve output
sed -i 's/all-h2-contain-a-version/all-h2-contain-a-version (ignored)/' heylogs.txt

cat heylogs.txt

# exit 1 in case of error
# We have 1 "valid" issue in CHANGELOG.md
grep -q "2 problems" heylogs.txt || exit 1
4 changes: 4 additions & 0 deletions .markdownlint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
default: true

# allow arbitrary line length
MD013: false
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ 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-04-25
## [2024-04-25]

### Added

Expand All @@ -20,11 +20,15 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).

- Commits without any pull request number are also analyzed.
- Fixed typo in parameter `--login-mapping`.
- Handling of ignored users.

### Removed

- Removed some hard-coded JabRef defaults (such as ignored users).

## 2024-04-09
## [2024-04-09]

Initial release.

[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
23 changes: 13 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ See <https://blog.jabref.org/2024/04/03/JabRef5-13/#special-thanks> for real-wor
3. `cd` to the repository you want to analyze.
4. `jbang gcl@koppor/github-contributors-list`

```
Usage: jbang gcl.java [-lhV] [--startrevision=<startCommitRevStr>]
[--endrevision=<endCommitRevStr>] [--owner=<owner>]
[--repo=<repository>] [--cols=<cols>] [--filter=<ignoredUsers>]...
```terminal
Usage: jbang gcl@koppor/github-contributors-list [-lhV] [--startrevision=<startCommitRevStr>]
[--endrevision=<endCommitRevStr>] [--repository=<ownerRepository>]
[--cols=<cols>] [--filter=<ignoredUsers>]...
[--filter-emails=<ignoredEmails>]... [-m=<String=String>]...
<repositoryPath>
<repositoryPath> The path to the git repository to analyse.
[<repositoryPath>]
[<repositoryPath>] The path to the git repository to analyse.
--cols=<cols> Number of columns
--endrevision=<endCommitRevStr>
The last revision to check (tag or commit id).
Expand All @@ -40,11 +40,12 @@ Usage: jbang gcl.java [-lhV] [--startrevision=<startCommitRevStr>]
-h, --help Show this help message and exit.
-l, --[no-]github-lookup Should calls be made to GitHub's API for user
information
-m, --lgin-mapping=<String=String>
-m, --login-mapping=<String=String>
Mapping of GitHub logins to names. Format:
name=login
--owner=<owner> The GitHub owner of the repository
--repo=<repository> The GitHub repository name
--repository=<ownerRepository>
The GitHub repository in the form
owner/repostiory. E.g., JabRef/jabref
--startrevision=<startCommitRevStr>
The first revision to check (tag or commit id).
Excluded.
Expand All @@ -55,7 +56,9 @@ At the end, non-found committers are listed.
The format is `<used name> <PR link> <commit link>`.
Example:

Anish.Pal https://github.com/JabRef/jabref/pull/10829 https://github.com/JabRef/jabref/pull/10829/commits/d2d84923df2c6c7d59559da8d583ae17dc803c3d
```text
Anish.Pal https://github.com/JabRef/jabref/pull/10829 https://github.com/JabRef/jabref/pull/10829/commits/d2d84923df2c6c7d59559da8d583ae17dc803c3d
```

With that information, one can create a mapping from the committer name to the GitHub username.
In this case: `Anish.Pal=pal-anish`
Expand Down
37 changes: 30 additions & 7 deletions gcl.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ public class gcl implements Callable<Integer> {
private static final Pattern numberAtEnd = Pattern.compile(".*\\(#(\\d+)\\)$");
private static final Pattern mergeCommit = Pattern.compile("^Merge pull request #(\\d+) from.*");

@Parameters(index = "0", description = "The path to the git repository to analyse.")
@Parameters(index = "0", arity = "0..1", description = "The path to the git repository to analyse.")
private Path repositoryPath = Path.of(".");

@Option(names = "--startrevision", description = "The first revision to check (tag or commit id). Excluded.")
Expand Down Expand Up @@ -126,6 +126,10 @@ public class gcl implements Callable<Integer> {
private static final String githubUsersEmailSuffix = "@users.noreply.github.com";

private record Contributor(String name, String url, String avatarUrl) implements Serializable {
public String getUserId() {
// Example: https://github.com/LoayGhreeb, then userId is LoeyGhreeb
return url.substring(url.lastIndexOf('/') + 1);
}
}

private record CoAuthor(String name, String email) {
Expand All @@ -136,7 +140,7 @@ public CoAuthor(String line) {
}
}

private SortedSet<Contributor> contributors = new TreeSet<>((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(a.name,b.name));
private SortedSet<Contributor> contributors = new TreeSet<>((a, b) -> String.CASE_INSENSITIVE_ORDER.compare(a.name, b.name));

private SortedSet<String> fallbacks = new TreeSet<>();

Expand Down Expand Up @@ -179,15 +183,32 @@ public Integer call() throws Exception {
Git git = Git.open(repositoryPath.toFile());
Repository repository = git.getRepository(); RevWalk revWalk = new RevWalk(repository)) {

String remoteOriginUrl = "n/a";
if (!hasRepository) {
// Source: https://stackoverflow.com/a/38062680/873282
ownerRepository = git.getRepository().getConfig().getString("remote", "origin", "url");
ownerRepository = ownerRepository.substring(ownerRepository.indexOf(':') + 1, ownerRepository.lastIndexOf('.'));
remoteOriginUrl = git.getRepository().getConfig().getString("remote", "origin", "url");
if (remoteOriginUrl.startsWith("git@")) {
ownerRepository = remoteOriginUrl.substring(remoteOriginUrl.indexOf(':') + 1, remoteOriginUrl.lastIndexOf('.'));
} else {
ownerRepository = remoteOriginUrl.substring(remoteOriginUrl.indexOf("github.com/") + "github.com/".length());
if (ownerRepository.endsWith(".git")) {
ownerRepository = ownerRepository.substring(0, ownerRepository.length() - ".git".length());
}
}
}

Logger.info("Connecting to {}...", ownerRepository);
GitHub gitHub = GitHub.connect();
GHRepository gitHubRepository = gitHub.getRepository(ownerRepository);
GHRepository gitHubRepository;
try {
gitHubRepository = gitHub.getRepository(ownerRepository);
} catch (IllegalArgumentException e) {
Logger.error("Error in repository reference {}", ownerRepository);
if (!hasRepository) {
Logger.error("It was automatically derived from {}", remoteOriginUrl);
}
return 1;
}

MVMap<String, Contributor> emailToContributor = store.openMap("emailToContributor");
MVMap<String, Contributor> loginToContributor = store.openMap("loginToContributor");
Expand Down Expand Up @@ -472,13 +493,15 @@ private Optional<Contributor> lookupContributorData(MVMap<String, Contributor> e

Contributor contributor = emailToContributor.get(email);
if (contributor != null) {
// Example: Store "LoyGhreeb" https://github.com/LoayGhreeb in userId
String userId = contributor.url.substring(contributor.url.lastIndexOf('/') + 1);
// We already know this email, just check whether we ignore this one
String userId = contributor.getUserId();
if (ignoredUsers.contains(userId)) {
Logger.trace("Ignored because of userId {}: {}", userId, coAuthor);
return Optional.empty();
}
return Optional.of(contributor);
}

if (!ghLookup) {
Logger.trace("Online lookup disabled. Using {} as fallback.", coAuthor.name);
fallbacks.add(coAuthor.name);
Expand Down