UNPKG

958 BJavaScriptView Raw
1import request from "./request";
2import config from "../config";
3const { gitlab } = config;
4
5export 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