Skip to content

Commit

Permalink
feat: initial version
Browse files Browse the repository at this point in the history
  • Loading branch information
gr2m committed May 10, 2021
0 parents commit d6486cb
Show file tree
Hide file tree
Showing 12 changed files with 3,167 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Release
on:
push:
branches:
- main

jobs:
release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: 14
- run: npx semantic-release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
17 changes: 17 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Test
on:
push:
branches:
- main
pull_request:
types: [opened, synchronize]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
- run: npm ci
- run: npm test
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# local configuration
.env

# package directories
node_modules
46 changes: 46 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to making participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, gender identity and expression, level of experience, nationality, personal appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment include:

- Using welcoming and inclusive language
- Being respectful of differing viewpoints and experiences
- Gracefully accepting constructive criticism
- Focusing on what is best for the community
- Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

- The use of sexualized language or imagery and unwelcome sexual attention or advances
- Trolling, insulting/derogatory comments, and personal or political attacks
- Public or private harassment
- Publishing others' private information, such as a physical or electronic address, without explicit permission
- Other conduct which could reasonably be considered inappropriate in a professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [email protected]. The project team will review and investigate all complaints, and will respond in a way that it deems appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at [http://contributor-covenant.org/version/1/4][version]

[homepage]: http://contributor-covenant.org
[version]: http://contributor-covenant.org/version/1/4/
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2020 Probot Contributors

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Probot & Netlify Functions example

This repository is an example of how to deploy the "Hello, World" of probot apps to [Netlify Functions](https://www.netlify.com/products/functions/).

## Local setup

Install dependencies

```
npm install
```

Start the server

```
npm start
```

Follow the instructions to register a new GitHub app.

## Run the netlify function locally

You need to run `npm start` at least once in order to register a new GitHub App for your local testing. It will create a `.env` file with your app's credentials once it's done.

Install the [Netlify Dev CLI](https://www.netlify.com/products/dev/)

```
npm install --global netlify-cli
```

Then start it the root folder of this repository

```
netlify dev
```

In a new terminal app, start [`smee-client`](https://github.com/probot/smee-client/#readme) in order to receive webhook event requests from GitHub

```
npx smee --url [WEBHOOK_PROXY_URL] --target http://127.0.0.1:8888/.netlify/functions/webhooks
```

Replace `WEBHOOK_PROXY_URL` with the value of `WEBHOOK_PROXY_URL` in your `.env` file.

## Deployment

_tbd_

## License

[ISC](LICENSE)
12 changes: 12 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/**
* @param {import('probot').Probot} app
*/
module.exports = (app) => {
app.log("Yay! The app was loaded!");

app.on("issues.opened", async (context) => {
return context.octokit.issues.createComment(
context.issue({ body: "Hello, World!" })
);
});
};
6 changes: 6 additions & 0 deletions app.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
default_events:
- issues

default_permissions:
issues: write
metadata: read
42 changes: 42 additions & 0 deletions netlify/functions/webhooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
const { createProbot } = require("probot");
const app = require("../../app");

const probot = createProbot();
const loadingApp = probot.load(app);

/**
* Netlify function to handle webhook event requests from GitHub
*
* @param {import("@netlify/functions").HandlerEvent} event
* @param {import("@netlify/functions").HandlerContext} context
*/
exports.handler = async function (event, context) {
try {
await loadingApp;

// this could will be simpler once we ship `verifyAndParse()`
// see https://github.com/octokit/webhooks.js/issues/379
await probot.webhooks.verifyAndReceive({
id:
event.headers["X-GitHub-Delivery"] ||
event.headers["x-github-delivery"],
name: event.headers["X-GitHub-Event"] || event.headers["x-github-event"],
signature:
event.headers["X-Hub-Signature-256"] ||
event.headers["x-hub-signature-256"],
payload: JSON.parse(event.body),
});

return {
statusCode: 200,
body: '{"ok":true}',
};
} catch (error) {
app.log.error(error);

return {
statusCode: error.status || 500,
error: "ooops",
};
}
};
Loading

0 comments on commit d6486cb

Please sign in to comment.