Skip to content

Commit bcfa5c0

Browse files
committed
File extension is now .aplc rather than .dyalog
1 parent f3000d4 commit bcfa5c0

26 files changed

+257
-46
lines changed

APLSource/GitHubAPIv3.aplc

Lines changed: 126 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
⍝ Apart from the REST interface the class also offers one method that relies on the REST interface but goes beyond
88
⍝ it: `GetRelease`returns the URL of a tarball or a zipball or an EXE from GitHub.\\
99
⍝ For the time being this class runs only under Windows: it relies on .NET. If there is demand for other platforms
10-
⍝ the .NET calls could be exchanged against Rumba.\\
10+
⍝ the .NET calls could be exchanged against Rumba or .NET core.\\
1111
⍝ The project lives on <https://github.com/aplteam/GitHubAPIv3>\\
1212
⍝ It is part of the [APLTree library](https://github.com/aplteam/apltree/wiki)
1313
⍝ Kai Jaeger ⋄ APL Team Ltd
@@ -18,16 +18,16 @@
1818

1919
∇ r←Version
2020
:Access Public Shared
21-
r←'GitHub' '0.4.0.15' '2019-06-11'
22-
23-
24-
∇ ToDo
25-
⍝ * Implement PutTopics
26-
⍝ * Add methods for creating and deleting an issue
21+
r←'GitHub' '0.6.0.18' '2020-03-23'
2722
2823

2924
∇ History
3025
:Access Public Shared
26+
⍝ * 0.6.0
27+
⍝ * File extension is now .aplc rather than .dyalog
28+
⍝ * 0.5.0
29+
⍝ * Issue-related methods added: `GetAllIssues`, `GetIssue`, `CreateIssue`, `UpdateIssue`.
30+
⍝ * Topic-related methods added: `GetAllTopics` and ... (not yet) `ReplaceAllTopics`.
3131
⍝ * 0.4.0
3232
⍝ * New methods added: `GetRelease`, `GetLatestTag` and `CheckForUpdate`.
3333
⍝ * There is now a property `regEx`.
@@ -139,7 +139,7 @@
139139
:EndIf
140140
141141

142-
∇ (rc msg ns)←GetAllTopics repoName;gitPath;parms
142+
∇ (rc msg r)←GetAllTopics repoName;gitPath;parms;ns
143143
:Access Public Instance
144144
⍝ Returns all topics of a given repository.\\
145145
⍝ You must use `https://` as protocol or not specify a protocol at all.
@@ -149,12 +149,13 @@
149149
⍝ : Is empty in case `rc ←→ 0` but might offer addtional information otherwise.
150150
⍝ `ns`
151151
⍝ : Namespace with the data received from GitHub.
152+
r←''
152153
gitPath←'https://api.github.com/repos/',_owner,'/',repoName,'/topics'
153-
parms←CreateParms
154+
parms←CreateHttpParms
154155
parms.Accepted←'application/vnd.github.mercy-preview+json'
155156
(rc msg ns)←parms GetJson gitPath
156157
:If 0=rc
157-
ns.⎕DF'[JSON object: ',repoName,':topics]'
158+
r←ns.names
158159
:EndIf
159160
160161

@@ -168,6 +169,50 @@
168169
:EndIf
169170
170171

172+
∇ (rc msg ns)←GetAllIssues repoName;gitPath
173+
:Access Public Instance
174+
⍝ Returns all issues for a given repository
175+
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/issues'
176+
(rc msg ns)←GetJson gitPath
177+
:If 0≠≢ns
178+
ns.{⎕DF'[Issues of repo ',⍵,']'}⊂repoName
179+
ns.⎕FX⊂⎕CR'∆List'
180+
ns.⎕FX⊂'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
181+
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];]'
182+
:EndIf
183+
184+
185+
∇ (rc msg ns)←GetIssue(repoName number);gitPath
186+
:Access Public Instance
187+
⍝ Returns exactly one issue for a given repository.\\
188+
⍝ Note that `ns` gets three functions injected: ∆List, ∆Details and ∆QuickView. While ∆List does not
189+
⍝ require an argument, ∆Details and ∆QuickView require an instance of this class as right argument.\\
190+
⍝ ∆Details and ∆QuickView both replace the JSON objects "assignees" and "labels" by real data, but
191+
⍝ ∆QuickView returns a small subset for a quick glance.
192+
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/',⍕number
193+
(rc msg ns)←GetJson gitPath
194+
:If 0≠≢ns
195+
ns.{⎕DF ⍵}'[Issue ',(⍕number),' of repo ',repoName,']'
196+
ns.⎕FX ⎕CR'∆List'
197+
ns.⎕FX'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
198+
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];]'
199+
:EndIf
200+
201+
202+
∇ (rc msg ns)←UpdateIssue(repoName parms);gitPath
203+
:Access Public Instance
204+
⍝ Typically the (probably modified) result of call to `GetIssue` is passed as "parms".
205+
∘∘∘ ⍝TODO⍝ requires a POST
206+
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/',⍕number
207+
(rc msg ns)←GetJson gitPath
208+
:If 0≠≢ns
209+
ns.{⎕DF ⍵}'[Issue ',(⍕number),' of repo ',repoName,']'
210+
ns.⎕FX ⎕CR'∆List'
211+
ns.⎕FX'r←∆Details instance' 'r←∆List' 'r(instance.GetPrinciple)←''assignees'' ''login''' 'r(instance.GetPrinciple)←''labels'' ''name'''
212+
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];]'
213+
:EndIf
214+
215+
171216
∇ (rc msg endpoints)←GetAllEndpoints;gitPath;msg;rc
172217
:Access Public Shared
173218
⍝ This method returns all REST endpoints offered by the API.\\
@@ -193,9 +238,10 @@
193238
∇ (rc msg)←PutTopics(repoName topics);gitPath;parms;dummy
194239
⍝ :Access Public Instance ⍝TODO⍝ Not implemented yet
195240
⍝ ...
241+
∘∘∘ ⍝TODO⍝
196242
'"topics" must be a vector of character vectors'⎕SIGNAL 11/⍨2≠≡topics
197243
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/topics'
198-
parms←CreateParms
244+
parms←CreateHttpParms
199245
parms.Accepted←'application/vnd.github.mercy-preview+json'
200246
parms.Method←'PUT'
201247
parms.Body←'{',(1 JSON'names'topics),'}'
@@ -312,7 +358,42 @@
312358
r←version_<gitVersion
313359
314360

