Skip to content

Commit 4bbd20e

Browse files
committed
Protect default branches in organization workflow
1 parent e58cc26 commit 4bbd20e

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

GitHub/API.cls.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ Protect branch<br>
180180
Do ..Request.RemoveHeader("Accept")
181181
Do ..Request.SetHeader("Accept"," application/vnd.github.loki-preview+json") // custom header as this functionality is currently in beta
182182
Do ..Request.EntityBody.Write("{""protection"": {""enabled"": true}") // to supply true value in pre 16.1 versions
183-
Set st = ..Request.Send("PATCH","",2)
183+
Set st = ..Request.Send("PATCH","")
184184
Do ..Request.RemoveHeader("Accept")
185185
Do ..Request.SetHeader("Accept",..#Accept) // back to main header
186186
Return st

GitHub/Workflows.cls.xml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<Export generator="Cache" version="25">
3+
<Class name="GitHub.Workflows">
4+
<TimeCreated>63914,64417.969689</TimeCreated>
5+
6+
<Method name="ProtectDefaultBranches">
7+
<Description><![CDATA[
8+
Protect default branches in organization.<br>
9+
<var>Org</var> - name of Organization<br>
10+
<var>Username</var> - GitHub user, whois organisation owner<br>
11+
<var>Password</var> - GitHub password, corresponding to Username.<br>]]></Description>
12+
<ClassMethod>1</ClassMethod>
13+
<FormalSpec>Org:%String,Username:%String,Password:%String</FormalSpec>
14+
<Implementation><![CDATA[
15+
Set api = ##class(GitHub.API).%New(Username,Password)
16+
#dim repos As List of %ZEN.proxyObject
17+
Set st = api.GetOrgRepos(Org, "public", .repos)
18+
Write $System.Status.GetErrorText(st)
19+
For i=1:1:repos.Count() {
20+
Set repo = repos.GetAt(i).name
21+
Set branch = repos.GetAt(i)."default_branch"
22+
Set st = api.ProtectBranch(Org, repo, branch)
23+
Write repo, " ", $System.Status.GetErrorText(st), !
24+
}
25+
]]></Implementation>
26+
</Method>
27+
</Class>
28+
</Export>

0 commit comments

Comments
 (0)