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

Dump git-log to change-log #156

Draft
wants to merge 30 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
957976d
Dump git-log to change-log
HeikoTheissen Sep 22, 2021
4df5141
typo
HeikoTheissen Sep 22, 2021
a06e4a5
Only commits where the long text starts with CHANGELOG
HeikoTheissen Sep 22, 2021
3417423
markdown flavor
HeikoTheissen Sep 23, 2021
195116e
Script for updating CHANGELOG.md
HeikoTheissen Sep 23, 2021
b0d6a81
conditional step for changelog
HeikoTheissen Sep 23, 2021
84e53b0
determination of remote URL
HeikoTheissen Sep 23, 2021
3ec05ca
added test
HeikoTheissen Sep 23, 2021
b2b6e5c
prepare alternative
HeikoTheissen Sep 23, 2021
0ade0ff
corrected nodejs.yml
HeikoTheissen Sep 23, 2021
d0ae1b4
corrected commit message
HeikoTheissen Sep 23, 2021
adac6c7
Update changelog.test.js
ralfhandl Sep 23, 2021
e38f779
Extended test to two changelog entries
HeikoTheissen Sep 23, 2021
9e5daf2
Merge branch 'changelogs' of
HeikoTheissen Sep 23, 2021
290094b
Mechanism to correct typos in the changelog.
HeikoTheissen Sep 23, 2021
0771726
Allow corrections of corrections
HeikoTheissen Sep 23, 2021
cad3ecb
changelog handbook
HeikoTheissen Sep 23, 2021
6682867
Prepare for CHANGELOG.md in main branch
HeikoTheissen Sep 23, 2021
f117ab5
allow indentation in markdown
HeikoTheissen Sep 23, 2021
c7dd50c
Switch to standard-changelog
HeikoTheissen Sep 24, 2021
f8a319d
Revert handbook
HeikoTheissen Sep 24, 2021
641ca41
remove empty line
HeikoTheissen Sep 24, 2021
b839f32
This is no merge commit.
HeikoTheissen Sep 26, 2021
3263262
Own template
HeikoTheissen Sep 26, 2021
c7f63c8
Amendment
HeikoTheissen Sep 26, 2021
1e94709
git add before git commit
HeikoTheissen Sep 30, 2021
622f265
amended changelog entries keep their commit id
HeikoTheissen Oct 1, 2021
f539a8a
maintain CHANGELOG.md in main branch
HeikoTheissen Oct 1, 2021
837a367
Merge branch 'main' into changelogs
ralfhandl Dec 14, 2021
58f61e7
Refreshed package.json and package-lock.json
ralfhandl Dec 14, 2021
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
6 changes: 6 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,9 @@ jobs:
git diff --exit-code vocabularies
env:
CI: true
- name: write changelog
if: ${{ github.event.pull_request.merged == true }}
run: npm run changelog
env:
CI: true
PUSHER_EMAIL: ${{ github.event.pusher.email }}
58 changes: 58 additions & 0 deletions lib/changelog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
const {Transform} = require("stream");

var entry;
var blocked = new Map();

function nextLine(t) {
var offset = t.buffer.indexOf("\n");
if (offset >= 0) {
var o = offset;
if (t.buffer[o - 1] === 13) o--; // drop carriage-return before line-feed
t.emit("line", t.buffer.toString("utf8", 0, o));
t.buffer = t.buffer.slice(offset + 1);
process.nextTick(nextLine, t);
} else
t.callback();
}

process.stdin.pipe(
new Transform({
transform(chunk, encoding, callback) {
this.buffer = this.buffer ?
Buffer.concat([this.buffer, chunk], this.buffer.length + chunk.length) :
Buffer.from(chunk);
this.callback = callback;
nextLine(this);
},
flush(callback) {
if (this.buffer && this.buffer.length > 0) // add line-feed to final line
this._transform(Buffer.from("\n"), undefined, callback);
else
callback();
}
})
.on("line", function(line) {
if (/^commit\s+([0-9a-f]*)/.test(line)) {
if (entry && entry.length > 2) this.push(entry.join(""));
if (blocked.get(RegExp.$1)) entry = undefined;
else entry = [];
} else if (entry && /^Date:\s+(.*)$/.test(line))
entry.push("# " + RegExp.$1 + "\n");
else if (entry && /^\s+\S/.test(line)) {
if (entry.length === 1)
entry.push("");
else if (entry.length === 2) {
if (!/^\s+CHANGELOG(\s+([0-9a-f]*))?\s*$/.test(line))
entry = undefined;
else {
blocked.set(RegExp.$2, true);
entry.push("");
}
} else
entry.push(line.replace(/^\s*/, "") + "\n");
}
})
.on("end", function() {
if (entry && entry.length > 2) process.stdout.write(entry.join(""));
})
).pipe(process.stdout);
13 changes: 13 additions & 0 deletions lib/changelog.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
remote=$(git remote show origin | grep -P -o "(?<=Push URL: ).*")
folder=$(mktemp -d)
git log | node lib/changelog >$folder/CHANGELOG.md
cd $folder
git init -b main
git add .
git commit -m "changelog"
git push --force $remote main:changelog

# Alternative
# git log | node lib/changelog >$folder/CHANGELOG.md
# git diff-index --quiet HEAD || git commit -m "changelog"
# git push
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
},
"scripts": {
"build": "node lib/transform.js",
"changelog": "./lib/changelog.sh",
"test": "c8 -r html -r text mocha",
"watch": "mocha --watch"
},
Expand Down
26 changes: 26 additions & 0 deletions test/changelog.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const assert = require("assert");
const { spawn } = require("child_process");
const fs = require("fs");

describe("Changelog", function () {
it("Convert git log to changelog", function () {
var markdown = "";
var proc = spawn("node", ["lib/changelog"], { cwd: __dirname + "/.." });
proc.stdout
.on("data", function (chunk) {
markdown += chunk;
})
.on("end", function () {
assert.deepStrictEqual(markdown.split("\n"), [
"# Thu Sep 16 17:19:02 2021 +0200",
"- All terms were deprecated",
"- 100 new terms were introduced",
"# Thu Sep 16 17:19:01 2021 +0200",
"New vocabulary",
"",
]);
process.exit(0);
});
fs.createReadStream("test/gitlog.txt").pipe(proc.stdin);
});
});
44 changes: 44 additions & 0 deletions test/gitlog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
commit 0c620c74d1c738e98f270c809ea6f347d5106e7c
Author: Ralf Handl <ralf.handl@sap.com>
Date: Fri Sep 17 11:00:09 2021 +0200

Update README.md (#155)

* Update README.md

Co-authored-by: Heiko Theißen <heiko.theissen@sap.com>

commit 122dff83ef4f139e3361e5af557519c898ee81bd
Author: Ralf Handl <ralf.handl@sap.com>
Date: Thu Sep 16 17:19:02 2021 +0200

Temporal: example for timeline with object key (#154)

CHANGELOG
- All terms were deprecated
- 100 new terms were introduced

commit c231de3dbb043eae0deed124851055712da6ff59
Author: Heiko Theißen <heiko.theissen@sap.com>
Date: Thu Sep 16 17:24:48 2021 +0200

Temporal vocabulary (#146)

commit 122dff93ef4f139e3361e5af557519c898ee81bd
Author: Ralf Handl <ralf.handl@sap.com>
Date: Thu Sep 16 17:19:01 2021 +0200

Temporal: example for timeline with object key (#154)

CHANGELOG 122dff73ef4f139e3361e5af557519c898ee81bd
HeikoTheissen marked this conversation as resolved.
Show resolved Hide resolved
New vocabulary

commit 122dff73ef4f139e3361e5af557519c898ee81bd
Author: Ralf Handl <ralf.handl@sap.com>
Date: Thu Sep 16 17:19:01 2021 +0200

Temporal: example for timeline with object key (#154)

CHANGELOG
HeikoTheissen marked this conversation as resolved.
Show resolved Hide resolved
New vocabularie