<commit_before><?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="GitHub.API">
<Super>%RegisteredObject</Super>
<TimeCreated>63914,59463.518731</TimeCreated>

<Parameter name="SSLConfig">
<Description>
Name of a valid Cache SSL config. 
Created on object initialization automatically. </Description>
<Default>GitHub</Default>
</Parameter>

<Parameter name="Server">
<Description>
GitHub API server address</Description>
<Default>api.github.com</Default>
</Parameter>

<Property name="Request">
<Type>%Net.HttpRequest</Type>
<Internal>1</Internal>
</Property>

<Method name="%OnNew">
<FormalSpec>Username:%String="",Password:%String=""</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<ServerOnly>1</ServerOnly>
<Implementation><![CDATA[	Quit ..CreateRequest(Username,Password)
]]></Implementation>
</Method>

<Method name="CreateRequest">
<Description><![CDATA[
This methd is called automatically on object creation.<br>
<var>Username</var> - GitHub user, who has access to repository. Optional for public repositories.<br>
<var>Password</var> - GitHub password, corresponding to Username. Optional for public repositories.<br>
Note, that with Username, you can make up to 5,000 requests per hour. 
For unauthenticated requests, the rate limit allows to make up to 60 requests per hour. 
Unauthenticated requests are associated with an IP address.<br>]]></Description>
<FormalSpec>Username:%String,Password:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	New $Namespace
 	Set SSLConfig = ..#SSLConfig
 	
 	Zn "%SYS"
 	Do:'##class(Security.SSLConfigs).Exists(SSLConfig) ##class(Security.SSLConfigs).Create(SSLConfig)

 	Set ..Request = ##class(%Net.HttpRequest).%New()
 	Set ..Request.Https = 1
	Set ..Request.SSLConfiguration = SSLConfig
	Set ..Request.Server=	..#Server					
	Do ..Request.SetHeader("Accept","application/vnd.github.v3+json") 		// we want 3rd version of api	
	
	If ($d(Username) && $d(Password) && (Username'="") && (Password'="")) {	// supply Username and Passwor, if both are provided. GitHub accept Basic Auth
		Set ..Request.Username = Username									// https://developer.github.com/v3/auth/
	 	Set ..Request.Password = Password
	} 	

	Return $$$OK
]]></Implementation>
</Method>

<Method name="GetOrgReposNames">
<Description><![CDATA[
Get list of names of all repositories in a organization.<br>
<var>Org</var> - name of Organization<br>
<var>Type</var> - select one type of repos to return (all - for eveything)<br>
<var>Repos</var> - list of repositories' names<br>
<var>Page</var> - internal, do not set]]></Description>
<FormalSpec><![CDATA[Org:%String,Type:%String(VALUELIST=",all,public,private,forks,sources,member")="all",&Repos:%ListOfDataTypes,Page:%Integer=1]]></FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set:(('$Data(Repos)) || ('$IsObject(Repos))) Repos = ##class(%ListOfDataTypes).%New()
	#dim obj As List of %ZEN.proxyObject

	Set ..Request.Location = "orgs/" _ Org _ "/repos" 
	Do ..Request.SetParam("page",Page) 
	Do ..Request.SetParam("type",Type) 
	Set st = ..Request.Get()

	Set st1 = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(..Request.HttpResponse.Data,,.obj,1)
	Set st = $$$ADDSC(st, st1)
	
	For i=1:1:obj.Count() {
		Set repo = obj.GetAt(i)
		Do Repos.Insert(repo.name)
		/// Write repo.name,"  ",repo.url,!
		/// see structure of repo object at:
		/// https://developer.github.com/v3/repos/#list-organization-repositories
	}
	
	If obj.Count()'=0 {
		/// next page exists
		Set Page = Page + 1
		Set st1 = ..GetOrgReposNames(Org, Type, .Repos, Page)
		Set st = $$$ADDSC(st, st1)
	}
	Return st
]]></Implementation>
</Method>

<Method name="GetOrgRepos">
<Description><![CDATA[
Get list of all repositories in a organization. Use GetOrgReposNames method if you only need names<br>
<var>Org</var> - name of Organization<br>
<var>Type</var> - select one type of repos to return (all - for eveything)<br>
<var>Repos</var> - list of repositories' names<br>
<var>Page</var> - internal, do not set]]></Description>
<FormalSpec><![CDATA[Org:%String,Type:%String(VALUELIST=",all,public,private,forks,sources,member")="all",&Repos:%ListOfObjects,Page:%Integer=1]]></FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set:(('$Data(Repos)) || ('$IsObject(Repos))) Repos = ##class(%ListOfObjects).%New()
	#dim obj As List of %ZEN.proxyObject

	Set ..Request.Location = "orgs/" _ Org _ "/repos" 
	Do ..Request.SetParam("page",Page) 
	Do ..Request.SetParam("type",Type) 
	Set st = ..Request.Get()

	Set st1 = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(..Request.HttpResponse.Data,,.obj,1)
	Set st = $$$ADDSC(st, st1)
	
	For i=1:1:obj.Count() {
		Set repo = obj.GetAt(i)
		Do Repos.Insert(repo)
		/// Write repo.name,"  ",repo.url,!
		/// see structure of repo object at:
		/// https://developer.github.com/v3/repos/#list-organization-repositories
	}
	
	If obj.Count()'=0 {
		/// next page exists
		Set Page = Page + 1
		Set st1 = ..GetOrgRepos(Org, Type, .Repos, Page)
		Set st = $$$ADDSC(st, st1)
	}
	Return st
]]></Implementation>
</Method>

