Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
charphi committed Aug 28, 2024
2 parents 6d073e1 + 94d43a5 commit 438cf10
Show file tree
Hide file tree
Showing 100 changed files with 2,084 additions and 638 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/check-links.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:

- name: Check links
id: lychee
uses: lycheeverse/lychee-action@v1.9.3
uses: lycheeverse/lychee-action@v1.10.0
with:
fail: true
args: --max-concurrency 1 --cache --no-progress --exclude-all-private './**/*.md'
33 changes: 33 additions & 0 deletions .github/workflows/heylogs.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Heylogs

on: [ push ]

jobs:
badge-job:
if: startsWith(github.repository, 'nbbrd/') && startsWith(github.ref, 'refs/heads/develop')
runs-on: ubuntu-latest
steps:
- name: Checkout source code
uses: actions/checkout@v4

- name: Setup Java
uses: actions/setup-java@v4
with:
distribution: 'temurin'
java-version: 21
cache: 'maven'

- name: Scan changelog
run: mvn -B -ntp -U com.github.nbbrd.heylogs:heylogs-maven-plugin::scan -Dheylogs.output.file=scan.json -Dheylogs.format.id=json

- name: Create badges endpoint json
run: |
mkdir heylogs
jq '{schemaVersion: 1, label: "unreleased changes", message: "#\(.[0].summary.unreleasedChanges)", color: "E05735", logoColor: "white", namedLogo: "keepachangelog"}' scan.json > heylogs/unreleased-changes.json
- name: Deploy badges endpoint json
uses: peaceiris/actions-gh-pages@v4
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
publish_branch: badges
publish_dir: ./heylogs
2 changes: 1 addition & 1 deletion .github/workflows/java-ea-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
fail-fast: false
matrix:
java: [ 21 ]
os: [ ubuntu-latest ]
os: [ ubuntu-latest, macos-latest ]

name: JDK${{ matrix.java }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/java8-maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ jobs:
fail-fast: false
matrix:
java: [ 8, 21 ]
os: [ ubuntu-latest, macOS-latest, windows-latest ]
os: [ ubuntu-latest, macos-13, windows-latest ]

name: JDK${{ matrix.java }} on ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand Down
16 changes: 15 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@ to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.9.0] - 2024-08-28

This release adds a release command that greatly improves the use of heylogs in automations.
It also brings some code refactoring to split the code into more manageable parts.

### Added

