Skip to content

Commit

Permalink
feat: Support for GitHub Actions (#36)
Browse files Browse the repository at this point in the history
* Create .dockerignore

* Create Dockerfile

* Create entrypoint.sh

* Updated permissions entrypoint

* Create action.js

* Update action.js

* Update entrypoint.sh

* Update action.js

* Update action.js

* Added octokit to action

* Update package.json

* Added err variable

* Update Dockerfile

* Update README.md
  • Loading branch information
SvanBoxel authored Nov 6, 2018
1 parent b180209 commit 45e477a
Show file tree
Hide file tree
Showing 7 changed files with 72 additions and 1 deletion.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
16 changes: 16 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM node:10.11.0-alpine

LABEL "com.github.actions.name"="Delete merged branch"
LABEL "com.github.actions.description"="No more manually deleting merged branches, this lovely app does it for you."
LABEL "com.github.actions.icon"="archive"
LABEL "com.github.actions.color"="red"

LABEL "repository"="https://github.com/SvanBoxel/delete-merged-branch"
LABEL "homepage"="https://github.com/SvanBoxel"
LABEL "maintainer"="[email protected]"

COPY ./lib /delete-merged-branch-action
COPY ./package.json /delete-merged-branch-action/package.json
COPY ./entrypoint.sh /delete-merged-branch-action/entrypoint.sh

ENTRYPOINT ["/delete-merged-branch-action/entrypoint.sh"]
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
[![Build Status](https://travis-ci.com/SvanBoxel/delete-merged-branch.svg?token=BrByTtLgfVKqDJ6GzD2p&branch=master)](https://travis-ci.com/SvanBoxel/delete-merged-branch)
_Want to see more badges? [Click here](#badges)!_


_Want to run this app with [GitHub Actions](https://github.com/features/actions)? [Click here](#running-in-github-actions)_

A GitHub app built with [Probot](https://github.com/probot/probot) that automatically deletes a branch after it's merged. That's it, enjoy!

## Running it locally
Expand Down Expand Up @@ -33,6 +36,11 @@ This GitHub app listens to the `pull_request.closed` webhook. If a pull request
## Release process
CI (Travis) is in charge of releasing new versions of the GitHub Application to [Now](https://zeit.co/now). On every new commit to master we run [semantic-release](https://github.com/semantic-release/semantic-release) to determine whether the major/minor/patch version should be incremented. If so, we update the version running in production.

## Running in GitHub actions
This app is compatible with [GitHub Actions](https://github.com/features/actions). You need to create a workflow that is triggered on the `pull_request` event for this. Then, you use this repo for the action. (`SvanBoxel/delete-merged-branch@master`). Don't forget to check the `GITHUB_TOKEN` secret. That's it.

![Delete merged branch action](https://user-images.githubusercontent.com/24505883/48064765-14e49180-e1c9-11e8-9fa5-151bf5783b5c.png)

## Contributing

If you have suggestions for how this GitHub app could be improved, or want to report a bug, open an issue! We'd love all and any contributions.
Expand Down
4 changes: 4 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/bin/sh -l

npm --prefix /delete-merged-branch-action install /delete-merged-branch-action
node /delete-merged-branch-action/action.js
27 changes: 27 additions & 0 deletions lib/action.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
const fs = require('fs');
const octokit = require('@octokit/rest')()
const deleteMergedBranch = require('./delete-merged-branch');

fs.readFile('/github/workflow/event.json', 'utf8', function(err, contents) {
if (err) {
throw err;
}

const payload = JSON.parse(contents);
const context = {
payload: payload,
log: console,
github: octokit
}

if (payload.action === 'closed') {
octokit.authenticate({
type: 'token',
token: process.env.GITHUB_TOKEN
})

return deleteMergedBranch(context)
}
console.log('no closed event')
});

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"semantic-release": "semantic-release"
},
"dependencies": {
"probot": "7.3.0"
"probot": "7.3.0",
"@octokit/rest": "15.16.1"
},
"devDependencies": {
"codecov": "3.1.0",
Expand Down
14 changes: 14 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,20 @@
version "1.1.0"
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"

"@octokit/[email protected]":
version "15.16.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-15.16.1.tgz#399b06660fe16852cf432059c845d4cdcaf77f5a"
dependencies:
before-after-hook "^1.1.0"
btoa-lite "^1.0.0"
debug "^3.1.0"
http-proxy-agent "^2.1.0"
https-proxy-agent "^2.2.0"
lodash "^4.17.4"
node-fetch "^2.1.1"
universal-user-agent "^2.0.0"
url-template "^2.0.8"

"@octokit/rest@^15.13.1":
version "15.13.1"
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-15.13.1.tgz#68b12ff0e470ad70c90e99bbb69f16bcdf62edb4"
Expand Down

0 comments on commit 45e477a

Please sign in to comment.