Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion csharp/Platform.Bot/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ private static async Task<int> Main(string[] args)
var dbContext = new FileStorage(databaseFilePath?.FullName ?? new TemporaryFile().Filename);
Console.WriteLine($"Bot has been started. {Environment.NewLine}Press CTRL+C to close");
var githubStorage = new GitHubStorage(githubUserName, githubApiToken, githubApplicationName);
var issueTracker = new IssueTracker(githubStorage, new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage));
var issueTracker = new IssueTracker(githubStorage, new HelloWorldTrigger(githubStorage, dbContext, fileSetName), new OrganizationLastMonthActivityTrigger(githubStorage), new LastCommitActivityTrigger(githubStorage), new RubberDuckTrigger(githubStorage), new RubberDuckDialogTrigger(githubStorage), new AdminAuthorIssueTriggerDecorator(new ProtectDefaultBranchTrigger(githubStorage), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationRepositoriesDefaultBranchTrigger(githubStorage, dbContext), githubStorage), new AdminAuthorIssueTriggerDecorator(new ChangeOrganizationPullRequestsBaseBranchTrigger(githubStorage, dbContext), githubStorage));
var pullRequenstTracker = new PullRequestTracker(githubStorage, new MergeDependabotBumpsTrigger(githubStorage));
var timestampTracker = new DateTimeTracker(githubStorage, new CreateAndSaveOrganizationRepositoriesMigrationTrigger(githubStorage, dbContext, Path.Combine(Directory.GetCurrentDirectory(), "/github-migrations")));
var cancellation = new CancellationTokenSource();
Expand Down
106 changes: 106 additions & 0 deletions csharp/Platform.Bot/Triggers/RubberDuckDialogTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
using System;
using System.Threading.Tasks;
using Interfaces;
using Octokit;
using Storage.Remote.GitHub;

namespace Platform.Bot.Triggers
{
using TContext = Issue;
/// <summary>
/// <para>
/// Represents the rubber duck debugging dialog continuation trigger.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="ITrigger{TContext}"/>
internal class RubberDuckDialogTrigger : ITrigger<TContext>
{
private readonly GitHubStorage _storage;

/// <summary>
/// <para>
/// Initializes a new <see cref="RubberDuckDialogTrigger"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="storage">
/// <para>A git hub api.</para>
/// <para></para>
/// </param>
public RubberDuckDialogTrigger(GitHubStorage storage)
{
this._storage = storage;
}

/// <summary>
/// <para>
/// Actions the context.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
public async Task Action(TContext context)
{
var debuggingGuide = $@"🦆 **Great! Let's debug together!**

I'm your rubber duck debugging assistant. Please follow these steps:

## Step 1: Describe Your Problem
Please tell me:
- **What are you trying to do?**
- **What is happening instead?**
- **What error messages (if any) are you seeing?**

## Step 2: Show Me The Code
- Share the relevant code snippet
- Include any error messages or unexpected output

## Step 3: Recent Changes
- **What was the last thing you changed before this problem appeared?**
- Have you tried undoing recent changes?

## Step 4: Let's Think Through This Together
I'll help you by asking questions like:
- What assumptions are you making about the code?
- Can you trace through the code line by line?
- Have you checked the most obvious things first?

## Step 5: Problem-Solving Techniques
We can try:
- Adding debug logging/print statements
- Testing with simpler inputs
- Checking documentation
- Looking for similar examples

**🎯 Often, just explaining your problem step-by-step to me will help you spot the issue!**

Go ahead and describe your problem in detail. I'm listening! 👂";

await _storage.CreateIssueComment(context.Repository.Id, context.Number, debuggingGuide);
}

/// <summary>
/// <para>
/// Determines whether this instance condition.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>The bool</para>
/// <para></para>
/// </returns>
public async Task<bool> Condition(TContext context)
{
var title = context.Title.ToLower().Trim();
return title == "yes" || title == "да";
}
}
}
102 changes: 102 additions & 0 deletions csharp/Platform.Bot/Triggers/RubberDuckTrigger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
using System;
using System.Threading.Tasks;
using Interfaces;
using Octokit;
using Storage.Remote.GitHub;

namespace Platform.Bot.Triggers
{
using TContext = Issue;
/// <summary>
/// <para>
/// Represents the rubber duck debugging trigger.
/// </para>
/// <para></para>
/// </summary>
/// <seealso cref="ITrigger{TContext}"/>
internal class RubberDuckTrigger : ITrigger<TContext>
{
private readonly GitHubStorage _storage;

/// <summary>
/// <para>
/// Initializes a new <see cref="RubberDuckTrigger"/> instance.
/// </para>
/// <para></para>
/// </summary>
/// <param name="storage">
/// <para>A git hub api.</para>
/// <para></para>
/// </param>
public RubberDuckTrigger(GitHubStorage storage)
{
this._storage = storage;
}

/// <summary>
/// <para>
/// Actions the context.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
public async Task Action(TContext context)
{
var openerQuestion = $@"🦆 **Rubber Duck Debugging Assistant**

Do you have problem with code?
У вас проблема с кодом?

**Instructions:**
- Reply with **""Yes""** or **""Да""** to start debugging session
- I'll guide you through the problem-solving process step by step
- Explaining your problem to me (the rubber duck) often helps you find the solution yourself!

**Common debugging steps I can help with:**
1. Understanding the problem clearly
2. Breaking down the problem into smaller parts
3. Checking assumptions
4. Reviewing recent changes
5. Testing hypotheses
6. Finding similar examples

Ready to debug? 🐛➡️✨";

await _storage.CreateIssueComment(context.Repository.Id, context.Number, openerQuestion);
}

/// <summary>
/// <para>
/// Determines whether this instance condition.
/// </para>
/// <para></para>
/// </summary>
/// <param name="context">
/// <para>The context.</para>
/// <para></para>
/// </param>
/// <returns>
/// <para>The bool</para>
/// <para></para>
/// </returns>
public async Task<bool> Condition(TContext context)
{
var title = context.Title.ToLower().Trim();
var triggerWords = new[]
{
"help",
"help me",
"sos",
"помощь",
"помогите",
"помогите мне",
"спасите"
};

return Array.Exists(triggerWords, trigger => title == trigger);
}
}
}
Loading