Skip to main content
Glama

优先级升级

gitea_workflow_escalate_priority

Automatically escalate priority for aged issues in Gitea repositories based on predefined time thresholds, ensuring timely attention to pending tasks and security concerns.

Instructions

Automatically escalate priority for aged issues. P3→P2 after 30 days, P2→P1 after 14 days, P1→P0 after 3 days. Security issues are always P0.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ownerNoRepository owner. Uses context if not provided
repoNoRepository name. Uses context if not provided
dry_runNoPreview changes without applying (default: false)

Implementation Reference

  • Core handler function implementing the tool logic. Scans open issues, checks age and type against escalation rules (P3-30d->P2, P2-14d->P1, P1-3d->P0, security->P0), updates labels accordingly (dry-run option).
    export async function workflowEscalatePriority(
      ctx: WorkflowToolsContext,
      args: {
        owner?: string;
        repo?: string;
        config?: WorkflowConfig;
        dry_run?: boolean;
      }
    ): Promise<{
      success: boolean;
      escalated: Array<{
        number: number;
        title: string;
        from_priority: string;
        to_priority: string;
        reason: string;
      }>;
      error?: string;
    }> {
      logger.debug({ args: { ...args, config: args.config ? '[provided]' : undefined } }, 'Escalating priorities');
    
      const { owner, repo } = ctx.contextManager.resolveOwnerRepo(args.owner, args.repo);
      const dryRun = args.dry_run ?? false;
    
      // 获取配置
      let config = args.config;
      if (!config) {
        const loadResult = await workflowLoadConfig(ctx, { owner, repo });
        if (!loadResult.success || !loadResult.config) {
          return {
            success: false,
            escalated: [],
            error: loadResult.error || '无法加载配置',
          };
        }
        config = loadResult.config;
      }
    
      const prefixes = getLabelPrefixes(config);
    
      const escalated: Array<{
        number: number;
        title: string;
        from_priority: string;
        to_priority: string;
        reason: string;
      }> = [];
    
      try {
        // 获取开放的 Issue
        const issues = await ctx.client.get<Issue[]>(`/repos/${owner}/${repo}/issues?state=open&limit=100`);
    
        // 获取标签 ID 映射
        const repoLabels = await ctx.client.get<Array<{ id: number; name: string }>>(
          `/repos/${owner}/${repo}/labels`
        );
        const labelIdMap = new Map(repoLabels.map((l) => [l.name, l.id]));
        const idToLabelMap = new Map(repoLabels.map((l) => [l.id, l.name]));
    
        // 定义升级映射
        const upgradeMap: Record<string, { days: number; to: string }> = {
          P3: { days: 30, to: 'P2' },
          P2: { days: 14, to: 'P1' },
          P1: { days: 3, to: 'P0' },
        };
    
        for (const issue of issues) {
          const currentPriority = getIssuePriority(issue, prefixes);
          const issueTypeLabel = issue.labels.find((l) => matchLabel(prefixes.type, l.name) !== null);
          const issueType = issueTypeLabel ? matchLabel(prefixes.type, issueTypeLabel.name) : null;
          const ageDays = calculateIssueAgeDays(issue);
    
          let newPriority: string | null = null;
          let reason = '';
    
          // 安全问题强制 P0
          if (issueType === 'security' && currentPriority !== 'P0') {
            newPriority = 'P0';
            reason = '安全问题自动升级为紧急';
          } else if (currentPriority && upgradeMap[currentPriority]) {
            const upgrade = upgradeMap[currentPriority];
            if (ageDays > upgrade.days) {
              newPriority = upgrade.to;
              reason = `超过 ${upgrade.days} 天未解决`;
            }
          }
    
          if (newPriority && currentPriority) {
            if (!dryRun) {
              // 移除旧优先级标签
              const oldLabelId = labelIdMap.get(buildLabel(prefixes.priority, currentPriority));
              if (oldLabelId) {
                try {
                  await ctx.client.delete(
                    `/repos/${owner}/${repo}/issues/${issue.number}/labels/${oldLabelId}`
                  );
                } catch {
                  // 忽略删除失败
                }
              }
    
              // 添加新优先级标签
              const newLabelId = labelIdMap.get(buildLabel(prefixes.priority, newPriority));
              if (newLabelId) {
                await ctx.client.post(`/repos/${owner}/${repo}/issues/${issue.number}/labels`, {
                  labels: [newLabelId],
                });
              }
            }
    
            escalated.push({
              number: issue.number,
              title: issue.title,
              from_priority: currentPriority,
              to_priority: newPriority,
              reason,
            });
          }
        }
    
        logger.info({ owner, repo, escalated: escalated.length, dry_run: dryRun }, 'Priorities escalated');
    
        return {
          success: true,
          escalated,
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        logger.error({ owner, repo, error: errorMessage }, 'Failed to escalate priorities');
    
        return {
          success: false,
          escalated: [],
          error: errorMessage,
        };
      }
    }
  • MCP tool registration including name, title, description, input schema (Zod), and wrapper handler calling the core workflowEscalatePriority function.
    mcpServer.registerTool(
      'gitea_workflow_escalate_priority',
      {
        title: '优先级升级',
        description:
          'Automatically escalate priority for aged issues. P3→P2 after 30 days, P2→P1 after 14 days, P1→P0 after 3 days. Security issues are always P0.',
        inputSchema: z.object({
          owner: z.string().optional().describe('Repository owner. Uses context if not provided'),
          repo: z.string().optional().describe('Repository name. Uses context if not provided'),
          dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'),
        }),
      },
      async (args) => {
        try {
          const result = await WorkflowTools.workflowEscalatePriority(
            { client: ctx.client, contextManager: ctx.contextManager },
            args
          );
          return {
            content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }],
            isError: !result.success,
          };
        } catch (error: unknown) {
          const errorMessage = error instanceof Error ? error.message : String(error);
          return {
            content: [{ type: 'text' as const, text: `Error: ${errorMessage}` }],
            isError: true,
          };
        }
      }
    );
  • Zod input schema defining parameters: owner/repo (optional), dry_run (boolean optional).
    inputSchema: z.object({
      owner: z.string().optional().describe('Repository owner. Uses context if not provided'),
      repo: z.string().optional().describe('Repository name. Uses context if not provided'),
      dry_run: z.boolean().optional().describe('Preview changes without applying (default: false)'),
    }),
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries the full burden. It discloses key behavioral traits: the tool performs automatic priority escalation with specific time-based rules and special handling for security issues. However, it lacks details on permissions needed, rate limits, or error handling, which are important for a mutation tool. No contradiction with annotations exists.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is front-loaded and concise, with two sentences that efficiently convey the core functionality and special case (security issues). Every sentence adds value without redundancy, making it easy for an agent to grasp the tool's behavior quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (automated mutation with rules) and lack of annotations or output schema, the description is mostly complete: it explains what the tool does and its rules. However, it misses details like return values, error conditions, or confirmation of changes, which could aid the agent in handling responses. It compensates well but has minor gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents all parameters (owner, repo, dry_run). The description does not add meaning beyond the schema, such as explaining how 'dry_run' interacts with the escalation rules or clarifying context usage. Baseline 3 is appropriate as the schema handles parameter documentation adequately.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('escalate priority') and resources ('aged issues'), including detailed escalation rules (P3→P2 after 30 days, etc.). It distinguishes itself from sibling tools like 'gitea_workflow_check_issues' or 'gitea_issue_create' by focusing on automated priority escalation rather than checking, creating, or reporting on issues.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for automatically handling aged issues based on time thresholds and security concerns, but it does not explicitly state when to use this tool versus alternatives (e.g., 'gitea_workflow_check_issues' for monitoring or 'gitea_issue_create' for manual updates). No exclusions or prerequisites are mentioned, leaving some ambiguity in context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SupenBysz/gitea-mcp-tool'

If you have feedback or need assistance with the MCP directory API, please join our Discord server