Skip to content

Commit

Permalink
refactor: add classes, object_oriented code
Browse files Browse the repository at this point in the history
  • Loading branch information
Varun-Kolanu committed Jun 13, 2024
1 parent 93a0f41 commit 66d7647
Show file tree
Hide file tree
Showing 23 changed files with 451 additions and 234 deletions.
15 changes: 6 additions & 9 deletions .env.example
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
# The ID of your GitHub App
APP_ID=
WEBHOOK_SECRET=development

# Use `trace` to get verbose logging or `info` to show less
LOG_LEVEL=debug

# Go to https://smee.io/new set this to the URL that you are redirected to.
WEBHOOK_PROXY_URL=
WEBHOOK_PROXY_URL=https://smee.io/...
APP_ID=...
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\n......-----END RSA PRIVATE KEY-----\n"
WEBHOOK_SECRET=....
GITHUB_CLIENT_ID=Iv23ct....
GITHUB_CLIENT_SECRET=...
1 change: 1 addition & 0 deletions .nyc_output/a4fbe8e7-5396-48c3-a3a3-935da35eae78.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"parent":null,"pid":18812,"argv":["C:\\Program Files\\nodejs\\node.exe","D:\\Varun\\Coding\\Projects\\issue-assigner\\node_modules\\.bin\\node-test"],"execArgv":["--experimental-vm-modules","--loader","ts-node/esm"],"cwd":"D:\\Varun\\Coding\\Projects\\issue-assigner","time":1718272327655,"ppid":1792,"coverageFilename":"D:\\Varun\\Coding\\Projects\\issue-assigner\\.nyc_output\\a4fbe8e7-5396-48c3-a3a3-935da35eae78.json","externalId":"","uuid":"a4fbe8e7-5396-48c3-a3a3-935da35eae78","files":[]}
1 change: 1 addition & 0 deletions .nyc_output/processinfo/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"processes":{"a4fbe8e7-5396-48c3-a3a3-935da35eae78":{"parent":null,"children":[]}},"files":{},"externalIds":{}}
26 changes: 19 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,33 @@ Hi there! We're thrilled that you'd like to contribute to this project. Your hel

Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms.

## Prerequisites

1. Git installed
2. Node installed

## Issues and PRs

If you have suggestions for how this project could be improved, or want to report a bug, open an issue! We'd love all and any contributions. If you have questions, too, we'd love to hear them.

We'd also love PRs. If you're thinking of a large PR, we advise opening up an issue first to talk about it, though! Look at the links below if you're not sure how to open a PR.

To get an issue assigned, use the issue-assigner bot:

1. Comment `@issue-assigner claim` to get an issue assigned.
2. Comment `@issue-assigner abandon` to get an issue unassigned.

## Submitting a pull request

1. [Fork][fork] and clone the repository.
1. Configure and install the dependencies: `npm install`.
1. Make sure the tests pass on your machine: `npm test`, note: these tests also apply the linter, so there's no need to lint separately.
1. Create a new branch: `git checkout -b my-branch-name`.
1. Make your change, add tests, and make sure the tests still pass.
1. Push to your fork and [submit a pull request][pr].
1. Pat your self on the back and wait for your pull request to be reviewed and merged.
1. Fork and clone the repository.
2. Configure and install the dependencies: `npm install`.
3. Make sure the tests pass on your machine: `npm test`.
4. Create a new branch: `git checkout -b my-branch-name`.
5. Make your change, add tests, and make sure the tests still pass.
6. Push to your fork and submit a pull request.
7. The pull request should contain a phrase like `fixes #1`, `closes #1` etc., to get the PR linked to the issue you re trying to solve.
8. Make the PR a Draft, if not ready for a review and make it Open when your PR is ready.
9. Pat your self on the back and wait for your pull request to be reviewed and merged.

Here are a few things you can do that will increase the likelihood of your pull request being accepted:

Expand Down
60 changes: 27 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# GitHub Issue Assigner Bot

[contributing]: /CONTRIBUTING.md

This GitHub bot helps manage issue assignments in a repository by automatically assigning or unassigning issues based on predefined rules and user commands in comments. The bot is implemented using Probot, a framework for building GitHub Apps.

If you find this project helpful, please consider giving it a star ⭐ on GitHub. It helps others discover the project and shows your appreciation for the work!
Expand Down Expand Up @@ -68,39 +70,31 @@ If you find this project helpful, please consider giving it a star ⭐ on GitHub
4. You can edit the values in the yml to customize the comments from the bot.
5. For example, commenting '@issue-asigner claim' will assign the issue and '@issue-assigner abandon' will remove the assignment.
# Contributing
If you have any suggestions or want to report a bug, open an issue or make a pull request.
## Prerequisites
1. Git installed
2. Node installed
## Setup
1. Clone the repository
```bash
git clone https://github.com/Varun-Kolanu/issue-assigner.git
```

2. Open the repo

```bash
cd issue-assigner
```

3. Install dependencies

```bash
npm i
```

4. Run the app
```bash
npm start
```
See [Contributing guide][contributing] for contributing to the project.
# Folder structure
```bash
.
├── .github/ ## configuration files
│ └── issue-assigner.yml
├── assets/ ## assets like images, icons, etc
├── src/ ## main source code
│ ├── classes/ # classes for event handlers defined
│ ├── handlers/ # functions to handle webhook events from github
│ │ ├── issue_comment.js
│ │ └── issue_opened.js
│ ├── helpers/ # utility functions to help handlers
│ ├── app.js # main file which exports probot app
│ └── server.js # server for the app
├── test/ ## tests for app
│ ├── fixtures/ # mock data for testing
│ ├── integration/ # integration tests
│ ├── unit/ # unit tests
│ └── utils/ # utility functions for tests
├── CONTRIBUTING.md ## Contributing Guide
└── README.md ## Readme
```

# License

Expand Down
136 changes: 135 additions & 1 deletion package-lock.json

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

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"devDependencies": {
"nock": "^14.0.0-beta.5",
"nodemon": "^3.1.0",
"smee-client": "^2.0.0"
"smee-client": "^2.0.0",
"supertest": "^7.0.0"
},
"engines": {
"node": ">= 18"
Expand Down
File renamed without changes.
33 changes: 16 additions & 17 deletions src/app.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,24 @@
import bodyParser from "body-parser";
import issue_comment_created from "./handlers/issue_comment_created.js";
import issue_opened from "./handlers/issue_opened.js";
import {
IssueCommentHandler,
IssueOpenerHandler,
} from "./classes/event_handler.js";
import routes from "./routes/routes.js";

export default async (app, { getRouter }) => {
const router = getRouter("/issue-assigner");
router.use(bodyParser.json());
router.get("/", async (req, res) => {
res.status(200).send("Welcome to Issue Assigner");
});
// Define routes of server
routes(getRouter);

router.post("/webhook", (req, res) => {
console.log("Webhook from marketplace: ", req.body);
res.status(200).json({ success: "Webhook received successfully" });
});
/* Webhooks received */

// Issue opened by a user
app.on("issues.opened", issue_opened);
app.on("issues.opened", async (context) => {
const issueOpenerHandlerObj = new IssueOpenerHandler(context);
await issueOpenerHandlerObj.handleEvent();
});

// Comment is created in an issue by a user
app.on(
["issue_comment.created", "issue_comment.edited"],
issue_comment_created
);
app.on(["issue_comment.created", "issue_comment.edited"], async (context) => {
const issueCommentHandlerObj = new IssueCommentHandler(context);
await issueCommentHandlerObj.handleEvent();
});
};
Loading

0 comments on commit 66d7647

Please sign in to comment.