github.com/abayer/test-infra@v0.0.5/prow/github/helpers.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package github
    18  
    19  import (
    20  	"fmt"
    21  	"net/http"
    22  	"strconv"
    23  	"strings"
    24  )
    25  
    26  // HasLabel checks if label is in the label set "issueLabels".
    27  func HasLabel(label string, issueLabels []Label) bool {
    28  	for _, l := range issueLabels {
    29  		if strings.ToLower(l.Name) == strings.ToLower(label) {
    30  			return true
    31  		}
    32  	}
    33  	return false
    34  }
    35  
    36  // ImageTooBig checks if image is bigger than github limits
    37  func ImageTooBig(url string) (bool, error) {
    38  	// limit is 10MB
    39  	limit := 10000000
    40  	// try to get the image size from Content-Length header
    41  	resp, err := http.Head(url)
    42  	if err != nil {
    43  		return true, fmt.Errorf("error getting size of image, cannot get headers for %s: %s", url, err)
    44  	}
    45  	if resp.StatusCode != http.StatusOK {
    46  		return true, fmt.Errorf("error getting size of image %s: %s", url, resp.Status)
    47  	}
    48  	size, _ := strconv.Atoi(resp.Header.Get("Content-Length"))
    49  	if size > limit {
    50  		return true, nil
    51  	}
    52  	return false, nil
    53  }