@@ -28,12 +28,12 @@ export function matchEmoji(queryText: string): string[] {
2828 return sortAndReduce ( results ) ;
2929}
3030
31- type Mention = { value : string ; name : string ; fullname : string ; avatar : string } ;
32- export function matchMention ( queryText : string ) : Mention [ ] {
31+ type MentionSuggestion = { value : string ; name : string ; fullname : string ; avatar : string } ;
32+ export function matchMention ( queryText : string ) : MentionSuggestion [ ] {
3333 const query = queryText . toLowerCase ( ) ;
3434
3535 // results is a map of weights, lower is better
36- const results = new Map < Mention , number > ( ) ;
36+ const results = new Map < MentionSuggestion , number > ( ) ;
3737 for ( const obj of window . config . mentionValues ?? [ ] ) {
3838 const index = obj . key . toLowerCase ( ) . indexOf ( query ) ;
3939 if ( index === - 1 ) continue ;
@@ -44,113 +44,20 @@ export function matchMention(queryText: string): Mention[] {
4444 return sortAndReduce ( results ) ;
4545}
4646
47- type Issue = { state : 'open' | 'closed' ; pull_request : { draft : boolean ; merged : boolean } | null } ;
48- type IssueMention = { value : string ; name : string ; issue : Issue } ;
49- export async function matchIssue ( url : string , queryText : string ) : Promise < IssueMention [ ] > {
47+ type Issue = { id : number ; title : string ; state : 'open' | 'closed' ; pull_request ?: { draft : boolean ; merged : boolean } } ;
48+ export async function matchIssue ( url : string , queryText : string ) : Promise < Issue [ ] > {
5049 const query = queryText . toLowerCase ( ) ;
5150
52- // http://localhost:3000/anbraten/test/issues/1
53- // http://localhost:3000/anbraten/test/compare/main...anbraten-patch-1
51+ // TODO: support sub-path
5452 const repository = ( new URL ( url ) ) . pathname . split ( '/' ) . slice ( 1 , 3 ) . join ( '/' ) ;
55- const issuePullRequestId = url . split ( '/' ) . slice ( - 1 ) [ 0 ] ;
53+ const issuePullRequestId = parseInt ( url . split ( '/' ) . slice ( - 1 ) [ 0 ] ) ;
5654
57- console . log ( 'suggestions for 1' , {
58- repository,
59- query,
55+ const res = await request ( `/api/v1/repos/${ repository } /issues?q=${ query } ` , {
56+ method : 'GET' ,
6057 } ) ;
6158
62- // TODO: fetch data from api
63- // const res = await request('/-/suggestions', {
64- // method: 'GET',
65- // data: {
66- // repository,
67- // query,
68- // },
69- // });
70- // console.log(await res.json());
59+ const issues : Issue [ ] = await res . json ( ) ;
7160
72- // results is a map of weights, lower is better
73- const results = new Map < IssueMention , number > ( ) ;
74- // for (const obj of window.config.mentionValues ?? []) {
75- // const index = obj.key.toLowerCase().indexOf(query);
76- // if (index === -1) continue;
77- // const existing = results.get(obj);
78- // results.set(obj, existing ? existing - index : index);
79- // }
80-
81- results . set ( {
82- value : '28958' ,
83- name : 'Live removal of issue comments using htmx websocket' ,
84- issue : {
85- state : 'open' ,
86- pull_request : {
87- merged : false ,
88- draft : false ,
89- } ,
90- } ,
91- } , 0 ) ;
92-
93- results . set ( {
94- value : '32234' ,
95- name : 'Calculate `PublicOnly` for org membership only once' ,
96- issue : {
97- state : 'closed' ,
98- pull_request : {
99- merged : true ,
100- draft : false ,
101- } ,
102- } ,
103- } , 1 ) ;
104-
105- results . set ( {
106- value : '32280' ,
107- name : 'Optimize branch protection rule loading' ,
108- issue : {
109- state : 'open' ,
110- pull_request : {
111- merged : false ,
112- draft : false ,
113- } ,
114- } ,
115- } , 2 ) ;
116-
117- results . set ( {
118- value : '32326' ,
119- name : 'Shallow Mirroring' ,
120- issue : {
121- state : 'open' ,
122- pull_request : null ,
123- } ,
124- } , 3 ) ;
125-
126- results . set ( {
127- value : '32248' ,
128- name : 'Make admins adhere to branch protection rules' ,
129- issue : {
130- state : 'closed' ,
131- pull_request : {
132- merged : true ,
133- draft : false ,
134- } ,
135- } ,
136- } , 4 ) ;
137-
138- results . set ( {
139- value : '32249' ,
140- name : 'Add a way to disable branch protection rules for admins' ,
141- issue : {
142- state : 'closed' ,
143- pull_request : null ,
144- } ,
145- } , 5 ) ;
146-
147- // filter out current issue/pull request
148- for ( const [ key ] of results . entries ( ) ) {
149- if ( key . value === issuePullRequestId ) {
150- results . delete ( key ) ;
151- break ;
152- }
153- }
154-
155- return sortAndReduce ( results ) ;
61+ // filter issue with same id
62+ return issues . filter ( ( i ) => i . id !== issuePullRequestId ) ;
15663}
0 commit comments