generated from ubiquity-os/plugin-template
-
Notifications
You must be signed in to change notification settings - Fork 9
feat: pull requests are automatically merged based on their activity #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
gentlementlegen
merged 107 commits into
ubiquity-os-marketplace:development
from
Meniole:main
Jul 29, 2024
Merged
Changes from all commits
Commits
Show all changes
107 commits
Select commit
Hold shift + click to select a range
579042d
chore: init repo
gentlementlegen ab8dad9
chore: renamed action steps
gentlementlegen bb001cf
fix: fixed imports within main
gentlementlegen 2dbe73b
feat: set db to be sqlite
gentlementlegen 22c79f0
chore: added save to db step
gentlementlegen c18685a
chore: moved reflect metadata
gentlementlegen 710686a
chore: moved reflect metadata
gentlementlegen 3c709dc
chore: added type to column
gentlementlegen 0142048
chore: added run input log
gentlementlegen df95f5f
chore: added default to env
gentlementlegen 5bad80a
feat: database update step
gentlementlegen f55a47d
chore: [skip ci] updated database
github-actions[bot] c29a220
chore: added git pull before push
gentlementlegen f040003
chore: ours on conflict
gentlementlegen 89c01d0
chore: update pull request set on activity
gentlementlegen bfc9791
chore: [skip ci] updated database
github-actions[bot] bdd59f2
chore: added PR close and delete
gentlementlegen 46af921
chore: added minimum checks for settings
gentlementlegen 584ce87
chore: delete PR from db if already closed
gentlementlegen 98e21d0
chore: cleanup up db creation for tests
gentlementlegen c6ba786
chore: added test for non-closing PR
gentlementlegen 336f0a0
chore: added test to close PR
gentlementlegen c9c88d3
chore: added collaborator status check for assignees
gentlementlegen ccf831a
chore: added required validation check
gentlementlegen f419e76
chore: added green CI check
gentlementlegen 07e9186
chore: fixed tests
gentlementlegen 2f9998e
chore: fixed knip
gentlementlegen c44fc3c
chore: fixed author association
gentlementlegen 101a75d
chore: [skip ci] updated database
github-actions[bot] ba47c31
chore: updated README.md
gentlementlegen 3518dce
chore: [skip ci] updated database
github-actions[bot] 5ab8128
chore: fix cspell
gentlementlegen b5f8e7e
chore: fix tests
gentlementlegen 7612e2b
chore: [skip ci] updated database
github-actions[bot] 0e39a1a
chore: added git merge strategy
gentlementlegen adb8f1c
Merge branch 'refs/heads/meniole-main' into feat/auomated-merging
gentlementlegen 7624bb5
chore: logs for activity
gentlementlegen efbd556
chore: [skip ci] updated database
github-actions[bot] 4b0706e
chore: [skip ci] updated database
github-actions[bot] 4a97732
Merge branch 'main' of https://github.com/Meniole/automated-merging
github-actions[bot] a615267
chore: added member as collaborator
gentlementlegen 3987054
chore: added closed status removal for PRs
gentlementlegen 42bd973
chore: [skip ci] updated database
github-actions[bot] d2aa853
chore: removed concurrency
gentlementlegen f1b4e93
chore: [skip ci] updated database
github-actions[bot] 2b07b7e
chore: [skip ci] updated database
github-actions[bot] bad0d0c
chore: added sha log
gentlementlegen 2512a9c
chore: added runs logs
gentlementlegen b758d95
chore: added skipped to success run
gentlementlegen a8cadf0
chore: retry function wip
gentlementlegen 9304b36
chore: retry function now returns properly
gentlementlegen a47f49f
chore: fixed CI
gentlementlegen 40578b7
chore: added logs for suite checks
gentlementlegen cfebc4b
chore: changed condition for failure
gentlementlegen b31b4ac
chore: ignore self runs
gentlementlegen 0e361fb
chore: changed until condition
gentlementlegen 1699101
chore: fixed CI
gentlementlegen cffd021
chore: fixed CI
gentlementlegen ff9e6eb
chore: filter results
gentlementlegen 6f760d1
chore: [skip ci] updated database
github-actions[bot] 318503d
Merge pull request #4 from Meniole/main
ubiquity-os-main[bot] 74b7ff4
chore: added upload retry
gentlementlegen 7457464
Update README.md
gentlementlegen 51d03fe
chore: [skip ci] updated database
github-actions[bot] 73cfc40
Merge pull request #5 from Meniole/development
ubiquity-os-main[bot] cee464a
chore: [skip ci] updated database
github-actions[bot] b4a91ec
Merge branch 'main' of https://github.com/Meniole/automated-merging
github-actions[bot] dfecd7c
chore: [skip ci] updated database
github-actions[bot] c59e010
chore: [skip ci] updated database
github-actions[bot] e23e411
chore: [skip ci] updated database
github-actions[bot] 457f02a
Merge branch 'main' of https://github.com/Meniole/automated-merging
github-actions[bot] f7a9bc0
chore: [skip ci] updated database
github-actions[bot] bedb5ca
chore: manifest.json
gentlementlegen e1f50e9
fix: changed approval requirement check to use the configuration
gentlementlegen 656bcbc
chore: removed last activity column in db
gentlementlegen 0592aee
chore: changed plugin settings schema
gentlementlegen 7677885
chore: added default values to the documentation
gentlementlegen f7a0d7f
chore: manifest.json
gentlementlegen 6e3f575
chore: [skip ci] updated database
github-actions[bot] ead7f4a
chore: removed unused env variable
gentlementlegen 8dc079b
chore: restored env variable
gentlementlegen ed30444
chore: deleted worker related files
gentlementlegen 109beef
Update src/helpers/update-pull-requests.ts
gentlementlegen 4a6f46f
chore: changed token to use workflow's token
gentlementlegen d7a4b56
chore: changed token to use workflow's token
gentlementlegen 6f9518c
Update manifest.json
gentlementlegen 1005d41
Update manifest.json
gentlementlegen 89288b2
chore: [skip ci] updated database
github-actions[bot] 82ab227
chore: [skip ci] updated database
github-actions[bot] 07fab7c
chore: debug tests
gentlementlegen a58622c
chore: debug tests
gentlementlegen 8dc95fe
chore: debug tests
gentlementlegen 1137e12
chore: debug tests
gentlementlegen a5f244b
chore: debug tests
gentlementlegen b1393f8
chore: debug tests
gentlementlegen 82c9c21
chore: debug tests
gentlementlegen bab134b
chore: debug tests
gentlementlegen 091367e
chore: debug tests
gentlementlegen 493fca8
chore: debug tests
gentlementlegen 2adf74f
chore: debug tests
gentlementlegen a87d48b
chore: debug tests
gentlementlegen 9bf2cc1
chore: debug tests
gentlementlegen 1af81e5
chore: debug tests
gentlementlegen fd7da20
chore: manifest.json
gentlementlegen 5b9a086
chore: [skip ci] updated database
github-actions[bot] 366a6da
chore: [skip ci] updated database
github-actions[bot] 0862845
Update package.json
gentlementlegen File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
|
||
./** @gentlementlegen |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,3 +17,4 @@ jobs: | |
- uses: googleapis/release-please-action@v4 | ||
with: | ||
release-type: simple | ||
target-branch: main |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,4 +14,6 @@ coverage | |
junit.xml | ||
cypress/screenshots | ||
script.ts | ||
.wrangler | ||
.wrangler | ||
test-dashboard.md | ||
database/tests/* |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,93 +1,26 @@ | ||
# `@ubiquibot/plugin-template` | ||
# `@ubiquibot/automated-merging` | ||
|
||
## Prerequisites | ||
Automatically merge pull-requests based on the reviewer count, the time elapsed since the last activity, depending | ||
on the association of the pull-request author. | ||
|
||
- A good understanding of how the [kernel](https://github.com/ubiquity/ubiquibot-kernel) works and how to interact with it. | ||
- A basic understanding of the Ubiquibot configuration and how to define your plugin's settings. | ||
|
||
## Getting Started | ||
|
||
1. Create a new repository using this template. | ||
2. Clone the repository to your local machine. | ||
3. Install the dependencies preferably using `yarn` or `bun`. | ||
|
||
## Creating a new plugin | ||
|
||
- If your plugin is to be used as a slash command which should have faster response times as opposed to longer running GitHub action tasks, you should use the `worker` type. | ||
|
||
1. Ensure you understand and have setup the [kernel](https://github.com/ubiquity/ubiquibot-kernel). | ||
2. Update [compute.yml](./.github/workflows/compute.yml) with your plugin's name and update the `id`. | ||
3. Update [context.ts](./src/types/context.ts) with the events that your plugin will fire on. | ||
4. Update [plugin-inputs.ts](./src/types/plugin-inputs.ts) to match the `with:` settings in your org or repo level configuration. | ||
|
||
- Your plugin config should look similar to this: | ||
## Configuration example | ||
|
||
```yml | ||
- plugin: <plugin-org/owner>/<plugin-repo-name>:compute.yml@development | ||
name: plugin-name | ||
id: plugin-name-command | ||
description: "Plugin description" # small description of what the plugin does | ||
command: "<regex for command>" # if you are creating a plugin with a slash command | ||
example: "<example usage>" # how to invoke the slash command | ||
with: # these are the example settings, the kernel passes these to the plugin. | ||
disabledCommands: [] | ||
timers: | ||
reviewDelayTolerance: 86000 | ||
taskStaleTimeoutDuration: 2580000 | ||
miscellaneous: | ||
maxConcurrentTasks: 3 | ||
labels: | ||
time: [] | ||
priority: [] | ||
- plugin: ubiquibot/automated-merging | ||
name: automated-merging | ||
id: automated-merging | ||
description: "Automatically merge pull-requests." | ||
with: | ||
approvalsRequired: | ||
collaborator: 1 # defaults to 1 | ||
contributor: 2 # defaults to 2 | ||
mergeTimeout: | ||
collaborator: "3.5 days" # defaults to 3.5 days | ||
contributor: "7 days" # defaults to 7 days | ||
``` | ||
|
||
###### At this stage, your plugin will fire on your defined events with the required settings passed in from the kernel. You can now start writing your plugin's logic. | ||
|
||
5. Start building your plugin by adding your logic to the [plugin.ts](./src/plugin.ts) file. | ||
|
||
## Testing a plugin | ||
|
||
### Worker Plugins | ||
## Testing | ||
|
||
- `yarn/bun worker` - to run the worker locally. | ||
- To trigger the worker, `POST` requests to http://localhost:4000/ with an event payload similar to: | ||
|
||
```ts | ||
await fetch("http://localhost:4000/", { | ||
method: "POST", | ||
headers: { | ||
"Content-Type": "application/json", | ||
}, | ||
body: JSON.stringify({ | ||
stateId: "", | ||
eventName: "", | ||
eventPayload: "", | ||
settings: "", | ||
ref: "", | ||
authToken: "", | ||
}), | ||
}); | ||
```shell | ||
yarn test | ||
``` | ||
|
||
A full example can be found [here](https://github.com/ubiquibot/assistive-pricing/blob/623ea3f950f04842f2d003bda3fc7b7684e41378/tests/http/request.http). | ||
|
||
### Action Plugins | ||
|
||
- Ensure the kernel is running and listening for events. | ||
- Fire an event in/to the repo where the kernel is installed. This can be done in a number of ways, the easiest being via the GitHub UI or using the GitHub API, such as posting a comment, opening an issue, etc in the org/repo where the kernel is installed. | ||
- The kernel will process the event and dispatch it using the settings defined in your `.ubiquibot-config.yml`. | ||
- The `compute.yml` workflow will run and execute your plugin's logic. | ||
- You can view the logs in the Actions tab of your repo. | ||
|
||
[Nektos Act](https://github.com/nektos/act) - a tool for running GitHub Actions locally. | ||
|
||
## More information | ||
|
||
- [Full Ubiquibot Configuration](https://github.com/ubiquity/ubiquibot/blob/0fde7551585499b1e0618ec8ea5e826f11271c9c/src/types/configuration-types.ts#L62) - helpful for defining your plugin's settings as they are strongly typed and will be validated by the kernel. | ||
- [Ubiquibot V1](https://github.com/ubiquity/ubiquibot) - helpful for porting V1 functionality to V2, helper/utility functions, types, etc. Everything is based on the V1 codebase but with a more modular approach. When using V1 code, keep in mind that most all code will need refactored to work with the new V2 architecture. | ||
|
||
## Examples | ||
|
||
- [Start/Stop Slash Command](https://github.com/ubq-testing/start-stop-module) - simple | ||
- [Assistive Pricing Plugin](https://github.com/ubiquibot/assistive-pricing) - complex | ||
- [Conversation Rewards](https://github.com/ubiquibot/conversation-rewards) - really complex |
Binary file not shown.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
{ | ||
"name": "Automated merging", | ||
"description": "Automatically merge pull-requests.", | ||
"ubiquity:listeners": [ "push", "pull_request.opened", "pull_request.reopened" ] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import * as github from "@actions/github"; | ||
import { Octokit } from "@octokit/rest"; | ||
import { Value } from "@sinclair/typebox/value"; | ||
import { plugin } from "./plugin"; | ||
import { envSchema, envValidator, PluginInputs, pluginSettingsSchema, pluginSettingsValidator } from "./types"; | ||
|
||
/** | ||
* How a GitHub action executes the plugin. | ||
*/ | ||
export async function run() { | ||
const payload = github.context.payload.inputs; | ||
|
||
payload.env = { ...(payload.env || {}), workflowName: github.context.workflow }; | ||
if (!envValidator.test(payload.env)) { | ||
const errors: string[] = []; | ||
for (const error of envValidator.errors(payload.env)) { | ||
console.error(error); | ||
errors.push(`${error.path}: ${error.message}`); | ||
} | ||
throw new Error(`Invalid environment provided:\n${errors.join(";\n")}`); | ||
} | ||
const env = Value.Decode(envSchema, payload.env || {}); | ||
|
||
payload.settings = Value.Default(pluginSettingsSchema, JSON.parse(payload.settings)); | ||
if (!pluginSettingsValidator.test(payload.settings)) { | ||
const errors: string[] = []; | ||
for (const error of pluginSettingsValidator.errors(payload.settings)) { | ||
console.error(error); | ||
errors.push(`${error.path}: ${error.message}`); | ||
} | ||
throw new Error(`Invalid settings provided:\n${errors.join(";\n")}`); | ||
} | ||
|
||
const settings = Value.Decode(pluginSettingsSchema, payload.settings); | ||
const inputs: PluginInputs = { | ||
stateId: payload.stateId, | ||
eventName: payload.eventName, | ||
eventPayload: JSON.parse(payload.eventPayload), | ||
settings, | ||
authToken: payload.authToken, | ||
ref: payload.ref, | ||
}; | ||
|
||
await plugin(inputs, env); | ||
|
||
return returnDataToKernel(process.env.GITHUB_TOKEN, inputs.stateId, {}); | ||
} | ||
|
||
async function returnDataToKernel(repoToken: string, stateId: string, output: object) { | ||
const octokit = new Octokit({ auth: repoToken }); | ||
return octokit.repos.createDispatchEvent({ | ||
owner: github.context.repo.owner, | ||
repo: github.context.repo.repo, | ||
event_type: "return_data_to_ubiquibot_kernel", | ||
client_payload: { | ||
state_id: stateId, | ||
output: JSON.stringify(output), | ||
}, | ||
}); | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.