github.com/blend/go-sdk@v1.20240719.1/pagerduty/update_incident.go (about)

     1  /*
     2  
     3  Copyright (c) 2024 - Present. Blend Labs, Inc. All rights reserved
     4  Use of this source code is governed by a MIT license that can be found in the LICENSE file.
     5  
     6  */
     7  
     8  package pagerduty
     9  
    10  import (
    11  	"context"
    12  	"encoding/json"
    13  	"net/http"
    14  
    15  	"github.com/blend/go-sdk/ex"
    16  	"github.com/blend/go-sdk/r2"
    17  )
    18  
    19  // UpdateIncident implements the update incident method for the client.
    20  func (hc HTTPClient) UpdateIncident(ctx context.Context, id string, incident UpdateIncidentInput) (output Incident, err error) {
    21  	var res *http.Response
    22  	res, err = hc.Request(ctx,
    23  		r2.OptPut(),
    24  		r2.OptPathf("/incidents/%s", id),
    25  		r2.OptJSONBody(updateIncidentInputWrapper{Incident: incident}),
    26  	).Do()
    27  	if err != nil {
    28  		return
    29  	}
    30  	if statusCode := res.StatusCode; statusCode < 200 || statusCode > 299 {
    31  		err = ex.New(ErrNon200Status, ex.OptMessagef("method: put, path: /incidents/%s, status: %d", id, statusCode))
    32  		return
    33  	}
    34  	defer res.Body.Close()
    35  	var body updateIncidentOutputWrapper
    36  	if err = json.NewDecoder(res.Body).Decode(&body); err != nil {
    37  		err = ex.New(err)
    38  		return
    39  	}
    40  	output = body.Incident
    41  	return
    42  }
    43  
    44  // UpdateIncidentInput is the input to update incident.
    45  type UpdateIncidentInput struct {
    46  	Type             string            `json:"type"`             // required
    47  	Status           IncidentStatus    `json:"status,omitempty"` // required
    48  	Priority         *APIObject        `json:"priority,omitempty"`
    49  	Resolution       string            `json:"resolution,omitempty"`
    50  	Title            string            `json:"title,omitempty"`
    51  	EscalationLevel  int               `json:"escalation_level,omitempty"`
    52  	Assignments      []Assignment      `json:"assignments,omitempty"`
    53  	EscalationPolicy *APIObject        `json:"escalation_policy,omitempty"`
    54  	Urgency          string            `json:"urgency,omitempty"`
    55  	ConferenceBridge *ConferenceBridge `json:"conference_bridge,omitempty"`
    56  }
    57  
    58  // updateIncidentInputWrapper wraps the input to satisfy the input schema.
    59  type updateIncidentInputWrapper struct {
    60  	Incident UpdateIncidentInput `json:"incident"`
    61  }
    62  
    63  // updateIncidentOutputWrapper is the response to update incident.
    64  type updateIncidentOutputWrapper struct {
    65  	Incident Incident `json:"incident"`
    66  }