Skip to content

Commit 88233f6

Browse files
committed
feat: 新增 Webhook 用参数 --extra-data --webhook-mode --webhook-addr
1 parent d1e527f commit 88233f6

File tree

4 files changed

+59
-0
lines changed

4 files changed

+59
-0
lines changed

api/create_sub_task.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ type CreateSubTaskRequest struct {
2424
PackagePrivateId string `json:"package_private_id,omitempty"`
2525
PackagePrivateName string `json:"package_private_name,omitempty"`
2626
ProjectTagNames []string `json:"project_tag_names,omitempty"`
27+
WebhookAddr *string `json:"webhook_addr,omitempty"`
28+
WebhookMode *string `json:"webhook_mode,omitempty"`
29+
ExtraData *string `json:"extra_data,omitempty"`
2730
}
2831

2932
type CreateSubTaskResponse struct {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package common
2+
3+
import (
4+
"fmt"
5+
"github.com/spf13/pflag"
6+
"strconv"
7+
"strings"
8+
)
9+
10+
type WebhookModeFlag struct {
11+
simple bool
12+
}
13+
14+
func (w *WebhookModeFlag) IsSimple() bool {
15+
return w.simple
16+
}
17+
18+
func (w *WebhookModeFlag) String() string {
19+
if w.simple {
20+
return "webhook_mode:simple"
21+
}
22+
return "webhook_mode:full"
23+
}
24+
25+
func (w *WebhookModeFlag) Set(s string) error {
26+
s = strings.ToLower(s)
27+
if s == "simple" {
28+
w.simple = true
29+
} else if s == "" || s == "full" {
30+
w.simple = false
31+
}
32+
return fmt.Errorf("invalid webhook mode: %s", strconv.Quote(s))
33+
}
34+
35+
func (w *WebhookModeFlag) Type() string {
36+
return "WebhookModeFlag"
37+
}
38+
39+
var _ pflag.Value = (*WebhookModeFlag)(nil)

cmd/murphy/internal/scan/cmd.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ var projectTagNames []string
3636
var concurrentNumber int
3737
var sbomOutputConfig string
3838
var sbomOutputType common.SBOMFormatFlag
39+
var webhookAddr string
40+
var webhookMode common.WebhookModeFlag
41+
var extraData string
3942

4043
func Cmd() *cobra.Command {
4144
var c cobra.Command
@@ -52,6 +55,9 @@ func Cmd() *cobra.Command {
5255
c.Flags().StringVar(&privateSourceName, "maven-setting-name", "", "specify the name of the Maven settings.xml file used during the scan")
5356
c.Flags().StringArrayVar(&projectTagNames, "project-tag", make([]string, 0), "specify the tag of the project")
5457
c.Flags().IntVarP(&concurrentNumber, "max-concurrent-uploads", "j", 1, "Set the maximum number of parallel uploads.")
58+
c.Flags().StringVar(&webhookAddr, "webhook-addr", "", "Specify the webhook address")
59+
c.Flags().Var(&webhookMode, "webhook-mode", "Specify the webhook mode, currently supports: simple, full(default)")
60+
c.Flags().StringVar(&extraData, "extra-data", "", "Specify the extra data")
5561
return &c
5662
}
5763

@@ -70,6 +76,9 @@ func DfCmd() *cobra.Command {
7076
c.Flags().StringArrayVar(&projectTagNames, "project-tag", make([]string, 0), "specify the tag of the project")
7177
c.Flags().StringVar(&sbomOutputConfig, "sbom-output", "-", "Specify the SBOM output file path, use \"-\" to output to stdout")
7278
c.Flags().Var(&sbomOutputType, "sbom-format", "(Required) Specify the SBOM format, currently supports: msdx1.1+json")
79+
c.Flags().StringVar(&webhookAddr, "webhook-addr", "", "Specify the webhook address")
80+
c.Flags().Var(&webhookMode, "webhook-mode", "Specify the webhook mode, currently supports: simple, full(default)")
81+
c.Flags().StringVar(&extraData, "extra-data", "", "Specify the extra data")
7382
return &c
7483
}
7584

@@ -84,6 +93,9 @@ func EnvCmd() *cobra.Command {
8493
c.Flags().StringArrayVar(&projectTagNames, "project-tag", make([]string, 0), "specify the tag of the project")
8594
c.Flags().StringVar(&sbomOutputConfig, "sbom-output", "-", "Specify the SBOM output file path, use \"-\" to output to stdout")
8695
c.Flags().Var(&sbomOutputType, "sbom-format", "(Required) Specify the SBOM format, currently supports: msdx1.1+json")
96+
c.Flags().StringVar(&webhookAddr, "webhook-addr", "", "Specify the webhook address")
97+
c.Flags().Var(&webhookMode, "webhook-mode", "Specify the webhook mode, currently supports: simple, full(default)")
98+
c.Flags().StringVar(&extraData, "extra-data", "", "Specify the extra data")
8799
return &c
88100
}
89101

cmd/murphy/internal/scan/scan.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,11 @@ func scan(ctx context.Context, dir string, accessType model.AccessType, mode mod
161161
return nil, e
162162
}
163163
}
164+
if webhookAddr != "" {
165+
createSubtask.WebhookAddr = ref.OmitZero(webhookAddr)
166+
createSubtask.WebhookMode = ref.OmitZero(webhookMode.String())
167+
}
168+
createSubtask.ExtraData = ref.OmitZero(extraData)
164169

165170
// get git info
166171
var gitSummary *gitinfo.Summary

0 commit comments

Comments
 (0)