octokit / request-action

A GitHub Action to send arbitrary requests to GitHub's REST API

Home Page:https://github.com/marketplace/actions/GitHub-API-Request

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

String with colon is loaded as object

robingenz opened this issue · comments

First of all, thanks for this helpful GitHub action!

I want to use this action to delete a specific label whenever a comment is created on an issue.
The label is: needs: reply.

This is my workflow:

name: Remove needs-reply label

on:
  issue_comment:
    types:
      - created

jobs:
  needs-reply:
    runs-on: ubuntu-latest
    steps:
      - name: Remove needs-reply label
        uses: octokit/request-action@v2.x
        continue-on-error: true
        with:
          route: DELETE /repos/:repository/issues/:issue/labels/:label
          repository: ${{ github.repository }}
          issue: ${{ github.event.issue.number }}
          label: 'needs: reply'
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

I get the following error when running the action:

Error: Label does not exist

(see this example)

The following request works:

curl --location --request DELETE 'https://api.github.com/repos/{user}/{repo}/issues/{issue}/labels/needs: reply' \
--header 'Authorization: token {token}'

For this reason, I assume that the error lies with the action.
Please let me know if you need more information.
Thank you very much!

You get the error when the label no longer exists on the issue. Try running the curl command twice to replicate.

Does the action work the first time? My guess is that the action is run again after the label was removed. You can add an if: condition to the step or the job to make sure it doesn't.

If it fails the first time, can you create a minimal public repository to replicate the problem? I'll have a look

I get the error even if the label still exists.
If I call the label needs-reply (for example), then it works as desired. The problem only occurs if there is a colon/space in the name.

I created a minimal public repository: robingenz/octokit-request-action-issues-118.
This is my demo issue: robingenz/octokit-request-action-issues-118#1
I added the label needs: reply and commented a few minutes later.
The workflow was executed (see here) and returned the following error message:

 Error: Label does not exist

The label is still present.

I created a minimal public repository: robingenz/octokit-request-action-issues-118.

thanks!

The problem only occurs if there is a colon/space in the name.

that very much sounds like a YAML problem 😌

You see how it says label: [object Object]? It should say label: "needs: reply" instead.

image

It's likely related to how we load the YAML config here:

result[inputName] = yaml.load(value);

Here is a test case to confirm my assumption

https://runkit.com/gr2m/octokit-request-action-118

I'm open to ideas how to fix it. The reason why we do load value this way is that some parameters need to be set to objects, that's why we have the complex example in the readme with this line:

          output: | # The | is significant!

I think you can probably workaround the problem you are having by doing the following

-          label: 'needs: reply'
+          label: |
+            |
+              needs: label

Can you give that a try?

Ideally we would support the label: 'needs: reply' out of the box. But I'm not sure how to be sure that the user didn't intend to send label: { needs: 'reply' }

maybe there is some YAML escape syntax that we can recommend to use for cases such as yours? I'm not super familiar with YAML though, not sure what the correct one would be, I always get lost in the YAML spec

Thank you for pointing this out.
I am also not very familiar with YAML.

-          label: 'needs: reply'
+          label: |
+            |
+              needs: label

Unfortunately, this did not work (workflow run / comment).

I also tried:

label: >
  needs: reply

label: >-
  needs: reply

label: "
  needs: reply"

label: |-
  needs: reply

I couldn't find any YAML escape syntax so far.

I will look for other possible solutions over the weekend.
Please let me know if you have any other ideas.

Hmm at least the workflow run output looks correct:
https://github.com/robingenz/octokit-request-action-issues-118/runs/3527025647#step:2:16

image

Can you please enable DEBUG logs by adding the ACTIONS_STEP_DEBUG secret and setting it to true

It seems that the string now is

needs: reply

With a line break at the end.

Can you try this please?

label: |
  |-
    needs: reply

Gosh this syntax makes me cringe 🤣

I enabled the debug logs.

However, the line break did not move. 😄

My temporary workaround:

name: Remove needs-reply label

on:
  issue_comment:
    types:
      - created

jobs:
  needs-reply:
    runs-on: ubuntu-latest
    steps:
      - name: Remove needs-reply label
        run: |
          curl --request DELETE \
          --url 'https://api.github.com/repos/${{ github.repository }}/issues/${{ github.event.issue.number }}/labels/needs%3A%20reply' \
          --header 'Authorization: token ${{ secrets.GITHUB_TOKEN }}'

Just in case anyone else is looking for a quick fix.

Short update: Unfortunately, I have not found a syntax that works. As soon as I have some more time I will try to find a fix for the action. Until then, I'll use my workaround.

I have fixed a similar issue by adding an extra '

Before: tag_name: "${{ env.tag_name }}" was parsed as a number when tag_name was 2023.07
After: tag_name: "'${{ env.tag_name }}'" was correctly parsed as a string

For context see: dodona-edu/dodona#4808