GithubHelp home page GithubHelp logo

Comments (4)

LCSLITX avatar LCSLITX commented on July 27, 2024 1

Just to complement the previous answer, I found an alternate solution.

I experienced this same error and I added the following permissions to respective job: discussions: write; contents: read.

  create_discussion:
    needs: [job1]
    runs-on: ubuntu-latest
    # Added permissions
    permissions:
       discussions: write
       contents: read

    steps:
    - uses: actions/checkout@v4
    - name: Download all artifacts
      uses: actions/download-artifact@v4

    - name: Create a new GitHub Discussion
      id: create-discussion
      uses: abirismyname/[email protected]
      env:
        GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
      with:
        title: 'Title'
        body-filepath: 'path/to/file'
        repository-id: ${{ secrets.REPOSITORY_ID }}
        category-id: ${{ secrets.CATEGORY_ID }}
    - name: Print discussion URL
      run: |
        echo discussion-url: ${{steps.create-discussion.outputs.discussion-url}}

from create-discussion.

franzenr avatar franzenr commented on July 27, 2024

I'm also experiencing the same problem -- haven't been able to figure out a way around it yet

from create-discussion.

mbordash2 avatar mbordash2 commented on July 27, 2024

@franzenr what is your specific use case and does it involve cross-repository discussion? As far as I can tell, this is a permissions thing...but I haven't figured out a solution yet.

I am trying to create a new discussion in another repo from where the GHA is running, although within the same organization.

from create-discussion.

mbordash2 avatar mbordash2 commented on July 27, 2024

@franzenr I was able to get this working and it turned out to be really simple but hard to diagnose due to lack of sufficiently helpful error messages. Ultimately it was the token the GHA was using didn't have permissions to see the repository.

Some things to consider:

  • The token must be authorized for the organization if you have SSO enabled. Just creating a token without proper authorization will fail.
  • The new fine grained PAT token must be enabled for your organization. I ended up just using the classic token as this wasn't enabled to work properly on my org.

I ultimately created a small python program to test this out directly and was able to get better error messages that helped me out. Below is the code if you'd like to use it to help you diagnose.

def create_github_discussion(repo_id, title, body, category_id, token):
    url = "https://api.github.com/graphql"
    headers = {"Authorization": f"Bearer {token}"}
    query = """
        mutation($input: CreateDiscussionInput!) {
          createDiscussion(input: $input) {
            discussion {
              id
              url
            }
          }
        }
    """
    variables = {
        "input": {
            "repositoryId": repo_id,
            "title": title,
            "body": body,
            "categoryId": category_id,
            "clientMutationId": "test"
        }
    }
    response = requests.post(url, json={"query": query, "variables": variables}, headers=headers)

from create-discussion.

Related Issues (6)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.