Skip to content

Commit

Permalink
closed issue or pr will not run chat-ops anymore (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored Feb 23, 2021
1 parent 84908ac commit 58be8a5
Show file tree
Hide file tree
Showing 7 changed files with 64 additions and 36 deletions.
14 changes: 0 additions & 14 deletions .github/governance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,6 @@ issue:
multiple: false
needs: true

- prefix: area
list: [ "security", "documentation", "chat-ops", "labels", "captures", "permission" ]
multiple: true
needs:
comment: |
@$AUTHOR: There are no area labels on this issue. Adding an appropriate label will greatly expedite the process for us. You can add as many area as you see fit. **If you are unsure what to do you can ignore this!**
* `/area labels`
* `/area chat-ops`
* `/area documentation`
* `/area security`
* `/area captures`
* `/area permission`
chat_ops:
- cmd: /close
type: close
Expand Down
17 changes: 0 additions & 17 deletions .github/labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
- color: cc40d8
name: needs/kind
description: Needs kind label
- color: cc40d8
name: needs/area
description: Needs area label(s)
- color: cc40d8
name: needs/priority
description: Needs a priority label
Expand Down Expand Up @@ -46,20 +43,6 @@
name: kind/dependencies
description: Pull requests that update a dependency file

# Area
- color: fbca04
name: area/security
- color: fbca04
name: area/documentation
- color: fbca04
name: area/chat-ops
- color: fbca04
name: area/labels
- color: fbca04
name: area/captures
- color: fbca04
name: area/permission

# Priority
- color: d93f0b
name: priority/urgent-now
Expand Down
20 changes: 20 additions & 0 deletions __tests__/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,26 @@ describe('issue_comment', () => {
set('issue_comment', 'deleted', 'User')
await expectIgnore(true)
})

it('should ignore created but closed', async () => {
set('issue_comment', 'created', 'User', {
pull_request: {
number: 1,
state: 'closed'
}
})
await expectIgnore(true)
})

it('should ignore created but closed', async () => {
set('issue_comment', 'created', 'User', {
issue: {
number: 1,
state: 'closed'
}
})
await expectIgnore(true)
})
})

describe('pull_request', () => {
Expand Down
10 changes: 6 additions & 4 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,14 +103,15 @@ describe('getGovernance', () => {
jest.setTimeout(10000)
github.context.payload = {
issue: {
number: 1
number: 1,
state: 'open'
}
}

const {getGovernance} = require('../src/main')
const governance = await getGovernance()

expect(governance?.labels?.length).toBe(3)
expect(governance?.labels?.length).toBe(2)
})

it('should be pull request', async function () {
Expand All @@ -134,14 +135,15 @@ describe('getGovernance', () => {
id: 1
},
issue: {
number: 1
number: 1,
state: 'open'
}
}

const {getGovernance} = require('../src/main')
const governance = await getGovernance()

expect(governance?.labels?.length).toBe(3)
expect(governance?.labels?.length).toBe(2)
})

it('should be pull request', async function () {
Expand Down
17 changes: 17 additions & 0 deletions dist/index.js

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

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

20 changes: 20 additions & 0 deletions src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ async function ignoreBot(): Promise<boolean> {
return false
}

/**
* Closed issue and pull_request should not trigger governance
*/
function ignoreClosed(): boolean {
const payload = github.context.payload
if (payload?.pull_request?.state === 'closed') {
return true
}

if (payload?.issue?.state === 'closed') {
return true
}

return false
}

/**
* To prevent mistakes, this will ignore invalid workflow trigger
*/
Expand All @@ -66,6 +82,10 @@ export default async function (): Promise<boolean> {
return true
}

if (ignoreClosed()) {
return true
}

if (await ignoreBot()) {
return true
}
Expand Down

0 comments on commit 58be8a5

Please sign in to comment.