在 GitHub 个操作中清理 GitHub 个上下文
Sanitize GitHub context in GitHub actions
我正在尝试编写一个松弛通知机器人来触发 GitHub 拉取请求,但我 运行 遇到了清理问题
我有一个动作定义如下
name: slack-notification
on:
pull_request:
types: [closed]
jobs:
slack-notifications:
runs-on: ubuntu-latest
steps:
- name: Send message to slack
id: slack
uses: slackapi/slack-github-action@v1.18.0
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ github.event.pull_request.title }}"
}
}
]
}
当 pull_request 标题正常时,这很有效。但是,如果它包含富文本格式,或任何会破坏 JSON 的内容(如引号等),则该过程将失败。我该如何消毒以避免这种情况?
尝试使用 toJSON 进行引用
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{ toJSON(github.event.pull_request.title) }}
}
}
]
}
我正在尝试编写一个松弛通知机器人来触发 GitHub 拉取请求,但我 运行 遇到了清理问题
我有一个动作定义如下
name: slack-notification
on:
pull_request:
types: [closed]
jobs:
slack-notifications:
runs-on: ubuntu-latest
steps:
- name: Send message to slack
id: slack
uses: slackapi/slack-github-action@v1.18.0
with:
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": "${{ github.event.pull_request.title }}"
}
}
]
}
当 pull_request 标题正常时,这很有效。但是,如果它包含富文本格式,或任何会破坏 JSON 的内容(如引号等),则该过程将失败。我该如何消毒以避免这种情况?
尝试使用 toJSON 进行引用
payload: |
{
"blocks": [
{
"type": "section",
"text": {
"type": "mrkdwn",
"text": ${{ toJSON(github.event.pull_request.title) }}
}
}
]
}