vsoch / pull-request-action

open a pull request when a branch is pushed or updated

Home Page:https://github.com/marketplace/actions/pull-request-action

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Environment Variable Inputs bug

brandon-kyle-bailey opened this issue · comments

Hi,

Have an issue that im not sure how to approach for a solution.

problem:

  • environment variable inputs either not being set, or being set incorrectly on PR creation.

example:

code:

 name: Pull Request to Production on Push to Development branch
 
 on:
     push:
         branches:
             - development
 
 jobs:
   auto-pull-request:
     name: Auto Pull Request to Master
     runs-on: ubuntu-latest
     steps:
       - name: pull-request-action
         uses: vsoch/pull-request-action@1.0.5
         env:
           GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
           PULL_REQUEST_TITLE: ${{github.event.head_commit.message}}
           PULL_REQUEST_ASSIGNEES: ${{github.event.head_commit.author.name}}
  • the title variable seems to pick up extra information in the commit message.
  • the assignees variables doesn't assign any specified users to the PR.

I have tried setting the assignees manually with:

           PULL_REQUEST_ASSIGNEES: "brandon-kyle-bailey"

to no avail.

Does anyone have any ideas?

Thanks,

hey @brandon-kyle-bailey - I'd be happy to help you with this! Let's walk through each component one step at a time.

  • version: looks like you are using 1.0.5, which is the latest that supports assignees, so we are good there

We can look at output for the action to see what variables it is seeing:

image

In the above I see that the pull request title is set to this commit

Pull request title is Merge pull request #54 from brandon-kyle-bailey/issue#37

And for the assignee, I see:

PULL_REQUEST_ASSIGNEES is set, Brandon

So from the above I'd say that your Title is working correctly, but for assignee you are using your GitHub "name" and not the "login" (if I remember correctly). Could you find the page where the payload is described and verify what field has the username? You would need to change this line:

          PULL_REQUEST_ASSIGNEES: ${{github.event.head_commit.author.name}}

to something else. I don't remember off the top of my head, but I'd use something like sender.login.
A nice approach for debugging like this is to add a step where you can print additional variables you are interested in (if the action doesn't do it for you, which this one does.)

    steps:
      - name: pull-request-action
        env:
          PULL_REQUEST_TITLE: ${{github.event.head_commit.message}}
          PULL_REQUEST_ASSIGNEES: ${{github.event.head_commit.author.name}}
        runs: |
            echo "${PULL_REQUEST_TITLE}"   
            echo "${PULL_REQUEST_ASSIGNEES}"   

So that should be enough I think for you to at least get started. If you would like to do a test run and echo those variables, and then direct me to the Action output where they are printed (and the action fails) I'd be happy to take a look. Also keep in mind that assignees and reviewers need to have admin on the repo, or be someone that you could assign manually in the interface (all other cases are ignored).

the title variable seems to pick up extra information in the commit message.

If you are setting your title to be the commit message:

PULL_REQUEST_TITLE: ${{github.event.head_commit.message}}

I don't think this should be a surprise. If you want to cut / truncate or otherwise edit it, you would need to insert another run statement before the action to set that environment variable, and then set it again in the run for the next action (changed).

Hey @vsoch ,

Thanks for getting back to me. I'll run another test with your advice and get back to you.

Regarding the ASSIGNEES:

If i point you to this action : this action

You can see:

PULL_REQUEST_ASSIGNEES is set,  brandon-kyle-bailey bot

In a previous test of this action file, i had the following code:

PULL_REQUEST_ASSIGNEES: "brandon-kyle-bailey bot"

Which is a space separated string as suggested by the documentation. This also failed to set any ASSIGNEES once the PR was created.

Is there something i'm missing in the workflow? should the PR be created in draft mode?

Thanks again for your help

Thanks for linking me to the action! That example that you linked this time around is correct usage. I see the issue - the dashes are not being properly parsed:

image

I'll see if I can reproduce locally and update the action to address. Stay tuned!

Thanks for linking me to the action! That example that you linked this time around is correct usage. I see the issue - the dashes are not being properly parsed:

image

I'll see if I can reproduce locally and update the action to address. Stay tuned!

Wow, i really should start wearing my glasses when i read logs lol... Thanks for looking in to that. in the mean time, i can attempt to escape the dashes and see if that works!

Yep @vsoch , no luck with escaping special characters. I guess i found an annoying edge case?

You found a very interesting case actually! I came down to a difference in the sed that is on my local machine vs. GitHub actions, and the fix was to parse it another way. I've opened a PR with branch fix/assignee-reviewer-parsing to test this change, linked above, #33, would you care to update your current testing PR with that branch (e.g., vsoch/pull-request-action@fix/assignee-reviewer-parsing) and then link me to the action run, and we can go from there?

Hey @vsoch sure thing.

  • Test action can be found here
  • Test PR can be found here

Seems to now be behaving as expected!

Awesome! So happy to hear! I'll get the PR merged and a release drafted asap for you to use! I think this will be 1.0.6. Be back soon!

Amazing, you're a saint. Thanks for the swift resolution !

okay all set! The release is out https://github.com/vsoch/pull-request-action/releases/tag/1.0.6 so you should get the same functionality with 1.0.6. I'm also going to be deleting the PR branch so be sure to update your test with the release version.

And you are so sweet! Always happy to help :) Happy pull requesting!