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

[BUG]: Different result from a graphql postman request than from a github action/ github explorer graphql #276

Open
1 task done
MatthieuGomes opened this issue Nov 13, 2024 · 2 comments
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented

Comments

@MatthieuGomes
Copy link

What happened?

I'm trying to get (not only, but that's part of the process) the number of the project associated with the repository from which pull request occurs. To do so, I found out that I need to use graphql requests. So I tested my queries first on Postman... And I happily found a way (yay). But, when I try to get the same result from github actions or explorer, the result is always empty on the fields that matters in this discussion and it's driving me crazy.

The repository is part of an organization but :

  1. No problem in postman
  2. A get all the informations I need EXCEPT the things about the ProjectsV2's nodes !

Here's the query

query ($repo: String!, $organisation: String!, $pull_request_number: Int!) {
              organization(login: $organisation) {
                repository(name: $repo, followRenames: true) {
                  pullRequest(number: $pull_request_number) {
                    body
                    commits(first: 100) {
                      nodes {
                        commit {
                          message
                        }
                      }
                    }
                  }
                  projectsV2(first: 1) {
                      totalCount
                      nodes {
                        number
                      }
                  }
                  recentProjects(first: 10) {
                    nodes {
                      number
                      title
                    }
                  }
                }
              }
            }

Here is the yaml for the github actions

ame: AutoMoveTickets

on:
  pull_request:
    types: [opened,reopened]

env: 
  repo: ${{ github.repository }}
  organisation: ${{ github.repository_owner }}
  pull_request_number: ${{ github.event.number}}

jobs:

  move_mentionned_tickets:
    runs-on: ubuntu-latest
    steps:
      - name: Get Issues Cited of PR 1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        id: get_infos
        uses: octokit/[email protected]
        with:
          query: |
            query ($repo: String!, $organisation: String!, $pull_request_number: Int!) {
              organization(login: $organisation) {
                repository(name: $repo, followRenames: true) {
                  pullRequest(number: $pull_request_number) {
                    body
                    commits(first: 100) {
                      nodes {
                        commit {
                          message
                        }
                      }
                    }
                  }
                  projectsV2(first: 1) {
                      totalCount
                      nodes {
                        number
                      }
                  }
                }
              }
            }
          variables: |
            repo: ${{ github.event.repository.name }}
            organisation : ${{ github.repository_owner }}
            pull_request_number : ${{ github.event.number }}
      - run : "echo ${{ steps.get_infos.outputs.data }}"

(in case you wonder : it's just for test currently and the echo doesnt work BUT i can read the object supposed to be echoed in the log error, so it's fine ^^)

Then, here is the result from such command with a PAT with Postman

{
    "data": {
        "organization": {
            "repository": {
                "pullRequest": {
                    "body": "",
                    "commits": {
                        "nodes": [
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Update auto_move_tickets.yml"
                                }
                            },
                            {
                                "commit": {
                                    "message": "nouveau test"
                                }
                            },
                            {
                                "commit": {
                                    "message": "correction"
                                }
                            },
                            {
                                "commit": {
                                    "message": "re correction?"
                                }
                            },
                            {
                                "commit": {
                                    "message": "re correction encore ?"
                                }
                            },
                            {
                                "commit": {
                                    "message": "test"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Retest"
                                }
                            },
                            {
                                "commit": {
                                    "message": "re"
                                }
                            },
                            {
                                "commit": {
                                    "message": "re correction"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Nouvelle correction"
                                }
                            },
                            {
                                "commit": {
                                    "message": "Nouvelles datas à lire"
                                }
                            },
                            {
                                "commit": {
                                    "message": "rerererere"
                                }
                            },
                            {
                                "commit": {
                                    "message": "rerererererere"
                                }
                            },
                            {
                                "commit": {
                                    "message": "nouvelles infos"
                                }
                            }
                        ]
                    }
                },
                "projectsV2": {
                    "totalCount": 1,
                    "nodes": [
                        {
                            "number": 7
                        }
                    ]
                }
            }
        }
    }
}

And there is the result from github action using the token generated by github action ITSELF.

"data":{
  "organization": {
      "repository": {
        "pullRequest": {
          "body": "",
          "commits": {
            "nodes": [
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "nouveau test"
                }
              },
              {
                "commit": {
                  "message": "correction"
                }
              },
              {
                "commit": {
                  "message": "re correction?"
                }
              },
              {
                "commit": {
                  "message": "re correction encore ?"
                }
              },
              {
                "commit": {
                  "message": "test"
                }
              },
              {
                "commit": {
                  "message": "Retest"
                }
              },
              {
                "commit": {
                  "message": "re"
                }
              },
              {
                "commit": {
                  "message": "re correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelle correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelles datas à lire"
                }
              },
              {
                "commit": {
                  "message": "rerererere"
                }
              },
              {
                "commit": {
                  "message": "rerererererere"
                }
              },
              {
                "commit": {
                  "message": "nouvelles infos"
                }
              }
            ]
          }
        },
        "projectsV2": {
          "totalCount": 0,
          "nodes": []
        }
      }
    }
  }

And I have the same problem with github explorer...

Can someone help ? T.T

Versions

2.0.1

Relevant log output

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct
@MatthieuGomes MatthieuGomes added Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented labels Nov 13, 2024
Copy link

👋 Hi! Thank you for this contribution! Just to let you know, our GitHub SDK team does a round of issue and PR reviews twice a week, every Monday and Friday! We have a process in place for prioritizing and responding to your input. Because you are a part of this community please feel free to comment, add to, or pick up any issues/PRs that are labeled with Status: Up for grabs. You & others like you are the reason all of this works! So thank you & happy coding! 🚀

@MatthieuGomes
Copy link
Author

[UPDATE]: This seems to be a token issue.

I tried (and it was a pain) to use curl with my PAT to make the graphql request and it gave me the right result...

here is the curl command, with obsfucated PAT, REPO and ORGANISATION, and the result :

curl -X POST  https://api.github.com/graphql -H "Content-Type: application/json" -H "Authorization: Bearer PAT" -d '{"query": "query { organization(login: \"ORGANISATION\") { repository(name: \"REPO\", followRenames: true) { pullRequest(number: 39) { body commits(first: 100) { nodes { commit { message } } } } projectsV2(first: 1) { totalCount nodes { number } } } } }"}' | jq
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  1390  100  1132  100   258   1668    380 --:--:-- --:--:-- --:--:--  2050
{
  "data": {
    "organization": {
      "repository": {
        "pullRequest": {
          "body": "",
          "commits": {
            "nodes": [
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "nouveau test"
                }
              },
              {
                "commit": {
                  "message": "correction"
                }
              },
              {
                "commit": {
                  "message": "re correction?"
                }
              },
              {
                "commit": {
                  "message": "re correction encore ?"
                }
              },
              {
                "commit": {
                  "message": "test"
                }
              },
              {
                "commit": {
                  "message": "Retest"
                }
              },
              {
                "commit": {
                  "message": "re"
                }
              },
              {
                "commit": {
                  "message": "re correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelle correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelles datas à lire"
                }
              },
              {
                "commit": {
                  "message": "rerererere"
                }
              },
              {
                "commit": {
                  "message": "rerererererere"
                }
              },
              {
                "commit": {
                  "message": "nouvelles infos"
                }
              }
            ]
          }
        },
        "projectsV2": {
          "totalCount": 1,
          "nodes": [
            {
              "number": 7
            }
          ]
        }
      }
    }
  }
}

And, after configuring (with pain, again) GitHub CLI to use my PAT instead of the default generated token (with no modifyable scope), the command works fine with GitHub CLI :

gh api graphql -f query='query { organization(login: "ORGANISATION") { repository(name: "REPO", followRenames: true) { pullRequest(number: 39) { body commits(first: 100) { nodes { commit { message } } } } projectsV2(first: 1) { totalCount nodes { number } } } } }'
{
  "data": {
    "organization": {
      "repository": {
        "pullRequest": {
          "body": "",
          "commits": {
            "nodes": [
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "Update auto_move_tickets.yml"
                }
              },
              {
                "commit": {
                  "message": "nouveau test"
                }
              },
              {
                "commit": {
                  "message": "correction"
                }
              },
              {
                "commit": {
                  "message": "re correction?"
                }
              },
              {
                "commit": {
                  "message": "re correction encore ?"
                }
              },
              {
                "commit": {
                  "message": "test"
                }
              },
              {
                "commit": {
                  "message": "Retest"
                }
              },
              {
                "commit": {
                  "message": "re"
                }
              },
              {
                "commit": {
                  "message": "re correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelle correction"
                }
              },
              {
                "commit": {
                  "message": "Nouvelles datas à lire"
                }
              },
              {
                "commit": {
                  "message": "rerererere"
                }
              },
              {
                "commit": {
                  "message": "rerererererere"
                }
              },
              {
                "commit": {
                  "message": "nouvelles infos"
                }
              }
            ]
          }
        },
        "projectsV2": {
          "totalCount": 1,
          "nodes": [
            {
              "number": 7
            }
          ]
        }
      }
    }
  }
}

My questions are now those ones :

  • Why the github generated token doesn't seem to have equivalent right as my personnal access token (full authorization) ?
  • Why don't have ANY error message on this issue and instead an empty array ?
  • How to change the permissions of this generated token (if the issue comes from here, of course) ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Status: Triage This is being looked at and prioritized Type: Bug Something isn't working as documented
Projects
Status: 🆕 Triage
Development

No branches or pull requests

1 participant