Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

1.1 KB
Raw Blame
import type { ShellWorkScanner } from './types';

/**
 * github issue/PR Works from `gh issue|pr create/edit` runs — plus, when the
 * scan carries pull request linking, numbered `gh pr ready|merge` runs. Parsing reuses
 * the github skill's gh-CLI normalizer (via
 * `workModel.registerShellGithubResult` → `normalizeGithubShellToolResult`),
 * so identity lands on the same `owner/repo#number` Work row as
 * skill-registered versions.
 */
export const githubShellWorkScanner: ShellWorkScanner = {
  matches: (command) => command.includes('gh '),
  name: 'github',
  register: async ({ pullRequestLinking, transcript: _transcript, workModel, ...input }) => {
    if (!pullRequestLinking) return workModel.registerShellGithubResult(input);

    // A bare `gh pr ready|merge <n>` names no repository; the topic's own
    // pull requests are the only safe place to look it up.
    const needsTopic = /\bgh\s+pr\s+(?:ready|merge)\b/.test(input.data.command);
    return workModel.registerShellGithubResult(input, {
      pullRequestLifecycle: true,
      topicPullRequests: needsTopic ? await pullRequestLinking.listTopicPullRequestIds() : [],
    });
  },
};