Skip to content

Commit 1ec6ee0

Browse files
committed
0.3.0
1 parent 3afc402 commit 1ec6ee0

File tree

9 files changed

+135
-31
lines changed

9 files changed

+135
-31
lines changed

APLSource/GitHubAPIv3.aplc

Lines changed: 60 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,31 @@
11
:Class GitHubAPIv3
2-
⍝ This clas offers methods that allows one to communicate with GitHub by using GitHub's REST API from Dyalog APL.
2+
⍝ This class offers methods that allows one to communicate with GitHub by using GitHub's REST API from Dyalog APL.
33
⍝ Note that this is version 3 of the GitHub API; the coming version 4 is **_not_** a REST interface!\\
44
⍝ Most methods of this class become available only by instanciating the class. At the moment this might seem
55
⍝ unnecessary because there is only one constructor requiring an owner's name, but this will change once OAuth
66
⍝ is going to be implemented.\\
77
⍝ The class came into being because APL Team needed such a class in order to deal with the members of the APLTree
88
⍝ and the APL-cation projects.\\
9-
⍝ Note that this class needs **at least Dyalog 16.0** (⎕JSON).\\
109
⍝ The project lives on <https://github.com/aplteam/GitHubAPIv3>\\
1110
⍝ It is part of the [APLTree library](https://github.com/aplteam/apltree/wiki)
1211
⍝ Kai Jaeger ⋄ APL Team Ltd
1312

14-
:Include ##.APLTreeUtils
13+
:Include APLTreeUtils
1514

1615
⎕IO←1 ⋄ ⎕ML←1
1716

1817
∇ r←Version
1918
:Access Public Shared
20-
r←'GitHub' '0.0.2.8' '2018-12-31'
19+
r←'GitHub' '0.3.0.8' '2019-02-17'
2120
2221

2322
∇ History
2423
:Access Public Shared
24+
⍝ * 0.3.0
25+
⍝ * Oktokit support added.
26+
⍝ * Versioning corrected.
27+
⍝ * Documentation polished.
28+
⍝ * :Include ##.APLTreeUtils fixed
2529
⍝ * 0.0.2
2630
⍝ * Method `GetAllTopics` added.
2731
⍝ * 0.0.1
@@ -51,7 +55,7 @@
5155
gitPath←'https://api.github.com/repos/',_owner,'/',repoName,'/releases/latest'
5256
(rc msg ns)←GetJson gitPath
5357
:If 0=rc
54-
ns.⎕DF'[JSON object: Release (',repoName,'-',ns.tag_name,')]'
58+
ns.⎕DF'[JSON object: ',repoName,'-',ns.tag_name,']'
5559
:EndIf
5660
5761

@@ -66,7 +70,7 @@
6670
gitPath←'https://api.github.com/repos/',_owner,'/',repoName,'/releases/tags/',tagName
6771
(rc msg ns)←GetJson gitPath
6872
:If 0=rc
69-
ns.⎕DF'[JSON object: Release (',repoName,'-',tagName,')]'
73+
ns.⎕DF'[JSON object: ',repoName,'-',tagName,']'
7074
:EndIf
7175
7276

@@ -82,7 +86,7 @@
8286
gitPath←'https://api.github.com/repos/',_owner,'/',repoName,'/tags'
8387
(rc msg ns)←GetJson gitPath
8488
:If 0≠≢ns
85-
ns.{⎕DF'[JSON Object: Release (',name,')]'}⊂
89+
ns.{⎕DF'[JSON Object: ',⍵,' ',name,']'}⊂repoName
8690
:EndIf
8791
8892

@@ -97,7 +101,7 @@
97101
parms.Accepted←'application/vnd.github.mercy-preview+json'
98102
(rc msg ns)←parms GetJson gitPath
99103
:If 0=rc
100-
ns.⎕DF'[JSON object: Release (',repoName,': topics)]'
104+
ns.⎕DF'[JSON object: ',repoName,':topics]'
101105
:EndIf
102106
103107

@@ -107,7 +111,7 @@
107111
gitPath←'https://api.github.com/users/',(_owner),'/repos'
108112
(rc msg ns)←GetJson gitPath
109113
:If 0≠≢ns
110-
ns.{⎕DF'[JSON Object: Repository (',name,')]'}⊂⍬
114+
ns.{⎕DF'[JSON Object: ',name,']'}⊂⍬
111115
:EndIf
112116
113117

@@ -141,7 +145,7 @@
141145
parms←CreateParms
142146
parms.Accepted←'application/vnd.github.mercy-preview+json'
143147
parms.Method←'PUT'
144-
parms.Body←'{',(1 JSON'names'topics),'}'
148+
parms.Body←'{',(1 JSON'names'topics),'}'
145149
(rc msg dummy)←parms GetJson gitPath
146150
147151

@@ -151,36 +155,39 @@
151155
⍝ The items are called major.minor.patch.built with "built" being optional.\\
152156
⍝ In case that is impossible (because `text` does not fulfil the criteria) `⍬` is returned.\\
153157
⍝ Assumptions:
154-
⍝ * `text` may or may not start with a non-digit. If there is one it will be removed.\\
158+
⍝ * `text` may or may not start with a non-digit. All leading non-digit characters are ignored.\\
155159
⍝ Therefore both `1.2.3` and `v.1.2.3` are valid input.
156160
⍝ * The remaining `text` must consist of nothing but digits and dots.
157161
⍝ * The first two numbers ("major" and "minor") must not be bigger than 99.
158162
⍝ * The third number ("path") must not be bigger than 999.
159163
⍝ * The optional last (forth) number must not be bigger than 99999.
160164
⍝ * `text` must come either with three numbers (as in `1.2.3`) or with four number (as in `1.2.3.9999`).
161165
⍝ However, even if all assumptions are fulfilled but the result is zero there is still a `⍬` returned.
162-
⍝ Note that leading zeros are mermitted. Therefor 1.2.3.001 is **_not_** a valid input.
166+
⍝ Note that leading zeros are not permitted. Therefore 1.2.3.001 is **_not_** a valid input.\\
163167
⍝ Examples:
164168
⍝ + 1.20.333 transforms into 120333
165-
⍝ + 12.12.123.12345 transforms into 1212123.12345
169+
⍝ + 12.12.123.12345 transforms into 1212123.12345\\
166170
⍝ If the tag name does not fulfil the assumptions the conversion might crash. In that case `⍬` is
167171
⍝ returned as result.
168172
number←⍬
169-
(bool vec)←'.'⎕VFI{⍵↓⍨~⎕D∊⍨⊃⍵}text
170-
:If 3 4∊⍨⍴bool
171-
vec←{⍵↑⍨3⌈4⌊⍴⍵}↑vec
172-
:If 3=⍴vec
173-
:If ∧/100 100 1000>vec
174-
:AndIf 0=number←100 100 1000⊥vec
175-
number←⍬
176-
:EndIf
177-
:Else
178-
:If ~∧/100 100 1000 100000>vec
179-
number←⍬
180-
:ElseIf 0=number←100 100 1000 100000⊥vec
181-
number←⍬
173+
text←{⍵↓⍨+/∧\0=⍵∊⎕D}text
174+
:If 0=+/{+/∧\'0'=⍵}¨'.'Split text
175+
(bool vec)←'.'⎕VFI text
176+
:If 3 4∊⍨⍴bool
177+
vec←{⍵↑⍨3⌈4⌊⍴⍵}↑vec
178+
:If 3=⍴vec
179+
:If ∧/100 100 1000>vec
180+
:AndIf 0=number←100 100 1000⊥vec
181+
number←⍬
182+
:EndIf
183+
:Else
184+
:If ~∧/100 100 1000 100000>vec
185+
number←⍬
186+
:ElseIf 0=number←100 100 1000 100000⊥vec
187+
number←⍬
188+
:EndIf
189+
number÷←100000
182190
:EndIf
183-
number÷←100000
184191
:EndIf
185192
:EndIf
186193
@@ -261,7 +268,7 @@
261268
msg←'HTTP error'
262269
:Return
263270
:EndIf
264-
ns←JSON GetText res.GetResponseStream
271+
ns←JSON GetText res.GetResponseStream
265272
headers←SplitHeaders⍕res.Headers
266273
:If 0<noOfPages←GetNoOfPages headers
267274
:For i :In 1↓⍳noOfPages
@@ -273,7 +280,7 @@
273280
msg←'HTTP error'
274281
:Return
275282
:EndIf
276-
ns,←JSON GetText res.GetResponseStream
283+
ns,←JSON GetText res.GetResponseStream
277284
:EndFor
278285
:EndIf
279286
:Else
@@ -290,4 +297,28 @@
290297
r.Body←''
291298
292299

300+
∇ r←{type}JSON y;version;buff
301+
⍝ Cover for `⎕JSON` in order to support 15.0 which had only an ⌶ for what became later `⎕JSON`.\\
302+
⍝ Note that by default this function imports JSON (`type`=0).\\
303+
⍝ In order to export `type` must be specified as 1.\\
304+
⍝ `y` must be a nested vector representing JSON in case `type` is 0 (the default).
305+
⍝ Otherwise `y` must be an APL array (including a namespace) that will be exported to JSON.
306+
type←{0<⎕NC ⍵:⍎⍵ ⋄ 0}'type'
307+
version←⊃(//)⎕VFI{⍵/⍨2>+\⍵='.'}2⊃'#'⎕WG'APLVersion'
308+
'This version of Dyalog is not supported'⎕SIGNAL 11/⍨15>version
309+
'Invalid left argument: must be Boolean'⎕SIGNAL 11/⍨~(⊂type)∊0 1
310+
:If 15=version
311+
:If 0=type ⍝ Import?
312+
r←7159⌶y
313+
:ElseIf 1=type ⍝ Export!
314+
∘∘∘ ⍝ Not implemented eyt (because not required)
315+
7160⌶
316+
:Else
317+
∘∘∘ ⍝ Huuh?!
318+
:EndIf
319+
:Else
320+
r←⍎'type ⎕JSON filename'
321+
:EndIf
322+
323+
293324
:EndClass

APLSource/TestCases/Test_006.aplf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
→PassesIf 1020030=##.GitHubAPIv3.CastTagname2Number'v10.20.30'
1717
→PassesIf 102003.00001=##.GitHubAPIv3.CastTagname2Number'v1.2.3.1'
1818
→PassesIf 102003.09999=##.GitHubAPIv3.CastTagname2Number'v1.2.3.9999'
19+
→PassesIf 102003.09999=##.GitHubAPIv3.CastTagname2Number'abc1.2.3.9999'
1920

2021
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'va2b3n4n5'
2122
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'99.1'
@@ -25,6 +26,10 @@
2526
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.200.3'
2627
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.2.3000'
2728
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.2.3.123456'
29+
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'01.2.3.4'
30+
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.02.3.4'
31+
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.2.03.4'
32+
→PassesIf ⍬≡##.GitHubAPIv3.CastTagname2Number'1.2.3.04'
2833

2934
R←∆OK
3035
⍝Done
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
R←Test_ZZZ_998(stopFlag batchFlag);⎕IO;⎕ML;⎕TRAP;report;buff;xml;source;FindSpecialString
2+
⍝ Checks on two text vectors: "⍝TODO⍝" and "⍝CHECK⍝"; never fails, just reports.
3+
⎕IO←0 ⋄ ⎕ML←3
4+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
5+
R←∆OK
6+
report←''
7+
8+
FindSpecialString←{
9+
⍝ Use this to search for stuff like "CHECK" or "TODO" enclosed between `⍝` (⍵).
10+
⎕IO←0 ⋄ ⎕ML←3
11+
startIn←⍺
12+
r←⍉1↓[1]⎕SE.UCMD'locate "',⍵,'" -return=count -objects=',⍕startIn
13+
r←(0<r[;1])⌿r ⍝ Drop those with no hits
14+
0≥1↑⍴r:r
15+
r[;0]←{2>'#'+.=⍵:⍵ ⋄ {⌽⍵↑⍨1+⍵⍳'#'}⌽⍵}¨r[;0] ⍝ Circumvent bug <01356>
16+
r
17+
}
18+
19+
xml←⎕XML'flat'#.APLTreeUtils.ReadUtf8File'publish.config'
20+
source←2⊃xml[xml[;1]⍳⊂'container';]
21+
buff←source FindSpecialString'⍝CHECK⍝'
22+
buff←(buff[;0]≢¨⎕XSI[0])⌿buff ⍝ remove caller
23+
:If ~0∊⍴buff
24+
report,←↓(⊂' ⍝CHECK⍝ found:'),(⊂' '),¨buff
25+
:EndIf
26+
buff←source FindSpecialString'⍝TODO⍝'
27+
buff←(buff[;0]≢¨⎕XSI[0])⌿buff ⍝ remove caller
28+
:If ~0∊⍴buff
29+
report,←↓(⊂' ⍝TODO⍝ found:'),(⊂' '),¨buff
30+
:EndIf
31+
:If 1=⍴,report
32+
report,←⊂' Nothing found!'
33+
:Else
34+
⎕←'Checking for ⍝TODO⍝ and ⍝CHECK⍝ '{⍵↑,'--- ',⍺,' ',⍵⍴'-'}80⌊⎕PW-1
35+
⎕←⊃report
36+
:EndIf
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
R←Test_ZZZ_999(stopFlag batchFlag);v;n;d;xml;rf;f1;f2;⎕TRAP
2+
⍝ Check the "Version" function and publish.config.
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
R←∆Failed
5+
6+
rf←#._GitHubAPIv3.GitHubAPIv3
7+
8+
⍝ First we check whether "Version" returns a valid result:
9+
(n v d)←rf.Version
10+
v←{⍵/⍨3>+\'.'=⍵}v ⍝ Remove build ID
11+
f1←~5≤⍴v
12+
f1∨←2≠'.'+.=v
13+
f1∨←~∧/⎕D∊⍨v~'.'
14+
15+
f1∨←10≠⍴d
16+
f1∨←d[4 7+⎕IO]∨.≠'-'
17+
f1∨←~∧/⎕D∊⍨d~'-'
18+
19+
⍝ publish.config must be in line with what "Version" returns of course:
20+
xml←⎕XML'flat'#.APLTreeUtils.ReadUtf8File'publish.config'
21+
f2←v≢(2+⎕IO)⊃xml[xml[;1+⎕IO]⍳⊂'version';]
22+
f2∨←d≢(2+⎕IO)⊃xml[xml[;1+⎕IO]⍳⊂'date';]
23+
24+
:If f1
25+
⎕←'Result of the "Version" function is invalid.'
26+
:EndIf
27+
:If f2
28+
⎕←'The contents of "publish.config" is not in line with "Version".'
29+
:EndIf
30+
31+
→FailsIf f1∨f2
32+
33+
R←∆OK

Dist/GitHubAPIv3.zip

-3.81 KB
Binary file not shown.

Make/Make-old.DWS

-1.63 MB
Binary file not shown.

Make/Make.DWS

-42.6 KB
Binary file not shown.

acre.config

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
[
22
CaseCode←'Off'
3-
KeepHistory←'On'
43
Open←''
54
ProjectSpace←'#._GitHubAPIv3'
65
StartUp←''

publish.config

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<tool name="GitHubAPIv3"> <version>1.0.0</version> <date>2018-12-25</date> <files></files> <container>#._GitHubAPIv3</container> <needs> <script>APLTreeUtils</script> <script>FilesAndDirs</script> <script>OS</script> <script>Tester</script> </needs> <scriptOnly>1</scriptOnly> <wsid>Development</wsid> <autoload>1</autoload> <buildid>8</buildid></tool>
1+
<tool name="GitHubAPIv3"> <version>0.3.0</version> <date>2019-02-17</date> <files></files> <container>#._GitHubAPIv3</container> <needs> <script>APLTreeUtils</script> <script>FilesAndDirs</script> <script>OS</script> <script>Tester</script> </needs> <scriptOnly>1</scriptOnly> <wsid>Development</wsid> <autoload>1</autoload> <buildid>8</buildid></tool>

0 commit comments

Comments
 (0)