feat(vscode): webhook 副作用按 assignee 门禁,适配多人协作

This commit is contained in:
2026-08-18 23:57:21 +08:00
parent c20bd86370
commit c370214d12
11 changed files with 450 additions and 22 deletions
+9 -1
View File
@@ -164,7 +164,15 @@ func buildIssueCmd() *cobra.Command {
}
}
rc := fromCtx(cmd)
issue, err := rc.Client.CreateIssue(rc.Owner, rc.Repo, icTitle, body)
// 创建即认领:assignee=创建人,是插件 webhook 门禁的路由依据。
// 身份解析失败不阻塞创建(门禁侧有本地终端兜底)。
var assignees []string
if login, loginErr := rc.Client.CurrentUserLogin(); loginErr == nil && login != "" {
assignees = []string{login}
} else if loginErr != nil {
fmt.Fprintf(os.Stderr, "警告: 解析当前用户失败,工单将无 assignee: %v\n", loginErr)
}
issue, err := rc.Client.CreateIssue(rc.Owner, rc.Repo, icTitle, body, assignees)
if err != nil {
return err
}
+15 -1
View File
@@ -81,10 +81,24 @@ func (c *Client) do(method, path string, payload any, out any) error {
return nil
}
// CurrentUserLogin resolves the token owner's login.
func (c *Client) CurrentUserLogin() (string, error) {
var out struct {
Login string `json:"login"`
}
if err := c.do(http.MethodGet, "/api/v1/user", nil, &out); err != nil {
return "", err
}
return out.Login, nil
}
// CreateIssue creates a new issue and returns the created object.
func (c *Client) CreateIssue(owner, repo, title, body string) (*Issue, error) {
func (c *Client) CreateIssue(owner, repo, title, body string, assignees []string) (*Issue, error) {
path := fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner, repo)
payload := map[string]any{"title": title, "body": body}
if len(assignees) > 0 {
payload["assignees"] = assignees
}
var out Issue
if err := c.do(http.MethodPost, path, payload, &out); err != nil {
return nil, err