Skip to content

Commit

Permalink
File extension is now .aplc rather than .dyalog
Browse files Browse the repository at this point in the history
  • Loading branch information
aplteam committed Mar 23, 2020
1 parent f3000d4 commit bcfa5c0
Show file tree
Hide file tree
Showing 26 changed files with 257 additions and 46 deletions.
148 changes: 126 additions & 22 deletions APLSource/GitHubAPIv3.aplc
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
Apart from the REST interface the class also offers one method that relies on the REST interface but goes beyond
it: `GetRelease`returns the URL of a tarball or a zipball or an EXE from GitHub.\\
For the time being this class runs only under Windows: it relies on .NET. If there is demand for other platforms
the .NET calls could be exchanged against Rumba.\\
the .NET calls could be exchanged against Rumba or .NET core.\\
The project lives on <https://github.com/aplteam/GitHubAPIv3>\\
It is part of the [APLTree library](https://github.com/aplteam/apltree/wiki)
Kai Jaeger ⋄ APL Team Ltd
Expand All @@ -18,16 +18,16 @@

rVersion
:Access Public Shared
r'GitHub' '0.4.0.15' '2019-06-11'

ToDo
* Implement PutTopics
* Add methods for creating and deleting an issue
r'GitHub' '0.6.0.18' '2020-03-23'

History
:Access Public Shared
* 0.6.0
* File extension is now .aplc rather than .dyalog
* 0.5.0
* Issue-related methods added: `GetAllIssues`, `GetIssue`, `CreateIssue`, `UpdateIssue`.
* Topic-related methods added: `GetAllTopics` and ... (not yet) `ReplaceAllTopics`.
* 0.4.0
* New methods added: `GetRelease`, `GetLatestTag` and `CheckForUpdate`.
* There is now a property `regEx`.
Expand Down Expand Up @@ -139,7 +139,7 @@
:EndIf

(rc msg ns)GetAllTopics repoName;gitPath;parms
(rc msg r)GetAllTopics repoName;gitPath;parms;ns
:Access Public Instance
Returns all topics of a given repository.\\
You must use `https://` as protocol or not specify a protocol at all.
Expand All @@ -149,12 +149,13 @@
: Is empty in case `rc ←→ 0` but might offer addtional information otherwise.
`ns`
: Namespace with the data received from GitHub.
r''
gitPath'https://api.github.com/repos/',_owner,'/',repoName,'/topics'
parmsCreateParms
parmsCreateHttpParms
parms.Accepted'application/vnd.github.mercy-preview+json'
(rc msg ns)parms GetJson gitPath
:If 0=rc
ns.⎕DF'[JSON object: ',repoName,':topics]'
rns.names
:EndIf

Expand All @@ -168,6 +169,50 @@
:EndIf

(rc msg ns)GetAllIssues repoName;gitPath
:Access Public Instance
Returns all issues for a given repository
gitPath'https://api.github.com/repos/',(_owner),'/',repoName,'/issues'
(rc msg ns)GetJson gitPath
:If 0ns
ns.{⎕DF'[Issues of repo ',,']'}repoName
ns.⎕FX⎕CR'∆List'
ns.⎕FX'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
ns.⎕FX'r←∆QuickView instance;keyWords' 'r←∆Details instance' 'keyWords←''title'' ''number'' ''state'' ''updated_at'' ''labels'' ''assignees''' 'r←(r[;1]∊keyWords)⌿r' 'r←r[⍋keyWords⍳r[;1];]'
:EndIf

(rc msg ns)GetIssue(repoName number);gitPath
:Access Public Instance
Returns exactly one issue for a given repository.\\
Note that `ns` gets three functions injected: ∆List, ∆Details and ∆QuickView. While ∆List does not
require an argument, ∆Details and ∆QuickView require an instance of this class as right argument.\\
∆Details and ∆QuickView both replace the JSON objects "assignees" and "labels" by real data, but
∆QuickView returns a small subset for a quick glance.
gitPath'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/',number
(rc msg ns)GetJson gitPath
:If 0ns
ns.{⎕DF }'[Issue ',(number),' of repo ',repoName,']'
ns.⎕FX ⎕CR'∆List'
ns.⎕FX'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
ns.⎕FX'r←∆QuickView instance;keyWords' 'r←∆Details instance' 'keyWords←''title'' ''number'' ''state'' ''updated_at'' ''labels'' ''assignees''' 'r←(r[;1]∊keyWords)⌿r' 'r←r[⍋keyWords⍳r[;1];]'
:EndIf

(rc msg ns)UpdateIssue(repoName parms);gitPath
:Access Public Instance
Typically the (probably modified) result of call to `GetIssue` is passed as "parms".
∘∘∘ TODO⍝ requires a POST
gitPath'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/',number
(rc msg ns)GetJson gitPath
:If 0ns
ns.{⎕DF }'[Issue ',(number),' of repo ',repoName,']'
ns.⎕FX ⎕CR'∆List'
ns.⎕FX'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
ns.⎕FX'r←∆QuickView instance;keyWords' 'r←∆Details instance' 'keyWords←''title'' ''number'' ''state'' ''updated_at'' ''labels'' ''assignees''' 'r←(r[;1]∊keyWords)⌿r' 'r←r[⍋keyWords⍳r[;1];]'
:EndIf

(rc msg endpoints)GetAllEndpoints;gitPath;msg;rc
:Access Public Shared
This method returns all REST endpoints offered by the API.\\
Expand All @@ -193,9 +238,10 @@
(rc msg)PutTopics(repoName topics);gitPath;parms;dummy
:Access Public Instance ⍝TODO⍝ Not implemented yet
...
∘∘∘ TODO⍝
'"topics" must be a vector of character vectors'⎕SIGNAL 11/2topics
gitPath'https://api.github.com/repos/',(_owner),'/',repoName,'/topics'
parmsCreateParms
parmsCreateHttpParms
parms.Accepted'application/vnd.github.mercy-preview+json'
parms.Method'PUT'
parms.Body'{',(1 JSON'names'topics),'}'
Expand Down Expand Up @@ -312,7 +358,42 @@
rversion_<gitVersion

---------- Private stuff
rCreateIssueParms
:Access Public Instance ⍝TODO⍝ NOT IMPLEMENTED YET
r⎕NS''
r.title''
r.body''
r.milestone0
r.labels'' Nested vector
r.assignees'' Nested vector
r.⎕FX'r←∆List' 'r←{⍉⍵,[.5]⍎¨⍵}'' ''~¨⍨↓⎕NL 2'

rCreateIssue(repoName parms);gitPath;rc;msg;ns
:Access Public Instance ⍝TODO⍝ NOT IMPLEMENTED YET
'Invalid: "title"'⎕SIGNAL 11/1,parms.title
'Invalid: "title"'⎕SIGNAL 11/' '10parms.title
'Invalid: "milestone"'⎕SIGNAL 11/1parms.milestone
'Invalid: "milestone"'⎕SIGNAL 11/010parms.milestone
'Invalid: "milestone"'⎕SIGNAL 11/1,parms.milestone
... and so on ...
gitPath'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/'
gitPath,'?title=',EncodeBlank parms.title
(rc msg ns)GetJson gitPath
.


rCreateHttpParms
Create a parameter space that can be passed to some method that actually write to GitHub like `PutTopics'
:Access Public Instance
r⎕NS''
r.Accepted'Accept: application/vnd.github.v3+json'
r.Method'GET'
r.Body''

------------------------------------------ Private stuff ----------------------------------

htmlGetGitHubPage(repoName tag);c;q;buff;⎕USING;cp;req;res
:Trap 90
Expand Down Expand Up @@ -369,14 +450,14 @@
(rc msg ns){parms}GetJson gitURL;cp;ServicePointManager;req;res;data;WebRequest;i;noOfPages;headers;owner;parms;str;c;q;⎕USING
Takes `gitURL`which must specify a valid GitHub API URL and returns the data from GitHub.\\
`⍵`: Project URL, for example 'api.github.com/repos/aplteam/testrepo/releases/latest'
`⍺`: Optional parameter space, typically create by calling `CreateParms`.
`⍺`: Optional parameter space, typically create by calling `CreateHttpParms`.
`rc`
: Either 0 for okay or an error code.\\
`msg`
: Is empty in case `rc←→0` but might offer addtional information otherwise.
`ns`
: Namespace with the data received from GitHub.
parms{0<⎕NC : CreateParms}'parms'
parms{0<⎕NC : CreateHttpParms}'parms'
:If 0=⎕NC'_owner'
owner'APL GitHub API'
:Else
Expand Down Expand Up @@ -422,14 +503,6 @@
:EndTrap

rCreateParms
Create a parameter space that can be passed to some method that actually write to GitHub like `PutTopics'
r⎕NS''
r.Accepted'Accept: application/vnd.github.v3+json'
r.Method'GET'
r.Body''

r{type}JSON y;version;buff
Cover for `⎕JSON` in order to support 15.0 which had only an `⌶` for what became later `⎕JSON`.\\
Note that by default this function imports JSON (`type`=0).\\
Expand Down Expand Up @@ -459,4 +532,35 @@
txt(-offset)new,(old)offsettxt

datadata GetPrinciple(propName principleName);row;jsonObj;buff
* `propName` is the name of a variable in a data space that is a JSON object
* `principleName` is the principle name of all the properies of that JSON object\\
Take a ref
is concatenated with a comma and a blank, so ('bug' 'question') become:
'bug, question'
:Access Public instance
rowdata[;1]propName
:If 0jsonObj2data[row;]
buffjsonObj¨principleName
data[row;2]{,', ',}/buff
:EndIf

The following function is fixed within the data spaces returned by many if not all commands:
r∆List;names;values;bool
List all variables and their values. See also ∆View
names' '~¨⎕NL 2
values¨names
bool{16::1 010}¨values Were are objects?
:If /bool
{.⎕DF'(JSON object)'}¨bool/values
:EndIf
rnames,[0.5]values

rEncodeBlank r
((' '=r)/r)'%20'
r

:EndClass
1 change: 1 addition & 0 deletions APLSource/TestCases/Assert.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Assert{'' (,1),:r1 ⎕ML3 ⎕SIGNAL 1(),11}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_002(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_GetRelease_005(stopFlag batchFlag);⎕TRAP;data;more;rc
Get information regarding the latest release with the dedicated method `GetLatestReleaseInfo`
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_007(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_GetRelease_006(stopFlag batchFlag);⎕TRAP;data;more;rc
Get list of releases with the dedicated method `GetAllReleases`
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_009(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_GetRelease_007(stopFlag batchFlag);⎕TRAP;data;more;rc
Get a specific release with `GetRelease`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
17 changes: 17 additions & 0 deletions APLSource/TestCases/Test_Issue_010.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
RTest_Issue_010(stopFlag batchFlag);⎕TRAP;data;more;rc
Get a list with all issues of a given repository of the current owner with `GetAllIssues`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed

(rc more data)∆MyGitHubAPI.GetAllIssues'TestRepo'
T.PassesIf 0=rc
T.PassesIf 0=more
T.PassesIf 1=⍴⍴data.∆List
T.PassesIf/2.=¨¨data.∆List
T.PassesIf 1=⍴⍴data.∆Details ∆MyGitHubAPI
T.PassesIf/2.=¨¨data.∆Details ∆MyGitHubAPI
T.PassesIf 1=⍴⍴data.∆QuickView ∆MyGitHubAPI
T.PassesIf/2.=¨¨data.∆QuickView ∆MyGitHubAPI

RT._OK
Done
14 changes: 14 additions & 0 deletions APLSource/TestCases/Test_Issue_020.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
RTest_Issue_020(stopFlag batchFlag);⎕TRAP;data;more;rc
Get a single issue of a given repository for the current owner with `GetIssue`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed

(rc more data)∆MyGitHubAPI.GetIssue'TestRepo' 2
T.PassesIf 0=rc
T.PassesIf 0=more
T.PassesIf 2=⍴⍴data.∆List
T.PassesIf 2=⍴⍴data.∆Details ∆MyGitHubAPI
T.PassesIf 6 2data.∆QuickView ∆MyGitHubAPI

RT._OK
Done
25 changes: 25 additions & 0 deletions APLSource/TestCases/Test_Issue_030.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
RTest_Issue_030(stopFlag batchFlag);⎕TRAP;data;more;rc;parms
Add an issue; exercises `CreateIssueParms` and `CreateIssue`
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')

:If 1
RT._Inactive Not implemented yet
:Return
:EndIf

RT._Failed

parms∆MyGitHubAPI.CreateIssueParms
parms.title⎕SI
parms.assignees'aplteam'
parms.labels'duplicate' 'invalid' 'Foo'
(rc more data)∆MyGitHubAPI.CreateIssue'TestRepo'parms
⎕SE.APLGit.Commit''
T.PassesIf 0=rc
T.PassesIf 0=more
T.PassesIf 2=⍴⍴data.∆List
T.PassesIf 2=⍴⍴data.∆Details ∆MyGitHubAPI
T.PassesIf 6 2data.∆QuickView ∆MyGitHubAPI

RT._OK
Done
15 changes: 15 additions & 0 deletions APLSource/TestCases/Test_Issue_040.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
RTest_Issue_040(stopFlag batchFlag);⎕TRAP;data;more;rc;parms
Update an issue; exercises `UpdateIssue`
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')

:If 1
RT._Inactive Not implemented yet
:Return
:EndIf

RT._Failed

∘∘∘ TODO⍝

RT._OK
Done
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_004(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_Misc_001(stopFlag batchFlag);⎕TRAP;data;more;rc
Get a list with all public repositories owned by "aplteam" with `GetAllRepos`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_006(stopFlag batchFlag);⎕TRAP;more;rc;version;tag
RTest_Misc_010(stopFlag batchFlag);⎕TRAP;more;rc;version;tag
Convert text (for example a tagname) to a number with `CastTagname2Number`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_008(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_Misc_020(stopFlag batchFlag);⎕TRAP;data;more;rc
Get a list with all endpoints offered by the API with `GetAllEndpoints`.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
RTest_018(stopFlag batchFlag);⎕TRAP;data;more;rc
RTest_Misc_030(stopFlag batchFlag);⎕TRAP;data;more;rc
Exercise the `GetAllTopics` method.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed

(rc more data)∆MyGitHubAPI.GetAllTopics'TestRepo'
T.PassesIf 0=rc
T.PassesIf 0=more
T.PassesIf 0<data.names
T.PassesIf 0<data

:If 0
(rc more)∆MyGitHubAPI.PutTopics'TestRepo'('test1' 'test2')
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_019(stopFlag batchFlag);⎕TRAP;tag
RTest_Misc_040(stopFlag batchFlag);⎕TRAP;tag
Exercise the `GetLatestTag` method.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
RTest_021(stopFlag batchFlag);⎕TRAP
RTest_Misc_050(stopFlag batchFlag);⎕TRAP
Exercise the `CheckForUpdate` method.
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed
Expand Down
13 changes: 13 additions & 0 deletions APLSource/TestCases/Test_Topic_010.aplf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
RTest_Topic_010(stopFlag batchFlag);⎕TRAP;data;more;rc
Request a list of all topcis assigned to the "TestRep" repository
⎕TRAP(999 'C' '. ⍝ Deliberate error')(0 'N')
RT._Failed

(rc more data)∆MyGitHubAPI.GetAllTopics'TestRepo'
T.PassesIf 0=rc
T.PassesIf 0=more
T.PassesIf 2=data
T.PassesIf 0<data

RT._OK
Done
Loading

0 comments on commit bcfa5c0

Please sign in to comment.