private List <HistoryInfos> WriteRulesJsonFileHistory(SpRulesDataSet data) { _log.LogInformation($"Writing History Json File"); List <HistoryInfos> infos = new List <HistoryInfos>(); foreach (var rule in data.Rules) { var rulePaths = new RulePaths(_config, rule); var creationData = rule.Versions .Where(v => !string.IsNullOrWhiteSpace(v.IntroText) || !string.IsNullOrWhiteSpace(v.Content)) // filter out where we have no content .OrderBy(v => v.ModifiedUtc).FirstOrDefault(); var lastModifiedData = rule.Versions .Where(v => !string.IsNullOrWhiteSpace(v.IntroText) || !string.IsNullOrWhiteSpace(v.Content)) // filter out where we have no content .OrderByDescending(v => v.ModifiedUtc).FirstOrDefault(); var info = new HistoryInfos { file = rulePaths.RuleFileRelative.Replace("\\", "/"), created = creationData.ModifiedUtc, createdBy = creationData.ModifiedByDisplayName, createdByEmail = creationData.ModifiedByEmail, lastUpdated = lastModifiedData.ModifiedUtc, lastUpdatedBy = lastModifiedData.ModifiedByDisplayName, lastUpdatedByEmail = lastModifiedData.ModifiedByEmail }; infos.Add(info); } return(infos); }
private void WriteRule(RulePage rule) { var tempRule = rule.ToFrontMatter(); //Hack to make sure the redirect Urls are populated var rulePaths = new RulePaths(_config, rule); if (!Directory.Exists(rulePaths.RuleFolderFull)) { Directory.CreateDirectory(rulePaths.RuleFolderFull); } _log.LogInformation("writing file {Path}", rulePaths.RuleFileFull); if (_config.ProcessHistory) { ProcessRuleHistory(rule); } // Write final HTML Version using (var writer = new StreamWriter(rulePaths.RuleFileFull, false)) { writer.Write(rule.ToMarkdown(true)); writer.Flush(); } if (_config.ProcessHistory) { GitCommit( _config.TargetRepository, $"Extracted from Sharepoint to Git", new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow), new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow), rulePaths.RuleFileRelative); } // Write final Markdown version using (var writer = new StreamWriter(rulePaths.RuleFileFull, false)) { writer.Write(rule.ToMarkdown(false)); writer.Flush(); } if (_config.ProcessHistory) { GitCommit( _config.TargetRepository, $"Converted to Markdown", new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow), new LibGit2Sharp.Signature("SSW.Rules.SharePointExtractor", "*****@*****.**", DateTime.UtcNow), rulePaths.RuleFileRelative); } }
private void ProcessRuleHistory(RulePage rule) { var rulePaths = new RulePaths(_config, rule); bool isFirst = true; foreach (var version in rule.Versions .Where(v => !string.IsNullOrWhiteSpace(v.IntroText) || !string.IsNullOrWhiteSpace(v.Content)) // filter out where we have no content .OrderBy(v => v.ModifiedUtc)) { using (var writer = new StreamWriter(rulePaths.RuleFileFull, false)) { writer.Write(version.ToMarkdown(rule)); writer.Flush(); } var gitComment = $"{version.VersionLabel} - {version.Comment}"; // if the first version label isn't 1.0, the history was truncated by SharePoint. add comment. if (isFirst && !version.VersionLabel.StartsWith("1.0")) { gitComment = gitComment + " Note: previous versions of this content may have been deleted by SharePoint."; } var sw = new Stopwatch(); sw.Start(); GitCommit( _config.TargetRepository, gitComment, new LibGit2Sharp.Signature(version.ModifiedByName, version.ModifiedByEmail, version.ModifiedUtc), new LibGit2Sharp.Signature(version.ModifiedByName, version.ModifiedByEmail, version.ModifiedUtc), rulePaths.RuleFileRelative); sw.Stop(); _log.LogInformation($"{version.VersionLabel} committed in {sw.Elapsed.TotalMilliseconds}ms"); isFirst = false; } }