Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commita4f2b9d

Browse files
committed
feat(gh): when on a review comment, thegh_comment action will now do a reply instead of a top-level comment.Fixes#2410
1 parent2099572 commita4f2b9d

File tree

5 files changed

+77
-10
lines changed

5 files changed

+77
-10
lines changed

‎lua/snacks/gh/actions.lua‎

Lines changed: 45 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ local M = {}
66
---@classsnacks.gh.action.ctx
77
---@fielditemssnacks.picker.gh.Item[]
88
---@fieldpicker?snacks.Picker
9+
---@fieldmain?number
910
---@fieldaction?snacks.picker.Action
1011

1112
---@classsnacks.gh.cli.Action.ctx
@@ -79,6 +80,7 @@ M.actions.gh_actions = {
7980
ifctx.actionandctx.action.cmdthen
8081
returnSnacks.picker.actions.jump(ctx.picker,item,ctx.action)
8182
end
83+
ctx.main=ctx.mainorctx.pickerandctx.picker.mainornil
8284
localactions=M.get_actions(item)
8385
actions.gh_actions=nil-- remove this action
8486
actions.gh_perform_action=nil-- remove this action
@@ -103,6 +105,7 @@ M.actions.gh_actions = {
103105
ifctx.pickerthen
104106
ctx.picker:focus()
105107
end
108+
ctx.main=ctx.mainorpickerandpicker.mainornil
106109
it.action.action(item,ctx)
107110
picker:close()
108111
end,
@@ -233,6 +236,35 @@ M.actions.gh_yank = {
233236
end,
234237
}
235238

239+
M.actions.gh_comment= {
240+
desc="Comment on {type} #{number}",
241+
icon="",
242+
action=function(item,ctx)
243+
localwin=ctx.mainorvim.api.nvim_get_current_win()
244+
localbuf=vim.api.nvim_win_get_buf(win)
245+
246+
localaction=vim.deepcopy(M.cli_actions.gh_comment)
247+
ifitem.uri==vim.api.nvim_buf_get_name(buf)then
248+
locallino=vim.api.nvim_win_get_cursor(win)[1]
249+
---@type{line:number,id:number}[]
250+
localcomments=vim.b[buf].snacks_gh_commentsor {}
251+
for_,cinipairs(comments)do
252+
ifc.line==linothen
253+
action.title="Reply to comment on {type} #{number}"
254+
action.api= {
255+
endpoint="/repos/{repo}/pulls/{number}/comments",
256+
input= {
257+
in_reply_to=c.id,
258+
},
259+
}
260+
break
261+
end
262+
end
263+
end
264+
M.run(item,action,ctx)
265+
end,
266+
}
267+
236268
---@typetable<string,snacks.gh.cli.Action>
237269
M.cli_actions= {
238270
gh_comment= {
@@ -570,7 +602,6 @@ function M._run(ctx, force)
570602
Api.request(
571603
cb,
572604
Snacks.config.merge(ctx.opts.apior {}, {
573-
input=ctx.input,
574605
args=ctx.args,
575606
on_error=function()
576607
spinner:stop()
@@ -655,10 +686,20 @@ function M.submit(ctx)
655686

656687
ifbody:find("%S")then
657688
ifedit=="body-file"then
658-
vim.list_extend(ctx.args, {"--body-file","-"})
659-
ctx.input=body
689+
ifctx.opts.apithen
690+
ctx.opts.api.input=ctx.opts.api.inputor {}
691+
ctx.opts.api.input.body=body
692+
else
693+
ctx.input=body
694+
vim.list_extend(ctx.args, {"--body-file","-"})
695+
end
660696
else
661-
vim.list_extend(ctx.args, {"--"..edit,body })
697+
ifctx.opts.apithen
698+
ctx.opts.api.fields=ctx.opts.api.fieldsor {}
699+
ctx.opts.api.fields[edit]=body
700+
else
701+
vim.list_extend(ctx.args, {"--"..edit,body })
702+
end
662703
end
663704
end
664705

‎lua/snacks/gh/api.lua‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ function M.request(cb, opts)
228228
cb(proc,dataanddata:find("%S")andproc:json()ornil)
229229
end, {
230230
args=args,
231-
input=opts.input,
231+
input=opts.inputandvim.json.encode(opts.input)ornil,
232232
on_error=opts.on_error,
233233
})
234234
end
@@ -417,6 +417,7 @@ function M.comments(item, cb)
417417
comments(first: 50) {
418418
nodes {
419419
id
420+
databaseId
420421
body
421422
path
422423
diffHunk
@@ -427,7 +428,7 @@ function M.comments(item, cb)
427428
createdAt
428429
subjectType
429430
author { login }
430-
replyTo { id }
431+
replyTo { iddatabaseId}
431432
reactionGroups {
432433
content
433434
users { totalCount }
@@ -439,6 +440,7 @@ function M.comments(item, cb)
439440
comments(first: 100) {
440441
nodes {
441442
id
443+
databaseId
442444
body
443445
author { login }
444446
authorAssociation

‎lua/snacks/gh/render/init.lua‎

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ local extend = Snacks.picker.highlight.extend
1111
---@fielditemsnacks.picker.gh.Item
1212
---@fieldoptssnacks.gh.Config
1313
---@fieldcomment_skiptable<string,boolean>
14+
---@fieldis_review?boolean
1415

1516
---@paramfieldstring
1617
localfunctiontime_prop(field)
@@ -296,17 +297,24 @@ function M.render(buf, item, opts)
296297
if#threads>0then
297298
lines[#lines+1]= { {""} }-- empty line
298299
lines[#lines+1]= { {"---","@punctuation.special.markdown"} }
300+
lines[#lines+1]= {}-- empty line
299301

300302
for_,threadinipairs(threads)do
301-
lines[#lines+1]= {}-- empty line
303+
localc=#lines
302304

303305
ifthread.submittedthen
304306
---@castthreadsnacks.gh.Review
307+
ctx.is_review=true
305308
vim.list_extend(lines,M.review(thread,1,ctx))
306309
else
307310
---@castthreadsnacks.gh.Comment
311+
ctx.is_review=false
308312
vim.list_extend(lines,M.comment(thread,1,ctx))
309313
end
314+
315+
if#lines>cthen-- only add separator if there were comments added
316+
lines[#lines+1]= {}-- empty line
317+
end
310318
end
311319
end
312320

@@ -316,7 +324,13 @@ function M.render(buf, item, opts)
316324
vim.api.nvim_buf_clear_namespace(buf,ns,0,-1)
317325

318326
localchanged=#lines~=#buf_lines
327+
localcomments= {}---@type{line:number,id:number}[]
319328
forl,lineinipairs(lines)do
329+
for_,segmentinipairs(line)do
330+
ifsegment.metaandsegment.meta.replythen
331+
comments[#comments+1]= {line=l,id=segment.meta.reply }
332+
end
333+
end
320334
localline_text,extmarks=Snacks.picker.highlight.to_text(line)
321335
ifline_text~=buf_lines[l]then
322336
vim.api.nvim_buf_set_lines(buf,l-1,l,false, {line_text })
@@ -339,6 +353,7 @@ function M.render(buf, item, opts)
339353
end
340354
end
341355
end
356+
vim.b[buf].snacks_gh_comments=comments
342357
if#lines<#buf_linesthen
343358
vim.api.nvim_buf_set_lines(buf,#lines,-1,false, {})
344359
end
@@ -490,6 +505,14 @@ function M.comment(comment, level, ctx)
490505
vim.list_extend(ret,M.comment(reply,level,ctx))
491506
ctx.comment_skip[reply.id]=true
492507
end
508+
ifctx.is_reviewthen
509+
for_,lineinipairs(ret)do
510+
localreply_id=comment.replyToandcomment.replyTo.databaseIdorcomment.databaseId
511+
ifreply_idthen
512+
line[#line+1]= {"",meta= {reply=reply_id } }
513+
end
514+
end
515+
end
493516
returnret
494517
end
495518

‎lua/snacks/gh/types.lua‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
---@fieldparams?table<string,string|number|boolean> typed fields(--field)
3131
---@fieldheader?table<string,string|number|boolean>
3232
---@fieldjq?string
33-
---@fieldinput?string
33+
---@fieldinput?any
3434
---@fieldmethod?"GET"|"POST"|"PATCH"|"PUT"|"DELETE"
3535
---@fieldpaginate?boolean
3636
---@fieldsilent?boolean
@@ -138,6 +138,7 @@
138138

139139
---@classsnacks.gh.Comment
140140
---@fieldidstring
141+
---@fielddatabaseIdnumber
141142
---@fieldurlstring
142143
---@fieldauthor{login:string}
143144
---@fieldauthorAssociation?string
@@ -149,7 +150,7 @@
149150
---@fieldcreatedAtstring
150151
---@fieldreactionGroups?snacks.gh.Reaction[]
151152
---@fieldcreated?number
152-
---@fieldreplyTo?{id:string}
153+
---@fieldreplyTo?{id:string,databaseId:number}
153154
---@fieldpath?string
154155
---@fielddiffHunk?string
155156
---@fieldline?number

‎lua/snacks/picker/config/defaults.lua‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ local M = {}
22

33
---@aliassnacks.picker.format.resolvefun(max_width:number):snacks.picker.Highlight[]
44
---@aliassnacks.picker.Extmarkvim.api.keyset.set_extmark|{col:number,row?:number,field?:string}
5-
---@aliassnacks.picker.Text{[1]:string,[2]:(string|string[])?,virtual?:boolean,field?:string,resolve?:snacks.picker.format.resolve}
5+
---@aliassnacks.picker.Text{[1]:string,[2]:(string|string[])?,virtual?:boolean,field?:string,resolve?:snacks.picker.format.resolve,meta?:table<string,any>}
66
---@aliassnacks.picker.Highlightsnacks.picker.Text|snacks.picker.Extmark
77
---@aliassnacks.picker.formatfun(item:snacks.picker.Item,picker:snacks.Picker):snacks.picker.Highlight[]
88
---@aliassnacks.picker.previewfun(ctx:snacks.picker.preview.ctx):boolean?

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp