Skip to content

Commit

Permalink
will not ignore bot for pr and issue as dependabot opens them (#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
fuxingloh authored Mar 8, 2021
1 parent 58be8a5 commit 06ed76b
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 37 deletions.
11 changes: 7 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<img src="icon.png" width="120" height="120" align="left" style="margin-right:32px"/>
<img src="icon.png" width="120" height="120" align="right" style="margin-left:32px"/>

# OSS Governance Bot

Expand All @@ -9,9 +9,8 @@

<!-- 3 Arc: Context - Problem - Solution -->

[DeFiChain](https://defichain.com/) - Decentralized finance enabled on
Bitcoin. [A blockchain dedicated to fast, intelligent and transparent financial services, accessible by everyone.](https://defichain.com/white-paper/)
To achieve that, our projects have to be open source and accessible by anyone.
To building a decentralized finance at [DeFiChain](https://defichain.com/),
[we created a blockchain dedicated to fast, intelligent and transparent financial services, accessible by everyone.](https://defichain.com/white-paper/)

Although putting our project on GitHub makes it transparent and visible for public contributions, it's far from making
it maintainable. For new contributors, creating an issue or pull request and successfully sending it is a mountainous
Expand All @@ -35,6 +34,7 @@ contributors can trigger chat-ops via /slash style commands.
* Scale to thousands of contributors without alienating community participation with complex quality control hierarchy.
* A GitHub Action that lives natively and integrate well with the GitHub action/workflow product offering. You can view
the source directly and modify it to your needs.
* See it in action at [DeFiCh/app](https://github.com/DeFiCh/app/issues) or [DeFiCh/ain](https://github.com/DeFiCh/ain/pulls).

![preview](preview.png)

Expand Down Expand Up @@ -376,8 +376,11 @@ npm run all # to build/check/lint/package

* For any question please feel free to create an issue.
* Pull request for non-breaking features are welcomed too!
* Although all features were created specifically for DeFiChain foundation needs; you should not limit yourself to our
offering. Feel free to fork the project. Appreciate if you mention us!

## Prior art

* [Open Source Governance Models](https://gist.github.com/calebamiles/c578f88403b2fcb203deb5c9ef941d98)
* [Kubernetes Prow](https://github.com/kubernetes/test-infra)
* [jpmcb/prow-github-actions](https://github.com/jpmcb/prow-github-actions)
12 changes: 6 additions & 6 deletions __tests__/ignore.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ describe('pull_request', () => {
await expectIgnore(false)
})

it('should ignore opened if Bot', async () => {
it('should not ignore opened if Bot', async () => {
set('pull_request', 'opened', 'Bot')
await expectIgnore(true)
await expectIgnore(false)
})

it('should ignore locked', async () => {
Expand Down Expand Up @@ -253,9 +253,9 @@ describe('pull_request_target', () => {
await expectIgnore(false)
})

it('should ignore opened if Bot', async () => {
it('should not ignore opened if Bot', async () => {
set('pull_request_target', 'opened', 'Bot')
await expectIgnore(true)
await expectIgnore(false)
})

it('should ignore locked', async () => {
Expand Down Expand Up @@ -367,9 +367,9 @@ describe('issues', () => {
await expectIgnore(false)
})

it('should ignore opened if Bot', async () => {
it('should not ignore opened if Bot', async () => {
set('issues', 'opened', 'Bot')
await expectIgnore(true)
await expectIgnore(false)
})

it('should ignore assigned', async () => {
Expand Down
25 changes: 13 additions & 12 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.

26 changes: 12 additions & 14 deletions src/ignore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,19 @@ function ignoreLabeledRaceCondition(): boolean {

/**
* Ignore non 'User' to prevent infinite loop.
* Also ignores if sender is bot-token user
*/
async function ignoreBot(): Promise<boolean> {
function ignoreBot(): boolean {
const payload = github.context.payload
return payload.sender?.type !== 'User'
}

if (payload.sender?.type !== 'User') {
return true
}

// allow fail because 'github-token' resource not accessible by integration
if (payload.sender?.id === (await getBotUserId().catch(() => ''))) {
return true
}

return false
/**
* Ignores if sender is bot-token user
*/
async function ignoreSelf(): Promise<boolean> {
const payload = github.context.payload
// allow fail because with 'github-token' > 'resource not accessible by integration'
return payload.sender?.id === (await getBotUserId().catch(() => ''))
}

/**
Expand Down Expand Up @@ -86,12 +84,12 @@ export default async function (): Promise<boolean> {
return true
}

if (await ignoreBot()) {
if (await ignoreSelf()) {
return true
}

if (is('issue_comment', ['created'])) {
return false
return ignoreBot()
}

if (is('pull_request', ['synchronize', 'opened', 'labeled', 'unlabeled'])) {
Expand Down

0 comments on commit 06ed76b

Please sign in to comment.