@@ -6,38 +6,30 @@ import { stateToIcon } from './stateToIcon';
6
6
import { User } from './User' ;
7
7
8
8
export class Issue extends GithubEntity {
9
- readonly number : number = 0 ;
10
- readonly repositoryUrl : string = '' ;
11
- readonly labelsUrl : string = '' ;
12
- readonly htmlUrl : string = '' ;
13
- readonly body : string = '' ;
14
- readonly title : string = '' ;
15
- readonly user : User = User . fromJS ( { } ) ;
16
- readonly state : 'open' | 'closed' = 'open' ;
17
- readonly locked : boolean = false ;
18
- readonly comments : number = 0 ;
19
- readonly createdAt = Temporal . Instant . fromEpochSeconds ( 0 ) ;
20
- readonly updatedAt = Temporal . Instant . fromEpochSeconds ( 0 ) ;
21
- readonly closedAt : Date | null = null ;
22
- readonly labels : Label [ ] = [ ] ;
23
- readonly authorAssociation : string = 'NONE' ;
24
- readonly pullRequest : Record < string , any > | null = null ;
25
- readonly draft ?: boolean ;
9
+ number = 0 ;
10
+ owner = '' ;
11
+ repo = '' ;
12
+ repositoryUrl = '' ;
13
+ labelsUrl = '' ;
14
+ htmlUrl = '' ;
15
+ body = '' ;
16
+ title = '' ;
17
+ user = User . fromJS ( { } ) ;
18
+ state : 'open' | 'closed' = 'open' ;
19
+ locked = false ;
20
+ comments = 0 ;
21
+ createdAt = Temporal . Instant . fromEpochSeconds ( 0 ) ;
22
+ updatedAt = Temporal . Instant . fromEpochSeconds ( 0 ) ;
23
+ closedAt : Date | null = null ;
24
+ labels : Label [ ] = [ ] ;
25
+ authorAssociation = 'NONE' ;
26
+ pullRequest : Record < string , any > | null = null ;
27
+ draft ?: boolean ;
26
28
27
29
get stateIcon ( ) {
28
30
return stateToIcon [ this . state ] ;
29
31
}
30
32
31
- get owner ( ) {
32
- const pieces = this . repositoryUrl . split ( '/' ) ;
33
- return pieces [ pieces . length - 2 ] ;
34
- }
35
-
36
- get repo ( ) {
37
- const pieces = this . repositoryUrl . split ( '/' ) ;
38
- return pieces [ pieces . length - 1 ] ;
39
- }
40
-
41
33
static schema = {
42
34
user : User ,
43
35
createdAt : Temporal . Instant . from ,
@@ -47,18 +39,40 @@ export class Issue extends GithubEntity {
47
39
} ;
48
40
49
41
pk ( ) {
50
- return [ this . repositoryUrl , this . number ] . join ( ',' ) ;
42
+ if ( ! this . owner ) {
43
+ const { owner, repo } = splitRepoUrl ( this . repositoryUrl ) ;
44
+ return `${ owner } /${ repo } /${ this . number } ` ;
45
+ }
46
+ return `${ this . owner } /${ this . repo } /${ this . number } ` ;
51
47
}
48
+
49
+ static process (
50
+ input : any ,
51
+ parent : any ,
52
+ key : string | undefined ,
53
+ args : any [ ] ,
54
+ ) {
55
+ const { owner, repo } = splitRepoUrl ( input . repositoryUrl ) ;
56
+ return { owner, repo, ...input } ;
57
+ }
58
+ }
59
+
60
+ function splitRepoUrl ( url : string ) {
61
+ const [ a , b , c , d , owner , repo ] = url . split ( '/' ) ;
62
+ return { owner, repo } ;
52
63
}
53
64
54
65
export const IssueResource = githubResource ( {
55
66
path : '/repos/:owner/:repo/issues/:number' ,
56
67
schema : Issue ,
68
+ dataExpiryLength : 60000 ,
57
69
pollFrequency : 60000 ,
58
70
searchParams : { } as IssueFilters | undefined ,
71
+ paginationField : 'page' ,
59
72
} ) . extend ( ( Base ) => ( {
60
73
search : Base . getList . extend ( {
61
- path : '/search/issues\\?q=:q?%20repo\\::owner/:repo&page=:page?' ,
74
+ path : '/search/issues' ,
75
+ searchParams : { } as IssueFilters & { q : string } ,
62
76
schema : {
63
77
results : {
64
78
incompleteResults : false ,
0 commit comments