This repository has been archived by the owner on Feb 5, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 10
/
logs.go
82 lines (69 loc) · 1.96 KB
/
logs.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package travis
import (
"context"
"fmt"
"net/http"
)
// LogsService handles communication with the logs
// related methods of the Travis CI API.
type LogsService struct {
client *Client
}
// Log represents a Travis CI job log
type Log struct {
// The log's id
Id *uint `json:"id,omitempty"`
// The content of the log
Content *string `json:"content,omitempty"`
// The log parts that form the log
LogParts []*LogPart `json:"log_parts,omitempty"`
*Metadata
}
// LogPart is parts that form the log
type LogPart struct {
Content *string `json:"content,omitempty"`
Final *bool `json:"final,omitempty"`
Number *uint `json:"number,omitempty"`
}
// FindByJobId fetches a job's log based on it's provided id.
//
// Travis CI API docs: https://developer.travis-ci.com/resource/log#find
func (ls *LogsService) FindByJobId(ctx context.Context, jobId uint) (*Log, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("job/%d/log", jobId), nil)
if err != nil {
return nil, nil, err
}
req, err := ls.client.NewRequest(http.MethodGet, u, nil, nil)
if err != nil {
return nil, nil, err
}
var log Log
resp, err := ls.client.Do(ctx, req, &log)
if err != nil {
return nil, resp, err
}
return &log, resp, err
}
// DeleteByJobId fetches a job's log based on it's provided id.
//
// Travis CI API docs: https://developer.travis-ci.com/resource/log#delete
func (ls *LogsService) DeleteByJobId(ctx context.Context, jobId uint) (*Log, *http.Response, error) {
u, err := urlWithOptions(fmt.Sprintf("job/%d/log", jobId), nil)
if err != nil {
return nil, nil, err
}
req, err := ls.client.NewRequest(http.MethodDelete, u, nil, nil)
if err != nil {
return nil, nil, err
}
var log Log
resp, err := ls.client.Do(ctx, req, &log)
if err != nil {
return nil, resp, err
}
return &log, resp, err
}