| 1 | ---
|
|---|
| 2 | -- Output a list of merged PRs since last release in the CHANGES.txt format.
|
|---|
| 3 | ---
|
|---|
| 4 |
|
|---|
| 5 | local usage = "Usage: premake5 --file=scripts/changes.lua --since=<rev> changes"
|
|---|
| 6 |
|
|---|
| 7 | local sinceRev = _OPTIONS["since"]
|
|---|
| 8 |
|
|---|
| 9 | if not sinceRev then
|
|---|
| 10 | print(usage)
|
|---|
| 11 | error("Missing `--since`", 0)
|
|---|
| 12 | end
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 | local function parsePullRequestId(line)
|
|---|
| 16 | return line:match("#%d+%s")
|
|---|
| 17 | end
|
|---|
| 18 |
|
|---|
| 19 | local function parseTitle(line)
|
|---|
| 20 | return line:match("||(.+)")
|
|---|
| 21 | end
|
|---|
| 22 |
|
|---|
| 23 | local function parseAuthor(line)
|
|---|
| 24 | return line:match("%s([^%s]-)/")
|
|---|
| 25 | end
|
|---|
| 26 |
|
|---|
| 27 | local function parseLog(line)
|
|---|
| 28 | local pr = parsePullRequestId(line)
|
|---|
| 29 | local title = parseTitle(line)
|
|---|
| 30 | local author = parseAuthor(line)
|
|---|
| 31 | return string.format("* PR %s %s (@%s)", pr, title, author)
|
|---|
| 32 | end
|
|---|
| 33 |
|
|---|
| 34 |
|
|---|
| 35 | local function gatherChanges()
|
|---|
| 36 | local cmd = string.format('git log HEAD "^%s" --merges --first-parent --format="%%s||%%b"', _OPTIONS["since"])
|
|---|
| 37 | local output = os.outputof(cmd)
|
|---|
| 38 |
|
|---|
| 39 | changes = {}
|
|---|
| 40 |
|
|---|
| 41 | for line in output:gmatch("[^\r\n]+") do
|
|---|
| 42 | table.insert(changes, parseLog(line))
|
|---|
| 43 | end
|
|---|
| 44 |
|
|---|
| 45 | return changes
|
|---|
| 46 | end
|
|---|
| 47 |
|
|---|
| 48 |
|
|---|
| 49 | local function generateChanges()
|
|---|
| 50 | local changes = gatherChanges()
|
|---|
| 51 | table.sort(changes)
|
|---|
| 52 | for i = 1, #changes do
|
|---|
| 53 | print(changes[i])
|
|---|
| 54 | end
|
|---|
| 55 | end
|
|---|
| 56 |
|
|---|
| 57 |
|
|---|
| 58 | newaction {
|
|---|
| 59 | trigger = "changes",
|
|---|
| 60 | description = "Generate list of git merges in CHANGES.txt format",
|
|---|
| 61 | execute = generateChanges
|
|---|
| 62 | }
|
|---|
| 63 |
|
|---|
| 64 | newoption {
|
|---|
| 65 | trigger = "since",
|
|---|
| 66 | value = "revision",
|
|---|
| 67 | description = "Log merges since this revision"
|
|---|
| 68 | }
|
|---|
| 69 |
|
|---|