- Add release command to promote the Unreleased section into a new release version section [#10](https://github.com/nbbrd/heylogs/issues/10)

### Changed

- Improve code modularization

## [0.8.1] - 2024-04-18

### Fixed
Expand Down Expand Up @@ -154,7 +167,8 @@ This release improves extension points and also aligns features of Maven plugin

- Initial release

[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.8.1...HEAD
[Unreleased]: https://github.com/nbbrd/heylogs/compare/v0.9.0...HEAD
[0.9.0]: https://github.com/nbbrd/heylogs/compare/v0.8.1...v0.9.0
[0.8.1]: https://github.com/nbbrd/heylogs/compare/v0.8.0...v0.8.1
[0.8.0]: https://github.com/nbbrd/heylogs/compare/v0.7.2...v0.8.0
[0.7.2]: https://github.com/nbbrd/heylogs/compare/v0.7.1...v0.7.2
Expand Down
68 changes: 55 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# heylogs

[![Download](https://img.shields.io/github/release/nbbrd/heylogs.svg)](https://github.com/nbbrd/heylogs/releases/latest)
[![Changes](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnbbrd%2Fheylogs%2Fbadges%2Funreleased-changes.json)](https://github.com/nbbrd/heylogs/blob/develop/CHANGELOG.md)

`heylogs` is a set of tools to deal with the [keep-a-changelog format](https://keepachangelog.com),
a changelog format designed to be human-readable.
Expand All @@ -16,11 +17,40 @@ Features:
- Checks format
- Summarizes content
- Extracts versions
- Modify content

[ [Library](#library) | [Command-line tool](#command-line-tool) | [Maven plugin](#maven-plugin) | [Developing](#developing) | [Contributing](#contributing) | [Licensing](#licensing) | [Related work](#related-work)]
[ [Library](#library) | [Command-line tool](#command-line-tool) | [Maven plugin](#maven-plugin) | [Badges](#badges) | [Developing](#developing) | [Contributing](#contributing) | [Licensing](#licensing) | [Related work](#related-work)]

## Library

Heylogs is available as a Java library.
_Note that the API is currently in beta and might change frequently._

```xml
<dependencies>
<dependency>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-api</artifactId>
<version>_VERSION_</version>
</dependency>
<dependency>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-ext-github</artifactId>
<version>_VERSION_</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
```

The API is straightforward and has a single point of entry:
```java
Heylogs heylogs = Heylogs.ofServiceLoader();
Document flexmarkDocument = parseFileWithFlexmark(file);
List<Problem> problems = heylogs.checkFormat(flexmarkDocument);
...
```

`WIP`

## Command-line tool
Expand All @@ -31,12 +61,13 @@ It requires a Java SE Runtime Environment (JRE) version 8 or later to run on suc

It provides the following commands:

| Name | Description |
|-----------|---------------------------------|
| `scan` | Summarize changelog content |
| `check` | Check changelog format |
| `extract` | Extract versions from changelog |
| `list` | List available resources |
| Name | Description |
|-----------|-------------------|
| `check` | Check format |
| `scan` | Summarize content |
| `extract` | Extract versions |
| `release` | Release changes |
| `list` | List resources |

It follows the Unix philosophy of [“Do one thing and do it well“](https://en.wikipedia.org/wiki/Unix_philosophy#Do_One_Thing_and_Do_It_Well) by performing a single function and beeing composable.

Expand Down Expand Up @@ -140,12 +171,13 @@ To use the CLI without installing it:

It provides the following goals:

| Name | Description |
|-----------|---------------------------------|
| `scan` | Summarize changelog content |
| `check` | Check changelog format |
| `extract` | Extract versions from changelog |
| `list` | List available resources |
| Name | Description |
|-----------|-------------------|
| `check` | Check format |
| `scan` | Summarize content |
| `extract` | Extract versions |
| `release` | Release changes |
| `list` | List resources |

### Examples

Expand Down Expand Up @@ -196,6 +228,16 @@ Extract the latest version from the changelog during a release:
</profile>
```

## Badges

Heylogs make it possible to generate nice badges using a [GitHub workflow](https://github.com/nbbrd/heylogs/blob/develop/.github/workflows/heylogs.yml) and the [shields.io API](https://shields.io/badges/endpoint-badge).
Here are some examples:

![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnbbrd%2Fheylogs%2Fbadges%2Funreleased-changes.json)
![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnbbrd%2Fheylogs%2Fbadges%2Funreleased-changes.json&label=changelog)
![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnbbrd%2Fheylogs%2Fbadges%2Funreleased-changes.json&label=changelog&logo=none)
![Endpoint Badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fraw.githubusercontent.com%2Fnbbrd%2Fheylogs%2Fbadges%2Funreleased-changes.json&label=%20)

## Developing

This project is written in Java and uses [Apache Maven](https://maven.apache.org/) as a build tool.
Expand Down
41 changes: 23 additions & 18 deletions heylogs-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<parent>
<groupId>com.github.nbbrd.heylogs</groupId>
<artifactId>heylogs-parent</artifactId>
<version>0.8.1</version>
<version>0.9.0</version>
</parent>

<artifactId>heylogs-api</artifactId>
Expand All @@ -22,7 +22,7 @@
<dependency>
<groupId>com.github.nbbrd.java-io-util</groupId>
<artifactId>java-io-bom</artifactId>
<version>0.0.28</version>
<version>0.0.30</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Expand Down Expand Up @@ -65,17 +65,6 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.semver4j</groupId>
<artifactId>semver4j</artifactId>
<version>5.2.3</version>
<exclusions>
<exclusion>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>com.github.nbbrd.java-io-util</groupId>
<artifactId>java-io-base</artifactId>
Expand All @@ -84,11 +73,6 @@
<groupId>com.github.nbbrd.java-io-util</groupId>
<artifactId>java-io-http</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

<!-- test only -->
<dependency>
Expand All @@ -102,4 +86,25 @@
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
<configuration>
<includes>
<include>tests/**</include>
</includes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.vladsch.flexmark.ast.BulletList;
import com.vladsch.flexmark.ast.BulletListItem;
import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.ast.Reference;
import com.vladsch.flexmark.util.ast.Node;
import com.vladsch.flexmark.util.sequence.BasedSequence;
import nbbrd.heylogs.Nodes;
import nbbrd.heylogs.TypeOfChange;
import nbbrd.heylogs.Version;

import java.net.URL;
import java.util.List;
import java.util.Map;
import java.util.Optional;
Expand Down Expand Up @@ -64,4 +67,8 @@ private static List<BulletListItem> collect(Heading typeOfChange) {
.flatMap(Nodes.of(BulletListItem.class)::descendants)
.collect(toList());
}

public static Reference newReference(Version newVersion, URL newURL) {
return new Reference(BasedSequence.of("[" + newVersion.getRef() + "]: " + newURL), null, null);
}
}
19 changes: 19 additions & 0 deletions heylogs-api/src/main/java/internal/heylogs/RuleSupport.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package internal.heylogs;

import com.vladsch.flexmark.ast.LinkNodeBase;
import com.vladsch.flexmark.util.ast.Document;
import com.vladsch.flexmark.util.ast.Node;
import lombok.NonNull;
import nbbrd.heylogs.Nodes;
import nbbrd.heylogs.Problem;
import nbbrd.heylogs.spi.Rule;
import nbbrd.heylogs.spi.RuleIssue;
import nbbrd.io.text.Parser;

import java.net.URL;
import java.util.List;
import java.util.Locale;
import java.util.Objects;
import java.util.Optional;
import java.util.stream.Stream;

public final class RuleSupport {

Expand All @@ -21,4 +30,14 @@ private RuleSupport() {
public static @NonNull Optional<URL> linkToURL(@NonNull LinkNodeBase link) {
return Parser.onURL().parseValue(link.getUrl());
}

public static @NonNull Stream<Problem> problemStreamOf(@NonNull Document root, @NonNull List<Rule> rules) {
return Nodes.walk(root)
.flatMap(node -> rules.stream().map(rule -> getProblemOrNull(node, rule)).filter(Objects::nonNull));
}

private static Problem getProblemOrNull(Node node, Rule rule) {
RuleIssue ruleIssueOrNull = rule.getRuleIssueOrNull(node);
return ruleIssueOrNull != null ? Problem.builder().rule(rule).issue(ruleIssueOrNull).build() : null;
}
}
61 changes: 61 additions & 0 deletions heylogs-api/src/main/java/internal/heylogs/VersionNode.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package internal.heylogs;

import com.vladsch.flexmark.ast.Heading;
import com.vladsch.flexmark.ast.Reference;
import com.vladsch.flexmark.ast.util.ReferenceRepository;
import com.vladsch.flexmark.util.ast.Document;
import lombok.NonNull;
import nbbrd.heylogs.Nodes;
import nbbrd.heylogs.Version;

import java.net.URL;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

import static java.util.stream.Collectors.toList;

@lombok.Value
public class VersionNode {

@NonNull
Heading heading;

@NonNull
Version version;

@NonNull
Reference reference;

public static VersionNode of(Version version, URL url) {
return new VersionNode(
version.toHeading(), version,
ChangelogNodes.newReference(version, url));
}

public static List<VersionNode> allOf(Document document, ReferenceRepository repository) {
return Nodes.of(Heading.class)
.descendants(document)
.filter(Version::isVersionLevel)
.map(heading -> {
try {
Version version = Version.parse(heading);
return new VersionNode(heading, version, Objects.requireNonNull(repository.getFromRaw(version.getRef())));
} catch (RuntimeException ex) {
return null;
}
})
.filter(Objects::nonNull)
.collect(toList());
}

public static Optional<VersionNode> findUnreleased(List<VersionNode> list) {
return list.stream()
.filter(versionNode -> versionNode.getVersion().isUnreleased())
.findFirst();
}

public URL getURL() {
return URLExtractor.urlOf(getReference().getUrl());
}
}
Loading

0 comments on commit 438cf10

Please sign in to comment.