add support for DELETE /builds/:repo/:pr

Signed-off-by: Jakub Sokołowski <jakub@status.im>
This commit is contained in:
Jakub Sokołowski 2020-07-06 19:02:27 +02:00
parent 56529f3fe1
commit dfe95c0e2b
No known key found for this signature in database
GPG Key ID: 4EF064D0E6D63020
3 changed files with 25 additions and 2 deletions

View File

@ -55,6 +55,12 @@ const App = ({ghc, schema}) => {
ctx.body = {count: builds.length, builds}
})
/* drop builds for repo+pr */
router.delete('/builds/:repo/:pr', async (ctx) => {
const rval = await ghc.db.removeBuilds(ctx.params)
ctx.body = {}
})
/* list all managed comments */
router.get('/comments', async (ctx) => {
const comments = await ghc.db.getComments()

View File

@ -65,13 +65,18 @@ class Builds {
})
}
async removeBuilds ({repo, pr}) {
log.info(`Removing build for ${repo}/PR-${pr}`)
return await this.builds.findAndRemove({repo, pr})
}
async addBuild ({repo, pr, build}) {
log.info(`Storing build for PR-${pr}: #${build.id} for ${build.platform}`)
log.info(`Storing build for ${repo}/PR-${pr}: #${build.id} for ${build.platform}`)
return await this.builds.insert({repo, pr, ...build})
}
async addComment ({repo, pr, comment_id}) {
log.info(`Storing comment for PR-${pr}: ${comment_id}`)
log.info(`Storing comment for ${repo}/PR-${pr}: ${comment_id}`)
return await this.comments.insert({repo, pr, comment_id})
}

View File

@ -66,6 +66,18 @@ describe('App', () => {
})
})
describe('DELETE /builds/:repo/:pr', () => {
it('should delete all matching builds', async () => {
const resp = await request(app.callback())
.delete('/builds/REPO-1/PR-1')
expect(resp.body).to.eql({})
expect(resp.status).to.eq(200)
expect(ghc.db.removeBuilds).calledOnceWith({
repo: 'REPO-1', pr: 'PR-1',
})
})
})
describe('POST /builds/:repo/:pr/refresh', () => {
it('should update github comment', async () => {
const resp = await request(app.callback())