@@ -43,6 +43,12 @@ func execCreateSalsaProject(args []string) {
43
43
log .Fatalf ("Could not create webhook on salsa project: %s\n " , err )
44
44
}
45
45
46
+ for _ , branch := range []string {"master" , "debian/*" , "upstream" , "upstream/*" , "pristine-tar" } {
47
+ if err := protectSalsaProjectBranch (gitlabProject .ID , branch , token ); err != nil {
48
+ log .Printf ("Could not protect branch %s: %s\n " , branch , err )
49
+ }
50
+ }
51
+
46
52
}
47
53
48
54
func postFormToSalsaApi (path string , data url.Values , token string ) (* http.Response , error ) {
@@ -51,6 +57,29 @@ func postFormToSalsaApi(path string, data url.Values, token string) (*http.Respo
51
57
return http .PostForm (postUrl , data )
52
58
}
53
59
60
+ func protectSalsaProjectBranch (projectId int , branch , token string ) error {
61
+ postPath := "/projects/" + strconv .Itoa (projectId ) + "/protected_branches"
62
+
63
+ response , err := postFormToSalsaApi (postPath ,
64
+ url.Values {
65
+ "name" : {branch },
66
+ },
67
+ token )
68
+ if err != nil {
69
+ return err
70
+ }
71
+
72
+ if response .StatusCode != http .StatusCreated {
73
+ responseData , _ := ioutil .ReadAll (response .Body )
74
+
75
+ return fmt .Errorf ("http status %d: %s" ,
76
+ response .StatusCode ,
77
+ responseData )
78
+ }
79
+
80
+ return nil
81
+ }
82
+
54
83
func createSalsaWebhook (projectId int , webhookUrl , token string ) error {
55
84
postPath := "/projects/" + strconv .Itoa (projectId ) + "/hooks"
56
85
0 commit comments