315-
⍝ ---------- Private stuff
361+
∇ r←CreateIssueParms
362+
⍝ :Access Public Instance ⍝TODO⍝ NOT IMPLEMENTED YET
363+
r←⎕NS''
364+
r.title←''
365+
r.body←''
366+
r.milestone←0
367+
r.labels←'' ⍝ Nested vector
368+
r.assignees←'' ⍝ Nested vector
369+
r.⎕FX'r←∆List' 'r←{⍉⍵,[.5]⍎¨⍵}'' ''~¨⍨↓⎕NL 2'
370+
371+
372+
∇ r←CreateIssue(repoName parms);gitPath;rc;msg;ns
373+
⍝ :Access Public Instance ⍝TODO⍝ NOT IMPLEMENTED YET
374+
'Invalid: "title"'⎕SIGNAL 11/⍨1≠≡,parms.title
375+
'Invalid: "title"'⎕SIGNAL 11/⍨' '≠1↑0⍴∊parms.title
376+
'Invalid: "milestone"'⎕SIGNAL 11/⍨1≠≢parms.milestone
377+
'Invalid: "milestone"'⎕SIGNAL 11/⍨0≠1↑0⍴∊parms.milestone
378+
'Invalid: "milestone"'⎕SIGNAL 11/⍨1≠≡,parms.milestone
379+
⍝ ... and so on ...
380+
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/issues/'
381+
gitPath,←'?title=',EncodeBlank parms.title
382+
(rc msg ns)←GetJson gitPath
383+
.
384+
385+
386+
387+
∇ r←CreateHttpParms
388+
⍝ Create a parameter space that can be passed to some method that actually write to GitHub like `PutTopics'
389+
:Access Public Instance
390+
r←⎕NS''
391+
r.Accepted←'Accept: application/vnd.github.v3+json'
392+
r.Method←'GET'
393+
r.Body←''
394+
395+
396+
⍝ ------------------------------------------ Private stuff ----------------------------------
316397

317398
∇ html←GetGitHubPage(repoName tag);c;q;buff;⎕USING;cp;req;res
318399
:Trap 90
@@ -369,14 +450,14 @@
369450
∇ (rc msg ns)←{parms}GetJson gitURL;cp;ServicePointManager;req;res;data;WebRequest;i;noOfPages;headers;owner;parms;str;c;q;⎕USING
370451
⍝ Takes `gitURL`which must specify a valid GitHub API URL and returns the data from GitHub.\\
371452
⍝ `⍵`: Project URL, for example 'api.github.com/repos/aplteam/testrepo/releases/latest'
372-
⍝ `⍺`: Optional parameter space, typically create by calling `CreateParms`.
453+
⍝ `⍺`: Optional parameter space, typically create by calling `CreateHttpParms`.
373454
⍝ `rc`
374455
⍝ : Either 0 for okay or an error code.\\
375456
⍝ `msg`
376457
⍝ : Is empty in case `rc←→0` but might offer addtional information otherwise.
377458
⍝ `ns`
378459
⍝ : Namespace with the data received from GitHub.
379-
parms←{0<⎕NC ⍵:⍎⍵ ⋄ CreateParms}'parms'
460+
parms←{0<⎕NC ⍵:⍎⍵ ⋄ CreateHttpParms}'parms'
380461
:If 0=⎕NC'_owner'
381462
owner←'APL GitHub API'
382463
:Else
@@ -422,14 +503,6 @@
422503
:EndTrap
423504
424505

425-
∇ r←CreateParms
426-
⍝ Create a parameter space that can be passed to some method that actually write to GitHub like `PutTopics'
427-
r←⎕NS''
428-
r.Accepted←'Accept: application/vnd.github.v3+json'
429-
r.Method←'GET'
430-
r.Body←''
431-
432-
433506
∇ r←{type}JSON y;version;buff
434507
⍝ Cover for `⎕JSON` in order to support 15.0 which had only an `⌶` for what became later `⎕JSON`.\\
435508
⍝ Note that by default this function imports JSON (`type`=0).\\
@@ -459,4 +532,35 @@
459532
txt←(-offset)⌽new,(≢old)↓offset⌽txt
460533
461534

