gh icon indicating copy to clipboard operation
gh copied to clipboard

API version not a valid parameter for setting labels?

Open aghaynes opened this issue 3 months ago • 1 comments

Hi! This is a really useful package!

I'm playing around with it and noticed something that I find weird, but maybe I'm doing something wrong...

It's possible to set issue labels like this

repo <- "something"
issue <- xx
label <- "somelabel"
gh::gh(repo = repo,
       issue = issue,
       endpoint = "POST /repos/:repo/issues/:issue/labels",
       # .params = list("X-GitHub-Api-Version" = "2022-11-28"),
       labels = list(label))

and remove them again like this

gh::gh(repo = repo,
       issue = issue,
       endpoint = "DELETE /repos/:repo/issues/:issue/labels/:label",
       .params = list("X-GitHub-Api-Version" = "2022-11-28"),
       label = label)

The weird thing is that as soon as i uncomment the API version number from the code to set a label, I get an error.

Error in `gh::gh()`:
! GitHub API error (422): Invalid request.  No subschema in "anyOf" matched. For 'anyOf/0',
  {"body"=>{"labels"=>["somelabel"]}, "X-GitHub-Api-Version"=>"2022-11-28"} is not an array. For 'anyOf/1',
  {"body"=>{"labels"=>["somelabel"]}, "X-GitHub-Api-Version"=>"2022-11-28"} is not an array.
  "X-GitHub-Api-Version", "body" are not permitted keys. "labels" wasn't supplied.
ℹ Read more at <https://docs.github.com/rest/issues/labels#add-labels-to-an-issue>

Other endpoints also work with code similar to above, e.g. the following for posting a comment:

gh::gh(repo = repo,
       issue = issue,
       endpoint = "POST /repos/:repo/issues/:issue/comments",
       .params = list("X-GitHub-Api-Version" = "2022-11-28"),
       body = comment)

I assume that something is thus off with the API, but I'm not sure. Do you have any idea?

aghaynes avatar Apr 02 '24 14:04 aghaynes

Are you trying to send a header? That's .send_headers, not params.

gaborcsardi avatar Apr 02 '24 14:04 gaborcsardi

Ah! Indeed! The version is a header parameter... Thanks! I still find it odd that the POST labels endpoint is the only one to complain about the version being in the params, but i guess that doesnt matter so much.

aghaynes avatar Apr 03 '24 05:04 aghaynes