Skip to content

Commit

Permalink
Re-order middleware to allow /healthz
Browse files Browse the repository at this point in the history
Signed-off-by: Brett Logan <lindluni@github.com>
  • Loading branch information
lindluni committed Mar 13, 2024
1 parent f96640d commit ab831d5
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
4 changes: 1 addition & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {
} from './src/middleware.js'

const app = express()
app.get('/healthz', respond)
app.use(express.json())
app.use(debugRequest)
app.use(hydrateKey)
Expand All @@ -23,9 +24,6 @@ app.use(verifyGitHubWebhook)
app.use(verifyMembership)
app.use(verifyCommand)
app.use(hydrateOctokit)

app.get('/', respond)
app.get('/healthz', respond)
app.post('/api/github/webhooks', processWebhook)

const main = async () => {
Expand Down
5 changes: 4 additions & 1 deletion src/middleware.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,10 @@ export const hydrateOctokit = async (req, res, next) => {
}

export const verifyMembership = async (req, res, next) => {
if (req.body.comment.author_association === 'MEMBER') {
if (req.body.comment.author_association === 'COLLABORATOR' ||
req.body.comment.author_association === 'MEMBER' ||
req.body.comment.author_association === 'CONTRIBUTOR' ||
req.body.comment.author_association === 'OWNER') {
return next()
}
return next('User is not a member')
Expand Down
10 changes: 10 additions & 0 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,14 @@ export const retrieveRequiredChecks = async (properties) => {
}
}
return requiredChecks
}

export const unless = function (path, middleware) {
return function (req, res, next) {
if (path === req.path) {
return next();
} else {
return middleware(req, res, next);
}
};
}

0 comments on commit ab831d5

Please sign in to comment.