Skip to content
This repository was archived by the owner on May 20, 2023. It is now read-only.

Commit

Permalink
Merge branch 'master' into ensure-unlocked-tests
Browse files Browse the repository at this point in the history
* master:
  Bump https-proxy-agent from 2.2.1 to 2.2.4 (#275)
  Double-check issue state is not closed before acting
  Bump acorn from 5.7.3 to 5.7.4
  • Loading branch information
JamesMGreene committed Apr 23, 2020
2 parents 3fe6a57 + 32fdff5 commit dfd6b5f
Show file tree
Hide file tree
Showing 3 changed files with 117 additions and 19 deletions.
16 changes: 10 additions & 6 deletions lib/stale.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,11 @@ module.exports = class Stale {

const staleItems = (await this.getStale(type)).data.items

await Promise.all(staleItems.filter(issue => !issue.locked).map(issue => {
return this.markIssue(type, issue)
}))
await Promise.all(
staleItems
.filter(issue => !issue.locked && issue.state !== 'closed')
.map(issue => this.markIssue(type, issue))
)
}

async sweep (type) {
Expand All @@ -54,9 +56,11 @@ module.exports = class Stale {
this.logger.trace({ owner, repo }, 'Configured to close stale issues')
const closableItems = (await this.getClosable(type)).data.items

await Promise.all(closableItems.filter(issue => !issue.locked).map(issue => {
this.close(type, issue)
}))
await Promise.all(
closableItems
.filter(issue => !issue.locked && issue.state !== 'closed')
.map(issue => this.close(type, issue))
)
} else {
this.logger.trace({ owner, repo }, 'Configured to leave stale issues open')
}
Expand Down
36 changes: 23 additions & 13 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 84 additions & 0 deletions test/stale.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,26 @@ describe('stale', () => {
)

describe('mark', () => {
test(
'should not mark issue if it is already closed',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.getStale = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
items: [
{ number: 1, state: 'closed' }
]
}
})
})
stale.markIssue = jest.fn()

await stale.mark('issues')
expect(stale.markIssue).not.toHaveBeenCalled()
}
)

test(
'should not mark issue if it is locked',
async () => {
Expand All @@ -216,9 +236,51 @@ describe('stale', () => {
expect(stale.markIssue).not.toHaveBeenCalled()
}
)

test(
'should mark issue if it is open',
async () => {
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.getStale = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
items: [
{ number: 1, state: 'open' }
]
}
})
})
stale.markIssue = jest.fn()

await stale.mark('issues')
expect(stale.markIssue).toHaveBeenCalled()
}
)
})

describe('sweep', () => {
test(
'should not close issue if it is already closed',
async () => {
const staleLabel = 'stale'
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = 1
stale.getClosable = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
items: [
{ number: 1, labels: [{ name: staleLabel }], state: 'closed' }
]
}
})
})
stale.close = jest.fn()

await stale.sweep('issues')
expect(stale.close).not.toHaveBeenCalled()
}
)

test(
'should not close issue if it is locked',
async () => {
Expand All @@ -240,5 +302,27 @@ describe('stale', () => {
expect(stale.close).not.toHaveBeenCalled()
}
)

test(
'should close issue if it is open',
async () => {
const staleLabel = 'stale'
let stale = new Stale(github, { perform: true, owner: 'probot', repo: 'stale', logger: app.log })
stale.config.daysUntilClose = 1
stale.getClosable = jest.fn().mockImplementation(() => {
return Promise.resolve({
data: {
items: [
{ number: 1, labels: [{ name: staleLabel }], state: 'open' }
]
}
})
})
stale.close = jest.fn()

await stale.sweep('issues')
expect(stale.close).toHaveBeenCalled()
}
)
})
})

0 comments on commit dfd6b5f

Please sign in to comment.