Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
$(".parameterized-build-pullrequest").click(function() {
var prJSON = require('bitbucket/internal/model/page-state').getPullRequest().toJSON();
var branch = prJSON.fromRef.id;
var commit = prJSON.fromRef.latestCommit;
var prDest = prJSON.toRef.displayId;
var resourceUrl = getResourceUrl("getJobs") + "?branch=" + encodeURIComponent(branch) + "&commit=" + commit + "&prdestination=" + encodeURIComponent(prDest) + "&prid=" + prJSON.id;
return $.when(getJobs(resourceUrl)).then(function( jobs ) {
allJobs = jobs
if (jobs.length == 1){
if (jobs[0].buildParameters.length == 0){
var splitBranch = branch.split("/")
splitBranch.splice(0, 2) //remove ref/heads or ref/tags
var branchName = splitBranch.join("%2F")
var buildUrl = getResourceUrl("triggerBuild/0/" + encodeURIComponent(branchName));
triggerBuild(buildUrl);
return false;