|
12 | 12 | ⍝ It is part of the [APLTree library](https://github.com/aplteam/apltree/wiki) |
13 | 13 | ⍝ Kai Jaeger ⋄ APL Team Ltd |
14 | 14 |
|
15 | | - :Include APLTreeUtils |
16 | | - |
17 | 15 | ⎕IO←1 ⋄ ⎕ML←1 |
18 | 16 |
|
19 | 17 | ∇ r←Version |
20 | 18 | :Access Public Shared |
21 | | - r←'GitHub' '0.6.0.18' '2020-03-23' |
| 19 | + r←'GitHub' '0.7.0+22' '2020-03-17' |
22 | 20 | ∇ |
23 | 21 |
|
24 | 22 | ∇ History |
25 | 23 | :Access Public Shared |
| 24 | + ⍝ * 0.7.0 |
| 25 | + ⍝ * Is a Tatin package now and therefore requires 18.0 Unicode or better |
| 26 | + ⍝ * Does not :Include APLTreeUtils anymore (but does depend on APLTreeUtils2 being a sibling) |
26 | 27 | ⍝ * 0.6.0 |
27 | 28 | ⍝ * File extension is now .aplc rather than .dyalog |
28 | 29 | ⍝ * 0.5.0 |
|
79 | 80 | :Implements Constructor |
80 | 81 | _owner←owner |
81 | 82 | _regEx←'setup_<repoName>_<version>[.\]*.[0-9]{0,6}\.exe' ⍝ After version there _might_ be a built number |
| 83 | + A←(⊃⊃⎕CLASS ⎕THIS).##.APLTreeUtils2 |
82 | 84 | ∇ |
83 | 85 |
|
84 | 86 | ∇ (rc msg ns)←GetLatestReleaseInfo repoName;gitPath |
|
213 | 215 | :EndIf |
214 | 216 | ∇ |
215 | 217 |
|
216 | | - ∇ (rc msg endpoints)←GetAllEndpoints;gitPath;msg;rc |
| 218 | + ∇ (rc msg endpoints)←GetAllEndpoints;gitPath;msg;rc;A |
217 | 219 | :Access Public Shared |
218 | 220 | ⍝ This method returns all REST endpoints offered by the API.\\ |
219 | 221 | ⍝ It returns a namespace. Use the built-in `List` function for an overview. |
|
224 | 226 | ⍝ : Is empty in case `rc ←→ 0` but might offer addtional information otherwise. |
225 | 227 | ⍝ `ns` |
226 | 228 | ⍝ : Namespace with the data received from GitHub. |
| 229 | + A←##.APLTreeUtils2 |
227 | 230 | gitPath←'https://api.github.com/' |
228 | 231 | endpoints←⎕NS'' |
229 | 232 | (rc msg endpoints)←GetJson gitPath |
|
269 | 272 | ⍝ + 1.20.333 transforms into 120333 |
270 | 273 | ⍝ + 12.12.123.12345 transforms into 1212123.12345\\ |
271 | 274 | number←⍬ |
| 275 | + ⍝ This function might be called from a Shared method. when we need to address APLTreeUtils2 explicitly, |
| 276 | + ⍝ or from a n Instance method, when `A` is a ref pointing to APLTreeUtils2. |
| 277 | + :If 0<##.⎕NC'APLTreeUtils2' |
| 278 | + A←##.APLTreeUtils2 |
| 279 | + :EndIf |
272 | 280 | :If 0<≢text←{⍵↓⍨+/∧\0=⍵∊⎕D}text |
273 | 281 | text,←⊃,/(0⌈2-text+.='.')⍴⊂'.0' |
274 | | - :AndIf 0=+/{(1<⊃≢⍵)∧⊃'0'=1↑⍵}¨'.'Split text |
| 282 | + :AndIf 0=+/{(1<⊃≢⍵)∧⊃'0'=1↑⍵}¨'.'A.Split text |
275 | 283 | (bool vec)←'.'⎕VFI text |
276 | 284 | :AndIf 3 4∊⍨⍴bool |
277 | 285 | vec←{⍵↑⍨3⌈4⌊⍴⍵}↑vec |
|
307 | 315 | :If 0=⎕NC'regEx' |
308 | 316 | regEx←_regEx |
309 | 317 | :EndIf |
310 | | - type←Uppercase type |
| 318 | + type←1 ⎕C type |
311 | 319 | 'Invalid right argument ("type")'⎕SIGNAL 11/⍨~(⊂type)∊'EXE' 'ZIP' 'TAR' |
312 | 320 | :If 0=⎕NC'tag' |
313 | 321 | (rc more info)←GetLatestReleaseInfo repoName |
|
331 | 339 | regEx←'/',_owner,'/',repoName,'/releases/download/v',tag,'/',regEx |
332 | 340 | :If 1=≢buff←regEx ⎕S 2 0 1⍠('Greedy' 0)('IC' 1)⊣html |
333 | 341 | (itemNo offset length)←⊃buff |
334 | | - url←'https://github.com/',1↓(1+length)↑(offset-1)↓(itemNo+1)⊃(⎕UCS 10)Split html |
| 342 | + url←'https://github.com/',1↓(1+length)↑(offset-1)↓(itemNo+1)⊃(⎕UCS 10)A.Split html |
335 | 343 | :EndIf |
336 | 344 | :EndIf |
337 | 345 | :EndIf |
|
342 | 350 | ⍝ Note that drafted release and pre-release are both ignored. |
343 | 351 | :Access Public Instance |
344 | 352 | (rc more ns)←GetLatestReleaseInfo repoName |
345 | | - :If ∨/'Error'⍷∊more |
346 | | - 'Error accessin GitHub via the REST API'⎕SIGNAL 11 |
| 353 | + :If 0≠rc |
| 354 | + :OrIf ∨/'Error'⍷∊more |
| 355 | + :If 0=≢more |
| 356 | + 'Error accessing GitHub via the REST API'⎕SIGNAL 11 |
| 357 | + :Else |
| 358 | + more ⎕SIGNAL 11 |
| 359 | + :EndIf |
347 | 360 | :Else |
348 | 361 | tag←ns.tag_name |
349 | 362 | :EndIf |
|
418 | 431 | GetNoOfPages←{ |
419 | 432 | ⍝ Takes HTTP headers and returns the number of pages. If there are not any a zero is returned. |
420 | 433 | headers←⍵ |
421 | | - bool←'Link:'{⍺∘≡¨(⍴⍺)↑¨⍵}headers |
| 434 | + bool←'link:'{⍺∘≡¨(⍴⍺)↑¨⍵}⎕C headers |
422 | 435 | 0=+/bool:0 |
423 | 436 | link←(bool⍳1)⊃headers |
424 | | - buff←' 'Split link |
| 437 | + buff←' 'A.Split link |
425 | 438 | last←(¯1+⍴buff)⊃buff |
426 | 439 | buff←{⍵{(⍴'?page-')↓⍵[2]↑⍵[1]↓⍺}⊃'(&|\?)page=[0-9]{1,}'⎕S 0 1⊣⍵}last |
427 | 440 | ⊃⊃(//)⎕VFI buff |
|
430 | 443 | GetLinkToNextPage←{ |
431 | 444 | ⍝ Takes HTTP headers and returns the link pointing to the next page, if any |
432 | 445 | headers←⍵ |
433 | | - bool←'Link:'{⍺∘≡¨(⍴⍺)↑¨⍵}headers |
| 446 | + bool←'link:'{⍺∘≡¨(⍴⍺)↑¨⍵}⎕C headers |
434 | 447 | 0=+/bool:0 |
435 | 448 | link←(bool⍳1)⊃headers |
436 | | - buff←' 'Split link |
| 449 | + buff←' 'A.Split link |
437 | 450 | 1↓¯2↓⊃1↓buff |
438 | 451 | } |
439 | 452 |
|
440 | 453 | SplitHeaders←{ |
441 | 454 | headers←⍵↑⍨1⍳⍨(⎕UCS 10 13)⍷⍵ |
442 | | - (⎕UCS 13 10)Split headers |
| 455 | + A.Split headers |
443 | 456 | } |
444 | 457 |
|
445 | 458 | ∇ txt←GetText obj;ts |
|
451 | 464 | ⍝ Takes `gitURL`which must specify a valid GitHub API URL and returns the data from GitHub.\\ |
452 | 465 | ⍝ `⍵`: Project URL, for example 'api.github.com/repos/aplteam/testrepo/releases/latest' |
453 | 466 | ⍝ `⍺`: Optional parameter space, typically create by calling `CreateHttpParms`. |
454 | | - ⍝ `rc` |
455 | | - ⍝ : Either 0 for okay or an error code.\\ |
456 | | - ⍝ `msg` |
457 | | - ⍝ : Is empty in case `rc←→0` but might offer addtional information otherwise. |
458 | | - ⍝ `ns` |
459 | | - ⍝ : Namespace with the data received from GitHub. |
| 467 | + ⍝ | `rc` | Either 0 for okay or an error code. |
| 468 | + ⍝ | `msg` | Is empty in case `rc←→0` but might offer addtional information otherwise. |
| 469 | + ⍝ | `ns` | Namespace with the data received from GitHub. |
460 | 470 | parms←{0<⎕NC ⍵:⍎⍵ ⋄ CreateHttpParms}'parms' |
461 | 471 | :If 0=⎕NC'_owner' |
462 | 472 | owner←'APL GitHub API' |
463 | 473 | :Else |
464 | 474 | owner←_owner |
465 | 475 | :EndIf |
466 | | - gitURL←'https://'{⍵,⍨⍺/⍨⍺≢(⍴⍺)↑⍵}Lowercase gitURL |
| 476 | + gitURL←'https://'{⍵,⍨⍺/⍨⍺≢(⍴⍺)↑⍵}⎕C gitURL |
467 | 477 | rc←0 |
468 | 478 | msg←'' |
469 | 479 | ns←⎕NS'' |
|
517 | 527 | :If 0=type ⍝ Import? |
518 | 528 | r←7159⌶y |
519 | 529 | :ElseIf 1=type ⍝ Export! |
520 | | - ∘∘∘ ⍝ Not implemented yet (because not required) |
| 530 | + ∘∘∘ ⍝ Not implemented yet (because never required) |
521 | 531 | 7160⌶ |
522 | 532 | :Else |
523 | 533 | ∘∘∘ ⍝ Huuh?! |
|
0 commit comments