@@ -6,38 +6,30 @@ import { stateToIcon } from './stateToIcon';
66import { User } from './User' ;
77
88export 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 ;
2628
2729 get stateIcon ( ) {
2830 return stateToIcon [ this . state ] ;
2931 }
3032
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-
4133 static schema = {
4234 user : User ,
4335 createdAt : Temporal . Instant . from ,
@@ -47,18 +39,40 @@ export class Issue extends GithubEntity {
4739 } ;
4840
4941 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 } ` ;
5147 }
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 } ;
5263}
5364
5465export const IssueResource = githubResource ( {
5566 path : '/repos/:owner/:repo/issues/:number' ,
5667 schema : Issue ,
68+ dataExpiryLength : 60000 ,
5769 pollFrequency : 60000 ,
5870 searchParams : { } as IssueFilters | undefined ,
71+ paginationField : 'page' ,
5972} ) . extend ( ( Base ) => ( {
6073 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 } ,
6276 schema : {
6377 results : {
6478 incompleteResults : false ,
0 commit comments