@@ -62,6 +62,91 @@ describe("auto-label-bot", () => {
6262 emptyMockConfig ( payload . repository . full_name ) ;
6363
6464 const scope = nock ( "https://api.github.com" )
65+ . get (
66+ "/repos/ezyang/testing-ideal-computing-machine/issues/5/events?per_page=100"
67+ )
68+ . reply ( 200 , [ ] )
69+ . post (
70+ "/repos/ezyang/testing-ideal-computing-machine/issues/5/labels" ,
71+ ( body ) => {
72+ expect ( body ) . toMatchObject ( { labels : [ "triage review" ] } ) ;
73+ return true ;
74+ }
75+ )
76+ . reply ( 200 ) ;
77+
78+ await probot . receive ( { name : "issues" , payload, id : "2" } ) ;
79+
80+ scope . done ( ) ;
81+ } ) ;
82+
83+ test ( "do not re-add triage review if it was just removed (within the hour)" , async ( ) => {
84+ nock ( "https://api.github.com" )
85+ . post ( "/app/installations/2/access_tokens" )
86+ . reply ( 200 , { token : "test" } ) ;
87+
88+ const payload = requireDeepCopy ( "./fixtures/issues.labeled" ) ;
89+ payload [ "label" ] = { name : "high priority" } ;
90+ payload [ "issue" ] [ "labels" ] = [ { name : "high priority" } ] ;
91+ emptyMockConfig ( payload . repository . full_name ) ;
92+
93+ const recent = new Date ( Date . now ( ) - 5 * 60 * 1000 ) . toISOString ( ) ;
94+ const scope = nock ( "https://api.github.com" )
95+ . get (
96+ "/repos/ezyang/testing-ideal-computing-machine/issues/5/events?per_page=100"
97+ )
98+ . reply ( 200 , [
99+ {
100+ event : "labeled" ,
101+ label : { name : "high priority" } ,
102+ created_at : recent ,
103+ } ,
104+ {
105+ event : "labeled" ,
106+ label : { name : "triage review" } ,
107+ created_at : recent ,
108+ } ,
109+ {
110+ event : "unlabeled" ,
111+ label : { name : "triage review" } ,
112+ created_at : recent ,
113+ } ,
114+ ] ) ;
115+
116+ await probot . receive ( { name : "issues" , payload, id : "2" } ) ;
117+
118+ scope . done ( ) ;
119+ } ) ;
120+
121+ test ( "re-add triage review if old issue resurfaces (stale removal)" , async ( ) => {
122+ nock ( "https://api.github.com" )
123+ . post ( "/app/installations/2/access_tokens" )
124+ . reply ( 200 , { token : "test" } ) ;
125+
126+ const payload = requireDeepCopy ( "./fixtures/issues.labeled" ) ;
127+ payload [ "label" ] = { name : "high priority" } ;
128+ payload [ "issue" ] [ "labels" ] = [ { name : "high priority" } ] ;
129+ emptyMockConfig ( payload . repository . full_name ) ;
130+
131+ // Triage review was removed long ago — issue is resurfacing and
132+ // should be triaged again.
133+ const old = new Date ( Date . now ( ) - 30 * 24 * 60 * 60 * 1000 ) . toISOString ( ) ;
134+ const scope = nock ( "https://api.github.com" )
135+ . get (
136+ "/repos/ezyang/testing-ideal-computing-machine/issues/5/events?per_page=100"
137+ )
138+ . reply ( 200 , [
139+ {
140+ event : "labeled" ,
141+ label : { name : "triage review" } ,
142+ created_at : old ,
143+ } ,
144+ {
145+ event : "unlabeled" ,
146+ label : { name : "triage review" } ,
147+ created_at : old ,
148+ } ,
149+ ] )
65150 . post (
66151 "/repos/ezyang/testing-ideal-computing-machine/issues/5/labels" ,
67152 ( body ) => {
0 commit comments