2022-09-04 19:43:53 +00:00
|
|
|
export class WorkRepository {
|
|
|
|
constructor(res) {
|
|
|
|
if (res) {
|
|
|
|
this.update(res);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update({ id, id_user, id_work, uri, last_check }) {
|
|
|
|
this.id = id;
|
|
|
|
this.id_user = id_user;
|
|
|
|
this.id_work = id_work;
|
|
|
|
this.uri = uri;
|
|
|
|
this.last_check = last_check;
|
|
|
|
}
|
|
|
|
|
|
|
|
async delete() {
|
|
|
|
const res = await fetch(`api/repositories/${this.id}`, {
|
|
|
|
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() {
|
|
|
|
const res = await fetch(`api/repositories/${this.id}/state`, {
|
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-05 02:58:48 +00:00
|
|
|
async getBuildLogs() {
|
|
|
|
const res = await fetch(`api/repositories/${this.id}/state-logs`, {
|
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
return await res.json();
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-04 21:54:10 +00:00
|
|
|
async retrieveWork() {
|
|
|
|
const res = await fetch(`api/repositories/${this.id}/trigger`, {
|
|
|
|
method: 'POST',
|
|
|
|
headers: {'Accept': 'application/json'}
|
|
|
|
});
|
|
|
|
if (res.status == 200) {
|
|
|
|
const data = await res.json();
|
|
|
|
this.update(data);
|
|
|
|
return data;
|
|
|
|
} else {
|
|
|
|
throw new Error((await res.json()).errmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-04 19:43:53 +00:00
|
|
|
async save() {
|
|
|
|
const res = await fetch(this.id?`api/repositories/${this.id}`:'api/repositories', {
|
|
|
|
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) {
|
|
|
|
return (await res.json()).map((r) => new WorkRepository(r));
|
|
|
|
} 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);
|
|
|
|
}
|
|
|
|
}
|