@@ -17,6 +17,12 @@ GitHub API server address</Description>
17
17
<Default >api.github.com</Default >
18
18
</Parameter >
19
19
20
+ <Parameter name =" Accept" >
21
+ <Description >
22
+ Default accept header for our requests</Description >
23
+ <Default >application/vnd.github.v3+json</Default >
24
+ </Parameter >
25
+
20
26
<Property name =" Request" >
21
27
<Type >%Net.HttpRequest</Type >
22
28
<Internal >1</Internal >
@@ -52,7 +58,7 @@ Unauthenticated requests are associated with an IP address.<br>]]></Description>
52
58
Set ..Request.Https = 1
53
59
Set ..Request.SSLConfiguration = SSLConfig
54
60
Set ..Request.Server= ..#Server
55
- Do ..Request.SetHeader("Accept","application/vnd.github.v3+json" ) // we want 3rd version of api
61
+ Do ..Request.SetHeader("Accept",..#Accept ) // we want 3rd version of api
56
62
57
63
If ($d(Username) && $d(Password) && (Username'="") && (Password'="")) { // supply Username and Passwor, if both are provided. GitHub accept Basic Auth
58
64
Set ..Request.Username = Username // https://developer.github.com/v3/auth/
@@ -161,8 +167,24 @@ Add repository to team.<br>
161
167
</Method >
162
168
163
169
<Method name =" ProtectBranch" >
164
- <FormalSpec >Owner:%String,Repo:%String,Branch:%String</FormalSpec >
170
+ <Description ><![CDATA[
171
+ Protect branch<br>
172
+ <var>Owner</var> - owner of repository<br>
173
+ <var>Repo</var> - repository name (eg. Cache-MDX2JSON)<br>
174
+ <var>Branch</var> - branch to protect<br>
175
+ <a href="https://help.github.com/articles/about-protected-branches/">About</a> protected branches]]> </Description >
176
+ <FormalSpec >Owner:%String,Repo:%String,Branch:%String="master"</FormalSpec >
165
177
<ReturnType >%Status</ReturnType >
178
+ <Implementation ><![CDATA[
179
+ Set ..Request.Location = "repos/" _ Owner _ "/" _ Repo _ "/branches/" _ Branch
180
+ Do ..Request.RemoveHeader("Accept")
181
+ Do ..Request.SetHeader("Accept"," application/vnd.github.loki-preview+json") // custom header as this functionality is currently in beta
182
+ Do ..Request.EntityBody.Write("{""protection"": {""enabled"": true}") // to supply true value in pre 16.1 versions
183
+ Set st = ..Request.Send("PATCH","",2)
184
+ Do ..Request.RemoveHeader("Accept")
185
+ Do ..Request.SetHeader("Accept",..#Accept) // back to main header
186
+ Return st
187
+ ]]> </Implementation >
166
188
</Method >
167
189
</Class >
168
190
</Export >
0 commit comments