Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
salmanm committed Nov 11, 2020
0 parents commit 69db3d8
Show file tree
Hide file tree
Showing 370 changed files with 88,825 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vscode
31 changes: 31 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Github Action Merge Dependabot

This action automatically merges dependabot PRs.

## Inputs

### `GITHUB_TOKEN`

**Required** A github token.

## Example usage

```yml
name: CI
on: [push, pull_request]

jobs:
build:
runs-on: ubuntu-latest
steps:
...

automerge:
needs: build
runs-on: ubuntu-latest
steps:
- uses: salmanm/github-action-merge-dependabot@v1
if: ${{ github.actor == 'dependabot[bot]' && github.event_name == 'pull_request' }}
with:
github-token: ${{secrets.github_token}}
```
9 changes: 9 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name: "Github Action Merge Dependabot"
description: "Automatically merge dependabot PRs"
inputs:
GITHUB_TOKEN:
description: "A GitHub token."
required: true
runs:
using: "node12"
main: "index.js"
45 changes: 45 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
const core = require('@actions/core')
const github = require('@actions/github')

const GITHUB_TOKEN = core.getInput('github-token', { required: true })

const getMergeMethod = (repo) => {
if (repo.allow_merge_commit) return 'merge'
if (repo.allow_squash_merge) return 'squash'
return 'rebase'
}

async function run () {
try {
const octokit = github.getOctokit(GITHUB_TOKEN)

const { repository, pull_request: pr } = github.context.payload
const owner = repository.owner.login
const repo = repository.name
const prNumber = pr.number

const isDependabotPR = pr.user.login === 'dependabot[bot]'

if (!isDependabotPR) {
return console.log('Unable to merge')
}

await octokit.pulls.createReview({
owner,
repo,
pull_number: prNumber,
event: 'APPROVE'
})

await octokit.pulls.merge({
owner,
repo,
pull_number: prNumber,
merge_method: getMergeMethod(pr.head.repo)
})
} catch (error) {
core.setFailed(error.message)
}
}

run()
9 changes: 9 additions & 0 deletions node_modules/@actions/core/LICENSE.md

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

147 changes: 147 additions & 0 deletions node_modules/@actions/core/README.md

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

16 changes: 16 additions & 0 deletions node_modules/@actions/core/lib/command.d.ts

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

79 changes: 79 additions & 0 deletions node_modules/@actions/core/lib/command.js

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

1 change: 1 addition & 0 deletions node_modules/@actions/core/lib/command.js.map

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

Loading

0 comments on commit 69db3d8

Please sign in to comment.