Skip to content

Calls to search.issuesAndPullRequests are dropping the "q" parameter #114

@andyedwardsibm

Description

@andyedwardsibm

Checklist

Environment

Versions

  ├─┬ @octokit/rest@18.10.0
  │ ├─┬ @octokit/core@3.5.1
  │ │ ├─┬ @octokit/auth-token@2.5.0
  │ │ ├─┬ @octokit/graphql@4.8.0
  │ │ ├─┬ @octokit/request@5.6.1
  │ │ │ ├─┬ @octokit/endpoint@6.0.12
  │ │ ├─┬ @octokit/request-error@2.1.0
  │ │ ├─┬ @octokit/types@6.28.1
  │ │ │ └── @octokit/openapi-types@10.2.2
  │ ├─┬ @octokit/plugin-paginate-rest@2.16.3
  │ ├── @octokit/plugin-request-log@1.0.4
  │ └─┬ @octokit/plugin-rest-endpoint-methods@5.10.4

What happened?

I recently updated my Node dependencies and calls to octokit.rest.search.issuesAndPullRequests have stopped working and now report an error containing {"message":"Validation Failed","errors":[{"resource":"Search","field":"q","code":"missing"}

Minimal test case to reproduce the problem

I've installed octokit/rest fresh today. When I run this snippet below...

const Octokit = require('@octokit/rest').Octokit

async function main () {
  const octokit = new Octokit({})
  const q = 'properties+is:issue+repo:"octokit/rest"+label:bug'
  const issuesFound = await octokit.rest.search.issuesAndPullRequests({ q })
  console.log(`${JSON.stringify(issuesFound)}`)
}

main().catch(e => {
  console.log(JSON.stringify(e, null, 2))
})

I get the error below:

{
  "name": "HttpError",
  "status": 422,
  "response": {
    "url": "https://api.github.com/search/issues?q=properties+is%3Aissue+repo%3A%22octokit%2Frest%22+label%3Abug",
    "status": 422,
    "headers": {
      "access-control-allow-origin": "*",
      "access-control-expose-headers": "ETag, Link, Location, Retry-After, X-GitHub-OTP, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Used, X-RateLimit-Resource, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval, X-GitHub-Media-Type, Deprecation, Sunset",
      "cache-control": "no-cache",
      "connection": "close",
      "content-length": "149",
      "content-security-policy": "default-src 'none'",
      "content-type": "application/json; charset=utf-8",
      "date": "Tue, 21 Sep 2021 13:42:20 GMT",
      "referrer-policy": "origin-when-cross-origin, strict-origin-when-cross-origin",
      "server": "GitHub.com",
      "strict-transport-security": "max-age=31536000; includeSubdomains; preload",
      "vary": "Accept, Accept-Encoding, Accept, X-Requested-With",
      "x-content-type-options": "nosniff",
      "x-frame-options": "deny",
      "x-github-media-type": "github.v3; format=json",
      "x-github-request-id": "EB7C:DD2A:1CBEB1D:1D4B13C:6149E145",
      "x-ratelimit-limit": "10",
      "x-ratelimit-remaining": "8",
      "x-ratelimit-reset": "1632231800",
      "x-ratelimit-resource": "search",
      "x-ratelimit-used": "2",
      "x-xss-protection": "0"
    },
    "data": {
      "message": "Validation Failed",
      "errors": [
        {
          "resource": "Search",
          "field": "q",
          "code": "missing"
        }
      ],
      "documentation_url": "https://docs.github.com/v3/search"
    }
  },
  "request": {
    "method": "GET",
    "url": "https://api.github.com/search/issues?q=properties+is%3Aissue+repo%3A%22octokit%2Frest%22+label%3Abug",
    "headers": {
      "accept": "application/vnd.github.v3+json",
      "user-agent": "octokit-rest.js/18.7.1 octokit-core.js/3.5.1 Node.js/14.16.1 (linux; x64)"
    },
    "request": {}
  }
}

The error is claiming that the q parameter is missing, but it is specified in the code and is echoed in the error. I find the same behaviour when talking to an enterprise instance with a personal access token.

If I make the equivalent curl call (i.e. curl "https://api.github.com/search/issues?q=properties+is%3Aissue+repo%3A%22octokit%2Frest%22+label%3Abug") then I get the error below...

{
  "message": "Validation Failed",
  "errors": [
    {
      "message": "The listed users and repositories cannot be searched either because the resources do not exist or you do not have permission to view them.",
      "resource": "Search",
      "field": "q",
      "code": "invalid"
    }
  ],
  "documentation_url": "https://docs.github.com/v3/search/"
}

... which is what I'd expect (there is a q value, but I'm not allowed to see the results).

If I change my snippet code such that const octokit = new Octokit({ baseUrl: 'http://localhost:12345' }) and have netcat listening on 12345 then I see the following request come in...

GET /search/issues HTTP/1.1
accept: application/vnd.github.v3+json
user-agent: octokit-rest.js/18.7.1 octokit-core.js/3.5.1 Node.js/14.16.1 (linux; x64)
Accept-Encoding: gzip,deflate
Connection: close
Host: localhost:12345


... so the endpoint isn't wrong; the q parameter is not being added to the request URL any more

What did you expect to happen?

Calls to octokit.rest.search.issuesAndPullRequests({ q }) would return a list of issues (or at least include the q parameter in the outgoing call)

What the problem might be

Other than it's a change made since about June somewhere in one of the octokit dependencies, I've not yet found where the parameter is being dropped

Metadata

Metadata

Assignees

Labels

Type: BugSomething isn't working as documented

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions