Skip to content

Commit 6459335

Browse files
committed
Bug fix: ListIssues crashed when there were no issues to report on
1 parent 3a828a6 commit 6459335

File tree

7 files changed

+661
-12
lines changed

7 files changed

+661
-12
lines changed

APLSource/GitHubAPIv3.aplc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
:Class GitHubAPIv3
2-
⍝ This class offers methods that allows one to communicate with GitHub by using GitHub's REST API from Dyalog APL.
2+
⍝ This class offers methods that allow one to communicate with GitHub by using the GitHub REST API from Dyalog APL.
33
⍝ Note that this is version 3 of the GitHub API; Later versions do **not** use REST.\\
44
⍝ Most methods of this class become available only by instantiating the class. `⎕NEW` requires an owner as argument.\\
55
⍝ However, there are also a few shared methods beyond `Version` and `History` available.\\
@@ -10,11 +10,14 @@
1010

1111
∇ r←Version
1212
:Access Public Shared
13-
r←'GitHubAPIv3' '1.2.0' '2024-04-28'
13+
r←'GitHubAPIv3' '1.2.1' '2024-07-25'
1414
1515

1616
∇ History
1717
:Access Public Shared
18+
⍝ * 1.2.1
19+
⍝ * Bug fixed
20+
⍝ `GetAllIssues` crashed when there were no issues to report
1821
⍝ * 1.2.0
1922
⍝ * Instances of GitHubAPIv3 now have a useful display format: for a user "foo" it shows GitHubAPIv3[foo]
2023
⍝ * The name of the function `GetPrinciple` was changed to `GetPrincipal`
@@ -137,17 +140,20 @@
137140
:Access Public Instance
138141
⍝ Returns all issues for a given repository but no pull requests by default.\\
139142
⍝ In GitHub, every pull request is an issue, but not all issues are pull requests.
140-
⍝ You can enforce the addition of Pull Requests by passing a 1 as left argument.
143+
⍝ You can enforce the addition of Pull Requests by passing a 1 as left argument.\\
144+
⍝ In case there are no issues an empty vector is returned.
141145
addPullRequests←{0<⎕NC ⍵:⍎⍵ ⋄ 0}'addPullRequests'
142146
gitPath←'https://api.github.com/repos/',(_owner),'/',repoName,'/issues'
143147
ns←GetJson gitPath
144-
:If ~addPullRequests
145-
ns←(0=⊃¨ns.⎕NC⊂'pull_request')/ns
148+
:If 0<≢ns
149+
:If ~addPullRequests
150+
ns←(0=⊃¨ns.⎕NC⊂'pull_request')/ns
151+
:EndIf
152+
ns.⎕DF(repoName,' issue ')∘,¨(⍕¨ns.number)
153+
ns.⎕FX⊂⎕CR'∆List'
154+
ns.⎕FX⊂'r←∆Details instance' 'r←∆List' ' :If 0<≢instance' 'r(instance.GetPrincipal)←''assignees'' ''login''' 'r(instance.GetPrincipal)←''labels'' ''name''' ':EndIf'
155+
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];]'
146156
:EndIf
147-
ns.⎕DF(repoName,' issue ')∘,¨(⍕¨ns.number)
148-
ns.⎕FX⊂⎕CR'∆List'
149-
ns.⎕FX⊂'r←∆Details instance' 'r←∆List' ' :If 0<≢instance' 'r(instance.GetPrincipal)←''assignees'' ''login''' 'r(instance.GetPrincipal)←''labels'' ''name''' ':EndIf'
150-
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];]'
151157
152158

153159
∇ ns←GetIssue(repoName number);gitPath
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
R←Test_Issue_055(stopFlag batchFlag);⎕TRAP;data
2+
3+
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
4+
R←T._Failed
5+
6+
data←∆MyGitHubAPI.GetAllIssues'TestRepo'
7+
→T.PassesIf 2∧.=⊃∘⍴∘⍴¨data.∆List
8+
9+
R←T._OK
10+
⍝Done
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
R←Test_Misc_003(stopFlag batchFlag);⎕TRAP;buff
1+
R←Test_Misc_003(stopFlag batchFlag);⎕TRAP;myInstance
22
⍝ Create an Instance of GitHubAPIv3
33
⎕TRAP←(999 'C' '. ⍝ Deliberate error')(0 'N')
44
R←T._Failed
55

6-
buff←⎕NEW ##.GitHubAPIv3(,⊂'Foo')
6+
myInstance←⎕NEW ##.GitHubAPIv3(,⊂'Foo')
77

88
R←T._OK
99
⍝Done

TestResults/CodeCoverage.cr

576 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)