DevOpsJavaScript funciones
Las reglas de automatización incluyen una biblioteca de DevOps funciones que ayudan a automatizar los flujos de trabajo de su empresa.
DevOps funciones
DevOps Las funciones no están disponibles de forma predeterminada. Deben cargarse en JavaScript rule. Aquí tienes un ejemplo de cómo puedes hacerlo:
const devOps = context.getService("devOps");
Lista de DevOps funciones
Crear rama
Crea una rama en DevOps la herramienta:createBranch(payload: CreateBranchPayload, repositoryId: string | number): Promise<Branch>
interface CreateBranchPayload{
name: string // name of the creating branch
ref: string // name of the branch we create from
}
repositoryId: number | string // Internal integration Id or internal in DevOps tool Id or repository name.
const devOps = context.getService("devOps")
await devOps.createBranch({name: 'feature/us12345', ref: 'masster'}, 'my_repo_name')
// creates branch 'feature/us12345' from 'master' in repository 'my_repo_name'
Crear solicitud de fusión
Crea una solicitud de fusión en DevOps la herramienta:createMergeRequest(payload: CreateMergeRequestPayload): Promise<MergeRequest> MergeRequestinterface CreateMergeRequestPayload {
source: {
branch: string // Source branch name
repositoryId: number // In integration id of repository
}
target: {
branch: string // Target branch name
repositoryId: number // In integration id of repository
}
title: string // Merge request title
}
const devOps = context.getService("devOps")
await devOps.createMergeRequest({
source: {
branch: 'feature/us12345',
repositoryId: 1
},
target: {
branch: 'master',
repositoryId: 1
},
title: 'US#12345 add sample merge request'
})
// creates merge request with title 'US#12345 add sample merge request' in repository with an integration id 1 from branch 'feature/us12345' to branch 'master'
Obtener ramas
Devuelve DevOps los datos adjuntos a las entidades TargetprocessgetBranches(filter: {entitties: number[]}): Promise<BranchFull> especificadas. BranchFullconst devOps = context.getService("devOps")
const branches = await devOps.getBranches({entities: [123, 124, 125]})
// Returns all branches attached to Targetprocess entitites with ids 123, 124 and 125 (directly or via merge request)
Combinar solicitud de combinación
Fusiona la solicitud de fusión con el ID especificado (en la integración) en DevOps la herramienta.mergeMergeRequest(mergeRequestId: number): Promise<void>const devOps = context.getService("devOps")
await devOps.mergeMergeRequest(1)
// Merges merge request with an integration id 1.
Ayudantes para el cambio de estado de las solicitudes de fusión:
Cuando se utiliza DevOps la fuente devOps, el servicio proporciona una lista de ayudas útiles para comprobar si se ha producido alguna transición específica:mergeRequestClosed(event: DevOpsChangedEntityEvent): booleanmergeRequestMerged(event: DevOpsChangedEntityEvent): booleanmergeRequestUnapproved(event: DevOpsChangedEntityEvent): booleanmergeRequestRejected(event: DevOpsChangedEntityEvent): booleanmergeRequestApproved(event: DevOpsChangedEntityEvent): booleanmergeRequestDraftRemoved(event: DevOpsChangedEntityEvent): booleanmergeRequestDraftAdded(event: DevOpsChangedEntityEvent): booleanmergeRequestCreated(event: DevOpsChangedEntityEvent): boolean DevOpsChangedEntityEventconst devOps = context.getService("devOps")
// Args represents incoming event in js executor context. So if DevOps events source is selected in rule args will contain devops event.
const created = devOps.mergeRequestCreated(args) // will return true if current event is merge request created event
const draftAdded = devOps.mergeRequestDraftAdded(args) // will return true if merge request moved to draft state in DevOps tool. In some tool is is called WIP (Work in progress)
const draftRemoved = devOps.mergeRequestDraftRemoved(args) // will return true if merge request moved to not draft state in DevOps tool. In some tool is is called WIP (Work in progress) and will mean that merge request is not WIP any more
const mergeRequestApproved = devOps.mergeRequestApproved(args) // will return true if merge request got required amount of approvals by the tool policy. If 0 approvals required will become true when merge request gets at least one approve.
const mergeRequestRejected = devOps.mergeRequestRejected(args) // will return true if merge request got rejected after the code review. Some tools(like Phabricator for example) allow not only approve but also reject changes.
const mergeRequestUnapproved = devops.mergeRequestUnapproved(args) // will return true if merge request was in approved state but someone removed his approval and merge request has become not approved anymore according to the tool policies
const mergeRequestMerged = devops.mergeRequestMerged(args) // wiil return if current event signalize about merge request merge in DevOps tool.
const mergeRequestClosed = devops.mergeRequestClosed(args) // will return if current event signalizes a merge request close(this action has different name in different tools close, abandon, remove etc. Usualy means changes in merge request should not be integrated) in DevOps tool.