1// Copyright (c) 2015 Ableton AG, Berlin. All rights reserved. 2// 3// Use of this source code is governed by a BSD-style 4// license that can be found in the LICENSE file. 5 6package travis 7 8import ( 9 "context" 10 "net/http" 11) 12 13// LintService handles communication with the lint endpoint 14// of Travis CI API 15type LintService struct { 16 client *Client 17} 18 19type TravisYml struct { 20 Content string `json:"content,omitempty"` 21} 22 23// Warning is a standard representation of 24// a warning of .travis.yml content validation 25// 26// Travis CI API docs: https://developer.travis-ci.com/resource/lint 27type Warning struct { 28 Key []string `json:"key,omitempty"` 29 Message string `json:"message,omitempty"` 30 *Metadata 31} 32 33type lintResponse struct { 34 Warnings []*Warning `json:"warnings,omitempty"` 35} 36 37// Lint validates the .travis.yml file and returns any warnings 38// 39// Travis CI API docs: https://developer.travis-ci.com/resource/lint#lint 40func (es *LintService) Lint(ctx context.Context, yml *TravisYml) ([]*Warning, *http.Response, error) { 41 u, err := urlWithOptions("/lint", nil) 42 if err != nil { 43 return nil, nil, err 44 } 45 46 req, err := es.client.NewRequest(http.MethodPost, u, yml, nil) 47 if err != nil { 48 return nil, nil, err 49 } 50 51 var lintResponse lintResponse 52 resp, err := es.client.Do(ctx, req, &lintResponse) 53 if err != nil { 54 return nil, resp, err 55 } 56 57 return lintResponse.Warnings, resp, err 58} 59