forked from shuheiktgw/go-travis
-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.go
58 lines (48 loc) · 1.36 KB
/
lint.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
// 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"
"net/http"
)
// LintService handles communication with the lint endpoint
// of Travis CI API
type LintService struct {
client *Client
}
type TravisYml struct {
Content string `json:"content,omitempty"`
}
// Warning is a standard representation of
// a warning of .travis.yml content validation
//
// Travis CI API docs: https://developer.travis-ci.com/resource/lint
type Warning struct {
Key []*string `json:"key,omitempty"`
Message *string `json:"message,omitempty"`
*Metadata
}
type lintResponse struct {
Warnings []*Warning `json:"warnings,omitempty"`
}
// Lint validates the .travis.yml file and returns any warnings
//
// Travis CI API docs: https://developer.travis-ci.com/resource/lint#lint
func (es *LintService) Lint(ctx context.Context, yml *TravisYml) ([]*Warning, *http.Response, error) {
u, err := urlWithOptions("/lint", nil)
if err != nil {
return nil, nil, err
}
req, err := es.client.NewRequest(http.MethodPost, u, yml, nil)
if err != nil {
return nil, nil, err
}
var lintResponse lintResponse
resp, err := es.client.Do(ctx, req, &lintResponse)
if err != nil {
return nil, resp, err
}
return lintResponse.Warnings, resp, err
}