尧图网站设计 尧图网站设计YAOTU DESIGN
ARTICLE DETAIL

资讯详情

深耕网站设计与一线实操的经验洞察。

Automatisch 集成 Gitea 触发器指南:用轮询触发 Issue、Pull Request、Star 与 Watch 事件

Automatisch 集成 Gitea 触发器指南:用轮询触发 Issue、Pull Request、Star 与 Watch 事件 Automatisch 集成 Gitea 触发器指南用轮询触发 Issue、Pull Request、Star 与 Watch 事件【免费下载链接】automatischThe open source Zapier alternative. Build workflow automation without spending time and money.项目地址: https://gitcode.com/GitHub_Trending/au/automatisch本指南基于 Automatisch 开源项目GitHub 上备受欢迎的开源 Zapier 替代方案中 Gitea 应用的官方文档与真实源码系统讲解如何在 Automatisch 工作流中使用 Gitea 的四个内置触发器——New issues、New pull requests、New stargazers、New watchers。读完本文你将掌握每个触发器的功能、可配置参数、底层轮询实现原理含分页逻辑与幂等去重机制并能够独立搭建仓库动态 → 自动化动作的工作流。一、Gitea 触发器概览Automatisch 的 Gitea 应用通过**轮询polling**方式监听仓库动态共提供四个触发器定义于 triggers/index.js与官方文档 triggers.md 一一对应触发器key触发条件轮询间隔分钟New issuesnewIssues仓库中创建了新 Issue15New pull requestsnewPullRequests用户创建了新的 Pull Request15New stargazersnewStargazers有用户给仓库点 Star15New watchersnewWatchers有用户 Watch订阅了仓库15四个触发器全部声明了pollInterval: 15即每 15 分钟检查一次对应 API 端点。根据 define-trigger.js 的校验逻辑触发器必须带有pollInterval或声明为 webhook 类型才能通过定义校验Gitea 这四个触发器均属于轮询型polling trigger无需在 Gitea 侧配置 Webhook仅依赖 API 轮询即可工作。二、前置条件建立 Gitea 连接在使用任何触发器之前必须先完成 Gitea OAuth2 连接配置完整步骤见 connection.md登录你的 Gitea 实例进入Settings设置面板点击Applications应用按钮在Manage OAuth2 Applications区域创建一个新的 OAuth2 应用将 Automatisch 提供的OAuth Redirect URL复制到 Gitea 的Redirect URIs字段每个 URI 单独占一行将 Gitea 生成的Client ID填入 Automatisch将 Gitea 生成的Client Secret填入 Automatisch在 Automatisch 的Instance URL字段填写你的 Gitea 实例地址点击Submit提交完成连接创建。连接所需的字段定义在 auth/index.jsoAuthRedirectUrl只读字段固定值为{WEB_APP_URL}/app/gitea/connections/add可一键复制instanceUrl必填你的 Gitea 实例地址支持 Gitea.com 或自托管实例clientId/clientSecret必填来自 Gitea 的 OAuth2 应用。instanceUrl之所以关键是因为 set-base-url.js 会在每个请求发出前把baseURL动态设置为${instanceUrl}/api/v1所有触发器与动态数据的 API 调用都基于该地址。授权流程由 generate-auth-url.js 实现构造{instanceUrl}/login/oauth/authorize授权链接含client_id、redirect_uri、response_typecode与随机state并将原始 state 保存用于后续校验。三、New issues新 Issue 触发触发条件指定的 Gitea 仓库中创建了新 Issuenew-issues/index.js。该触发器提供三个配置参数Repo必选下拉框动态加载当前用户可见的仓库列表数据源来自动态数据listRepos见下文动态数据支持Which types of issues should this trigger on?必选Issue 状态过滤默认值为all可选closed、open、allLabels可选动态字段可为每个 Label 再次打开下拉框从指定仓库的标签列表中选择只有被添加了所选标签的 Issue 才会触发。底层会把这些标签以逗号连接后作为 API 的labels查询参数传递。触发运行时先读取$.step.parameters中的repo、issueType、labels并从$.auth.data.repoOwner取出仓库属主然后分页请求GET /repos/{repoOwner}/{repo}/issues查询参数包含state状态过滤与labels标签过滤。四、New pull requests新 Pull Request 触发触发条件用户创建了新的 Pull Requestnew-pull-requests/index.js。配置参数Repo必选同 New issues动态加载仓库列表Which types of pulls should this trigger on?可选PR 状态过滤默认all可选closed、open、allType of Sort?可选排序方式默认all可选oldest、recentupdate、leastupdate、mostcomment、leastcomment、priority。触发运行时请求GET /repos/{repoOwner}/{repo}/pulls查询参数为sort排序与state状态同样采用分页拉取全部结果。五、New stargazers 与 New watchersStar 与 Watch 事件触发New stargazersnew-stargazers/index.js当有用户给仓库点 Star 时触发仅需选择Repo必选运行时请求GET /repos/{repoOwner}/{repo}/stargazers。New watchersnew-watchers/index.js当有用户 Watch订阅仓库时触发仅需选择Repo必选运行时请求GET /repos/{repoOwner}/{repo}/subscribersGitea 将订阅者视为 watch 用户。两个触发器返回的每一条数据都会通过$.pushTriggerItem推入执行流raw 数据为 Gitea API 返回的用户对象internalId取id字段字符串用于事件去重。六、底层实现机制轮询、分页与去重四个触发器的run($)函数采用完全一致的轮询模式核心流程如下以 New issues 为例const params { page: 1, limit: 100, state: issueType, labels: formattedAllLabels }; let totalCount; let totalRequestedCount; do { const { data, headers } await $.http.get(/repos/${repoOwner}/${repo}/issues, { params }); params.page params.page 1; totalCount Number(headers[x-total-count]); totalRequestedCount params.page * params.limit; if (data?.length) { for (const issue of data) { $.pushTriggerItem({ raw: issue, meta: { internalId: issue.id.toString() } }); } } } while (totalRequestedCount totalCount);值得注意的实现细节分页拉全量单页上限limit: 100通过 Gitea 响应头x-total-count判断总条数循环递增page直至拉完全部数据避免遗漏历史事件幂等去重internalId取自 Gitea 数据的idAutomatisch 会依据该 ID 跳过已处理过的事件因此即使轮询间隔内产生多条数据也不会重复触发轮询频率pollInterval: 15表示每 15 分钟执行一次检查属于近实时触发无法做到秒级即时响应适合对时效性要求不高的场景。七、配套动态数据支持触发器中的仓库下拉框由动态数据listRepos提供list-repos/index.js分页请求GET /user/repos将当前连接用户可见的仓库以{ value: repo.name, name: repo.name }形式返回为下拉选项。New issues 的 Labels 动态字段依赖listLabelslist-labels/index.js请求GET /repos/{repoOwner}/{repo}/labels依据showLabelId参数决定下拉值使用标签 ID 还是名称。listRepos与listLabels均由应用定义文件 index.js 挂载到dynamicData集合触发器通过getDynamicData查询机制动态引用。八、实战搭建新 Issue → 自动通知工作流综合上述能力一个典型的使用场景是Gitea 仓库出现新 Issue 时自动发送通知。在 Automatisch 中新建 Flow添加Gitea → New issues触发器下拉选择要监听的仓库按需设置 Issue 状态如open与标签过滤连接后续动作步骤例如使用 SMTP 或 Slack 等应用发送告警触发器每 15 分钟检查一次新 Issue 会作为触发数据进入下游步骤可直接引用 Issue 的标题、编号、创建人等字段。同理将触发器替换为 New pull requests、New stargazers 或 New watchers即可分别实现 PR 提醒、Star 播报与 Watch 统计等自动化。九、适用范围与限制触发器依赖 OAuth2 连接且请求目标为instanceUrl对应的 Gitea 实例 API/api/v1自托管 Gitea 与 Gitea.com 均可使用触发方式为轮询而非 Webhook存在最长 15 分钟的延迟不适用于需要即时响应的场景若 Gitea 实例不可达或 Token 失效轮询将失败请通过连接的重新授权refresh-token 逻辑恢复。上述实现细节均可在仓库中验证触发器定义位于 packages/backend/src/apps/gitea/triggers/连接配置说明见 packages/docs/pages/apps/gitea/connection.md官方触发器清单见 packages/docs/pages/apps/gitea/triggers.md。【免费下载链接】automatischThe open source Zapier alternative. Build workflow automation without spending time and money.项目地址: https://gitcode.com/GitHub_Trending/au/automatisch创作声明:本文部分内容由AI辅助生成(AIGC),仅供参考
返回列表