1 | import request from "./request";
|
2 | import config from "../config";
|
3 | const { gitlab } = config;
|
4 |
|
5 | export default {
|
6 |
|
7 | async exists(projectName, branch){
|
8 | try{
|
9 | await request.get(`${gitlab["api-url"]}/projects/${gitlab.projects[projectName]}/repository/branches/${branch}?private_token=${gitlab["private-token"]}`);
|
10 | return true;
|
11 | }catch(e){
|
12 | if(e.type === "status" && e.value === 404){
|
13 | return false;
|
14 | }else{
|
15 | throw e.value;
|
16 | }
|
17 | }
|
18 | },
|
19 |
|
20 | async create(projectName, branch){
|
21 | try{
|
22 | await request.post(`${gitlab["api-url"]}/projects/${gitlab.projects[projectName]}/repository/branches?private_token=${gitlab["private-token"]}`, {
|
23 | "branch_name": branch,
|
24 | "ref": "template"
|
25 | });
|
26 | }catch(e){
|
27 | throw e.value;
|
28 | }
|
29 | }
|
30 | } |
\ | No newline at end of file |