535+
∇ data←data GetPrinciple(propName principleName);row;jsonObj;buff
536+
⍝ * `propName` is the name of a variable in a data space that is a JSON object
537+
⍝ * `principleName` is the principle name of all the properies of that JSON object\\
538+
⍝ Take a ref
539+
⍝ is concatenated with a comma and a blank, so ('bug' 'question') become:
540+
⍝ 'bug, question'
541+
:Access Public instance
542+
row←data[;1]⍳⊂propName
543+
:If 0≠≢jsonObj←2⊃data[row;]
544+
buff←jsonObj⍎¨⊂principleName
545+
data[row;2]←{⍺,', ',⍵}/buff
546+
:EndIf
547+
548+
549+
⍝ The following function is fixed within the data spaces returned by many if not all commands:
550+
∇ r←∆List;names;values;bool
551+
⍝ List all variables and their values. See also ∆View
552+
names←' '~¨⍨↓⎕NL 2
553+
values←⍎¨names
554+
bool←{16::1 ⋄ 0⊣1↑0⍴⍵}¨values ⍝ Were are objects?
555+
:If ∨/bool
556+
{⍵.⎕DF⊂'(JSON object)'}¨bool/values
557+
:EndIf
558+
r←⍉names,[0.5]values
559+
560+
561+
∇ r←EncodeBlank r
562+
((' '=r)/r)←⊂'%20'
563+
∊r
564+
565+
462566
:EndClass

APLSource/TestCases/Assert.aplf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Assert←{⍺←'' ⋄ (,1)≡,⍵:r←1 ⋄ ⎕ML←3 ⋄ ⍺ ⎕SIGNAL 1↓(↑∊⍵),11}

APLSource/TestCases/Test_002.aplf renamed to APLSource/TestCases/Test_GetRelease_005.aplf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
R←Test_002(stopFlag batchFlag);⎕TRAP;data;more;rc
1+
R←Test_GetRelease_005(stopFlag batchFlag);⎕TRAP;data;more;rc
22
⍝ Get information regarding the latest release with the dedicated method `GetLatestReleaseInfo`
33
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
44
R←T._Failed

APLSource/TestCases/Test_007.aplf renamed to APLSource/TestCases/Test_GetRelease_006.aplf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
R←Test_007(stopFlag batchFlag);⎕TRAP;data;more;rc
1+
R←Test_GetRelease_006(stopFlag batchFlag);⎕TRAP;data;more;rc
22
⍝ Get list of releases with the dedicated method `GetAllReleases`
33
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
44
R←T._Failed

