Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@ A GitHub App built with [Probot](https://github.com/probot/probot) for approving

![image](https://user-images.githubusercontent.com/4306809/50573484-13a0a100-0dd5-11e9-8ef3-aad5069e83e3.png)

## Setup
## Setup (for contributors)
These are instructions for contributing code to the bot. If you just want to run the bot, skip to
the Configure section below.

```sh
# Install dependencies
Expand Down Expand Up @@ -61,7 +63,9 @@ jobs:

## Configuration

In order to use the bot, the config file should be provided. Config file should be defined in your repository. Config file is the yml file with the path `.github/autoapproval.yml`. The file should have at least 3 mandatory entries: `from_owner`, `required_labels` and `apply_labels`.
In order to use the bot, the config file should be provided. Config file should be defined in your
repository. Config file is the yml file with the path `.github/autoapproval.yml`. The file should
have at least 3 mandatory entries: `from_owner`, `required_labels`, `apply_labels`, and `blacklisted_labels`.

---

Expand Down Expand Up @@ -98,7 +102,7 @@ If the value set to `one_of`, then it's enough to have only of the `required_lab
---

### blacklisted_labels

**mandatory**
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do you make blacklisted_labels as a mandatory property?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dkhmelenko : please correct me if I'm wrong, but I ran into #753 (i.e. my GitHub Action fails if my autoapprove.yml doesn't have the blacklisted_labels field, and succeeds if it does [with an empty array]).

Defines the list of labels on PR, which will prevent the PR from being automatically approved. For example:
```
blacklisted_labels:
Expand Down
9 changes: 5 additions & 4 deletions lib/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 lib/index.js.map

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

10 changes: 0 additions & 10 deletions package-lock.json

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

9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Probot, Context } from 'probot'
import { PullRequestEvent, PullRequestReviewEvent } from '@octokit/webhooks-types'
import { Context, Probot } from 'probot'

module.exports = (app: Probot) => {
app.on(['pull_request.opened', 'pull_request.reopened', 'pull_request.labeled', 'pull_request.edited', 'pull_request_review'], async (context) => {
Expand Down Expand Up @@ -39,8 +39,9 @@ module.exports = (app: Probot) => {
}
}

// reading pull request owner info and check it with configuration
const ownerSatisfied = config.from_owner.length === 0 || config.from_owner.includes(pr.user.login)
// reading pull request owner info and check it with configuration (case insensitive)
const lowerLogin = pr.user.login.toLowerCase()
const ownerSatisfied = config.from_owner.length === 0 || config.from_owner.some((owner: string) => owner.toLowerCase() === lowerLogin)
Comment on lines +43 to +44
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's an interesting case, out of curiosity: when can it happen that we have different cases of the owner? Or do you want to prevent a situation when GitHub username has different case than the one in the config file?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm trying to address the situation where the yml file contains a different case from what GitHub has. Since GitHub handles are case-insensitive, it feels like the yml format should similarly not enforce casing.


// reading pull request labels and check them with configuration
let requiredLabelsSatisfied
Expand Down Expand Up @@ -75,7 +76,7 @@ module.exports = (app: Probot) => {
}
} else {
// one of the checks failed
context.log('Condition failed! \n - missing required labels: %s\n - PR owner found: %s', requiredLabelsSatisfied, ownerSatisfied)
context.log('Condition failed! \n - has required labels: %s\n - PR owner found: %s', requiredLabelsSatisfied, ownerSatisfied)
}
})
}
Expand Down
26 changes: 26 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,32 @@ describe('Autoapproval bot', () => {
expect(nock.isDone()).toBeTruthy()
})

test('PR has expected mixed-case owner -> will be approved', async () => {
const payload = require('./fixtures/pull_request.opened.json')
const config = 'from_owner:\n - dKHMelenko\nrequired_labels:\n - merge\nblacklisted_labels: []\napply_labels: []'
const reviews = require('./fixtures/pull_request_reviews_empty.json')

nock('https://api.github.com')
.get('/repos/dkhmelenko/autoapproval/contents/.github%2Fautoapproval.yml')
.reply(200, config)

nock('https://api.github.com')
.get('/repos/dkhmelenko/autoapproval/pulls/1/reviews')
.reply(200, reviews)

nock('https://api.github.com')
.post('/repos/dkhmelenko/autoapproval/pulls/1/reviews', (body: any) => {
return body.event === 'APPROVE'
})
.reply(200)

// Receive a webhook event
await probot.receive({ name: 'pull_request', payload })

await new Promise(process.nextTick) // Don't assert until all async processing finishes
expect(nock.isDone()).toBeTruthy()
})

test('PR has multiple required labels and expected owner -> will be approved', async () => {
const payload = require('./fixtures/pull_request_opened_multiple_labels.json')
const config = 'from_owner:\n - dkhmelenko\nrequired_labels:\n - merge\n - merge2\nblacklisted_labels: []\napply_labels: []'
Expand Down