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

Pass table to format templated endpoint #888

Merged
merged 3 commits into from
Feb 24, 2025

Conversation

wd60622
Copy link
Collaborator

@wd60622 wd60622 commented Feb 23, 2025

Describe what this PR does / why we need it

Closes #821

Use the format parameter to format a templated endpoint string

local gh = require "octo.gh"

local endpoint = "/repos/{owner}/{repo}/issues/{issue_number}"

local opts = { cb = gh.create_callback {} }

gh.api.get { 
  endpoint, 
  format = { owner = "pwntester", repo = "octo.nvim", issue_number = 1 },
  jq = "{ title, body, author: .user.login }",
  opts = opts,
}

However, the format parameter is not required. If it is not provided, the endpoint string is used as is (current behavior).

local gh = require "octo.gh"

local endpoint = "/repos/pwntester/octo.nvim/issues/1"

local opts = { cb = gh.create_callback {} }

gh.api.get { 
  endpoint, 
  jq = "{ title, body, author: .user.login }",
  opts = opts,
}

CC: @ldelossa

Does this pull request fix one issue?

Describe how you did it

Describe how to verify it

Special notes for reviews

Checklist

  • Passing tests and linting standards
  • Documentation updates in README.md and doc/octo.txt

@wd60622 wd60622 linked an issue Feb 23, 2025 that may be closed by this pull request
@github-actions github-actions bot added maintenance request discussion Feedback is welcomed! labels Feb 23, 2025
@wd60622 wd60622 removed the request discussion Feedback is welcomed! label Feb 23, 2025
@ldelossa
Copy link
Contributor

Awesome!

@wd60622
Copy link
Collaborator Author

wd60622 commented Feb 23, 2025

How is the name? Make sense or is something else better?

@ldelossa
Copy link
Contributor

Which name

@wd60622
Copy link
Collaborator Author

wd60622 commented Feb 24, 2025

Using format as the designated keyword. Something better suited?

One parallel with api.graph is the fields parameter. That acts as the values which will be substituted into graphql query. For example,

local gh = require "octo.gh"

local query = [[
query($login: String!) {
  user(login: $login) {
    id
  }
}
]]

local opts = { cb = gh.create_callback {} }

gh.api.graphql {
  query = query,
  fields = { login = "wd60622" },
  opts = opts,
}

fields play a bit different role in call than format but the idea is similar.

@wd60622 wd60622 merged commit e3df84e into master Feb 24, 2025
5 checks passed
@wd60622 wd60622 deleted the 821-helper-to-construct-rest-endpoints branch February 24, 2025 11:09
@ldelossa
Copy link
Contributor

I like either! Fields is prob a bit better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Helper to construct REST endpoints
2 participants