2018-11-20 20:47:30 +05:30
< script >
2020-10-24 23:57:45 +05:30
import { GlSprintf , GlLink } from '@gitlab/ui' ;
2021-03-11 19:13:27 +05:30
import { isEmpty } from 'lodash' ;
2018-12-13 13:39:08 +05:30
import CiIcon from '~/vue_shared/components/ci_icon.vue' ;
2022-06-21 17:19:12 +05:30
import { _ _ } from '~/locale' ;
2018-11-20 20:47:30 +05:30
2018-12-13 13:39:08 +05:30
export default {
2020-08-18 19:51:02 +05:30
creatingEnvironment : 'creating' ,
2018-12-13 13:39:08 +05:30
components : {
CiIcon ,
2020-08-18 19:51:02 +05:30
GlSprintf ,
GlLink ,
2018-12-13 13:39:08 +05:30
} ,
props : {
deploymentStatus : {
type : Object ,
required : true ,
2018-11-20 20:47:30 +05:30
} ,
2020-03-13 15:44:24 +05:30
deploymentCluster : {
type : Object ,
required : false ,
default : null ,
} ,
2018-12-13 13:39:08 +05:30
iconStatus : {
type : Object ,
required : true ,
2018-11-20 20:47:30 +05:30
} ,
2018-12-13 13:39:08 +05:30
} ,
computed : {
environment ( ) {
switch ( this . deploymentStatus . status ) {
case 'last' :
2019-12-21 20:55:43 +05:30
return this . lastEnvironmentMessage ( ) ;
2018-12-13 13:39:08 +05:30
case 'out_of_date' :
2019-12-21 20:55:43 +05:30
return this . outOfDateEnvironmentMessage ( ) ;
2018-12-13 13:39:08 +05:30
case 'failed' :
2019-12-21 20:55:43 +05:30
return this . failedEnvironmentMessage ( ) ;
2020-08-18 19:51:02 +05:30
case this . $options . creatingEnvironment :
2019-12-21 20:55:43 +05:30
return this . creatingEnvironmentMessage ( ) ;
2018-12-13 13:39:08 +05:30
default :
2019-12-21 20:55:43 +05:30
return '' ;
2018-12-13 13:39:08 +05:30
}
2018-12-05 23:21:45 +05:30
} ,
2018-12-13 13:39:08 +05:30
environmentLink ( ) {
if ( this . hasEnvironment ) {
2020-08-18 19:51:02 +05:30
return {
link : this . deploymentStatus . environment . environment _path ,
name : this . deploymentStatus . environment . name ,
} ;
2018-12-13 13:39:08 +05:30
}
2020-08-18 19:51:02 +05:30
return { } ;
2018-12-13 13:39:08 +05:30
} ,
hasLastDeployment ( ) {
return this . hasEnvironment && this . deploymentStatus . environment . last _deployment ;
} ,
lastDeployment ( ) {
return this . hasLastDeployment ? this . deploymentStatus . environment . last _deployment : { } ;
} ,
hasEnvironment ( ) {
2020-03-13 15:44:24 +05:30
return ! isEmpty ( this . deploymentStatus . environment ) ;
2018-12-13 13:39:08 +05:30
} ,
lastDeploymentPath ( ) {
2020-03-13 15:44:24 +05:30
return ! isEmpty ( this . lastDeployment . deployable )
2018-12-13 13:39:08 +05:30
? this . lastDeployment . deployable . build _path
: '' ;
} ,
2019-12-04 20:38:33 +05:30
hasCluster ( ) {
2020-03-13 15:44:24 +05:30
return Boolean ( this . deploymentCluster ) && Boolean ( this . deploymentCluster . name ) ;
2019-12-04 20:38:33 +05:30
} ,
clusterNameOrLink ( ) {
if ( ! this . hasCluster ) {
return '' ;
}
2020-03-13 15:44:24 +05:30
const { name , path } = this . deploymentCluster ;
2019-12-04 20:38:33 +05:30
2020-08-18 19:51:02 +05:30
return {
path ,
name ,
} ;
2019-12-04 20:38:33 +05:30
} ,
2020-03-13 15:44:24 +05:30
kubernetesNamespace ( ) {
return this . hasCluster ? this . deploymentCluster . kubernetes _namespace : null ;
} ,
2020-08-18 19:51:02 +05:30
deploymentLink ( ) {
return {
path : this . lastDeploymentPath ,
name :
this . deploymentStatus . status === this . $options . creatingEnvironment
? _ _ ( 'latest deployment' )
: _ _ ( 'most recent deployment' ) ,
} ;
} ,
2018-12-13 13:39:08 +05:30
} ,
methods : {
2019-12-21 20:55:43 +05:30
failedEnvironmentMessage ( ) {
2020-08-18 19:51:02 +05:30
return _ _ ( 'The deployment of this job to %{environmentLink} did not succeed.' ) ;
2019-12-21 20:55:43 +05:30
} ,
lastEnvironmentMessage ( ) {
2020-08-18 19:51:02 +05:30
if ( this . hasCluster ) {
if ( this . kubernetesNamespace ) {
return _ _ (
'This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// we know the cluster but not the namespace
2020-08-18 19:51:02 +05:30
return _ _ ( 'This job is deployed to %{environmentLink} using cluster %{clusterNameOrLink}.' ) ;
2020-03-13 15:44:24 +05:30
}
// not a cluster deployment
2020-08-18 19:51:02 +05:30
return _ _ ( 'This job is deployed to %{environmentLink}.' ) ;
2019-12-21 20:55:43 +05:30
} ,
outOfDateEnvironmentMessage ( ) {
2020-08-18 19:51:02 +05:30
if ( this . hasLastDeployment ) {
if ( this . hasCluster ) {
if ( this . kubernetesNamespace ) {
return _ _ (
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}. View the %{deploymentLink}.' ,
2019-12-21 20:55:43 +05:30
) ;
2020-03-13 15:44:24 +05:30
}
// we know the cluster but not the namespace
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}. View the %{deploymentLink}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// not a cluster deployment
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is an out-of-date deployment to %{environmentLink}. View the %{deploymentLink}.' ,
2019-12-21 20:55:43 +05:30
) ;
}
2020-03-13 15:44:24 +05:30
// no last deployment, i.e. this is the first deployment
2020-08-18 19:51:02 +05:30
if ( this . hasCluster ) {
if ( this . kubernetesNamespace ) {
return _ _ (
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// we know the cluster but not the namespace
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is an out-of-date deployment to %{environmentLink} using cluster %{clusterNameOrLink}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// not a cluster deployment
2020-08-18 19:51:02 +05:30
return _ _ ( 'This job is an out-of-date deployment to %{environmentLink}.' ) ;
2019-12-21 20:55:43 +05:30
} ,
creatingEnvironmentMessage ( ) {
2020-08-18 19:51:02 +05:30
if ( this . hasLastDeployment ) {
if ( this . hasCluster ) {
if ( this . kubernetesNamespace ) {
return _ _ (
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}. This will overwrite the %{deploymentLink}.' ,
2019-12-21 20:55:43 +05:30
) ;
2020-03-13 15:44:24 +05:30
}
// we know the cluster but not the namespace
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}. This will overwrite the %{deploymentLink}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// not a cluster deployment
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is creating a deployment to %{environmentLink}. This will overwrite the %{deploymentLink}.' ,
2019-12-21 20:55:43 +05:30
) ;
}
2020-03-13 15:44:24 +05:30
// no last deployment, i.e. this is the first deployment
2020-08-18 19:51:02 +05:30
if ( this . hasCluster ) {
if ( this . kubernetesNamespace ) {
return _ _ (
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink} and namespace %{kubernetesNamespace}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// we know the cluster but not the namespace
2020-08-18 19:51:02 +05:30
return _ _ (
'This job is creating a deployment to %{environmentLink} using cluster %{clusterNameOrLink}.' ,
2020-03-13 15:44:24 +05:30
) ;
}
// not a cluster deployment
2020-08-18 19:51:02 +05:30
return _ _ ( 'This job is creating a deployment to %{environmentLink}.' ) ;
2019-12-21 20:55:43 +05:30
} ,
2018-12-13 13:39:08 +05:30
} ,
} ;
2018-11-20 20:47:30 +05:30
< / script >
< template >
2020-07-28 23:09:34 +05:30
< div class = "gl-mt-3 gl-mb-3 js-environment-container" >
2018-11-20 20:47:30 +05:30
< div class = "environment-information" >
2019-02-15 15:39:39 +05:30
< ci-icon :status = "iconStatus" / >
2020-08-18 19:51:02 +05:30
< p class = "inline gl-mb-0" >
< gl-sprintf :message = "environment" >
< template # environmentLink >
< gl-link
v - if = "hasEnvironment"
: href = "environmentLink.link"
data - testid = "job-environment-link"
2022-08-27 11:52:29 +05:30
> { { environmentLink . name } } < / g l - l i n k
>
2020-08-18 19:51:02 +05:30
< / template >
< template # clusterNameOrLink >
< gl-link
v - if = "clusterNameOrLink.path"
: href = "clusterNameOrLink.path"
data - testid = "job-cluster-link"
2022-08-27 11:52:29 +05:30
> { { clusterNameOrLink . name } } < / g l - l i n k
>
2020-08-18 19:51:02 +05:30
< template v-else > {{ clusterNameOrLink.name }} < / template >
< / template >
2021-03-11 19:13:27 +05:30
< template # kubernetesNamespace > { { kubernetesNamespace } } < / template >
2020-08-18 19:51:02 +05:30
< template # deploymentLink >
2022-08-27 11:52:29 +05:30
< gl-link :href = "deploymentLink.path" data -testid = " job -deployment -link " > { {
deploymentLink . name
} } < / gl-link >
2020-08-18 19:51:02 +05:30
< / template >
< / gl-sprintf >
< / p >
2018-11-20 20:47:30 +05:30
< / div >
< / div >
< / template >