Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add configuration run environment #48

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

feat: Add configuration run environment #48

wants to merge 3 commits into from

Conversation

xuexb
Copy link
Owner

@xuexb xuexb commented Jan 21, 2018

先不要合并。

  1. 在所有功能文件里添加了 name 字段,标识当前功能模块对应的配置名称,如:name: issue/autoLabel 表示对应了配置文件里的 issue.autoLabel ,当然也在想配置里是不是也直接写这个 key 而不是多套一级,如:pullRequest/autoReviewRequestpullRequest.autoReviewRequest 的区别
  2. 在注册里先把功能文件根据 name 排列,并循环所有的 package.json 配置开启的功能,去注册事件,注册时以 空间名/仓库名@事件名 ,这样在触发时就可以无条件触发了,因为是以仓库为粒度了
  3. 注册事件时为了注入配置数据,做了一层代理,如:
module.exports = {
  name: 'pullRequest/autoReviewRequest',
  register (on) {
    on('pull_request_labeled', ({payload, repo}, {config, scope}) => {
    })
  }
}

上面对应了:

"config": {
  "github-bot": {
    "username/repo": {
      "pullRequest": {
        "autoReviewRequest": {
          "enabled": true,
          "data": {
            "need demo": "您好,请填写相关 Demo 链接。",
            "need update package": "请更新版本号。"
          }
        }
      }
    }
  }
}

事件回调参数说明:

  • payload - 对应接口数据,via:

    github-bot/src/app.js

    Lines 35 to 38 in 4bdb7b5

    githubEvent.emit(`${payload.repository.full_name}@${eventName}`, {
    repo: payload.repository.name,
    payload
    })
  • repo - 仓库名称(不带空间名)
  • config - 对应当前匹配请求+空间名/仓库名下的所有配置,也就是 pkg.config.github-bot.username/repo,via:

    github-bot/src/app.js

    Lines 69 to 72 in 4bdb7b5

    callback(data, {
    config: pkg.config['github-bot'][repo],
    scope: config.data || {}
    })
  • scope - 当前配置功能模块的配置,也就是 pkg.config.github-bot.username/repo.pullRequest.autoReviewRequest

@coveralls
Copy link

coveralls commented Jan 21, 2018

Coverage Status

Coverage decreased (-0.08%) to 99.359% when pulling daf7a5a on feat/config into 4da5f41 on master.

@xuexb
Copy link
Owner Author

xuexb commented Jan 23, 2018

@yugasun 老铁看下大体上没毛病吧,现在就差测试用例和文档说明了。

@yugasun
Copy link
Collaborator

yugasun commented Jan 24, 2018

@xuexb 整体流程没问题,思路也很好,可不可以在重要流程地方把注释加上,方便阅读。

另外几点建议:

  1. 可否将相关配置从 package.json 文件中脱离,这里本来是项目的整体信息,不方便可定制化的配置
  2. 部分箭头嵌套是的代码可否用统一工具函数来处理,精简代码,比如此处:

    github-bot/src/app.js

    Lines 63 to 65 in bf92708

    Object.keys(pkg.config['github-bot']).forEach(repo => {
    Object.keys(pkg.config['github-bot'][repo]).forEach(type => {
    Object.keys(pkg.config['github-bot'][repo][type]).forEach(name => {
  3. 对于各个模块的 name 属性值,使用 . 作为命名空间连接符,会不会更加清晰明了。

@xuexb xuexb mentioned this pull request Feb 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants