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

Fetch status information for a given commit sha #2

Closed
sladyn98 opened this issue Feb 13, 2021 · 6 comments
Closed

Fetch status information for a given commit sha #2

sladyn98 opened this issue Feb 13, 2021 · 6 comments
Labels

Comments

@sladyn98
Copy link
Collaborator

We need to fetch the following information
a) Status
b) Context of the status check
c) If all checks have passed

@sladyn98
Copy link
Collaborator Author

I tried running this query

{
  repository(owner: "jenkinsci", name:"custom-distribution-service"){
    url
    pullRequest(number: 162){
        number
        url
        author {
          login
          url
        }
        commits(last: 1){
          nodes{
            commit{
              commitUrl
              oid
              status {
                state
                contexts {
                  state
                  targetUrl
                  description
                  context
                }
              }
            }
          }
        }
    }
  }
}

This was the data i got returned and as we can see it returns the status check for the commit

{
  "data": {
    "repository": {
      "url": "https://github.com/jenkinsci/custom-distribution-service",
      "pullRequest": {
        "number": 162,
        "url": "https://github.com/jenkinsci/custom-distribution-service/pull/162",
        "author": {
          "login": "sladyn98",
          "url": "https://github.com/sladyn98"
        },
        "commits": {
          "nodes": [
            {
              "commit": {
                "commitUrl": "https://github.com/jenkinsci/custom-distribution-service/commit/4648520244d8879c60ddcb2b53b78c6164b4715b",
                "oid": "4648520244d8879c60ddcb2b53b78c6164b4715b",
                "status": {
                  "state": "FAILURE",
                  "contexts": [
                    {
                      "state": "ERROR",
                      "targetUrl": "https://ci.jenkins.io/job/Tools/job/custom-distribution-service/job/PR-162/7/display/redirect",
                      "description": "The build of this commit was aborted",
                      "context": "continuous-integration/jenkins/pr-merge"
                    }
                  ]
                }
              }
            }
          ]
        }
      }
    }
  }
}

@ljharb
Copy link
Owner

ljharb commented Feb 13, 2021

@sladyn98
Copy link
Collaborator Author

sladyn98 commented Feb 13, 2021

Yeah I guess this is the issue so if I try to get the status of a repo I am not a collaborator for or dont have write access to the status returns null

{
  "data": {
    "repository": {
      "url": "https://github.com/es-shims/Promise.any",
      "pullRequest": {
        "number": 9,
        "url": "https://github.com/es-shims/Promise.any/pull/9",
        "author": {
          "login": "ljharb",
          "url": "https://github.com/ljharb"
        },
        "commits": {
          "nodes": [
            {
              "commit": {
                "commitUrl": "https://github.com/es-shims/Promise.any/commit/660317fd059f9b83980181ea1067b99d94c40351",
                "oid": "660317fd059f9b83980181ea1067b99d94c40351",
                "status": null
              }
            }
          ]
        }
      }

Edit: I do not think it would be an issue for us since the query user would have write access and the token

@ljharb
Copy link
Owner

ljharb commented Feb 13, 2021

hm, interesting. I can provide you a token if needed that has commit status read permissions, but I’d expect it to be globally readable.

@sladyn98
Copy link
Collaborator Author

@ljharb yeah, since the API is built in a way to provide statuses to only authenticated tokens with certain permissions. The CLI tool could start off with the token and then do the later stuff using that token. Does Not harm us to have 5000 requests per hour with an authenticated token

@sladyn98
Copy link
Collaborator Author

https://www.npmjs.com/package/hawk-fetch
Created a small npm package to get the status object in the response. Maybe we can extend the functionality of the package to later parse the statuses and do something with it.

thehanimo added a commit that referenced this issue Feb 18, 2021
Migrate to Yargs and update eslint config
@ljharb ljharb closed this as completed Aug 20, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants