Skip to content

Commit

Permalink
Fix cla 504 (#51)
Browse files Browse the repository at this point in the history
* fix: replace gh api from pulls to search to avoid rate limits

* test: add some working integration and pending e2e tests

* fix: error handling in case of missing referr

* feat: improve ux in case of failure

* fix: installation auth issues to support org wide label removal
  • Loading branch information
gitcommitshow authored Sep 27, 2024
1 parent bb07086 commit 9c017bc
Show file tree
Hide file tree
Showing 12 changed files with 1,632 additions and 428 deletions.
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@ A Node.js server for GitHub app to assist external contributors and save maintai
## Roadmap

- [x] When an external contributor (not the internal team) raises a PR, post a comment to sign CLA and label PR `Pending CLA`
- [x] On signing CLA, remove `Pending CLA` label and never ask that user to sign the CLA again on any of our repo in future
- [x] On signing CLA, remove `Pending CLA` label from all the PRs of that user. Never ask that user to sign the CLA on any of our repo in future
- [x] On `rudder-transformer` PR merge, post a comment to raise PR in `integrations-config`
- [ ] On `integrations-config` PR merge, psot a comment to join Slack's product-releases channel to get notified when that integration goes live
- [ ] On `integrations-config` PR merge, post a comment to raise PR in `rudder-docs`

## Requirements

Expand Down Expand Up @@ -60,4 +61,9 @@ by major cloud providers:
[Azure Key Vault](https://learn.microsoft.com/en-us/azure/key-vault/secrets/quick-create-node?tabs=windows),
[AWS Secrets Manager](https://docs.aws.amazon.com/AWSJavaScriptSDK/v3/latest/clients/client-secrets-manager/),
[Google Secret Manager](https://cloud.google.com/nodejs/docs/reference/secret-manager/latest),
etc.
etc.

## References

- [Docs - octokit.rest.* methods](https://github.com/octokit/plugin-rest-endpoint-methods.js/tree/main/docs)
- [Docs - GitHub API](https://docs.github.com/en/rest)
11 changes: 8 additions & 3 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { Octokit, App } from "octokit";
import { createNodeMiddleware } from "@octokit/webhooks";
import { routes } from "./src/routes.js";
import {
verifyGitHubAppAuthenticationAndAccess,
getMessage,
isCLARequired,
isMessageAfterMergeRequired,
Expand Down Expand Up @@ -57,6 +58,7 @@ const app = new App({
}),
}),
});
await verifyGitHubAppAuthenticationAndAccess(app);

// Optional: Get & log the authenticated app's name
const { data } = await app.octokit.request("/app");
Expand Down Expand Up @@ -108,6 +110,7 @@ app.webhooks.on("pull_request.labeled", async ({ octokit, payload }) => {
repo: repository.name,
pr_number: pull_request.number,
});
// Docs for octokit.rest.issues.createComment - https://github.com/octokit/plugin-rest-endpoint-methods.js/blob/main/docs/issues/createComment.md
await octokit.rest.issues.createComment({
owner: repository.owner.login,
repo: repository.name,
Expand Down Expand Up @@ -143,6 +146,7 @@ app.webhooks.on("pull_request.closed", async ({ octokit, payload }) => {
repo: payload.repository.name,
pr_number: payload.pull_request.number,
});
// Docs for octokit.rest.issues.createComment - https://github.com/octokit/plugin-rest-endpoint-methods.js/blob/main/docs/issues/createComment.md
await octokit.rest.issues.createComment({
owner: payload.repository.owner,
repo: payload.repository.name,
Expand All @@ -163,6 +167,7 @@ app.webhooks.on("pull_request.closed", async ({ octokit, payload }) => {
app.webhooks.on("issues.opened", async ({ octokit, payload }) => {
console.log(`Received a new issue event for #${payload.issue.number}`);
try {
// Docs for octokit.rest.issues.createComment - https://github.com/octokit/plugin-rest-endpoint-methods.js/tree/main/docs/issues/createComment.md
await octokit.rest.issues.createComment({
owner: payload.repository.owner.login,
repo: payload.repository.name,
Expand Down Expand Up @@ -199,11 +204,11 @@ app.webhooks.onError((error) => {

// Launch a web server to listen for GitHub webhooks
const port = process.env.PORT || 3000;
const path = "/api/webhook";
const localWebhookUrl = `http://localhost:${port}${path}`;
const webhookPath = "/api/webhook";
const localWebhookUrl = `http://localhost:${port}${webhookPath}`;

// See https://github.com/octokit/webhooks.js/#createnodemiddleware for all options
const middleware = createNodeMiddleware(app.webhooks, { path });
const middleware = createNodeMiddleware(app.webhooks, { path: webhookPath });

http
.createServer((req, res) => {
Expand Down
Loading

0 comments on commit 9c017bc

Please sign in to comment.