APLSource/TestCases/Test_009.aplf renamed to APLSource/TestCases/Test_GetRelease_007.aplf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
R←Test_009(stopFlag batchFlag);⎕TRAP;data;more;rc
1+
R←Test_GetRelease_007(stopFlag batchFlag);⎕TRAP;data;more;rc
22
⍝ Get a specific release with `GetRelease`.
33
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
44
R←T._Failed
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
R←Test_Issue_010(stopFlag batchFlag);⎕TRAP;data;more;rc
2+
⍝ Get a list with all issues of a given repository of the current owner with `GetAllIssues`.
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
R←T._Failed
5+
6+
(rc more data)←∆MyGitHubAPI.GetAllIssues'TestRepo'
7+
→T.PassesIf 0=rc
8+
→T.PassesIf 0=≢more
9+
→T.PassesIf 1=⍴⍴data.∆List
10+
→T.PassesIf∧/2∧.=¨⍴∘⍴¨data.∆List
11+
→T.PassesIf 1=⍴⍴data.∆Details ∆MyGitHubAPI
12+
→T.PassesIf∧/2∧.=¨⍴∘⍴¨data.∆Details ∆MyGitHubAPI
13+
→T.PassesIf 1=⍴⍴data.∆QuickView ∆MyGitHubAPI
14+
→T.PassesIf∧/2∧.=¨⍴∘⍴¨data.∆QuickView ∆MyGitHubAPI
15+
16+
R←T._OK
17+
⍝Done
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
R←Test_Issue_020(stopFlag batchFlag);⎕TRAP;data;more;rc
2+
⍝ Get a single issue of a given repository for the current owner with `GetIssue`.
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
R←T._Failed
5+
6+
(rc more data)←∆MyGitHubAPI.GetIssue'TestRepo' 2
7+
→T.PassesIf 0=rc
8+
→T.PassesIf 0=≢more
9+
→T.PassesIf 2=⍴⍴data.∆List
10+
→T.PassesIf 2=⍴⍴data.∆Details ∆MyGitHubAPI
11+
→T.PassesIf 6 2≡⍴data.∆QuickView ∆MyGitHubAPI
12+
13+
R←T._OK
14+
⍝Done
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
R←Test_Issue_030(stopFlag batchFlag);⎕TRAP;data;more;rc;parms
2+
⍝ Add an issue; exercises `CreateIssueParms` and `CreateIssue`
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
5+
:If 1
6+
R←T._Inactive ⍝ Not implemented yet
7+
:Return
8+
:EndIf
9+
10+
R←T._Failed
11+
12+
parms←∆MyGitHubAPI.CreateIssueParms
13+
parms.title←⊃⎕SI
14+
parms.assignees←⊂'aplteam'
15+
parms.labels←'duplicate' 'invalid' 'Foo'
16+
(rc more data)←∆MyGitHubAPI.CreateIssue'TestRepo'parms
17+
⎕SE.APLGit.Commit''
18+
→T.PassesIf 0=rc
19+
→T.PassesIf 0=≢more
20+
→T.PassesIf 2=⍴⍴data.∆List
21+
→T.PassesIf 2=⍴⍴data.∆Details ∆MyGitHubAPI
22+
→T.PassesIf 6 2≡⍴data.∆QuickView ∆MyGitHubAPI
23+
24+
R←T._OK
25+
⍝Done
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
R←Test_Issue_040(stopFlag batchFlag);⎕TRAP;data;more;rc;parms
2+
⍝ Update an issue; exercises `UpdateIssue`
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
5+
:If 1
6+
R←T._Inactive ⍝ Not implemented yet
7+
:Return
8+
:EndIf
9+
10+
R←T._Failed
11+
12+
∘∘∘ ⍝TODO⍝
13+
14+
R←T._OK
15+
⍝Done

APLSource/TestCases/Test_004.aplf renamed to APLSource/TestCases/Test_Misc_001.aplf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
R←Test_004(stopFlag batchFlag);⎕TRAP;data;more;rc
1+
R←Test_Misc_001(stopFlag batchFlag);⎕TRAP;data;more;rc
22
⍝ Get a list with all public repositories owned by "aplteam" with `GetAllRepos`.
33
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
44
R←T._Failed

0 commit comments

Comments
 (0)