You need to sign in to do that
Don't have an account?
Sreenu Reddy 16
How to get auto updated status response from External server (Git)
In lightning component if I enter a branch name and hit a button in UI page it invoke/run the git pipeline after get the Json response,The response having Status, Job id and displayed same response in outfield of same page .
Here i am getting status as intial stage f pipeline .But I want to get auto update status. means if git pipelines are running its status changed like pipeline status changes pending, running, success/failure .
I want to ;update that same status in a Component ui page bellow it my code
GitInvoke.Cmp:
<aura:component controller="callOutInvoke2" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="branchName" type="String"/>
<aura:attribute name="jobId" type="String"/>
<aura:attribute name="response" type="object"/>
<aura:attribute name="status" type="String"/>
<aura:registerEvent name="loadMyEvent" type="c:GitpipelineStatusEvt_1"/><br/>
<lightning:card class="slds-card slds-has-bottom-magnet" >
<div class = "slds-grid slds-grid_vertical slds-text-color--default slds-align_absolute-center">
<div class="page-section page-header slds-align_absolute-center slds-text-heading_large" style="height:2rem">
<h2 class="header" style="font-weight: bold;">Invoke GIT Pipeline </h2>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<b><lightning:input type="text" name="input1" value="{!v.branchName}" label="Enter Future Branch" /></b>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<h2 class="header">Job Status :{!v.status}</h2> <br/>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<h2 class="header">Jobid :{!v.jobId}</h2>
</div>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<lightning:button variant="brand" label="Invoke GIT" onclick="{! c.calloutCtrl }" />
</div>
</lightning:card>
</aura:component>
GitInvoke.controller:
({
calloutCtrl : function(component, event, helper) {
helper.getResponse(component, event,helper);
}
})
GitInvoke.Helper:
({ getResponse : function(component, event,helper) {
var bname=component.get("v.branchName");
var action = component.get("c.getCalloutResponseContents");
action.setParams({"branchName": bname});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.response", response.getReturnValue());
var getStatus = component.get("v.response").status;
var getJobId = component.get("v.response").id;
component.set("v.status",getStatus);
component.set("v.jobId",getJobId);
var evt = $A.get("e.c:GitpipelineStatusEvt_1");
evt.setParams({ "Pass_Result": getJobId});
var evtParam=evt.getParam("Pass_Result");
evt.fire();
}
else{
alert('Failed call from parent!!');
}
});
$A.enqueueAction(action);
}
})
callOutInvoke2.class :
public class callOutInvoke2 {
@AuraEnabled
public static Sr_calloutGitPipelineResponseWrapper getCalloutResponseContents(String branchName) {
system.debug('url'+branchName);
String gitBranch=branchName;
String endPoint;
if(gitBranch=='Develop'){
endPoint=system.label.gitDevelop;
}
else if(gitBranch=='Integration'){
endPoint=system.label.gitIntegration;
}
else if(gitBranch=='Master'){
endPoint=system.label.gitMaster;
}
else
endPoint=system.label.gitMaster;
system.debug('endPoint---'+endPoint);
String authToken=system.label.gitToken;
callOutGitPipelineWrapper requestPayload=new callOutGitPipelineWrapper();
requestPayload.branchName=branchName;
String jsonReq = JSON.serialize(requestPayload);
// Instantiate a new http object
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader( 'Content-Type', 'application/json' );
request.setHeader( 'Accept', 'application/json' );
request.setHeader( 'Authorization', 'Bearer ' + authToken );
request.setEndpoint(endPoint);
request.setMethod('POST');
request.setBody(jsonReq);
System.debug('request:--> ' + request.getBody());
// Send the request, and return a response
HttpResponse res = http.send(request);
System.debug('response:--> ' + res.getBody());
Sr_calloutGitPipelineResponseWrapper callList= (Sr_calloutGitPipelineResponseWrapper)JSON.deserialize(res.getBody(), Sr_calloutGitPipelineResponseWrapper.class);
system.debug('result-->' + callList);
return callList;
}
public class callOutGitPipelineWrapper{
string branchName { get; set; }
String Id { get; set; }
}
}
Sr_calloutGitPipelineResponsewrapperclass:
public class Sr_calloutGitPipelineResponseWrapper {
public class Detailed_status {
public String icon {get;set;}
public String text {get;set;}
public String label {get;set;}
public String group_Z {get;set;} // in json: group
public String tooltip {get;set;}
public Boolean has_details {get;set;}
public String details_path {get;set;}
public Object illustration {get;set;}
public String favicon {get;set;}
public Detailed_status(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'icon') {
icon = parser.getText();
} else if (text == 'text') {
text = parser.getText();
} else if (text == 'label') {
label = parser.getText();
} else if (text == 'group') {
group_Z = parser.getText();
} else if (text == 'tooltip') {
tooltip = parser.getText();
} else if (text == 'has_details') {
has_details = parser.getBooleanValue();
} else if (text == 'details_path') {
details_path = parser.getText();
} else if (text == 'illustration') {
illustration = parser.readValueAs(Object.class);
} else if (text == 'favicon') {
favicon = parser.getText();
} else {
System.debug(LoggingLevel.WARN, 'Detailed_status consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
public class User {
public Integer id {get;set;}
public String name {get;set;}
public String username {get;set;}
public String state {get;set;}
public String avatar_url {get;set;}
public String web_url {get;set;}
public User(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'id') {
id = parser.getIntegerValue();
} else if (text == 'name') {
name = parser.getText();
} else if (text == 'username') {
username = parser.getText();
} else if (text == 'state') {
state = parser.getText();
} else if (text == 'avatar_url') {
avatar_url = parser.getText();
} else if (text == 'web_url') {
web_url = parser.getText();
} else {
System.debug(LoggingLevel.WARN, 'User consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
@AuraEnabled
public Integer id {get;set;}
public String sha {get;set;}
public String ref {get;set;}
@AuraEnabled
public String status {get;set;}
public String created_at {get;set;}
public String updated_at {get;set;}
public String web_url {get;set;}
public String before_sha {get;set;}
public Boolean tag {get;set;}
public Object yaml_errors {get;set;}
public User user {get;set;}
public Object started_at {get;set;}
public Object finished_at {get;set;}
public Object committed_at {get;set;}
public Object duration {get;set;}
public Object coverage {get;set;}
public Detailed_status detailed_status {get;set;}
public Sr_calloutGitPipelineResponseWrapper(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'id') {
id = parser.getIntegerValue();
} else if (text == 'sha') {
sha = parser.getText();
} else if (text == 'ref') {
ref = parser.getText();
} else if (text == 'status') {
status = parser.getText();
} else if (text == 'created_at') {
created_at = parser.getText();
} else if (text == 'updated_at') {
updated_at = parser.getText();
} else if (text == 'web_url') {
web_url = parser.getText();
} else if (text == 'before_sha') {
before_sha = parser.getText();
} else if (text == 'tag') {
tag = parser.getBooleanValue();
} else if (text == 'yaml_errors') {
yaml_errors = parser.readValueAs(Object.class);
} else if (text == 'user') {
user = new User(parser);
} else if (text == 'started_at') {
started_at = parser.readValueAs(Object.class);
} else if (text == 'finished_at') {
finished_at = parser.readValueAs(Object.class);
} else if (text == 'committed_at') {
committed_at = parser.readValueAs(Object.class);
} else if (text == 'duration') {
duration = parser.readValueAs(Object.class);
} else if (text == 'coverage') {
coverage = parser.readValueAs(Object.class);
} else if (text == 'detailed_status') {
detailed_status = new Detailed_status(parser);
} else {
System.debug(LoggingLevel.WARN, 'calloutGitPipelineResponseWrapper consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
public static calloutGitPipelineResponseWrapper parse(String json) {
System.JSONParser parser = System.JSON.createParser(json);
return new calloutGitPipelineResponseWrapper(parser);
}
public static void consumeObject(System.JSONParser parser) {
Integer depth = 0;
do {
System.JSONToken curr = parser.getCurrentToken();
if (curr == System.JSONToken.START_OBJECT ||
curr == System.JSONToken.START_ARRAY) {
depth++;
} else if (curr == System.JSONToken.END_OBJECT ||
curr == System.JSONToken.END_ARRAY) {
depth--;
}
} while (depth > 0 && parser.nextToken() != null);
}
}
Here i am getting status as intial stage f pipeline .But I want to get auto update status. means if git pipelines are running its status changed like pipeline status changes pending, running, success/failure .
I want to ;update that same status in a Component ui page bellow it my code
GitInvoke.Cmp:
<aura:component controller="callOutInvoke2" implements="force:appHostable,flexipage:availableForAllPageTypes,flexipage:availableForRecordHome,force:hasRecordId" access="global" >
<aura:attribute name="branchName" type="String"/>
<aura:attribute name="jobId" type="String"/>
<aura:attribute name="response" type="object"/>
<aura:attribute name="status" type="String"/>
<aura:registerEvent name="loadMyEvent" type="c:GitpipelineStatusEvt_1"/><br/>
<lightning:card class="slds-card slds-has-bottom-magnet" >
<div class = "slds-grid slds-grid_vertical slds-text-color--default slds-align_absolute-center">
<div class="page-section page-header slds-align_absolute-center slds-text-heading_large" style="height:2rem">
<h2 class="header" style="font-weight: bold;">Invoke GIT Pipeline </h2>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<b><lightning:input type="text" name="input1" value="{!v.branchName}" label="Enter Future Branch" /></b>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<h2 class="header">Job Status :{!v.status}</h2> <br/>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<h2 class="header">Jobid :{!v.jobId}</h2>
</div>
</div>
<div class="page-section page-header slds-align_absolute-center slds-text-heading_medium">
<lightning:button variant="brand" label="Invoke GIT" onclick="{! c.calloutCtrl }" />
</div>
</lightning:card>
</aura:component>
GitInvoke.controller:
({
calloutCtrl : function(component, event, helper) {
helper.getResponse(component, event,helper);
}
})
GitInvoke.Helper:
({ getResponse : function(component, event,helper) {
var bname=component.get("v.branchName");
var action = component.get("c.getCalloutResponseContents");
action.setParams({"branchName": bname});
action.setCallback(this, function(response) {
var state = response.getState();
if (component.isValid() && state === "SUCCESS") {
component.set("v.response", response.getReturnValue());
var getStatus = component.get("v.response").status;
var getJobId = component.get("v.response").id;
component.set("v.status",getStatus);
component.set("v.jobId",getJobId);
var evt = $A.get("e.c:GitpipelineStatusEvt_1");
evt.setParams({ "Pass_Result": getJobId});
var evtParam=evt.getParam("Pass_Result");
evt.fire();
}
else{
alert('Failed call from parent!!');
}
});
$A.enqueueAction(action);
}
})
callOutInvoke2.class :
public class callOutInvoke2 {
@AuraEnabled
public static Sr_calloutGitPipelineResponseWrapper getCalloutResponseContents(String branchName) {
system.debug('url'+branchName);
String gitBranch=branchName;
String endPoint;
if(gitBranch=='Develop'){
endPoint=system.label.gitDevelop;
}
else if(gitBranch=='Integration'){
endPoint=system.label.gitIntegration;
}
else if(gitBranch=='Master'){
endPoint=system.label.gitMaster;
}
else
endPoint=system.label.gitMaster;
system.debug('endPoint---'+endPoint);
String authToken=system.label.gitToken;
callOutGitPipelineWrapper requestPayload=new callOutGitPipelineWrapper();
requestPayload.branchName=branchName;
String jsonReq = JSON.serialize(requestPayload);
// Instantiate a new http object
Http http = new Http();
HttpRequest request = new HttpRequest();
request.setHeader( 'Content-Type', 'application/json' );
request.setHeader( 'Accept', 'application/json' );
request.setHeader( 'Authorization', 'Bearer ' + authToken );
request.setEndpoint(endPoint);
request.setMethod('POST');
request.setBody(jsonReq);
System.debug('request:--> ' + request.getBody());
// Send the request, and return a response
HttpResponse res = http.send(request);
System.debug('response:--> ' + res.getBody());
Sr_calloutGitPipelineResponseWrapper callList= (Sr_calloutGitPipelineResponseWrapper)JSON.deserialize(res.getBody(), Sr_calloutGitPipelineResponseWrapper.class);
system.debug('result-->' + callList);
return callList;
}
public class callOutGitPipelineWrapper{
string branchName { get; set; }
String Id { get; set; }
}
}
Sr_calloutGitPipelineResponsewrapperclass:
public class Sr_calloutGitPipelineResponseWrapper {
public class Detailed_status {
public String icon {get;set;}
public String text {get;set;}
public String label {get;set;}
public String group_Z {get;set;} // in json: group
public String tooltip {get;set;}
public Boolean has_details {get;set;}
public String details_path {get;set;}
public Object illustration {get;set;}
public String favicon {get;set;}
public Detailed_status(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'icon') {
icon = parser.getText();
} else if (text == 'text') {
text = parser.getText();
} else if (text == 'label') {
label = parser.getText();
} else if (text == 'group') {
group_Z = parser.getText();
} else if (text == 'tooltip') {
tooltip = parser.getText();
} else if (text == 'has_details') {
has_details = parser.getBooleanValue();
} else if (text == 'details_path') {
details_path = parser.getText();
} else if (text == 'illustration') {
illustration = parser.readValueAs(Object.class);
} else if (text == 'favicon') {
favicon = parser.getText();
} else {
System.debug(LoggingLevel.WARN, 'Detailed_status consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
public class User {
public Integer id {get;set;}
public String name {get;set;}
public String username {get;set;}
public String state {get;set;}
public String avatar_url {get;set;}
public String web_url {get;set;}
public User(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'id') {
id = parser.getIntegerValue();
} else if (text == 'name') {
name = parser.getText();
} else if (text == 'username') {
username = parser.getText();
} else if (text == 'state') {
state = parser.getText();
} else if (text == 'avatar_url') {
avatar_url = parser.getText();
} else if (text == 'web_url') {
web_url = parser.getText();
} else {
System.debug(LoggingLevel.WARN, 'User consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
}
@AuraEnabled
public Integer id {get;set;}
public String sha {get;set;}
public String ref {get;set;}
@AuraEnabled
public String status {get;set;}
public String created_at {get;set;}
public String updated_at {get;set;}
public String web_url {get;set;}
public String before_sha {get;set;}
public Boolean tag {get;set;}
public Object yaml_errors {get;set;}
public User user {get;set;}
public Object started_at {get;set;}
public Object finished_at {get;set;}
public Object committed_at {get;set;}
public Object duration {get;set;}
public Object coverage {get;set;}
public Detailed_status detailed_status {get;set;}
public Sr_calloutGitPipelineResponseWrapper(JSONParser parser) {
while (parser.nextToken() != System.JSONToken.END_OBJECT) {
if (parser.getCurrentToken() == System.JSONToken.FIELD_NAME) {
String text = parser.getText();
if (parser.nextToken() != System.JSONToken.VALUE_NULL) {
if (text == 'id') {
id = parser.getIntegerValue();
} else if (text == 'sha') {
sha = parser.getText();
} else if (text == 'ref') {
ref = parser.getText();
} else if (text == 'status') {
status = parser.getText();
} else if (text == 'created_at') {
created_at = parser.getText();
} else if (text == 'updated_at') {
updated_at = parser.getText();
} else if (text == 'web_url') {
web_url = parser.getText();
} else if (text == 'before_sha') {
before_sha = parser.getText();
} else if (text == 'tag') {
tag = parser.getBooleanValue();
} else if (text == 'yaml_errors') {
yaml_errors = parser.readValueAs(Object.class);
} else if (text == 'user') {
user = new User(parser);
} else if (text == 'started_at') {
started_at = parser.readValueAs(Object.class);
} else if (text == 'finished_at') {
finished_at = parser.readValueAs(Object.class);
} else if (text == 'committed_at') {
committed_at = parser.readValueAs(Object.class);
} else if (text == 'duration') {
duration = parser.readValueAs(Object.class);
} else if (text == 'coverage') {
coverage = parser.readValueAs(Object.class);
} else if (text == 'detailed_status') {
detailed_status = new Detailed_status(parser);
} else {
System.debug(LoggingLevel.WARN, 'calloutGitPipelineResponseWrapper consuming unrecognized property: '+text);
consumeObject(parser);
}
}
}
}
}
public static calloutGitPipelineResponseWrapper parse(String json) {
System.JSONParser parser = System.JSON.createParser(json);
return new calloutGitPipelineResponseWrapper(parser);
}
public static void consumeObject(System.JSONParser parser) {
Integer depth = 0;
do {
System.JSONToken curr = parser.getCurrentToken();
if (curr == System.JSONToken.START_OBJECT ||
curr == System.JSONToken.START_ARRAY) {
depth++;
} else if (curr == System.JSONToken.END_OBJECT ||
curr == System.JSONToken.END_ARRAY) {
depth--;
}
} while (depth > 0 && parser.nextToken() != null);
}
}