srggrs / assign-one-project-github-action

Automatically add an issue or pull request to specific GitHub Project(s) when you create and/or label them.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

MY_GITHUB_TOKEN not defined

TheFlyer1983 opened this issue · comments

Hi,

I am trying to create an issue in a personal repo, but the add it to a user project board (https://github.com/users/TheFlyer1983/projects/5) for example. I keep getting an error in my action saying:
MY_GITHUB_TOKEN not defined.

I have created a PAT named MY_GITHUB_TOKEN but whenever I run it I get the error, and my job fails.

My workflow is detailed below.

name: Add Issues
on: 
  issues:
    types:
      - opened
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
  
jobs:
  add_issues:
    runs-on: ubuntu-latest
    steps:
      - name: Assign to One Project
        uses: srggrs/assign-one-project-github-action@1.2.1
        if: github.event.action == 'opened'
        with:
          project: https://github.com/users/TheFlyer1983/projects/1
          column_name: 'Backlog'

I was wondering if you could help resolve my issue?

@TheFlyer1983 Is that PAT called MY_GITHUB_TOKEN added to your repository as a repository secret?
Check out this doc on how to do that. Make sure you name the secret MY_GITHUB_TOKEN and then put your PAT in as the secret value.

I should also add that you shouldn't need to create a PAT and add the secret if you are operating the automation in the same repo as the issues and project board. just use the built in secret as shown here.

Hope that helps!

@zkoppert the PAT was called MY_GITHUB_TOKEN and added to a repository as a repository secret (with all the possible permissions and added as a repo secret to all the needed repositories) but still doesn't work. Cannot figure out why. Is the action working?

@TheFlyer1983 any success? were you able to set it up?

@zkoppert Thank you for your help.

I've just tried this on a test Repo and it's working. Just one further question. I have Beta access to the new projects. I'm assuming there is no real difference between adding cards to the projects, so this action should still work as expected?

@ayakalauova Yes I have managed to get this working properly on my test repo. I will now be looking at moving it over to the actual repo I need it for.

I started by creating a PAT with every permission, and then took that PAT and added into a repo secret in my repo where the issue is as MY_GITHUB_TOKEN, then used the following code in my action to access this:

Screenshot 2021-10-14 at 15 17 04

Created an issue and the action was successful. I then went through the PAT and removed all permission that weren't needed, and created a new issue and the action was successful.

After testing I found that the only permissions that I needed were:

Screenshot 2021-10-14 at 15 20 14

I hope this works for you.

@zkoppert @TheFlyer1983 Thank you so much! It really helps. But one thing that I noticed is that after my job fails it gives me "GITHUB_TOKEN not defined" error instead of "MY_GITHUB_TOKEN not defined". Any clue what might be the reason? (I'm attempting cross private repository option inside an organization)

@ayakalauova The GITHUB_TOKEN is an automatically generated secret that lets you make authenticated calls to the GitHub API in your workflow runs. Actions generates a new token for each job and expires the token when a job completes.
Check out https://github.blog/changelog/2021-04-20-github-actions-control-permissions-for-github_token/ for details.

In order to get permissions for other repos you need to create a new token named something else. Here is the way to do that. https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-token

@zkoppert that's something I already did (I followed all the instructions above) and that is the reason I'm a bit confused

Did you name your token GITHUB_TOKEN ?

@zkoppert nope, it's MY_GITHUB_TOKEN (in the action itself and in the secret)

Can you post what your workflow file looks like?

name: Auto Assign to Project(s)

on:
  issues:
    types: [created, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign issues from Business to Bi Team Board
      uses: srggrs/assign-one-project-github-action@1.2.1
      if: |
        contains(github.event.issue.labels.*.name, 'bi-issue')
      with:
        project: 'https://github.com/Test12345667t743895739/bi/projects/1'
        column_name: 'To Do'

Hmm that doesn't make much sense to me. I'm not sure what is happening.

name: Auto Assign to Project(s)

on:
  issues:
    types: [created, labeled]
env:
  MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}

jobs:
  assign_one_project:
    runs-on: ubuntu-latest
    name: Assign to One Project
    steps:
    - name: Assign issues from Business to Bi Team Board
      uses: srggrs/assign-one-project-github-action@1.2.1
      if: |
        contains(github.event.issue.labels.*.name, 'bi-issue')
      with:
        project: 'https://github.com/Test12345667t743895739/bi/projects/1'
        column_name: 'To Do'

env:
MY_GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

if you try like this?

I'm also receiving this error. Has anyone found a solution?