Skip to content

Commit

Permalink
TODO messages
Browse files Browse the repository at this point in the history
ardacetinkaya committed Oct 13, 2024
1 parent 6a538e2 commit 79934be
Showing 5 changed files with 53 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/summarizePR.yml
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ jobs:
exit 0
fi
- name: Summarize PR action
uses: ardacetinkaya/summarize-pull-request-action/@main
uses: ardacetinkaya/summarize-pull-request-action/@ai-comment-revision
env:
PAT: ${{ secrets.ACTION_TOKEN }}
APIKey: ${{ secrets.AI_API_KEY }}
11 changes: 0 additions & 11 deletions src/Summarize.PR/Models/GithubRepositoryModels.cs
Original file line number Diff line number Diff line change
@@ -15,15 +15,4 @@ public record CommitComment
public required string PullRequestId { get; set; }
public required string RepositoryName { get; set; }
public required string RepositoryAccount { get; set; }
}

public record Settings
{
public required string PAT { get; set; }
public required string APIKey { get; set; }
public required string ModelId { get; set; }
public required string CommitSHA { get; set; }
public required string PullRequestId { get; set; }
public required string RepositoryName { get; set; }
public required string RepositoryAccount { get; set; }
}
8 changes: 8 additions & 0 deletions src/Summarize.PR/Models/PRDescriptionAnswer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Summarize.PR.Models;

public record PRDescriptionAnswer
{
public required string Comment { get; set; }

public List<string>? Todos { get; set; }
}
11 changes: 11 additions & 0 deletions src/Summarize.PR/Models/Settings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace Summarize.PR.Models;
public record Settings
{
public required string PAT { get; set; }
public required string APIKey { get; set; }
public required string ModelId { get; set; }
public required string CommitSHA { get; set; }
public required string PullRequestId { get; set; }
public required string RepositoryName { get; set; }
public required string RepositoryAccount { get; set; }
}
36 changes: 33 additions & 3 deletions src/Summarize.PR/Program.cs
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@
using Summarize.PR.Models;
using Summarize.PR.Repository;
using System.Net.Http.Headers;
using System.Text.Json;

var builder = Host.CreateApplicationBuilder(args);

@@ -90,11 +91,22 @@ Your descriptions are simple and clear so that they help developers to understan
{
Role = Microsoft.Extensions.AI.ChatRole.User,
Text = $$"""
Describe the following commit and group descriptions per file.
Describe the following commit and group descriptions per file. If there are some TODO notes in the commit
<code>
{{diff}}
</code>
Evaluate the description in this JSON format
{
"comment": "___DESCRIPTION___"
"todos": [
{ "___TODO_MESSAGE___"},
{ "___TODO_MESSAGE___" },
...etc
]
}
""",
});

@@ -107,14 +119,32 @@ Describe the following commit and group descriptions per file.
return;
}

var answer = JsonSerializer.Deserialize<PRDescriptionAnswer>(result.Message.Text);
if (answer == null)
{
Console.WriteLine("Invalid answer, summarization is skipped.");
return;
}

var commitComment = new CommitComment
{
Comment = result.Message.Text,
Comment = answer.Comment,
PullRequestId = settings.PullRequestId,
RepositoryName = settings.RepositoryName,
RepositoryAccount = settings.RepositoryAccount,
};

await repository.PostCommentAsync(commitComment);

Console.WriteLine("Commit changes are summarized.");
Console.WriteLine("Commit changes are summarized.");

if(answer.Todos!=null && answer.Todos.Count != 0)
{
Console.WriteLine("There are some TODOs in commit, issues will be created");
foreach (var todo in answer.Todos)
{
Console.WriteLine(todo);
}
//TODO: Create GitHub issue

}

0 comments on commit 79934be

Please sign in to comment.