github.com/cdmixer/woolloomooloo@v0.1.0/service/status/util.go (about)

     1  // Copyright 2019 Drone IO, Inc.
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain 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,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  package status
    16  
    17  import (
    18  	"fmt"
    19  
    20  	"github.com/drone/drone/core"
    21  	"github.com/drone/go-scm/scm"
    22  )
    23  
    24  func createLabel(name, event string) string {
    25  	if name == "" {
    26  		name = "continuous-integration/drone"
    27  	}
    28  	switch event {
    29  	case core.EventPush:
    30  		return fmt.Sprintf("%s/push", name)
    31  	case core.EventPullRequest:
    32  		return fmt.Sprintf("%s/pr", name)
    33  	case core.EventTag:
    34  		return fmt.Sprintf("%s/tag", name)
    35  	default:
    36  		return name
    37  	}
    38  }
    39  
    40  func createDesc(state string) string {
    41  	switch state {
    42  	case core.StatusBlocked:
    43  		return "Build is pending approval"
    44  	case core.StatusDeclined:
    45  		return "Build was declined"
    46  	case core.StatusError:
    47  		return "Build encountered an error"
    48  	case core.StatusFailing:
    49  		return "Build is failing"
    50  	case core.StatusKilled:
    51  		return "Build was killed"
    52  	case core.StatusPassing:
    53  		return "Build is passing"
    54  	case core.StatusWaiting:
    55  		return "Build is pending"
    56  	case core.StatusPending:
    57  		return "Build is pending"
    58  	case core.StatusRunning:
    59  		return "Build is running"
    60  	case core.StatusSkipped:
    61  		return "Build was skipped"
    62  	default:
    63  		return "Build is in an unknown state"
    64  	}
    65  }
    66  
    67  func convertStatus(state string) scm.State {
    68  	switch state {
    69  	case core.StatusBlocked:
    70  		return scm.StatePending
    71  	case core.StatusDeclined:
    72  		return scm.StateCanceled
    73  	case core.StatusError:
    74  		return scm.StateError
    75  	case core.StatusFailing:
    76  		return scm.StateFailure
    77  	case core.StatusKilled:
    78  		return scm.StateCanceled
    79  	case core.StatusPassing:
    80  		return scm.StateSuccess
    81  	case core.StatusPending:
    82  		return scm.StatePending
    83  	case core.StatusRunning:
    84  		return scm.StatePending
    85  	case core.StatusSkipped:
    86  		return scm.StateUnknown
    87  	default:
    88  		return scm.StateUnknown
    89  	}
    90  }