Giter Club home page Giter Club logo

git-webhook-wework-robot's Introduction

git-webhook-wework-robot

快速使用

直接在git项目中配置webhook https://service-d6if097q-1251767583.gz.apigw.tencentcs.com/release/wechat-work-gitlab-robot?id={robotid}

其中robotid是你的机器人id,可以在企业微信的机器人列表中查看,见图:

Changelog

2020-10 支持了 gitlab 的 review/wiki 事件

2020-9 支持了 gitlab 的腾讯云函数 git 机器人

API网关地址: https://service-d6if097q-1251767583.gz.apigw.tencentcs.com/release/wechat-work-gitlab-robot?id={robotid}

自建云函数、设置 webhook 请参考下面 github 的介绍,是一样。

2020-1 支持了腾讯云云函数的创建

使用方式: 在github中的Webhook配置 API 的网关地址:https://service-5mv1fv1k-1251767583.gz.apigw.tencentcs.com/release/wechatwork_git_robot?id={robotid}

注意:其中robotid是你需要推送的机器人id

自建云函数方式:

  1. git clone https://github.com/LeoEatle/git-webhook-wework-robot.git

  2. 注册并登陆腾讯云管理后台,新建一个云函数,可以先选个Node的Helloworld模板

  3. 将代码中的cloud目录上传,见图

  4. 点击保存(保存后🉑️测试试试)

  5. 选择触发方式,添加新的触发方式,类型选择API网关,保存后得到url

  6. ok!可以填到Github的webhook里了,类型选择Send me everything,也可以自定义,url填上上面的url,别忘了要在后面加上?id={你的机器人id}作为参数

可见下面如何使用

2019-8

  1. docker镜像上传到新地址:https://cloud.docker.com/repository/docker/leoeatle/wxwork-git-robot

2019-7

  1. 由于一直在维护公司内的机器人,有些改动不适用于外部使用。单独分开两个项目,不再作为两个分支管理。

2019-6

  1. 重新审视之前的dockerfile感觉过于臃肿,不如直接把dist打包进docker,所以进行了修改
  2. 之前的腾讯云服务器没钱了,wework-robot.xyz 宣告停止服务,如有需要请自行搭建

目前支持的事件

Push event 示例

Issue event 示例

Merge Request 示例

Merge Request 会有发起、合并、关闭、重新发起等几种情况,文案会有所不同。

如何使用

Github

如果是使用github,在github项目中的Setting中选择Webhooks,选择Add Webhooks,填写url,如http://{{你的域名或者IP}}/github?id=7048958e-8b4b-4381-9758-af84347c240c

/github用来区分github和gitlab,这两者的处理方式不同。

id参数代表自定义的机器人id,可以在企业微信的机器人列表中查看(注意,这个必须要自己新建的机器人才能看到),见图:

Gitlab

如果是gitlab,将webhook地址改为http://{{你的域名或者IP}}/git?id={{机器人id}}

注意这里的路由是git

2019-10-17 更新 现在gitlab路由也会指向同样的功能了,所以两种路由都可以

如何部署

建议将此服务部署在自己的机器上

最简单的方式

# 在服务器上
git pull https://github.com/LeoEatle/git-webhook-wework-robot.git
npm install
npm run build
pm2 start ./dist/server.js

使用docker

目前已经编译出了一份镜像文件,地址:https://cloud.docker.com/repository/docker/leoeatle/wxwork-git-robot

// 先登录
sudo docker pull https://cloud.docker.com/repository/docker/leoeatle/wxwork-git-robot:latest
docker run -d leoeatle/wxwork-git-robot

当然,也可以使用pm2-docker来同时利用到pm2和docker。

机器人id配置

如果需要修改服务器端的默认机器人id设置,请修改项目根目录下的.env

PORT=8080
NODE_ENV=development
JWT_SECRET=your-secret-whatever
DATABASE_URL=postgres://user:pass@localhost:5432/apidb
CHAT_ID=82c08203-82a6-4824-8319-04a361bc0b2a # 改这里!

项目介绍 && 开发(热烈欢迎提PR)

此项目用于连接git webhook和企业微信机器人webhook,采用koa2 + typescript开发,大部分git webhook 和 企业微信机器人的数据结构已经定义好typing,如:

interface Repository {
    name: string;
    description: string;
    homepage: string;
    git_http_url: string;
    git_ssh_url: string;
    url: string;
    visibility_level: number;
}

并且项目有配置严格的tslint和lint-staged等检查。

异步解决方案为async/await

github事件handler: github.ts gitlab事件handler: gilab.ts

