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

String with colon is loaded as object #118

Open
robingenz opened this issue Sep 4, 2021 · 12 comments
Open

String with colon is loaded as object #118

robingenz opened this issue Sep 4, 2021 · 12 comments
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects

Comments

@robingenz
Copy link

robingenz commented Sep 4, 2021

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!

@ghost ghost added this to Inbox in JS Sep 4, 2021
@gr2m
Copy link
Contributor

gr2m commented Sep 5, 2021

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

@gr2m gr2m added the Type: Support Any questions, information, or general needs around the SDK or GitHub APIs label Sep 5, 2021
@ghost ghost moved this from Inbox to Support in JS Sep 5, 2021
@robingenz
Copy link
Author

robingenz commented Sep 5, 2021

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.

@gr2m
Copy link
Contributor

gr2m commented Sep 5, 2021

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' }

@gr2m
Copy link
Contributor

gr2m commented Sep 5, 2021

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

@robingenz
Copy link
Author

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.

@gr2m
Copy link
Contributor

gr2m commented Sep 6, 2021

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

@gr2m
Copy link
Contributor

gr2m commented Sep 6, 2021

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 🤣

@robingenz
Copy link
Author

I enabled the debug logs.

However, the line break did not move. 😄

@gr2m
Copy link
Contributor

gr2m commented Sep 6, 2021

At least now I'm positive that there is a line break at the end:
https://github.com/robingenz/octokit-request-action-issues-118/runs/3527613745?check_suite_focus=true#step:2:113

image

@robingenz
Copy link
Author

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.

@robingenz robingenz changed the title Label does not exist String with colon is loaded as object Sep 7, 2021
@robingenz
Copy link
Author

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.

@jorg-vr
Copy link

jorg-vr commented Jul 5, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Support Any questions, information, or general needs around the SDK or GitHub APIs
Projects
No open projects
JS
  
Support
Development

No branches or pull requests

3 participants