github.com/bndr/gojenkins@v1.1.0/plugin.go (about) 1 // Copyright 2015 Vadim Kravcenko 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"): you may 4 // not use this file except in compliance with the License. You may obtain 5 // a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 11 // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 12 // License for the specific language governing permissions and limitations 13 // under the License. 14 15 package gojenkins 16 17 import ( 18 "context" 19 "strconv" 20 ) 21 22 type Plugins struct { 23 Jenkins *Jenkins 24 Raw *PluginResponse 25 Base string 26 Depth int 27 } 28 29 type PluginResponse struct { 30 Plugins []Plugin `json:"plugins"` 31 } 32 33 type Plugin struct { 34 Active bool `json:"active"` 35 BackupVersion interface{} `json:"backupVersion"` 36 Bundled bool `json:"bundled"` 37 Deleted bool `json:"deleted"` 38 Dependencies []struct { 39 Optional string `json:"optional"` 40 ShortName string `json:"shortname"` 41 Version string `json:"version"` 42 } `json:"dependencies"` 43 Downgradable bool `json:"downgradable"` 44 Enabled bool `json:"enabled"` 45 HasUpdate bool `json:"hasUpdate"` 46 LongName string `json:"longName"` 47 Pinned bool `json:"pinned"` 48 ShortName string `json:"shortName"` 49 SupportsDynamicLoad string `json:"supportsDynamicLoad"` 50 URL string `json:"url"` 51 Version string `json:"version"` 52 } 53 54 func (p *Plugins) Count() int { 55 return len(p.Raw.Plugins) 56 } 57 58 func (p *Plugins) Contains(name string) *Plugin { 59 for _, p := range p.Raw.Plugins { 60 if p.LongName == name || p.ShortName == name { 61 return &p 62 } 63 } 64 return nil 65 } 66 67 func (p *Plugins) Poll(ctx context.Context) (int, error) { 68 qr := map[string]string{ 69 "depth": strconv.Itoa(p.Depth), 70 } 71 response, err := p.Jenkins.Requester.GetJSON(ctx, p.Base, p.Raw, qr) 72 if err != nil { 73 return 0, err 74 } 75 return response.StatusCode, nil 76 }