-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
64 lines (49 loc) · 1.96 KB
/
main.js
File metadata and controls
64 lines (49 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { registerPipeline } from '../modules/storage.js'
const showDebugInformation = false;
window.onload = async function () {
const parameters = new URL(window.location).searchParams;
if (showDebugInformation) {
const technicalInformationTextArea = document.getElementById("technical-information");
parameters.forEach(function (value, key, parent) {
technicalInformationTextArea.value += key + ": " + value + "\n";
});
}
const gitLabProjectId = parameters.get("gitlab_project_id");
const get_latest = parameters.get("latest");
const gitLabPipelineId = parameters.get("gitlab_pipeline_id");
const gitLabJobId = parameters.get("gitlab_job_id");
if(get_latest != 1){
await registerPipeline(gitLabProjectId, gitLabPipelineId, gitLabJobId);
}
if (showDebugInformation) {
await new Promise(r => setTimeout(r, 5000));
}
const token = localStorage.getItem("gitlab-api-token");
if (token) {
if(get_latest==1){
await latest(gitLabProjectId, token);
}else{
window.location = "../dashboard/";
}
return;
} else {
alert("Please set up the GitLab connection, then go to the dashboard!");
window.location = "../gitlab-setup/";
return;
}
}
async function latest(projectId, token) {
const jobResponse = await fetch(
`https://codebase.helmholtz.cloud/api/v4/projects/${projectId}/jobs/`,
{ headers: { "Content-Type": "application/json", "PRIVATE-TOKEN": token } }
);
if (!jobResponse.ok) {
alert("Fetching pipeline failed");
return;
}
const jobData = await jobResponse.json();
const jobId = jobData[0]["id"];
const pipelineId = jobData[0]["pipeline"]["id"];
window.location = `../callback?gitlab_project_id=${projectId}&gitlab_pipeline_id=${pipelineId}&gitlab_job_id=${jobId}&latest=2`;
//gitlab_pipeline_id=618554&gitlab_job_id=2513432
}