Skip to content

Commit 47b7205

Browse files
authored
Merge pull request #1 from cpanato/fix-lints
Fix lints
2 parents f11d6c3 + 60bb7e4 commit 47b7205

13 files changed

Lines changed: 88 additions & 102 deletions

.golangci.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
version: "2"
3+
run:
4+
issues-exit-code: 1
5+
timeout: 5m
6+
linters:
7+
enable:
8+
- asciicheck
9+
- errorlint
10+
- forbidigo
11+
- gocritic
12+
- gosec
13+
- importas
14+
- makezero
15+
- misspell
16+
- nilnesserr
17+
- prealloc
18+
- revive
19+
- tparallel
20+
- unconvert
21+
- unparam
22+
- usestdlibvars
23+
- whitespace
24+
25+
issues:
26+
max-issues-per-linter: 0
27+
max-same-issues: 0
28+
uniq-by-line: false
29+
formatters:
30+
enable:
31+
- gofmt
32+
- goimports
33+
exclusions:
34+
generated: lax
35+
paths:
36+
- third_party$
37+
- builtin$
38+
- examples$

incidentio/actions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ type ActionsService struct {
55
client *Client
66
}
77

8+
// Action represents an action in Incident.io.
89
type Action struct {
910
ID string `json:"id"`
1011
IncidentID string `json:"incident_id"`

incidentio/custom_fields.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type CustomFieldsService struct {
1010
client *Client
1111
}
1212

13+
// CustomField represents a custom field in Incident.io.
1314
type CustomField struct {
1415
ID string `json:"id"`
1516
Name string `json:"name"`

incidentio/doc.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
// Package incidentio provides a client for the Incident.io API.
2+
package incidentio

incidentio/incident_roles.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"net/http"
66
)
77

8+
// CreateRoleAssignment represents the payload for creating a role assignment in an incident.
89
type CreateRoleAssignment struct {
910
IncidentRoleID string `json:"incident_role_id"`
1011
UserID string `json:"user_id"`
@@ -16,6 +17,7 @@ type IncidentRoleAssignment struct {
1617
Assignee *User `json:"assignee"`
1718
}
1819

20+
// Severity represents the severity of an incident.
1921
type Severity struct {
2022
ID string `json:"id"`
2123
Name string `json:"name"`
@@ -25,6 +27,7 @@ type Severity struct {
2527
UpdatedAt Timestamp `json:"updated_at"`
2628
}
2729

30+
// IncidentRole represents a role that can be assigned to users in an incident.
2831
type IncidentRole struct {
2932
ID string `json:"id"`
3033
Name string `json:"name"`

incidentio/incident_type.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type IncidentTypesService struct {
1010
client *Client
1111
}
1212

13+
// IncidentType represents an incident type in Incident.io.
1314
type IncidentType struct {
1415
ID string `json:"id"`
1516
Name string `json:"name"`

incidentio/incidentio.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt
126126
if err != nil {
127127
return nil, err
128128
}
129-
defer resp.Body.Close()
129+
defer resp.Body.Close() //nolint: errcheck
130130

131131
err = CheckResponse(resp)
132132
if err != nil {
@@ -135,7 +135,7 @@ func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*htt
135135

136136
if v != nil && resp.StatusCode != http.StatusNoContent {
137137
if w, ok := v.(io.Writer); ok {
138-
io.Copy(w, resp.Body)
138+
_, _ = io.Copy(w, resp.Body)
139139
} else {
140140
err = json.NewDecoder(resp.Body).Decode(v)
141141
}
@@ -153,7 +153,7 @@ func CheckResponse(r *http.Response) error {
153153
errorResponse := &ErrorResponse{Response: r}
154154
data, err := io.ReadAll(r.Body)
155155
if err == nil && data != nil {
156-
json.Unmarshal(data, errorResponse)
156+
_ = json.Unmarshal(data, errorResponse)
157157
}
158158

159159
return errorResponse
@@ -186,17 +186,18 @@ type ListOptions struct {
186186
After string `url:"after,omitempty"`
187187
}
188188

189-
// Common types used across the API
190-
189+
// ExternalResource represents a common type used across the API
191190
type ExternalResource struct {
192191
ExternalID string `json:"external_id"`
193192
DisplayName string `json:"display_name"`
194193
}
195194

195+
// Timestamp is a wrapper around time.Time to handle JSON serialization
196196
type Timestamp struct {
197197
time.Time
198198
}
199199

200+
// UnmarshalJSON parses a JSON string
200201
func (t *Timestamp) UnmarshalJSON(data []byte) error {
201202
var s string
202203
if err := json.Unmarshal(data, &s); err != nil {
@@ -210,6 +211,7 @@ func (t *Timestamp) UnmarshalJSON(data []byte) error {
210211
return nil
211212
}
212213

214+
// MarshalJSON formats the Timestamp as a JSON string in RFC3339 format.
213215
func (t Timestamp) MarshalJSON() ([]byte, error) {
214-
return json.Marshal(t.Time.Format(time.RFC3339))
216+
return json.Marshal(t.Format(time.RFC3339))
215217
}

incidentio/incidents.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ type CreateIncidentOptions struct {
5151
}
5252

5353
// List returns a list of incidents.
54-
func (s *IncidentsService) List(ctx context.Context, opts *ListOptions) ([]*Incident, *http.Response, error) {
54+
func (s *IncidentsService) List(ctx context.Context, _ *ListOptions) ([]*Incident, *http.Response, error) {
5555
u := "v2/incidents"
5656

5757
req, err := s.client.NewRequest("GET", u, nil)

incidentio/incidents_test.go

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package incidentio
33
import (
44
"context"
55
"encoding/json"
6+
"errors"
67
"fmt"
78
"net/http"
89
"net/http/httptest"
@@ -14,7 +15,7 @@ import (
1415

1516
// Test helpers
1617

17-
func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown func()) {
18+
func setup() (client *Client, mux *http.ServeMux, serverURL string, teardown func()) { //nolint: unparam
1819
mux = http.NewServeMux()
1920
server := httptest.NewServer(mux)
2021

@@ -76,7 +77,7 @@ func TestIncidentsService_List(t *testing.T) {
7677
]
7778
}`
7879

79-
fmt.Fprint(w, response)
80+
_, _ = fmt.Fprint(w, response)
8081
})
8182

8283
ctx := context.Background()
@@ -144,7 +145,7 @@ func TestIncidentsService_Get(t *testing.T) {
144145
}
145146
}`
146147

147-
fmt.Fprint(w, response)
148+
_, _ = fmt.Fprint(w, response)
148149
})
149150

150151
ctx := context.Background()
@@ -251,7 +252,7 @@ func TestIncidentsService_Create(t *testing.T) {
251252
}`
252253

253254
w.WriteHeader(http.StatusCreated)
254-
fmt.Fprint(w, response)
255+
_, _ = fmt.Fprint(w, response)
255256
})
256257

257258
ctx := context.Background()
@@ -315,7 +316,7 @@ func TestIncidentsService_Update(t *testing.T) {
315316
}
316317
}`
317318

318-
fmt.Fprint(w, response)
319+
_, _ = fmt.Fprint(w, response)
319320
})
320321

321322
ctx := context.Background()
@@ -363,7 +364,7 @@ func TestIncidentsService_ErrorHandling(t *testing.T) {
363364
client, mux, _, teardown := setup()
364365
defer teardown()
365366

366-
mux.HandleFunc("/v2/incidents/not-found", func(w http.ResponseWriter, r *http.Request) {
367+
mux.HandleFunc("/v2/incidents/not-found", func(w http.ResponseWriter, _ *http.Request) {
367368
w.WriteHeader(http.StatusNotFound)
368369
response := `{
369370
"type": "validation_error",
@@ -379,7 +380,7 @@ func TestIncidentsService_ErrorHandling(t *testing.T) {
379380
}
380381
]
381382
}`
382-
fmt.Fprint(w, response)
383+
_, _ = fmt.Fprint(w, response)
383384
})
384385

385386
ctx := context.Background()
@@ -389,7 +390,8 @@ func TestIncidentsService_ErrorHandling(t *testing.T) {
389390
t.Error("Expected error, got nil")
390391
}
391392

392-
errResp, ok := err.(*ErrorResponse)
393+
errResp := &ErrorResponse{}
394+
ok := errors.As(err, &errResp)
393395
if !ok {
394396
t.Errorf("Error type = %T, want *ErrorResponse", err)
395397
}
@@ -467,18 +469,18 @@ func TestTimestamp_UnmarshalJSON(t *testing.T) {
467469
t.Errorf("Timestamp.UnmarshalJSON() error = %v, wantErr %v", err, tt.wantErr)
468470
return
469471
}
470-
if !tt.wantErr && !ts.Time.Equal(tt.want) {
472+
if !tt.wantErr && !ts.Equal(tt.want) {
471473
t.Errorf("Timestamp.UnmarshalJSON() = %v, want %v", ts.Time, tt.want)
472474
}
473475
})
474476
}
475477
}
476478

477479
func TestErrorResponse_Error(t *testing.T) {
478-
req, _ := http.NewRequest("GET", "https://api.incident.io/v2/incidents/123", nil)
480+
req, _ := http.NewRequest(http.MethodGet, "https://api.incident.io/v2/incidents/123", nil)
479481
resp := &http.Response{
480482
Request: req,
481-
StatusCode: 404,
483+
StatusCode: http.StatusNotFound,
482484
}
483485

484486
err := &ErrorResponse{

incidentio/schedules.go

Lines changed: 2 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ type UpdateOverrideOptions struct {
171171
}
172172

173173
// List returns a list of schedules.
174-
func (s *SchedulesService) List(ctx context.Context, opts *ScheduleListOptions) ([]*Schedule, *http.Response, error) {
174+
func (s *SchedulesService) List(ctx context.Context, _ *ScheduleListOptions) ([]*Schedule, *http.Response, error) {
175175
u := "v2/schedules"
176176

177177
req, err := s.client.NewRequest("GET", u, nil)
@@ -291,7 +291,7 @@ func (s *SchedulesService) ListEntries(ctx context.Context, scheduleID string, o
291291
}
292292

293293
// ListOverrides returns overrides for a schedule.
294-
func (s *SchedulesService) ListOverrides(ctx context.Context, scheduleID string, opts *ListOptions) ([]*Override, *http.Response, error) {
294+
func (s *SchedulesService) ListOverrides(ctx context.Context, scheduleID string, _ *ListOptions) ([]*Override, *http.Response, error) {
295295
u := fmt.Sprintf("v2/schedules/%s/overrides", scheduleID)
296296

297297
req, err := s.client.NewRequest("GET", u, nil)
@@ -381,70 +381,3 @@ func (s *SchedulesService) DeleteOverride(ctx context.Context, scheduleID, overr
381381

382382
return s.client.Do(ctx, req, nil)
383383
}
384-
385-
// ExampleCreateSchedule shows how to create a new schedule
386-
func ExampleCreateSchedule(client *Client) {
387-
ctx := context.Background()
388-
389-
// Define the schedule configuration
390-
config := &ScheduleConfig{
391-
Rotations: []RotationConfig{
392-
{
393-
ID: "weekly-rotation",
394-
Name: "Weekly Rotation",
395-
Layers: []LayerConfig{
396-
{
397-
ID: "layer-1",
398-
Name: "Primary On-Call",
399-
Users: []LayerUser{
400-
{UserID: "01FCNDV6P870EA6S7TK1DSYDG0"},
401-
{UserID: "01FCQSP07Z74QMMYPDDGQB9FTG"},
402-
},
403-
},
404-
},
405-
HandoverStartAt: Timestamp{time.Now()},
406-
HandoversAt: Timestamp{time.Now().Add(7 * 24 * time.Hour)},
407-
},
408-
},
409-
}
410-
411-
opts := &CreateScheduleOptions{
412-
Name: "Engineering On-Call",
413-
Timezone: "America/New_York",
414-
Config: config,
415-
}
416-
417-
schedule, _, err := client.Schedules.Create(ctx, opts)
418-
if err != nil {
419-
fmt.Printf("Error creating schedule: %v\n", err)
420-
return
421-
}
422-
423-
fmt.Printf("Created schedule: %s\n", schedule.ID)
424-
}
425-
426-
// ExampleListScheduleEntries shows how to list schedule entries for a time window
427-
func ExampleListScheduleEntries(client *Client) {
428-
ctx := context.Background()
429-
430-
// Get entries for the next 7 days
431-
opts := &ScheduleEntriesOptions{
432-
EntryWindow: &TimeWindow{
433-
StartAt: time.Now(),
434-
EndAt: time.Now().Add(7 * 24 * time.Hour),
435-
},
436-
}
437-
438-
entries, _, err := client.Schedules.ListEntries(ctx, "schedule-id", opts)
439-
if err != nil {
440-
fmt.Printf("Error listing entries: %v\n", err)
441-
return
442-
}
443-
444-
for _, entry := range entries {
445-
fmt.Printf("User %s is on-call from %s to %s\n",
446-
entry.UserID,
447-
entry.Interval.StartAt.Format(time.RFC3339),
448-
entry.Interval.EndAt.Format(time.RFC3339))
449-
}
450-
}

0 commit comments

Comments
 (0)