2022-09-04 19:43:53 +00:00
|
|
|
export class WorkRepository {
|
|
|
|
constructor(res) {
|
|
|
|
if (res) {
|
|
|
|
this.update(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-30 10:41:34 +00:00
|
|
|
update({ id, id_user, id_work, uri, secret, last_check, already_used }) {
|
2022-09-04 19:43:53 +00:00
|
|
|
this.id = id;
|
|
|
|
this.id_user = id_user;
|
|
|
|
this.id_work = id_work;
|
|
|
|
this.uri = uri;
|
2022-09-05 10:20:33 +00:00
|
|
|
this.secret = secret;
|
2022-09-04 19:43:53 +00:00
|
|
|
this.last_check = last_check;
|
2022-09-30 10:41:34 +00:00
|
|
|
this.already_used = already_used == true;
|
2022-09-04 19:43:53 +00:00
|
|
|
}
|
|
|
|
|
2022-11-20 14:53:50 +00:00
|
|
|
async delete(userid) {
|
|
|
|
let url = this.id_work?`works/${this.id_work}/repositories/${this.id}`:`repositories/${this.id}`;
|
|
|
|
|
|
|
|
if (userid) {
|
|
|
|
url = `users/${userid}/` + url;
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await fetch("api/" + url, {
|
2022-09-04 19:43:53 +00:00
|
|
|
method: 'DELETE',
|
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 01:30:10 +00:00
|
|
|
async getBuildState() {
|
2022-09-07 19:02:45 +00:00
|
|
|
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/state`:`api/repositories/${this.id}/state`, {
|
2022-09-05 01:30:10 +00:00
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-16 10:03:50 +00:00
|
|
|
async getBuildLogs(userid) {
|
|
|
|
let url = this.id_work?`works/${this.id_work}/repositories/${this.id}/state-logs`:`repositories/${this.id}/state-logs`;
|
|
|
|
|
|
|
|
if (userid) {
|
|
|
|
url = `users/${userid}/` + url;
|
|
|
|
}
|
|
|
|
|
|
|
|
const res = await fetch("api/" + url, {
|
2022-09-05 02:58:48 +00:00
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-11-11 12:27:09 +00:00
|
|
|
async retrieveWork(admin_struct) {
|
2022-09-07 19:02:45 +00:00
|
|
|
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/trigger`:`api/repositories/${this.id}/trigger`, {
|
2022-09-04 21:54:10 +00:00
|
|
|
method: 'POST',
|
2022-09-25 15:41:47 +00:00
|
|
|
headers: {'Accept': 'application/json'},
|
2022-11-11 12:27:09 +00:00
|
|
|
body: !admin_struct?{}:JSON.stringify(admin_struct)
|
2022-09-04 21:54:10 +00:00
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
const data = await res.json();
|
|
|
|
this.update(data);
|
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-01-01 20:11:20 +00:00
|
|
|
async runGradation() {
|
|
|
|
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/gradation`:`api/repositories/${this.id}/gradation`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {'Accept': 'application/json'},
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-03-06 02:44:39 +00:00
|
|
|
async gradationStatus() {
|
|
|
|
const res = await fetch(this.id_work?`api/works/${this.id_work}/repositories/${this.id}/gradation_status`:`api/repositories/${this.id}/gradation_status`, {
|
|
|
|
method: 'GET',
|
|
|
|
headers: {'Accept': 'application/json'},
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-25 17:25:27 +00:00
|
|
|
async save(user) {
|
2022-09-07 19:02:45 +00:00
|
|
|
let url = this.id?`repositories/${this.id}`:'repositories';
|
|
|
|
|
|
|
|
if (this.id_work) {
|
|
|
|
url = `works/${this.id_work}/` + url;
|
|
|
|
}
|
2022-09-25 17:25:27 +00:00
|
|
|
if (user != null) {
|
|
|
|
url = `users/${user.id}/` + url;
|
|
|
|
}
|
2022-09-07 19:02:45 +00:00
|
|
|
|
|
|
|
const res = await fetch("api/"+url, {
|
2022-09-04 19:43:53 +00:00
|
|
|
method: this.id?'PUT':'POST',
|
|
|
|
headers: {'Accept': 'application/json'},
|
|
|
|
body: JSON.stringify(this),
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
const data = await res.json();
|
|
|
|
this.update(data);
|
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getRemoteRepositories(userid) {
|
|
|
|
const res = await fetch(userid?`api/users/${userid}/gitlabcri/repositories`:`api/gitlabcri/repositories`, {headers: {'Accept': 'application/json'}})
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getRepositories(wid, userid) {
|
|
|
|
const res = await fetch(userid?`api/users/${userid}/works/${wid}/repositories`:`api/works/${wid}/repositories`, {headers: {'Accept': 'application/json'}})
|
|
|
|
if (res.status == 200) {
|
2022-09-16 10:02:47 +00:00
|
|
|
const data = await res.json()
|
|
|
|
if (data) {
|
|
|
|
return data.map((r) => new WorkRepository(r));
|
|
|
|
} else {
|
2022-09-16 14:43:57 +00:00
|
|
|
throw new Error("No repository attached");
|
2022-09-16 10:02:47 +00:00
|
|
|
}
|
2022-09-04 19:43:53 +00:00
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function getRepository(kid) {
|
|
|
|
const res = await fetch(`api/repositories/${kid}`, {headers: {'Accept': 'application/json'}})
|
|
|
|
if (res.status == 200) {
|
|
|
|
return new Repository(await res.json());
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|