Skip to content

Add repo-level configuration for automatic CI failure follow-up #1926

Closed

Description

@propr-dev

Context

ProPR already stores monitored repository configuration with fields like name, enabled, alias, and branch settings. The new automatic CI-failure follow-up behavior must be controlled per repository and must be off by default so existing installations do not start posting or processing autonomous follow-up work after upgrade.

Requirements

  • Add a repository config boolean named autoFollowupOnFailedCi.
  • Default the field to false for existing and newly-added repositories unless explicitly enabled by an admin.
  • Persist, validate, return, and consume this field through the existing /api/config/repos flow.
  • Update CLI/API client types so repository config callers can read and write the field.
  • Add tests proving missing values default to false, true values persist, and invalid non-boolean values are rejected.

Implementation Specification

  1. Update packages/api/routes/configRepoValidation.ts so normalizeRepoConfig includes autoFollowupOnFailedCi.
  2. Add a helper in packages/core/src/daemon/configLoader.ts named isAutoCiFollowupEnabledForRepository(owner, repo) so webhook code can check the saved repo option without duplicating config parsing.
  3. Export the helper from packages/core/src/index.ts.
  4. Update packages/cli/src/api/repos.ts interfaces and request bodies.
  5. Add focused validation tests.

Acceptance Criteria

  • Existing repo configs without autoFollowupOnFailedCi are returned with false or treated as false everywhere.
  • Admin updates can set autoFollowupOnFailedCi: true for one repo without enabling it for others.
  • CLI API helpers preserve the field during add/update flows.
  • Tests cover default false, accepted true/false, and rejected invalid values.

Created by ProPR AI Planner

Activity

  1. propr-dev commented on Aug 24, 2026

    @propr-dev
    ContributorAuthor

    Suggested Implementation:

    Implementation Approach

    This implementation puts the opt-in flag on the existing monitored repository configuration because the requested behavior is repository-specific and already managed by admins through /api/config/repos. A global setting plus allowlist was considered, but that would duplicate the monitored-repo list and make the UI/CLI harder to reason about. The main trade-off is that older persisted repo records need normalization at read/write time; defaulting missing values to false keeps upgrades safe.

    File: packages/api/routes/configRepoValidation.ts

    Why this file: This is the API boundary for repository config writes. Adding the field here ensures malformed client payloads are rejected before persistence, while old records are normalized consistently.

    --- a/packages/api/routes/configRepoValidation.ts
    +++ b/packages/api/routes/configRepoValidation.ts
    @@
     export interface NormalizedRepoConfig {
       id: string;
       name: string;
       enabled: boolean;
       alias?: string;
       baseBranch?: string;
       defaultBranch?: string;
    +  autoFollowupOnFailedCi: boolean;
     }
    +
    +function normalizeOptionalBoolean(value: unknown, fieldName: string): boolean {
    +  // Keep this strict instead of accepting strings like "true" so accidental
    +  // form serialization bugs do not silently enable autonomous CI follow-up work.
    +  if (value === undefined || value === null) return false;
    +  if (typeof value === 'boolean') return value;
    +  throw new Error(`${fieldName} must be a boolean when provided`);
    +}
    @@
       return {
         id,
         name,
         enabled,
         ...(alias ? { alias } : {}),
         ...(baseBranch ? { baseBranch } : {}),
         ...(defaultBranch ? { defaultBranch } : {}),
    +    // Default missing values to false so upgrading existing repositories never
    +    // starts posting automated follow-up comments without an admin opt-in.
    +    autoFollowupOnFailedCi: normalizeOptionalBoolean(repo.autoFollowupOnFailedCi, 'autoFollowupOnFailedCi'),
       };
     }

    File: packages/core/src/daemon/configLoader.ts

    Why this file: Webhook handling lives in core, but repository configuration is already loaded through the daemon config layer. This helper gives CI webhook code one narrow API for checking whether a repo opted in.

    --- a/packages/core/src/daemon/configLoader.ts
    +++ b/packages/core/src/daemon/configLoader.ts
    @@
     export async function isMonitoredRepository(owner: string, repo: string): Promise<boolean> {
       // existing implementation
     }
    +
    +export async function isAutoCiFollowupEnabledForRepository(owner: string, repo: string): Promise<boolean> {
    +  const target = `${owner}/${repo}`.toLowerCase();
    +  const repos = await loadReposFromConfig();
    +
    +  return repos.some((entry) => {
    +    // Support both legacy string entries and normalized object entries because
    +    // older config paths may still hydrate repository names without metadata.
    +    if (typeof entry === 'string') return false;
    +
    +    const name = typeof entry.name === 'string' ? entry.name.toLowerCase() : '';
    +    if (name !== target) return false;
    +
    +    // Disabled repositories must not produce autonomous follow-up work even if
    +    // the field remains true in persisted config for a future re-enable.
    +    if (entry.enabled === false) return false;
    +
    +    return entry.autoFollowupOnFailedCi === true;
    +  });
    +}

    File: packages/core/src/index.ts

    Why this file: Other packages import core behavior through the barrel. Exporting the helper keeps the check-run implementation and tests aligned with the public core surface.

    --- a/packages/core/src/index.ts
    +++ b/packages/core/src/index.ts
    @@
         getRepos,
         isMonitoredRepository,
    +    isAutoCiFollowupEnabledForRepository,
         resolveMonitoredRepositories,

    File: packages/cli/src/api/repos.ts

    Why this file: The CLI repository client owns the typed request/response contract for repo config. Without this update, CLI callers would drop the new field during updates.

    --- a/packages/cli/src/api/repos.ts
    +++ b/packages/cli/src/api/repos.ts
    @@
     export interface MonitoredRepo {
    @@
       baseBranch?: string;
    +
    +  /**
    +   * Enables ProPR to post and process a system follow-up comment when CI fails.
    +   * Defaults to false so existing repositories do not opt into autonomous work.
    +   */
    +  autoFollowupOnFailedCi?: boolean;
     }
    @@
     export interface AddRepoOptions {
    @@
       enabled?: boolean;
    +
    +  /**
    +   * Explicit admin opt-in for automatic CI failure follow-up comments.
    +   */
    +  autoFollowupOnFailedCi?: boolean;
     }
    @@
     export interface UpdateRepoOptions {
    @@
       enabled?: boolean;
    +
    +  /**
    +   * Explicitly enable or disable automatic CI failure follow-up for this repo.
    +   */
    +  autoFollowupOnFailedCi?: boolean;
     }
    @@
       const newRepo: MonitoredRepo = {
         id: crypto.randomUUID(),
         name: fullName,
         enabled: options.enabled ?? true,
         alias: options.alias?.trim() || undefined,
         baseBranch: options.baseBranch?.trim() || undefined,
    +    // New repositories stay opted out unless an admin deliberately passes true.
    +    autoFollowupOnFailedCi: options.autoFollowupOnFailedCi ?? false,
       };
    @@
         ...(updates.enabled !== undefined && { enabled: updates.enabled }),
         ...(updates.alias !== undefined && { alias: updates.alias?.trim() || undefined }),
         ...(updates.baseBranch !== undefined && { baseBranch: updates.baseBranch?.trim() || undefined }),
    +    // Preserve the field unless the caller explicitly changes it; this avoids
    +    // unrelated repo edits accidentally disabling an admin's opt-in.
    +    ...(updates.autoFollowupOnFailedCi !== undefined && { autoFollowupOnFailedCi: updates.autoFollowupOnFailedCi }),
       };

    File: test/configRepoValidation.test.ts (new file)

    Why this file: This test locks the upgrade-safe default and strict boolean validation so future config changes cannot accidentally make the feature opt-out.

    import assert from 'node:assert/strict';
    import { test } from 'node:test';
    import { normalizeRepoConfig } from '../packages/api/routes/configRepoValidation.js';
    
    test('repository config defaults automatic CI follow-up off', () => {
      const normalized = normalizeRepoConfig({
        id: 'repo-1',
        name: 'owner/repo',
        enabled: true,
      });
    
      assert.equal(normalized.autoFollowupOnFailedCi, false);
    });
    
    test('repository config preserves explicit automatic CI follow-up opt-in', () => {
      const normalized = normalizeRepoConfig({
        id: 'repo-1',
        name: 'owner/repo',
        enabled: true,
        autoFollowupOnFailedCi: true,
      });
    
      assert.equal(normalized.autoFollowupOnFailedCi, true);
    });
    
    test('repository config rejects non-boolean automatic CI follow-up values', () => {
      assert.throws(
        () => normalizeRepoConfig({
          id: 'repo-1',
          name: 'owner/repo',
          enabled: true,
          // Use an invalid string here because browser/API serialization mistakes
          // are the most likely way this field could become unsafe.
          autoFollowupOnFailedCi: 'true',
        }),
        /autoFollowupOnFailedCi must be a boolean/,
      );
    });
  2. propr-dev commented on Aug 24, 2026

    @propr-dev
    ContributorAuthor

    🤖 AI processing has started for this issue using codex agent with gpt-5.6-sol model.

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

    Processing Details:

    • Agent: codex
    • Model: gpt-5.6-sol
    • Branch: 1926/gpt-5.6-sol-add-repo-level-configurat-20260824-0813-3t5
    • Base Branch: 1926-epic-automatic-ci-vn4
    • Worktree: issue-1926-20260824-0813-gpt-5.6-sol-3t5

    🔍 Track Task Execution

  3. added a commit that references this issue on Aug 24, 2026
  4. added a commit that references this issue on Aug 24, 2026
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