@@ -99,11 +99,12 @@ router.post('/:id/authorise', async (req: Request, res: Response) => {
9999
100100 const { username } = req . user as { username : string } ;
101101
102- const push = await getValidPushOrRespond ( id , res ) ;
103- if ( ! push ) return ;
102+ // Get the push request
103+ const push = await db . getPush ( id ) ;
104+ console . log ( { push } ) ;
104105
105106 // Get the committer of the push via their email address
106- const committerEmail = push . userEmail ;
107+ const committerEmail = push ? .userEmail ;
107108 const list = await db . getUsers ( { email : committerEmail } ) ;
108109 console . log ( { list } ) ;
109110
@@ -121,40 +122,39 @@ router.post('/:id/authorise', async (req: Request, res: Response) => {
121122 return ;
122123 }
123124
124- // If we are not the author, now check that we are allowed to authorise on this repo
125+ // If we are not the author, now check that we are allowed to authorise on this
126+ // repo
125127 const isAllowed = await db . canUserApproveRejectPush ( id , username ) ;
126- if ( ! isAllowed ) {
128+ if ( isAllowed ) {
129+ console . log ( `user ${ username } approved push request for ${ id } ` ) ;
130+
131+ const reviewerList = await db . getUsers ( { username } ) ;
132+ console . log ( { reviewerList } ) ;
133+
134+ const reviewerGitAccount = reviewerList [ 0 ] . gitAccount ;
135+ console . log ( { reviewerGitAccount } ) ;
136+
137+ if ( ! reviewerGitAccount ) {
138+ res . status ( 401 ) . send ( {
139+ message : 'You must associate a GitHub account with your user before approving...' ,
140+ } ) ;
141+ return ;
142+ }
143+
144+ const attestation = {
145+ questions,
146+ timestamp : new Date ( ) ,
147+ reviewer : {
148+ username,
149+ } ,
150+ } ;
151+ const result = await db . authorise ( id , attestation ) ;
152+ res . send ( result ) ;
153+ } else {
127154 res . status ( 401 ) . send ( {
128- message : 'User is not authorised to authorise changes' ,
155+ message : `user ${ username } not authorised to approve push's on this project` ,
129156 } ) ;
130- return ;
131157 }
132-
133- console . log ( `user ${ username } approved push request for ${ id } ` ) ;
134-
135- const reviewerList = await db . getUsers ( { username } ) ;
136- console . log ( { reviewerList } ) ;
137-
138- const reviewerGitAccount = reviewerList [ 0 ] . gitAccount ;
139- console . log ( { reviewerGitAccount } ) ;
140-
141- if ( ! reviewerGitAccount ) {
142- res . status ( 401 ) . send ( {
143- message : 'You must associate a GitHub account with your user before approving...' ,
144- } ) ;
145- return ;
146- }
147-
148- const attestation = {
149- questions,
150- timestamp : new Date ( ) ,
151- reviewer : {
152- username,
153- gitAccount : reviewerGitAccount ,
154- } ,
155- } ;
156- const result = await db . authorise ( id , attestation ) ;
157- res . send ( result ) ;
158158 } else {
159159 res . status ( 401 ) . send ( {
160160 message : 'You are unauthorized to perform this action...' ,
0 commit comments