Skip to content

Commit

Permalink
needs label was not added if author_association is not whitelisted (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored Feb 23, 2021
1 parent d7411dd commit ef32aea
Show file tree
Hide file tree
Showing 9 changed files with 68 additions and 15 deletions.
4 changes: 4 additions & 0 deletions __tests__/config.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,10 @@ describe('valid config', () => {
return expectValid('version.yml')
})

it('label-triage.yml is valid', () => {
return expectValid('label-triage.yml')
})

describe('captures', () => {
it('captures-all.yml is valid', () => {
return expectValid('captures-all.yml')
Expand Down
22 changes: 22 additions & 0 deletions __tests__/fixtures/config-valid/label-triage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
version: v1

issue:
labels:
- prefix: triage
list: [ "accepted" ]
multiple: false
author_association:
collaborator: true
member: true
owner: true
needs:
comment: |
@$AUTHOR: Thanks for opening an issue, it is currently awaiting triage.
The triage/accepted label can be added by foundation members by writing `/triage accepted` in a comment.
In the meantime, you can:
1. Checkout [DeFiChain’s Github issue page](https://github.com/DeFiCh/app/issues) to see if your issue has already been reported
2. Checkout [how to an submit issue for DeFi app](https://github.com/DeFiCh/app/wiki/How-to-submit-issues-for-DeFi-app)
3. Submit any logs if you have them, this will greatly expedite the process for us.
1 change: 0 additions & 1 deletion __tests__/ignore.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import ignore, {isCreatedOpened} from '../src/ignore'
import * as github from '@actions/github'
import nock from 'nock'
import fs from 'fs'
import * as core from '@actions/core'

function set(
Expand Down
2 changes: 1 addition & 1 deletion __tests__/operations/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ describe('all', () => {
}
]
}, getCommands(['/close', '/prefix a', '/another a']))
await expect(intercepted).toHaveBeenCalledTimes(5)
await expect(intercepted).toHaveBeenCalledTimes(6)
});
})

Expand Down
34 changes: 30 additions & 4 deletions __tests__/operations/label.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,6 @@ describe('labels', () => {
await expect(deleteLabels).not.toHaveBeenCalled()
});


it('should have removed labels with command', async function () {
github.context.eventName = 'issues'
github.context.payload = {
Expand Down Expand Up @@ -920,7 +919,7 @@ describe('status', () => {
});
})

describe('flaky test', () => {
describe('scenario', () => {
it('should have needs/kind removed when /kind fix is commented', async () => {
github.context.eventName = 'issue_comment'
github.context.payload = {
Expand Down Expand Up @@ -949,7 +948,7 @@ describe('flaky test', () => {
await expect(postComments).not.toHaveBeenCalled()
});

it('needs/kind', async () => {
it('needs/kind should not be called', async () => {
github.context.eventName = 'issue_comment'
github.context.payload = {
action: 'created',
Expand All @@ -976,7 +975,7 @@ describe('flaky test', () => {
await expect(deleteLabels).not.toHaveBeenCalled()
});

it('should have removed labels with command', async function () {
it('should have removed labels with command', async () => {
github.context.eventName = 'issues'
github.context.payload = {
action: 'opened',
Expand Down Expand Up @@ -1007,4 +1006,31 @@ describe('flaky test', () => {
await expect(postLabels).toHaveBeenCalledTimes(2)
await expect(deleteLabels).not.toHaveBeenCalled()
});

it('should have needs/triage added when sender is not whitelisted', async () => {
github.context.eventName = 'issue'
github.context.payload = {
action: 'opened',
issue: {
number: 1,
author_association: 'NONE'
}
}

await label({
prefix: 'triage',
multiple: false,
list: ["accepted"],
needs: {
comment: 'TEST'
},
author_association: {
contributor: true
}
}, getCommands())

await expect(postLabels).toHaveBeenCalledWith({labels: ['needs/triage']})
await expect(deleteLabels).not.toHaveBeenCalled()
await expect(postComments).toHaveBeenCalled()
});
})
8 changes: 4 additions & 4 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.

4 changes: 1 addition & 3 deletions src/operations/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@ async function processLabels(
commands: Commands
): Promise<void> {
for (const labelOp of labels) {
if (isAuthorAssociationAllowed(labelOp.author_association)) {
await label(labelOp, commands)
}
await label(labelOp, commands)
}
}

Expand Down
6 changes: 5 additions & 1 deletion src/operations/label.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
} from '../github'
import * as github from '@actions/github'
import {isCreatedOpened} from '../ignore'
import {isAuthorAssociationAllowed} from '../author-association'

class PrefixLabelSet {
public prefix: string
Expand Down Expand Up @@ -141,7 +142,10 @@ export default async function (
}
}

if (isCreatedOpened()) {
if (
isCreatedOpened() &&
isAuthorAssociationAllowed(label.author_association)
) {
computeLabels()
}

Expand Down

0 comments on commit ef32aea

Please sign in to comment.