<Method name="AddRepoToTeam">
<Description><![CDATA[
Add repository to team.<br>
<var>Org</var> - name of Organization<br>
<var>TeamId</var> - Id (not Name) of a team<br>
<var>Repo</var> - repository name (eg. Cache-MDX2JSON)<br>
<var>Permission</var> - access level. Currently <b>defaults to team default level</b><br>]]></Description>
<FormalSpec>Org:%String,TeamId:%Integer,Repo:%String,Permission:%String(VALUELIST=",pull,push,admin")="pull"</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set ..Request.Location = "teams/" _ TeamId _ "/repos/" _ Org _ "/" _ Repo 
	Do ..Request.SetHeader("Accept","application/vnd.github.ironman-preview+json") 
	//Do ..Request.SetHeader("Content-Length",0) 
	Do ..Request.SetParam("permission",Permission) 		
	Set st = ..Request.Put()
	Return st
]]></Implementation>
</Method>

<Method name="ProtectBranch">
<FormalSpec>Owner:%String,Repo:%String,Branch:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
</Method>
</Class>
</Export><commit_msg>Protect branch method https://help.github.com/articles/about-protected-branches/<commit_after><?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25">
<Class name="GitHub.API">
<Super>%RegisteredObject</Super>
<TimeCreated>63914,59463.518731</TimeCreated>

<Parameter name="SSLConfig">
<Description>
Name of a valid Cache SSL config. 
Created on object initialization automatically. </Description>
<Default>GitHub</Default>
</Parameter>

<Parameter name="Server">
<Description>
GitHub API server address</Description>
<Default>api.github.com</Default>
</Parameter>

<Parameter name="Accept">
<Description>
Default accept header for our requests</Description>
<Default>application/vnd.github.v3+json</Default>
</Parameter>

<Property name="Request">
<Type>%Net.HttpRequest</Type>
<Internal>1</Internal>
</Property>

<Method name="%OnNew">
<FormalSpec>Username:%String="",Password:%String=""</FormalSpec>
<Private>1</Private>
<ReturnType>%Status</ReturnType>
<ServerOnly>1</ServerOnly>
<Implementation><![CDATA[	Quit ..CreateRequest(Username,Password)
]]></Implementation>
</Method>

<Method name="CreateRequest">
<Description><![CDATA[
This methd is called automatically on object creation.<br>
<var>Username</var> - GitHub user, who has access to repository. Optional for public repositories.<br>
<var>Password</var> - GitHub password, corresponding to Username. Optional for public repositories.<br>
Note, that with Username, you can make up to 5,000 requests per hour. 
For unauthenticated requests, the rate limit allows to make up to 60 requests per hour. 
Unauthenticated requests are associated with an IP address.<br>]]></Description>
<FormalSpec>Username:%String,Password:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	New $Namespace
 	Set SSLConfig = ..#SSLConfig
 	
 	Zn "%SYS"
 	Do:'##class(Security.SSLConfigs).Exists(SSLConfig) ##class(Security.SSLConfigs).Create(SSLConfig)

 	Set ..Request = ##class(%Net.HttpRequest).%New()
 	Set ..Request.Https = 1
	Set ..Request.SSLConfiguration = SSLConfig
	Set ..Request.Server=	..#Server					
	Do ..Request.SetHeader("Accept",..#Accept) 		// we want 3rd version of api	
	
	If ($d(Username) && $d(Password) && (Username'="") && (Password'="")) {	// supply Username and Passwor, if both are provided. GitHub accept Basic Auth
		Set ..Request.Username = Username									// https://developer.github.com/v3/auth/
	 	Set ..Request.Password = Password
	} 	

	Return $$$OK
]]></Implementation>
</Method>

