Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
36 lines
1.9 KiB
JavaScript
36 lines
1.9 KiB
JavaScript
import superagent from 'superagent';
|
|
import request from '../../homebrew/utils/request-middleware.js';
|
|
|
|
const patch = (path)=>superagent.patch(path).set('Homebrewery-Version', global.version);
|
|
|
|
// Dünne Hülle um /api/git/* (ADR 0003 §7). Fehler tragen `HBErrorCode` und `message` des Servers.
|
|
const unwrap = (promise)=>promise.then((res)=>res.body).catch((err)=>{
|
|
const body = err.response?.body ?? {};
|
|
const e = new Error(body.message || err.message);
|
|
e.status = err.response?.status;
|
|
e.HBErrorCode = body.HBErrorCode;
|
|
e.body = body;
|
|
throw e;
|
|
});
|
|
|
|
export const gitApi = {
|
|
listConnections : ()=>unwrap(request.get('/api/git/connections')),
|
|
createConnection : (data)=>unwrap(request.post('/api/git/connections').send(data)),
|
|
updateConnection : (id, data)=>unwrap(patch(`/api/git/connections/${id}`).send(data)),
|
|
deleteConnection : (id)=>unwrap(request.delete(`/api/git/connections/${id}`)),
|
|
testConnection : (id)=>unwrap(request.post(`/api/git/connections/${id}/test`)),
|
|
listBranches : (id)=>unwrap(request.get(`/api/git/connections/${id}/branches`)),
|
|
listFiles : (id, branch, dir)=>unwrap(request.get(`/api/git/connections/${id}/files`).query({ branch, dir })),
|
|
importBrew : (data)=>unwrap(request.post('/api/git/brews/import').send(data)),
|
|
linkBrew : (editId, data)=>unwrap(request.post(`/api/git/brews/${editId}/link`).send(data)),
|
|
unlinkBrew : (editId)=>unwrap(request.delete(`/api/git/brews/${editId}/link`)),
|
|
status : (editId)=>unwrap(request.get(`/api/git/brews/${editId}`)),
|
|
pull : (editId)=>unwrap(request.post(`/api/git/brews/${editId}/pull`))
|
|
};
|
|
|
|
// "Meine Version behalten" (Konfliktdialog G01): der nächste Save hängt ?gitOverwrite=<blob> an.
|
|
let overwriteBlob = null;
|
|
export const setGitOverwrite = (blob)=>{ overwriteBlob = blob; };
|
|
export const consumeGitOverwrite = ()=>{ const b = overwriteBlob; overwriteBlob = null; return b; };
|
|
export const SAVE_EVENT = 'hb:git-save';
|