chatRobot推送信息相关: chat.ts

提交

git add .
npm run commit # 让commitlint自动生成commit信息

TODO

  • 目前gitlab只做了pushmerge request事件的handler,以及只做了文字和mardown信息的推送,其余事件和其他类型的推送还需开发。

  • github推送目前只考虑push pr issue,其他有待添加

  • 为了方便其他团队甚至外面开源的使用,考虑使用docker方便自己部署。

  • 考虑是不是可以在配置webhook的地方直接配置机器人id,分别推送

  • 进一步考虑是不是可以用GUI统一管理项目和机器人id的关系

  • 考虑可以补全gitlab的typing,实在太多了,有人帮忙就好了,github已经使用了有人开源整理的typing依赖库

Contributors ✨

Thanks goes to these wonderful people (emoji key):

soul11201
soul11201

🐛 💻
Haitao
Haitao

🐛 💻

This project follows the all-contributors specification. Contributions of any kind welcome!

git-webhook-wework-robot's People

Contributors

allcontributors[bot] avatar dependabot[bot] avatar leoeatle avatar liubiantao avatar noname007 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

git-webhook-wework-robot's Issues

gitlab的issues评论

async function handleNote(body, robotid) {
    const robot = new ChatRobot(
        robotid || config.chatid
    );
    const { user, project, issue, object_attributes, repository } = body;
    const { noteable_type, url } = object_attributes;
    if (noteable_type === 'Issue') {
        const mdMsg = `${user.name} 评论了[${repository.name}](${repository.url})的issue[${issue.title}]
                        评论:${object_attributes.note}
                        [查看详情](${url})`
        await robot.sendMdMsg(mdMsg);
    }
    return;
}

仅支持文字,gitlab8中文社区版

新增对 ISSUE 评论的支持(标题、ISSUE名 )

报错

截屏2020-04-16 下午4 03 11

这个报错不知道怎么解决 😭

部署安装完配置env之后怎么使用?

按照说明部署完了以后,修改了端口为18080 然后在gitlab的webhook内写的地址为

http://服务器地址:18080/gitlab?id=xxx

但是无法使用。


0|server  | info: POST /gitlab?id=xxxxx 403 1ms
0|server  | info: GET /gitlab?id=xxxxx 404 0ms
0|server  | info: POST /gitlab?id=xxxxx 404 0ms

腾讯云函数测试成功但返回"Not a github webhook deliver"

自建gitlab。
用readme里提供的https://service-d6if097q-1251767583.gz.apigw.tencentcs.com/release/wechat-work-gitlab-robot?id={robotid}通知消息成功发送,但换我自己部署的腾讯云函数通知消息没有成功。
云函数后台日志显示“调用成功”,返回数据是"Not a github webhook deliver"
但是,同一个自建的云函数地址放到github上运行没有问题。好神奇。
麻烦关注一下,感谢。

具体日志如下:

返回数据:

"Not a github webhook deliver"

日志:

START RequestId: c7c091ccce1a67604f94223faf8ec76b

Event RequestId: c7c091ccce1a67604f94223faf8ec76b

