Skip to content

Feat: Monitor PR comments for follow-up tasks #40

Closed

Description

@integry

General Goal

This is the first stage of implementing a new feature that allows GitFix to handle follow-up changes requested in the comments of open Pull Requests. This issue focuses on updating the daemon to watch for these comments and enqueue new jobs for the worker.

Task Description

The daemon.js script needs to be updated to poll for comments on open PRs in the monitored repositories. When a comment matches specific criteria, a new task should be added to the queue for a worker to process.

Implementation Steps

  1. Update src/daemon.js:

    • Create a new function, pollForPullRequestComments, that will be called within the main polling loop.
    • This function should:
      1. Fetch all open pull requests for the monitored repositories.
      2. For each pull request, fetch its comments.
      3. Filter the comments based on the following criteria:
        • The comment body must include the string !gitfix.
        • The author of the comment should not be the bot itself.
        • The author should be checked against a whitelist and not be on a blacklist.
  2. Add New Environment Variables:

    • Introduce the following new variables in the .env.example and README.md files:
      • GITHUB_BOT_USERNAME: The GitHub username of the bot, to ignore its own comments.
      • GITHUB_USER_WHITELIST: A comma-separated list of GitHub usernames that are allowed to trigger follow-up tasks. If empty, all users are allowed.
      • GITHUB_USER_BLACKLIST: A comma-separated list of GitHub usernames that are not allowed to trigger follow-up tasks.
  3. Enqueue New Job Type:

    • When a valid comment is detected, a new job of type processPullRequestComment should be added to the BullMQ.
    • The job data should contain all the necessary information for the worker, including:
      • pullRequestNumber
      • commentBody
      • commentAuthor
      • repoOwner
      • repoName
      • branchName (from the PR's head ref)
      • The target LLM (e.g., 'opus', 'sonnet', parsed from !gitfix:opus).

Acceptance Criteria

  • The daemon successfully identifies comments with !gitfix.
  • The daemon correctly filters comments based on the author, whitelist, and blacklist.
  • A new processPullRequestComment job is created in the queue with the correct data for each valid comment.
  • The system remains stable and continues to process new issues as before.

Next Steps

The next issue will cover the implementation of the worker to process these new processPullRequestComment jobs.

Activity

  1. integry commented on Jul 21, 2025

    @integry
    OwnerAuthor

    Suggested Implementation for `src/daemon.js`

    Here is a suggested implementation for the changes in `src/daemon.js`. This code introduces a new function to poll for PR comments and adds it to the main loop.

    // src/daemon.js
    
    // ... existing imports
    
    // New environment variables
    const GITHUB_BOT_USERNAME = process.env.GITHUB_BOT_USERNAME;
    const GITHUB_USER_WHITELIST = (process.env.GITHUB_USER_WHITELIST || '').split(',').filter(u => u);
    const GITHUB_USER_BLACKLIST = (process.env.GITHUB_USER_BLACKLIST || '').split(',').filter(u => u);
    
    // ... existing code
    
    /**
     * Fetches and processes comments on open pull requests for a repository
     * @param {import('@octokit/core').Octokit} octokit - Authenticated Octokit instance
     * @param {string} repoFullName - Repository in format \"owner/repo\"
     * @param {string} correlationId - Correlation ID for tracking
     */
    async function pollForPullRequestComments(octokit, repoFullName, correlationId) {
        const correlatedLogger = logger.withCorrelation(correlationId);
        const [owner, repo] = repoFullName.split('/');
    
        try {
            const prs = await octokit.request('GET /repos/{owner}/{repo}/pulls', {
                owner,
                repo,
                state: 'open',
                per_page: 100,
            });
    
            for (const pr of prs.data) {
                const comments = await octokit.request('GET /repos/{owner}/{repo}/issues/{issue_number}/comments', {
                    owner,
                    repo,
                    issue_number: pr.number,
                });
    
                for (const comment of comments.data) {
                    const commentAuthor = comment.user.login;
                    if (comment.body && comment.body.includes('!gitfix')) {
                        // 1. Check if author is the bot
                        if (GITHUB_BOT_USERNAME && commentAuthor === GITHUB_BOT_USERNAME) {
                            continue;
                        }
    
                        // 2. Check blacklist
                        if (GITHUB_USER_BLACKLIST.length > 0 && GITHUB_USER_BLACKLIST.includes(commentAuthor)) {
                            continue;
                        }
    
                        // 3. Check whitelist
                        if (GITHUB_USER_WHITELIST.length > 0 && !GITHUB_USER_WHITELIST.includes(commentAuthor)) {
                            continue;
                        }
    
                        const llmMatch = comment.body.match(/!gitfix:(\w+)/);
                        const llm = llmMatch ? llmMatch[1] : null;
    
                        const jobData = {
                            pullRequestNumber: pr.number,
                            commentId: comment.id,
                            commentBody: comment.body,
                            commentAuthor,
                            repoOwner: owner,
                            repoName: repo,
                            branchName: pr.head.ref,
                            llm,
                            correlationId: generateCorrelationId(),
                        };
    
                        const jobId = `pr-comment-${owner}-${repo}-${pr.number}-${comment.id}`;
    
                        try {
                            await issueQueue.add('processPullRequestComment', jobData, { jobId });
                            correlatedLogger.info({
                                jobId,
                                pullRequestNumber: pr.number,
                                commentId: comment.id,
                            }, 'Successfully added PR comment to processing queue');
                        } catch (error) {
                            if (error.message?.includes('Job already exists')) {
                                correlatedLogger.debug({
                                    pullRequestNumber: pr.number,
                                    commentId: comment.id,
                                }, 'PR comment job already in queue, skipping');
                            } else {
                                handleError(error, `Failed to add PR comment ${comment.id} to queue`, { correlationId });
                            }
                        }
                    }
                }
            }
        } catch (error) {
            handleError(error, `Error polling PR comments for repository \${repoFullName}`, { correlationId });
        }
    }
    
    
    // In the main pollForIssues function, we'll call this new function
    async function pollForIssues() {
        // ... existing pollForIssues logic ...
    
        for (const repoFullName of repos) {
            // ... existing logic to fetch issues ...
    
            // Add the new call to poll for comments
            await pollForPullRequestComments(octokit, repoFullName, correlationId);
        }
    
        // ... rest of the function
    }
  2. Repository owner deleted a comment from propr-dev on Jul 21, 2025
  3. Repository owner deleted a comment from propr-dev on Jul 21, 2025
  4. propr-dev commented on Jul 21, 2025

    @propr-dev
    Contributor

    🤖 AI processing has started for this issue using opus model.

    I'll analyze the problem and work on a solution. This may take a few minutes.

    Processing Details:

    • Model: opus
    • Branch: ai-fix/40-feat-monitor-pr-comments--20250722-0134-opus-vjb
    • Base Branch: main
    • Worktree: issue-40-20250722-0134-opus-vjb
  5. added a commit that references this issue on Jul 21, 2025
  6. added a commit that references this issue on Jul 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions