changes.lua 1.3 KB

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