diff options
| author | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
|---|---|---|
| committer | Robert Günzler <r@gnzler.io> | 2026-09-27 17:38:39 +0200 |
| commit | 0860db73ae6fd9a6f6347219d820bf026a6b8b91 (patch) | |
| tree | 11318c3670d1c32c5aa0bf404c22fba3bf63fc53 /.config/nvim/lua/mod/gh.lua | |
| parent | 4e34cbf9673aeaba252e01df554a0d204e83c5e2 (diff) | |
| download | dotfiles-master.tar.gz | |
Automated-commit-by: dots Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '.config/nvim/lua/mod/gh.lua')
| -rw-r--r-- | .config/nvim/lua/mod/gh.lua | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/.config/nvim/lua/mod/gh.lua b/.config/nvim/lua/mod/gh.lua new file mode 100644 index 0000000..1f8a267 --- /dev/null +++ b/.config/nvim/lua/mod/gh.lua @@ -0,0 +1,86 @@ +local M = {} + +-- gh api \ +-- --method POST \ +-- -H "Accept: application/vnd.github+json" \ +-- -H "X-GitHub-Api-Version: 2022-11-28" \ +-- /repos/OWNER/REPO/pulls/PULL_NUMBER/comments \ + +function M.pr_comment(repo, pull, commit_id, comment) + vim.print(vim.inspect(comment)) + vim.print(vim.inspect({ + 'gh', + 'api', + '--method', + 'POST', + string.format('/repos/%s/pulls/%d/comments', repo, pull), + '-f', + 'body=' .. comment.body, + '-f', + 'commit_id=' .. commit_id, + '-f', + 'path=' .. comment.path, + '-f', + 'side=RIGHT', + '-f', + 'line=' .. comment.line, + })) +end + +function M.pr_view() + local p = vim + .system({ + 'gh', + 'pr', + 'view', + '--json', + 'number,headRepository,headRefOid', + '--jq', + '{head:.headRefOid,repo:.headRepository.nameWithOwner,pull:.number}', + }) + :wait() + return vim.json.decode(p.stdout) +end + +function M.submit_review() + local gitroot = vim.fs.root(0, { '.git' }) + if not gitroot then + vim.notify('Not a git repository.', vim.log.levels.WARN) + return + end + + local review = { comments = {} } + + local marks = require('haunt.api').get_bookmarks() + for _, mark in ipairs(marks) do + -- nil for bookmarks outside the current repo + local path = vim.fs.relpath(gitroot, mark.file) + if path then + review.comments[#review.comments] = { + path = path, + line = mark.line, + body = mark.note, + } + end + end + + review.pr = M.pr_view() + + vim.print(vim.inspect(review)) + + vim.ui.select({ + 'OK', + 'Cancel', + }, { + prompt = 'Submit review?', + }, function(choice) + vim.print(choice) + if choice == 'OK' then + for _, comment in ipairs(review.comments) do + M.pr_comment(pr.repo, pr.pull, pr.head, comment) + end + end + end) +end + +return M |