Sync Jira issues with subsequent comments to Notion database

工作流概述

这是一个包含10个节点的复杂工作流,主要用于自动化处理各种任务。

工作流源代码

下载
{
  "id": "YCQFaJdmJc6Rx4o7",
  "meta": {
    "instanceId": "0c0787ab1a9ebbb0967650f7b4012417acdd61c2fa7c9e119981847e2fc8b09c"
  },
  "name": "Sync Jira issues with subsequent comments to Notion database",
  "tags": [
    {
      "id": "24",
      "name": "n8n team",
      "createdAt": "2023-02-28T11:17:04.513Z",
      "updatedAt": "2023-02-28T11:17:04.513Z"
    }
  ],
  "nodes": [
    {
      "id": "3f36dc12-5011-4786-aa21-f20ba72944df",
      "name": "Create database page",
      "type": "n8n-nodes-base.notion",
      "position": [
        460,
        460
      ],
      "parameters": {
        "title": "={{$node[\"On issues created/updated/deleted\"].json[\"issue\"][\"fields\"][\"summary\"]}}",
        "options": {},
        "resource": "databasePage",
        "databaseId": "e3503d88-accb-4ddb-aa45-f962cb03e729",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Issue Key|rich_text",
              "textContent": "={{$node[\"On issues created/updated/deleted\"].json[\"issue\"][\"key\"]}}"
            },
            {
              "key": "Issue ID|number",
              "numberValue": "={{parseInt($node[\"On issues created/updated/deleted\"].json[\"issue\"][\"id\"])}}"
            },
            {
              "key": "Link|url",
              "urlValue": "=https://n8n-io.atlassian.net/browse/{{$node[\"On issues created/updated/deleted\"].json[\"issue\"][\"key\"]}}",
              "ignoreIfEmpty": true
            },
            {
              "key": "Status|select",
              "selectValue": "={{$node[\"Lookup table\"].json[\"Status ID\"]}}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "XNjSmr171NUO17TK",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "2d13b713-dd3d-48aa-a550-fe8db1e7aafd",
      "name": "Note",
      "type": "n8n-nodes-base.stickyNote",
      "position": [
        660,
        460
      ],
      "parameters": {
        "width": 232.65822784810126,
        "height": 137.9746835443038,
        "content": "### `IF` & `Switch` nodes
These conditional nodes (`IF` and `Switch`) determine which Notion [**CRUD**](https://www.sumologic.com/glossary/crud/) operations will be performed."
      },
      "typeVersion": 1
    },
    {
      "id": "374761f7-9299-41a3-8bb3-25434f4f9eaf",
      "name": "Find database page",
      "type": "n8n-nodes-base.notion",
      "position": [
        660,
        660
      ],
      "parameters": {
        "options": {},
        "resource": "databasePage",
        "operation": "getAll",
        "returnAll": true,
        "databaseId": "e3503d88-accb-4ddb-aa45-f962cb03e729",
        "filterJson": "={{$node[\"Create custom Notion filters\"].json[\"notionfilter\"]}}",
        "filterType": "json"
      },
      "credentials": {
        "notionApi": {
          "id": "XNjSmr171NUO17TK",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "159db4ca-c8da-439a-aa44-63527c7b9dcd",
      "name": "Switch",
      "type": "n8n-nodes-base.switch",
      "position": [
        860,
        660
      ],
      "parameters": {
        "rules": {
          "rules": [
            {
              "value2": "jira:issue_updated"
            },
            {
              "output": 1,
              "value2": "jira:issue_deleted"
            }
          ]
        },
        "value1": "={{$node[\"On issues created/updated/deleted\"].json[\"webhookEvent\"]}}",
        "dataType": "string"
      },
      "typeVersion": 1
    },
    {
      "id": "080fb157-e160-4bf0-9348-05eabee60f9f",
      "name": "IF",
      "type": "n8n-nodes-base.if",
      "position": [
        240,
        560
      ],
      "parameters": {
        "conditions": {
          "string": [
            {
              "value1": "={{$node[\"On issues created/updated/deleted\"].json[\"webhookEvent\"]}}",
              "value2": "jira:issue_created"
            }
          ]
        }
      },
      "typeVersion": 1
    },
    {
      "id": "3ec2a130-251d-4d28-8dc3-ca31f528f90e",
      "name": "Delete issue",
      "type": "n8n-nodes-base.notion",
      "position": [
        1080,
        760
      ],
      "parameters": {
        "pageId": "={{ $node[\"Find database page\"].json[\"id\"] }}",
        "operation": "archive"
      },
      "credentials": {
        "notionApi": {
          "id": "XNjSmr171NUO17TK",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    },
    {
      "id": "5a23919a-ee95-4935-b619-5eb0b486eef7",
      "name": "On issues created/updated/deleted",
      "type": "n8n-nodes-base.jiraTrigger",
      "position": [
        -160,
        560
      ],
      "webhookId": "042e0fd3-9776-4c23-9f0d-dc032ef22744",
      "parameters": {
        "events": [
          "jira:issue_created",
          "jira:issue_deleted",
          "jira:issue_updated"
        ],
        "additionalFields": {}
      },
      "credentials": {
        "jiraSoftwareCloudApi": {
          "id": "xZbqpSTMv8IjtS5Y",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 1
    },
    {
      "id": "6d3bbfce-cbfc-4590-827b-4ec1eb5c11b6",
      "name": "Lookup table",
      "type": "n8n-nodes-base.code",
      "position": [
        40,
        560
      ],
      "parameters": {
        "jsCode": "/* Lookup table for the statuses in Jira. You can find the status IDs by
   following the instructions provided at this link:
   https://community.atlassian.com/t5/Jira-Service-Management/How-do-I-get-a-list-of-statuses-that-show-the-associated-status/qaq-p/1803682
*/
var lookup = {
    \"To Do\": \"To do\",
    \"In Progress\": \"In progress\",
    \"Done\": \"Done\"
};



new_items = [];

for (item of $items(\"On issues created/updated/deleted\")) {
  console.log(item.json[\"Status\"]);
  // instantiate a new variable for status
  var issue_status = item.json[\"issue\"][\"fields\"][\"status\"][\"name\"];
  // check if the status is in the lookup table
  if (issue_status in lookup) {
    // if it is, then add the status ID to the new_items array
    new_items.push({
      \"Status ID\": lookup[issue_status]
    });
  }
}

return new_items;"
      },
      "typeVersion": 2
    },
    {
      "id": "bdc966ce-16bf-47de-aba3-fcd0f912f95f",
      "name": "Create custom Notion filters",
      "type": "n8n-nodes-base.code",
      "position": [
        460,
        660
      ],
      "parameters": {
        "jsCode": "const new_items = [];
for (item of $items(\"On issues created/updated/deleted\")) {

  // do not process this item if action is created
  if (item.json[\"webhookEvent\"] == \"jira:issue_created\") {
    continue;
  }

  // build the output template
  var new_item = {
    \"json\": {
      \"notionfilter\": \"\"
    }
  };
  new_item = JSON.stringify(new_item);
  new_item = JSON.parse(new_item);
  new_items.push(new_item);

  // create Notion filter to find specific database page by issue ID
  notionfilter = {
    or: [],
  }

  const filter = {
    property: 'Issue ID',
    number: {
      equals: parseInt(item.json[\"issue\"][\"id\"])
    }
  }
  notionfilter[\"or\"].push(filter);

  new_item.json.notionfilter = JSON.stringify(notionfilter); 
}

return new_items;"
      },
      "typeVersion": 2
    },
    {
      "id": "f92157a9-1a63-4907-87c8-0b54c3b0ac8e",
      "name": "Update issue",
      "type": "n8n-nodes-base.notion",
      "position": [
        1080,
        560
      ],
      "parameters": {
        "pageId": "={{ $node[\"Find database page\"].json[\"id\"] }}",
        "options": {},
        "resource": "databasePage",
        "operation": "update",
        "propertiesUi": {
          "propertyValues": [
            {
              "key": "Title|title",
              "title": "={{$node[\"On issues created/updated/deleted\"].json[\"issue\"][\"fields\"][\"summary\"]}}"
            },
            {
              "key": "Status|select",
              "selectValue": "={{$node[\"Lookup table\"].json[\"Status ID\"]}}"
            }
          ]
        }
      },
      "credentials": {
        "notionApi": {
          "id": "XNjSmr171NUO17TK",
          "name": "REPLACE ME"
        }
      },
      "typeVersion": 2
    }
  ],
  "active": false,
  "pinData": {},
  "settings": {
    "executionOrder": "v1"
  },
  "versionId": "490138aa-d92d-439a-b7bb-d6d00a9fab86",
  "connections": {
    "IF": {
      "main": [
        [
          {
            "node": "Create database page",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Create custom Notion filters",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Switch": {
      "main": [
        [
          {
            "node": "Update issue",
            "type": "main",
            "index": 0
          }
        ],
        [
          {
            "node": "Delete issue",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Lookup table": {
      "main": [
        [
          {
            "node": "IF",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Find database page": {
      "main": [
        [
          {
            "node": "Switch",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "Create custom Notion filters": {
      "main": [
        [
          {
            "node": "Find database page",
            "type": "main",
            "index": 0
          }
        ]
      ]
    },
    "On issues created/updated/deleted": {
      "main": [
        [
          {
            "node": "Lookup table",
            "type": "main",
            "index": 0
          }
        ]
      ]
    }
  }
}

功能特点

  • 自动检测新邮件
  • AI智能内容分析
  • 自定义分类规则
  • 批量处理能力
  • 详细的处理日志

技术分析

节点类型及作用

  • Notion
  • Stickynote
  • Switch
  • If
  • Jiratrigger

复杂度评估

配置难度:
★★★★☆
维护难度:
★★☆☆☆
扩展性:
★★★★☆

实施指南

前置条件

  • 有效的Gmail账户
  • n8n平台访问权限
  • Google API凭证
  • AI分类服务订阅

配置步骤

  1. 在n8n中导入工作流JSON文件
  2. 配置Gmail节点的认证信息
  3. 设置AI分类器的API密钥
  4. 自定义分类规则和标签映射
  5. 测试工作流执行
  6. 配置定时触发器(可选)

关键参数

参数名称 默认值 说明
maxEmails 50 单次处理的最大邮件数量
confidenceThreshold 0.8 分类置信度阈值
autoLabel true 是否自动添加标签

最佳实践

优化建议

  • 定期更新AI分类模型以提高准确性
  • 根据邮件量调整处理批次大小
  • 设置合理的分类置信度阈值
  • 定期清理过期的分类规则

安全注意事项

  • 妥善保管API密钥和认证信息
  • 限制工作流的访问权限
  • 定期审查处理日志
  • 启用双因素认证保护Gmail账户

性能优化

  • 使用增量处理减少重复工作
  • 缓存频繁访问的数据
  • 并行处理多个邮件分类任务
  • 监控系统资源使用情况

故障排除

常见问题

邮件未被正确分类

检查AI分类器的置信度阈值设置,适当降低阈值或更新训练数据。

Gmail认证失败

确认Google API凭证有效且具有正确的权限范围,重新进行OAuth授权。

调试技巧

  • 启用详细日志记录查看每个步骤的执行情况
  • 使用测试邮件验证分类逻辑
  • 检查网络连接和API服务状态
  • 逐步执行工作流定位问题节点

错误处理

工作流包含以下错误处理机制:

  • 网络超时自动重试(最多3次)
  • API错误记录和告警
  • 处理失败邮件的隔离机制
  • 异常情况下的回滚操作