actions / github-script

Write workflows scripting the GitHub API in JavaScript
MIT License
4.24k stars 424 forks source link

How to add an issue to a project? #427

Closed guardrex closed 1 year ago

guardrex commented 1 year ago

The documentation at https://github.com/marketplace/actions/github-script is a bit incomplete on basic tasks.

I've worked out most of what I need to do, but one task eludes me ... how do I add an issue to a project?

I can imagine a job like this ...

  add-projects:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v6
        with:
          script: |
            github.rest.issues.addProjects({
              issue_number: context.issue.number,
              owner: context.repo.owner,
              repo: context.repo.repo,
              projects: [35]
            })

How is it actually done?

Perhaps along the lines of ...

  create-card:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/github-script@v6
        with:
          script: |
            github.rest.projects.createCard({
              column_id: 4248551,
              content_id: context.payload.issue.id,
              content_type: "Issue"
            })

... where 4248551 is the "Triage" column from my project, which is found via the link to the column. Even if close, it's not super clear how it knows the project number. I assume the column_id is unique across projects, and that's how it adds it to the correct project.

However, that approach isn't working. Could it be because the project is a classic GH project, and that code will only work with a late-model project?

Any assistance greatly appreciated!

Here's the workflow that I'm working with. The highlight is the code I show above placed in the process-blazor-issue job ...

https://github.com/dotnet/AspNetCore.Docs/blob/main/.github/workflows/issue-processing.yml#L123-L130

This is the project that I'm trying to add issues to (the Triage column is 4248551) ...

https://github.com/dotnet/AspNetCore.Docs/projects/35

Everything above the last step works fine. This is the only part of the workflow that I can't get working.

guardrex commented 1 year ago

I've updated the project from a classic project to a latest-version GH project.

However, there's no option to get the URL for the column, so the column ID isn't clear, unless it's the <div> of of that column in markup (which seems rather unlikely): 2528996e

guardrex commented 1 year ago

Looks promising ...

https://github.com/orgs/community/discussions/66878#discussioncomment-7018566

Am I supposed to use the GH CLI now to get a column ID?

guardrex commented 1 year ago

Looks like I merely don't have the correct column ID. Looks like I'll need to use the GH CLI to obtain it because it's no longer possible to grab from a column URL now that I've migrated the project from classic.

I'll close now on that basis. Thanks for everyone's help here.