Skip to content

Commit e58cc26

Browse files
committed
1 parent 83232cc commit e58cc26

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

GitHub/API.cls.xml

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,12 @@ GitHub API server address</Description>
1717
<Default>api.github.com</Default>
1818
</Parameter>
1919

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+
2026
<Property name="Request">
2127
<Type>%Net.HttpRequest</Type>
2228
<Internal>1</Internal>
@@ -52,7 +58,7 @@ Unauthenticated requests are associated with an IP address.<br>]]></Description>
5258
Set ..Request.Https = 1
5359
Set ..Request.SSLConfiguration = SSLConfig
5460
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
5662
5763
If ($d(Username) && $d(Password) && (Username'="") && (Password'="")) { // supply Username and Passwor, if both are provided. GitHub accept Basic Auth
5864
Set ..Request.Username = Username // https://developer.github.com/v3/auth/
@@ -161,8 +167,24 @@ Add repository to team.<br>
161167
</Method>
162168

163169
<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>
165177
<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>
166188
</Method>
167189
</Class>
168190
</Export>

0 commit comments

Comments
 (0)