Skip to content

Commit

Permalink
feat: complete changelog generation - AI stage
Browse files Browse the repository at this point in the history
  • Loading branch information
mhrstv committed Feb 19, 2025
1 parent 5c7420f commit 466f602
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 37 deletions.
31 changes: 17 additions & 14 deletions Kodify/AutoDoc/Services/Documentation/ChangelogGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ public void GenerateChangelog(string projectPath)
{
writer.WriteLine("# Changelog");
writer.WriteLine();
writer.WriteLine("This changelog aims to highlight user-impactful changes with references to issues/PRs where available.");
writer.WriteLine();

var repoPath = LibGit2Sharp.Repository.Discover(projectPath);
if (repoPath == null)
Expand Down Expand Up @@ -131,7 +129,7 @@ public void GenerateChangelog(string projectPath)
}
}

public async Task GenerateChangelog(IAIService aiService)
public async Task GenerateChangelogAsync(IAIService aiService)
{
// Determine the project root.
var projectPath = _gitService.DetectProjectRoot();
Expand Down Expand Up @@ -234,20 +232,25 @@ private void WriteCommitDetails(TextWriter writer, Commit commit)
var messageParts = commit.Message.Split(new[] { '\n' }, 2);
var subject = ReplaceIssueReferences(messageParts[0].Trim());
var body = messageParts.Length > 1 ? ReplaceIssueReferences(messageParts[1].Trim()) : null;

writer.WriteLine($"- **{subject}**");
writer.WriteLine($" *Commit: {commit.Sha.Substring(0, 7)} | Date: {commit.Committer.When:yyyy-MM-dd} | Author: {commit.Author.Name}*");


// Write the subject line with a forced markdown line break (using two trailing spaces)
writer.WriteLine($"- **{subject}** ");

// Write the commit details (shortened SHA, date, author) with a forced line break
writer.WriteLine($" *Commit: {commit.Sha.Substring(0, 7)} | Date: {commit.Committer.When:yyyy-MM-dd} | Author: {commit.Author.Name}* ");

// If there is extra commit message body, join the lines and output it on a new line
if (!string.IsNullOrWhiteSpace(body))
{
writer.WriteLine();
writer.WriteLine(" ```");
foreach (var line in body.Split('\n'))
{
writer.WriteLine($" {line.Trim()}");
}
writer.WriteLine(" ```");
var shortBody = string.Join(" ",
body.Split('\n')
.Select(line => line.Trim())
.Where(line => !string.IsNullOrWhiteSpace(line))
);
writer.WriteLine($"{shortBody}");
}

// A blank line to separate commit items
writer.WriteLine();
}

Expand Down
19 changes: 12 additions & 7 deletions Kodify/AutoDoc/Services/Documentation/MarkdownGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,18 @@ public class MarkdownGenerator
private readonly ReadmeGenerator _readmeGenerator;
private readonly ChangelogGenerator _changelogGenerator;

public MarkdownGenerator(OpenAIService aiService)
// Parameterless constructor overload.
public MarkdownGenerator() : this(null)
{
var contentBuilder = new ContentBuilder();
var gitRepositoryService = new GitRepositoryService();
_readmeGenerator = new ReadmeGenerator();
_changelogGenerator = new ChangelogGenerator();
}

_readmeGenerator = new ReadmeGenerator(aiService, contentBuilder, gitRepositoryService);
_changelogGenerator = new ChangelogGenerator(gitRepositoryService);
// Constructor with AI service implemented
public MarkdownGenerator(IAIService aiService)
{
_readmeGenerator = new ReadmeGenerator(aiService);
_changelogGenerator = new ChangelogGenerator();
}

public async Task GenerateReadMe(ProjectInfo projectInfo, string projectName, string projectSummary, string usageInstructions, string template = null)

Check warning on line 31 in Kodify/AutoDoc/Services/Documentation/MarkdownGenerator.cs

View workflow job for this annotation

GitHub Actions / Build, Test & Package

Cannot convert null literal to non-nullable reference type.
Expand All @@ -38,9 +43,9 @@ public void GenerateChangelog(string projectPath)
_changelogGenerator.GenerateChangelog(projectPath);
}

public async void GenerateChangelog(IAIService aiService)
public async Task GenerateChangelogAsync(IAIService aiService)
{
await _changelogGenerator.GenerateChangelog(aiService);
await _changelogGenerator.GenerateChangelogAsync(aiService);
}
}
}
54 changes: 38 additions & 16 deletions Kodify/AutoDoc/Services/Documentation/ReadmeGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,23 @@ namespace Kodify.AutoDoc.Services.Documentation
{
public class ReadmeGenerator
{
private readonly OpenAIService _aiService;
private readonly IAIService _aiService;
private readonly ContentBuilder _contentBuilder;
private readonly GitRepositoryService _gitService;

// New constructor that only requires the OpenAIService.
public ReadmeGenerator(OpenAIService aiService)
// Parameterless constructor overload.
public ReadmeGenerator() : this(null, new ContentBuilder(), new GitRepositoryService())
{
}

// Constructor with AI service implemented
public ReadmeGenerator(IAIService aiService)
: this(aiService, new ContentBuilder(), new GitRepositoryService())
{
}

// Constructor that allows explicit dependency injection.
public ReadmeGenerator(OpenAIService aiService, ContentBuilder contentBuilder, GitRepositoryService gitService)
public ReadmeGenerator(IAIService aiService, ContentBuilder contentBuilder, GitRepositoryService gitService)
{
_aiService = aiService;
_contentBuilder = contentBuilder;
Expand All @@ -37,22 +42,39 @@ public async Task GenerateReadMe(ProjectInfo projectInfo, string projectName, st
using (var writer = new StreamWriter(outputPath))
{
string finalContent;
if (!string.IsNullOrEmpty(template))
if (_aiService == null)
{
// Build manual content and then enhance it using the AI service.
var readmeContent = _contentBuilder.BuildManualContent(projectInfo, projectName, projectSummary, usageInstructions);
finalContent = await _aiService.EnhanceDocumentationAsync(template, readmeContent);
// If no AI service is available, then simply use the generated content.
if (!string.IsNullOrEmpty(template))
{
// Build manual content from the content builder
var readmeContent = _contentBuilder.BuildManualContent(projectInfo, projectName, projectSummary, usageInstructions);
finalContent = string.Join("\n", readmeContent);
}
else
{
finalContent = _contentBuilder.BuildStructuredContent(projectInfo);
}
}
else
{
// Build structured content and generate documentation from it.
var structuredContent = _contentBuilder.BuildStructuredContent(projectInfo);
finalContent = await _aiService.GenerateDocumentationAsync(
projectName,
projectSummary,
usageInstructions,
structuredContent,
projectInfo.HasWebApi, projectInfo.License);
if (!string.IsNullOrEmpty(template))
{
// Build manual content and then enhance it using the AI service.
var readmeContent = _contentBuilder.BuildManualContent(projectInfo, projectName, projectSummary, usageInstructions);
finalContent = await _aiService.EnhanceDocumentationAsync(template, readmeContent);
}
else
{
// Build structured content and generate documentation from it via the AI service.
var structuredContent = _contentBuilder.BuildStructuredContent(projectInfo);
finalContent = await _aiService.GenerateDocumentationAsync(
projectName,
projectSummary,
usageInstructions,
structuredContent,
projectInfo.HasWebApi, projectInfo.License);
}
}
await writer.WriteLineAsync(finalContent);
}
Expand Down

0 comments on commit 466f602

Please sign in to comment.