<Method name="GetOrgReposNames">
<Description><![CDATA[
Get list of names of all repositories in a organization.<br>
<var>Org</var> - name of Organization<br>
<var>Type</var> - select one type of repos to return (all - for eveything)<br>
<var>Repos</var> - list of repositories' names<br>
<var>Page</var> - internal, do not set]]></Description>
<FormalSpec><![CDATA[Org:%String,Type:%String(VALUELIST=",all,public,private,forks,sources,member")="all",&Repos:%ListOfDataTypes,Page:%Integer=1]]></FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set:(('$Data(Repos)) || ('$IsObject(Repos))) Repos = ##class(%ListOfDataTypes).%New()
	#dim obj As List of %ZEN.proxyObject

	Set ..Request.Location = "orgs/" _ Org _ "/repos" 
	Do ..Request.SetParam("page",Page) 
	Do ..Request.SetParam("type",Type) 
	Set st = ..Request.Get()

	Set st1 = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(..Request.HttpResponse.Data,,.obj,1)
	Set st = $$$ADDSC(st, st1)
	
	For i=1:1:obj.Count() {
		Set repo = obj.GetAt(i)
		Do Repos.Insert(repo.name)
		/// Write repo.name,"  ",repo.url,!
		/// see structure of repo object at:
		/// https://developer.github.com/v3/repos/#list-organization-repositories
	}
	
	If obj.Count()'=0 {
		/// next page exists
		Set Page = Page + 1
		Set st1 = ..GetOrgReposNames(Org, Type, .Repos, Page)
		Set st = $$$ADDSC(st, st1)
	}
	Return st
]]></Implementation>
</Method>

<Method name="GetOrgRepos">
<Description><![CDATA[
Get list of all repositories in a organization. Use GetOrgReposNames method if you only need names<br>
<var>Org</var> - name of Organization<br>
<var>Type</var> - select one type of repos to return (all - for eveything)<br>
<var>Repos</var> - list of repositories' names<br>
<var>Page</var> - internal, do not set]]></Description>
<FormalSpec><![CDATA[Org:%String,Type:%String(VALUELIST=",all,public,private,forks,sources,member")="all",&Repos:%ListOfObjects,Page:%Integer=1]]></FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set:(('$Data(Repos)) || ('$IsObject(Repos))) Repos = ##class(%ListOfObjects).%New()
	#dim obj As List of %ZEN.proxyObject

	Set ..Request.Location = "orgs/" _ Org _ "/repos" 
	Do ..Request.SetParam("page",Page) 
	Do ..Request.SetParam("type",Type) 
	Set st = ..Request.Get()

	Set st1 = ##class(%ZEN.Auxiliary.jsonProvider).%ConvertJSONToObject(..Request.HttpResponse.Data,,.obj,1)
	Set st = $$$ADDSC(st, st1)
	
	For i=1:1:obj.Count() {
		Set repo = obj.GetAt(i)
		Do Repos.Insert(repo)
		/// Write repo.name,"  ",repo.url,!
		/// see structure of repo object at:
		/// https://developer.github.com/v3/repos/#list-organization-repositories
	}
	
	If obj.Count()'=0 {
		/// next page exists
		Set Page = Page + 1
		Set st1 = ..GetOrgRepos(Org, Type, .Repos, Page)
		Set st = $$$ADDSC(st, st1)
	}
	Return st
]]></Implementation>
</Method>

<Method name="AddRepoToTeam">
<Description><![CDATA[
Add repository to team.<br>
<var>Org</var> - name of Organization<br>
<var>TeamId</var> - Id (not Name) of a team<br>
<var>Repo</var> - repository name (eg. Cache-MDX2JSON)<br>
<var>Permission</var> - access level. Currently <b>defaults to team default level</b><br>]]></Description>
<FormalSpec>Org:%String,TeamId:%Integer,Repo:%String,Permission:%String(VALUELIST=",pull,push,admin")="pull"</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set ..Request.Location = "teams/" _ TeamId _ "/repos/" _ Org _ "/" _ Repo 
	Do ..Request.SetHeader("Accept","application/vnd.github.ironman-preview+json") 
	//Do ..Request.SetHeader("Content-Length",0) 
	Do ..Request.SetParam("permission",Permission) 		
	Set st = ..Request.Put()
	Return st
]]></Implementation>
</Method>

<Method name="ProtectBranch">
<Description><![CDATA[
Protect branch<br>
<var>Owner</var> - owner of repository<br>
<var>Repo</var> - repository name (eg. Cache-MDX2JSON)<br>
<var>Branch</var> - branch to protect<br>
<a href="https://help.github.com/articles/about-protected-branches/">About</a> protected branches]]></Description>
<FormalSpec>Owner:%String,Repo:%String,Branch:%String="master"</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set ..Request.Location = "repos/" _ Owner _ "/" _ Repo _ "/branches/" _ Branch 
	Do ..Request.RemoveHeader("Accept")
	Do ..Request.SetHeader("Accept"," application/vnd.github.loki-preview+json") // custom header as this functionality is currently in beta
	Do ..Request.EntityBody.Write("{""protection"": {""enabled"": true}") // to supply true value in pre 16.1 versions
	Set st = ..Request.Send("PATCH","",2)
	Do ..Request.RemoveHeader("Accept")
	Do ..Request.SetHeader("Accept",..#Accept) // back to main header
	Return st
]]></Implementation>
</Method>
</Class>
</Export>
{'fraction_non_alphanumeric': 0.18135719612229678, 'fraction_numerical': 0.009023117076808352, 'mean_word_length': 5.255130597014926, 'pattern_counts': {'":': 2, '<': 313, '<?xml version=': 2, '>': 313, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3467637', 'n_tokens_mistral': 4749, 'n_tokens_neox': 4451, 'n_words': 1021}