2016-10-10 14:45:28 +00:00
|
|
|
|
#region ======================== Namespaces
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-12-27 12:12:57 +00:00
|
|
|
|
using System.Collections.Generic;
|
2016-10-10 14:45:28 +00:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Text;
|
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
namespace mxd.ChangelogMaker
|
|
|
|
|
{
|
|
|
|
|
class Program
|
|
|
|
|
{
|
|
|
|
|
#region ======================== Constants
|
|
|
|
|
|
|
|
|
|
private const string SEPARATOR = "--------------------------------------------------------------------------------";
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
#region ======================== Main
|
|
|
|
|
|
|
|
|
|
static int Main(string[] args)
|
|
|
|
|
{
|
2016-12-27 12:12:57 +00:00
|
|
|
|
Console.WriteLine("Changelog Maker v03 by MaxED");
|
2016-12-26 23:05:53 +00:00
|
|
|
|
if(args.Length != 4)
|
2016-10-10 14:45:28 +00:00
|
|
|
|
{
|
2016-12-26 23:05:53 +00:00
|
|
|
|
return Fail("USAGE: ChangelogMaker.exe input output author revision_number\n" +
|
2016-12-27 12:12:57 +00:00
|
|
|
|
"input: xml file generated by MakeRelese.bat\\MakeGITRelese.bat\n" +
|
2016-10-10 14:45:28 +00:00
|
|
|
|
"output: directory to store Changelog.txt in\n" +
|
2016-12-27 12:12:57 +00:00
|
|
|
|
"renameauthor: commit authors rename scheme. For example, \"m-x-d>MaxED|biwa>Boris\"\n" +
|
2016-12-26 23:05:53 +00:00
|
|
|
|
"revision_number: latest revision number", 1);
|
2016-10-10 14:45:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string input = args[0];
|
|
|
|
|
string output = args[1];
|
2016-12-27 12:12:57 +00:00
|
|
|
|
string renameauthor = args[2]; // m-x-d>MaxED|biwa>Boris
|
2016-12-26 23:05:53 +00:00
|
|
|
|
int revnum;
|
|
|
|
|
if(!int.TryParse(args[3], out revnum)) return Fail("Unable to parse revision number from string '" + revnum + "'.", 4);
|
2016-10-10 14:45:28 +00:00
|
|
|
|
|
|
|
|
|
if(!File.Exists(input)) return Fail("Input file '" + input + "' does not exist.", 2);
|
|
|
|
|
if(!Directory.Exists(output)) return Fail("Output folder '" + output + "' does not exist.", 3);
|
|
|
|
|
|
2016-12-27 12:12:57 +00:00
|
|
|
|
// Create author rename array, because git log can't decide how to call me...
|
|
|
|
|
Dictionary<string, string> authorrename = new Dictionary<string, string>(StringComparer.OrdinalIgnoreCase);
|
|
|
|
|
string[] parts = renameauthor.Split(new[] { '|' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
foreach(string ren in parts)
|
|
|
|
|
{
|
|
|
|
|
string[] rename = ren.Split(new[] { '>' }, StringSplitOptions.RemoveEmptyEntries);
|
|
|
|
|
if(rename.Length == 2 && !string.IsNullOrEmpty(rename[0].Trim()) && !string.IsNullOrEmpty(rename[1].Trim()))
|
|
|
|
|
{
|
|
|
|
|
authorrename[rename[0].Trim()] = rename[1].Trim();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine("Invalid rename scheme: \"" + ren + "\"");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-26 23:05:53 +00:00
|
|
|
|
//Replace bracket placeholders, because git log command doesn't escape xml-unfriendly chars like < or >...
|
|
|
|
|
string inputtext = File.ReadAllText(input);
|
|
|
|
|
inputtext = inputtext.Replace("<", "<").Replace(">", ">").Replace("&", "&").Replace("[OB]", "<").Replace("[CB]", ">");
|
2016-10-10 14:45:28 +00:00
|
|
|
|
|
|
|
|
|
XmlDocument log = new XmlDocument();
|
2016-12-26 23:05:53 +00:00
|
|
|
|
using(MemoryStream stream = new MemoryStream(Encoding.ASCII.GetBytes(inputtext)))
|
|
|
|
|
{
|
|
|
|
|
log.Load(stream);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
StringBuilder result = new StringBuilder(1000);
|
2016-12-27 12:12:57 +00:00
|
|
|
|
char[] messagetrim = {' ', '\r', '\n' };
|
2016-10-10 14:45:28 +00:00
|
|
|
|
foreach(XmlNode node in log.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
if(node.ChildNodes.Count == 0) continue;
|
|
|
|
|
|
|
|
|
|
foreach (XmlNode logentry in node.ChildNodes)
|
|
|
|
|
{
|
2016-12-26 23:05:53 +00:00
|
|
|
|
string commit = (logentry.Attributes != null ? logentry.Attributes.GetNamedItem("commit").Value : "unknown");
|
2016-10-10 14:45:28 +00:00
|
|
|
|
DateTime date = DateTime.Now;
|
|
|
|
|
string message = string.Empty;
|
2016-12-27 12:12:57 +00:00
|
|
|
|
string author = string.Empty;
|
2016-10-10 14:45:28 +00:00
|
|
|
|
|
2016-12-26 23:05:53 +00:00
|
|
|
|
// Add revision info...
|
|
|
|
|
if(logentry.Attributes != null)
|
|
|
|
|
{
|
|
|
|
|
var revinfo = log.CreateAttribute("revision");
|
|
|
|
|
revinfo.Value = revnum.ToString();
|
|
|
|
|
logentry.Attributes.SetNamedItem(revinfo);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-10 14:45:28 +00:00
|
|
|
|
foreach(XmlNode value in logentry.ChildNodes)
|
|
|
|
|
{
|
|
|
|
|
switch(value.Name)
|
|
|
|
|
{
|
|
|
|
|
case "author":
|
2016-12-27 12:12:57 +00:00
|
|
|
|
if(authorrename.ContainsKey(value.InnerText))
|
|
|
|
|
{
|
|
|
|
|
author = authorrename[value.InnerText];
|
|
|
|
|
value.InnerText = author; // save author
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
author = value.InnerText;
|
|
|
|
|
}
|
2016-10-10 14:45:28 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "date":
|
|
|
|
|
date = Convert.ToDateTime(value.InnerText);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case "msg":
|
2016-12-27 12:12:57 +00:00
|
|
|
|
message = value.InnerText.Trim(messagetrim);
|
|
|
|
|
value.InnerText = message; // also save trimmed message
|
2016-10-10 14:45:28 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-27 12:12:57 +00:00
|
|
|
|
result.Append("R" + revnum)
|
|
|
|
|
.Append(" | ")
|
|
|
|
|
.Append(commit)
|
|
|
|
|
.Append(" | ")
|
|
|
|
|
.Append(author)
|
|
|
|
|
.Append(" | ")
|
|
|
|
|
.Append(date.ToShortDateString())
|
|
|
|
|
.Append(", ")
|
|
|
|
|
.Append(date.ToShortTimeString())
|
|
|
|
|
.Append(Environment.NewLine)
|
|
|
|
|
.AppendLine(SEPARATOR)
|
|
|
|
|
.Append(message)
|
|
|
|
|
.Append(Environment.NewLine)
|
|
|
|
|
.Append(Environment.NewLine)
|
|
|
|
|
.Append(Environment.NewLine);
|
2016-12-26 23:05:53 +00:00
|
|
|
|
|
|
|
|
|
// Decrease revision number...
|
|
|
|
|
revnum--;
|
2016-10-10 14:45:28 +00:00
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-26 23:05:53 +00:00
|
|
|
|
// Save modified xml
|
|
|
|
|
log.Save(input);
|
|
|
|
|
|
2016-10-10 14:45:28 +00:00
|
|
|
|
//Save result
|
|
|
|
|
string outputpath = Path.Combine(output, "Changelog.txt");
|
|
|
|
|
File.WriteAllText(outputpath, result.ToString());
|
|
|
|
|
Console.WriteLine("Saved '" + outputpath + "'");
|
|
|
|
|
|
|
|
|
|
//All done
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
|
|
private static int Fail(string message, int exitcode)
|
|
|
|
|
{
|
|
|
|
|
Console.WriteLine(message + "\nPress any key to quit");
|
|
|
|
|
Console.ReadKey();
|
|
|
|
|
return exitcode;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|