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

向脚本传递参数 #1

Open
lloydzhou opened this issue Jul 12, 2017 · 12 comments
Open

向脚本传递参数 #1

lloydzhou opened this issue Jul 12, 2017 · 12 comments

Comments

@lloydzhou
Copy link

No description provided.

@hustcc
Copy link
Owner

hustcc commented Jul 13, 2017

�很好的 issue,有兴趣提交 pr 吗?

@lloydzhou
Copy link
Author

#2

@lloydzhou
Copy link
Author

lloydzhou commented Jul 13, 2017

TODO

https://developer.github.com/webhooks/
很多的event都是有共同的参数,比如很多event有action也可以尝试拿出来

@lloydzhou
Copy link
Author

或者可以使用将整个payload里面的json展开弄成只有一层的。然后,就能直接在配置文件里面使用payload里面的参数例如

{
  "ref": "refs/heads/changes",
  "before": "9049f1265b7d61be4a8904a9a27120d2064dab3b",
  "after": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
  "created": false,
  "deleted": false,
  "forced": false,
  "base_ref": null,
  "compare": "https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f",
  "commits": [
    {
      "id": "0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
      "tree_id": "f9d2a07e9488b91af2641b26b9407fe22a451433",
      "distinct": true,
      "message": "Update README.md",
      "timestamp": "2015-05-05T19:40:15-04:00",
      "url": "https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c",
      "author": {
        "name": "baxterthehacker",
        "email": "baxterthehacker@users.noreply.github.com",
        "username": "baxterthehacker"
      },
      ...]
  }
}
'SCRIPT': '/path/to/shell.sh {commits.0.id}'
 ==> 
'SCRIPT': '/path/to/shell.sh 0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c'

@hustcc
Copy link
Owner

hustcc commented Jul 13, 2017

其实如果可以直接把这个 json 一起 post 过去,这个也没有什么问题吧?

@lloydzhou
Copy link
Author

  1. 如果向要将整个json传递给这个shell,感觉太大了点,可能很多时候用不上(可能使用配置的方式更好一点,让使用的人决定要用哪几个参数)
  2. 另外如果使用env的方式传递这个数据,好像也不能传递多层级的数据给一个shell

@hustcc
Copy link
Owner

hustcc commented Jul 13, 2017

嗯,正常情况下是传 id,然后由 git 平台提供接口去获得信息,当时这样 hook 脚本就麻烦了( ̄~ ̄)

你现在的场景是什么?

@lloydzhou
Copy link
Author

开发的时候,会有很多的新分支,我并不能提前预知会有什么分支。
然后,team里面会使用pull request。然而PR的hook并不能知道哪个分支。所以打算传几个简单的参数到脚本里面。

@hustcc
Copy link
Owner

hustcc commented Jul 14, 2017

在设置配置文件的时候可以指定分支的啊~

@lloydzhou
Copy link
Author

我并不能预先知道team里面的人会创建多少分支,以及不知道别人创建分支的名字 😄
总不能每次有新分支我就重启一下服务吧。

@hustcc
Copy link
Owner

hustcc commented Jul 14, 2017

哦,懂你的意思了,那我觉得:分支,提交人 id,仓库名,这些信息会比较重要一些。

@lloydzhou
Copy link
Author

对,像你说的,可能这些信息比较重要。不过我也不确定是不是只会用到这些参数。所以上面的comment我提了一个想法,就是将整个json展开成一级,然后让使用的人自己在配置文件里面去配置就好。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants