Created
September 5, 2017 10:06
-
-
Save kerbyfc/e3e346d352ee84c56886f7a4716a2565 to your computer and use it in GitHub Desktop.
Gitlab custom script to navigate into pull-request from pipelines page
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const projectIds = { | |
'frontend-react': 315, | |
'frontend': 147, | |
'appliance-face': 353 | |
} | |
const projectName = /main\/([^\/]+)/.exec(location.pathname); | |
if (projectName) { | |
const projectId = projectIds[projectName[1]]; | |
document.querySelector('.content-wrapper').addEventListener('click', (event) => { | |
if (event.target.classList.contains('ref-name')) { | |
if (event.detail === 'forced') { | |
return location.href = event.target.href; | |
} | |
event.preventDefault(); | |
event.stopPropagation(); | |
$.getJSON(`/api/v3/projects/${projectId}/merge_requests?state=opened`) | |
.then((requests) => { | |
const merge_request = requests.find((request) => { | |
return request.source_branch === event.target.text.trim(); | |
}); | |
if (merge_request) { | |
location.href = merge_request.web_url; | |
} else { | |
const forcedEvent = new CustomEvent('click', {detail: 'forced'}); | |
event.target.dispatchEvent(forcedEvent); | |
} | |
}); | |
} | |
}, true); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment