8
n8n 中文网amn8n.com

GitHub PR 深层链接与路由验证器 (n8n + ExecuteCommand + GitHub 评论)

初级

这是一个DevOps领域的自动化工作流,包含 5 个节点。主要使用 Set, Github, Webhook, Function, ExecuteCommand 等节点。 通过自动化测试验证 GitHub PR 中的移动应用深层链接

前置要求
  • GitHub Personal Access Token
  • HTTP Webhook 端点(n8n 会自动生成)
工作流预览
可视化展示节点连接关系,支持缩放和平移
导出工作流
复制以下 JSON 配置到 n8n 导入,即可使用此工作流
{
  "id": "lasX9PkmCrv41JNs",
  "meta": {
    "instanceId": "14e4c77104722ab186539dfea5182e419aecc83d85963fe13f6de862c875ebfa",
    "templateCredsSetupCompleted": true
  },
  "name": "GitHub PR 深层链接与路由验证器 (n8n + ExecuteCommand + GitHub 评论)",
  "tags": [],
  "nodes": [
    {
      "id": "e9665b03-2487-454a-8e9d-7f91d2a2d7bd",
      "name": "GitHub PR Webhook",
      "type": "n8n-nodes-base.webhook",
      "position": [
        -440,
        20
      ],
      "webhookId": "283c3a0f-15ca-4c8d-9440-6733d37d36a0",
      "parameters": {
        "path": "validate-pr",
        "options": {},
        "httpMethod": "POST",
        "responseMode": "lastNode"
      },
      "typeVersion": 1
    },
    {
      "id": "e58f11fb-8185-4964-9bfa-2b4b5422ee3a",
      "name": "配置 - 变量",
      "type": "n8n-nodes-base.set",
      "position": [
        -240,
        20
      ],
      "parameters": {
        "values": {
          "number": [
            {
              "name": "pullRequestNumber",
              "value": 1
            }
          ],
          "string": [
            {
              "name": "repoUrl",
              "value": ""
            },
            {
              "name": "manifestPath",
              "value": "deeplink-validator-demo/AndroidManifest.xml"
            },
            {
              "name": "scriptPath",
              "value": "deeplink-validator-demo/validate-links.sh"
            },
            {
              "name": "commentMode",
              "value": "replace"
            },
            {
              "name": "timeout",
              "value": "120"
            },
            {
              "name": "githubToken",
              "value": ""
            },
            {
              "name": "branchName",
              "value": "main"
            },
            {
              "name": "repositoryFullName",
              "value": "reponame"
            }
          ]
        },
        "options": {}
      },
      "typeVersion": 1
    },
    {
      "id": "ea82f4d2-26a6-4df3-8103-eb3e346541c1",
      "name": "运行验证脚本",
      "type": "n8n-nodes-base.executeCommand",
      "position": [
        -40,
        20
      ],
      "parameters": {
        "command": "=#!/bin/sh\nrm -rf /tmp/validation\necho \"🔄 Cloning repo: {{ $json.repoUrl }}\"\ngit clone --depth 1 --branch \"{{ $json.branchName }}\" \"{{ $json.repoUrl }}\" /tmp/validation || exit 1\n\nSCRIPT_PATH=\"/tmp/validation/{{ $json.scriptPath }}\"\nMANIFEST_PATH=\"/tmp/validation/{{ $json.manifestPath }}\"\n\necho \"📁 Validating script path:\"\nls -l \"$SCRIPT_PATH\" || exit 1\n\nchmod +x \"$SCRIPT_PATH\" || exit 1\necho \"🚀 Executing: $SCRIPT_PATH $MANIFEST_PATH\"\nsh \"$SCRIPT_PATH\" \"$MANIFEST_PATH\" || {\n  echo \"❌ Script execution failed\"\n  exit 1\n}\necho \"✅ Script ran successfully\"\n"
      },
      "typeVersion": 1
    },
    {
      "id": "76521f6f-e0d3-4ccf-84ae-ecb730979b2a",
      "name": "格式化 Markdown",
      "type": "n8n-nodes-base.function",
      "position": [
        160,
        20
      ],
      "parameters": {
        "functionCode": "const lines = $node[\"Run Validation Script\"].json[\"stdout\"].split(\"\\n\");\nlet table = \"| Deep Link | Status |\\n|-----------|--------|\\n\";\nfor (const line of lines) {\n  if (!line.includes(\",\")) continue;\n  const [url, status] = line.split(\",\");\n  if (!url || !status) continue;\n  const icon = status.trim() === \"OK\" ? \"✅\" : \"❌\";\n  table += `| ${url.trim()} | ${icon} ${status.trim()} |\\n`;\n}\nreturn [{ json: { markdownResult: table } }];"
      },
      "typeVersion": 1
    },
    {
      "id": "32999f84-7453-48ba-8f5f-70251fd80335",
      "name": "GitHub",
      "type": "n8n-nodes-base.github",
      "position": [
        400,
        20
      ],
      "webhookId": "a12cc2e2-24ea-424b-8eeb-4264c4758d17",
      "parameters": {
        "body": "={{ $json.markdownResult }}",
        "owner": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('CONFIG - Variables').item.json.repositoryFullName.split(\"/\")[0] }}"
        },
        "operation": "createComment",
        "repository": {
          "__rl": true,
          "mode": "name",
          "value": "={{ $('CONFIG - Variables').item.json.repositoryFullName.split(\"/\")[1] }}"
        },
        "issueNumber": "={{ $('CONFIG - Variables').item.json.pullRequestNumber }}"
      },
      "credentials": {
        "githubApi": {
          "id": "Ryy6iiaCANDhpJC5",
          "name": "GitHub account 3"
        }
      },
      "typeVersion": 1.1
    }
  ],
  "active": false,
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "8326daf3-a1ba-49b1-a392-4b1522a7f660",
  "connections": {
    "Format Markdown": {
      "main": [
        [
          {
            "node": "GitHub",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "GitHub PR Webhook": {
      "main": [
        [
          {
            "node": "CONFIG - Variables",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "CONFIG - Variables": {
      "main": [
        [
          {
            "node": "Run Validation Script",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Run Validation Script": {
      "main": [
        [
          {
            "node": "Format Markdown",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}
常见问题

如何使用这个工作流?

复制上方的 JSON 配置代码,在您的 n8n 实例中创建新工作流并选择「从 JSON 导入」,粘贴配置后根据需要修改凭证设置即可。

这个工作流适合什么场景?

初级 - 开发运维

需要付费吗?

本工作流完全免费,您可以直接导入使用。但请注意,工作流中使用的第三方服务(如 OpenAI API)可能需要您自行付费。

工作流信息
难度等级
初级
节点数量5
分类1
节点类型5
难度说明

适合 n8n 新手,包含 1-5 个节点的简单工作流

作者
WeblineIndia

WeblineIndia

@weblineindia

A Leading Software Engineering, Consulting & Outsourcing Services Company in USA & India serving Clients Globally since 1999.

外部链接
在 n8n.io 查看

分享此工作流