Skip to content

Commit

Permalink
Code refactoring & documentation (#16)
Browse files Browse the repository at this point in the history
  • Loading branch information
NikkelM authored Feb 6, 2024
1 parent 259f6fb commit f2b1363
Show file tree
Hide file tree
Showing 8 changed files with 194 additions and 150 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Custom
.env
*.pem
*notes.txt

# Ruby
*.gem
Expand Down
27 changes: 27 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
AllCops:
NewCops: enable
TargetRubyVersion: 3.1

Layout/LineLength:
Max: 300

Layout/EndOfLine:
Enabled: false

Metrics/MethodLength:
Max: 40

Metrics/BlockLength:
Enabled: false

Metrics/AbcSize:
Enabled: false

Metrics/CyclomaticComplexity:
Enabled: false

Metrics/PerceivedComplexity:
Enabled: false

Style/MethodCallWithoutArgsParentheses:
Enabled: false
11 changes: 9 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
# Changelog

## v1.1.1
## v1.1.2

<!--Releasenotes start-->
- The server now sends a different status code if a webhook was received, but not handled.
- The app now is more restrictive when handling received webhook events, meaning it only handles those events that are relevant to the app.
- The app now uses a more efficient and native way of getting Pull Request changes.
- Optimized some code paths to reduce the time it takes to process a Pull Request change.
- Improved the maintainability and readability of the app and its code.
<!--Releasenotes end-->

## v1.1.1

- The server now sends a different status code if a webhook was received, but not handled.

## v1.1.0

- Action items no longer need to be free-standing, but may be pre- or post-fixed with special characters.
Expand Down
19 changes: 12 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ This list will update whenever new changes are pushed, so you always know exactl
The app supports a wide array of programming languages and action items.
Should you find that your language of choice or action item is not supported, feel free to open an issue.

The app is built automaticall using Google Cloud Build and hosted through Google Cloud Run.
The app is built automatically using Google Cloud Build and hosted through Google Cloud Run.

## In-Depth

Expand Down Expand Up @@ -46,28 +46,29 @@ bundle install
Then create a `.env` file with the following content:

```text
GITHUB_APP_ID=${your_app_id}
GITHUB_PRIVATE_KEY=${app_private_key}
GITHUB_WEBHOOK_SECRET=${app_webhook_secret}
GITHUB_APP_ID=${App ID from the GitHub App settings}
GITHUB_PRIVATE_KEY=${Private key generated in the GitHub App settings}
GITHUB_WEBHOOK_SECRET=${Webhook secret set in the GitHub App settings}
APP_FRIENDLY_NAME=${Name of the CI check}
```

The documentation linked above describes where to obtain these values.

You can then use [smee](https://smee.io/) to create a webhook that will forward the webhook events to your local app:

```bash
smee --url smee_url --path / --port 3000
smee --url https://smee.io/gsPiE7FUxg0q3TPz --path / --port 3000
```

Make sure to also set the Webhook URL in the app settingson GitHub to the same `smee_url`.
Make sure to also set the Webhook URL in the app settings on GitHub to the same smee URL, like `https://smee.io/gsPiE7FUxg0q3TPz` in the example.

Then, you can start the app with:

```bash
ruby ./app.rb
```

If you have installed the app in a repository, and set up the webhooks correctly, you should now see the app receiving events when you create or update a Pull Request as such:
If you have correctly created and installed the app in a repository, and set up the webhooks correctly, you should now see the app receiving events like these when you create or update a Pull Request:

```text
D, [2024-02-05T14:04:28.359807 #26008] DEBUG -- : ---- received event check_suite
Expand All @@ -85,6 +86,10 @@ D, [2024-02-05T14:04:33.351184 #26008] DEBUG -- : ---- received event check_run
D, [2024-02-05T14:04:33.351388 #26008] DEBUG -- : ---- action completed
```

### Troubleshooting

If your private key is being rejected/fails to parse, replace the line breaks of the key in your `.env` file with `\n`.

---

If you enjoy this app and want to say thanks, consider buying me a [coffee](https://ko-fi.com/nikkelm) or [sponsoring](https://github.com/sponsors/NikkelM) this project.
Loading

0 comments on commit f2b1363

Please sign in to comment.