Skip to content

Commit 45e477a

Browse files
authored
feat: Support for GitHub Actions (#36)
* 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
1 parent b180209 commit 45e477a

File tree

7 files changed

+72
-1
lines changed

7 files changed

+72
-1
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
node_modules

Dockerfile

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
FROM node:10.11.0-alpine
2+
3+
LABEL "com.github.actions.name"="Delete merged branch"
4+
LABEL "com.github.actions.description"="No more manually deleting merged branches, this lovely app does it for you."
5+
LABEL "com.github.actions.icon"="archive"
6+
LABEL "com.github.actions.color"="red"
7+
8+
LABEL "repository"="https://github.com/SvanBoxel/delete-merged-branch"
9+
LABEL "homepage"="https://github.com/SvanBoxel"
10+
LABEL "maintainer"="[email protected]"
11+
12+
COPY ./lib /delete-merged-branch-action
13+
COPY ./package.json /delete-merged-branch-action/package.json
14+
COPY ./entrypoint.sh /delete-merged-branch-action/entrypoint.sh
15+
16+
ENTRYPOINT ["/delete-merged-branch-action/entrypoint.sh"]

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
[![Build Status](https://travis-ci.com/SvanBoxel/delete-merged-branch.svg?token=BrByTtLgfVKqDJ6GzD2p&branch=master)](https://travis-ci.com/SvanBoxel/delete-merged-branch)
33
_Want to see more badges? [Click here](#badges)!_
44

5+
6+
_Want to run this app with [GitHub Actions](https://github.com/features/actions)? [Click here](#running-in-github-actions)_
7+
58
A GitHub app built with [Probot](https://github.com/probot/probot) that automatically deletes a branch after it's merged. That's it, enjoy!
69

710
## Running it locally
@@ -33,6 +36,11 @@ This GitHub app listens to the `pull_request.closed` webhook. If a pull request
3336
## Release process
3437
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.
3538

39+
## Running in GitHub actions
40+
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.
41+
42+
![Delete merged branch action](https://user-images.githubusercontent.com/24505883/48064765-14e49180-e1c9-11e8-9fa5-151bf5783b5c.png)
43+
3644
## Contributing
3745

3846
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.

entrypoint.sh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh -l
2+
3+
npm --prefix /delete-merged-branch-action install /delete-merged-branch-action
4+
node /delete-merged-branch-action/action.js

lib/action.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
const fs = require('fs');
2+
const octokit = require('@octokit/rest')()
3+
const deleteMergedBranch = require('./delete-merged-branch');
4+
5+
fs.readFile('/github/workflow/event.json', 'utf8', function(err, contents) {
6+
if (err) {
7+
throw err;
8+
}
9+
10+
const payload = JSON.parse(contents);
11+
const context = {
12+
payload: payload,
13+
log: console,
14+
github: octokit
15+
}
16+
17+
if (payload.action === 'closed') {
18+
octokit.authenticate({
19+
type: 'token',
20+
token: process.env.GITHUB_TOKEN
21+
})
22+
23+
return deleteMergedBranch(context)
24+
}
25+
console.log('no closed event')
26+
});
27+

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@
2626
"semantic-release": "semantic-release"
2727
},
2828
"dependencies": {
29-
"probot": "7.3.0"
29+
"probot": "7.3.0",
30+
"@octokit/rest": "15.16.1"
3031
},
3132
"devDependencies": {
3233
"codecov": "3.1.0",

yarn.lock

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,20 @@
2727
version "1.1.0"
2828
resolved "https://registry.yarnpkg.com/@nodelib/fs.stat/-/fs.stat-1.1.0.tgz#50c1e2260ac0ed9439a181de3725a0168d59c48a"
2929

30+
"@octokit/[email protected]":
31+
version "15.16.1"
32+
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-15.16.1.tgz#399b06660fe16852cf432059c845d4cdcaf77f5a"
33+
dependencies:
34+
before-after-hook "^1.1.0"
35+
btoa-lite "^1.0.0"
36+
debug "^3.1.0"
37+
http-proxy-agent "^2.1.0"
38+
https-proxy-agent "^2.2.0"
39+
lodash "^4.17.4"
40+
node-fetch "^2.1.1"
41+
universal-user-agent "^2.0.0"
42+
url-template "^2.0.8"
43+
3044
"@octokit/rest@^15.13.1":
3145
version "15.13.1"
3246
resolved "https://registry.yarnpkg.com/@octokit/rest/-/rest-15.13.1.tgz#68b12ff0e470ad70c90e99bbb69f16bcdf62edb4"

0 commit comments

Comments
 (0)