+
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions github/dependabot_alerts.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,13 @@ type ListAlertsOptions struct {
ListCursorOptions
}

// AlertUpdate specifies the optional parameters to the DependabotService.UpdateRepoAlert method.
type AlertUpdate struct {
State string `json:"state"`
DismissedReason *string `json:"dismissed_reason,omitempty"`
DismissedComment *string `json:"dismissed_comment,omitempty"`
}

func (s *DependabotService) listAlerts(ctx context.Context, url string, opts *ListAlertsOptions) ([]*DependabotAlert, *Response, error) {
u, err := addOptions(url, opts)
if err != nil {
Expand Down Expand Up @@ -128,11 +135,27 @@ func (s *DependabotService) GetRepoAlert(ctx context.Context, owner, repo string
return nil, nil, err
}

alert := new(DependabotAlert)
var alert DependabotAlert
resp, err := s.client.Do(ctx, req, alert)
if err != nil {
return nil, resp, err
}

return alert, resp, nil
return &alert, resp, nil
}

func (s *DependabotService) UpdateRepoAlert(ctx context.Context, owner, repo string, number int, update *AlertUpdate) (*DependabotAlert, *Response, error) {
url := fmt.Sprintf("repos/%v/%v/dependabot/alerts/%v", owner, repo, number)
req, err := s.client.NewRequest("PATCH", url, update)
if err != nil {
return nil, nil, err
}

var alert DependabotAlert
resp, err := s.client.Do(ctx, req, &alert)
if err != nil {
return nil, resp, err
}

return &alert, resp, nil
}
41 changes: 41 additions & 0 deletions github/dependabot_alerts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,47 @@ func TestDependabotService_GetRepoAlert(t *testing.T) {
})
}

func TestDependabotService_UpdateRepoAlert(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/repos/o/r/dependabot/alerts/42", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PATCH")
fmt.Fprint(w, `{"number":42,"state":"fixed"}`)
})

update := AlertUpdate{
State: "fixed",
}
ctx := context.Background()
alert, _, err := client.Dependabot.UpdateRepoAlert(ctx, "o", "r", 42, &update)
if err != nil {
t.Errorf("Dependabot.GetRepoAlert returned error: %v", err)
}

want := &DependabotAlert{
Number: Int(42),
State: String("fixed"),
}
if !cmp.Equal(alert, want) {
t.Errorf("Dependabot.UpdateRepoAlert returned %+v, want %+v", alert, want)
}

const methodName = "UpdateRepoAlert"
testBadOptions(t, methodName, func() (err error) {
_, _, err = client.Dependabot.UpdateRepoAlert(ctx, "\n", "\n", 0, &update)
return err
})

testNewRequestAndDoFailure(t, methodName, client, func() (*Response, error) {
got, resp, err := client.Dependabot.UpdateRepoAlert(ctx, "o", "r", 42, &update)
if got != nil {
t.Errorf("testNewRequestAndDoFailure %v = %#v, want nil", methodName, got)
}
return resp, err
})
}

func TestDependabotService_ListOrgAlerts(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()
Expand Down
点击 这是indexloc提供的php浏览器服务,不要输入任何密码和下载