2020-12-05T00:55:50.779Z c7c091ccce1a67604f94223faf8ec76b event:  { body: '{"object_kind":"merge_request","event_type":"merge_request","user":{"name":"dami","username":"hl_00015","avatar_url":"http://192.168.11.155/uploads/-/system/user/avatar/29/avatar.png","email":"[email protected]"},"project":{"id":60,"name":"00015","description":"o","web_url":"http://192.168.11.155/hl_00015/design","avatar_url":"http://192.168.11.155/uploads/-/system/project/avatar/60/vlcsnap-2020-10-28-12h39m41s218.jpg","git_ssh_url":"[email protected]:hl_00015/design.git","git_http_url":"http://192.168.11.155/hl_00015/design.git","namespace":"dami","visibility_level":0,"path_with_namespace":"hl_00015/design","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.11.155/hl_00015/design","url":"[email protected]:hl_00015/design.git","ssh_url":"[email protected]:hl_00015/design.git","http_url":"http://192.168.11.155/hl_00015/design.git"},"object_attributes":{"assignee_id":1,"author_id":1,"created_at":"2020-10-21T09:22:06.023Z","description":"按照milestone,搭建教程框架和部分更细节的点","head_pipeline_id":null,"id":17,"iid":1,"last_edited_at":null,"last_edited_by_id":null,"merge_commit_sha":null,"merge_error":null,"merge_params":{"force_remove_source_branch":"0"},"merge_status":"can_be_merged","merge_user_id":null,"merge_when_pipeline_succeeds":false,"milestone_id":2,"source_branch":"feature_gitlab-lession","source_project_id":60,"state_id":2,"target_branch":"develop","target_project_id":60,"time_estimate":0,"title":"完成教程框架搭建","updated_at":"2020-10-21T09:22:36.279Z","updated_by_id":null,"url":"http://192.168.11.155/hl_00015/design/-/merge_requests/1","source":{"id":60,"name":"00015","description":"o","web_url":"http://192.168.11.155/hl_00015/design","avatar_url":"http://192.168.11.155/uploads/-/system/project/avatar/60/vlcsnap-2020-10-28-12h39m41s218.jpg","git_ssh_url":"[email protected]:hl_00015/design.git","git_http_url":"http://192.168.11.155/hl_00015/design.git","namespace":"dami","visibility_level":0,"path_with_namespace":"hl_00015/design","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.11.155/hl_00015/design","url":"[email protected]:hl_00015/design.git","ssh_url":"[email protected]:hl_00015/design.git","http_url":"http://192.168.11.155/hl_00015/design.git"},"target":{"id":60,"name":"00015","description":"o","web_url":"http://192.168.11.155/hl_00015/design","avatar_url":"http://192.168.11.155/uploads/-/system/project/avatar/60/vlcsnap-2020-10-28-12h39m41s218.jpg","git_ssh_url":"[email protected]:hl_00015/design.git","git_http_url":"http://192.168.11.155/hl_00015/design.git","namespace":"dami","visibility_level":0,"path_with_namespace":"hl_00015/design","default_branch":"master","ci_config_path":null,"homepage":"http://192.168.11.155/hl_00015/design","url":"[email protected]:hl_00015/design.git","ssh_url":"[email protected]:hl_00015/design.git","http_url":"http://192.168.11.155/hl_00015/design.git"},"last_commit":{"id":"04a2f5aa1036a74920ec0a34b161101dad5e3e51","message":"完善Gitlab项目培训教程的整体框架  #8\\n","title":"完善Gitlab项目培训教程的整体框架  #8","timestamp":"2020-10-21T17:15:47+08:00","url":"http://192.168.11.155/hl_00015/design/-/commit/04a2f5aa1036a74920ec0a34b161101dad5e3e51","author":{"name":"dami","email":"[email protected]"}},"work_in_progress":false,"total_time_spent":0,"human_total_time_spent":null,"human_time_estimate":null,"assignee_ids":[1],"state":"closed"},"labels":[{"id":46,"title":"Feature","color":"#F0AD4E","project_id":60,"created_at":"2020-10-21T08:29:39.588Z","updated_at":"2020-10-21T08:31:18.982Z","template":false,"description":"功能开发","type":"ProjectLabel","group_id":null}],"changes":{},"repository":{"name":"00015","url":"[email protected]:hl_00015/design.git","description":"o","homepage":"http://192.168.11.155/hl_00015/design"},"assignees":[{"name":"Administrator","username":"root","avatar_url":"https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\\u0026d=identicon","email":"[email protected]"}]}',

  headerParameters: {},

  headers: 

   { connection: 'close',

     'content-length': '4047',

     'content-type': 'application/json',

     host: 'service-iyt------1304425898.gz.apigw.tencentcs.com',

     requestsource: 'APIGW',

     'x-api-requestid': 'c7c091ccce1a67604f94223faf8ec76b',

     'x-api-scheme': 'https',

     'x-b3-traceid': 'c7c091ccce1a67604f94223faf8ec76b',

     'x-gitlab-event': 'Merge Request Hook',

     'x-qualifier': '$LATEST' },

  httpMethod: 'POST',

  path: '/gitlabmrnotification',

  pathParameters: {},

  queryString: { id: 'e6e54293-14cb-4ef2-9a67-97---------' },

  queryStringParameters: {},

  requestContext: 

   { httpMethod: 'ANY',

     identity: {},

     path: '/gitlabmrnotification',

     serviceId: 'service-iyt------',

     sourceIp: '117.89.132.239',

     stage: 'release' } }

 

END RequestId: c7c091ccce1a67604f94223faf8ec76b

Report RequestId: c7c091ccce1a67604f94223faf8ec76b Duration:3ms Memory:128MB MemUsage:19.593750MB

一个大问题

没有明白,按步骤创建完云函数得到了url,企业微信也创建了机器人拿到了机器人的key,用这个url到gitlab创建了一个webhook,然后怎么使用啊,下面的使用步骤没看明白

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.