Skip to content

💡 Allow " on PR Title and not breaking JSON payload #202

@miquelrossello

Description

@miquelrossello

Description

When using " on a Pull Request title the JSON payload is broken.

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • example code related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

When placing a " on the Pull Request title, for example Add new field "image", the JSON payload gets broken.

Reproducible in:

package version: action version v1.23.0

node version:

OS version(s):

Steps to reproduce:

  1. Add " to Pull Request title
  2. Execute GH Action and expect to fail

Expected result:

Be able to place " on Pull Request title without breaking JSON payload.

Actual result:

JSON payload is broken.

Console error:

Run slackapi/slack-github-action@v1.23.0
Error: Error: Need to provide valid JSON payload
passed in payload was invalid JSON

Attachments:

Our current use of this GitHub Action from we get this issue.

name: Notifying slack
on:
  pull_request:
    types: [ labeled ]
jobs:
  notify-slack:
    runs-on: small
    if: ${{ github.event.label.name == 'slack-notification'}}
    steps:
      - name: Send custom JSON data to Slack workflow
        id: slack
        uses: slackapi/slack-github-action@v1.23.0
        with:
          payload: |
            {
              "repository": "${{ github.repository }}",
              "pull_request_username": "${{ github.event.pull_request.user.login }}",
              "pull_request_title": "${{ github.event.pull_request.title }}",
              "pull_request_url": "${{ github.event.pull_request.html_url }}"
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

A possible fix for this could be having something like this following workflow but inside the GitHub Action.

name: Notifying slack
on:
  pull_request:
    types: [ labeled ]
jobs:
  variables:
    outputs:
      pr_title: ${{ steps.var.outputs.pr_title}}
    runs-on: small
    steps:
      - name: Setting global variables
        uses: actions/github-script@v6
        id: var
        with:
          script: |
            core.setOutput('pr_title', '${{ github.event.pull_request.title }}'.replaceAll(/[/"]/g, '\''));
  notify-slack:
    needs: [variables]
    runs-on: small
    if: ${{ github.event.label.name == 'slack-notification'}}
    steps:
      - name: Send custom JSON data to Slack workflow
        id: slack
        uses: slackapi/slack-github-action@v1.23.0
        with:
          payload: |
            {
              "repository": "${{ github.repository }}",
              "pull_request_username": "${{ github.event.pull_request.user.login }}",
              "pull_request_title": "${{ needs.variables.outputs.pr_title }}",
              "pull_request_url": "${{ github.event.pull_request.html_url }}"
            }
        env:
          SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK }}
          SLACK_WEBHOOK_TYPE: INCOMING_WEBHOOK

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions