OSDN Git Service

misc: add changelog autogenerate scripts
authorhylom <hylom@users.sourceforge.jp>
Sun, 4 Dec 2016 14:07:23 +0000 (23:07 +0900)
committerhylom <hylom@users.sourceforge.jp>
Sun, 4 Dec 2016 14:07:52 +0000 (23:07 +0900)
misc/gen_changelog.sh [new file with mode: 0644]
misc/make_changelog.py [new file with mode: 0644]

diff --git a/misc/gen_changelog.sh b/misc/gen_changelog.sh
new file mode 100644 (file)
index 0000000..7a16336
--- /dev/null
@@ -0,0 +1,3 @@
+#!/bin/sh
+FILTER="python make_changelog.py"
+git log --pretty=format:'%H%n%s%n%cD%n%cn%n%ce>%n' --date=rfc | git name-rev --stdin | $FILTER
diff --git a/misc/make_changelog.py b/misc/make_changelog.py
new file mode 100644 (file)
index 0000000..2b90e39
--- /dev/null
@@ -0,0 +1,78 @@
+#!/usr/bin/python
+import json
+import sys
+import re
+import commands
+import datetime
+
+CHANGELOG_FORMAT=ur"""newslash ({describe}) unstable; urgency=low
+
+{changes}
+
+-- {packager}  {date}
+"""
+CHANGES_FORMAT=ur""" * {subject} ({committer}, {date})"""
+PACKAGER="Hiromichi MATSUSHIMA <hirom@osdn.jp>"
+
+def get_desc(hs):
+    cmd = "git describe --tags " + hs
+    rs = commands.getoutput(cmd)
+    return rs
+
+def main():
+    counter = 0
+    logs = []
+    item = {}
+
+    for l in sys.stdin:
+        l = l.strip()
+        if counter == 0:
+            item["hash"] = l
+        elif counter == 1:
+            item["subject"] = l
+        elif counter == 2:
+            item["date"] = l
+        elif counter == 3:
+            item["committer"] = l
+        elif counter == 4:
+            item["email"] = l
+        counter += 1
+        if re.match(r'^\s*$', l):
+            counter = 0
+            logs.append(item)
+            item = {}
+    if counter != 0:
+        logs.append(item)
+
+    output_changelog(logs)
+
+def _output_item(target, changes):
+    data = {}
+    data["describe"] = get_desc((target["hash"].split())[0])
+    data["date"] = target["date"]
+    data["changes"] = "\n".join(changes)
+    data["packager"] = PACKAGER
+    print CHANGELOG_FORMAT.format(**data)
+
+def output_changelog(logs):
+    changes = []
+    target = logs[0]
+    for item in logs:
+        t = item["hash"].split()
+        commit = t[0]
+        tag = ""
+        m = re.match(r"\(tags/([^~]*)(~.*)?\)", t[1])
+        if m:
+            if not m.group(2):
+                tag = m.group(1)
+
+        if tag:
+            _output_item(target, changes)
+            changes = []
+            target = item
+        changes.append(CHANGES_FORMAT.format(**item))
+
+    _output_item(target, changes)
+    
+if __name__ == '__main__':
+    main()