Skip to content

trigger_comment may screw pipelinerun yaml with the the newline #1929

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

Closed
chmouel opened this issue Feb 13, 2025 · 0 comments · Fixed by #1934
Closed

trigger_comment may screw pipelinerun yaml with the the newline #1929

chmouel opened this issue Feb 13, 2025 · 0 comments · Fixed by #1934
Assignees

Comments

@chmouel
Copy link
Member

chmouel commented Feb 13, 2025

when we have a yaml with the {{trigger_comment}} expansion variable we may end up with bad yaml:

for example this pipelinerun:

apiVersion: tekton.dev/v1
kind: PipelineRun
metadata:
  name: prow-commands
  annotations:
    pipelinesascode.tekton.dev/pipeline: "https://raw.githubusercontent.com/openshift-pipelines/pac-boussole/main/pipeline-boussole.yaml"
    pipelinesascode.tekton.dev/on-comment: "^/(hello|merge|help|lgtm|(assign|unassign|label|unlabel)[ ].*)$"
    pipelinesascode.tekton.dev/max-keep-runs: "2"
spec:
  params:
    - name: trigger_comment
      value: |
        {{ trigger_comment }}
    - name: repo_owner
      value: "{{ repo_owner }}"
    - name: repo_name
      value: "{{ repo_name }}"
    - name: pull_request_number
      value: "{{ pull_request_number }}"
    - name: pull_request_sender
      value: "{{ body.issue.user.login }}"
    - name: git_auth_secret
      value: "{{ git_auth_secret }}"
    - name: comment_sender
      value: "{{ sender }}"
  pipelineRef:
    name: boussole

if i do a github comment with newlines like this

/help

it will be expanded to this:

Image

and then we get a parser error:

Image

because it's not a yaml anymore..

I suggest we change the trigger_comment to expand the \r\n to real \n the same way we do for pull_requests_labels:

https://pipelinesascode.com/docs/guide/matchingevents/#matching-pipelinerun-to-a-pull-request-labels

and let the user do it from their script... since there is no reliable way to do this and this is prone to bad user input interpolation

@chmouel chmouel self-assigned this Feb 14, 2025
chmouel added a commit to chmouel/pipelines-as-code that referenced this issue Feb 14, 2025
When using `{{ trigger_comment }}` in a PipelineRun YAML, GitHub
comments containing newlines (e.g., `/help`) can break YAML parsing due
to improper expansion.

This change replaces `\r\n` with `\n` in `trigger_comment`, similar to
how `pull_requests_labels` are handled. This ensures valid YAML
formatting and avoids parser errors.

Fixes openshift-pipelines#1929

Signed-off-by: Chmouel Boudjnah <[email protected]>
chmouel added a commit to chmouel/pipelines-as-code that referenced this issue Feb 14, 2025
When using `{{ trigger_comment }}` in a PipelineRun YAML, GitHub
comments containing newlines (e.g., `/help`) can break YAML parsing due
to improper expansion.

This change replaces `\r\n` with `\n` in `trigger_comment`, similar to
how `pull_requests_labels` are handled. This ensures valid YAML
formatting and avoids parser errors.

Fixes openshift-pipelines#1929

Signed-off-by: Chmouel Boudjnah <[email protected]>
chmouel added a commit to chmouel/pipelines-as-code that referenced this issue Feb 14, 2025
When using `{{ trigger_comment }}` in a PipelineRun YAML, GitHub
comments containing newlines (e.g., `/help`) can break YAML parsing due
to improper expansion.

This change replaces `\r\n` with `\n` in `trigger_comment`, similar to
how `pull_requests_labels` are handled. This ensures valid YAML
formatting and avoids parser errors.

Fixes openshift-pipelines#1929

Signed-off-by: Chmouel Boudjnah <[email protected]>
pipelines-as-code bot pushed a commit that referenced this issue Feb 14, 2025
When using `{{ trigger_comment }}` in a PipelineRun YAML, GitHub
comments containing newlines (e.g., `/help`) can break YAML parsing due
to improper expansion.

This change replaces `\r\n` with `\n` in `trigger_comment`, similar to
how `pull_requests_labels` are handled. This ensures valid YAML
formatting and avoids parser errors.

Fixes #1929

Signed-off-by: Chmouel Boudjnah <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant