[DO-103] eva_api_class (#9)
[DO-103] Created class for work with Eva API Added method that to create link in eva objects Added method for getting taskId Reviewed-on: https://git.avroid.tech/DevOps/jenkins-shared-lib/pulls/9 Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech> Co-committed-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
This commit is contained in:
committed by
Denis Patrakeev
parent
72c8f18cd2
commit
86740d0fb5
91
src/tech/avroid/api/Eva.groovy
Normal file
91
src/tech/avroid/api/Eva.groovy
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
import groovy.json.JsonOutput
|
||||||
|
import groovy.json.JsonSlurper
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class for work with API Eva
|
||||||
|
*/
|
||||||
|
class Eva implements Serializable {
|
||||||
|
private Script script
|
||||||
|
private String host
|
||||||
|
private String creds
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor
|
||||||
|
* @param script Script - script context
|
||||||
|
* @param host String - url of Eva service
|
||||||
|
* @param creds String - jenkins credentials with eva token for API work
|
||||||
|
*/
|
||||||
|
Eva(Script script, String host, String creds) {
|
||||||
|
this.script = script
|
||||||
|
this.host = host
|
||||||
|
this.creds = creds
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create new link for Eva Object. For example, tasks
|
||||||
|
* !WARNING: can to create multiple similar links
|
||||||
|
* @param parentId String - id of Object for which created link
|
||||||
|
* @param linkName String - name of link
|
||||||
|
* @param url String - full url of link
|
||||||
|
* @return Boolean - success or failure create
|
||||||
|
*/
|
||||||
|
public createLink(String parentId, String linkName, String url) {
|
||||||
|
Map body = [
|
||||||
|
jsonrpc: "1.2",
|
||||||
|
method: "CmfLink.create",
|
||||||
|
kwargs: [
|
||||||
|
parent: parentId,
|
||||||
|
name: linkName,
|
||||||
|
url: url
|
||||||
|
]]
|
||||||
|
|
||||||
|
script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) {
|
||||||
|
script.httpRequest(
|
||||||
|
url: "$host/api/",
|
||||||
|
contentType: 'APPLICATION_JSON',
|
||||||
|
httpMode: 'POST',
|
||||||
|
customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]],
|
||||||
|
validResponseCodes: '200',
|
||||||
|
requestBody: JsonOutput.toJson(body)
|
||||||
|
)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting Eva task id
|
||||||
|
* @param filterValue String - value for search task
|
||||||
|
* @param filterParam String - type of filter for search task. Default value - "code"
|
||||||
|
* @return String - id of task
|
||||||
|
*/
|
||||||
|
public String getTaskId(String filterValue, String filterParam = "code") {
|
||||||
|
String response = getTask(filterValue, filterParam)
|
||||||
|
|
||||||
|
return new JsonSlurper().parseText(response).result.id
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Getting Eva task information
|
||||||
|
* @param filterValue String - value for search task
|
||||||
|
* @param filterParam String - type of filter for search task. Default value - "code"
|
||||||
|
* @return String - id of task
|
||||||
|
*/
|
||||||
|
private String getTask(String filterValue, String filterParam = "code") {
|
||||||
|
Map body = [
|
||||||
|
jsonrpc: "1.2",
|
||||||
|
method: "CmfTask.get",
|
||||||
|
kwargs: [
|
||||||
|
filter: [filterParam, "==", filterValue],
|
||||||
|
]]
|
||||||
|
|
||||||
|
script.withCredentials([script.string(credentialsId: creds, variable: 'token')]) {
|
||||||
|
return script.httpRequest(
|
||||||
|
url: "$host/api/",
|
||||||
|
contentType: 'APPLICATION_JSON',
|
||||||
|
httpMode: 'POST',
|
||||||
|
customHeaders: [[name: 'Authorization', value: "Bearer $script.token"]],
|
||||||
|
validResponseCodes: '200',
|
||||||
|
requestBody: JsonOutput.toJson(body)
|
||||||
|
).content.toString()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -4,7 +4,6 @@ import groovy.json.JsonOutput
|
|||||||
* Class for work with API gitea
|
* Class for work with API gitea
|
||||||
*/
|
*/
|
||||||
class Gitea implements Serializable {
|
class Gitea implements Serializable {
|
||||||
|
|
||||||
private Script script
|
private Script script
|
||||||
private String projectURL
|
private String projectURL
|
||||||
private String creds
|
private String creds
|
||||||
|
|||||||
Reference in New Issue
Block a user