Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kv109 committed Feb 25, 2020
0 parents commit f86bd69
Show file tree
Hide file tree
Showing 2,407 changed files with 335,851 additions and 0 deletions.
Empty file added .gitignore
Empty file.
59 changes: 59 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
# ReadyToReview - Slack Notifier

**ReadyToReview** notifies you when a pull request is ready for review, i.e. when
- a non-draft PR is opened or
- a draft PR is ready to review.

### Setup

1. Generate your Slack webhook. You can do it [here](https://slack.com/apps/A0F7XDUAZ-incoming-webhooks).
1. Add created webhook as a secret named `SLACK_WEBHOOK` using GitHub Action's Secret. See your project Settings -> Secrets.

### Example usage

```yaml
on:
pull_request:
types: [opened, ready_for_review]
name: Notify about PR ready for review
jobs:
slackNotification:
name: Slack Notification
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Slack Notification
uses: kv109/[email protected]
env:
SLACK_CHANNEL: your-slack-channel # required
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} # required
```
```yaml
on:
pull_request:
types: [opened, ready_for_review]
name: Notify about PR ready for review
jobs:
slackNotification:
name: Slack Notification
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Slack Notification
uses: kv109/[email protected]
env:
FORMAT: | # Format is fully customizable.
My custom message format! :smile:
Title: *{ pull_request.title }*
Author: { pull_request.user.login }
URL: { pull_request.html_url }
IGNORE_DRAFTS: false # Notify also about drafts. Default: true.
SLACK_CHANNEL: your-slack-channel
SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}
USERNAME: Your username
```
## Formatting
Any string inside brackets is replaced with a value taken from an actual event payload.
All available values can be found [here](https://developer.github.com/v3/activity/events/types/#webhook-payload-example-28).
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: 'Ready to review - Slack notifier'
description: 'Notifies you when a pull request is ready for review'
runs:
using: 'node12'
main: 'index.js'
65 changes: 65 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
const Core = require('@actions/core');
const Github = require('@actions/github');
const Slack = require('node-slack');

const DefaultFormat = `:rocket: New PR ready to review! :rocket:\nTitle: *{ pull_request.title }*\nAuthor: { pull_request.user.login }\nURL: { pull_request.html_url }`;

try {
e = process.env;
config = {
channel: e.SLACK_CHANNEL,
format: e.FORMAT || DefaultFormat,
hookUrl: e.SLACK_WEBHOOK,
ignoreDrafts: e.IGNORE_DRAFTS || true,
username: e.USERNAME || 'ReadyToReviewBot'
};

if (!config.channel) {
Core.setFailed("Slack channel is not set. Set it with\nenv:\n\tSLACK_CHANNEL: your-channel");
}
if (!config.hookUrl) {
Core.setFailed("SLACK_WEBHOOK is not set. Set it with\nenv:\n\tSLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }}\n");
}

const payload = Github.context.payload;

if (payload.action !== "ready_for_review" && payload.action !== "opened") {
return
}

const pr = payload.pull_request;
const slack = new Slack(config.hookUrl);
// console.log(JSON.stringify(payload, null, 2));

if (payload.pull_request.draft && config.ignoreDrafts === true) {
return
}

let message = config.format;
config.format.match(/\{.+\}/g).forEach(template => {
const templateWithoutBrackets = template
.replace(/^\{\s?/, "")
.replace(/\s?\}$/, "");

const keys = templateWithoutBrackets.split(".")
console.log(keys)
let value = payload;
keys.forEach(key => {
try {
value = value[key];
} catch (error) {
console.log(error);
}
});
console.log(value);
message = message.replace(template, value);
});

slack.send({
text: message,
channel: '#' + config.channel,
username: config.username
});
} catch (error) {
Core.setFailed(error.message);
}
1 change: 1 addition & 0 deletions node_modules/.bin/semver

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/.bin/sshpk-conv

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/.bin/sshpk-sign

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/.bin/sshpk-verify

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/.bin/uuid

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/.bin/which

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

140 changes: 140 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.

78 changes: 78 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 f86bd69

Please sign in to comment.